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
49 digiProducer_ = params.
getParameter<
string>(
"unsuppressedDigiProducer");
52 srDigiProducer_ = params.
getParameter<
string>(
"srProducer");
58 tpProducer_ = params.
getParameter<
string>(
"trigPrimProducer");
74 if(writeMode==
string(
"littleEndian")){
75 writeMode_ = littleEndian;
76 }
else if(writeMode==
string(
"bigEndian")){
77 writeMode_ = bigEndian;
89 if(xtalVerbose_ | tpVerbose_){
90 cout <<
"======================================================================\n" 91 <<
" Event " <<
iEvent <<
"\n" 92 <<
"----------------------------------------------------------------------\n";
96 vector<uint16_t>
adc[nEbEta][nEbPhi];
97 getEbDigi(event, adc);
98 genFeData(basename_,
iEvent, adc);
102 int tcp[nTtEta][nTtPhi]={{0}};
103 getTp(event, tcpDigiCollection_, tcp);
104 genTccIn(basename_,
iEvent, tcp);
108 int tp[nTtEta][nTtPhi]={{0}};
109 getTp(event, tpDigiCollection_, tp);
110 genTccOut(basename_,
iEvent, tp);
114 int ebSrf[nTtEta][nTtPhi];
118 getSrfs(event, ebSrf, eeSrf);
119 genSrData(basename_,
iEvent, ebSrf);
125 int ch1,
int& iEta0,
int& iPhi0)
const{
126 assert(0<=ittEta0 && ittEta0<nEbTtEta);
127 assert(0<=ittPhi0 && ittPhi0<nTtPhi);
128 assert(1<=strip1&& strip1<=ttEdge);
129 assert(1<=ch1 && ch1<=ttEdge);
130 const int type = ttType[ittEta0];
131 iEta0 = ittEta0*ttEdge + strip2Eta[
type][strip1-1];
132 iPhi0 = ittPhi0*ttEdge + stripCh2Phi[
type][strip1-1][ch1-1];
133 assert(0<=iEta0 && iEta0<nEbEta);
134 assert(0<=iPhi0 && iPhi0<nEbPhi);
138 int& iWord,
bool hpar)
const{
148 char c = data & 0x00FF;
149 f.write(&c,
sizeof(c));
150 c = (data >>8) & 0x00FF;
151 f.write(&c,
sizeof(c));
156 char c = (data >>8) & 0x00FF;
157 f.write(&c,
sizeof(c));
159 f.write(&c,
sizeof(c));
163 f << ((iWord%8==0&&iWord!=0)?
"\n":
"")
164 <<
"0x" << setfill(
'0') << setw(4) << hex << data <<
"\t" 165 <<
dec << setfill(
' ');
185 const vector<uint16_t> adcCount[nEbEta][nEbPhi]
191 int chFrameLen = adcCount[0][0].size() + 1;
195 for(
int iZ0 = 0; iZ0<2; ++iZ0){
196 for(
int iDccPhi0 = 0; iDccPhi0<nDccInPhi; ++iDccPhi0){
197 int iDcc1 = iDccPhi0 + iZ0*nDccInPhi + nDccEndcap + 1;
199 if(dccNum_!=-1 && dccNum_!=iDcc1)
continue;
203 const string&
ext = getExt();
204 s << basename <<
"_fe2dcc" << setfill(
'0') << setw(2) << iDcc1
205 << setfill(
' ') << ext;
206 ofstream
f(s.str().c_str(), (iEvent==1?ios::ate:ios::app));
211 if(writeMode_==ascii){
212 f << (iEvent==1?
"":
"\n") <<
"[Event:" << iEvent <<
"]\n";
215 for(
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
216 int iTtEta0 = iZ0*nTtSmEta + iTtEtaInSm0;
217 for(
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
219 int iTtPhi0 = -nTtPhisPerEbDcc/2 + iDccPhi0*nTtPhisPerEbDcc
221 if(iTtPhi0<0) iTtPhi0 += nTtPhi;
222 for(
int stripId1 = 1; stripId1 <= ttEdge; ++stripId1){
223 uint16_t stripHeader =
225 | (nPendingEvt & 0x3F) << 5
230 fwrite(f,stripHeader, iWord);
232 for(
int xtalId1 = 1; xtalId1 <= ttEdge; ++xtalId1){
234 uint16_t crystalHeader =
236 | (chFrameLen & 0xFF) <<4
237 | (monitorFlag & 0x1) <<3
240 fwrite(f, crystalHeader, iWord);
244 elec2GeomNum(iTtEta0, iTtPhi0, stripId1, xtalId1,
248 <<
"iDcc1 = " << iDcc1 <<
"\t" 249 <<
"iEbTtEta0 = " << iTtEta0 <<
"\t" 250 <<
"iEbTtPhi0 = " << iTtPhi0 <<
"\t" 251 <<
"stripId1 = " << stripId1 <<
"\t" 252 <<
"xtalId1 = " << xtalId1 <<
"\t" 253 <<
"iEta0 = " << iEta0 <<
"\t" 254 <<
"iPhi0 = " << iPhi0 <<
"\t" 255 <<
"adc[5] = 0x" << hex << adcCount[iEta0][iPhi0][5]
260 const vector<uint16_t>&
adc = adcCount[iEta0][iPhi0];
261 for(
unsigned iSample=0; iSample < adc.size(); ++iSample){
262 uint16_t
data = adc[iSample] & 0x3FFF;
264 fwrite(f, data, iWord);
275 int srf[nEbTtEta][nTtPhi])
const{
276 for(
int iZ0 = 0; iZ0<2; ++iZ0){
277 for(
int iDccPhi0 = 0; iDccPhi0<nDccInPhi; ++iDccPhi0){
278 int iDcc1 = iDccPhi0 + iZ0*nDccInPhi + nDccEndcap + 1;
279 if(dccNum_!=-1 && dccNum_!=iDcc1)
continue;
282 s << basename <<
"_ab2dcc" << setfill(
'0') << setw(2) << iDcc1
283 << setfill(
' ') << getExt();
284 ofstream
f(s.str().c_str(), (iEvent==1?ios::ate:ios::app));
286 if(f.fail())
throw cms::Exception(
string(
"Cannot create/open file ")
291 if(writeMode_==ascii){
292 f << (iEvent==1?
"":
"\n")<<
"[Event:" << iEvent <<
"]\n";
295 const uint16_t le1 = 0;
296 const uint16_t le0 = 0;
297 const uint16_t h1 = 1;
298 const uint16_t nFlags = 68;
299 uint16_t
data = (h1 & 0x1)<< 14
304 fwrite(f, data, iWord,
true);
309 for(
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
311 int iTtEta0 = nEeTtEta + iZ0*nTtSmEta + iTtEtaInSm0;
312 for(
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
314 int iTtPhi0 = -nTtPhisPerEbDcc/2 + iDccPhi0*nTtPhisPerEbDcc
316 if(iTtPhi0<0) iTtPhi0 += nTtPhi;
321 const int field = iFlag%4;
325 data |= srf[iTtEta0][iTtPhi0] << (field*3);
329 fwrite(f, data, iWord,
true);
341 const int tcp[nTtEta][nTtPhi])
const{
342 for(
int iZ0 = 0; iZ0<2; ++iZ0){
343 for(
int iTccPhi0 = 0; iTccPhi0<nTccInPhi; ++iTccPhi0){
344 int iTcc1 = iTccPhi0 + iZ0*nTccInPhi + nTccEndcap + 1;
346 if(tccNum_!=-1 && tccNum_!=iTcc1)
continue;
350 const char*
ext =
".txt";
352 s << basename <<
"_tcc" << setfill(
'0') << setw(2) << iTcc1
353 << setfill(
' ') << ext;
354 ofstream fe2tcc(s.str().c_str(), (iEvent==1?ios::ate:ios::app));
356 if(fe2tcc.fail())
throw cms::Exception(
string(
"Failed to create file ")
359 int memPos = iEvent-1;
361 for(
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
362 int iTtEta0 = (iZ0==0) ? 27 - iTtEtaInSm0 : 28 + iTtEtaInSm0;
363 for(
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
365 int iTtPhi0 = -nTtPhisPerEbTcc/2 + iTccPhi0*nTtPhisPerEbTcc
367 iTtPhi0 += nTtPhisPerEbTcc*iTccPhi0;
368 if(iTtPhi0<0) iTtPhi0 += nTtPhi;
369 uint16_t tp_fe2tcc = (tcp[iTtEta0][iTtPhi0] & 0x7ff) ;
371 if(tpVerbose_ && tp_fe2tcc!=0){
373 <<
"iTcc1 = " << iTcc1 <<
"\t" 374 <<
"iTtEta0 = " << iTtEta0 <<
"\t" 375 <<
"iTtPhi0 = " << iTtPhi0 <<
"\t" 376 <<
"iCh1 = " << iCh1 <<
"\t" 377 <<
"memPos = " << memPos <<
"\t" 378 <<
"tp = 0x" << setfill(
'0') << hex << setw(3)
380 <<
dec << setfill(
' ') <<
"\n";
382 fe2tcc << iCh1 <<
"\t" 384 << setfill(
'0') << hex
385 <<
"0x" << setw(4) << tp_fe2tcc <<
"\t" 387 <<
dec << setfill(
' ') <<
"\n";
391 fe2tcc << std::flush;
399 const int tps[nTtEta][nTtPhi])
const{
402 for(
int iZ0 = 0; iZ0<2; ++iZ0){
403 for(
int iTccPhi0 = 0; iTccPhi0<nTccInPhi; ++iTccPhi0){
404 int iTcc1 = iTccPhi0 + iZ0*nTccInPhi + nTccEndcap + 1;
406 if(tccNum_!=-1 && tccNum_!=iTcc1)
continue;
410 const char*
ext =
".txt";
412 s << basename <<
"_tcc" << setfill(
'0') << setw(2) << iTcc1
413 << setfill(
' ') << ext;
416 s << basename <<
"_tcc2dcc" << setfill(
'0') << setw(2) << iTcc1
417 << setfill(
' ') << getExt();
418 ofstream dccF(s.str().c_str(), (iEvent==1?ios::ate:ios::app));
421 cout <<
"Warning: failed to create or open file " << s.str() <<
".\n";
425 const uint16_t h1 = 1;
426 const uint16_t le1 = 0;
427 const uint16_t le0 = 0;
429 const uint16_t nTts = 68;
430 const uint16_t
data = (h1 & 0x1) << 14
433 | (nSamples & 0xF) << 7
435 dccF << (iEvent==1?
"":
"\n") <<
"[Event:" << iEvent <<
"]\n";
436 fwrite(dccF, data, iDccWord,
false);
438 int memPos = iEvent-1;
440 for(
int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
441 int iTtEta0 = nEeTtEta + iZ0*nTtSmEta + iTtEtaInSm0;
442 for(
int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
444 int iTtPhi0 = -nTtPhisPerEbTcc/2 + iTccPhi0*nTtPhisPerEbTcc
446 if(iTtPhi0<0) iTtPhi0 += nTtPhi;
450 <<
"iTcc1 = " << iTcc1 <<
"\t" 451 <<
"iTtEta0 = " << iTtEta0 <<
"\t" 452 <<
"iTtPhi0 = " << iTtPhi0 <<
"\t" 453 <<
"iCh1 = " << iCh1 <<
"\t" 454 <<
"memPos = " << memPos <<
"\t" 455 <<
"tp = 0x" << hex << tps[iTtEta0][iTtPhi0]
458 fwrite(dccF, tps[iTtEta0][iTtPhi0], iDccWord,
false);
468 const int odd = 1 <<15;
472 const int p[16] = {even,odd,odd,even,odd,even,even,odd,odd,even,even,odd,even,odd,odd,even};
474 a ^= p[a&0xF] ^ p[(a>>4)&0xF] ^ p[(a>>8)&0xF] ^ p[a>>12&0xF] ^ odd;
478 int ebSrf[nTtEta][nTtPhi],
479 int eeSrf[
nEndcaps][nScX][nScY])
const{
483 event.getByLabel(srDigiProducer_, eeSrFlagCollection_, hEeSrFlags);
484 for(
size_t i=0;
i < (
nEndcaps*nScX*nScY); ((
int*)eeSrf)[
i++] = -1){};
487 it != hEeSrFlags->
end(); ++it){
489 int iZ0 = flag.
id().
zside()>0?1:0;
490 int iX0 = flag.
id().
ix()-1;
491 int iY0 = flag.
id().
iy()-1;
493 assert(iX0>=0 && iX0<nScX);
494 assert(iY0>=0 && iY0<nScY);
495 eeSrf[iZ0][iX0][iY0] = flag.
value();
498 LogWarning(
"EcalSimRawData") <<
"EE SR flag not found (" 499 <<
"Product label: " << srDigiProducer_
500 <<
"Producet instance: " 501 << eeSrFlagCollection_ <<
")";
506 event.getByLabel(srDigiProducer_, ebSrFlagCollection_, hEbSrFlags);
507 for(
size_t i=0;
i<(nTtEta*nTtPhi); ((
int*)ebSrf)[
i++] = -1){};
510 it != hEbSrFlags->
end(); ++it){
513 int iEta = flag.
id().
ieta();
514 int iEta0 = iEta + nTtEta/2 - (iEta>=0?1:0);
515 int iEbEta0 = iEta0 - nEeTtEta;
516 int iPhi0 = flag.
id().
iphi() - 1;
518 assert(iEbEta0>=0 && iEbEta0<nEbTtEta);
519 assert(iPhi0>=0 && iPhi0<nTtPhi);
521 ebSrf[iEbEta0][iPhi0] = flag.
value();
524 LogWarning(
"EcalSimRawData") <<
"EB SR flag not found (" 525 <<
"Product label: " << srDigiProducer_
526 <<
"Producet instance: " 527 << ebSrFlagCollection_ <<
")";
532 vector<uint16_t>
adc[nEbEta][nEbPhi])
const{
535 event.getByLabel(digiProducer_, ebDigiCollection_, hEbDigis);
539 nSamples = hEbDigis->
begin()->size();
543 const uint16_t suppressed = 0xFFFF;
545 adc[0][0] = vector<uint16_t>(
nSamples, suppressed);
547 for(
int iEbEta=0; iEbEta<nEbEta; ++iEbEta){
548 for(
int iEbPhi=0; iEbPhi<nEbPhi; ++iEbPhi){
549 adc[iEbEta][iEbPhi] =
adc[0][0];
553 if(xtalVerbose_)
cout << setfill(
'0');
555 it != hEbDigis->
end(); ++it){
558 int iEta0 = iEta2cIndex((frame.
id()).ieta());
559 int iPhi0 = iPhi2cIndex((frame.
id()).iphi());
565 if(iEta0<0 || iEta0>=nEbEta){
566 cout <<
"iEta0 (= " << iEta0 <<
") is out of range (" 567 <<
"[0," << nEbEta -1 <<
"])\n";
569 if(iPhi0<0 || iPhi0>=nEbPhi){
570 cout <<
"iPhi0 (= " << iPhi0 <<
") is out of range (" 571 <<
"[0," << nEbPhi -1 <<
"])\n";
575 cout << iEta0 <<
"\t" << iPhi0 <<
":\t";
579 if(nSamples!=frame.
size()){
580 throw cms::Exception(
"EcalSimRawData",
"Found EB digis with different sample count! This is not supported by EcalSimRawData.");
583 for(
int iSample=0; iSample<
nSamples; ++iSample){
585 uint16_t encodedAdc = sample.
raw();
586 adc[iEta0][iPhi0][iSample] = encodedAdc;
588 cout << (iSample>0?
" ":
"") <<
"0x" << setw(4)
592 if(xtalVerbose_)
cout <<
"\n" <<
dec;
594 if(xtalVerbose_)
cout << setfill(
' ');
601 int tcp[nTtEta][nTtPhi])
const{
603 event.getByLabel(tpProducer_, collName, hTpDigis);
608 for(
int iTtEta0=0; iTtEta0 < nTtEta; ++iTtEta0){
609 for(
int iTtPhi0=0; iTtPhi0 < nTtPhi; ++iTtPhi0){
610 tcp[iTtEta0][iTtPhi0] = tccInDefaultVal_ ;
614 cout << setfill(
'0');
617 it != tpDigis.
end(); ++it){
619 int iTtEta0 = iTtEta2cIndex(tp.
id().
ieta());
620 int iTtPhi0 = iTtPhi2cIndex(tp.
id().
iphi());
621 if(iTtEta0<0 || iTtEta0>=nTtEta){
622 cout <<
"iTtEta0 (= " << iTtEta0 <<
") is out of range (" 623 <<
"[0," << nEbTtEta -1 <<
"])\n";
625 if(iTtPhi0<0 || iTtPhi0>=nTtPhi){
626 cout <<
"iTtPhi0 (= " << iTtPhi0 <<
") is out of range (" 627 <<
"[0," << nTtPhi -1 <<
"])\n";
633 if(tcp[iTtEta0][iTtPhi0]!=0)
634 cout << collName << (collName.size()==0?
"":
" ")
635 <<
"TP(" << setw(2) << iTtEta0 <<
"," << iTtPhi0 <<
") = " 637 << tcp[iTtEta0][iTtPhi0]
638 <<
"\tcmssw indices: " 642 if(tpVerbose_)
cout << setfill(
' ');
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
std::vector< EESrFlag >::const_iterator const_iterator
virtual void analyze(const edm::Event &, const edm::EventSetup &)
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
EcalSimRawData(const edm::ParameterSet &pset)
constexpr size_t nSamples
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
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
const EcalScDetId & id() 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
const EcalTrigTowerDetId & id() const
const_iterator end() const
char data[epos_bytes_allocation]
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]