CMS 3D CMS Logo

DTTFFEDReader.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTFFEDReader
4 //
5 // L1 DT Track Finder Raw-to-Digi
6 //
7 //
8 //
9 // Author :
10 // J. Troconiz UAM Madrid
11 //
12 //--------------------------------------------------
13 
15 
19 
21 
22 #include <iostream>
23 
24 using namespace std;
25 
27 
28  produces<L1MuDTChambPhContainer>();
29  produces<L1MuDTChambThContainer>();
30  produces<L1MuDTTrackContainer>("DATA");
31 
32  DTTFInputTag = pset.getParameter<edm::InputTag>("DTTF_FED_Source");
33 
34  verbose_ = pset.getUntrackedParameter<bool>("verbose", false);
35 
36  Raw_token = consumes<FEDRawDataCollection>(DTTFInputTag);
37 }
38 
40 
42 
43  unique_ptr<L1MuDTChambPhContainer> phi_product(new L1MuDTChambPhContainer);
44  unique_ptr<L1MuDTChambThContainer> the_product(new L1MuDTChambThContainer);
45  unique_ptr<L1MuDTTrackContainer> tra_product(new L1MuDTTrackContainer);
46 
50 
51  if (!fillRawData(e, phi_data, the_data, tra_data))
52  return;
53 
54  phi_product->setContainer(phi_data);
55  the_product->setContainer(the_data);
56  tra_product->setContainer(tra_data);
57 
58  e.put(std::move(phi_product));
59  e.put(std::move(the_product));
60  e.put(std::move(tra_product), "DATA");
61 }
62 
67 
68  analyse(e);
69 
70  phi_data = p_data();
71  the_data = t_data();
72  tra_data = k_data();
73 
74  return true;
75 }
76 
77 //--------------
78 // Operations --
79 //--------------
81  clear();
82  process(e);
83  match();
84  return;
85 }
86 
87 // process data
89 
90  // Container
91  vector<int> DTTFWordContainer;
92  vector<int>::iterator DTTFiterator;
93 
94  // Header constituents
95  int BOEevTy, DTTFId;
96 
97  // DTTF Payload constituents
98  int DTTFWord;
99  int DTTFChan, bitsID;
100  int addr1[2] = {3, 3};
101  int addr2[2] = {15, 15};
102  int addr3[2] = {15, 15};
103  int addr4[2] = {15, 15};
104 
105  // Trailer constituents
106  int evtLgth, CRC;
107 
108  //--> Header
109 
111  e.getByToken(Raw_token, data);
112  FEDRawData dttfdata = data->FEDData(0x030C);
113  if (dttfdata.size() == 0)
114  return;
115 
116  int *dataWord1 = new int;
117  int *dataWord2 = new int;
118  unsigned char *LineFED = dttfdata.data();
119  *dataWord2 = *((int *)LineFED);
120  LineFED += 4;
121  *dataWord1 = *((int *)LineFED);
122  int lines = 1; // already counting header
123 
124  BOEevTy = ((*dataWord1) & 0xFF000000) >> 24; // positions 57 ->64
125  DTTFId = ((*dataWord2) & 0x000FFF00) >> 8; // positions 9 ->20
126 
127  if ((BOEevTy != 0x50) || (DTTFId != 0x030C)) {
128  if (verbose_)
129  edm::LogWarning("dttf_unpacker")
130  << "Not a DTTF header " << hex << *dataWord1;
131  delete dataWord1;
132  delete dataWord2;
133  return;
134  }
135 
136  int newCRC = 0xFFFF;
137  dt_crc::calcCRC(*dataWord1, *dataWord2, newCRC);
138 
139  //--> DTTF data
140 
141  LineFED += 4;
142  *dataWord2 = *((int *)LineFED);
143  LineFED += 4;
144  *dataWord1 = *((int *)LineFED);
145  int chkEOE = ((*dataWord1) & 0xFFF00000) >> 20;
146  lines++;
147 
148  while (chkEOE != 0xA00) {
149 
150  dt_crc::calcCRC(*dataWord1, *dataWord2, newCRC);
151 
152  DTTFWord = *dataWord1;
153  DTTFWordContainer.push_back(DTTFWord);
154  DTTFWord = *dataWord2;
155  DTTFWordContainer.push_back(DTTFWord);
156 
157  LineFED += 4;
158  *dataWord2 = *((int *)LineFED);
159  LineFED += 4;
160  *dataWord1 = *((int *)LineFED);
161  chkEOE = ((*dataWord1) & 0xFFF00000) >> 20;
162  lines++;
163 
164  if (lines > 3026) {
165  if (verbose_)
166  edm::LogWarning("dttf_unpacker")
167  << "Warning : number of DTTF lines > 3026 "; // 3026 = 1(header) +
168  // 3024(max # PHTF-ETTF
169  // 64 bits words) +
170  // 1(trailer)
171  delete dataWord1;
172  delete dataWord2;
173  return;
174  }
175 
176  } // end while-Data loop
177 
178  //--> Trailer
179 
180  evtLgth = ((*dataWord1) & 0x00FFFFFF); // positions 33 ->56
181  CRC = ((*dataWord2) & 0xFFFF0000) >> 16; // positions 17 ->32
182 
183  dt_crc::calcCRC(*dataWord1, (*dataWord2) & 0xFFFF, newCRC);
184 
185  if (newCRC != CRC) {
186  if (verbose_)
187  edm::LogWarning("dttf_unpacker")
188  << "Calculated CRC " << hex << newCRC
189  << " differs from CRC in trailer " << hex << CRC;
190  delete dataWord1;
191  delete dataWord2;
192  return;
193  }
194 
195  if (lines != evtLgth) {
196  if (verbose_)
197  edm::LogWarning("dttf_unpacker")
198  << "Number of words read != event length " << dec << lines << " "
199  << evtLgth;
200  delete dataWord1;
201  delete dataWord2;
202  return;
203  }
204 
205  // --> analyse event
206 
207  for (DTTFiterator = DTTFWordContainer.begin();
208  DTTFiterator != DTTFWordContainer.end(); DTTFiterator++) {
209 
210  DTTFChan = ((*DTTFiterator) & 0xFF000000) >> 24;
211  DTTFiterator++;
212  bitsID = ((*DTTFiterator) & 0xF0000000) >> 28;
213 
214  int bxID = bxNr(DTTFChan);
215  if (bxID == -999)
216  continue;
217  int wheelID = wheel(DTTFChan);
218  if (wheelID == -999)
219  continue;
220  int sectorID = sector(DTTFChan);
221  if (sectorID == -999)
222  continue;
223 
224  // Input
225  if (wheelID != 0 && bitsID <= 0x9) {
226 
227  int wheelPh = (abs(wheelID) - 1) * wheelID / abs(wheelID);
228  int stationID = 0;
229  int ra = 0;
230  int ba = 0;
231  int tsqual = 0;
232  int ts2tag = 0;
233 
234  if ((bitsID >> 1) == 0) {
235  stationID = 1;
236  }
237  if ((bitsID >> 1) == 1) {
238  stationID = 2;
239  }
240  if ((bitsID >> 1) == 4) {
241  stationID = 3;
242  }
243  if ((bitsID >> 1) == 2) {
244  stationID = 4;
245  }
246 
247  if (stationID != 3) {
248 
249  ts2tag = (bitsID)&0x1;
250  tsqual = (~(*DTTFiterator) & 0x07) - 1;
251  ba = (~(*DTTFiterator) & 0x1FF8) >> 3;
252  if (ba > 0x1FF)
253  ba -= 0x400;
254  ra = (~(*DTTFiterator) & 0x1FFE000) >> 13;
255  if (ra > 0x7FF)
256  ra -= 0x1000;
257  } else {
258 
259  ts2tag = (bitsID)&0x1;
260  tsqual = (~(*DTTFiterator) & 0x07) - 1;
261  ra = (~(*DTTFiterator) & 0x7FF8) >> 3;
262  if (ra > 0x7FF)
263  ra -= 0x1000;
264  }
265 
266  if (tsqual != 7 && wheelID != -1) {
267  phiSegments.push_back(L1MuDTChambPhDigi(bxID + ts2tag, wheelPh,
268  sectorID, stationID, ra, ba,
269  tsqual, ts2tag, 0));
270  }
271  }
272  // Input
273 
274  // Input
275  if (wheelID == 0 && bitsID <= 0x4) {
276 
277  int wheelTh = bitsID - 2;
278 
279  int posALL, posBTI[7];
280 
281  if (wheelTh == -2 || wheelTh == -1 ||
282  (wheelTh == 0 &&
283  (sectorID == 0 || sectorID == 3 || sectorID == 4 || sectorID == 7 ||
284  sectorID == 8 || sectorID == 11))) {
285 
286  posALL = ~(*DTTFiterator) & 0x7F;
287  posBTI[0] = ~(*DTTFiterator) & 0x01;
288  posBTI[1] = (~(*DTTFiterator) & 0x02) >> 1;
289  posBTI[2] = (~(*DTTFiterator) & 0x04) >> 2;
290  posBTI[3] = (~(*DTTFiterator) & 0x08) >> 3;
291  posBTI[4] = (~(*DTTFiterator) & 0x10) >> 4;
292  posBTI[5] = (~(*DTTFiterator) & 0x20) >> 5;
293  posBTI[6] = (~(*DTTFiterator) & 0x40) >> 6;
294 
295  if (posALL) {
296  theSegments.push_back(
297  L1MuDTChambThDigi(bxID, wheelTh, sectorID, 1, posBTI));
298  }
299 
300  posALL = ~(*DTTFiterator) & 0x3F80;
301  posBTI[0] = (~(*DTTFiterator) & 0x0080) >> 7;
302  posBTI[1] = (~(*DTTFiterator) & 0x0100) >> 8;
303  posBTI[2] = (~(*DTTFiterator) & 0x0200) >> 9;
304  posBTI[3] = (~(*DTTFiterator) & 0x0400) >> 10;
305  posBTI[4] = (~(*DTTFiterator) & 0x0800) >> 11;
306  posBTI[5] = (~(*DTTFiterator) & 0x1000) >> 12;
307  posBTI[6] = (~(*DTTFiterator) & 0x2000) >> 13;
308 
309  if (posALL) {
310  theSegments.push_back(
311  L1MuDTChambThDigi(bxID, wheelTh, sectorID, 2, posBTI));
312  }
313 
314  posALL = ~(*DTTFiterator) & 0x1FC000;
315  posBTI[0] = (~(*DTTFiterator) & 0x004000) >> 14;
316  posBTI[1] = (~(*DTTFiterator) & 0x008000) >> 15;
317  posBTI[2] = (~(*DTTFiterator) & 0x010000) >> 16;
318  posBTI[3] = (~(*DTTFiterator) & 0x020000) >> 17;
319  posBTI[4] = (~(*DTTFiterator) & 0x040000) >> 18;
320  posBTI[5] = (~(*DTTFiterator) & 0x080000) >> 19;
321  posBTI[6] = (~(*DTTFiterator) & 0x100000) >> 20;
322 
323  if (posALL) {
324  theSegments.push_back(
325  L1MuDTChambThDigi(bxID, wheelTh, sectorID, 3, posBTI));
326  }
327  }
328 
329  else {
330 
331  posALL = ~(*DTTFiterator) & 0x7F;
332  posBTI[6] = ~(*DTTFiterator) & 0x01;
333  posBTI[5] = (~(*DTTFiterator) & 0x02) >> 1;
334  posBTI[4] = (~(*DTTFiterator) & 0x04) >> 2;
335  posBTI[3] = (~(*DTTFiterator) & 0x08) >> 3;
336  posBTI[2] = (~(*DTTFiterator) & 0x10) >> 4;
337  posBTI[1] = (~(*DTTFiterator) & 0x20) >> 5;
338  posBTI[0] = (~(*DTTFiterator) & 0x40) >> 6;
339 
340  if (posALL) {
341  theSegments.push_back(
342  L1MuDTChambThDigi(bxID, wheelTh, sectorID, 1, posBTI));
343  }
344 
345  posALL = ~(*DTTFiterator) & 0x3F80;
346  posBTI[6] = (~(*DTTFiterator) & 0x0080) >> 7;
347  posBTI[5] = (~(*DTTFiterator) & 0x0100) >> 8;
348  posBTI[4] = (~(*DTTFiterator) & 0x0200) >> 9;
349  posBTI[3] = (~(*DTTFiterator) & 0x0400) >> 10;
350  posBTI[2] = (~(*DTTFiterator) & 0x0800) >> 11;
351  posBTI[1] = (~(*DTTFiterator) & 0x1000) >> 12;
352  posBTI[0] = (~(*DTTFiterator) & 0x2000) >> 13;
353 
354  if (posALL) {
355  theSegments.push_back(
356  L1MuDTChambThDigi(bxID, wheelTh, sectorID, 2, posBTI));
357  }
358 
359  posALL = ~(*DTTFiterator) & 0x1FC000;
360  posBTI[6] = (~(*DTTFiterator) & 0x004000) >> 14;
361  posBTI[5] = (~(*DTTFiterator) & 0x008000) >> 15;
362  posBTI[4] = (~(*DTTFiterator) & 0x010000) >> 16;
363  posBTI[3] = (~(*DTTFiterator) & 0x020000) >> 17;
364  posBTI[2] = (~(*DTTFiterator) & 0x040000) >> 18;
365  posBTI[1] = (~(*DTTFiterator) & 0x080000) >> 19;
366  posBTI[0] = (~(*DTTFiterator) & 0x100000) >> 20;
367 
368  if (posALL) {
369  theSegments.push_back(
370  L1MuDTChambThDigi(bxID, wheelTh, sectorID, 3, posBTI));
371  }
372  }
373  }
374  // Input
375 
376  // Addresses
377  if (wheelID != 0 && bitsID >= 0xA && bitsID <= 0xB) {
378 
379  int candID = bitsID - 0xA;
380 
381  addr4[candID] = ((*DTTFiterator) & 0x0F);
382  addr3[candID] = ((*DTTFiterator) & 0xF0) >> 4;
383  addr2[candID] = ((*DTTFiterator) & 0xF00) >> 8;
384  addr1[candID] = ((*DTTFiterator) & 0x3000) >> 12;
385  }
386  // Addresses
387 
388  // Output
389  if (wheelID != 0 && bitsID >= 0xC) {
390 
391  int muonID = 0;
392  int pt = 0;
393  int ch = 0;
394  int phi = 0;
395  int qual = 0;
396 
397  muonID = (bitsID & 0x1);
398  qual = (~(*DTTFiterator) & 0x07);
399  phi = ((*DTTFiterator) & 0x7F8) >> 3;
400  ch = (~(*DTTFiterator) & 0x800) >> 11;
401  pt = (~(*DTTFiterator) & 0x1F000) >> 12;
402 
403  if (qual != 0) {
404  dtTracks.push_back(L1MuDTTrackCand(
405  0, phi, 0, pt, ch, 1, 0, qual, bxID, wheelID, sectorID, muonID,
406  addr1[muonID], addr2[muonID], addr3[muonID], addr4[muonID]));
407  }
408  }
409  // Output
410 
411  // Output
412  if (wheelID == 0 && bitsID >= 0x8) {
413 
414  int wheelTh = bitsID & 0x7;
415 
416  int etaALL;
417 
418  etaALL = ~(*DTTFiterator) & 0x007F;
419  if (etaALL) {
420  etTrack[bxID + 1][sectorID][wheelTh][0] = (*DTTFiterator) & 0x003F;
421  efTrack[bxID + 1][sectorID][wheelTh][0] =
422  (~(*DTTFiterator) & 0x0040) >> 6;
423  }
424 
425  etaALL = (~(*DTTFiterator) & 0x3F80) >> 7;
426  if (etaALL) {
427  etTrack[bxID + 1][sectorID][wheelTh][1] =
428  ((*DTTFiterator) & 0x1F80) >> 7;
429  efTrack[bxID + 1][sectorID][wheelTh][1] =
430  (~(*DTTFiterator) & 0x2000) >> 13;
431  }
432  }
433  // Output
434 
435  } // end for-loop container content
436 
437  delete dataWord1;
438  delete dataWord2;
439  return;
440 }
441 
443 
444  for (L1MuDTTrackContainer::TrackIterator i = dtTracks.begin();
445  i != dtTracks.end(); i++) {
446  int bxTh = i->bx() + 1;
447  int sectorTh = i->scNum();
448  int wheelTh = i->whNum() + 3;
449  if (wheelTh > 3)
450  wheelTh -= 1;
451  int muonTh = i->TrkTag();
452 
453  i->setEtaPacked(etTrack[bxTh][sectorTh][wheelTh][muonTh]);
454  i->setFineHaloPacked(efTrack[bxTh][sectorTh][wheelTh][muonTh]);
455  }
456 
457  return;
458 }
459 
460 // access data
462  return phiSegments;
463 }
464 
466  return theSegments;
467 }
468 
470  return dtTracks;
471 }
472 
474  phiSegments.clear();
475  theSegments.clear();
476  dtTracks.clear();
477 
478  for (int i = 0; i < 3; i++) {
479  for (int j = 0; j < 12; j++) {
480  for (int k = 0; k < 6; k++) {
481  for (int l = 0; l < 2; l++) {
482  etTrack[i][j][k][l] = 0;
483  efTrack[i][j][k][l] = 0;
484  }
485  }
486  }
487  }
488 
489  return;
490 }
491 
492 int DTTFFEDReader::channel(int wheel, int sector, int bx) {
493 
494  // wheel : -3 -2 -1 +1 +2 +3 <=> PHTF's : N2, N1, N0, P0, P1, P2
495  // 0 <=> ETTF
496  // sector : 0 -> 11
497  // bx : -1 -> +1
498 
499  int myChannel = 255;
500 
501  if (abs(bx) > 1) {
502  return myChannel;
503  }
504  if (sector < 0 || sector > 11) {
505  return myChannel;
506  }
507  if (abs(wheel) > 3) {
508  return myChannel;
509  }
510 
511  myChannel = sector * 21 + wheel * 3 - bx + 10;
512 
513  if (myChannel > 125)
514  myChannel += 2;
515 
516  return myChannel;
517 }
518 
519 int DTTFFEDReader::bxNr(int channel) {
520 
521  int myChannel = channel;
522 
523  if (myChannel > 127)
524  myChannel -= 2;
525 
526  if (myChannel < 0 || myChannel > 251) {
527  return -999;
528  }
529 
530  int myBx = 1 - (myChannel % 3);
531 
532  return myBx;
533 }
534 
535 int DTTFFEDReader::sector(int channel) {
536 
537  int myChannel = channel;
538 
539  if (myChannel > 127)
540  myChannel -= 2;
541 
542  if (myChannel < 0 || myChannel > 251) {
543  return -999;
544  }
545 
546  return myChannel / 21;
547 }
548 
549 int DTTFFEDReader::wheel(int channel) {
550 
551  int myChannel = channel;
552 
553  if (myChannel > 127)
554  myChannel -= 2;
555 
556  if (myChannel < 0 || myChannel > 251) {
557  return -999;
558  }
559 
560  int myWheel = ((myChannel % 21) / 3) - 3;
561 
562  return myWheel;
563 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
const L1MuDTChambThContainer::The_Container & t_data()
void produce(edm::Event &e, const edm::EventSetup &c) override
Produce digis out of raw data.
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
DTTFFEDReader(const edm::ParameterSet &pset)
Constructor.
std::vector< L1MuDTTrackCand > TrackContainer
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< L1MuDTChambPhDigi > Phi_Container
std::vector< L1MuDTChambThDigi > The_Container
int k[5][pyjets_maxn]
TrackContainer::iterator TrackIterator
void process(edm::Event &e)
static const int muonID
Definition: TopGenEvent.h:20
void calcCRC(long, int &)
Definition: DTCRC.cc:3
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const L1MuDTTrackContainer::TrackContainer & k_data()
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
int channel(int wheel, int sector, int bx)
void analyse(edm::Event &e)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
int wheel(int channel)
bool fillRawData(edm::Event &e, L1MuDTChambPhContainer::Phi_Container &phi_data, L1MuDTChambThContainer::The_Container &the_data, L1MuDTTrackContainer::TrackContainer &tra_data)
Generate and fill FED raw data for a full event.
const L1MuDTChambPhContainer::Phi_Container & p_data()
int bxNr(int channel)
~DTTFFEDReader() override
Destructor.
def move(src, dest)
Definition: eostools.py:511
int sector(int channel)