Skip to content

Commit 7aba54d

Browse files
bazinskishahor02
authored andcommitted
fix trd mc 2 raw conversion
1 parent d917d31 commit 7aba54d

8 files changed

Lines changed: 783 additions & 237 deletions

File tree

DataFormats/Detectors/TRD/include/DataFormatsTRD/Constants.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ constexpr int NLAYER = 6; // the number of layers
2727
constexpr int NCHAMBERPERSEC = 30; // the number of chambers per sector
2828
constexpr int MAXCHAMBER = 540; // the maximum number of installed chambers
2929
constexpr int NCHAMBER = 521; // the number of chambers actually installed
30+
constexpr int NHALFCRU = 72; // the number of half cru (link bundles)
31+
constexpr int NLINKSPERHALFCRU = 15; // the number of links per half cru or cru end point.
32+
constexpr int NRU = 36; // the number of CRU we have
33+
constexpr int NFLP = 12; // the number of FLP we have.
34+
constexpr int NCRUPERFLP = 3; // the number of CRU per FLP
35+
constexpr int TRDLINKID = 15; // hard coded link id, specific to TRD
3036

3137
constexpr int NCOLUMN = 144; // the number of pad columns for each chamber
3238
constexpr int NROWC0 = 12; // the number of pad rows for chambers of type C0 (installed stack 0,1,3 and 4)

DataFormats/Detectors/TRD/include/DataFormatsTRD/RawData.h

Lines changed: 190 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ Word 7 | reserved 5 | link 14 da
122122
struct TrackletHCHeader {
123123
union {
124124
// 10987654321098765432109876543210
125-
// uint32_t: 00000000000000000000000000000000
125+
// uint32_t: 33222222222211111111110000000000
126126
// cccccccccccccccX LLL SSSSS
127127
// ffff| |y| sss|
128128
// | | ||| | |----- 0-4 supermodule
129129
// | | ||| |-------- 5-7 stack
130130
// | | ||------------ 8-10 layer
131131
// | | |------------- 11 always 0x1
132132
// | | |------------- 12 side of chamber
133-
// | ----------------------------- 13-72 MCM Clock counter
133+
// | ----------------------------- 13-27 MCM Clock counter
134134
// --------------------------------- 28-31 tracklet data format number
135135
uint32_t word;
136136
struct {
@@ -139,7 +139,7 @@ struct TrackletHCHeader {
139139
uint32_t layer : 3;
140140
uint32_t one : 1; //always 1
141141
uint32_t side : 1; // side of chamber
142-
uint32_t MCLK : 15; // MCM clock counter 120MHz ... for simulation -- incrementing, and same number in all for each event.
142+
uint32_t MCLK : 15; // MCM clock counter 120MHz ... for simulation -- incrementing, and uniform across an event
143143
uint32_t format : 4;
144144
// 0 baseline PID 3 time slices, 7 bit each
145145
// 1 DO NOT USE ! reserved for tracklet end marker disambiguation
@@ -155,7 +155,7 @@ struct TrackletHCHeader {
155155
struct TrackletMCMHeader {
156156
//first word *
157157
// 10987654321098765432109876543210
158-
// uint32_t: 00000000000000000000000000000000
158+
// uint32_t: 33222222222211111111110000000000
159159
// 1zzzz pppppppp pppppppp1
160160
// || yy| pppppppp | |--- 0 1 check bits
161161
// || | | | ----------- 1-8 pid for tracklet 3 second part
@@ -218,6 +218,183 @@ struct TRDFeeID {
218218
};
219219
};
220220

221+
/// \structure DigitHCHeader
222+
/// \brief Digit version of the TrackletHCHeader above, although contents are rather different.
223+
// TODO come back and comment the fields or make the name more expressive, and fill in the jjjjjjj
224+
struct DigitHCHeader {
225+
//
226+
// 10987654321098765432109876543210
227+
// uint32_t: 00000000000000000000000000000000
228+
//
229+
union { // section 15.6.1 in tdp
230+
uint32_t word0;
231+
struct {
232+
uint32_t res0 : 2;
233+
uint32_t side : 1;
234+
uint32_t stack : 3;
235+
uint32_t layer : 3;
236+
uint32_t supermodule : 5;
237+
uint32_t numberHCW : 3;
238+
uint32_t minor : 7;
239+
uint32_t major : 7;
240+
uint32_t version : 1;
241+
} __attribute__((__packed__));
242+
};
243+
244+
// 10987654321098765432109876543210
245+
// uint32_t: 00000000000000000000000000000000
246+
//
247+
union { //section 15.6.2 in tdp
248+
uint32_t word1;
249+
struct {
250+
uint32_t res1 : 2;
251+
uint32_t ptrigcount : 4;
252+
uint32_t ptrigphase : 4;
253+
uint32_t bunchcrossing : 16;
254+
uint32_t numtimebins : 6;
255+
} __attribute__((__packed__));
256+
};
257+
#ifdef DIGITALHCOPTIONALHEADER
258+
// 10987654321098765432109876543210
259+
// uint32_t: 00000000000000000000000000000000
260+
union { //section 15.6.3 in tdp
261+
uint32_t word2;
262+
struct {
263+
uint32_t res2 : 6;
264+
uint32_t dfilter : 6;
265+
uint32_t rfilter : 1;
266+
uint32_t nlfilter : 1;
267+
uint32_t xtfilter : 1;
268+
uint32_t tfilter : 1;
269+
uint32_t gfilter : 1;
270+
uint32_t pfilter : 6;
271+
} __attribute__((__packed__));
272+
};
273+
// 10987654321098765432109876543210
274+
// uint32_t: 00000000000000000000000000000000
275+
union { //section 15.6.4 in tdp
276+
uint32_t word3;
277+
struct {
278+
uint32_t res3 : 6;
279+
uint32_t svnrver : 13; //readout program svn revision
280+
uint32_t svnver : 13; //assember programm svn revision
281+
} __attribute__((__packed__));
282+
};
283+
#endif
284+
};
285+
286+
struct DigitMCMHeader {
287+
// 10987654321098765432109876543210
288+
// uint32_t: 00000000000000000000000000000000
289+
union {
290+
uint32_t word; //MCM header
291+
struct {
292+
uint32_t res : 4; // reserve 1100
293+
uint32_t eventcount : 20;
294+
uint32_t mcm : 4;
295+
uint32_t rob : 3;
296+
uint32_t yearflag : 1; //< oct2007 0, else 1
297+
} __attribute__((__packed__));
298+
};
299+
};
300+
301+
//the odd numbering of 1 2 3 and 6 are taken from the TDP page 111 section 15.7.2, 15.7.3 15.7.4 15.7.5
302+
struct trdTestPattern1 {
303+
// 10987654321098765432109876543210
304+
// uint32_t: 00000000000000000000000000000000
305+
// 11h41 for 2flp in data stream. before that on 14th dec was1 flp in timeframe.
306+
union {
307+
uint32_t word;
308+
struct {
309+
uint32_t eventcount : 6; // lower 6 bits of e counter.
310+
uint32_t stack : 5;
311+
uint32_t layer : 3;
312+
uint32_t roc : 3;
313+
uint32_t rob : 3;
314+
uint32_t mcmTp2 : 4;
315+
uint32_t cpu : 2;
316+
uint32_t counter : 6;
317+
} __attribute__((__packed__));
318+
};
319+
};
320+
321+
struct trdTestPattern2 {
322+
// 10987654321098765432109876543210
323+
// uint32_t: 00000000000000000000000000000000
324+
union {
325+
uint32_t word;
326+
struct {
327+
uint32_t eventcount : 6; // lower 6 bits of e counter.
328+
uint32_t stack : 5;
329+
uint32_t layer : 3;
330+
uint32_t roc : 3;
331+
uint32_t rob : 3;
332+
uint32_t mcmTp2 : 4;
333+
uint32_t cpu : 2;
334+
uint32_t wordcounter : 6;
335+
} __attribute__((__packed__));
336+
};
337+
};
338+
struct trdTestPattern3 {
339+
// 10987654321098765432109876543210
340+
// uint32_t: 00000000000000000000000000000000
341+
union {
342+
uint32_t word;
343+
struct {
344+
uint32_t eventcount : 12; //lower 12 bits of ecounter
345+
uint32_t stack : 5;
346+
uint32_t layer : 3;
347+
uint32_t roc : 3;
348+
uint32_t rob : 3;
349+
uint32_t mcm : 4;
350+
uint32_t cpu : 2;
351+
} __attribute__((__packed__));
352+
};
353+
};
354+
struct trdTestPattern6 {
355+
// 10987654321098765432109876543210
356+
// uint32_t: 00000000000000000000000000000000
357+
// 1zzzz pppppppp pppppppp1
358+
union {
359+
uint32_t word; //HC header0
360+
struct {
361+
uint32_t eventcount; // lower 4 bits of e counter.
362+
uint32_t stack : 5; // starting at 1
363+
uint32_t layer : 3;
364+
uint32_t roc : 3;
365+
uint32_t rob : 3;
366+
uint32_t mcm : 4;
367+
uint32_t cpu : 2;
368+
uint32_t wordcounter : 6;
369+
uint32_t oddadc : 2;
370+
} __attribute__((__packed__));
371+
};
372+
};
373+
374+
struct DigitMCMData {
375+
// 10987654321098765432109876543210
376+
// uint32_t: 00000000000000000000000000000000
377+
/* union {
378+
uint32_t word0;
379+
struct {
380+
uint32_t a : 2;
381+
uint32_t b : 5;
382+
uint32_t adc : 21; //adc bit patternpad plane
383+
} __attribute__((__packed__));
384+
};*/
385+
union {
386+
// 10987654321098765432109876543210
387+
// uint32_t: 00000000000000000000000000000000
388+
uint32_t word;
389+
struct {
390+
uint32_t c : 2; // c is wrong I cant remember name, but not a concern at the moment.
391+
uint32_t z : 10;
392+
uint32_t y : 10;
393+
uint32_t x : 10;
394+
} __attribute__((__packed__));
395+
};
396+
};
397+
221398
void buildTrackletHCHeader(TrackletHCHeader& header, int sector, int stack, int layer, int side, int chipclock, int format);
222399
void buildTrackletHCHeaderd(TrackletHCHeader& header, int detector, int rob, int chipclock, int format);
223400
uint16_t buildTRDFeeID(int supermodule, int side, int endpoint);
@@ -229,16 +406,23 @@ uint32_t getlinkerrorflag(const HalfCRUHeader& cruhead, const uint32_t link);
229406
uint32_t getlinkdatasize(const HalfCRUHeader& cruhead, const uint32_t link);
230407
uint32_t getlinkerrorflags(const HalfCRUHeader& cruheader, std::array<uint32_t, 15>& linkerrorflags);
231408
uint32_t getlinkdatasizes(const HalfCRUHeader& cruheader, std::array<uint32_t, 15>& linksizes);
232-
std::ostream& operator<<(std::ostream& stream, const TrackletHCHeader halfchamberheader);
409+
uint32_t getHCIDFromTrackletHCHeader(const TrackletHCHeader& header);
410+
uint32_t getHCIDFromTrackletHCHeader(const uint32_t& headerword);
411+
std::ostream& operator<<(std::ostream& stream, const TrackletHCHeader& halfchamberheader);
412+
std::ostream& operator<<(std::ostream& stream, const TrackletMCMHeader& mcmhead);
233413
std::ostream& operator<<(std::ostream& stream, const TrackletMCMData& tracklet);
234414
void printTrackletMCMData(o2::trd::TrackletMCMData& tracklet);
235415
void printTrackletMCMHeader(o2::trd::TrackletMCMHeader& mcmhead);
236-
std::ostream& operator<<(std::ostream& stream, const TrackletMCMHeader& mcmhead);
237416
void printHalfChamber(o2::trd::TrackletHCHeader& halfchamber);
238417
void dumpHalfChamber(o2::trd::TrackletHCHeader& halfchamber);
239418
void printHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru);
240419
void dumpHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru);
241420
std::ostream& operator<<(std::ostream& stream, const HalfCRUHeader& halfcru);
421+
bool trackletMCMHeaderSanityCheck(o2::trd::TrackletMCMHeader& header);
422+
bool trackletHCHeaderSanityCheck(o2::trd::TrackletHCHeader& header);
423+
bool digitMCMHeaderSanityCheck(o2::trd::DigitMCMHeader* header);
424+
void printDigitMCMHeader(o2::trd::DigitMCMHeader& header);
425+
void printDigitHCHeader(o2::trd::DigitHCHeader& header);
242426
}
243427
}
244428
#endif

Detectors/TRD/base/include/TRDBase/FeeParam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class FeeParam
6060
static int getMCMfromSharedPad(int irow, int icol);
6161
static int getROBfromPad(int irow, int icol);
6262
static int getROBfromSharedPad(int irow, int icol);
63-
static int getRobSide(int irob);
63+
static int getROBSide(int irob);
6464
static int getColSide(int icol);
6565

6666
// SCSN-related

Detectors/TRD/base/src/FeeParam.cxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int FeeParam::getPadColFromADC(int irob, int imcm, int iadc)
223223
if (iadc < 0 || iadc > NADCMCM) {
224224
return -100;
225225
}
226-
int mcmcol = imcm % NMCMROBINCOL + getRobSide(irob) * NMCMROBINCOL; // MCM column number on ROC [0..7]
226+
int mcmcol = imcm % NMCMROBINCOL + getROBSide(irob) * NMCMROBINCOL; // MCM column number on ROC [0..7]
227227
int padcol = mcmcol * NCOLMCM + NCOLMCM + 1 - iadc;
228228
if (padcol < 0 || padcol >= NCOLUMN) {
229229
return -1; // this is commented because of reason above OK
@@ -243,7 +243,7 @@ int FeeParam::getExtendedPadColFromADC(int irob, int imcm, int iadc)
243243
if (iadc < 0 || iadc > NADCMCM) {
244244
return -100;
245245
}
246-
int mcmcol = imcm % NMCMROBINCOL + getRobSide(irob) * NMCMROBINCOL; // MCM column number on ROC [0..7]
246+
int mcmcol = imcm % NMCMROBINCOL + getROBSide(irob) * NMCMROBINCOL; // MCM column number on ROC [0..7]
247247
int padcol = mcmcol * NADCMCM + NCOLMCM + 2 - iadc;
248248

249249
return padcol;
@@ -318,7 +318,7 @@ int FeeParam::getROBfromSharedPad(int irow, int icol)
318318
}
319319

320320
//_____________________________________________________________________________
321-
int FeeParam::getRobSide(int irob)
321+
int FeeParam::getROBSide(int irob)
322322
{
323323
//
324324
// Return on which side this rob sits (A side = 0, B side = 1)
@@ -513,9 +513,9 @@ void FeeParam::createORILookUpTable()
513513

514514
int FeeParam::getORI(int detector, int readoutboard)
515515
{
516-
int supermodule = detector / 30;
517-
LOG(debug3) << "getORI : " << detector << " :: " << readoutboard << getORIinSM(detector, readoutboard) + 60 * detector;
518-
return getORIinSM(detector, readoutboard) + 2 * detector; // 2 ORI per detector
516+
int supermodule = detector / NCHAMBERPERSEC;
517+
/// LOG(info) << "getORI : " << detector << " :: " << readoutboard << " -- " << getORIinSM(detector, readoutboard) << " " << getORIinSM(detector, readoutboard) + NCHAMBERPERSEC * 2 * detector;
518+
return getORIinSM(detector, readoutboard) + NCHAMBER * 2 * detector; // 60 ORI per supermodule
519519
}
520520

521521
int FeeParam::getORIinSM(int detector, int readoutboard)
@@ -524,8 +524,8 @@ int FeeParam::getORIinSM(int detector, int readoutboard)
524524
int chamberside = 0;
525525
int trdstack = Geometry::getStack(detector);
526526
int trdlayer = Geometry::getLayer(detector);
527-
int side = getRobSide(readoutboard);
528-
//see TDP for explanation of mapping TODO should probably come from CCDB for the instances where the mapping of ori fibers is misconfigured (accidental fibre swaps).
527+
int side = getROBSide(readoutboard);
528+
//see TDP for explanation of mapping TODO should probably come from CCDB
529529
if (trdstack < 2 || (trdstack == 2 && side == 0)) // A Side
530530
{
531531
ori = trdstack * 12 + (5 - trdlayer + side * 5) + trdlayer / 6 + side; // <- that is correct for A side at least for now, probably not for very long LUT as that will come form CCDB ni anycase.

Detectors/TRD/simulation/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,30 @@ o2-sim -m PIPE MAG TRD -n 1000 -g boxgen --configKeyValues 'BoxGun.pdg=211;BoxGu
2020
```
2121
--configKeyValues 'TRDSimParams.doTR=false;TRDSimParams.maxMCStepSize=0.1'
2222
```
23+
24+
# Generate Raw data from MonteCarlo:
25+
26+
```
27+
o2-trd-trap2raw
28+
```
29+
This will convert the tracklets and digits in the current directory to a series of files containing the raw data as it would appear coming out of the cru.
30+
There are multiple options :
31+
- -d [ --input-file-digits ] default of trddigits.root
32+
input Trapsim digits file, empty string to have no digits.
33+
- -t [ --input-file-tracklets ] default of trdtracklets.root
34+
input Trapsim tracklets file
35+
- -l [ --fileper ] how to distrbute the data into raw files.
36+
- all : 1 raw file
37+
- halfcru : 1 file per cru end point, so 2 files per cru.
38+
- cru : one file per cru
39+
- sm: one file per supermodule
40+
- -o [ --output-dir ] output directory for raw data defaults to local directory
41+
- -x [ --trackletHCHeader ] include tracklet half chamber header (for run3, and not in run2)
42+
- -e [ --no-empty-hbf ] do not create empty HBF pages (except for HBF starting TF)
43+
- -r [ --rdh-version ] rdh version in use default of 6
44+
- --configKeyValues arg comma-separated configKeyValues
45+
46+
default would then be the following :
47+
```
48+
o2-trd-trap2raw -d trddigits.root -t trdtracklets.root -l halfcru -o ./ -x -r 6 -e
49+
```

0 commit comments

Comments
 (0)