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