CMS 3D CMS Logo

EcalSimRawData.cc
Go to the documentation of this file.
8 
9 #include <memory>
10 
13 #include <cmath>
14 #include <fstream> //used for debugging
15 #include <iomanip>
16 #include <iostream>
17 
18 using namespace std;
19 using namespace edm;
20 
21 const int EcalSimRawData::ttType[nEbTtEta] = {
22  0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, // EE-
23  0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 // EE+
24 };
25 
26 const int EcalSimRawData::stripCh2Phi[nTtTypes][ttEdge][ttEdge] = {
27  // TT type 0:
28  /*ch-->*/
29  {{4, 3, 2, 1, 0}, /*strip*/
30  {0, 1, 2, 3, 4}, /*|*/
31  {4, 3, 2, 1, 0}, /*|*/
32  {0, 1, 2, 3, 4}, /*|*/
33  {4, 3, 2, 1, 0}}, /*V*/
34  // TT type 1:
35  {{0, 1, 2, 3, 4}, {4, 3, 2, 1, 0}, {0, 1, 2, 3, 4}, {4, 3, 2, 1, 0}, {0, 1, 2, 3, 4}}};
36 
37 const int EcalSimRawData::strip2Eta[nTtTypes][ttEdge] = {
38  {4, 3, 2, 1, 0}, // TT type 0
39  {0, 1, 2, 3, 4} // TT type 1
40 };
41 
43  // sets up parameters:
44  digiProducer_ = params.getParameter<string>("unsuppressedDigiProducer");
45  ebDigiCollection_ = params.getParameter<std::string>("EBdigiCollection");
46  eeDigiCollection_ = params.getParameter<std::string>("EEdigiCollection");
47  srDigiProducer_ = params.getParameter<string>("srProducer");
48  ebSrFlagCollection_ = params.getParameter<std::string>("EBSrFlagCollection");
49  eeSrFlagCollection_ = params.getParameter<std::string>("EESrFlagCollection");
50  tpDigiCollection_ = params.getParameter<std::string>("trigPrimDigiCollection");
51  tcpDigiCollection_ = params.getParameter<std::string>("tcpDigiCollection");
52  tpProducer_ = params.getParameter<string>("trigPrimProducer");
53  xtalVerbose_ = params.getUntrackedParameter<bool>("xtalVerbose", false);
54  tpVerbose_ = params.getUntrackedParameter<bool>("tpVerbose", false);
55  tcc2dcc_ = params.getUntrackedParameter<bool>("tcc2dccData", true);
56  srp2dcc_ = params.getUntrackedParameter<bool>("srp2dccData", true);
57  fe2dcc_ = params.getUntrackedParameter<bool>("fe2dccData", true);
58  fe2tcc_ = params.getUntrackedParameter<bool>("fe2tccData", true);
59  dccNum_ = params.getUntrackedParameter<int>("dccNum", -1);
60  tccNum_ = params.getUntrackedParameter<int>("tccNum", -1);
61  tccInDefaultVal_ = params.getUntrackedParameter<int>("tccInDefaultVal", 0xffff);
62  basename_ = params.getUntrackedParameter<std::string>("outputBaseName");
63 
64  iEvent = 0;
65 
66  string writeMode = params.getParameter<string>("writeMode");
67 
68  if (writeMode == string("littleEndian")) {
69  writeMode_ = littleEndian;
70  } else if (writeMode == string("bigEndian")) {
71  writeMode_ = bigEndian;
72  } else {
73  writeMode_ = ascii;
74  }
75 }
76 
78  // Event counter:
79  ++iEvent;
80 
81  if (xtalVerbose_ | tpVerbose_) {
82  cout << "=================================================================="
83  "====\n"
84  << " Event " << iEvent << "\n"
85  << "------------------------------------------------------------------"
86  "----\n";
87  }
88 
89  if (fe2dcc_) {
90  vector<uint16_t> adc[nEbEta][nEbPhi];
91  getEbDigi(event, adc);
92  genFeData(basename_, iEvent, adc);
93  }
94 
95  if (fe2tcc_) {
96  int tcp[nTtEta][nTtPhi] = {{0}};
97  getTp(event, tcpDigiCollection_, tcp);
98  genTccIn(basename_, iEvent, tcp);
99  }
100 
101  if (tcc2dcc_) {
102  int tp[nTtEta][nTtPhi] = {{0}};
103  getTp(event, tpDigiCollection_, tp);
104  genTccOut(basename_, iEvent, tp);
105  }
106 
107  // SR flags:
108  int ebSrf[nTtEta][nTtPhi];
109  int eeSrf[nEndcaps][nScX][nScY];
110 
111  if (srp2dcc_) {
112  getSrfs(event, ebSrf, eeSrf);
113  genSrData(basename_, iEvent, ebSrf);
114  }
115 }
116 
117 void EcalSimRawData::elec2GeomNum(int ittEta0, int ittPhi0, int strip1, int ch1, int &iEta0, int &iPhi0) const {
118  assert(0 <= ittEta0 && ittEta0 < nEbTtEta);
119  assert(0 <= ittPhi0 && ittPhi0 < nTtPhi);
120  assert(1 <= strip1 && strip1 <= ttEdge);
121  assert(1 <= ch1 && ch1 <= ttEdge);
122  const int type = ttType[ittEta0];
123  iEta0 = ittEta0 * ttEdge + strip2Eta[type][strip1 - 1];
124  iPhi0 = ittPhi0 * ttEdge + stripCh2Phi[type][strip1 - 1][ch1 - 1];
125  assert(0 <= iEta0 && iEta0 < nEbEta);
126  assert(0 <= iPhi0 && iPhi0 < nEbPhi);
127 }
128 
129 void EcalSimRawData::fwrite(ofstream &f, uint16_t data, int &iWord, bool hpar) const {
130  if (hpar) {
131  // set horizontal odd parity bit:
132  setHParity(data);
133  }
134 
135  switch (writeMode_) {
136  case littleEndian: {
137  char c = data & 0x00FF;
138  f.write(&c, sizeof(c));
139  c = (data >> 8) & 0x00FF;
140  f.write(&c, sizeof(c));
141  } break;
142  case bigEndian: {
143  char c = (data >> 8) & 0x00FF;
144  f.write(&c, sizeof(c));
145  c = data & 0x00FF;
146  f.write(&c, sizeof(c));
147  } break;
148  case ascii:
149  f << ((iWord % 8 == 0 && iWord != 0) ? "\n" : "") << "0x" << setfill('0') << setw(4) << hex << data << "\t" << dec
150  << setfill(' ');
151  break;
152  }
153  ++iWord;
154 }
155 
156 string EcalSimRawData::getExt() const {
157  switch (writeMode_) {
158  case littleEndian:
159  return ".le";
160  case bigEndian:
161  return ".be";
162  case ascii:
163  return ".txt";
164  default:
165  return ".?";
166  }
167 }
168 
169 void EcalSimRawData::genFeData(string basename, int iEvent, const vector<uint16_t> adcCount[nEbEta][nEbPhi]) const {
170  int smf = 0;
171  int gmf = 0;
172  int nPendingEvt = 0;
173  int monitorFlag = 0;
174  int chFrameLen = adcCount[0][0].size() + 1;
175 
176  int iWord = 0;
177 
178  for (int iZ0 = 0; iZ0 < 2; ++iZ0) {
179  for (int iDccPhi0 = 0; iDccPhi0 < nDccInPhi; ++iDccPhi0) {
180  int iDcc1 = iDccPhi0 + iZ0 * nDccInPhi + nDccEndcap + 1;
181 
182  if (dccNum_ != -1 && dccNum_ != iDcc1)
183  continue;
184 
185  stringstream s;
186  s.str("");
187  const string &ext = getExt();
188  s << basename << "_fe2dcc" << setfill('0') << setw(2) << iDcc1 << setfill(' ') << ext;
189  ofstream f(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
190 
191  if (f.fail())
192  return;
193 
194  if (writeMode_ == ascii) {
195  f << (iEvent == 1 ? "" : "\n") << "[Event:" << iEvent << "]\n";
196  }
197 
198  for (int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
199  int iTtEta0 = iZ0 * nTtSmEta + iTtEtaInSm0;
200  for (int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
201  // phi=0deg at middle of 1st barrel DCC:
202  int iTtPhi0 = -nTtPhisPerEbDcc / 2 + iDccPhi0 * nTtPhisPerEbDcc + iTtPhiInSm0;
203  if (iTtPhi0 < 0)
204  iTtPhi0 += nTtPhi;
205  for (int stripId1 = 1; stripId1 <= ttEdge; ++stripId1) {
206  uint16_t stripHeader =
207  0xF << 11 | (nPendingEvt & 0x3F) << 5 | (gmf & 0x1) << 4 | (smf & 0x1) << 3 | (stripId1 & 0x7);
209  fwrite(f, stripHeader, iWord);
210 
211  for (int xtalId1 = 1; xtalId1 <= ttEdge; ++xtalId1) {
212  uint16_t crystalHeader = 1 << 14 | (chFrameLen & 0xFF) << 4 | (monitorFlag & 0x1) << 3 | (xtalId1 & 0x7);
213  // crystalHeader |=parity(crystalHeader) << 15;
214  fwrite(f, crystalHeader, iWord);
215 
216  int iEta0;
217  int iPhi0;
218  elec2GeomNum(iTtEta0, iTtPhi0, stripId1, xtalId1, iEta0, iPhi0);
219  if (xtalVerbose_) {
220  cout << dec << "iDcc1 = " << iDcc1 << "\t"
221  << "iEbTtEta0 = " << iTtEta0 << "\t"
222  << "iEbTtPhi0 = " << iTtPhi0 << "\t"
223  << "stripId1 = " << stripId1 << "\t"
224  << "xtalId1 = " << xtalId1 << "\t"
225  << "iEta0 = " << iEta0 << "\t"
226  << "iPhi0 = " << iPhi0 << "\t"
227  << "adc[5] = 0x" << hex << adcCount[iEta0][iPhi0][5] << dec << "\n";
228  }
229 
230  const vector<uint16_t> &adc = adcCount[iEta0][iPhi0];
231  for (unsigned iSample = 0; iSample < adc.size(); ++iSample) {
232  uint16_t data = adc[iSample] & 0x3FFF;
233  // data |= parity(data);
234  fwrite(f, data, iWord);
235  } // next time sample
236  } // next crystal in strip
237  } // next strip in TT
238  } // next TT along phi
239  } // next TT along eta
240  } // next DCC
241  } // next half-barrel
242 }
243 
244 void EcalSimRawData::genSrData(string basename, int iEvent, int srf[nEbTtEta][nTtPhi]) const {
245  for (int iZ0 = 0; iZ0 < 2; ++iZ0) {
246  for (int iDccPhi0 = 0; iDccPhi0 < nDccInPhi; ++iDccPhi0) {
247  int iDcc1 = iDccPhi0 + iZ0 * nDccInPhi + nDccEndcap + 1;
248  if (dccNum_ != -1 && dccNum_ != iDcc1)
249  continue;
250  stringstream s;
251  s.str("");
252  s << basename << "_ab2dcc" << setfill('0') << setw(2) << iDcc1 << setfill(' ') << getExt();
253  ofstream f(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
254 
255  if (f.fail())
256  throw cms::Exception(string("Cannot create/open file ") + s.str() + ".");
257 
258  int iWord = 0;
259 
260  if (writeMode_ == ascii) {
261  f << (iEvent == 1 ? "" : "\n") << "[Event:" << iEvent << "]\n";
262  }
263 
264  const uint16_t le1 = 0;
265  const uint16_t le0 = 0;
266  const uint16_t h1 = 1;
267  const uint16_t nFlags = 68;
268  uint16_t data = (h1 & 0x1) << 14 | (le1 & 0x1) << 12 | (le0 & 0x1) << 11 | (nFlags & 0x7F);
269 
270  fwrite(f, data, iWord, true);
271 
272  int iFlag = 0;
273  data = 0;
274 
275  for (int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
276  // int iTtEbEta0 = iZ0*nTtSmEta + iTtEtaInSm0;
277  int iTtEta0 = nEeTtEta + iZ0 * nTtSmEta + iTtEtaInSm0;
278  for (int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
279  // phi=0deg at middle of 1st barrel DCC:
280  int iTtPhi0 = -nTtPhisPerEbDcc / 2 + iDccPhi0 * nTtPhisPerEbDcc + iTtPhiInSm0;
281  if (iTtPhi0 < 0)
282  iTtPhi0 += nTtPhi;
283  // flags are packed by four:
284  //|15 |14 |13-12 |11 9|8 6|5 3|2 0|
285  //| P | 0 | X X | srf i+3| srf i+2| srf i+1| srf i |
286  //| | | | field 3 |field 2 | field 1| field 0|
287  const int field = iFlag % 4;
288  // cout << "TtEta0: " << iTtEta0 << "\tTtPhi0: " << iTtPhi0 << "\n";
289  // cout << "#" << oct << (int)srf[iTtEta0][iTtPhi0] << "o ****> #" <<
290  // oct << (srf[iTtEta0][iTtPhi0] << (field*3)) << "o\n" << dec;
291 
292  data |= srf[iTtEta0][iTtPhi0] << (field * 3);
293 
294  if (field == 3) {
295  // cout << srf[iTtEta0][iTtPhi0] << "----> 0x" << hex << data <<
296  // "\n";
297  fwrite(f, data, iWord, true);
298  data = 0;
299  }
300  ++iFlag;
301  } // next TT along phi
302  } // next TT along eta
303  } // next DCC
304  } // next half-barrel
305 }
306 
307 void EcalSimRawData::genTccIn(string basename, int iEvent, const int tcp[nTtEta][nTtPhi]) const {
308  for (int iZ0 = 0; iZ0 < 2; ++iZ0) {
309  for (int iTccPhi0 = 0; iTccPhi0 < nTccInPhi; ++iTccPhi0) {
310  int iTcc1 = iTccPhi0 + iZ0 * nTccInPhi + nTccEndcap + 1;
311 
312  if (tccNum_ != -1 && tccNum_ != iTcc1)
313  continue;
314 
315  stringstream s;
316  s.str("");
317  const char *ext = ".txt"; // only ascii mode supported for TCP
318 
319  s << basename << "_tcc" << setfill('0') << setw(2) << iTcc1 << setfill(' ') << ext;
320  ofstream fe2tcc(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
321 
322  if (fe2tcc.fail())
323  throw cms::Exception(string("Failed to create file ") + s.str() + ".");
324 
325  int memPos = iEvent - 1;
326  int iCh1 = 1;
327  for (int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
328  int iTtEta0 = (iZ0 == 0) ? 27 - iTtEtaInSm0 : 28 + iTtEtaInSm0;
329  for (int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
330  // phi=0deg at middle of 1st barrel DCC:
331  int iTtPhi0 = -nTtPhisPerEbTcc / 2 + iTccPhi0 * nTtPhisPerEbTcc + iTtPhiInSm0;
332  iTtPhi0 += nTtPhisPerEbTcc * iTccPhi0;
333  if (iTtPhi0 < 0)
334  iTtPhi0 += nTtPhi;
335  uint16_t tp_fe2tcc = (tcp[iTtEta0][iTtPhi0] & 0x7ff); // keep only Et (9:0) and FineGrain (10)
336 
337  if (tpVerbose_ && tp_fe2tcc != 0) {
338  cout << dec << "iTcc1 = " << iTcc1 << "\t"
339  << "iTtEta0 = " << iTtEta0 << "\t"
340  << "iTtPhi0 = " << iTtPhi0 << "\t"
341  << "iCh1 = " << iCh1 << "\t"
342  << "memPos = " << memPos << "\t"
343  << "tp = 0x" << setfill('0') << hex << setw(3) << tp_fe2tcc << dec << setfill(' ') << "\n";
344  }
345  fe2tcc << iCh1 << "\t" << memPos << "\t" << setfill('0') << hex << "0x" << setw(4) << tp_fe2tcc << "\t"
346  << "0" << dec << setfill(' ') << "\n";
347  ++iCh1;
348  } // next TT along phi
349  } // next TT along eta
350  fe2tcc << std::flush;
351  fe2tcc.close();
352  } // next TCC
353  } // next half-barrel
354 }
355 
356 void EcalSimRawData::genTccOut(string basename, int iEvent, const int tps[nTtEta][nTtPhi]) const {
357  int iDccWord = 0;
358 
359  for (int iZ0 = 0; iZ0 < 2; ++iZ0) {
360  for (int iTccPhi0 = 0; iTccPhi0 < nTccInPhi; ++iTccPhi0) {
361  int iTcc1 = iTccPhi0 + iZ0 * nTccInPhi + nTccEndcap + 1;
362 
363  if (tccNum_ != -1 && tccNum_ != iTcc1)
364  continue;
365 
366  stringstream s;
367  s.str("");
368  const char *ext = ".txt"; // only ascii mode supported for TCP
369 
370  s << basename << "_tcc" << setfill('0') << setw(2) << iTcc1 << setfill(' ') << ext;
371 
372  s.str("");
373  s << basename << "_tcc2dcc" << setfill('0') << setw(2) << iTcc1 << setfill(' ') << getExt();
374  ofstream dccF(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
375 
376  if (dccF.fail()) {
377  cout << "Warning: failed to create or open file " << s.str() << ".\n";
378  return;
379  }
380 
381  const uint16_t h1 = 1;
382  const uint16_t le1 = 0;
383  const uint16_t le0 = 0;
384  const uint16_t nSamples = 1;
385  const uint16_t nTts = 68;
386  const uint16_t data =
387  (h1 & 0x1) << 14 | (le1 & 0x1) << 12 | (le0 & 0x1) << 11 | (nSamples & 0xF) << 7 | (nTts & 0x7F);
388  dccF << (iEvent == 1 ? "" : "\n") << "[Event:" << iEvent << "]\n";
389  fwrite(dccF, data, iDccWord, false);
390 
391  int memPos = iEvent - 1;
392  int iCh1 = 1;
393  for (int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
394  int iTtEta0 = nEeTtEta + iZ0 * nTtSmEta + iTtEtaInSm0;
395  for (int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
396  // phi=0deg at middle of 1st barrel DCC:
397  int iTtPhi0 = -nTtPhisPerEbTcc / 2 + iTccPhi0 * nTtPhisPerEbTcc + iTtPhiInSm0;
398  if (iTtPhi0 < 0)
399  iTtPhi0 += nTtPhi;
400 
401  if (tpVerbose_) {
402  cout << dec << "iTcc1 = " << iTcc1 << "\t"
403  << "iTtEta0 = " << iTtEta0 << "\t"
404  << "iTtPhi0 = " << iTtPhi0 << "\t"
405  << "iCh1 = " << iCh1 << "\t"
406  << "memPos = " << memPos << "\t"
407  << "tp = 0x" << hex << tps[iTtEta0][iTtPhi0] << dec << "\n";
408  }
409  fwrite(dccF, tps[iTtEta0][iTtPhi0], iDccWord, false);
410  ++iCh1;
411  } // next TT along phi
412  } // next TT along eta
413  } // next TCC
414  } // next half-barrel
415 }
416 
417 void EcalSimRawData::setHParity(uint16_t &a) const {
418  const int odd = 1 << 15;
419  const int even = 0;
420  // parity bit of numbers from 0x0 to 0xF:
421  // 0 1 2 3 4 5 6 7 8 9 A B C
422  // D E F
423  const int p[16] = {even, odd, odd, even, odd, even, even, odd, odd, even, even, odd, even, odd, odd, even};
424  // inverts parity bit (LSB) of 'a' in case of even parity:
425  a ^= p[a & 0xF] ^ p[(a >> 4) & 0xF] ^ p[(a >> 8) & 0xF] ^ p[a >> 12 & 0xF] ^ odd;
426 }
427 
429  int ebSrf[nTtEta][nTtPhi],
430  int eeSrf[nEndcaps][nScX][nScY]) const {
431  // EE
433  event.getByLabel(srDigiProducer_, eeSrFlagCollection_, hEeSrFlags);
434  for (size_t i = 0; i < (nEndcaps * nScX * nScY); ((int *)eeSrf)[i++] = -1) {
435  };
436  if (hEeSrFlags.isValid()) {
437  for (EESrFlagCollection::const_iterator it = hEeSrFlags->begin(); it != hEeSrFlags->end(); ++it) {
438  const EESrFlag &flag = *it;
439  int iZ0 = flag.id().zside() > 0 ? 1 : 0;
440  int iX0 = flag.id().ix() - 1;
441  int iY0 = flag.id().iy() - 1;
442  assert(iZ0 >= 0 && iZ0 < nEndcaps);
443  assert(iX0 >= 0 && iX0 < nScX);
444  assert(iY0 >= 0 && iY0 < nScY);
445  eeSrf[iZ0][iX0][iY0] = flag.value();
446  }
447  } else {
448  LogWarning("EcalSimRawData") << "EE SR flag not found ("
449  << "Product label: " << srDigiProducer_ << "Producet instance: " << eeSrFlagCollection_
450  << ")";
451  }
452 
453  // EB
455  event.getByLabel(srDigiProducer_, ebSrFlagCollection_, hEbSrFlags);
456  for (size_t i = 0; i < (nTtEta * nTtPhi); ((int *)ebSrf)[i++] = -1) {
457  };
458  if (hEbSrFlags.isValid()) {
459  for (EBSrFlagCollection::const_iterator it = hEbSrFlags->begin(); it != hEbSrFlags->end(); ++it) {
460  const EBSrFlag &flag = *it;
461  int iEta = flag.id().ieta();
462  int iEta0 = iEta + nTtEta / 2 - (iEta >= 0 ? 1 : 0); // 0->55 from eta=-3 to eta=3
463  int iEbEta0 = iEta0 - nEeTtEta; // 0->33 from eta=-1.48 to eta=1.48
464  int iPhi0 = flag.id().iphi() - 1;
465 
466  assert(iEbEta0 >= 0 && iEbEta0 < nEbTtEta);
467  assert(iPhi0 >= 0 && iPhi0 < nTtPhi);
468 
469  ebSrf[iEbEta0][iPhi0] = flag.value();
470  }
471  } else {
472  LogWarning("EcalSimRawData") << "EB SR flag not found ("
473  << "Product label: " << srDigiProducer_ << "Producet instance: " << ebSrFlagCollection_
474  << ")";
475  }
476 }
477 
478 void EcalSimRawData::getEbDigi(const edm::Event &event, vector<uint16_t> adc[nEbEta][nEbPhi]) const {
480  event.getByLabel(digiProducer_, ebDigiCollection_, hEbDigis);
481 
482  int nSamples = 0;
483  if (hEbDigis.isValid() && !hEbDigis->empty()) { // there is at least one digi
484  nSamples = hEbDigis->begin()->size(); // gets the sample count from 1st digi
485  }
486 
487  const uint16_t suppressed = 0xFFFF;
488 
489  adc[0][0] = vector<uint16_t>(nSamples, suppressed);
490 
491  for (int iEbEta = 0; iEbEta < nEbEta; ++iEbEta) {
492  for (int iEbPhi = 0; iEbPhi < nEbPhi; ++iEbPhi) {
493  adc[iEbEta][iEbPhi] = adc[0][0];
494  }
495  }
496  if (hEbDigis.isValid()) {
497  if (xtalVerbose_)
498  cout << setfill('0');
499  for (EBDigiCollection::const_iterator it = hEbDigis->begin(); it != hEbDigis->end(); ++it) {
500  const EBDataFrame &frame = *it;
501 
502  int iEta0 = iEta2cIndex((frame.id()).ieta());
503  int iPhi0 = iPhi2cIndex((frame.id()).iphi());
504 
505  // cout << "xtl indices conv: (" << frame.id().ieta() << ","
506  // << frame.id().iphi() << ") -> ("
507  // << iEta0 << "," << iPhi0 << ")\n";
508 
509  if (iEta0 < 0 || iEta0 >= nEbEta) {
510  cout << "iEta0 (= " << iEta0 << ") is out of range ("
511  << "[0," << nEbEta - 1 << "])\n";
512  }
513  if (iPhi0 < 0 || iPhi0 >= nEbPhi) {
514  cout << "iPhi0 (= " << iPhi0 << ") is out of range ("
515  << "[0," << nEbPhi - 1 << "])\n";
516  }
517 
518  if (xtalVerbose_) {
519  cout << iEta0 << "\t" << iPhi0 << ":\t";
520  cout << hex;
521  }
522 
523  if (nSamples != frame.size()) {
524  throw cms::Exception("EcalSimRawData",
525  "Found EB digis with different sample count! This "
526  "is not supported by EcalSimRawData.");
527  }
528 
529  for (int iSample = 0; iSample < nSamples; ++iSample) {
530  const EcalMGPASample &sample = frame.sample(iSample);
531  uint16_t encodedAdc = sample.raw();
532  adc[iEta0][iPhi0][iSample] = encodedAdc;
533  if (xtalVerbose_) {
534  cout << (iSample > 0 ? " " : "") << "0x" << setw(4) << encodedAdc;
535  }
536  }
537  if (xtalVerbose_)
538  cout << "\n" << dec;
539  }
540  if (xtalVerbose_)
541  cout << setfill(' ');
542  }
543 }
544 
545 void EcalSimRawData::getTp(const edm::Event &event, const std::string &collName, int tcp[nTtEta][nTtPhi]) const {
547  event.getByLabel(tpProducer_, collName, hTpDigis);
548  if (hTpDigis.isValid() && !hTpDigis->empty()) {
549  const EcalTrigPrimDigiCollection &tpDigis = *hTpDigis.product();
550 
551  // EcalSelectiveReadout::ttFlag_t ttf[nTtEta][nTtPhi];
552  for (int iTtEta0 = 0; iTtEta0 < nTtEta; ++iTtEta0) {
553  for (int iTtPhi0 = 0; iTtPhi0 < nTtPhi; ++iTtPhi0) {
554  tcp[iTtEta0][iTtPhi0] = tccInDefaultVal_;
555  }
556  }
557  if (tpVerbose_) {
558  cout << setfill('0');
559  }
560  for (EcalTrigPrimDigiCollection::const_iterator it = tpDigis.begin(); it != tpDigis.end(); ++it) {
561  const EcalTriggerPrimitiveDigi &tp = *it;
562  int iTtEta0 = iTtEta2cIndex(tp.id().ieta());
563  int iTtPhi0 = iTtPhi2cIndex(tp.id().iphi());
564  if (iTtEta0 < 0 || iTtEta0 >= nTtEta) {
565  cout << "iTtEta0 (= " << iTtEta0 << ") is out of range ("
566  << "[0," << nEbTtEta - 1 << "])\n";
567  }
568  if (iTtPhi0 < 0 || iTtPhi0 >= nTtPhi) {
569  cout << "iTtPhi0 (= " << iTtPhi0 << ") is out of range ("
570  << "[0," << nTtPhi - 1 << "])\n";
571  }
572 
573  tcp[iTtEta0][iTtPhi0] = tp[tp.sampleOfInterest()].raw();
574 
575  if (tpVerbose_) {
576  if (tcp[iTtEta0][iTtPhi0] != 0) // print non-zero values only
577  cout << collName << (collName.empty() ? "" : " ") << "TP(" << setw(2) << iTtEta0 << "," << iTtPhi0 << ") = "
578  << "0x" << setw(4) << tcp[iTtEta0][iTtPhi0] << "\tcmssw indices: " << tp.id().ieta() << " "
579  << tp.id().iphi() << "\n";
580  }
581  } // next TP
582  if (tpVerbose_)
583  cout << setfill(' ');
584  }
585 }
void analyze(const edm::Event &, const edm::EventSetup &) override
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int value() const
Definition: EcalSrFlag.h:44
key_type id() const
Definition: EBDataFrame.h:31
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
std::vector< T >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
void getTp(const edm::Event &event, const std::string &collName, int tp[nTtEta][nTtPhi]) const
const_iterator begin() const
uint16_t raw() const
get the raw word
std::string getExt() const
int size() const
Definition: EcalDataFrame.h:26
void setHParity(uint16_t &a) const
int ieta() const
get the tower ieta
int iEvent
Definition: GenABIO.cc:224
static const int strip2Eta[nTtTypes][ttEdge]
void genFeData(std::string basename, int iEvent, const std::vector< uint16_t > adcCount[nEbEta][nEbPhi]) const
int ix() const
Definition: EcalScDetId.h:70
void getSrfs(const edm::Event &event, int ebSrf[nTtEta][nTtPhi], int eeSrf[nEndcaps][nScX][nScY]) const
double f[11][100]
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
EcalSimRawData(const edm::ParameterSet &pset)
bool isValid() const
Definition: HandleBase.h:74
constexpr size_t nSamples
int iy() const
Definition: EcalScDetId.h:76
void fwrite(std::ofstream &f, uint16_t data, int &iword, bool hpar=true) const
void genTccOut(std::string basename, int iEvent, const int tps[nTtEta][nTtPhi]) const
const_iterator end() const
const EcalTrigTowerDetId & id() const override
Definition: EBSrFlag.h:36
int iphi() const
get the tower iphi
static const int nEndcaps
Definition: GenABIO.cc:115
void genSrData(std::string basename, int iEvent, int ttf[nEbTtEta][nTtPhi]) const
const EcalTrigTowerDetId & id() const
T const * product() const
Definition: Handle.h:74
void getEbDigi(const edm::Event &event, std::vector< uint16_t > adc[nEbEta][nEbPhi]) const
int zside() const
Definition: EcalScDetId.h:64
void genTccIn(std::string basename, int iEvent, const int tps[nTtEta][nTtPhi]) const
const_iterator end() const
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
const EcalScDetId & id() const override
Definition: EESrFlag.h:37
Definition: memstream.h:15
static const int stripCh2Phi[nTtTypes][ttEdge][ttEdge]
int sampleOfInterest() const
Gets the interesting sample.
void elec2GeomNum(int ittEta0, int ittPhi0, int strip1, int ch1, int &iEta0, int &iPhi0) const
const_iterator begin() const
Definition: event.py:1
static const int ttType[nEbTtEta]