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