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();
74  theEEShape = new EEShape();
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 
139 
140 }
141 
143 
144  Char_t histo[200];
145 
146  ibooker.setCurrentFolder("EcalDigisV/EcalDigiTask");
147 
148  sprintf (histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio gt 100 ADC" ) ;
149  meEBDigiMixRatiogt100ADC_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
150 
151  sprintf (histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio gt 100 ADC" ) ;
152  meEEDigiMixRatiogt100ADC_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
153 
154  sprintf (histo, "EcalDigiTask Barrel maximum Digi over sim signal ratio signal gt 50pc gun" ) ;
155  meEBDigiMixRatioOriggt50pc_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
156 
157  sprintf (histo, "EcalDigiTask Endcap maximum Digi over sim signal ratio signal gt 40pc gun" ) ;
158  meEEDigiMixRatioOriggt40pc_ = ibooker.book1D(histo, histo, 200, 0., 100.) ;
159 
160  sprintf (histo, "EcalDigiTask Barrel bunch crossing" ) ;
161  meEBbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.) ;
162 
163  sprintf (histo, "EcalDigiTask Endcap bunch crossing" ) ;
164  meEEbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.) ;
165 
166  sprintf (histo, "EcalDigiTask Preshower bunch crossing" ) ;
167  meESbunchCrossing_ = ibooker.book1D(histo, histo, 20, -10., 10.) ;
168 
169  for ( int i = 0 ; i < nBunch ; i++ ) {
170 
171  sprintf (histo, "EcalDigiTask Barrel shape bunch crossing %02d", i-10 );
172  meEBBunchShape_[i] = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
173 
174  sprintf (histo, "EcalDigiTask Endcap shape bunch crossing %02d", i-10 );
175  meEEBunchShape_[i] = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 400.);
176 
177  sprintf (histo, "EcalDigiTask Preshower shape bunch crossing %02d", i-10 );
178  meESBunchShape_[i] = ibooker.bookProfile(histo, histo, 3, 0, 3, 4000, 0., 400.);
179 
180  }
181 
182  sprintf (histo, "EcalDigiTask Barrel shape digi");
183  meEBShape_ = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
184 
185  sprintf (histo, "EcalDigiTask Endcap shape digi");
186  meEEShape_ = ibooker.bookProfile(histo, histo, 10, 0, 10, 4000, 0., 2000.);
187 
188  sprintf (histo, "EcalDigiTask Preshower shape digi");
189  meESShape_ = ibooker.bookProfile(histo, histo, 3, 0, 3, 4000, 0., 2000.);
190 
191  sprintf (histo, "EcalDigiTask Barrel shape digi ratio");
192  meEBShapeRatio_ = ibooker.book1D(histo, histo, 10, 0, 10.);
193 
194  sprintf (histo, "EcalDigiTask Endcap shape digi ratio");
195  meEEShapeRatio_ = ibooker.book1D(histo, histo, 10, 0, 10.);
196 
197  sprintf (histo, "EcalDigiTask Preshower shape digi ratio");
198  meESShapeRatio_ = ibooker.book1D(histo, histo, 3, 0, 3.);
199 
200 }
201 
203 
204  // add shapes for each bunch crossing and divide the digi by the result
205 
206  std::vector<MonitorElement *> theBunches;
207  for ( int i = 0 ; i < nBunch ; i++ ) {
208  theBunches.push_back(meEBBunchShape_[i]);
209  }
211 
212  theBunches.clear();
213 
214  for ( int i = 0 ; i < nBunch ; i++ ) {
215  theBunches.push_back(meEEBunchShape_[i]);
216  }
218 
219  theBunches.clear();
220 
221  for ( int i = 0 ; i < nBunch ; i++ ) {
222  theBunches.push_back(meESBunchShape_[i]);
223  }
225 
226 }
227 
228 void EcalMixingModuleValidation::bunchSumTest(std::vector<MonitorElement *> & theBunches, MonitorElement* & theTotal, MonitorElement* & theRatio, int nSample)
229 {
230 
231  std::vector<double> bunchSum;
232  bunchSum.reserve(nSample);
233  std::vector<double> bunchSumErro;
234  bunchSumErro.reserve(nSample);
235  std::vector<double> total;
236  total.reserve(nSample);
237  std::vector<double> totalErro;
238  totalErro.reserve(nSample);
239  std::vector<double> ratio;
240  ratio.reserve(nSample);
241  std::vector<double> ratioErro;
242  ratioErro.reserve(nSample);
243 
244 
245  for ( int iEl = 0 ; iEl < nSample ; iEl++ ) {
246  bunchSum[iEl] = 0.;
247  bunchSumErro[iEl] = 0.;
248  total[iEl] = 0.;
249  totalErro[iEl] = 0.;
250  ratio[iEl] = 0.;
251  ratioErro[iEl] = 0.;
252  }
253 
254  for ( int iSample = 0 ; iSample < nSample ; iSample++ ) {
255 
256  total[iSample] += theTotal->getBinContent(iSample+1);
257  totalErro[iSample] += theTotal->getBinError(iSample+1);
258 
259  for ( int iBunch = theMinBunch; iBunch <= theMaxBunch; iBunch++ ) {
260 
261  int iHisto = iBunch - theMinBunch;
262 
263  bunchSum[iSample] += theBunches[iHisto]->getBinContent(iSample+1);
264  bunchSumErro[iSample] += pow(theBunches[iHisto]->getBinError(iSample+1),2);
265 
266  }
267  bunchSumErro[iSample] = sqrt(bunchSumErro[iSample]);
268 
269  if ( bunchSum[iSample] > 0. ) {
270  ratio[iSample] = total[iSample]/bunchSum[iSample];
271  ratioErro[iSample] = sqrt(pow(totalErro[iSample]/bunchSum[iSample],2)+
272  pow((total[iSample]*bunchSumErro[iSample])/(bunchSum[iSample]*bunchSum[iSample]),2));
273  }
274 
275  std::cout << " Sample = " << iSample << " Total = " << total[iSample] << " +- " << totalErro[iSample] << "\n"
276  << " Sum = " << bunchSum[iSample] << " +- " << bunchSumErro[iSample] << "\n"
277  << " Ratio = " << ratio[iSample] << " +- " << ratioErro[iSample] << std::endl;
278 
279  theRatio->setBinContent(iSample+1, (float)ratio[iSample]);
280  theRatio->setBinError(iSample+1, (float)ratioErro[iSample]);
281 
282  }
283 
284 }
285 
287 
288  //LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
289 
290  checkPedestals(c);
291 
292  std::vector<SimTrack> theSimTracks;
293  std::vector<SimVertex> theSimVertexes;
294 
296  edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
300 
301 
302  bool skipMC = false;
303  e.getByToken( HepMCToken_, MCEvt );
304  if (!MCEvt.isValid()) { skipMC = true; }
305 
306  const EBDigiCollection* EBdigis =nullptr;
307  const EEDigiCollection* EEdigis =nullptr;
308  const ESDigiCollection* ESdigis =nullptr;
309 
310  bool isBarrel = true;
311  e.getByToken( EBdigiCollectionToken_, EcalDigiEB );
312  if (EcalDigiEB.isValid()) {
313  EBdigis = EcalDigiEB.product();
314  LogDebug("DigiInfo") << "total # EBdigis: " << EBdigis->size() ;
315  if ( EBdigis->empty() ) isBarrel = false;
316  } else {
317  isBarrel = false;
318  }
319 
320  bool isEndcap = true;
321  e.getByToken( EEdigiCollectionToken_, EcalDigiEE );
322  if (EcalDigiEE.isValid()) {
323  EEdigis = EcalDigiEE.product();
324  LogDebug("DigiInfo") << "total # EEdigis: " << EEdigis->size() ;
325  if ( EEdigis->empty() ) isEndcap = false;
326  } else {
327  isEndcap = false;
328  }
329 
330  bool isPreshower = true;
331  e.getByToken( ESdigiCollectionToken_, EcalDigiES );
332  if (EcalDigiES.isValid()) {
333  ESdigis = EcalDigiES.product();
334  LogDebug("DigiInfo") << "total # ESdigis: " << ESdigis->size() ;
335  if ( ESdigis->empty() ) isPreshower = false;
336  } else {
337  isPreshower = false;
338  }
339 
340  double theGunEnergy = 0.;
341  if ( ! skipMC ) {
342  for ( HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
343  p != MCEvt->GetEvent()->particles_end(); ++p ) {
344 
345  theGunEnergy = (*p)->momentum().e();
346  }
347  }
348  // in case no HepMC available, assume an arbitrary average energy for an interesting "gun"
349  else {
350  edm::LogWarning("DigiInfo") << "No HepMC available, using 30 GeV as giun energy";
351  theGunEnergy = 30.;
352  }
353 
354  // BARREL
355 
356  // loop over simHits
357 
358  if ( isBarrel ) {
359 
360  e.getByToken( crossingFramePCaloHitEBToken_, crossingFrame );
361  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
362 
363  MapType ebSignalSimMap;
364 
365  double ebSimThreshold = 0.5*theGunEnergy;
366 
367  for ( auto const &iHit : barrelHits ) {
368 
369  EBDetId ebid = EBDetId(iHit.id()) ;
370 
371  LogDebug("HitInfo")
372  << " CaloHit " << iHit.getName() << "\n"
373  << " DetID = "<<iHit.id()<< " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
374  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
375  << " Track Id = " << iHit.geantTrackId() << "\n"
376  << " Energy = " << iHit.energy();
377 
378  uint32_t crystid = ebid.rawId();
379 
380  if ( iHit.eventId().rawId() == 0 ) ebSignalSimMap[crystid] += iHit.energy();
381 
382  if ( meEBbunchCrossing_ ) meEBbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
383 
384  }
385 
386  // loop over Digis
387 
388  const EBDigiCollection * barrelDigi = EcalDigiEB.product () ;
389 
390  std::vector<double> ebAnalogSignal ;
391  std::vector<double> ebADCCounts ;
392  std::vector<double> ebADCGains ;
393  ebAnalogSignal.reserve(EBDataFrame::MAXSAMPLES);
394  ebADCCounts.reserve(EBDataFrame::MAXSAMPLES);
395  ebADCGains.reserve(EBDataFrame::MAXSAMPLES);
396 
397  for (unsigned int digis=0; digis<EcalDigiEB->size(); ++digis) {
398 
399  EBDataFrame ebdf=(*barrelDigi)[digis];
400  int nrSamples=ebdf.size();
401 
402  EBDetId ebid = ebdf.id () ;
403 
404  double Emax = 0. ;
405  int Pmax = 0 ;
406 
407  for (int sample = 0 ; sample < nrSamples; ++sample) {
408  ebAnalogSignal[sample] = 0.;
409  ebADCCounts[sample] = 0.;
410  ebADCGains[sample] = -1.;
411  }
412 
413  for (int sample = 0 ; sample < nrSamples; ++sample) {
414 
416 
417  ebADCCounts[sample] = (mySample.adc()) ;
418  ebADCGains[sample] = (mySample.gainId ()) ;
419  ebAnalogSignal[sample] = (ebADCCounts[sample]*gainConv_[(int)ebADCGains[sample]]*barrelADCtoGeV_);
420  if (Emax < ebAnalogSignal[sample] ) {
421  Emax = ebAnalogSignal[sample] ;
422  Pmax = sample ;
423  }
424  LogDebug("DigiInfo") << "EB sample " << sample << " ADC counts = " << ebADCCounts[sample] << " Gain Id = " << ebADCGains[sample] << " Analog eq = " << ebAnalogSignal[sample];
425  }
426  double pedestalPreSampleAnalog = 0.;
427  findPedestal( ebid, (int)ebADCGains[Pmax] , pedestalPreSampleAnalog);
428  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[Pmax]]*barrelADCtoGeV_;
429  double Erec = Emax - pedestalPreSampleAnalog;
430 
431  if ( ebSignalSimMap[ebid.rawId()] != 0. ) {
432  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << ebSignalSimMap[ebid.rawId()] << " gainConv " << gainConv_[(int)ebADCGains[Pmax]];
433  if ( Erec > 100.*barrelADCtoGeV_ && meEBDigiMixRatiogt100ADC_ ) meEBDigiMixRatiogt100ADC_->Fill( Erec/ebSignalSimMap[ebid.rawId()] );
434  if ( ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBDigiMixRatioOriggt50pc_ ) meEBDigiMixRatioOriggt50pc_->Fill( Erec/ebSignalSimMap[ebid.rawId()] );
435  if ( ebSignalSimMap[ebid.rawId()] > ebSimThreshold && meEBShape_ ) {
436  for ( int i = 0; i < 10 ; i++ ) {
437  pedestalPreSampleAnalog = 0.;
438  findPedestal( ebid, (int)ebADCGains[i] , pedestalPreSampleAnalog);
439  pedestalPreSampleAnalog *= gainConv_[(int)ebADCGains[i]]*barrelADCtoGeV_;
440  meEBShape_->Fill(i, ebAnalogSignal[i]-pedestalPreSampleAnalog );
441  }
442  }
443  }
444 
445  }
446 
447  EcalSubdetector thisDet = EcalBarrel;
448  computeSDBunchDigi(c, barrelHits, ebSignalSimMap, thisDet, ebSimThreshold, randomEngine(e.streamID()));
449  }
450 
451 
452  // ENDCAP
453 
454  // loop over simHits
455 
456  if ( isEndcap ) {
457 
458  e.getByToken( crossingFramePCaloHitEEToken_, crossingFrame );
459  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
460  MapType eeSignalSimMap;
461 
462  double eeSimThreshold = 0.4*theGunEnergy;
463 
464  for ( auto const & iHit : endcapHits ) {
465 
466  EEDetId eeid = EEDetId(iHit.id()) ;
467 
468  LogDebug("HitInfo")
469  << " CaloHit " << iHit.getName() << "\n"
470  << " DetID = "<<iHit.id()<< " EEDetId side = " << eeid.zside() << " = " << eeid.ix() << " " << eeid.iy() << "\n"
471  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
472  << " Track Id = " << iHit.geantTrackId() << "\n"
473  << " Energy = " << iHit.energy();
474 
475  uint32_t crystid = eeid.rawId();
476 
477  if ( iHit.eventId().rawId() == 0 ) eeSignalSimMap[crystid] += iHit.energy();
478 
479  if ( meEEbunchCrossing_ ) meEEbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
480 
481  }
482 
483  // loop over Digis
484 
485  const EEDigiCollection * endcapDigi = EcalDigiEE.product () ;
486 
487  std::vector<double> eeAnalogSignal ;
488  std::vector<double> eeADCCounts ;
489  std::vector<double> eeADCGains ;
490  eeAnalogSignal.reserve(EEDataFrame::MAXSAMPLES);
491  eeADCCounts.reserve(EEDataFrame::MAXSAMPLES);
492  eeADCGains.reserve(EEDataFrame::MAXSAMPLES);
493 
494  for (unsigned int digis=0; digis<EcalDigiEE->size(); ++digis) {
495 
496  EEDataFrame eedf=(*endcapDigi)[digis];
497  int nrSamples=eedf.size();
498 
499  EEDetId eeid = eedf.id () ;
500 
501  double Emax = 0. ;
502  int Pmax = 0 ;
503 
504  for (int sample = 0 ; sample < nrSamples; ++sample) {
505  eeAnalogSignal[sample] = 0.;
506  eeADCCounts[sample] = 0.;
507  eeADCGains[sample] = -1.;
508  }
509 
510  for (int sample = 0 ; sample < nrSamples; ++sample) {
511 
513 
514  eeADCCounts[sample] = (mySample.adc()) ;
515  eeADCGains[sample] = (mySample.gainId()) ;
516  eeAnalogSignal[sample] = (eeADCCounts[sample]*gainConv_[(int)eeADCGains[sample]]*endcapADCtoGeV_);
517  if (Emax < eeAnalogSignal[sample] ) {
518  Emax = eeAnalogSignal[sample] ;
519  Pmax = sample ;
520  }
521  LogDebug("DigiInfo") << "EE sample " << sample << " ADC counts = " << eeADCCounts[sample] << " Gain Id = " << eeADCGains[sample] << " Analog eq = " << eeAnalogSignal[sample];
522  }
523  double pedestalPreSampleAnalog = 0.;
524  findPedestal( eeid, (int)eeADCGains[Pmax] , pedestalPreSampleAnalog);
525  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[Pmax]]*endcapADCtoGeV_;
526  double Erec = Emax - pedestalPreSampleAnalog;
527 
528  if ( eeSignalSimMap[eeid.rawId()] != 0. ) {
529  LogDebug("DigiInfo") << " Digi / Signal Hit = " << Erec << " / " << eeSignalSimMap[eeid.rawId()] << " gainConv " << gainConv_[(int)eeADCGains[Pmax]];
530  if ( Erec > 100.*endcapADCtoGeV_ && meEEDigiMixRatiogt100ADC_ ) meEEDigiMixRatiogt100ADC_->Fill( Erec/eeSignalSimMap[eeid.rawId()] );
531  if ( eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEEDigiMixRatioOriggt40pc_ ) meEEDigiMixRatioOriggt40pc_->Fill( Erec/eeSignalSimMap[eeid.rawId()] );
532  if ( eeSignalSimMap[eeid.rawId()] > eeSimThreshold && meEBShape_ ) {
533  for ( int i = 0; i < 10 ; i++ ) {
534  pedestalPreSampleAnalog = 0.;
535  findPedestal( eeid, (int)eeADCGains[i] , pedestalPreSampleAnalog);
536  pedestalPreSampleAnalog *= gainConv_[(int)eeADCGains[i]]*endcapADCtoGeV_;
537  meEEShape_->Fill(i, eeAnalogSignal[i]-pedestalPreSampleAnalog );
538  }
539  }
540  }
541  }
542 
543  EcalSubdetector thisDet = EcalEndcap;
544  computeSDBunchDigi(c, endcapHits, eeSignalSimMap, thisDet, eeSimThreshold, randomEngine(e.streamID()));
545  }
546 
547  if ( isPreshower) {
548 
549  e.getByToken(crossingFramePCaloHitESToken_, crossingFrame );
550  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
551 
552  MapType esSignalSimMap;
553 
554  for ( auto const & iHit : preshowerHits ) {
555 
556  ESDetId esid = ESDetId(iHit.id()) ;
557 
558  LogDebug("HitInfo")
559  << " CaloHit " << iHit.getName() << "\n"
560  << " DetID = "<<iHit.id()<< "ESDetId: z side " << esid.zside() << " plane " << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
561  << " Time = " << iHit.time() << " Event id. = " << iHit.eventId().rawId() << "\n"
562  << " Track Id = " << iHit.geantTrackId() << "\n"
563  << " Energy = " << iHit.energy();
564 
565  uint32_t stripid = esid.rawId();
566 
567  if ( iHit.eventId().rawId() == 0 ) esSignalSimMap[stripid] += iHit.energy();
568 
569  if ( meESbunchCrossing_ ) meESbunchCrossing_->Fill(iHit.eventId().bunchCrossing());
570 
571  // loop over Digis
572 
573  const ESDigiCollection * preshowerDigi = EcalDigiES.product () ;
574 
575  std::vector<double> esADCCounts ;
576  std::vector<double> esADCAnalogSignal ;
577  esADCCounts.reserve(ESDataFrame::MAXSAMPLES);
578  esADCAnalogSignal.reserve(ESDataFrame::MAXSAMPLES);
579 
580  for (unsigned int digis=0; digis<EcalDigiES->size(); ++digis) {
581 
582  ESDataFrame esdf=(*preshowerDigi)[digis];
583  int nrSamples=esdf.size();
584 
585  ESDetId esid = esdf.id () ;
586 
587  for (int sample = 0 ; sample < nrSamples; ++sample) {
588  esADCCounts[sample] = 0.;
589  esADCAnalogSignal[sample] = 0.;
590  }
591 
592  for (int sample = 0 ; sample < nrSamples; ++sample) {
593 
594  ESSample mySample = esdf[sample];
595 
596  esADCCounts[sample] = (mySample.adc()) ;
597  esBaseline_ = m_ESpeds->find(esid)->getMean() ;
598  const double factor ( esADCtokeV_/(*(m_ESmips->getMap().find(esid)) ) ) ;
599  esThreshold_ = 3.*m_ESeffwei*( (*m_ESpeds->find(esid)).getRms())/factor;
600  esADCAnalogSignal[sample] = (esADCCounts[sample]-esBaseline_)/factor;
601  }
602  LogDebug("DigiInfo") << "Preshower Digi for ESDetId: z side " << esid.zside() << " plane " << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip();
603  for ( int i = 0; i < 3 ; i++ ) {
604  LogDebug("DigiInfo") << "sample " << i << " ADC = " << esADCCounts[i] << " Analog eq = " << esADCAnalogSignal[i];
605  }
606 
607  if ( esSignalSimMap[esid.rawId()] > esThreshold_ && meESShape_ ) {
608  for ( int i = 0; i < 3 ; i++ ) {
609  meESShape_->Fill(i, esADCAnalogSignal[i] );
610  }
611  }
612 
613  }
614 
615  }
616 
617  EcalSubdetector thisDet = EcalPreshower;
618  computeSDBunchDigi(c, preshowerHits, esSignalSimMap, thisDet, esThreshold_, randomEngine(e.streamID()));
619 
620  }
621 
622 }
623 
625 
626  // ADC -> GeV Scale
628  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
629  const EcalADCToGeVConstant* agc = pAgc.product();
630 
631  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
632 
633  gainConv_[1] = 1.;
634  gainConv_[2] = defaultRatios->gain12Over6() ;
635  gainConv_[3] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
636  gainConv_[0] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
637 
638  LogDebug("EcalDigi") << " Gains conversions: " << "\n" << " g1 = " << gainConv_[1] << "\n" << " g2 = " << gainConv_[2] << "\n" << " g3 = " << gainConv_[3];
639 
640  delete defaultRatios;
641 
642  const double barrelADCtoGeV_ = agc->getEBValue();
643  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
644  const double endcapADCtoGeV_ = agc->getEEValue();
645  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
646 
647 
648  // ES condition objects
649  edm::ESHandle<ESGain> esgain_;
651  edm::ESHandle<ESPedestals> esPedestals_;
653 
654  eventSetup.get<ESGainRcd>().get(esgain_);
655  eventSetup.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
656  eventSetup.get<ESPedestalsRcd>().get(esPedestals_);
657  eventSetup.get<ESIntercalibConstantsRcd>().get(esMIPs_);
658 
659  const ESGain *esgain = esgain_.product();
660  m_ESpeds = esPedestals_.product();
661  m_ESmips = esMIPs_.product();
662  const ESMIPToGeVConstant *esMipToGeV = esMIPToGeV_.product();
663  m_ESgain = (int) esgain->getESGain();
664  const double valESMIPToGeV = (m_ESgain == 1) ? esMipToGeV->getESValueLow() : esMipToGeV->getESValueHigh();
665 
667 
668  esADCtokeV_ = 1000000.*valESMIPToGeV ;
669 
670  m_ESeffwei = ( 0 == m_ESgain ? 1.45 :
671  ( 1 == m_ESgain ? 0.9066 :
672  ( 2 == m_ESgain ? 0.8815 : 1.0 ) ) ) ;
673 
674 }
675 
677 {
678 
679  // Pedestals from event setup
680 
682  eventSetup.get<EcalPedestalsRcd>().get( dbPed );
683  thePedestals=dbPed.product();
684 
685 }
686 
687 void EcalMixingModuleValidation::findPedestal(const DetId & detId, int gainId, double & ped) const
688 {
690  = thePedestals->getMap().find(detId);
691  // should I care if it doesn't get found?
692  if(mapItr == thePedestals->getMap().end()) {
693  edm::LogError("EcalMMValid") << "Could not find pedestal for " << detId.rawId() << " among the " << thePedestals->getMap().size();
694  } else {
695  EcalPedestals::Item item = (*mapItr);
696 
697  switch(gainId) {
698  case 0:
699  ped = item.mean_x1;
700  case 1:
701  ped = item.mean_x12;
702  break;
703  case 2:
704  ped = item.mean_x6;
705  break;
706  case 3:
707  ped = item.mean_x1;
708  break;
709  default:
710  edm::LogError("EcalMMValid") << "Bad Pedestal " << gainId;
711  break;
712  }
713  LogDebug("EcalMMValid") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n" << "Mean = " << ped;
714  }
715 }
716 
717 void EcalMixingModuleValidation::computeSDBunchDigi(const edm::EventSetup & eventSetup, const MixCollection<PCaloHit> & theHits, MapType & SignalSimMap, const EcalSubdetector & thisDet, const double & theSimThreshold, CLHEP::HepRandomEngine* engine)
718 {
719 
720  if ( thisDet != EcalBarrel && thisDet != EcalEndcap && thisDet != EcalPreshower ) {
721  edm::LogError("EcalMMValid") << "Invalid subdetector type";
722  return;
723  }
724  //bool isCrystal = true;
725  //if ( thisDet == EcalPreshower ) isCrystal = false;
726 
727  // load the geometry
728 
729  edm::ESHandle<CaloGeometry> hGeometry;
730  eventSetup.get<CaloGeometryRecord>().get(hGeometry);
731 
732  const CaloGeometry * pGeometry = &*hGeometry;
733 
734  // see if we need to update
735  if(pGeometry != theGeometry) {
736  theGeometry = pGeometry;
737  //theEcalResponse->setGeometry(theGeometry);
741 
742  }
743 
744  // vector of DetId with energy above a fraction of the gun's energy
745 
746  const std::vector<DetId>& theSDId = theGeometry->getValidDetIds( DetId::Ecal, thisDet );
747 
748  std::vector<DetId> theOverThresholdId;
749  for ( unsigned int i = 0 ; i < theSDId.size() ; i++ ) {
750 
751  int sdId = theSDId[i].rawId();
752  if ( SignalSimMap[sdId] > theSimThreshold ) theOverThresholdId.push_back( theSDId[i] );
753 
754  }
755 
757  if ( thisDet == EcalPreshower ) limit = ESDataFrame::MAXSAMPLES;
758 
759  for (int iBunch = theMinBunch ; iBunch <= theMaxBunch ; iBunch++ ) {
760 
761  //if ( isCrystal ) {
762  if( thisDet == EcalBarrel ) {
763  theEBResponse->setBunchRange(iBunch, iBunch);
764  theEBResponse->clear();
765  theEBResponse->run(theHits, engine);
766  }
767  else if( thisDet == EcalEndcap ) {
768  theEEResponse->setBunchRange(iBunch, iBunch);
769  theEEResponse->clear();
770  theEEResponse->run(theHits, engine);
771  }
772  else {
773  theESResponse->setBunchRange(iBunch, iBunch);
774  theESResponse->clear();
775  theESResponse->run(theHits, engine);
776  }
777 
778  int iHisto = iBunch - theMinBunch;
779 
780  for ( std::vector<DetId>::const_iterator idItr = theOverThresholdId.begin() ; idItr != theOverThresholdId.end() ; ++idItr ) {
781 
782  CaloSamples * analogSignal;
783  //if ( isCrystal )
784  if( thisDet == EcalBarrel ) {
785  analogSignal = theEBResponse->findSignal(*idItr);
786  }
787  else if( thisDet == EcalEndcap ) {
788  analogSignal = theEEResponse->findSignal(*idItr);
789  }
790  else {
791  analogSignal = theESResponse->findSignal(*idItr);
792  }
793 
794  if ( analogSignal ) {
795 
796  (*analogSignal) *= theParameterMap->simParameters(analogSignal->id()).photoelectronsToAnalog();
797 
798  for ( int i = 0 ; i < limit ; i++ ) {
799  if ( thisDet == EcalBarrel ) { meEBBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
800  else if ( thisDet == EcalEndcap ) { meEEBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
801  else if ( thisDet == EcalPreshower ) { meESBunchShape_[iHisto]->Fill(i,(float)(*analogSignal)[i]); }
802  }
803  }
804 
805  }
806 
807  }
808 
809  }
810 
811 CLHEP::HepRandomEngine* EcalMixingModuleValidation::randomEngine(edm::StreamID const& streamID) {
812  unsigned int index = streamID.value();
813  if(index >= randomEngines_.size()) {
814  randomEngines_.resize(index + 1, nullptr);
815  }
816  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
817  if(!ptr) {
819  ptr = &rng->getEngine(streamID);
820  randomEngines_[index] = ptr;
821  }
822  return ptr;
823 }
#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:160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
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
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
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
edm::EDGetTokenT< CrossingFrame< PCaloHit > > crossingFramePCaloHitEEToken_
int siy() const
Definition: ESDetId.h:51
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:118
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
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.
const T & get() const
Definition: EventSetup.h:59
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.
Definition: CaloGeometry.cc:97
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
StreamID streamID() const
Definition: Event.h:95
int plane() const
Definition: ESDetId.h:47
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
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:86
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
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:43
Definition: EEShape.h:6
int adc() const
get the ADC sample (12 bits)