CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBSelectiveReadoutTask.cc
Go to the documentation of this file.
1 /*
2  * \file EBSelectiveReadoutTask.cc
3  *
4  * \author P. Gras
5  * \author E. Di Marco
6  *
7 */
8 
9 #include <iostream>
10 #include <fstream>
11 #include <vector>
12 #include <math.h>
13 #include <cassert>
14 
18 
20 
22 
25 
28 
30 
32 
33 
36 
37 
39 
40  init_ = false;
41 
43 
44  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
45 
46  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
47 
48  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
49 
50  // parameters...
51  EBDigiCollection_ = consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EBDigiCollection"));
52  EBSRFlagCollection_ = consumes<EBSrFlagCollection>(ps.getParameter<edm::InputTag>("EBSRFlagCollection"));
53  EcalTrigPrimDigiCollection_ = consumes<EcalTrigPrimDigiCollection>(ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollection"));
54  FEDRawDataCollection_ = consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("FEDRawDataCollection"));
55 
56  firstFIRSample_ = ps.getParameter<int>("ecalDccZs1stSample");
57 
58  useCondDb_ = ps.getParameter<bool>("configFromCondDB");
59 
60  if(!useCondDb_) configFirWeights(ps.getParameter<std::vector<double> >("dccWeights"));
61 
62 
63  // histograms...
64  EBTowerSize_ = 0;
65  EBTTFMismatch_ = 0;
66  EBDccEventSize_ = 0;
75  EBTTFlags_ = 0;
76  EBCompleteZSMap_ = 0;
78  EBDroppedFRMap_ = 0;
80  EBEventSize_ = 0;
85 
86  // initialize variable binning for DCC size...
87  float ZSthreshold = 0.608; // kBytes of 1 TT fully readout
88  float zeroBinSize = ZSthreshold / 20.;
89  for(int i=0; i<20; i++) ybins[i] = i*zeroBinSize;
90  for(int i=20; i<89; i++) ybins[i] = ZSthreshold * (i-19);
91  for(int i=0; i<=36; i++) xbins[i] = i+1;
92 
93 }
94 
96 
97 }
98 
100 
101  ievt_ = 0;
102 
103  if ( dqmStore_ ) {
104  dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
105  dqmStore_->rmdir(prefixME_ + "/EBSelectiveReadoutTask");
106  }
107 
108 }
109 
111 
112  Numbers::initGeometry(c, false);
113 
114  if ( ! mergeRuns_ ) this->reset();
115 
116  for(int ietindex = 0; ietindex < 34; ietindex++ ) {
117  for(int iptindex = 0; iptindex < 72; iptindex++ ) {
118  nEvtFullReadout[iptindex][ietindex] = 0;
119  nEvtZS1Readout[iptindex][ietindex] = 0;
120  nEvtZSReadout[iptindex][ietindex] = 0;
121  nEvtCompleteReadoutIfZS[iptindex][ietindex] = 0;
122  nEvtDroppedReadoutIfFR[iptindex][ietindex] = 0;
123  nEvtRUForced[iptindex][ietindex] = 0;
124  nEvtAnyReadout[iptindex][ietindex] = 0;
125  nEvtHighInterest[iptindex][ietindex] = 0;
126  nEvtMediumInterest[iptindex][ietindex] = 0;
127  nEvtLowInterest[iptindex][ietindex] = 0;
128  nEvtAnyInterest[iptindex][ietindex] = 0;
129  }
130  }
131 
132  //getting selective readout configuration
133  if(useCondDb_) {
135  c.get<EcalSRSettingsRcd>().get(hSr);
136  settings_ = hSr.product();
137  std::vector<double> wsFromDB;
138 
139  std::vector<std::vector<float> > dccs = settings_->dccNormalizedWeights_;
140  int nws = dccs.size();
141  if(nws == 1) {
142  for(std::vector<float>::const_iterator it = dccs[0].begin(); it != dccs[0].end(); it++) {
143  wsFromDB.push_back(*it);
144  }
145  }
146  else edm::LogWarning("EBSelectiveReadoutTask") << "DCC weight set is not exactly 1.";
147 
148  configFirWeights(wsFromDB);
149  }
150 
151 }
152 
154 
155 }
156 
158 
159  if ( EBTowerSize_ ) EBTowerSize_->Reset();
160 
162 
164 
166 
168 
170 
172 
174 
176 
178 
180 
181  if ( EBTTFlags_ ) EBTTFlags_->Reset();
182 
184 
186 
188 
190 
191  if ( EBEventSize_ ) EBEventSize_->Reset();
192 
194 
196 
198 
200 
201 }
202 
204 
205  init_ = true;
206 
208 
209  if ( dqmStore_ ) {
210 
211  dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
212 
213  name = "EBSRT tower event size";
214  EBTowerSize_ = dqmStore_->bookProfile2D(name, name, 72, 0, 72, 34, -17, 17, 100, 0, 200, "s");
215  EBTowerSize_->setAxisTitle("jphi", 1);
216  EBTowerSize_->setAxisTitle("jeta", 2);
217 
218  name = "EBSRT TT flag mismatch";
219  EBTTFMismatch_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
220  EBTTFMismatch_->setAxisTitle("jphi", 1);
221  EBTTFMismatch_->setAxisTitle("jeta", 2);
222 
223  name = "EBSRT DCC event size";
224  EBDccEventSize_ = dqmStore_->bookProfile(name, name, 36, 1, 37, 100, 0., 200., "s");
225  EBDccEventSize_->setAxisTitle("event size (kB)", 2);
226  for (int i = 0; i < 36; i++) {
228  }
229 
230  name = "EBSRT event size vs DCC";
231  EBDccEventSizeMap_ = dqmStore_->book2D(name, name, 36, xbins, 88, ybins);
232  EBDccEventSizeMap_->setAxisTitle("event size (kB)", 2);
233  for (int i = 0; i < 36; i++) {
235  }
236 
237  name = "EBSRT readout unit with SR forced";
238  EBReadoutUnitForcedBitMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
242 
243  name = "EBSRT full readout SR Flags";
244  EBFullReadoutSRFlagMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
248 
249  name = "EBSRT full readout SR Flags Number";
250  EBFullReadoutSRFlagCount_ = dqmStore_->book1D(name, name, 200, 0., 200.);
251  EBFullReadoutSRFlagCount_->setAxisTitle("Readout Units number", 1);
252 
253  name = "EBSRT zero suppression 1 SR Flags";
254  EBZeroSuppression1SRFlagMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
258 
259  name = "EBSRT high interest TT Flags";
260  EBHighInterestTriggerTowerFlagMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
264 
265  name = "EBSRT medium interest TT Flags";
266  EBMediumInterestTriggerTowerFlagMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
270 
271  name = "EBSRT low interest TT Flags";
272  EBLowInterestTriggerTowerFlagMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
276 
277  name = "EBSRT TT Flags";
278  EBTTFlags_ = dqmStore_->book1D(name, name, 8, 0., 8.);
279  EBTTFlags_->setAxisTitle("TT Flag value", 1);
280 
281  name = "EBSRT ZS Flagged Fully Readout";
282  EBCompleteZSMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
283  EBCompleteZSMap_->setAxisTitle("jphi", 1);
284  EBCompleteZSMap_->setAxisTitle("jeta", 2);
285  EBCompleteZSMap_->setAxisTitle("rate", 3);
286 
287  name = "EBSRT ZS Flagged Fully Readout Number";
288  EBCompleteZSCount_ = dqmStore_->book1D(name, name, 20, 0., 20.);
289  EBCompleteZSCount_->setAxisTitle("Readout Units number", 1);
290 
291  name = "EBSRT FR Flagged Dropped Readout";
292  EBDroppedFRMap_ = dqmStore_->book2D(name, name, 72, 0, 72, 34, -17, 17);
293  EBDroppedFRMap_->setAxisTitle("jphi", 1);
294  EBDroppedFRMap_->setAxisTitle("jeta", 2);
295  EBDroppedFRMap_->setAxisTitle("rate", 3);
296 
297  name = "EBSRT FR Flagged Dropped Readout Number";
298  EBDroppedFRCount_ = dqmStore_->book1D(name, name, 20, 0., 20.);
299  EBDroppedFRCount_->setAxisTitle("Readout Units number", 1);
300 
301  name = "EBSRT event size";
302  EBEventSize_ = dqmStore_->book1D(name, name, 100, 0, 200);
303  EBEventSize_->setAxisTitle("event size (kB)",1);
304 
305  name = "EBSRT high interest payload";
306  EBHighInterestPayload_ = dqmStore_->book1D(name, name, 100, 0, 200);
307  EBHighInterestPayload_->setAxisTitle("event size (kB)",1);
308 
309  name = "EBSRT low interest payload";
310  EBLowInterestPayload_ = dqmStore_->book1D(name, name, 100, 0, 200);
311  EBLowInterestPayload_->setAxisTitle("event size (kB)",1);
312 
313  name = "EBSRT high interest ZS filter output";
314  EBHighInterestZsFIR_ = dqmStore_->book1D(name, name, 60, -30, 30);
315  EBHighInterestZsFIR_->setAxisTitle("ADC counts*4",1);
316 
317  name = "EBSRT low interest ZS filter output";
318  EBLowInterestZsFIR_ = dqmStore_->book1D(name, name, 60, -30, 30);
319  EBLowInterestZsFIR_->setAxisTitle("ADC counts*4",1);
320 
321  }
322 
323 }
324 
326 
327  if ( ! init_ ) return;
328 
329  if ( dqmStore_ ) {
330 
331  dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
332 
334  EBTowerSize_ = 0;
335 
337  EBTTFMismatch_ = 0;
338 
340  EBDccEventSize_ = 0;
341 
343  EBDccEventSizeMap_ = 0;
344 
347 
350 
353 
356 
359 
362 
365 
367  EBTTFlags_ = 0;
368 
370  EBCompleteZSMap_ = 0;
371 
373  EBCompleteZSCount_ = 0;
374 
376  EBDroppedFRMap_ = 0;
377 
379  EBDroppedFRCount_ = 0;
380 
382  EBEventSize_ = 0;
383 
386 
389 
392 
395 
396  }
397 
398  init_ = false;
399 
400 }
401 
403 
404  edm::LogInfo("EBSelectiveReadoutTask") << "analyzed " << ievt_ << " events";
405 
406  if ( enableCleanup_ ) this->cleanup();
407 
408 }
409 
411 
412  if ( ! init_ ) this->setup();
413 
414  ievt_++;
415 
417  if ( e.getByToken(FEDRawDataCollection_, raw) ) {
418 
419  for ( int iDcc = 0; iDcc < nEBDcc; ++iDcc ) {
420 
421  EBDccEventSize_->Fill(iDcc+1, ((double)raw->FEDData(610+iDcc).size())/kByte );
422  EBDccEventSizeMap_->Fill(iDcc+1, ((double)raw->FEDData(610+iDcc).size())/kByte);
423 
424  }
425 
426  } else {
427  edm::LogWarning("EBSelectiveReadoutTask") << "FEDRawDataCollection not available";
428  }
429 
430  // Selective Readout Flags
431  int nFRO, nCompleteZS, nDroppedFRO;
432  nFRO = 0;
433  nCompleteZS = 0;
434  nDroppedFRO = 0;
436  if ( e.getByToken(EBSRFlagCollection_,ebSrFlags) ) {
437 
438  // Data Volume
439  double aLowInterest=0;
440  double aHighInterest=0;
441  double aAnyInterest=0;
442 
444  if ( e.getByToken(EBDigiCollection_ , ebDigis) ) {
445 
446  anaDigiInit();
447 
448  // channel status
449  edm::ESHandle<EcalChannelStatus> pChannelStatus;
450  c.get<EcalChannelStatusRcd>().get(pChannelStatus);
451  const EcalChannelStatus* chStatus = pChannelStatus.product();
452 
453  for (unsigned int digis=0; digis<ebDigis->size(); ++digis){
454  EBDataFrame ebdf = (*ebDigis)[digis];
455  EBDetId id = ebdf.id();
457  chit = chStatus->getMap().find(id.rawId());
458  uint16_t statusCode = 0;
459  if( chit != chStatus->getMap().end() ) {
460  EcalChannelStatusCode ch_code = (*chit);
461  statusCode = ch_code.getStatusCode();
462  }
463  anaDigi(ebdf, *ebSrFlags, statusCode);
464  }
465 
466  //low interest channels:
467  aLowInterest = nEbLI_*bytesPerCrystal/kByte;
468  EBLowInterestPayload_->Fill(aLowInterest);
469 
470  //low interest channels:
471  aHighInterest = nEbHI_*bytesPerCrystal/kByte;
472  EBHighInterestPayload_->Fill(aHighInterest);
473 
474  //any-interest channels:
475  aAnyInterest = getEbEventSize(nEb_)/kByte;
476  EBEventSize_->Fill(aAnyInterest);
477 
478  //event size by tower:
479  for(int ietindex = 0; ietindex < 34; ietindex++ ) {
480  for(int iptindex = 0; iptindex < 72; iptindex++ ) {
481 
482  float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
483  float xipt = iptindex + 0.5;
484 
485  double towerSize = nCryTower[iptindex][ietindex] * bytesPerCrystal;
486  EBTowerSize_->Fill(xipt, xiet, towerSize);
487 
488  }
489  }
490  } else {
491  edm::LogWarning("EBSelectiveReadoutTask") << "EBDigiCollection not available";
492  }
493 
494  // initialize dcchs_ to mask disabled towers
495  std::map< int, std::vector<short> > towersStatus;
497 
498  if( e.getByToken(FEDRawDataCollection_, dcchs) ) {
499  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
500  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
501  int ism = Numbers::iSM( *dcchItr, EcalBarrel );
502  towersStatus.insert(std::make_pair(ism, dcchItr->getFEStatus()));
503  }
504  }
505 
506  for ( EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it ) {
507 
508  EcalTrigTowerDetId id = it->id();
509 
510  if ( Numbers::subDet( id ) != EcalBarrel ) continue;
511 
512  int iet = id.ieta();
513  int ietindex = (iet>0) ? iet - 1 : 16 + std::abs(iet);
514  // phi_tower: change the range from global to SM-local
515  // phi==0 is in the middle of a SM
516  int ipt = id.iphi() + 2;
517  if ( ipt > 72 ) ipt = ipt - 72;
518  int iptindex = ipt - 1;
519  int ism = Numbers::iSM( id );
520  int itt = Numbers::iTT( id );
521 
522  nEvtAnyReadout[iptindex][ietindex]++;
523 
524  int flag = it->value() & ~EcalSrFlag::SRF_FORCED_MASK;
525 
526  int status=0;
527  if( towersStatus[ism].size() > 0 ) status = (towersStatus[ism])[itt];
528 
529  if(flag == EcalSrFlag::SRF_FULL) {
530  nEvtFullReadout[iptindex][ietindex]++;
531  nFRO++;
532  if(nPerRu_[ism-1][itt-1] == 0) {
533  if(status != 1) nEvtDroppedReadoutIfFR[iptindex][ietindex]++;
534  nDroppedFRO++;
535  }
536  }
537 
538  if(flag == EcalSrFlag::SRF_ZS1) nEvtZS1Readout[iptindex][ietindex]++;
539 
540  if(it->value() & EcalSrFlag::SRF_FORCED_MASK) nEvtRUForced[iptindex][ietindex]++;
541 
542  if(flag == EcalSrFlag::SRF_ZS1 || flag == EcalSrFlag::SRF_ZS2) {
543  nEvtZSReadout[iptindex][ietindex]++;
544  if(nPerRu_[ism-1][itt-1] == getCrystalCount()) {
545  if(status != 1) nEvtCompleteReadoutIfZS[iptindex][ietindex]++;
546  nCompleteZS++;
547  }
548  }
549 
550  }
551  } else {
552  edm::LogWarning("EBSelectiveReadoutTask") << "EBSRFlagCollection not available";
553  }
554 
555  for(int ietindex = 0; ietindex < 34; ietindex++ ) {
556  for(int iptindex = 0; iptindex < 72; iptindex++ ) {
557 
558  if(nEvtAnyReadout[iptindex][ietindex]) {
559 
560  float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
561  float xipt = iptindex + 0.5;
562 
563  float fraction = float(nEvtFullReadout[iptindex][ietindex]) / float(nEvtAnyReadout[iptindex][ietindex]);
564  float error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
565 
566  TH2F *h2d = EBFullReadoutSRFlagMap_->getTH2F();
567 
568  int binet=0, binpt=0;
569 
570  if ( h2d ) {
571  binpt = h2d->GetXaxis()->FindBin(xipt);
572  binet = h2d->GetYaxis()->FindBin(xiet);
573  }
574 
575  EBFullReadoutSRFlagMap_->setBinContent(binpt, binet, fraction);
576  EBFullReadoutSRFlagMap_->setBinError(binpt, binet, error);
577 
578 
579  fraction = float(nEvtZS1Readout[iptindex][ietindex]) / float(nEvtAnyReadout[iptindex][ietindex]);
580  error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
581 
583 
584  if ( h2d ) {
585  binpt = h2d->GetXaxis()->FindBin(xipt);
586  binet = h2d->GetYaxis()->FindBin(xiet);
587  }
588 
589  EBZeroSuppression1SRFlagMap_->setBinContent(binpt, binet, fraction);
590  EBZeroSuppression1SRFlagMap_->setBinError(binpt, binet, error);
591 
592 
593  fraction = float(nEvtRUForced[iptindex][ietindex]) / float(nEvtAnyReadout[iptindex][ietindex]);
594  error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
595 
597 
598  if ( h2d ) {
599  binpt = h2d->GetXaxis()->FindBin(xipt);
600  binet = h2d->GetYaxis()->FindBin(xiet);
601  }
602 
603  EBReadoutUnitForcedBitMap_->setBinContent(binpt, binet, fraction);
604  EBReadoutUnitForcedBitMap_->setBinError(binpt, binet, error);
605 
606  if( nEvtZSReadout[iptindex][ietindex] ) {
607  fraction = float(nEvtCompleteReadoutIfZS[iptindex][ietindex]) / float(nEvtZSReadout[iptindex][ietindex]);
608  error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
609 
610  h2d = EBCompleteZSMap_->getTH2F();
611 
612  if ( h2d ) {
613  binpt = h2d->GetXaxis()->FindBin(xipt);
614  binet = h2d->GetYaxis()->FindBin(xiet);
615  }
616 
617  EBCompleteZSMap_->setBinContent(binpt, binet, fraction);
618  EBCompleteZSMap_->setBinError(binpt, binet, error);
619  }
620 
621  if( nEvtFullReadout[iptindex][ietindex] ) {
622  fraction = float(nEvtDroppedReadoutIfFR[iptindex][ietindex]) / float(nEvtFullReadout[iptindex][ietindex]);
623  error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
624 
625  h2d = EBDroppedFRMap_->getTH2F();
626 
627  if ( h2d ) {
628  binpt = h2d->GetXaxis()->FindBin(xipt);
629  binet = h2d->GetYaxis()->FindBin(xiet);
630  }
631 
632  EBDroppedFRMap_->setBinContent(binpt, binet, fraction);
633  EBDroppedFRMap_->setBinError(binpt, binet, error);
634  }
635  }
636 
637  }
638  }
639 
641  EBCompleteZSCount_->Fill( nCompleteZS );
642  EBDroppedFRCount_->Fill( nDroppedFRO );
643 
645  if ( e.getByToken(EcalTrigPrimDigiCollection_, TPCollection) ) {
646 
647  // Trigger Primitives
649  for (TPdigi = TPCollection->begin(); TPdigi != TPCollection->end(); ++TPdigi ) {
650 
651  if ( Numbers::subDet( TPdigi->id() ) != EcalBarrel ) continue;
652 
653  int iet = TPdigi->id().ieta();
654  int ietindex = (iet>0) ? iet - 1 : 16 + std::abs(iet);
655  // phi_tower: change the range from global to SM-local
656  // phi==0 is in the middle of a SM
657  int ipt = TPdigi->id().iphi() + 2;
658  if ( ipt > 72 ) ipt = ipt - 72;
659  int iptindex = ipt - 1;
660 
661  nEvtAnyInterest[iptindex][ietindex]++;
662 
663  if ( (TPdigi->ttFlag() & 0x3) == 0 ) nEvtLowInterest[iptindex][ietindex]++;
664 
665  if ( (TPdigi->ttFlag() & 0x3) == 1 ) nEvtMediumInterest[iptindex][ietindex]++;
666 
667  if ( (TPdigi->ttFlag() & 0x3) == 3 ) nEvtHighInterest[iptindex][ietindex]++;
668 
669  EBTTFlags_->Fill( TPdigi->ttFlag() );
670 
671  float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
672  float xipt = iptindex + 0.5;
673 
674  if ( ((TPdigi->ttFlag() & 0x3) == 1 || (TPdigi->ttFlag() & 0x3) == 3)
675  && nCryTower[iptindex][ietindex] != 25 ) EBTTFMismatch_->Fill(xipt, xiet);
676 
677  }
678  } else {
679  edm::LogWarning("EBSelectiveReadoutTask") << "EcalTrigPrimDigiCollection not available";
680  }
681 
682  for(int ietindex = 0; ietindex < 34; ietindex++ ) {
683  for(int iptindex = 0; iptindex < 72; iptindex++ ) {
684 
685  if(nEvtAnyInterest[iptindex][ietindex]) {
686 
687  float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
688  float xipt = iptindex + 0.5;
689 
690  float fraction = float(nEvtHighInterest[iptindex][ietindex]) / float(nEvtAnyInterest[iptindex][ietindex]);
691  float error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[iptindex][ietindex]));
692 
694 
695  int binet=0, binpt=0;
696 
697  if ( h2d ) {
698  binpt = h2d->GetXaxis()->FindBin(xipt);
699  binet = h2d->GetYaxis()->FindBin(xiet);
700  }
701 
702  EBHighInterestTriggerTowerFlagMap_->setBinContent(binpt, binet, fraction);
703  EBHighInterestTriggerTowerFlagMap_->setBinError(binpt, binet, error);
704 
705 
706  fraction = float(nEvtMediumInterest[iptindex][ietindex]) / float(nEvtAnyInterest[iptindex][ietindex]);
707  error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[iptindex][ietindex]));
708 
710 
711  if ( h2d ) {
712  binpt = h2d->GetXaxis()->FindBin(xipt);
713  binet = h2d->GetYaxis()->FindBin(xiet);
714  }
715 
716  EBMediumInterestTriggerTowerFlagMap_->setBinContent(binpt, binet, fraction);
718 
719 
720  fraction = float(nEvtLowInterest[iptindex][ietindex]) / float(nEvtAnyInterest[iptindex][ietindex]);
721  error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[iptindex][ietindex]));
722 
724 
725  if ( h2d ) {
726  binpt = h2d->GetXaxis()->FindBin(xipt);
727  binet = h2d->GetYaxis()->FindBin(xiet);
728  }
729 
730  EBLowInterestTriggerTowerFlagMap_->setBinContent(binpt, binet, fraction);
731  EBLowInterestTriggerTowerFlagMap_->setBinError(binpt, binet, error);
732 
733  }
734 
735  }
736  }
737 
738 
739 }
740 
741 void EBSelectiveReadoutTask::anaDigi(const EBDataFrame& frame, const EBSrFlagCollection& srFlagColl, uint16_t statusCode){
742 
743  EBDetId id = frame.id();
744 
745  bool barrel = (id.subdetId()==EcalBarrel);
746 
747  if(barrel){
748  ++nEb_;
749 
750  int ieta = id.ieta();
751  int iphi = id.iphi();
752 
753  int iEta0 = iEta2cIndex(ieta);
754  int iPhi0 = iPhi2cIndex(iphi);
755  if(!ebRuActive_[iEta0/ebTtEdge][iPhi0/ebTtEdge]){
756  ++nRuPerDcc_[dccNum(id)-1];
757  ebRuActive_[iEta0/ebTtEdge][iPhi0/ebTtEdge] = true;
758  }
759 
760  EcalTrigTowerDetId towid = id.tower();
761  int iet = towid.ieta();
762  int ietindex = (iet>0) ? iet - 1 : 16 + std::abs(iet);
763  // phi_tower: change the range from global to SM-local
764  // phi==0 is in the middle of a SM
765  int ipt = towid.iphi() + 2;
766  if ( ipt > 72 ) ipt = ipt - 72;
767  int iptindex = ipt - 1;
768 
769  int ism = Numbers::iSM( id );
770  int itt = Numbers::iTT( towid );
771 
772  nCryTower[iptindex][ietindex]++;
773 
775 
776  if(srf == srFlagColl.end()){
777  return;
778  }
779 
780  bool highInterest = ((srf->value() & ~EcalSrFlag::SRF_FORCED_MASK)
782 
783 
784  int dccZsFIRval = dccZsFIR(frame, firWeights_, firstFIRSample_, 0);
785 
786  if(highInterest){
787  ++nEbHI_;
788  // if(statusCode != 9) EBHighInterestZsFIR_->Fill( dccZsFIRval );
789  EBHighInterestZsFIR_->Fill( dccZsFIRval );
790  } else{//low interest
791  ++nEbLI_;
792  // if(statusCode != 9) EBLowInterestZsFIR_->Fill( dccZsFIRval );
793  EBLowInterestZsFIR_->Fill( dccZsFIRval );
794  }
795  ++nPerDcc_[dccNum(id)-1];
796  ++nPerRu_[ism-1][itt-1];
797  }
798 
799 }
800 
802  nEb_ = 0;
803  nEbLI_ = 0;
804  nEbHI_ = 0;
805  bzero(nPerDcc_, sizeof(nPerDcc_));
806  bzero(nRuPerDcc_, sizeof(nRuPerDcc_));
807  bzero(ebRuActive_, sizeof(ebRuActive_));
808 
809  for(int idcc=0; idcc<nECALDcc; idcc++) {
810  for(int isc=0; isc<nDccChs; isc++) {
811  nPerRu_[idcc][isc] = 0;
812  }
813  }
814 
815  for(int ietindex = 0; ietindex < 34; ietindex++ ) {
816  for(int iptindex = 0; iptindex < 72; iptindex++ ) {
817  nCryTower[iptindex][ietindex] = 0;
818  }
819  }
820 
821 }
822 
825  return xtalId.tower();
826 }
827 
828 unsigned EBSelectiveReadoutTask::dccNum(const DetId& xtalId) const{
829  int j;
830  int k;
831 
832  if ( xtalId.det()!=DetId::Ecal ) {
833  throw cms::Exception("EBSelectiveReadoutTask") << "Crystal does not belong to ECAL";
834  }
835 
836  if(xtalId.subdetId()==EcalBarrel){
837  EBDetId ebDetId(xtalId);
838  j = iEta2cIndex(ebDetId.ieta());
839  k = iPhi2cIndex(ebDetId.iphi());
840  } else {
841  throw cms::Exception("EBSelectiveReadoutTask") << "Not ECAL barrel.";
842  }
843  int iDcc0 = dccIndex(j,k);
844  assert(iDcc0>=0 && iDcc0<nECALDcc);
845  return iDcc0+1;
846 }
847 
848 double EBSelectiveReadoutTask::getEbEventSize(double nReadXtals) const{
849  double ruHeaderPayload = 0.;
850  const int nEEDcc = 18;
851  const int firstEbDcc0 = nEEDcc/2;
852  for (int iDcc0 = firstEbDcc0; iDcc0 < firstEbDcc0 + nEBDcc; ++iDcc0 ) {
853  ruHeaderPayload += nRuPerDcc_[iDcc0]*8.;
854  }
855  return getDccOverhead(EB)*nEBDcc +
856  nReadXtals*bytesPerCrystal +
857  ruHeaderPayload;
858 }
859 
861  //iEta=i, iPhi=j
862  //phi edge of a SM is 4 TT
863  return j/4;
864 }
865 
866 int EBSelectiveReadoutTask::dccIndex(int i, int j) const {
867  //a SM is 85 crystal long:
868  int iEtaSM = i/85;
869  //a SM is 20 crystal wide:
870  int iPhiSM = j/20;
871  //DCC numbers start at 9 in the barrel and there 18 DCC/SM
872  return 9+18*iEtaSM+iPhiSM;
873 }
874 
875 //This implementation assumes that int is coded on at least 28-bits,
876 //which in pratice should be always true.
877 int
879  const std::vector<int>& firWeights,
880  int firstFIRSample,
881  bool* saturated){
882  const int nFIRTaps = 6;
883  //FIR filter weights:
884  const std::vector<int>& w = firWeights;
885 
886  //accumulator used to compute weighted sum of samples
887  int acc = 0;
888  bool gain12saturated = false;
889  const int gain12 = 0x01;
890 
891  int iWeight = 0;
892  for(int i = -1; i < nFIRTaps - 1; ++i, ++iWeight){
893  int iSample(i + firstFIRSample);
894  if(iSample>=0 && iSample < frame.size()){
895  EcalMGPASample sample(frame[iSample]);
896  if(sample.gainId()!=gain12) gain12saturated = true;
897  LogTrace("DccFir") << (iSample>=firstFIRSample?"+":"") << sample.adc()
898  << "*(" << w[iWeight] << ")";
899  acc+=sample.adc()*w[iWeight];
900  } else{
901  edm::LogWarning("DccFir") << __FILE__ << ":" << __LINE__ <<
902  ": Not enough samples in data frame or 'ecalDccZs1stSample' module "
903  "parameter is not valid...";
904  }
905  }
906  LogTrace("DccFir") << "\n";
907  //discards the 8 LSBs
908  //(shift operator cannot be used on negative numbers because
909  // the result depends on compilator implementation)
910  acc = (acc>=0)?(acc >> 8):-(-acc >> 8);
911  //ZS passed if weighted sum acc above ZS threshold or if
912  //one sample has a lower gain than gain 12 (that is gain 12 output
913  //is saturated)
914 
915  LogTrace("DccFir") << "acc: " << acc << "\n"
916  << "saturated: " << (gain12saturated?"yes":"no") << "\n";
917 
918  if(saturated){
919  *saturated = gain12saturated;
920  }
921 
922  return gain12saturated?std::numeric_limits<int>::max():acc;
923 }
924 
925 std::vector<int>
926 EBSelectiveReadoutTask::getFIRWeights(const std::vector<double>&
927  normalizedWeights){
928  const int nFIRTaps = 6;
929  std::vector<int> firWeights(nFIRTaps, 0); //default weight: 0;
930  const static int maxWeight = 0xEFF; //weights coded on 11+1 signed bits
931  for(unsigned i=0; i < std::min((size_t)nFIRTaps,normalizedWeights.size()); ++i){
932  firWeights[i] = lround(normalizedWeights[i] * (1<<10));
933  if(std::abs(firWeights[i])>maxWeight){//overflow
934  firWeights[i] = firWeights[i]<0?-maxWeight:maxWeight;
935  }
936  }
937  return firWeights;
938 }
939 
940 void
941 EBSelectiveReadoutTask::configFirWeights(const std::vector<double>& weightsForZsFIR){
942  bool notNormalized = false;
943  bool notInt = false;
944  for(unsigned i=0; i < weightsForZsFIR.size(); ++i){
945  if(weightsForZsFIR[i] > 1.) notNormalized = true;
946  if((int)weightsForZsFIR[i]!=weightsForZsFIR[i]) notInt = true;
947  }
948  if(notInt && notNormalized){
949  throw cms::Exception("InvalidParameter")
950  << "weigtsForZsFIR paramater values are not valid: they "
951  << "must either be integer and uses the hardware representation "
952  << "of the weights or less or equal than 1 and used the normalized "
953  << "representation.";
954  }
955  edm::LogInfo log("DccFir");
956  if(notNormalized){
957  firWeights_ = std::vector<int>(weightsForZsFIR.size());
958  for(unsigned i = 0; i< weightsForZsFIR.size(); ++i){
959  firWeights_[i] = (int)weightsForZsFIR[i];
960  }
961  } else{
962  firWeights_ = getFIRWeights(weightsForZsFIR);
963  }
964 
965  log << "Input weights for FIR: ";
966  for(unsigned i = 0; i < weightsForZsFIR.size(); ++i){
967  log << weightsForZsFIR[i] << "\t";
968  }
969 
970  double s2 = 0.;
971  log << "\nActual FIR weights: ";
972  for(unsigned i = 0; i < firWeights_.size(); ++i){
973  log << firWeights_[i] << "\t";
974  s2 += firWeights_[i]*firWeights_[i];
975  }
976 
977  s2 = sqrt(s2);
978  log << "\nNormalized FIR weights after hw representation rounding: ";
979  for(unsigned i = 0; i < firWeights_.size(); ++i){
980  log << firWeights_[i] / (double)(1<<10) << "\t";
981  }
982 
983  log <<"\nFirst FIR sample: " << firstFIRSample_;
984 }
985 
int nEvtLowInterest[72][34]
To store the events with low interest TT.
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
int i
Definition: DBlmapReader.cc:9
int nCryTower[72][34]
To store the readout crystals / tower.
MonitorElement * EBMediumInterestTriggerTowerFlagMap_
static const int bytesPerCrystal
Number of bytes per crystal.
void setBinContent(int binx, double content)
set content of bin (1-D)
static std::vector< int > getFIRWeights(const std::vector< double > &normalizedWeights)
MonitorElement * EBDccEventSizeMap_
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
key_type id() const
Definition: EBDataFrame.h:31
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2730
MonitorElement * EBLowInterestZsFIR_
static const int SRF_ZS2
Definition: EcalSrFlag.h:21
static const int ebTtEdge
Number of crystals along an EB TT.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
const self & getMap() const
Some &quot;id&quot; conversions.
edm::EDGetTokenT< EcalTrigPrimDigiCollection > EcalTrigPrimDigiCollection_
MonitorElement * EBFullReadoutSRFlagCount_
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:91
static const int SRF_FORCED_MASK
Definition: EcalSrFlag.h:29
double getDccOverhead(subdet_t subdet) const
int nEvtHighInterest[72][34]
To store the events with high interest TT.
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
std::vector< std::vector< float > > dccNormalizedWeights_
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
void configFirWeights(const std::vector< double > &weightsForZsFIR)
EcalTrigTowerDetId readOutUnitOf(const EBDetId &xtalId) const
int gainId() const
get the gainId (2 bits)
int nEvtZSReadout[72][34]
To store the events with ZS1 or ZS2 readout.
int size() const
Definition: EcalDataFrame.h:26
int ieta() const
get the tower ieta
int iPhi2cIndex(int iPhi) const
MonitorElement * EBFullReadoutSRFlagMap_
tuple s2
Definition: indexGen.py:106
void Fill(long long x)
int nEvtAnyInterest[72][34]
To store the events with any interest.
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
edm::EDGetTokenT< EBDigiCollection > EBDigiCollection_
MonitorElement * EBLowInterestPayload_
virtual ~EBSelectiveReadoutTask()
Destructor.
int nEvtFullReadout[72][34]
To store the events with full readout.
static int dccZsFIR(const EcalDataFrame &frame, const std::vector< int > &firWeights, int firstFIRSample, bool *saturated=0)
int nEvtZS1Readout[72][34]
To store the events with ZS1 readout.
int nEvtDroppedReadoutIfFR[72][34]
To store the events with 0 channels readout when FR is requested.
uint16_t getStatusCode() const
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:48
MonitorElement * EBCompleteZSCount_
void removeElement(const std::string &name)
Definition: DQMStore.cc:2772
MonitorElement * EBHighInterestPayload_
std::vector< int > firWeights_
static const int SRF_FULL
Definition: EcalSrFlag.h:24
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:59
const EcalSRSettings * settings_
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1186
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void beginJob(void)
BeginJob.
double getEbEventSize(double nReadXtals) const
int dccPhiIndexOfRU(int i, int j) const
#define LogTrace(id)
int nEvtCompleteReadoutIfZS[72][34]
To store the events with complete readout when ZS is requested.
static const int SRF_ZS1
Definition: EcalSrFlag.h:18
edm::EDGetTokenT< EBSrFlagCollection > EBSRFlagCollection_
int k[5][pyjets_maxn]
const_iterator end() const
MonitorElement * EBHighInterestTriggerTowerFlagMap_
Definition: DetId.h:18
int iphi() const
get the tower iphi
EBSelectiveReadoutTask(const edm::ParameterSet &ps)
Constructor.
int nEvtRUForced[72][34]
To store the events with RU forced.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
int nEvtMediumInterest[72][34]
To store the events with medium interest TT.
const T & get() const
Definition: EventSetup.h:55
int dccIndex(int i, int j) const
std::vector< Item >::const_iterator const_iterator
static const int nDccChs
maximum number of RUs read by a DCC
T const * product() const
Definition: ESHandle.h:62
bool ebRuActive_[nEbEta/ebTtEdge][nEbPhi/ebTtEdge]
int nPerRu_[nECALDcc][nDccChs]
MonitorElement * EBLowInterestTriggerTowerFlagMap_
MonitorElement * EBHighInterestZsFIR_
unsigned dccNum(const DetId &xtalId) const
iterator find(key_type k)
#define begin
Definition: vmac.h:30
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
MonitorElement * EBZeroSuppression1SRFlagMap_
const_iterator find(uint32_t rawId) const
MonitorElement * EBDroppedFRCount_
int nEvtAnyReadout[72][34]
To store the events with any readout.
const_iterator end() const
MonitorElement * EBReadoutUnitForcedBitMap_
T w() const
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:142
tuple status
Definition: ntuplemaker.py:245
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1000
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
int iEta2cIndex(int iEta) const
tuple size
Write out results.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
edm::EDGetTokenT< FEDRawDataCollection > FEDRawDataCollection_
void anaDigi(const EBDataFrame &frame, const EBSrFlagCollection &srFlagColl, uint16_t statusCode)
static unsigned iTT(const unsigned ism, const EcalSubdetector subdet, const unsigned i1, const unsigned i2)
Definition: Numbers.cc:482
Definition: Run.h:41
int adc() const
get the ADC sample (12 bits)
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1330