CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTFFEDSim.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTFFEDSim
4 //
5 // L1 DT Track Finder Digi-to-Raw
6 //
7 //
8 // $Date: 2009/11/18 13:27:12 $
9 // $Revision: 1.13 $
10 //
11 // Author :
12 // J. Troconiz UAM Madrid
13 //
14 //--------------------------------------------------
15 
17 
20 
25 
26 #include <iostream>
27 
28 using namespace std;
29 
30 DTTFFEDSim::DTTFFEDSim(const edm::ParameterSet& pset) : eventNum(0) {
31 
32  produces<FEDRawDataCollection>();
33 
34  DTDigiInputTag = pset.getParameter<edm::InputTag>("DTDigi_Source");
35  DTPHTFInputTag = pset.getParameter<edm::InputTag>("DTTracks_Source");
36 
37 }
38 
40 
42 
44 
45  if (!fillRawData(e, data)) return;
46 
47  auto_ptr<FEDRawDataCollection> fed_product(new FEDRawDataCollection(data));
48 
49  e.put(fed_product);
50 
51 }
52 
55 
56  eventNum = e.id().event();
57 
58  int lines = 2;
59 
61  e.getByLabel(getDTDigiInputTag(),phtrig);
62  lines += phtrig->bxSize(-1, 1);
63 
65  e.getByLabel(getDTDigiInputTag(),thtrig);
66  lines += thtrig->bxSize(-1, 1);
67 
69  e.getByLabel(getDTPHTFInputTag(),trtrig);
70  lines += trtrig->bxSize(-1, 1)*3;
71 
72  FEDRawData& dttfdata = data.FEDData(0x30C);
73  dttfdata.resize(lines*8); // size in bytes
74  unsigned char* LineFED=dttfdata.data();
75 
76  int* dataWord1 = new int;
77  int* dataWord2 = new int;
78 
79  //--> Header
80 
81  *dataWord1 = 0x50000000
82  + (eventNum&0xFFFFFF);
83  *dataWord2 = 0x00030C00;
84 
85  int newCRC = 0xFFFF;
86  calcCRC(*dataWord1, *dataWord2, newCRC);
87  *((int*)LineFED)=*dataWord2;
88  LineFED+=4;
89  *((int*)LineFED)=*dataWord1;
90 
91  //--> DTTF data
92 
93  int TS1Id[4], TS2Id[4]; // word identifier for TS #1,#2 for stations
94  TS1Id[0] = 0x0E;
95  TS2Id[0] = 0x1E;
96  TS1Id[1] = 0x2E;
97  TS2Id[1] = 0x3E;
98  TS1Id[3] = 0x4E;
99  TS2Id[3] = 0x5E;
100  TS1Id[2] = 0x8FFF8;
101  TS2Id[2] = 0x9FFF8;
102 
103  //Input
105 
106  for ( tsphi = phtrig->getContainer()->begin();
107  tsphi != phtrig->getContainer()->end();
108  tsphi++ ) {
109  if ( tsphi->code() != 7 ) {
110 
111  int wheelID = tsphi->whNum()+1;
112  if ( wheelID <= 0 ) wheelID -= 2;
113  int stationID = tsphi->stNum()-1;
114  int is2nd = tsphi->Ts2Tag();
115 
116  int channelNr = channel(wheelID, tsphi->scNum(), tsphi->bxNum()-is2nd);
117  if ( channelNr == 255 ) continue;
118  int TSId = ( is2nd == 0 ) ? TS1Id[stationID] : TS2Id[stationID];
119 
120  *dataWord1 = ((channelNr&0xFF)<<24)
121  + 0x00FFFFFF;
122 
123  if ( stationID != 2 ){
124  *dataWord2 = ( (TSId&0x0FF)<<24)
125  + (~(tsphi->code()+1)&0x007)
126  + ( (~tsphi->phiB()&0x3FF)<<3)
127  + ( (~tsphi->phi()&0xFFF)<<13);
128  }
129  else {
130  *dataWord2 = ( (TSId&0xFFFFF)<<12)
131  + (~(tsphi->code()+1)&0x00007)
132  + ( (~tsphi->phi()&0x00FFF)<<3);
133  }
134 
135  calcCRC(*dataWord1, *dataWord2, newCRC);
136  LineFED+=4;
137  *((int*)LineFED)=*dataWord2;
138  LineFED+=4;
139  *((int*)LineFED)=*dataWord1;
140  }
141  }
142  //Input
143 
144  //Input
146 
147  for ( tsthe = thtrig->getContainer()->begin();
148  tsthe != thtrig->getContainer()->end();
149  tsthe++ ) {
150 
151  int wheelTh = tsthe->whNum();
152  int sectorID = tsthe->scNum();
153 
154  int channelNr = channel(0, sectorID, tsthe->bxNum());
155  if ( channelNr == 255 ) continue;
156  int TSId = wheelTh+2;
157 
158  *dataWord1 = ((channelNr&0xFF)<<24)
159  + 0x00FFFFFF;
160 
161  *dataWord2 = ((TSId&0x07)<<28)
162  + 0x0FFFFFFF;
163 
164  int stationID = tsthe->stNum()-1;
165  for ( int bti = 0; bti < 7; bti++ )
166  if ( wheelTh == -2 || wheelTh == -1 ||
167  ( wheelTh == 0 && (sectorID == 0 || sectorID == 3 || sectorID == 4 || sectorID == 7 || sectorID == 8 || sectorID == 11) ) )
168  *dataWord2 -= (tsthe->position(bti)&0x1)<<(stationID*7+bti);
169  else
170  *dataWord2 -= (tsthe->position(6-bti)&0x1)<<(stationID*7+bti);
171 
172  calcCRC(*dataWord1, *dataWord2, newCRC);
173  LineFED+=4;
174  *((int*)LineFED)=*dataWord2;
175  LineFED+=4;
176  *((int*)LineFED)=*dataWord1;
177  }
178  //Input
179 
180  //Output
182 
183  for ( tstrk = trtrig->getContainer()->begin();
184  tstrk != trtrig->getContainer()->end();
185  tstrk++ ) {
186 
187  int channelNr = channel(tstrk->whNum(), tstrk->scNum(), tstrk->bx());
188  if ( channelNr == 255 ) continue;
189  int TSId = ( tstrk->TrkTag() == 0 ) ? 0xAFFF : 0xBFFF;
190 
191  *dataWord1 = ((channelNr&0xFF)<<24)
192  + 0x00FFFFFF;
193 
194  *dataWord2 = ( (TSId&0xFFFF)<<16)
195  + ( tstrk->stNum(4)&0x0000F)
196  + ((tstrk->stNum(3)&0x0000F)<<4)
197  + ((tstrk->stNum(2)&0x0000F)<<8)
198  + ((tstrk->stNum(1)&0x00003)<<12);
199 
200  calcCRC(*dataWord1, *dataWord2, newCRC);
201  LineFED+=4;
202  *((int*)LineFED)=*dataWord2;
203  LineFED+=4;
204  *((int*)LineFED)=*dataWord1;
205 
206  TSId = ( tstrk->TrkTag() == 0 ) ? 0xCFFE : 0xDFFE;
207 
208  *dataWord1 = ((channelNr&0xFF)<<24)
209  + 0x00FFFFFF;
210 
211  *dataWord2 = ( (TSId&0xFFFE)<<16)
212  + ( ~tstrk->quality_packed()&0x0007)
213  + ( (tstrk->phi_packed()&0x00FF)<<3)
214  + ( (~tstrk->charge_packed()&0x0001)<<11)
215  + ( (~tstrk->pt_packed()&0x001F)<<12);
216 
217  calcCRC(*dataWord1, *dataWord2, newCRC);
218  LineFED+=4;
219  *((int*)LineFED)=*dataWord2;
220  LineFED+=4;
221  *((int*)LineFED)=*dataWord1;
222 
223  channelNr = channel(0, tstrk->scNum(), tstrk->bx());
224  if ( channelNr == 255 ) continue;
225  TSId = (tstrk->whNum()+3)<<16;
226  TSId += ( tstrk->whNum() < 0 ) ? 0x8FFFC : 0x7FFFC;
227 
228  *dataWord1 = ((channelNr&0xFF)<<24)
229  + 0x00FFFFFF;
230 
231  *dataWord2 = (TSId&0xFFFFC)<<12;
232 
233  if ( tstrk->TrkTag() == 0 ) {
234  *dataWord2 += 0x3F80
235  + ( tstrk->eta_packed()&0x003F)
236  + ((~tstrk->finehalo_packed()&0x0001)<<6);
237  }
238  else {
239  *dataWord2 += 0x007F
240  + ( ( tstrk->eta_packed()&0x003F)<<7)
241  + ((~tstrk->finehalo_packed()&0x0001)<<13);
242  }
243 
244  calcCRC(*dataWord1, *dataWord2, newCRC);
245  LineFED+=4;
246  *((int*)LineFED)=*dataWord2;
247  LineFED+=4;
248  *((int*)LineFED)=*dataWord1;
249  }
250  //Output
251 
252  //--> Trailer
253 
254  *dataWord1 = 0xA0000000
255  + (lines&0xFFFFFF);
256  *dataWord2 = 0;
257 
258  calcCRC(*dataWord1, *dataWord2&0xFFFF, newCRC);
259 
260  *dataWord2 += (newCRC&0xFFFF)<<16;
261 
262  LineFED+=4;
263  *((int*)LineFED)=*dataWord2;
264  LineFED+=4;
265  *((int*)LineFED)=*dataWord1;
266 
267  delete dataWord1;
268  delete dataWord2;
269  return true;
270 }
271 
272 int DTTFFEDSim::channel( int wheel, int sector, int bx ){
273 
274  // wheel : -3 -2 -1 +1 +2 +3 <=> PHTF's : N2, N1, N0, P0, P1, P2
275  // 0 <=> ETTF
276  // sector : 0 -> 11
277  // bx : -1 -> +1
278 
279  int myChannel = 255;
280 
281  if ( abs(bx) > 1) { return myChannel; }
282  if ( sector < 0 || sector > 11) { return myChannel; }
283  if ( abs(wheel) > 3) { return myChannel; }
284 
285  myChannel = sector*21 + wheel*3 - bx + 10 ;
286 
287  if (myChannel > 125) myChannel += 2;
288 
289  return myChannel;
290 }
291 
292 int DTTFFEDSim::bxNr( int channel ){
293 
294  int myChannel = channel;
295 
296  if (myChannel > 127) myChannel -= 2;
297 
298  if (myChannel < 0 || myChannel > 251 ){ return -999; }
299 
300  int myBx = 1-(myChannel%3);
301 
302  return myBx;
303 }
304 
305 int DTTFFEDSim::sector( int channel ){
306 
307  int myChannel = channel;
308 
309  if (myChannel > 127) myChannel -= 2;
310 
311  if (myChannel < 0 || myChannel > 251 ){ return -999; }
312 
313  return myChannel/21;
314 }
315 
316 int DTTFFEDSim::wheel( int channel ){
317 
318  int myChannel = channel;
319 
320  if (myChannel > 127) myChannel -= 2;
321 
322  if (myChannel < 0 || myChannel > 251 ){ return -999; }
323 
324  int myWheel = ((myChannel%21)/3)-3;
325 
326  return myWheel;
327 }
328 
329 void DTTFFEDSim::calcCRC(int myD1, int myD2, int &myC){
330 
331  int myCRC[16],D[64],C[16];
332 
333  for( int i=0; i < 32; i++ ){ D[i]=(myD2>>i)&0x1; }
334  for( int i=0; i < 32; i++ ){ D[i+32]=(myD1>>i)&0x1; }
335  for( int i=0; i < 16; i++ ){ C[i]=(myC>>i)&0x1; }
336 
337  myCRC[0] = ( D[63] + D[62] + D[61] + D[60] + D[55] + D[54] +
338  D[53] + D[52] + D[51] + D[50] + D[49] + D[48] +
339  D[47] + D[46] + D[45] + D[43] + D[41] + D[40] +
340  D[39] + D[38] + D[37] + D[36] + D[35] + D[34] +
341  D[33] + D[32] + D[31] + D[30] + D[27] + D[26] +
342  D[25] + D[24] + D[23] + D[22] + D[21] + D[20] +
343  D[19] + D[18] + D[17] + D[16] + D[15] + D[13] +
344  D[12] + D[11] + D[10] + D[9] + D[8] + D[7] +
345  D[6] + D[5] + D[4] + D[3] + D[2] + D[1] +
346  D[0] + C[0] + C[1] + C[2] + C[3] + C[4] +
347  C[5] + C[6] + C[7] + C[12] + C[13] + C[14] +
348  C[15] )%2;
349 
350  myCRC[1] = ( D[63] + D[62] + D[61] + D[56] + D[55] + D[54] +
351  D[53] + D[52] + D[51] + D[50] + D[49] + D[48] +
352  D[47] + D[46] + D[44] + D[42] + D[41] + D[40] +
353  D[39] + D[38] + D[37] + D[36] + D[35] + D[34] +
354  D[33] + D[32] + D[31] + D[28] + D[27] + D[26] +
355  D[25] + D[24] + D[23] + D[22] + D[21] + D[20] +
356  D[19] + D[18] + D[17] + D[16] + D[14] + D[13] +
357  D[12] + D[11] + D[10] + D[9] + D[8] + D[7] +
358  D[6] + D[5] + D[4] + D[3] + D[2] + D[1] +
359  C[0] + C[1] + C[2] + C[3] + C[4] + C[5] +
360  C[6] + C[7] + C[8] + C[13] + C[14] + C[15] )%2;
361 
362  myCRC[2] = ( D[61] + D[60] + D[57] + D[56] + D[46] + D[42] +
363  D[31] + D[30] + D[29] + D[28] + D[16] + D[14] +
364  D[1] + D[0] + C[8] + C[9] + C[12] + C[13] )%2;
365 
366  myCRC[3] = ( D[62] + D[61] + D[58] + D[57] + D[47] + D[43] +
367  D[32] + D[31] + D[30] + D[29] + D[17] + D[15] +
368  D[2] + D[1] + C[9] + C[10] + C[13] + C[14] )%2;
369 
370  myCRC[4] = ( D[63] + D[62] + D[59] + D[58] + D[48] + D[44] +
371  D[33] + D[32] + D[31] + D[30] + D[18] + D[16] +
372  D[3] + D[2] + C[0] + C[10] + C[11] + C[14] +
373  C[15] )%2;
374 
375  myCRC[5] = ( D[63] + D[60] + D[59] + D[49] + D[45] + D[34] +
376  D[33] + D[32] + D[31] + D[19] + D[17] + D[4] +
377  D[3] + C[1] + C[11] + C[12] + C[15] )%2;
378 
379  myCRC[6] = ( D[61] + D[60] + D[50] + D[46] + D[35] + D[34] +
380  D[33] + D[32] + D[20] + D[18] + D[5] + D[4] +
381  C[2] + C[12] + C[13] )%2;
382 
383  myCRC[7] = ( D[62] + D[61] + D[51] + D[47] + D[36] + D[35] +
384  D[34] + D[33] + D[21] + D[19] + D[6] + D[5] +
385  C[3] + C[13] + C[14] )%2;
386 
387  myCRC[8] = ( D[63] + D[62] + D[52] + D[48] + D[37] + D[36] +
388  D[35] + D[34] + D[22] + D[20] + D[7] + D[6] +
389  C[0] + C[4] + C[14] + C[15] )%2;
390 
391  myCRC[9] = ( D[63] + D[53] + D[49] + D[38] + D[37] + D[36] +
392  D[35] + D[23] + D[21] + D[8] + D[7] + C[1] +
393  C[5] + C[15] )%2;
394 
395  myCRC[10] = ( D[54] + D[50] + D[39] + D[38] + D[37] + D[36] +
396  D[24] + D[22] + D[9] + D[8] + C[2] + C[6] )%2;
397 
398  myCRC[11] = ( D[55] + D[51] + D[40] + D[39] + D[38] + D[37] +
399  D[25] + D[23] + D[10] + D[9] + C[3] + C[7] )%2;
400 
401  myCRC[12] = ( D[56] + D[52] + D[41] + D[40] + D[39] + D[38] +
402  D[26] + D[24] + D[11] + D[10] + C[4] + C[8] )%2;
403 
404  myCRC[13] = ( D[57] + D[53] + D[42] + D[41] + D[40] + D[39] +
405  D[27] + D[25] + D[12] + D[11] + C[5] + C[9] )%2;
406 
407  myCRC[14] = ( D[58] + D[54] + D[43] + D[42] + D[41] + D[40] +
408  D[28] + D[26] + D[13] + D[12] + C[6] + C[10] )%2;
409 
410  myCRC[15] = ( D[63] + D[62] + D[61] + D[60] + D[59] + D[54] +
411  D[53] + D[52] + D[51] + D[50] + D[49] + D[48] +
412  D[47] + D[46] + D[45] + D[44] + D[42] + D[40] +
413  D[39] + D[38] + D[37] + D[36] + D[35] + D[34] +
414  D[33] + D[32] + D[31] + D[30] + D[29] + D[26] +
415  D[25] + D[24] + D[23] + D[22] + D[21] + D[20] +
416  D[19] + D[18] + D[17] + D[16] + D[15] + D[14] +
417  D[12] + D[11] + D[10] + D[9] + D[8] + D[7] +
418  D[6] + D[5] + D[4] + D[3] + D[2] + D[1] +
419  D[0] + C[0] + C[1] + C[2] + C[3] + C[4] +
420  C[5] + C[6] + C[11] + C[12] + C[13] + C[14] +
421  C[15] )%2;
422 
423  int tempC = 0x0;
424  for(int i=0; i<16 ; i++){ tempC = tempC + (myCRC[i]<<i); }
425  myC = tempC ;
426  return;
427 }
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
edm::InputTag getDTPHTFInputTag()
Definition: DTTFFEDSim.h:62
virtual ~DTTFFEDSim()
Destructor.
Definition: DTTFFEDSim.cc:39
#define abs(x)
Definition: mlp_lapack.h:159
The_Container::const_iterator The_iterator
int sector(int channel)
Definition: DTTFFEDSim.cc:305
unsigned int eventNum
Definition: DTTFFEDSim.h:45
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
edm::InputTag DTDigiInputTag
Definition: DTTFFEDSim.h:47
void resize(size_t newsize)
Definition: FEDRawData.cc:33
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
int wheel(int channel)
Definition: DTTFFEDSim.cc:316
void calcCRC(int myD1, int myD2, int &myC)
Definition: DTTFFEDSim.cc:329
edm::InputTag getDTDigiInputTag()
Definition: DTTFFEDSim.h:61
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
Phi_Container::const_iterator Phi_iterator
int channel(int wheel, int sector, int bx)
Definition: DTTFFEDSim.cc:272
void produce(edm::Event &e, const edm::EventSetup &c)
Produce digis out of raw data.
Definition: DTTFFEDSim.cc:41
TrackContainer::const_iterator Trackiterator
bool fillRawData(edm::Event &e, FEDRawDataCollection &data)
Generate and fill FED raw data for a full event.
Definition: DTTFFEDSim.cc:53
int bxNr(int channel)
Definition: DTTFFEDSim.cc:292
edm::EventID id() const
Definition: EventBase.h:56
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
edm::InputTag DTPHTFInputTag
Definition: DTTFFEDSim.h:48
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
DTTFFEDSim(const edm::ParameterSet &pset)
Constructor.
Definition: DTTFFEDSim.cc:30