CMS 3D CMS Logo

EcalMixingModuleValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalMixingModuleValidation.cc
3  *
4  * \author F. Cossutti
5  *
6 */
7 
18 
20  HepMCToken_( consumes<edm::HepMCProduct>( edm::InputTag( ps.getParameter<std::string>( "moduleLabelMC" ) ) ) ),
21  EBdigiCollectionToken_( consumes<EBDigiCollection>( ps.getParameter<edm::InputTag>( "EBdigiCollection" ) ) ),
22  EEdigiCollectionToken_( consumes<EEDigiCollection>( ps.getParameter<edm::InputTag>( "EEdigiCollection" ) ) ),
23  ESdigiCollectionToken_( consumes<ESDigiCollection>( ps.getParameter<edm::InputTag>( "ESdigiCollection" ) ) ),
24  crossingFramePCaloHitEBToken_( consumes< CrossingFrame<PCaloHit> >( edm::InputTag( std::string( "mix" )
25  , ps.getParameter<std::string>( "hitsProducer" ) + std::string( "EcalHitsEB" )
26  )
27  )
28  ),
29  crossingFramePCaloHitEEToken_( consumes< CrossingFrame<PCaloHit> >( edm::InputTag( std::string( "mix" )
30  , ps.getParameter<std::string>( "hitsProducer" ) + std::string( "EcalHitsEE" )
31  )
32  )
33  ),
34  crossingFramePCaloHitESToken_( consumes< CrossingFrame<PCaloHit> >( edm::InputTag( std::string( "mix" )
35  , ps.getParameter<std::string>( "hitsProducer" ) + std::string( "EcalHitsES" )
36  )
37  )
38  ) {
39 
40 
41  // needed for MixingModule checks
42 
43  double simHitToPhotoelectronsBarrel = ps.getParameter<double>("simHitToPhotoelectronsBarrel");
44  double simHitToPhotoelectronsEndcap = ps.getParameter<double>("simHitToPhotoelectronsEndcap");
45  double photoelectronsToAnalogBarrel = ps.getParameter<double>("photoelectronsToAnalogBarrel");
46  double photoelectronsToAnalogEndcap = ps.getParameter<double>("photoelectronsToAnalogEndcap");
47  double samplingFactor = ps.getParameter<double>("samplingFactor");
48  double timePhase = ps.getParameter<double>("timePhase");
49  int readoutFrameSize = ps.getParameter<int>("readoutFrameSize");
50  int binOfMaximum = ps.getParameter<int>("binOfMaximum");
51  bool doPhotostatistics = ps.getParameter<bool>("doPhotostatistics");
52  bool syncPhase = ps.getParameter<bool>("syncPhase");
53 
54  doPhotostatistics = false;
55 
56  theParameterMap = new EcalSimParameterMap(simHitToPhotoelectronsBarrel, simHitToPhotoelectronsEndcap,
57  photoelectronsToAnalogBarrel, photoelectronsToAnalogEndcap,
58  samplingFactor, timePhase, readoutFrameSize, binOfMaximum,
59  doPhotostatistics, syncPhase);
60  //theEcalShape = new EcalShape(timePhase);
61 
62  //theEcalResponse = new CaloHitResponse(theParameterMap, theEcalShape);
63 
64 /*
65  int ESGain = ps.getParameter<int>("ESGain");
66  double ESNoiseSigma = ps.getParameter<double> ("ESNoiseSigma");
67  int ESBaseline = ps.getParameter<int>("ESBaseline");
68  double ESMIPADC = ps.getParameter<double>("ESMIPADC");
69  double ESMIPkeV = ps.getParameter<double>("ESMIPkeV");
70 */
71 
72  theESShape = new ESShape();
73  theEBShape = new EBShape(true);
74  theEEShape = new EEShape(true);
75 
79 
80 // double effwei = 1.;
81 
82 /*
83  if (ESGain == 0)
84  effwei = 1.45;
85  else if (ESGain == 1)
86  effwei = 0.9066;
87  else if (ESGain == 2)
88  effwei = 0.8815;
89 
90  esBaseline_ = (double)ESBaseline;
91  esADCtokeV_ = 1000000.*ESMIPADC/ESMIPkeV;
92  esThreshold_ = 3.*effwei*ESNoiseSigma/esADCtokeV_;
93 */
94  theMinBunch = -10;
95  theMaxBunch = 10;
96 
97 
98  // verbosity switch
99  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
100 
101  gainConv_[1] = 1.;
102  gainConv_[2] = 2.;
103  gainConv_[3] = 12.;
104  gainConv_[0] = 12.;
105  barrelADCtoGeV_ = 0.035;
106  endcapADCtoGeV_ = 0.06;
107 
108  meEBDigiMixRatiogt100ADC_ = nullptr;
109  meEEDigiMixRatiogt100ADC_ = nullptr;
110 
111  meEBDigiMixRatioOriggt50pc_ = nullptr;
112  meEEDigiMixRatioOriggt40pc_ = nullptr;
113 
114  meEBbunchCrossing_ = nullptr;
115  meEEbunchCrossing_ = nullptr;
116  meESbunchCrossing_ = nullptr;
117 
118  for ( int i = 0 ; i < nBunch ; i++ ) {
119  meEBBunchShape_[i] = nullptr;
120  meEEBunchShape_[i] = nullptr;
121  meESBunchShape_[i] = nullptr;
122  }
123 
124  meEBShape_ = nullptr;
125  meEEShape_ = nullptr;
126  meESShape_ = nullptr;
127 
128  meEBShapeRatio_ = nullptr;
129  meEEShapeRatio_ = nullptr;
130  meESShapeRatio_ = nullptr;
131 
132 }
133 
135 
137 
141 }
142 
144 
145  Char_t histo[200];
146 
147  ibooker.setCurrentFolder("EcalDigisV/EcalDigiTask");
148 
149  sprintf (histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio gt 100 ADC" ) ;
150  meEBDigiMixRatiogt100ADC_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
151 
152  sprintf (histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio gt 100 ADC" ) ;
153  meEEDigiMixRatiogt100ADC_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
154 
155  sprintf (histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio signal gt 50pc gun" ) ;
156  meEBDigiMixRatioOriggt50pc_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
157 
158  sprintf (histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio signal gt 40pc gun" ) ;
159  meEEDigiMixRatioOriggt40pc_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
160 
161  sprintf (histo, "EcalDigiTask Barrel bunch crossing" ) ;
162  meEBbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.) ;
163 
164  sprintf (histo, "EcalDigiTask Endcap bunch crossing" ) ;
165  meEEbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.) ;
166 
167  sprintf (histo, "EcalDigiTask Preshower bunch crossing" ) ;
168  meESbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.) ;
169 
170  for ( int i = 0 ; i < nBunch ; i++ ) {
171 
172  sprintf (histo, "EcalDigiTask Barrel shape bunch crossing %02d", i-10 );
173  meEBBunchShape_[i] = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
174 
175  sprintf (histo, "EcalDigiTask Endcap shape bunch crossing %02d", i-10 );
176  meEEBunchShape_[i] = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
177 
178  sprintf (histo, "EcalDigiTask Preshower shape bunch crossing %02d", i-10 );
179  meESBunchShape_[i] = ibooker.bookProfile(histo, histo, 3, 0, 3, 4000, 0., 400.);
180 
181  }
182 
183  sprintf (histo, "EcalDigiTask Barrel shape digi");
184  meEBShape_ = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
185 
186  sprintf (histo, "EcalDigiTask Endcap shape digi");
187  meEEShape_ = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
188 
189  sprintf (histo, "EcalDigiTask Preshower shape digi");
190  meESShape_ = ibooker.bookProfile(histo, histo, 3, 0, 3, 4000, 0., 2000.);
191 
192  sprintf (histo, "EcalDigiTask Barrel shape digi ratio");
193  meEBShapeRatio_ = ibooker.book1D(histo, histo, 10, 0, 10.);
194 
195  sprintf (histo, "EcalDigiTask Endcap shape digi ratio");
196  meEEShapeRatio_ = ibooker.book1D(histo, histo, 10, 0, 10.);
197 
198  sprintf (histo, "EcalDigiTask Preshower shape digi ratio");
199  meESShapeRatio_ = ibooker.book1D(histo, histo, 3, 0, 3.);
200 
201 }
202 
204 
205  // add shapes for each bunch crossing and divide the digi by the result
206 
207  std::vector<MonitorElement *> theBunches;
208  for ( int i = 0 ; i < nBunch ; i++ ) {
209  theBunches.push_back(meEBBunchShape_[i]);
210  }
212 
213  theBunches.clear();
214 
215  for ( int i = 0 ; i < nBunch ; i++ ) {
216  theBunches.push_back(meEEBunchShape_[i]);
217  }
219 
220  theBunches.clear();
221 
222  for ( int i = 0 ; i < nBunch ; i++ ) {
223  theBunches.push_back(meESBunchShape_[i]);
224  }
226 
227 }
228 
229 void EcalMixingModuleValidation::bunchSumTest(std::vector<MonitorElement *> & theBunches, MonitorElement* & theTotal, MonitorElement* & theRatio, int nSample)
230 {
231 
232  std::vector<double> bunchSum;
233  bunchSum.reserve(nSample);
234  std::vector<double> bunchSumErro;
235  bunchSumErro.reserve(nSample);
236  std::vector<double> total;
237  total.reserve(nSample);
238  std::vector<double> totalErro;
239  totalErro.reserve(nSample);
240  std::vector<double> ratio;
241  ratio.reserve(nSample);
242  std::vector<double> ratioErro;
243  ratioErro.reserve(nSample);
244 
245 
246  for ( int iEl = 0 ; iEl < nSample ; iEl++ ) {
247  bunchSum[iEl] = 0.;
248  bunchSumErro[iEl] = 0.;
249  total[iEl] = 0.;
250  totalErro[iEl] = 0.;
251  ratio[iEl] = 0.;
252  ratioErro[iEl] = 0.;
253  }
254 
255  for ( int iSample = 0 ; iSample < nSample ; iSample++ ) {
256 
257  total[iSample] += theTotal->getBinContent(iSample+1);
258  totalErro[iSample] += theTotal->getBinError(iSample+1);
259 
260  for ( int iBunch = theMinBunch; iBunch <= theMaxBunch; iBunch++ ) {
261 
262  int iHisto = iBunch - theMinBunch;
263 
264  bunchSum[iSample] += theBunches[iHisto]->getBinContent(iSample+1);
265  bunchSumErro[iSample] += pow(theBunches[iHisto]->getBinError(iSample+1),2);
266 
267  }
268  bunchSumErro[iSample] = sqrt(bunchSumErro[iSample]);
269 
270  if ( bunchSum[iSample] > 0. ) {
271  ratio[iSample] = total[iSample]/bunchSum[iSample];
272  ratioErro[iSample] = sqrt(pow(totalErro[iSample]/bunchSum[iSample],2)+
273  pow((total[iSample]*bunchSumErro[iSample])/(bunchSum[iSample]*bunchSum[iSample]),2));
274  }
275 
276  std::cout << " Sample = " << iSample << " Total = " << total[iSample] << " +- " << totalErro[iSample] << "\n"
277  << " Sum = " << bunchSum[iSample] << " +- " << bunchSumErro[iSample] << "\n"
278  << " Ratio = " << ratio[iSample] << " +- " << ratioErro[iSample] << std::endl;
279 
280  theRatio->setBinContent(iSample+1, (float)ratio[iSample]);
281  theRatio->setBinError(iSample+1, (float)ratioErro[iSample]);
282 
283  }
284 
285 }
286 
288 
289  //LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
290 
291  checkPedestals(c);
292 
293  std::vector<SimTrack> theSimTracks;
294  std::vector<SimVertex> theSimVertexes;
295 
297  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
301 
302 
303  bool skipMC = false;
304  e.getByToken( HepMCToken_, MCEvt );
305  if (!MCEvt.isValid()) { skipMC = true; }
306 
307  const EBDigiCollection* EBdigis =nullptr;
308  const EEDigiCollection* EEdigis =nullptr;
309  const ESDigiCollection* ESdigis =nullptr;
310 
311  bool isBarrel = true;
312  e.getByToken( EBdigiCollectionToken_, EcalDigiEB );
313  if (EcalDigiEB.isValid()) {
314  EBdigis = EcalDigiEB.product();
315  LogDebug("DigiInfo") << "total # EBdigis: " << EBdigis->size() ;
316  if ( EBdigis->empty() ) isBarrel = false;
317  } else {
318  isBarrel = false;
319  }
320 
321  bool isEndcap = true;
322  e.getByToken( EEdigiCollectionToken_, EcalDigiEE );
323  if (EcalDigiEE.isValid()) {
324  EEdigis = EcalDigiEE.product();
325  LogDebug("DigiInfo") << "total # EEdigis: " << EEdigis->size() ;
326  if ( EEdigis->empty() ) isEndcap = false;
327  } else {
328  isEndcap = false;
329  }
330 
331  bool isPreshower = true;
332  e.getByToken( ESdigiCollectionToken_, EcalDigiES );
333  if (EcalDigiES.isValid()) {
334  ESdigis = EcalDigiES.product();
335  LogDebug("DigiInfo") << "total # ESdigis: " << ESdigis->size() ;
336  if ( ESdigis->empty() ) isPreshower = false;
337  } else {
338  isPreshower = false;
339  }
340 
341  double theGunEnergy = 0.;
342  if ( ! skipMC ) {
343  for ( HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
344  p != MCEvt->GetEvent()->particles_end(); ++p ) {
345 
346  theGunEnergy = (*p)->momentum().e();
347  }
348  }
349  // in case no HepMC available, assume an arbitrary average energy for an interesting "gun"
350  else {
351  edm::LogWarning("DigiInfo") << "No HepMC available, using 30 GeV as giun energy";
352  theGunEnergy = 30.;
353  }
354 
355  // BARREL
356 
357  // loop over simHits
358 
359  if ( isBarrel ) {
360 
361  e.getByToken( crossingFramePCaloHitEBToken_, crossingFrame );
362  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
363 
364  MapType ebSignalSimMap;
365 
366  double ebSimThreshold = 0.5*theGunEnergy;
367 
368  for ( auto const &iHit : barrelHits ) {
369 
370  EBDetId ebid = EBDetId(iHit.id()) ;
371 
372  LogDebug("HitInfo")
373  << " CaloHit " << iHit.getName() << "\n"
374  << " DetID = "<<iHit.id()<< " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
375  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
376  << " Track Id = " << iHit.geantTrackId() << "\n"
377  << " Energy = " << iHit.energy();
378 
379  uint32_t crystid = ebid.rawId();
380 
381  if ( iHit.eventId().rawId() == 0 ) ebSignalSimMap[crystid] += iHit.energy();
382 
383  if ( meEBbunchCrossing_ ) meEBbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
384 
385  }
386 
387  // loop over Digis
388 
389  const EBDigiCollection * barrelDigi = EcalDigiEB.product () ;
390 
391  std::vector<double> ebAnalogSignal ;
392  std::vector<double> ebADCCounts ;
393  std::vector<double> ebADCGains ;
394  ebAnalogSignal.reserve(EBDataFrame::MAXSAMPLES);
395  ebADCCounts.reserve(EBDataFrame::MAXSAMPLES);
396  ebADCGains.reserve(EBDataFrame::MAXSAMPLES);
397 
398  for (unsigned int digis=0; digis<EcalDigiEB->size(); ++digis) {
399 
400  EBDataFrame ebdf=(*barrelDigi)[digis];
401  int nrSamples=ebdf.size();
402 
403  EBDetId ebid = ebdf.id () ;
404 
405  double Emax = 0. ;
406  int Pmax = 0 ;
407 
408  for (int sample = 0 ; sample < nrSamples; ++sample) {
409  ebAnalogSignal[sample] = 0.;
410  ebADCCounts[sample] = 0.;
411  ebADCGains[sample] = -1.;
412  }
413 
414  for (int sample = 0 ; sample < nrSamples; ++sample) {
415 
417 
418  ebADCCounts[sample] = (mySample.adc()) ;
419  ebADCGains[sample] = (mySample.gainId ()) ;
420  ebAnalogSignal[sample] = (ebADCCounts[sample]*gainConv_[(int)ebADCGains[sample]]*barrelADCtoGeV_);
421  if (Emax < ebAnalogSignal[sample] ) {
422  Emax = ebAnalogSignal[sample] ;
423  Pmax = sample ;
424  }
425  LogDebug("DigiInfo") << "EB sample " << sample << " ADC counts = " << ebADCCounts[sample] << " Gain Id = " << ebADCGains[sample] << " Analog eq = " << ebAnalogSignal[sample];
426  }
427  double pedestalPreSampleAnalog = 0.;
428  findPedestal( ebid, (int)ebADCGains[Pmax] , pedestalPreSampleAnalog);
429  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[Pmax]]*barrelADCtoGeV_;
430  double Erec = Emax - pedestalPreSampleAnalog;
431 
432  if ( ebSignalSimMap[ebid.rawId()] != 0. ) {
433  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << ebSignalSimMap[ebid.rawId()] << " gainConv " << gainConv_[(int)ebADCGains[Pmax]];
434  if ( Erec > 100.*barrelADCtoGeV_ && meEBDigiMixRatiogt100ADC_ ) meEBDigiMixRatiogt100ADC_->Fill( Erec/ebSignalSimMap[ebid.rawId()] );
435  if ( ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBDigiMixRatioOriggt50pc_ ) meEBDigiMixRatioOriggt50pc_->Fill( Erec/ebSignalSimMap[ebid.rawId()] );
436  if ( ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBShape_ ) {
437  for ( int i = 0; i < 10 ; i++ ) {
438  pedestalPreSampleAnalog = 0.;
439  findPedestal( ebid, (int)ebADCGains[i] , pedestalPreSampleAnalog);
440  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[i]]*barrelADCtoGeV_;
441  meEBShape_->Fill(i, ebAnalogSignal[i]-pedestalPreSampleAnalog );
442  }
443  }
444  }
445 
446  }
447 
448  EcalSubdetector thisDet = EcalBarrel;
449  computeSDBunchDigi(c, barrelHits, ebSignalSimMap, thisDet, ebSimThreshold, randomEngine(e.streamID()));
450  }
451 
452 
453  // ENDCAP
454 
455  // loop over simHits
456 
457  if ( isEndcap ) {
458 
459  e.getByToken( crossingFramePCaloHitEEToken_, crossingFrame );
460  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
461  MapType eeSignalSimMap;
462 
463  double eeSimThreshold = 0.4*theGunEnergy;
464 
465  for ( auto const & iHit : endcapHits ) {
466 
467  EEDetId eeid = EEDetId(iHit.id()) ;
468 
469  LogDebug("HitInfo")
470  << " CaloHit " << iHit.getName() << "\n"
471  << " DetID = "<<iHit.id()<< " EEDetId side = " << eeid.zside() << " = " << eeid.ix() << " " << eeid.iy() << "\n"
472  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
473  << " Track Id = " << iHit.geantTrackId() << "\n"
474  << " Energy = " << iHit.energy();
475 
476  uint32_t crystid = eeid.rawId();
477 
478  if ( iHit.eventId().rawId() == 0 ) eeSignalSimMap[crystid] += iHit.energy();
479 
480  if ( meEEbunchCrossing_ ) meEEbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
481 
482  }
483 
484  // loop over Digis
485 
486  const EEDigiCollection * endcapDigi = EcalDigiEE.product () ;
487 
488  std::vector<double> eeAnalogSignal ;
489  std::vector<double> eeADCCounts ;
490  std::vector<double> eeADCGains ;
491  eeAnalogSignal.reserve(EEDataFrame::MAXSAMPLES);
492  eeADCCounts.reserve(EEDataFrame::MAXSAMPLES);
493  eeADCGains.reserve(EEDataFrame::MAXSAMPLES);
494 
495  for (unsigned int digis=0; digis<EcalDigiEE->size(); ++digis) {
496 
497  EEDataFrame eedf=(*endcapDigi)[digis];
498  int nrSamples=eedf.size();
499 
500  EEDetId eeid = eedf.id () ;
501 
502  double Emax = 0. ;
503  int Pmax = 0 ;
504 
505  for (int sample = 0 ; sample < nrSamples; ++sample) {
506  eeAnalogSignal[sample] = 0.;
507  eeADCCounts[sample] = 0.;
508  eeADCGains[sample] = -1.;
509  }
510 
511  for (int sample = 0 ; sample < nrSamples; ++sample) {
512 
514 
515  eeADCCounts[sample] = (mySample.adc()) ;
516  eeADCGains[sample] = (mySample.gainId()) ;
517  eeAnalogSignal[sample] = (eeADCCounts[sample]*gainConv_[(int)eeADCGains[sample]]*endcapADCtoGeV_);
518  if (Emax < eeAnalogSignal[sample] ) {
519  Emax = eeAnalogSignal[sample] ;
520  Pmax = sample ;
521  }
522  LogDebug("DigiInfo") << "EE sample " << sample << " ADC counts = " << eeADCCounts[sample] << " Gain Id = " << eeADCGains[sample] << " Analog eq = " << eeAnalogSignal[sample];
523  }
524  double pedestalPreSampleAnalog = 0.;
525  findPedestal( eeid, (int)eeADCGains[Pmax] , pedestalPreSampleAnalog);
526  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[Pmax]]*endcapADCtoGeV_;
527  double Erec = Emax - pedestalPreSampleAnalog;
528 
529  if ( eeSignalSimMap[eeid.rawId()] != 0. ) {
530  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << eeSignalSimMap[eeid.rawId()] << " gainConv " << gainConv_[(int)eeADCGains[Pmax]];
531  if ( Erec > 100.*endcapADCtoGeV_ && meEEDigiMixRatiogt100ADC_ ) meEEDigiMixRatiogt100ADC_->Fill( Erec/eeSignalSimMap[eeid.rawId()] );
532  if ( eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEEDigiMixRatioOriggt40pc_ ) meEEDigiMixRatioOriggt40pc_->Fill( Erec/eeSignalSimMap[eeid.rawId()] );
533  if ( eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEBShape_ ) {
534  for ( int i = 0; i < 10 ; i++ ) {
535  pedestalPreSampleAnalog = 0.;
536  findPedestal( eeid, (int)eeADCGains[i] , pedestalPreSampleAnalog);
537  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[i]]*endcapADCtoGeV_;
538  meEEShape_->Fill(i, eeAnalogSignal[i]-pedestalPreSampleAnalog );
539  }
540  }
541  }
542  }
543 
544  EcalSubdetector thisDet = EcalEndcap;
545  computeSDBunchDigi(c, endcapHits, eeSignalSimMap, thisDet, eeSimThreshold, randomEngine(e.streamID()));
546  }
547 
548  if ( isPreshower) {
549 
550  e.getByToken(crossingFramePCaloHitESToken_, crossingFrame );
551  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
552 
553  MapType esSignalSimMap;
554 
555  for ( auto const & iHit : preshowerHits ) {
556 
557  ESDetId esid = ESDetId(iHit.id()) ;
558 
559  LogDebug("HitInfo")
560  << " CaloHit " << iHit.getName() << "\n"
561  << " DetID = "<<iHit.id()<< "ESDetId: z side " << esid.zside() << " plane " << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
562  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
563  << " Track Id = " << iHit.geantTrackId() << "\n"
564  << " Energy = " << iHit.energy();
565 
566  uint32_t stripid = esid.rawId();
567 
568  if ( iHit.eventId().rawId() == 0 ) esSignalSimMap[stripid] += iHit.energy();
569 
570  if ( meESbunchCrossing_ ) meESbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
571 
572  // loop over Digis
573 
574  const ESDigiCollection * preshowerDigi = EcalDigiES.product () ;
575 
576  std::vector<double> esADCCounts ;
577  std::vector<double> esADCAnalogSignal ;
578  esADCCounts.reserve(ESDataFrame::MAXSAMPLES);
579  esADCAnalogSignal.reserve(ESDataFrame::MAXSAMPLES);
580 
581  for (unsigned int digis=0; digis<EcalDigiES->size(); ++digis) {
582 
583  ESDataFrame esdf=(*preshowerDigi)[digis];
584  int nrSamples=esdf.size();
585 
586  ESDetId esid = esdf.id () ;
587 
588  for (int sample = 0 ; sample < nrSamples; ++sample) {
589  esADCCounts[sample] = 0.;
590  esADCAnalogSignal[sample] = 0.;
591  }
592 
593  for (int sample = 0 ; sample < nrSamples; ++sample) {
594 
595  ESSample mySample = esdf[sample];
596 
597  esADCCounts[sample] = (mySample.adc()) ;
598  esBaseline_ = m_ESpeds->find(esid)->getMean() ;
599  const double factor ( esADCtokeV_/(*(m_ESmips->getMap().find(esid)) ) ) ;
600  esThreshold_ = 3.*m_ESeffwei*( (*m_ESpeds->find(esid)).getRms())/factor;
601  esADCAnalogSignal[sample] = (esADCCounts[sample]-esBaseline_)/factor;
602  }
603  LogDebug("DigiInfo") << "Preshower Digi for ESDetId: z side " << esid.zside() << " plane " << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip();
604  for ( int i = 0; i < 3 ; i++ ) {
605  LogDebug("DigiInfo") << "sample " << i << " ADC = " << esADCCounts[i] << " Analog eq = " << esADCAnalogSignal[i];
606  }
607 
608  if ( esSignalSimMap[esid.rawId()] > esThreshold_ && meESShape_ ) {
609  for ( int i = 0; i < 3 ; i++ ) {
610  meESShape_->Fill(i, esADCAnalogSignal[i] );
611  }
612  }
613 
614  }
615 
616  }
617 
618  EcalSubdetector thisDet = EcalPreshower;
619  computeSDBunchDigi(c, preshowerHits, esSignalSimMap, thisDet, esThreshold_, randomEngine(e.streamID()));
620 
621  }
622 
623 }
624 
626 
627  // ADC -> GeV Scale
629  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
630  const EcalADCToGeVConstant* agc = pAgc.product();
631 
632  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
633 
634  gainConv_[1] = 1.;
635  gainConv_[2] = defaultRatios->gain12Over6() ;
636  gainConv_[3] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
637  gainConv_[0] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
638 
639  LogDebug("EcalDigi") << " Gains conversions: " << "\n" << " g1 = " << gainConv_[1] << "\n" << " g2 = " << gainConv_[2] << "\n" << " g3 = " << gainConv_[3];
640 
641  delete defaultRatios;
642 
643  const double barrelADCtoGeV_ = agc->getEBValue();
644  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
645  const double endcapADCtoGeV_ = agc->getEEValue();
646  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
647 
648 
649  // ES condition objects
650  edm::ESHandle<ESGain> esgain_;
652  edm::ESHandle<ESPedestals> esPedestals_;
654 
655  eventSetup.get<ESGainRcd>().get(esgain_);
656  eventSetup.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
657  eventSetup.get<ESPedestalsRcd>().get(esPedestals_);
658  eventSetup.get<ESIntercalibConstantsRcd>().get(esMIPs_);
659 
660  const ESGain *esgain = esgain_.product();
661  m_ESpeds = esPedestals_.product();
662  m_ESmips = esMIPs_.product();
663  const ESMIPToGeVConstant *esMipToGeV = esMIPToGeV_.product();
664  m_ESgain = (int) esgain->getESGain();
665  const double valESMIPToGeV = (m_ESgain == 1) ? esMipToGeV->getESValueLow() : esMipToGeV->getESValueHigh();
666 
668 
669  esADCtokeV_ = 1000000.*valESMIPToGeV ;
670 
671  m_ESeffwei = ( 0 == m_ESgain ? 1.45 :
672  ( 1 == m_ESgain ? 0.9066 :
673  ( 2 == m_ESgain ? 0.8815 : 1.0 ) ) ) ;
674 
675 }
676 
678 {
679 
680  // Pedestals from event setup
681 
683  eventSetup.get<EcalPedestalsRcd>().get( dbPed );
684  thePedestals=dbPed.product();
685 
686 }
687 
688 void EcalMixingModuleValidation::findPedestal(const DetId & detId, int gainId, double & ped) const
689 {
691  = thePedestals->getMap().find(detId);
692  // should I care if it doesn't get found?
693  if(mapItr == thePedestals->getMap().end()) {
694  edm::LogError("EcalMMValid") << "Could not find pedestal for " << detId.rawId() << " among the " << thePedestals->getMap().size();
695  } else {
696  EcalPedestals::Item item = (*mapItr);
697 
698  switch(gainId) {
699  case 0:
700  ped = item.mean_x1;
701  case 1:
702  ped = item.mean_x12;
703  break;
704  case 2:
705  ped = item.mean_x6;
706  break;
707  case 3:
708  ped = item.mean_x1;
709  break;
710  default:
711  edm::LogError("EcalMMValid") << "Bad Pedestal " << gainId;
712  break;
713  }
714  LogDebug("EcalMMValid") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n" << "Mean = " << ped;
715  }
716 }
717 
718 void EcalMixingModuleValidation::computeSDBunchDigi(const edm::EventSetup & eventSetup, const MixCollection<PCaloHit> & theHits, MapType & SignalSimMap, const EcalSubdetector & thisDet, const double & theSimThreshold, CLHEP::HepRandomEngine* engine)
719 {
720 
721  if ( thisDet != EcalBarrel && thisDet != EcalEndcap && thisDet != EcalPreshower ) {
722  edm::LogError("EcalMMValid") << "Invalid subdetector type";
723  return;
724  }
725  //bool isCrystal = true;
726  //if ( thisDet == EcalPreshower ) isCrystal = false;
727 
728  // load the geometry
729 
730  edm::ESHandle<CaloGeometry> hGeometry;
731  eventSetup.get<CaloGeometryRecord>().get(hGeometry);
732 
733  const CaloGeometry * pGeometry = &*hGeometry;
734 
735  // see if we need to update
736  if(pGeometry != theGeometry) {
737  theGeometry = pGeometry;
738  //theEcalResponse->setGeometry(theGeometry);
742 
743  }
744 
745  // vector of DetId with energy above a fraction of the gun's energy
746 
747  const std::vector<DetId>& theSDId = theGeometry->getValidDetIds( DetId::Ecal, thisDet );
748 
749  std::vector<DetId> theOverThresholdId;
750  for ( unsigned int i = 0 ; i < theSDId.size() ; i++ ) {
751 
752  int sdId = theSDId[i].rawId();
753  if ( SignalSimMap[sdId] > theSimThreshold ) theOverThresholdId.push_back( theSDId[i] );
754 
755  }
756 
758  if ( thisDet == EcalPreshower ) limit = ESDataFrame::MAXSAMPLES;
759 
760  for (int iBunch = theMinBunch ; iBunch <= theMaxBunch ; iBunch++ ) {
761 
762  //if ( isCrystal ) {
763  if( thisDet == EcalBarrel ) {
764  theEBResponse->setBunchRange(iBunch, iBunch);
765  theEBResponse->clear();
766  theEBResponse->run(theHits, engine);
767  }
768  else if( thisDet == EcalEndcap ) {
769  theEEResponse->setBunchRange(iBunch, iBunch);
770  theEEResponse->clear();
771  theEEResponse->run(theHits, engine);
772  }
773  else {
774  theESResponse->setBunchRange(iBunch, iBunch);
775  theESResponse->clear();
776  theESResponse->run(theHits, engine);
777  }
778 
779  int iHisto = iBunch - theMinBunch;
780 
781  for ( std::vector<DetId>::const_iterator idItr = theOverThresholdId.begin() ; idItr != theOverThresholdId.end() ; ++idItr ) {
782 
783  CaloSamples * analogSignal;
784  //if ( isCrystal )
785  if( thisDet == EcalBarrel ) {
786  analogSignal = theEBResponse->findSignal(*idItr);
787  }
788  else if( thisDet == EcalEndcap ) {
789  analogSignal = theEEResponse->findSignal(*idItr);
790  }
791  else {
792  analogSignal = theESResponse->findSignal(*idItr);
793  }
794 
795  if ( analogSignal ) {
796 
797  (*analogSignal) *= theParameterMap->simParameters(analogSignal->id()).photoelectronsToAnalog();
798 
799  for ( int i = 0 ; i < limit ; i++ ) {
800  if ( thisDet == EcalBarrel ) { meEBBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
801  else if ( thisDet == EcalEndcap ) { meEEBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
802  else if ( thisDet == EcalPreshower ) { meESBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
803  }
804  }
805 
806  }
807 
808  }
809 
810  }
811 
812 CLHEP::HepRandomEngine* EcalMixingModuleValidation::randomEngine(edm::StreamID const& streamID) {
813  unsigned int index = streamID.value();
814  if(index >= randomEngines_.size()) {
815  randomEngines_.resize(index + 1, nullptr);
816  }
817  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
818  if(!ptr) {
820  ptr = &rng->getEngine(streamID);
821  randomEngines_[index] = ptr;
822  }
823  return ptr;
824 }
#define LogDebug(id)
T getParameter(std::string const &) const
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
T getUntrackedParameter(std::string const &, T const &) const
void checkPedestals(const edm::EventSetup &c)
void setBinContent(int binx, double content)
set content of bin (1-D)
int strip() const
Definition: ESDetId.h:53
const ESIntercalibConstants * m_ESmips
int ix() const
Definition: EEDetId.h:76
void endRun(const edm::Run &r, const edm::EventSetup &c) override
key_type id() const
Definition: EBDataFrame.h:31
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitESToken_
void findPedestal(const DetId &detId, int gainId, double &ped) const
static const int MAXSAMPLES
Definition: CaloSamples.h:76
int gainId(sample_type sample)
get the gainId (2 bits)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Definition: ESGain.h:7
void setGain(const int gain)
Definition: ESShape.h:26
const self & getMap() const
edm::EDGetTokenT< edm::HepMCProduct > HepMCToken_
const ESDetId & id() const
Definition: ESDataFrame.h:21
const self & getMap() const
float getESValueLow() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void checkCalibrations(edm::EventSetup const &c)
MonitorElement * meEEBunchShape_[nBunch]
edm::EDGetTokenT< EBDigiCollection > EBdigiCollectionToken_
std::vector< CLHEP::HepRandomEngine * > randomEngines_
MonitorElement * meEBBunchShape_[nBunch]
int six() const
Definition: ESDetId.h:49
int size() const
Definition: ESDataFrame.h:23
int gainId() const
get the gainId (2 bits)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
virtual void run(const MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
Complete cell digitization.
int size() const
Definition: EcalDataFrame.h:26
void Fill(long long x)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEEToken_
int siy() const
Definition: ESDetId.h:51
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:52
void bunchSumTest(std::vector< MonitorElement * > &theBunches, MonitorElement *&theTotal, MonitorElement *&theRatio, int nSample)
MonitorElement * meESBunchShape_[nBunch]
Creates electronics signals from hits.
~EcalMixingModuleValidation() override
Destructor.
T sqrt(T t)
Definition: SSEVec.h:18
static const int MAXSAMPLES
Definition: ESDataFrame.h:32
CLHEP::HepRandomEngine * randomEngine(edm::StreamID const &streamID)
const_iterator find(uint32_t rawId) const
int zside() const
Definition: EEDetId.h:70
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
const CaloSimParameters & simParameters(const DetId &id) const override
return the sim parameters relative to the right subdet
int iy() const
Definition: EEDetId.h:82
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
float gain6Over1() const
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int zside() const
Definition: ESDetId.h:45
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEBToken_
bool isEndcap(GeomDetEnumerators::SubDetector m)
void computeSDBunchDigi(const edm::EventSetup &eventSetup, const MixCollection< PCaloHit > &theHits, MapType &ebSignalSimMap, const EcalSubdetector &thisDet, const double &theSimThreshold, CLHEP::HepRandomEngine *)
key_type id() const
Definition: EEDataFrame.h:28
Definition: EBShape.h:6
std::map< int, double, std::less< int > > gainConv_
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
void reserve(size_t isize)
Definition: DetId.h:18
const EcalSimParameterMap * theParameterMap
std::map< uint32_t, float, std::less< uint32_t > > MapType
edm::EDGetTokenT< ESDigiCollection > ESdigiCollectionToken_
unsigned int value() const
Definition: StreamID.h:46
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
T const * product() const
Definition: Handle.h:81
float getESGain() const
Definition: ESGain.h:13
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
void analyze(edm::Event const &e, edm::EventSetup const &c) override
Analyze.
float gain12Over6() const
void setBunchRange(int minBunch, int maxBunch)
tells it which pileup bunches to do
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
double getBinContent(int binx) const
get content of bin (1-D)
HLT enums.
void clear()
frees up memory
T get() const
Definition: EventSetup.h:68
StreamID streamID() const
Definition: Event.h:96
int plane() const
Definition: ESDetId.h:47
void setEventSetup(const edm::EventSetup &evtSetup)
const_iterator find(uint32_t rawId) const
const_iterator end() const
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:18
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
EcalMixingModuleValidation(const edm::ParameterSet &ps)
Constructor.
EcalSubdetector
float getESValueHigh() const
T const * product() const
Definition: ESHandle.h:84
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
edm::EDGetTokenT< EEDigiCollection > EEdigiCollectionToken_
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:44
Definition: EEShape.h:6
int adc() const
get the ADC sample (12 bits)