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