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