22 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1,
23 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 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}}};
44 digiProducer_ = params.
getParameter<
string>(
"unsuppressedDigiProducer");
47 srDigiProducer_ = params.
getParameter<
string>(
"srProducer");
52 tpProducer_ = params.
getParameter<
string>(
"trigPrimProducer");
68 if (writeMode ==
string(
"littleEndian")) {
69 writeMode_ = littleEndian;
70 }
else if (writeMode ==
string(
"bigEndian")) {
71 writeMode_ = bigEndian;
81 if (xtalVerbose_ | tpVerbose_) {
82 cout <<
"==================================================================" 84 <<
" Event " <<
iEvent <<
"\n" 85 <<
"------------------------------------------------------------------" 90 vector<uint16_t>
adc[nEbEta][nEbPhi];
91 getEbDigi(event, adc);
92 genFeData(basename_,
iEvent, adc);
96 int tcp[nTtEta][nTtPhi] = {{0}};
97 getTp(event, tcpDigiCollection_, tcp);
98 genTccIn(basename_,
iEvent, tcp);
102 int tp[nTtEta][nTtPhi] = {{0}};
103 getTp(event, tpDigiCollection_, tp);
104 genTccOut(basename_,
iEvent, tp);
108 int ebSrf[nTtEta][nTtPhi];
112 getSrfs(event, ebSrf, eeSrf);
113 genSrData(basename_,
iEvent, ebSrf);
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);
135 switch (writeMode_) {
137 char c = data & 0x00FF;
138 f.write(&c,
sizeof(c));
139 c = (data >> 8) & 0x00FF;
140 f.write(&c,
sizeof(c));
143 char c = (data >> 8) & 0x00FF;
144 f.write(&c,
sizeof(c));
146 f.write(&c,
sizeof(c));
149 f << ((iWord % 8 == 0 && iWord != 0) ?
"\n" :
"") <<
"0x" << setfill(
'0') << setw(4) << hex << data <<
"\t" <<
dec 157 switch (writeMode_) {
174 int chFrameLen = adcCount[0][0].size() + 1;
178 for (
int iZ0 = 0; iZ0 < 2; ++iZ0) {
179 for (
int iDccPhi0 = 0; iDccPhi0 < nDccInPhi; ++iDccPhi0) {
180 int iDcc1 = iDccPhi0 + iZ0 * nDccInPhi + nDccEndcap + 1;
182 if (dccNum_ != -1 && dccNum_ != iDcc1)
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));
194 if (writeMode_ == ascii) {
195 f << (iEvent == 1 ?
"" :
"\n") <<
"[Event:" << iEvent <<
"]\n";
198 for (
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
199 int iTtEta0 = iZ0 * nTtSmEta + iTtEtaInSm0;
200 for (
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
202 int iTtPhi0 = -nTtPhisPerEbDcc / 2 + iDccPhi0 * nTtPhisPerEbDcc + iTtPhiInSm0;
205 for (
int stripId1 = 1; stripId1 <= ttEdge; ++stripId1) {
206 uint16_t stripHeader =
207 0xF << 11 | (nPendingEvt & 0x3F) << 5 | (gmf & 0
x1) << 4 | (smf & 0x1) << 3 | (stripId1 & 0x7);
209 fwrite(f, stripHeader, iWord);
211 for (
int xtalId1 = 1; xtalId1 <= ttEdge; ++xtalId1) {
212 uint16_t crystalHeader = 1 << 14 | (chFrameLen & 0xFF) << 4 | (monitorFlag & 0x1) << 3 | (xtalId1 & 0x7);
214 fwrite(f, crystalHeader, iWord);
218 elec2GeomNum(iTtEta0, iTtPhi0, stripId1, xtalId1, iEta0, iPhi0);
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";
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;
234 fwrite(f, data, iWord);
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)
252 s << basename <<
"_ab2dcc" << setfill(
'0') << setw(2) << iDcc1 << setfill(
' ') << getExt();
253 ofstream
f(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
256 throw cms::Exception(
string(
"Cannot create/open file ") + s.str() +
".");
260 if (writeMode_ == ascii) {
261 f << (iEvent == 1 ?
"" :
"\n") <<
"[Event:" << iEvent <<
"]\n";
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 & 0
x1) << 12 | (le0 & 0x1) << 11 | (nFlags & 0x7F);
270 fwrite(f, data, iWord,
true);
275 for (
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
277 int iTtEta0 = nEeTtEta + iZ0 * nTtSmEta + iTtEtaInSm0;
278 for (
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
280 int iTtPhi0 = -nTtPhisPerEbDcc / 2 + iDccPhi0 * nTtPhisPerEbDcc + iTtPhiInSm0;
287 const int field = iFlag % 4;
292 data |= srf[iTtEta0][iTtPhi0] << (field * 3);
297 fwrite(f, data, iWord,
true);
308 for (
int iZ0 = 0; iZ0 < 2; ++iZ0) {
309 for (
int iTccPhi0 = 0; iTccPhi0 < nTccInPhi; ++iTccPhi0) {
310 int iTcc1 = iTccPhi0 + iZ0 * nTccInPhi + nTccEndcap + 1;
312 if (tccNum_ != -1 && tccNum_ != iTcc1)
317 const char *
ext =
".txt";
319 s << basename <<
"_tcc" << setfill(
'0') << setw(2) << iTcc1 << setfill(
' ') << ext;
320 ofstream fe2tcc(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
323 throw cms::Exception(
string(
"Failed to create file ") + s.str() +
".");
325 int memPos = iEvent - 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) {
331 int iTtPhi0 = -nTtPhisPerEbTcc / 2 + iTccPhi0 * nTtPhisPerEbTcc + iTtPhiInSm0;
332 iTtPhi0 += nTtPhisPerEbTcc * iTccPhi0;
335 uint16_t tp_fe2tcc = (tcp[iTtEta0][iTtPhi0] & 0x7ff);
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";
345 fe2tcc << iCh1 <<
"\t" << memPos <<
"\t" << setfill(
'0') << hex <<
"0x" << setw(4) << tp_fe2tcc <<
"\t" 346 <<
"0" <<
dec << setfill(
' ') <<
"\n";
350 fe2tcc << std::flush;
359 for (
int iZ0 = 0; iZ0 < 2; ++iZ0) {
360 for (
int iTccPhi0 = 0; iTccPhi0 < nTccInPhi; ++iTccPhi0) {
361 int iTcc1 = iTccPhi0 + iZ0 * nTccInPhi + nTccEndcap + 1;
363 if (tccNum_ != -1 && tccNum_ != iTcc1)
368 const char *
ext =
".txt";
370 s << basename <<
"_tcc" << setfill(
'0') << setw(2) << iTcc1 << setfill(
' ') << ext;
373 s << basename <<
"_tcc2dcc" << setfill(
'0') << setw(2) << iTcc1 << setfill(
' ') << getExt();
374 ofstream dccF(s.str().c_str(), (iEvent == 1 ? ios::ate : ios::app));
377 cout <<
"Warning: failed to create or open file " << s.str() <<
".\n";
381 const uint16_t h1 = 1;
382 const uint16_t le1 = 0;
383 const uint16_t le0 = 0;
385 const uint16_t nTts = 68;
386 const uint16_t
data =
387 (h1 & 0x1) << 14 | (le1 & 0
x1) << 12 | (le0 & 0x1) << 11 | (nSamples & 0xF) << 7 | (nTts & 0x7F);
388 dccF << (iEvent == 1 ?
"" :
"\n") <<
"[Event:" << iEvent <<
"]\n";
389 fwrite(dccF, data, iDccWord,
false);
391 int memPos = iEvent - 1;
393 for (
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0) {
394 int iTtEta0 = nEeTtEta + iZ0 * nTtSmEta + iTtEtaInSm0;
395 for (
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0) {
397 int iTtPhi0 = -nTtPhisPerEbTcc / 2 + iTccPhi0 * nTtPhisPerEbTcc + iTtPhiInSm0;
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";
409 fwrite(dccF, tps[iTtEta0][iTtPhi0], iDccWord,
false);
418 const int odd = 1 << 15;
423 const int p[16] = {even, odd, odd, even, odd, even, even, odd, odd, even, even, odd, even, odd, odd, even};
425 a ^= p[a & 0xF] ^ p[(a >> 4) & 0xF] ^ p[(a >> 8) & 0xF] ^ p[a >> 12 & 0xF] ^ odd;
429 int ebSrf[nTtEta][nTtPhi],
430 int eeSrf[
nEndcaps][nScX][nScY])
const {
433 event.getByLabel(srDigiProducer_, eeSrFlagCollection_, hEeSrFlags);
434 for (
size_t i = 0;
i < (
nEndcaps * nScX * nScY); ((
int *)eeSrf)[
i++] = -1) {
439 int iZ0 = flag.
id().
zside() > 0 ? 1 : 0;
440 int iX0 = flag.
id().
ix() - 1;
441 int iY0 = flag.
id().
iy() - 1;
443 assert(iX0 >= 0 && iX0 < nScX);
444 assert(iY0 >= 0 && iY0 < nScY);
445 eeSrf[iZ0][iX0][iY0] = flag.
value();
448 LogWarning(
"EcalSimRawData") <<
"EE SR flag not found (" 449 <<
"Product label: " << srDigiProducer_ <<
"Producet instance: " << eeSrFlagCollection_
455 event.getByLabel(srDigiProducer_, ebSrFlagCollection_, hEbSrFlags);
456 for (
size_t i = 0;
i < (nTtEta * nTtPhi); ((
int *)ebSrf)[
i++] = -1) {
461 int iEta = flag.
id().
ieta();
462 int iEta0 = iEta + nTtEta / 2 - (iEta >= 0 ? 1 : 0);
463 int iEbEta0 = iEta0 - nEeTtEta;
464 int iPhi0 = flag.
id().
iphi() - 1;
466 assert(iEbEta0 >= 0 && iEbEta0 < nEbTtEta);
467 assert(iPhi0 >= 0 && iPhi0 < nTtPhi);
469 ebSrf[iEbEta0][iPhi0] = flag.
value();
472 LogWarning(
"EcalSimRawData") <<
"EB SR flag not found (" 473 <<
"Product label: " << srDigiProducer_ <<
"Producet instance: " << ebSrFlagCollection_
480 event.getByLabel(digiProducer_, ebDigiCollection_, hEbDigis);
484 nSamples = hEbDigis->
begin()->size();
487 const uint16_t suppressed = 0xFFFF;
489 adc[0][0] = vector<uint16_t>(
nSamples, suppressed);
491 for (
int iEbEta = 0; iEbEta < nEbEta; ++iEbEta) {
492 for (
int iEbPhi = 0; iEbPhi < nEbPhi; ++iEbPhi) {
493 adc[iEbEta][iEbPhi] =
adc[0][0];
498 cout << setfill(
'0');
502 int iEta0 = iEta2cIndex((frame.
id()).
ieta());
503 int iPhi0 = iPhi2cIndex((frame.
id()).
iphi());
509 if (iEta0 < 0 || iEta0 >= nEbEta) {
510 cout <<
"iEta0 (= " << iEta0 <<
") is out of range (" 511 <<
"[0," << nEbEta - 1 <<
"])\n";
513 if (iPhi0 < 0 || iPhi0 >= nEbPhi) {
514 cout <<
"iPhi0 (= " << iPhi0 <<
") is out of range (" 515 <<
"[0," << nEbPhi - 1 <<
"])\n";
519 cout << iEta0 <<
"\t" << iPhi0 <<
":\t";
523 if (nSamples != frame.
size()) {
525 "Found EB digis with different sample count! This " 526 "is not supported by EcalSimRawData.");
529 for (
int iSample = 0; iSample <
nSamples; ++iSample) {
531 uint16_t encodedAdc = sample.
raw();
532 adc[iEta0][iPhi0][iSample] = encodedAdc;
534 cout << (iSample > 0 ?
" " :
"") <<
"0x" << setw(4) << encodedAdc;
541 cout << setfill(
' ');
547 event.getByLabel(tpProducer_, collName, hTpDigis);
552 for (
int iTtEta0 = 0; iTtEta0 < nTtEta; ++iTtEta0) {
553 for (
int iTtPhi0 = 0; iTtPhi0 < nTtPhi; ++iTtPhi0) {
554 tcp[iTtEta0][iTtPhi0] = tccInDefaultVal_;
558 cout << setfill(
'0');
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";
568 if (iTtPhi0 < 0 || iTtPhi0 >= nTtPhi) {
569 cout <<
"iTtPhi0 (= " << iTtPhi0 <<
") is out of range (" 570 <<
"[0," << nTtPhi - 1 <<
"])\n";
576 if (tcp[iTtEta0][iTtPhi0] != 0)
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";
583 cout << setfill(
' ');
void analyze(const edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< T >::const_iterator const_iterator
EcalMGPASample sample(int i) const
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
void setHParity(uint16_t &a) const
int ieta() const
get the tower ieta
static const int strip2Eta[nTtTypes][ttEdge]
void genFeData(std::string basename, int iEvent, const std::vector< uint16_t > adcCount[nEbEta][nEbPhi]) const
void getSrfs(const edm::Event &event, int ebSrf[nTtEta][nTtPhi], int eeSrf[nEndcaps][nScX][nScY]) const
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
EcalSimRawData(const edm::ParameterSet &pset)
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
int iphi() const
get the tower iphi
static const int nEndcaps
void genSrData(std::string basename, int iEvent, int ttf[nEbTtEta][nTtPhi]) const
const EcalTrigTowerDetId & id() const
T const * product() const
void getEbDigi(const edm::Event &event, std::vector< uint16_t > adc[nEbEta][nEbPhi]) const
void genTccIn(std::string basename, int iEvent, const int tps[nTtEta][nTtPhi]) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
const_iterator end() const
char data[epos_bytes_allocation]
const EcalScDetId & id() const override
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
static const int ttType[nEbTtEta]