CMS 3D CMS Logo

EcalRecHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalRecHitsValidation.cc
3  *
4  * \author C. Rovelli
5  *
6  */
7 
17 #include <string>
18 
19 using namespace cms;
20 using namespace edm;
21 using namespace std;
22 
24  // ----------------------
25  HepMCLabel = ps.getParameter<std::string>("moduleLabelMC");
26  hitsProducer_ = ps.getParameter<std::string>("hitsProducer");
27  EBrechitCollection_ = ps.getParameter<edm::InputTag>("EBrechitCollection");
28  EErechitCollection_ = ps.getParameter<edm::InputTag>("EErechitCollection");
29  ESrechitCollection_ = ps.getParameter<edm::InputTag>("ESrechitCollection");
30  EBuncalibrechitCollection_ = ps.getParameter<edm::InputTag>("EBuncalibrechitCollection");
31  EEuncalibrechitCollection_ = ps.getParameter<edm::InputTag>("EEuncalibrechitCollection");
32  // switch to allow disabling endcaps for phase 2
33  enableEndcaps_ = ps.getUntrackedParameter<bool>("enableEndcaps", true);
34 
35  // fix for consumes
36  HepMCLabel_Token_ = consumes<HepMCProduct>(ps.getParameter<std::string>("moduleLabelMC"));
37  EBrechitCollection_Token_ = consumes<EBRecHitCollection>(ps.getParameter<edm::InputTag>("EBrechitCollection"));
38  EBuncalibrechitCollection_Token_ =
39  consumes<EBUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EBuncalibrechitCollection"));
40 
41  EBHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
42  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEB")));
43  if (enableEndcaps_) {
44  EErechitCollection_Token_ = consumes<EERecHitCollection>(ps.getParameter<edm::InputTag>("EErechitCollection"));
45  ESrechitCollection_Token_ = consumes<ESRecHitCollection>(ps.getParameter<edm::InputTag>("ESrechitCollection"));
46  EEuncalibrechitCollection_Token_ =
47  consumes<EEUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EEuncalibrechitCollection"));
48  EEHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
49  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEE")));
50  ESHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
51  edm::InputTag(std::string("mix"), ps.getParameter<std::string>("hitsProducer") + std::string("EcalHitsES")));
52  }
53 
54  // ----------------------
55  // DQM ROOT output
56  outputFile_ = ps.getUntrackedParameter<string>("outputFile", "");
57 
58  if (!outputFile_.empty()) {
59  LogInfo("OutputInfo") << " Ecal RecHits Task histograms will be saved to '" << outputFile_.c_str() << "'";
60  } else {
61  LogInfo("OutputInfo") << " Ecal RecHits Task histograms will NOT be saved";
62  }
63 
64  // ----------------------
65  // verbosity switch
66  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
67 
68  // ----------------------
69  meGunEnergy_ = nullptr;
70  meGunEta_ = nullptr;
71  meGunPhi_ = nullptr;
72  meEBRecHitSimHitRatio_ = nullptr;
73  meEERecHitSimHitRatio_ = nullptr;
74  meESRecHitSimHitRatio_ = nullptr;
75  meEBRecHitSimHitRatio1011_ = nullptr;
76  meEERecHitSimHitRatio1011_ = nullptr;
77  meEBRecHitSimHitRatio12_ = nullptr;
78  meEERecHitSimHitRatio12_ = nullptr;
79  meEBRecHitSimHitRatio13_ = nullptr;
80  meEERecHitSimHitRatio13_ = nullptr;
81  meEBRecHitSimHitRatioGt35_ = nullptr;
82  meEERecHitSimHitRatioGt35_ = nullptr;
83  meEBUnRecHitSimHitRatio_ = nullptr;
84  meEEUnRecHitSimHitRatio_ = nullptr;
85  meEBUnRecHitSimHitRatioGt35_ = nullptr;
86  meEEUnRecHitSimHitRatioGt35_ = nullptr;
87  meEBe5x5_ = nullptr;
88  meEBe5x5OverSimHits_ = nullptr;
89  meEBe5x5OverGun_ = nullptr;
90  meEEe5x5_ = nullptr;
91  meEEe5x5OverSimHits_ = nullptr;
92  meEEe5x5OverGun_ = nullptr;
93 
94  meEBRecHitLog10Energy_ = nullptr;
95  meEERecHitLog10Energy_ = nullptr;
96  meESRecHitLog10Energy_ = nullptr;
97  meEBRecHitLog10EnergyContr_ = nullptr;
98  meEERecHitLog10EnergyContr_ = nullptr;
99  meESRecHitLog10EnergyContr_ = nullptr;
100  meEBRecHitLog10Energy5x5Contr_ = nullptr;
101  meEERecHitLog10Energy5x5Contr_ = nullptr;
102 
103  meEBRecHitsOccupancyFlag5_6_ = nullptr;
104  meEBRecHitsOccupancyFlag8_9_ = nullptr;
105  meEERecHitsOccupancyPlusFlag5_6_ = nullptr;
106  meEERecHitsOccupancyMinusFlag5_6_ = nullptr;
107  meEERecHitsOccupancyPlusFlag8_9_ = nullptr;
108  meEERecHitsOccupancyMinusFlag8_9_ = nullptr;
109 
110  meEBRecHitFlags_ = nullptr;
111  meEBRecHitSimHitvsSimHitFlag5_6_ = nullptr;
112  meEBRecHitSimHitFlag6_ = nullptr;
113  meEBRecHitSimHitFlag7_ = nullptr;
114  meEB5x5RecHitSimHitvsSimHitFlag8_ = nullptr;
115 
116  meEERecHitFlags_ = nullptr;
117  meEERecHitSimHitvsSimHitFlag5_6_ = nullptr;
118  meEERecHitSimHitFlag6_ = nullptr;
119  meEERecHitSimHitFlag7_ = nullptr;
120 }
121 
123 
126 
127  ibooker.setCurrentFolder("EcalRecHitsV/EcalRecHitsTask");
128 
129  histo = "EcalRecHitsTask Gun Momentum";
130  meGunEnergy_ = ibooker.book1D(histo.c_str(), histo.c_str(), 100, 0., 1000.);
131 
132  histo = "EcalRecHitsTask Gun Eta";
133  meGunEta_ = ibooker.book1D(histo.c_str(), histo.c_str(), 700, -3.5, 3.5);
134 
135  histo = "EcalRecHitsTask Gun Phi";
136  meGunPhi_ = ibooker.book1D(histo.c_str(), histo.c_str(), 360, 0., 360.);
137 
138  histo = "EcalRecHitsTask Barrel RecSimHit Ratio";
139  meEBRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
140 
141  histo = "EcalRecHitsTask Barrel RecSimHit Ratio gt 3p5 GeV";
142  meEBRecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
143 
144  histo = "EcalRecHitsTask Barrel Unc RecSimHit Ratio";
145  meEBUnRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
146 
147  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Channel Status=10 11";
148  meEBRecHitSimHitRatio1011_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
149 
150  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Channel Status=12";
151  meEBRecHitSimHitRatio12_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
152 
153  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Channel Status=13";
154  meEBRecHitSimHitRatio13_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
155 
156  histo = "EcalRecHitsTask Barrel Unc RecSimHit Ratio gt 3p5 GeV";
157  meEBUnRecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
158 
159  histo = "EcalRecHitsTask Barrel Rec E5x5";
160  meEBe5x5_ = ibooker.book1D(histo.c_str(), histo.c_str(), 4000, 0., 400.);
161 
162  histo = "EcalRecHitsTask Barrel Rec E5x5 over Sim E5x5";
163  meEBe5x5OverSimHits_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
164 
165  histo = "EcalRecHitsTask Barrel Rec E5x5 over gun energy";
166  meEBe5x5OverGun_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
167 
168  meEBRecHitLog10Energy_ =
169  ibooker.book1D("EcalRecHitsTask Barrel Log10 Energy", "EcalRecHitsTask Barrel Log10 Energy", 90, -5., 4.);
170  meEBRecHitLog10EnergyContr_ = ibooker.bookProfile("EcalRecHits Barrel Log10En vs Hit Contribution",
171  "EcalRecHits Barrel Log10En vs Hit Contribution",
172  90,
173  -5.,
174  4.,
175  100,
176  0.,
177  1.);
178  meEBRecHitLog10Energy5x5Contr_ = ibooker.bookProfile("EcalRecHits Barrel Log10En5x5 vs Hit Contribution",
179  "EcalRecHits Barrel Log10En5x5 vs Hit Contribution",
180  90,
181  -5.,
182  4.,
183  100,
184  0.,
185  1.);
186 
187  histo = "EB Occupancy Flag=5 6";
188  meEBRecHitsOccupancyFlag5_6_ = ibooker.book2D(histo, histo, 170, -85., 85., 360, 0., 360.);
189  histo = "EB Occupancy Flag=8 9";
190  meEBRecHitsOccupancyFlag8_9_ = ibooker.book2D(histo, histo, 170, -85., 85., 360, 0., 360.);
191 
192  histo = "EcalRecHitsTask Barrel Reco Flags";
193  meEBRecHitFlags_ = ibooker.book1D(histo.c_str(), histo.c_str(), 10, 0., 10.);
194  histo = "EcalRecHitsTask Barrel RecSimHit Ratio vs SimHit Flag=5 6";
195  meEBRecHitSimHitvsSimHitFlag5_6_ = ibooker.book2D(histo.c_str(), histo.c_str(), 80, 0., 2., 4000, 0., 400.);
196  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Flag=6";
197  meEBRecHitSimHitFlag6_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
198  histo = "EcalRecHitsTask Barrel RecSimHit Ratio Flag=7";
199  meEBRecHitSimHitFlag7_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
200  histo = "EcalRecHitsTask Barrel 5x5 RecSimHit Ratio vs SimHit Flag=8";
201  meEB5x5RecHitSimHitvsSimHitFlag8_ = ibooker.book2D(histo.c_str(), histo.c_str(), 80, 0., 2., 4000, 0., 400.);
202 
203  if (enableEndcaps_) {
204  histo = "EcalRecHitsTask Preshower RecSimHit Ratio";
205  meESRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
206 
207  histo = "EcalRecHitsTask Endcap RecSimHit Ratio";
208  meEERecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
209 
210  histo = "EcalRecHitsTask Endcap RecSimHit Ratio gt 3p5 GeV";
211  meEERecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
212 
213  histo = "EcalRecHitsTask Endcap Unc RecSimHit Ratio";
214  meEEUnRecHitSimHitRatio_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
215 
216  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Channel Status=10 11";
217  meEERecHitSimHitRatio1011_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
218 
219  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Channel Status=12";
220  meEERecHitSimHitRatio12_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
221 
222  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Channel Status=13";
223  meEERecHitSimHitRatio13_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
224 
225  histo = "EcalRecHitsTask Endcap Unc RecSimHit Ratio gt 3p5 GeV";
226  meEEUnRecHitSimHitRatioGt35_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
227 
228  histo = "EcalRecHitsTask Endcap Rec E5x5";
229  meEEe5x5_ = ibooker.book1D(histo.c_str(), histo.c_str(), 4000, 0., 400.);
230 
231  histo = "EcalRecHitsTask Endcap Rec E5x5 over Sim E5x5";
232  meEEe5x5OverSimHits_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
233 
234  histo = "EcalRecHitsTask Endcap Rec E5x5 over gun energy";
235  meEEe5x5OverGun_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0.9, 1.1);
236 
237  meEERecHitLog10Energy_ =
238  ibooker.book1D("EcalRecHitsTask Endcap Log10 Energy", "EcalRecHitsTask Endcap Log10 Energy", 90, -5., 4.);
239  meESRecHitLog10Energy_ =
240  ibooker.book1D("EcalRecHitsTask Preshower Log10 Energy", "EcalRecHitsTask Preshower Log10 Energy", 90, -5., 4.);
241 
242  meEERecHitLog10EnergyContr_ = ibooker.bookProfile("EcalRecHits Endcap Log10En vs Hit Contribution",
243  "EcalRecHits Endcap Log10En vs Hit Contribution",
244  90,
245  -5.,
246  4.,
247  100,
248  0.,
249  1.);
250  meESRecHitLog10EnergyContr_ = ibooker.bookProfile("EcalRecHits Preshower Log10En vs Hit Contribution",
251  "EcalRecHits Preshower Log10En vs Hit Contribution",
252  90,
253  -5.,
254  4.,
255  100,
256  0.,
257  1.);
258 
259  meEERecHitLog10Energy5x5Contr_ = ibooker.bookProfile("EcalRecHits Endcap Log10En5x5 vs Hit Contribution",
260  "EcalRecHits Endcap Log10En5x5 vs Hit Contribution",
261  90,
262  -5.,
263  4.,
264  100,
265  0.,
266  1.);
267 
268  histo = "EE+ Occupancy Flag=5 6";
269  meEERecHitsOccupancyPlusFlag5_6_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
270  histo = "EE- Occupancy Flag=5 6";
271  meEERecHitsOccupancyMinusFlag5_6_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
272  histo = "EE+ Occupancy Flag=8 9";
273  meEERecHitsOccupancyPlusFlag8_9_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
274  histo = "EE- Occupancy Flag=8 9";
275  meEERecHitsOccupancyMinusFlag8_9_ = ibooker.book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
276 
277  histo = "EcalRecHitsTask Endcap Reco Flags";
278  meEERecHitFlags_ = ibooker.book1D(histo.c_str(), histo.c_str(), 10, 0., 10.);
279 
280  histo = "EcalRecHitsTask Endcap RecSimHit Ratio vs SimHit Flag=5 6";
281  meEERecHitSimHitvsSimHitFlag5_6_ = ibooker.book2D(histo.c_str(), histo.c_str(), 80, 0., 2., 4000, 0., 400.);
282 
283  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Flag=6";
284  meEERecHitSimHitFlag6_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
285 
286  histo = "EcalRecHitsTask Endcap RecSimHit Ratio Flag=7";
287  meEERecHitSimHitFlag7_ = ibooker.book1D(histo.c_str(), histo.c_str(), 80, 0., 2.);
288  }
289 }
290 
292  // Temporary stuff
293 
294  LogInfo("EcalRecHitsTask, EventInfo: ") << " Run = " << e.id().run() << " Event = " << e.id().event();
295 
296  // ADC -> GeV Scale
298  c.get<EcalADCToGeVConstantRcd>().get(pAgc);
299  const EcalADCToGeVConstant *agc = pAgc.product();
300  const double barrelADCtoGeV_ = agc->getEBValue();
301  const double endcapADCtoGeV_ = agc->getEEValue();
302 
303  Handle<HepMCProduct> MCEvt;
304  bool skipMC = false;
305  e.getByToken(HepMCLabel_Token_, MCEvt);
306  if (!MCEvt.isValid()) {
307  skipMC = true;
308  }
309 
311 
312  bool skipBarrel = false;
314  Handle<EBUncalibratedRecHitCollection> EcalUncalibRecHitEB;
315  e.getByToken(EBuncalibrechitCollection_Token_, EcalUncalibRecHitEB);
316  if (EcalUncalibRecHitEB.isValid()) {
317  EBUncalibRecHit = EcalUncalibRecHitEB.product();
318  } else {
319  skipBarrel = true;
320  }
321 
322  bool skipEndcap = false;
324  Handle<EEUncalibratedRecHitCollection> EcalUncalibRecHitEE;
325  if (enableEndcaps_) {
326  e.getByToken(EEuncalibrechitCollection_Token_, EcalUncalibRecHitEE);
327  if (EcalUncalibRecHitEE.isValid()) {
328  EEUncalibRecHit = EcalUncalibRecHitEE.product();
329  } else {
330  skipEndcap = true;
331  }
332  } else
333  skipEndcap = true;
334 
335  const EBRecHitCollection *EBRecHit = nullptr;
336  Handle<EBRecHitCollection> EcalRecHitEB;
337  e.getByToken(EBrechitCollection_Token_, EcalRecHitEB);
338  if (EcalRecHitEB.isValid()) {
339  EBRecHit = EcalRecHitEB.product();
340  } else {
341  skipBarrel = true;
342  }
343 
344  const EERecHitCollection *EERecHit = nullptr;
345  Handle<EERecHitCollection> EcalRecHitEE;
346  if (enableEndcaps_) {
347  e.getByToken(EErechitCollection_Token_, EcalRecHitEE);
348  if (EcalRecHitEE.isValid()) {
349  EERecHit = EcalRecHitEE.product();
350  } else {
351  skipEndcap = true;
352  }
353  }
354 
355  bool skipPreshower = false;
356  const ESRecHitCollection *ESRecHit = nullptr;
357  Handle<ESRecHitCollection> EcalRecHitES;
358  if (enableEndcaps_) {
359  e.getByToken(ESrechitCollection_Token_, EcalRecHitES);
360  if (EcalRecHitES.isValid()) {
361  ESRecHit = EcalRecHitES.product();
362  } else {
363  skipPreshower = true;
364  }
365  } else
366  skipPreshower = true;
367 
368  // ----------------------
369  // gun
370  double eGun = 0.;
371  if (!skipMC) {
372  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
373  p != MCEvt->GetEvent()->particles_end();
374  ++p) {
375  double htheta = (*p)->momentum().theta();
376  double heta = -99999.;
377  if (tan(htheta * 0.5) > 0) {
378  heta = -log(tan(htheta * 0.5));
379  }
380  double hphi = (*p)->momentum().phi();
381  hphi = (hphi >= 0) ? hphi : hphi + 2 * M_PI;
382  hphi = hphi / M_PI * 180.;
383 
384  LogDebug("EventInfo") << "EcalRecHitsTask: Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n"
385  << "Energy = " << (*p)->momentum().e() << "\n"
386  << "Eta = " << heta << "\n"
387  << "Phi = " << hphi;
388 
389  if ((*p)->momentum().e() > eGun)
390  eGun = (*p)->momentum().e();
391 
392  if (meGunEnergy_)
393  meGunEnergy_->Fill((*p)->momentum().e());
394  if (meGunEta_)
395  meGunEta_->Fill(heta);
396  if (meGunPhi_)
397  meGunPhi_->Fill(hphi);
398  }
399  }
400 
401  // -------------------------------------------------------------------
402  // BARREL
403 
404  if (!skipBarrel) {
405  // 1) loop over simHits
406  e.getByToken(EBHits_Token_, crossingFrame);
407  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
408 
409  MapType ebSimMap;
410  MapType ebRecMap;
411  const int ebcSize = 90;
412  double ebcontr[ebcSize];
413  double ebcontr25[ebcSize];
414  for (int i = 0; i < ebcSize; i++) {
415  ebcontr[i] = 0.0;
416  ebcontr25[i] = 0.0;
417  }
418  double ebtotal = 0.;
419 
420  for (auto const &iHit : barrelHits) {
421  EBDetId ebid = EBDetId(iHit.id());
422 
423  LogDebug("SimHitInfo, barrel") << "CaloHit " << iHit.getName() << " DetID = " << iHit.id() << "\n"
424  << "Energy = " << iHit.energy() << " Time = " << iHit.time() << "\n"
425  << "EBDetId = " << ebid.ieta() << " " << ebid.iphi();
426 
427  uint32_t crystid = ebid.rawId();
428  ebSimMap[crystid] += iHit.energy();
429  }
430 
431  // 2) loop over RecHits
432  for (EcalUncalibratedRecHitCollection::const_iterator uncalibRecHit = EBUncalibRecHit->begin();
433  uncalibRecHit != EBUncalibRecHit->end();
434  ++uncalibRecHit) {
435  EBDetId EBid = EBDetId(uncalibRecHit->id());
436 
437  // Find corresponding recHit
438  EcalRecHitCollection::const_iterator myRecHit = EBRecHit->find(EBid);
439  if (myRecHit == EBRecHit->end())
440  continue;
441  ebRecMap[EBid.rawId()] += myRecHit->energy();
442 
443  // Fill log10(Energy) stuff...
444  ebtotal += myRecHit->energy();
445  if (myRecHit->energy() > 0) {
446  if (meEBRecHitLog10Energy_)
447  meEBRecHitLog10Energy_->Fill(log10(myRecHit->energy()));
448  int log10i = int((log10(myRecHit->energy()) + 5.) * 10.);
449  if (log10i >= 0 and log10i < ebcSize)
450  ebcontr[log10i] += myRecHit->energy();
451  }
452 
453  // comparison Rec/Sim hit
454  if (ebSimMap[EBid.rawId()] != 0.) {
455  double uncEnergy = uncalibRecHit->amplitude() * barrelADCtoGeV_;
456  if (meEBUnRecHitSimHitRatio_) {
457  meEBUnRecHitSimHitRatio_->Fill(uncEnergy / ebSimMap[EBid.rawId()]);
458  }
459  if (meEBUnRecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
460  meEBUnRecHitSimHitRatioGt35_->Fill(uncEnergy / ebSimMap[EBid.rawId()]);
461  }
462  }
463 
464  if (myRecHit != EBRecHit->end()) {
465  if (ebSimMap[EBid.rawId()] != 0.) {
466  if (meEBRecHitSimHitRatio_) {
467  meEBRecHitSimHitRatio_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
468  }
469  if (meEBRecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
470  meEBRecHitSimHitRatioGt35_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
471  }
472  uint16_t sc = 0;
474  c.get<EcalChannelStatusRcd>().get(pEcs);
475  const EcalChannelStatus *ecs = nullptr;
476  if (pEcs.isValid())
477  ecs = pEcs.product();
478  if (ecs != nullptr) {
479  EcalChannelStatusMap::const_iterator csmi = ecs->find(EBid.rawId());
481  if (csmi != ecs->end())
482  csc = *csmi;
483  sc = csc.getStatusCode();
484  }
485 
486  if (meEBRecHitSimHitRatio1011_ != nullptr && (sc == 10 || sc == 11)) {
487  meEBRecHitSimHitRatio1011_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
488  }
489  if (meEBRecHitSimHitRatio12_ != nullptr && sc == 12) {
490  meEBRecHitSimHitRatio12_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
491  }
492 
494  c.get<IdealGeometryRecord>().get(pttMap);
495  const EcalTrigTowerConstituentsMap *ttMap = nullptr;
496  if (pttMap.isValid())
497  ttMap = pttMap.product();
498  double ttSimEnergy = 0;
499  if (ttMap != nullptr) {
500  EcalTrigTowerDetId ttDetId = EBid.tower();
501  std::vector<DetId> vid = ttMap->constituentsOf(ttDetId);
502  for (std::vector<DetId>::const_iterator dit = vid.begin(); dit != vid.end(); dit++) {
503  EBDetId ttEBid = EBDetId(*dit);
504  ttSimEnergy += ebSimMap[ttEBid.rawId()];
505  }
506  if (!vid.empty())
507  ttSimEnergy = ttSimEnergy / vid.size();
508  }
509  if (meEBRecHitSimHitRatio13_ != nullptr && sc == 13 && ttSimEnergy != 0)
510  meEBRecHitSimHitRatio13_->Fill(myRecHit->energy() / ttSimEnergy);
511 
512  int flag = myRecHit->recoFlag();
513  if (meEBRecHitFlags_ != nullptr)
514  meEBRecHitFlags_->Fill(flag);
515  if (meEBRecHitSimHitvsSimHitFlag5_6_ &&
517  meEBRecHitSimHitvsSimHitFlag5_6_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()], ebSimMap[EBid.rawId()]);
518  if (meEBRecHitSimHitFlag6_ && (flag == EcalRecHit::kLeadingEdgeRecovered))
519  meEBRecHitSimHitFlag6_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
520  if (meEBRecHitSimHitFlag7_ && (flag == EcalRecHit::kNeighboursRecovered))
521  meEBRecHitSimHitFlag6_->Fill(myRecHit->energy() / ebSimMap[EBid.rawId()]);
522  if (meEB5x5RecHitSimHitvsSimHitFlag8_ && (flag == EcalRecHit::kTowerRecovered) && ttSimEnergy != 0)
523  meEB5x5RecHitSimHitvsSimHitFlag8_->Fill(myRecHit->energy() / ttSimEnergy, ttSimEnergy);
524 
525  if (meEBRecHitsOccupancyFlag5_6_ &&
527  meEBRecHitsOccupancyFlag5_6_->Fill(EBid.ieta(), EBid.iphi());
528  if (meEBRecHitsOccupancyFlag8_9_ && ((flag == EcalRecHit::kTowerRecovered) || (flag == EcalRecHit::kDead)))
529  meEBRecHitsOccupancyFlag8_9_->Fill(EBid.ieta(), EBid.iphi());
530  }
531  } else
532  continue;
533  } // loop over the UncalibratedRecHitCollection
534 
535  // RecHits matrix
536  uint32_t ebcenterid = getUnitWithMaxEnergy(ebRecMap);
537  EBDetId myEBid(ebcenterid);
538  int bx = myEBid.ietaAbs();
539  int by = myEBid.iphi();
540  int bz = myEBid.zside();
541  findBarrelMatrix(5, 5, bx, by, bz, ebRecMap);
542  double e5x5rec = 0.;
543  double e5x5sim = 0.;
544  for (unsigned int i = 0; i < crystalMatrix.size(); i++) {
545  e5x5rec += ebRecMap[crystalMatrix[i]];
546  e5x5sim += ebSimMap[crystalMatrix[i]];
547  if (ebRecMap[crystalMatrix[i]] > 0) {
548  int log10i25 = int((log10(ebRecMap[crystalMatrix[i]]) + 5.) * 10.);
549  if (log10i25 >= 0 && log10i25 < ebcSize)
550  ebcontr25[log10i25] += ebRecMap[crystalMatrix[i]];
551  }
552  }
553 
554  if (meEBe5x5_)
555  meEBe5x5_->Fill(e5x5rec);
556  if (e5x5sim > 0. && meEBe5x5OverSimHits_)
557  meEBe5x5OverSimHits_->Fill(e5x5rec / e5x5sim);
558  if (eGun > 0. && meEBe5x5OverGun_)
559  meEBe5x5OverGun_->Fill(e5x5rec / eGun);
560 
561  if (meEBRecHitLog10EnergyContr_ && ebtotal != 0) {
562  for (int i = 0; i < ebcSize; i++) {
563  meEBRecHitLog10EnergyContr_->Fill(-5. + (float(i) + 0.5) / 10., ebcontr[i] / ebtotal);
564  }
565  }
566 
567  if (meEBRecHitLog10Energy5x5Contr_ && e5x5rec != 0) {
568  for (int i = 0; i < ebcSize; i++) {
569  meEBRecHitLog10Energy5x5Contr_->Fill(-5. + (float(i) + 0.5) / 10., ebcontr25[i] / e5x5rec);
570  }
571  }
572  }
573 
574  // -------------------------------------------------------------------
575  // ENDCAP
576 
577  if (!skipEndcap) {
578  // 1) loop over simHits
579  e.getByToken(EEHits_Token_, crossingFrame);
580  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
581 
582  MapType eeSimMap;
583  MapType eeRecMap;
584  const int eecSize = 90;
585  double eecontr[eecSize];
586  double eecontr25[eecSize];
587  for (int i = 0; i < eecSize; i++) {
588  eecontr[i] = 0.0;
589  eecontr25[i] = 0.0;
590  }
591  double eetotal = 0.;
592 
593  for (auto const &iHit : endcapHits) {
594  EEDetId eeid(iHit.id());
595 
596  LogDebug("Endcap, HitInfo") << " CaloHit " << iHit.getName() << " DetID = " << iHit.id() << "\n"
597  << "Energy = " << iHit.energy() << " Time = " << iHit.time() << "\n"
598  << "EEDetId side " << eeid.zside() << " = " << eeid.ix() << " " << eeid.iy();
599 
600  uint32_t crystid = eeid.rawId();
601  eeSimMap[crystid] += iHit.energy();
602  }
603 
604  // 2) loop over RecHits
605  for (EcalUncalibratedRecHitCollection::const_iterator uncalibRecHit = EEUncalibRecHit->begin();
606  uncalibRecHit != EEUncalibRecHit->end();
607  ++uncalibRecHit) {
608  EEDetId EEid = EEDetId(uncalibRecHit->id());
609 
610  // Find corresponding recHit
611  EcalRecHitCollection::const_iterator myRecHit = EERecHit->find(EEid);
612  if (myRecHit == EERecHit->end())
613  continue;
614  eeRecMap[EEid.rawId()] += myRecHit->energy();
615 
616  // Fill log10(Energy) stuff...
617  eetotal += myRecHit->energy();
618  if (myRecHit->energy() > 0) {
619  if (meEERecHitLog10Energy_)
620  meEERecHitLog10Energy_->Fill(log10(myRecHit->energy()));
621  int log10i = int((log10(myRecHit->energy()) + 5.) * 10.);
622  if (log10i >= 0 and log10i < eecSize)
623  eecontr[log10i] += myRecHit->energy();
624  }
625 
626  // comparison Rec/Sim hit
627  if (eeSimMap[EEid.rawId()] != 0.) {
628  double uncEnergy = uncalibRecHit->amplitude() * endcapADCtoGeV_;
629  if (meEEUnRecHitSimHitRatio_) {
630  meEEUnRecHitSimHitRatio_->Fill(uncEnergy / eeSimMap[EEid.rawId()]);
631  }
632  if (meEEUnRecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
633  meEEUnRecHitSimHitRatioGt35_->Fill(uncEnergy / eeSimMap[EEid.rawId()]);
634  }
635  }
636 
637  if (myRecHit != EERecHit->end()) {
638  if (eeSimMap[EEid.rawId()] != 0.) {
639  if (meEERecHitSimHitRatio_) {
640  meEERecHitSimHitRatio_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
641  }
642  if (meEERecHitSimHitRatioGt35_ && (myRecHit->energy() > 3.5)) {
643  meEERecHitSimHitRatioGt35_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
644  }
645 
647  c.get<EcalChannelStatusRcd>().get(pEcs);
648  const EcalChannelStatus *ecs = nullptr;
649  if (pEcs.isValid())
650  ecs = pEcs.product();
651  if (ecs != nullptr) {
652  EcalChannelStatusMap::const_iterator csmi = ecs->find(EEid.rawId());
654  if (csmi != ecs->end())
655  csc = *csmi;
656  uint16_t sc = csc.getStatusCode();
657  if (meEERecHitSimHitRatio1011_ != nullptr && (sc == 10 || sc == 11)) {
658  meEERecHitSimHitRatio1011_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
659  }
660  if (meEERecHitSimHitRatio12_ != nullptr && sc == 12) {
661  meEERecHitSimHitRatio12_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
662  }
663  if (meEERecHitSimHitRatio13_ != nullptr && sc == 13) {
664  meEERecHitSimHitRatio13_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
665  }
666  }
667 
668  int flag = myRecHit->recoFlag();
669  if (meEERecHitFlags_ != nullptr)
670  meEERecHitFlags_->Fill(flag);
671  if (meEERecHitSimHitvsSimHitFlag5_6_ &&
673  meEERecHitSimHitvsSimHitFlag5_6_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()], eeSimMap[EEid.rawId()]);
674  if (meEERecHitSimHitFlag6_ && (flag == EcalRecHit::kLeadingEdgeRecovered))
675  meEERecHitSimHitFlag6_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
676  if (meEERecHitSimHitFlag7_ && (flag == EcalRecHit::kNeighboursRecovered))
677  meEERecHitSimHitFlag6_->Fill(myRecHit->energy() / eeSimMap[EEid.rawId()]);
678 
679  if (EEid.zside() > 0) {
680  if (meEERecHitsOccupancyPlusFlag5_6_ &&
682  meEERecHitsOccupancyPlusFlag5_6_->Fill(EEid.ix(), EEid.iy());
683  if (meEERecHitsOccupancyPlusFlag8_9_ &&
684  ((flag == EcalRecHit::kTowerRecovered) || (flag == EcalRecHit::kDead)))
685  meEERecHitsOccupancyPlusFlag8_9_->Fill(EEid.ix(), EEid.iy());
686  }
687  if (EEid.zside() < 0) {
688  if (meEERecHitsOccupancyMinusFlag5_6_ &&
690  meEERecHitsOccupancyMinusFlag5_6_->Fill(EEid.ix(), EEid.iy());
691  if (meEERecHitsOccupancyMinusFlag8_9_ &&
692  ((flag == EcalRecHit::kTowerRecovered) || (flag == EcalRecHit::kDead)))
693  meEERecHitsOccupancyMinusFlag8_9_->Fill(EEid.ix(), EEid.iy());
694  }
695  }
696  } else
697  continue;
698  } // loop over the UncalibratedechitCollection
699 
700  // RecHits matrix
701  uint32_t eecenterid = getUnitWithMaxEnergy(eeRecMap);
702  EEDetId myEEid(eecenterid);
703  int bx = myEEid.ix();
704  int by = myEEid.iy();
705  int bz = myEEid.zside();
706  findEndcapMatrix(5, 5, bx, by, bz, eeRecMap);
707  double e5x5rec = 0.;
708  double e5x5sim = 0.;
709  for (unsigned int i = 0; i < crystalMatrix.size(); i++) {
710  e5x5rec += eeRecMap[crystalMatrix[i]];
711  e5x5sim += eeSimMap[crystalMatrix[i]];
712  if (eeRecMap[crystalMatrix[i]] > 0) {
713  int log10i25 = int((log10(eeRecMap[crystalMatrix[i]]) + 5.) * 10.);
714  if (log10i25 >= 0 && log10i25 < eecSize)
715  eecontr25[log10i25] += eeRecMap[crystalMatrix[i]];
716  }
717  }
718 
719  if (meEEe5x5_)
720  meEEe5x5_->Fill(e5x5rec);
721  if (e5x5sim > 0. && meEEe5x5OverSimHits_)
722  meEEe5x5OverSimHits_->Fill(e5x5rec / e5x5sim);
723  if (eGun > 0. && meEEe5x5OverGun_)
724  meEEe5x5OverGun_->Fill(e5x5rec / eGun);
725 
726  if (meEERecHitLog10EnergyContr_ && eetotal != 0) {
727  for (int i = 0; i < eecSize; i++) {
728  meEERecHitLog10EnergyContr_->Fill(-5. + (float(i) + 0.5) / 10., eecontr[i] / eetotal);
729  }
730  }
731 
732  if (meEERecHitLog10Energy5x5Contr_ && e5x5rec != 0) {
733  for (int i = 0; i < eecSize; i++) {
734  meEERecHitLog10Energy5x5Contr_->Fill(-5. + (float(i) + 0.5) / 10., eecontr25[i] / e5x5rec);
735  }
736  }
737  }
738 
739  // -------------------------------------------------------------------
740  // PRESHOWER
741 
742  if (!skipPreshower) {
743  // 1) loop over simHits
744  e.getByToken(ESHits_Token_, crossingFrame);
745  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
746 
747  MapType esSimMap;
748  const int escSize = 90;
749  double escontr[escSize];
750  for (int i = 0; i < escSize; i++) {
751  escontr[i] = 0.0;
752  }
753  double estotal = 0.;
754 
755  for (auto const &iHit : preshowerHits) {
756  ESDetId esid(iHit.id());
757  LogDebug("Preshower, HitInfo") << " CaloHit " << iHit.getName() << " DetID = " << iHit.id() << "\n"
758  << "Energy = " << iHit.energy() << " Time = " << iHit.time() << "\n"
759  << "ESDetId strip " << esid.strip() << " = " << esid.six() << " " << esid.siy();
760 
761  uint32_t crystid = esid.rawId();
762  esSimMap[crystid] += iHit.energy();
763  }
764 
765  // 2) loop over RecHits
766  for (EcalRecHitCollection::const_iterator recHit = ESRecHit->begin(); recHit != ESRecHit->end(); ++recHit) {
767  ESDetId ESid = ESDetId(recHit->id());
768  if (esSimMap[ESid.rawId()] != 0.) {
769  // Fill log10(Energy) stuff...
770  estotal += recHit->energy();
771  if (recHit->energy() > 0) {
772  if (meESRecHitLog10Energy_)
773  meESRecHitLog10Energy_->Fill(log10(recHit->energy()));
774  int log10i = int((log10(recHit->energy()) + 5.) * 10.);
775  if (log10i >= 0 and log10i < escSize)
776  escontr[log10i] += recHit->energy();
777  }
778 
779  if (meESRecHitSimHitRatio_) {
780  meESRecHitSimHitRatio_->Fill(recHit->energy() / esSimMap[ESid.rawId()]);
781  }
782  } else
783  continue;
784  } // loop over the RechitCollection
785 
786  if (meESRecHitLog10EnergyContr_ && estotal != 0) {
787  for (int i = 0; i < escSize; i++) {
788  meESRecHitLog10EnergyContr_->Fill(-5. + (float(i) + 0.5) / 10., escontr[i] / estotal);
789  }
790  }
791  }
792 }
793 
795  // look for max
796  uint32_t unitWithMaxEnergy = 0;
797  float maxEnergy = 0.;
798 
799  MapType::iterator iter;
800  for (iter = themap.begin(); iter != themap.end(); iter++) {
801  if (maxEnergy < (*iter).second) {
802  maxEnergy = (*iter).second;
803  unitWithMaxEnergy = (*iter).first;
804  }
805  }
806 
807  return unitWithMaxEnergy;
808 }
809 
811  int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &themap) {
812  int goBackInEta = nCellInEta / 2;
813  int goBackInPhi = nCellInPhi / 2;
814  int matrixSize = nCellInEta * nCellInPhi;
815  crystalMatrix.clear();
816  crystalMatrix.resize(matrixSize);
817 
818  int startEta = CentralZ * CentralEta - goBackInEta;
819  int startPhi = CentralPhi - goBackInPhi;
820 
821  int i = 0;
822  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
823  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
824  uint32_t index;
825  if (abs(ieta) > 85 || abs(ieta) < 1) {
826  continue;
827  }
828  if (iphi < 1) {
829  index = EBDetId(ieta, iphi + 360).rawId();
830  } else if (iphi > 360) {
831  index = EBDetId(ieta, iphi - 360).rawId();
832  } else {
833  index = EBDetId(ieta, iphi).rawId();
834  }
835  crystalMatrix[i++] = index;
836  }
837  }
838 }
839 
841  int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &themap) {
842  int goBackInX = nCellInX / 2;
843  int goBackInY = nCellInY / 2;
844  crystalMatrix.clear();
845 
846  int startX = CentralX - goBackInX;
847  int startY = CentralY - goBackInY;
848 
849  for (int ix = startX; ix < startX + nCellInX; ix++) {
850  for (int iy = startY; iy < startY + nCellInY; iy++) {
851  uint32_t index;
852 
853  if (EEDetId::validDetId(ix, iy, CentralZ)) {
854  index = EEDetId(ix, iy, CentralZ).rawId();
855  } else {
856  continue;
857  }
858  crystalMatrix.push_back(index);
859  }
860  }
861 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:38
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
int ix() const
Definition: EEDetId.h:77
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
EcalRecHitsValidation(const edm::ParameterSet &ps)
Constructor.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
Code getStatusCode() const
return decoded status
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< T >::const_iterator const_iterator
uint32_t getUnitWithMaxEnergy(MapType &themap)
int size() const
Definition: MixCollection.h:20
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
std::map< uint32_t, float, std::less< uint32_t > > MapType
~EcalRecHitsValidation() override
Destructor.
void findEndcapMatrix(int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &themap)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
int zside() const
Definition: EEDetId.h:71
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int iy() const
Definition: EEDetId.h:83
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
bool isValid() const
Definition: HandleBase.h:70
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
Definition: L1Track.h:19
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
#define M_PI
Namespace of DDCMS conversion namespace.
const_iterator end() const
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
T const * product() const
Definition: Handle.h:69
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
edm::EventID id() const
Definition: EventBase.h:59
iterator find(key_type k)
HLT enums.
void findBarrelMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &themap)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
T get() const
Definition: EventSetup.h:73
const_iterator find(uint32_t rawId) const
const_iterator end() const
bool isValid() const
Definition: ESHandle.h:44
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
Definition: Run.h:45
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45