CMS 3D CMS Logo

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