CMS 3D CMS Logo

EcalBarrelSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalBarrelSimHitsValidation.cc
3  *
4  * \author C.Rovelli
5  *
6  */
7 
12 
13 using namespace cms;
14 using namespace edm;
15 using namespace std;
16 
18  : g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
19  EBHitsCollection(ps.getParameter<std::string>("EBHitsCollection")),
20  ValidationCollection(ps.getParameter<std::string>("ValidationCollection")) {
21  EBHitsToken =
22  consumes<edm::PCaloHitContainer>(edm::InputTag(std::string(g4InfoLabel), std::string(EBHitsCollection)));
25  // verbosity switch
26  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
27 
28  // get hold of back-end interface
29  dbe_ = nullptr;
30  dbe_ = edm::Service<DQMStore>().operator->();
31  if (dbe_) {
32  if (verbose_) {
33  dbe_->setVerbose(1);
34  } else {
35  dbe_->setVerbose(0);
36  }
37  }
38 
39  if (dbe_) {
40  if (verbose_)
41  dbe_->showDirStructure();
42  }
43 
44  menEBHits_ = nullptr;
45  menEBCrystals_ = nullptr;
46  meEBOccupancy_ = nullptr;
47  meEBLongitudinalShower_ = nullptr;
48  meEBhitEnergy_ = nullptr;
49  meEBhitLog10Energy_ = nullptr;
50  meEBhitLog10EnergyNorm_ = nullptr;
51  meEBhitLog10Energy25Norm_ = nullptr;
52  meEBhitEnergy2_ = nullptr;
53  meEBcrystalEnergy_ = nullptr;
54  meEBcrystalEnergy2_ = nullptr;
55 
56  meEBe1_ = nullptr;
57  meEBe4_ = nullptr;
58  meEBe9_ = nullptr;
59  meEBe16_ = nullptr;
60  meEBe25_ = nullptr;
61 
62  meEBe1oe4_ = nullptr;
63  meEBe1oe9_ = nullptr;
64  meEBe4oe9_ = nullptr;
65  meEBe9oe16_ = nullptr;
66  meEBe1oe25_ = nullptr;
67  meEBe9oe25_ = nullptr;
68  meEBe16oe25_ = nullptr;
69 
70  myEntries = 0;
71  for (int myStep = 0; myStep < 26; myStep++) {
72  eRLength[myStep] = 0.0;
73  }
74 
75  Char_t histo[200];
76 
77  if (dbe_) {
78  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
79 
80  sprintf(histo, "EB hits multiplicity");
81  menEBHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.);
82 
83  sprintf(histo, "EB crystals multiplicity");
84  menEBCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.);
85 
86  sprintf(histo, "EB occupancy");
87  meEBOccupancy_ = dbe_->book2D(histo, histo, 360, 0., 360., 170, -85., 85.);
88 
89  sprintf(histo, "EB longitudinal shower profile");
90  meEBLongitudinalShower_ = dbe_->bookProfile(histo, histo, 26, 0., 26., 100, 0., 20000.);
91 
92  sprintf(histo, "EB hits energy spectrum");
93  meEBhitEnergy_ = dbe_->book1D(histo, histo, 4000, 0., 400.);
94 
95  sprintf(histo, "EB hits log10energy spectrum");
96  meEBhitLog10Energy_ = dbe_->book1D(histo, histo, 140, -10., 4.);
97 
98  sprintf(histo, "EB hits log10energy spectrum vs normalized energy");
99  meEBhitLog10EnergyNorm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
100 
101  sprintf(histo, "EB hits log10energy spectrum vs normalized energy25");
102  meEBhitLog10Energy25Norm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
103 
104  sprintf(histo, "EB hits energy spectrum 2");
105  meEBhitEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
106 
107  sprintf(histo, "EB crystal energy spectrum");
108  meEBcrystalEnergy_ = dbe_->book1D(histo, histo, 5000, 0., 50.);
109 
110  sprintf(histo, "EB crystal energy spectrum 2");
111  meEBcrystalEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
112 
113  sprintf(histo, "EB E1");
114  meEBe1_ = dbe_->book1D(histo, histo, 400, 0., 400.);
115 
116  sprintf(histo, "EB E4");
117  meEBe4_ = dbe_->book1D(histo, histo, 400, 0., 400.);
118 
119  sprintf(histo, "EB E9");
120  meEBe9_ = dbe_->book1D(histo, histo, 400, 0., 400.);
121 
122  sprintf(histo, "EB E16");
123  meEBe16_ = dbe_->book1D(histo, histo, 400, 0., 400.);
124 
125  sprintf(histo, "EB E25");
126  meEBe25_ = dbe_->book1D(histo, histo, 400, 0., 400.);
127 
128  sprintf(histo, "EB E1oE4");
129  meEBe1oe4_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
130 
131  sprintf(histo, "EB E1oE9");
132  meEBe1oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
133 
134  sprintf(histo, "EB E4oE9");
135  meEBe4oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
136 
137  sprintf(histo, "EB E9oE16");
138  meEBe9oe16_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
139 
140  sprintf(histo, "EB E1oE25");
141  meEBe1oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
142 
143  sprintf(histo, "EB E9oE25");
144  meEBe9oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
145 
146  sprintf(histo, "EB E16oE25");
147  meEBe16oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
148  }
149 }
150 
152 
154 
156  // for (int myStep=0; myStep<26; myStep++){
157  // if (meEBLongitudinalShower_) meEBLongitudinalShower_->Fill(float(myStep),
158  // eRLength[myStep]/myEntries);
159  //}
160 }
161 
163  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
164 
166  e.getByToken(EBHitsToken, EcalHitsEB);
167 
168  // Do nothing if no Barrel data available
169  if (!EcalHitsEB.isValid())
170  return;
171 
172  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
173  e.getByToken(ValidationCollectionToken, MyPEcalValidInfo);
174 
175  std::vector<PCaloHit> theEBCaloHits;
176  theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
177 
178  myEntries++;
179 
180  double EBEnergy_ = 0.;
181  std::map<unsigned int, std::vector<PCaloHit *>, std::less<unsigned int>> CaloHitMap;
182 
183  double eb1 = 0.0;
184  double eb4 = 0.0;
185  double eb9 = 0.0;
186  double eb16 = 0.0;
187  double eb25 = 0.0;
188  std::vector<double> econtr(140, 0.);
189  std::vector<double> econtr25(140, 0.);
190 
191  MapType ebmap;
192  uint32_t nEBHits = 0;
193 
194  for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin(); isim != theEBCaloHits.end(); ++isim) {
195  if (isim->time() > 500.) {
196  continue;
197  }
198 
199  CaloHitMap[isim->id()].push_back(&(*isim));
200 
201  EBDetId ebid(isim->id());
202 
203  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
204  << " DetID = " << isim->id() << " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
205  << " Time = " << isim->time() << "\n"
206  << " Track Id = " << isim->geantTrackId() << "\n"
207  << " Energy = " << isim->energy();
208 
209  if (meEBOccupancy_)
210  meEBOccupancy_->Fill(ebid.iphi(), ebid.ieta());
211 
212  uint32_t crystid = ebid.rawId();
213  ebmap[crystid] += isim->energy();
214 
215  EBEnergy_ += isim->energy();
216  nEBHits++;
217  meEBhitEnergy_->Fill(isim->energy());
218  if (isim->energy() > 0) {
219  meEBhitLog10Energy_->Fill(log10(isim->energy()));
220  int log10i = int((log10(isim->energy()) + 10.) * 10.);
221  if (log10i >= 0 && log10i < 140)
222  econtr[log10i] += isim->energy();
223  }
224  meEBhitEnergy2_->Fill(isim->energy());
225  }
226 
227  if (menEBCrystals_)
228  menEBCrystals_->Fill(ebmap.size());
229  if (meEBcrystalEnergy_) {
230  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = ebmap.begin(); it != ebmap.end(); ++it)
231  meEBcrystalEnergy_->Fill((*it).second);
232  }
233  if (meEBcrystalEnergy2_) {
234  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = ebmap.begin(); it != ebmap.end(); ++it)
235  meEBcrystalEnergy2_->Fill((*it).second);
236  }
237 
238  if (menEBHits_)
239  menEBHits_->Fill(nEBHits);
240 
241  if (nEBHits > 0) {
242  uint32_t ebcenterid = getUnitWithMaxEnergy(ebmap);
243  EBDetId myEBid(ebcenterid);
244  int bx = myEBid.ietaAbs();
245  int by = myEBid.iphi();
246  int bz = myEBid.zside();
247  eb1 = energyInMatrixEB(1, 1, bx, by, bz, ebmap);
248  if (meEBe1_)
249  meEBe1_->Fill(eb1);
250  eb9 = energyInMatrixEB(3, 3, bx, by, bz, ebmap);
251  if (meEBe9_)
252  meEBe9_->Fill(eb9);
253  eb25 = energyInMatrixEB(5, 5, bx, by, bz, ebmap);
254  if (meEBe25_)
255  meEBe25_->Fill(eb25);
256 
257  std::vector<uint32_t> ids25;
258  ids25 = getIdsAroundMax(5, 5, bx, by, bz, ebmap);
259 
260  for (unsigned i = 0; i < 25; i++) {
261  for (unsigned int j = 0; j < CaloHitMap[ids25[i]].size(); j++) {
262  if (CaloHitMap[ids25[i]][j]->energy() > 0) {
263  int log10i = int((log10(CaloHitMap[ids25[i]][j]->energy()) + 10.) * 10.);
264  if (log10i >= 0 && log10i < 140)
265  econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
266  }
267  }
268  }
269 
270  MapType newebmap;
271  if (fillEBMatrix(3, 3, bx, by, bz, newebmap, ebmap)) {
272  eb4 = eCluster2x2(newebmap);
273  if (meEBe4_)
274  meEBe4_->Fill(eb4);
275  }
276  if (fillEBMatrix(5, 5, bx, by, bz, newebmap, ebmap)) {
277  eb16 = eCluster4x4(eb9, newebmap);
278  if (meEBe16_)
279  meEBe16_->Fill(eb16);
280  }
281 
282  if (meEBe1oe4_ && eb4 > 0.1)
283  meEBe1oe4_->Fill(eb1 / eb4);
284  if (meEBe1oe9_ && eb9 > 0.1)
285  meEBe1oe9_->Fill(eb1 / eb9);
286  if (meEBe4oe9_ && eb9 > 0.1)
287  meEBe4oe9_->Fill(eb4 / eb9);
288  if (meEBe9oe16_ && eb16 > 0.1)
289  meEBe9oe16_->Fill(eb9 / eb16);
290  if (meEBe1oe25_ && eb25 > 0.1)
291  meEBe1oe25_->Fill(eb1 / eb25);
292  if (meEBe9oe25_ && eb25 > 0.1)
293  meEBe9oe25_->Fill(eb9 / eb25);
294  if (meEBe16oe25_ && eb25 > 0.1)
295  meEBe16oe25_->Fill(eb16 / eb25);
296 
297  if (meEBhitLog10EnergyNorm_ && EBEnergy_ != 0) {
298  for (int i = 0; i < 140; i++) {
299  meEBhitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / EBEnergy_);
300  }
301  }
302 
303  if (meEBhitLog10Energy25Norm_ && eb25 != 0) {
304  for (int i = 0; i < 140; i++) {
305  meEBhitLog10Energy25Norm_->Fill(-10. + (float(i) + 0.5) / 10., econtr25[i] / eb25);
306  }
307  }
308  }
309 
310  if (MyPEcalValidInfo.isValid()) {
311  if (MyPEcalValidInfo->eb1x1() > 0.) {
312  std::vector<float> BX0 = MyPEcalValidInfo->bX0();
315  for (int myStep = 0; myStep < 26; myStep++) {
316  eRLength[myStep] += BX0[myStep];
318  meEBLongitudinalShower_->Fill(float(myStep), eRLength[myStep] / myEntries);
319  }
320  }
321  }
322 }
323 
325  int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap) {
326  int ncristals = 0;
327  float totalEnergy = 0.;
328 
329  int goBackInEta = nCellInEta / 2;
330  int goBackInPhi = nCellInPhi / 2;
331  int startEta = centralZ * centralEta - goBackInEta;
332  int startPhi = centralPhi - goBackInPhi;
333 
334  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
335  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
336  uint32_t index;
337  if (abs(ieta) > 85 || abs(ieta) < 1) {
338  continue;
339  }
340  if (iphi < 1) {
341  index = EBDetId(ieta, iphi + 360).rawId();
342  } else if (iphi > 360) {
343  index = EBDetId(ieta, iphi - 360).rawId();
344  } else {
345  index = EBDetId(ieta, iphi).rawId();
346  }
347 
348  totalEnergy += themap[index];
349  ncristals += 1;
350  }
351  }
352 
353  LogDebug("GeomInfo") << nCellInEta << " x " << nCellInPhi << " EB matrix energy = " << totalEnergy << " for "
354  << ncristals << " crystals";
355  return totalEnergy;
356 }
357 
359  int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap) {
360  int ncristals = 0;
361  std::vector<uint32_t> ids(nCellInEta * nCellInPhi);
362 
363  int goBackInEta = nCellInEta / 2;
364  int goBackInPhi = nCellInPhi / 2;
365  int startEta = centralZ * centralEta - goBackInEta;
366  int startPhi = centralPhi - goBackInPhi;
367 
368  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
369  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
370  uint32_t index;
371  if (abs(ieta) > 85 || abs(ieta) < 1) {
372  continue;
373  }
374  if (iphi < 1) {
375  index = EBDetId(ieta, iphi + 360).rawId();
376  } else if (iphi > 360) {
377  index = EBDetId(ieta, iphi - 360).rawId();
378  } else {
379  index = EBDetId(ieta, iphi).rawId();
380  }
381  ids[ncristals] = index;
382  ncristals += 1;
383  }
384  }
385 
386  return ids;
387 }
388 
390  int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap) {
391  int goBackInEta = nCellInEta / 2;
392  int goBackInPhi = nCellInPhi / 2;
393 
394  int startEta = CentralZ * CentralEta - goBackInEta;
395  int startPhi = CentralPhi - goBackInPhi;
396 
397  int i = 0;
398  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
399  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
400  uint32_t index;
401  if (abs(ieta) > 85 || abs(ieta) < 1) {
402  continue;
403  }
404  if (iphi < 1) {
405  index = EBDetId(ieta, iphi + 360).rawId();
406  } else if (iphi > 360) {
407  index = EBDetId(ieta, iphi - 360).rawId();
408  } else {
409  index = EBDetId(ieta, iphi).rawId();
410  }
411  fillmap[i++] = themap[index];
412  }
413  }
414 
415  uint32_t ebcenterid = getUnitWithMaxEnergy(themap);
416 
417  if (fillmap[i / 2] == themap[ebcenterid])
418  return true;
419  else
420  return false;
421 }
422 
424  float E22 = 0.;
425  float e012 = themap[0] + themap[1] + themap[2];
426  float e036 = themap[0] + themap[3] + themap[6];
427  float e678 = themap[6] + themap[7] + themap[8];
428  float e258 = themap[2] + themap[5] + themap[8];
429 
430  if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
431  return E22 = themap[0] + themap[1] + themap[3] + themap[4];
432  else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
433  return E22 = themap[1] + themap[2] + themap[4] + themap[5];
434  else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
435  return E22 = themap[3] + themap[4] + themap[6] + themap[7];
436  else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
437  return E22 = themap[4] + themap[5] + themap[7] + themap[8];
438  else {
439  return E22;
440  }
441 }
442 
444  float E44 = 0.;
445  float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
446  float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
447  float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
448  float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
449 
450  if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
451  return E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
452  else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
453  return E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
454  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
455  return E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
456  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
457  return E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
458  else {
459  return E44;
460  }
461 }
462 
464  // look for max
465  uint32_t unitWithMaxEnergy = 0;
466  float maxEnergy = 0.;
467 
468  MapType::iterator iter;
469  for (iter = themap.begin(); iter != themap.end(); iter++) {
470  if (maxEnergy < (*iter).second) {
471  maxEnergy = (*iter).second;
472  unitWithMaxEnergy = (*iter).first;
473  }
474  }
475 
476  LogDebug("GeomInfo") << " max energy of " << maxEnergy << " GeV in Unit id " << unitWithMaxEnergy;
477  return unitWithMaxEnergy;
478 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
std::vector< uint32_t > getIdsAroundMax(int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
float eb1x1() const
void Fill(long long x)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
float eCluster4x4(float e33, MapType &themap)
~EcalBarrelSimHitsValidation() override
Destructor.
std::map< uint32_t, float, std::less< uint32_t > > MapType
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< edm::PCaloHitContainer > EBHitsToken
void Reset()
reset ME (ie. contents, errors, etc)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< PEcalValidInfo > ValidationCollectionToken
uint32_t getUnitWithMaxEnergy(MapType &themap)
Namespace of DDCMS conversion namespace.
virtual float energyInMatrixEB(int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap)
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
bool fillEBMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap)
FloatVector bX0() const
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
EcalBarrelSimHitsValidation(const edm::ParameterSet &ps)
Constructor.