CMS 3D CMS Logo

EcalEndcapSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalEndcapSimHitsValidation.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  EEHitsCollection(ps.getParameter<std::string>("EEHitsCollection")),
20  ValidationCollection(ps.getParameter<std::string>("ValidationCollection")) {
21  EEHitsToken =
22  consumes<edm::PCaloHitContainer>(edm::InputTag(std::string(g4InfoLabel), std::string(EEHitsCollection)));
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 
32  if (dbe_) {
33  if (verbose_)
34  dbe_->showDirStructure();
35  }
36 
37  meEEzpHits_ = nullptr;
38  meEEzmHits_ = nullptr;
39  meEEzpCrystals_ = nullptr;
40  meEEzmCrystals_ = nullptr;
41  meEEzpOccupancy_ = nullptr;
42  meEEzmOccupancy_ = nullptr;
43  meEELongitudinalShower_ = nullptr;
44  meEEHitEnergy_ = nullptr;
45  meEEhitLog10Energy_ = nullptr;
46  meEEhitLog10EnergyNorm_ = nullptr;
47  meEEhitLog10Energy25Norm_ = nullptr;
48  meEEHitEnergy2_ = nullptr;
49  meEEcrystalEnergy_ = nullptr;
50  meEEcrystalEnergy2_ = nullptr;
51 
52  meEEe1_ = nullptr;
53  meEEe4_ = nullptr;
54  meEEe9_ = nullptr;
55  meEEe16_ = nullptr;
56  meEEe25_ = nullptr;
57 
58  meEEe1oe4_ = nullptr;
59  meEEe1oe9_ = nullptr;
60  meEEe4oe9_ = nullptr;
61  meEEe9oe16_ = nullptr;
62  meEEe1oe25_ = nullptr;
63  meEEe9oe25_ = nullptr;
64  meEEe16oe25_ = nullptr;
65 
66  myEntries = 0;
67  for (int myStep = 0; myStep < 26; myStep++) {
68  eRLength[myStep] = 0.0;
69  }
70 
71  Char_t histo[200];
72 
73  if (dbe_) {
74  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
75 
76  sprintf(histo, "EE+ hits multiplicity");
77  meEEzpHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.);
78 
79  sprintf(histo, "EE- hits multiplicity");
80  meEEzmHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.);
81 
82  sprintf(histo, "EE+ crystals multiplicity");
83  meEEzpCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.);
84 
85  sprintf(histo, "EE- crystals multiplicity");
86  meEEzmCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.);
87 
88  sprintf(histo, "EE+ occupancy");
89  meEEzpOccupancy_ = dbe_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
90 
91  sprintf(histo, "EE- occupancy");
92  meEEzmOccupancy_ = dbe_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
93 
94  sprintf(histo, "EE longitudinal shower profile");
95  meEELongitudinalShower_ = dbe_->bookProfile(histo, histo, 26, 0, 26, 100, 0, 20000);
96 
97  sprintf(histo, "EE hits energy spectrum");
98  meEEHitEnergy_ = dbe_->book1D(histo, histo, 4000, 0., 400.);
99 
100  sprintf(histo, "EE hits log10energy spectrum");
101  meEEhitLog10Energy_ = dbe_->book1D(histo, histo, 140, -10., 4.);
102 
103  sprintf(histo, "EE hits log10energy spectrum vs normalized energy");
104  meEEhitLog10EnergyNorm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
105 
106  sprintf(histo, "EE hits log10energy spectrum vs normalized energy25");
107  meEEhitLog10Energy25Norm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
108 
109  sprintf(histo, "EE hits energy spectrum 2");
110  meEEHitEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
111 
112  sprintf(histo, "EE crystal energy spectrum");
113  meEEcrystalEnergy_ = dbe_->book1D(histo, histo, 5000, 0., 50.);
114 
115  sprintf(histo, "EE crystal energy spectrum 2");
116  meEEcrystalEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
117 
118  sprintf(histo, "EE E1");
119  meEEe1_ = dbe_->book1D(histo, histo, 400, 0., 400.);
120 
121  sprintf(histo, "EE E4");
122  meEEe4_ = dbe_->book1D(histo, histo, 400, 0., 400.);
123 
124  sprintf(histo, "EE E9");
125  meEEe9_ = dbe_->book1D(histo, histo, 400, 0., 400.);
126 
127  sprintf(histo, "EE E16");
128  meEEe16_ = dbe_->book1D(histo, histo, 400, 0., 400.);
129 
130  sprintf(histo, "EE E25");
131  meEEe25_ = dbe_->book1D(histo, histo, 400, 0., 400.);
132 
133  sprintf(histo, "EE E1oE4");
134  meEEe1oe4_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
135 
136  sprintf(histo, "EE E1oE9");
137  meEEe1oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
138 
139  sprintf(histo, "EE E4oE9");
140  meEEe4oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
141 
142  sprintf(histo, "EE E9oE16");
143  meEEe9oe16_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
144 
145  sprintf(histo, "EE E1oE25");
146  meEEe1oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
147 
148  sprintf(histo, "EE E9oE25");
149  meEEe9oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
150 
151  sprintf(histo, "EE E16oE25");
152  meEEe16oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
153  }
154 }
155 
157 
159 
161  // for ( int myStep = 0; myStep<26; myStep++){
162  // if (meEELongitudinalShower_) meEELongitudinalShower_->Fill(float(myStep),
163  // eRLength[myStep]/myEntries);
164  //}
165 }
166 
168  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
169 
171  e.getByToken(EEHitsToken, EcalHitsEE);
172 
173  // Do nothing if no EndCap data available
174  if (!EcalHitsEE.isValid())
175  return;
176 
177  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
178  e.getByToken(ValidationCollectionToken, MyPEcalValidInfo);
179 
180  std::vector<PCaloHit> theEECaloHits;
181  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
182 
183  myEntries++;
184 
185  std::map<unsigned int, std::vector<PCaloHit *>, std::less<unsigned int>> CaloHitMap;
186 
187  double EEetzp_ = 0.;
188  double EEetzm_ = 0.;
189 
190  double ee1 = 0.0;
191  double ee4 = 0.0;
192  double ee9 = 0.0;
193  double ee16 = 0.0;
194  double ee25 = 0.0;
195  std::vector<double> econtr(140, 0.);
196  std::vector<double> econtr25(140, 0.);
197 
198  MapType eemap;
199  MapType eemapzp;
200  MapType eemapzm;
201  uint32_t nEEzpHits = 0;
202  uint32_t nEEzmHits = 0;
203 
204  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin(); isim != theEECaloHits.end(); ++isim) {
205  if (isim->time() > 500.) {
206  continue;
207  }
208 
209  CaloHitMap[isim->id()].push_back(&(*isim));
210 
211  EEDetId eeid(isim->id());
212 
213  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
214  << " DetID = " << isim->id() << " EEDetId = " << eeid.ix() << " " << eeid.iy() << "\n"
215  << " Time = " << isim->time() << "\n"
216  << " Track Id = " << isim->geantTrackId() << "\n"
217  << " Energy = " << isim->energy();
218 
219  uint32_t crystid = eeid.rawId();
220 
221  if (eeid.zside() > 0) {
222  nEEzpHits++;
223  EEetzp_ += isim->energy();
224  eemapzp[crystid] += isim->energy();
225  if (meEEzpOccupancy_)
226  meEEzpOccupancy_->Fill(eeid.ix(), eeid.iy());
227  } else if (eeid.zside() < 0) {
228  nEEzmHits++;
229  EEetzm_ += isim->energy();
230  eemapzm[crystid] += isim->energy();
231  if (meEEzmOccupancy_)
232  meEEzmOccupancy_->Fill(eeid.ix(), eeid.iy());
233  }
234 
235  if (meEEHitEnergy_)
236  meEEHitEnergy_->Fill(isim->energy());
237  if (isim->energy() > 0) {
239  meEEhitLog10Energy_->Fill(log10(isim->energy()));
240  int log10i = int((log10(isim->energy()) + 10.) * 10.);
241  if (log10i >= 0 && log10i < 140)
242  econtr[log10i] += isim->energy();
243  }
244  if (meEEHitEnergy2_)
245  meEEHitEnergy2_->Fill(isim->energy());
246  eemap[crystid] += isim->energy();
247  }
248 
249  if (meEEzpCrystals_)
250  meEEzpCrystals_->Fill(eemapzp.size());
251  if (meEEzmCrystals_)
252  meEEzmCrystals_->Fill(eemapzm.size());
253 
254  if (meEEcrystalEnergy_) {
255  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = eemap.begin(); it != eemap.end(); ++it)
256  meEEcrystalEnergy_->Fill((*it).second);
257  }
258  if (meEEcrystalEnergy2_) {
259  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = eemap.begin(); it != eemap.end(); ++it)
260  meEEcrystalEnergy2_->Fill((*it).second);
261  }
262 
263  if (meEEzpHits_)
264  meEEzpHits_->Fill(nEEzpHits);
265  if (meEEzmHits_)
266  meEEzmHits_->Fill(nEEzmHits);
267 
268  int nEEHits = nEEzmHits + nEEzpHits;
269  if (nEEHits > 0) {
270  uint32_t eecenterid = getUnitWithMaxEnergy(eemap);
271  EEDetId myEEid(eecenterid);
272  int bx = myEEid.ix();
273  int by = myEEid.iy();
274  int bz = myEEid.zside();
275  ee1 = energyInMatrixEE(1, 1, bx, by, bz, eemap);
276  if (meEEe1_)
277  meEEe1_->Fill(ee1);
278  ee9 = energyInMatrixEE(3, 3, bx, by, bz, eemap);
279  if (meEEe9_)
280  meEEe9_->Fill(ee9);
281  ee25 = energyInMatrixEE(5, 5, bx, by, bz, eemap);
282  if (meEEe25_)
283  meEEe25_->Fill(ee25);
284 
285  std::vector<uint32_t> ids25;
286  ids25 = getIdsAroundMax(5, 5, bx, by, bz, eemap);
287 
288  for (unsigned i = 0; i < 25; i++) {
289  for (unsigned int j = 0; j < CaloHitMap[ids25[i]].size(); j++) {
290  if (CaloHitMap[ids25[i]][j]->energy() > 0) {
291  int log10i = int((log10(CaloHitMap[ids25[i]][j]->energy()) + 10.) * 10.);
292  if (log10i >= 0 && log10i < 140)
293  econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
294  }
295  }
296  }
297 
298  MapType neweemap;
299  if (fillEEMatrix(3, 3, bx, by, bz, neweemap, eemap)) {
300  ee4 = eCluster2x2(neweemap);
301  if (meEEe4_)
302  meEEe4_->Fill(ee4);
303  }
304  if (fillEEMatrix(5, 5, bx, by, bz, neweemap, eemap)) {
305  ee16 = eCluster4x4(ee9, neweemap);
306  if (meEEe16_)
307  meEEe16_->Fill(ee16);
308  }
309 
310  if (meEEe1oe4_ && ee4 > 0.1)
311  meEEe1oe4_->Fill(ee1 / ee4);
312  if (meEEe1oe9_ && ee9 > 0.1)
313  meEEe1oe9_->Fill(ee1 / ee9);
314  if (meEEe4oe9_ && ee9 > 0.1)
315  meEEe4oe9_->Fill(ee4 / ee9);
316  if (meEEe9oe16_ && ee16 > 0.1)
317  meEEe9oe16_->Fill(ee9 / ee16);
318  if (meEEe16oe25_ && ee25 > 0.1)
319  meEEe16oe25_->Fill(ee16 / ee25);
320  if (meEEe1oe25_ && ee25 > 0.1)
321  meEEe1oe25_->Fill(ee1 / ee25);
322  if (meEEe9oe25_ && ee25 > 0.1)
323  meEEe9oe25_->Fill(ee9 / ee25);
324 
325  if (meEEhitLog10EnergyNorm_ && (EEetzp_ + EEetzm_) != 0) {
326  for (int i = 0; i < 140; i++) {
327  meEEhitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / (EEetzp_ + EEetzm_));
328  }
329  }
330 
331  if (meEEhitLog10Energy25Norm_ && ee25 != 0) {
332  for (int i = 0; i < 140; i++) {
333  meEEhitLog10Energy25Norm_->Fill(-10. + (float(i) + 0.5) / 10., econtr25[i] / ee25);
334  }
335  }
336  }
337 
338  if (MyPEcalValidInfo.isValid()) {
339  if (MyPEcalValidInfo->ee1x1() > 0.) {
340  std::vector<float> EX0 = MyPEcalValidInfo->eX0();
343  for (int myStep = 0; myStep < 26; myStep++) {
344  eRLength[myStep] += EX0[myStep];
346  meEELongitudinalShower_->Fill(float(myStep), eRLength[myStep] / myEntries);
347  }
348  }
349  }
350 }
351 
353  int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap) {
354  int ncristals = 0;
355  float totalEnergy = 0.;
356 
357  int goBackInX = nCellInX / 2;
358  int goBackInY = nCellInY / 2;
359  int startX = centralX - goBackInX;
360  int startY = centralY - goBackInY;
361 
362  for (int ix = startX; ix < startX + nCellInX; ix++) {
363  for (int iy = startY; iy < startY + nCellInY; iy++) {
364  uint32_t index;
365 
366  if (EEDetId::validDetId(ix, iy, centralZ)) {
367  index = EEDetId(ix, iy, centralZ).rawId();
368  } else {
369  continue;
370  }
371 
372  totalEnergy += themap[index];
373  ncristals += 1;
374  }
375  }
376 
377  LogDebug("GeomInfo") << nCellInX << " x " << nCellInY << " EE matrix energy = " << totalEnergy << " for " << ncristals
378  << " crystals";
379  return totalEnergy;
380 }
381 
383  int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap) {
384  int ncristals = 0;
385  std::vector<uint32_t> ids(nCellInX * nCellInY);
386 
387  int goBackInX = nCellInX / 2;
388  int goBackInY = nCellInY / 2;
389  int startX = centralX - goBackInX;
390  int startY = centralY - goBackInY;
391 
392  for (int ix = startX; ix < startX + nCellInX; ix++) {
393  for (int iy = startY; iy < startY + nCellInY; iy++) {
394  uint32_t index;
395 
396  if (EEDetId::validDetId(ix, iy, centralZ)) {
397  index = EEDetId(ix, iy, centralZ).rawId();
398  } else {
399  continue;
400  }
401 
402  ids[ncristals] = index;
403  ncristals += 1;
404  }
405  }
406 
407  return ids;
408 }
409 
411  int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap) {
412  int goBackInX = nCellInX / 2;
413  int goBackInY = nCellInY / 2;
414 
415  int startX = CentralX - goBackInX;
416  int startY = CentralY - goBackInY;
417 
418  int i = 0;
419  for (int ix = startX; ix < startX + nCellInX; ix++) {
420  for (int iy = startY; iy < startY + nCellInY; iy++) {
421  uint32_t index;
422 
423  if (EEDetId::validDetId(ix, iy, CentralZ)) {
424  index = EEDetId(ix, iy, CentralZ).rawId();
425  } else {
426  continue;
427  }
428  fillmap[i++] = themap[index];
429  }
430  }
431  uint32_t centerid = getUnitWithMaxEnergy(themap);
432 
433  if (fillmap[i / 2] == themap[centerid])
434  return true;
435  else
436  return false;
437 }
438 
440  float E22 = 0.;
441  float e012 = themap[0] + themap[1] + themap[2];
442  float e036 = themap[0] + themap[3] + themap[6];
443  float e678 = themap[6] + themap[7] + themap[8];
444  float e258 = themap[2] + themap[5] + themap[8];
445 
446  if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
447  return E22 = themap[0] + themap[1] + themap[3] + themap[4];
448  else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
449  return E22 = themap[1] + themap[2] + themap[4] + themap[5];
450  else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
451  return E22 = themap[3] + themap[4] + themap[6] + themap[7];
452  else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
453  return E22 = themap[4] + themap[5] + themap[7] + themap[8];
454  else {
455  return E22;
456  }
457 }
458 
460  float E44 = 0.;
461  float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
462  float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
463  float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
464  float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
465 
466  if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
467  return E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
468  else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
469  return E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
470  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
471  return E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
472  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
473  return E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
474  else {
475  return E44;
476  }
477 }
478 
480  // look for max
481  uint32_t unitWithMaxEnergy = 0;
482  float maxEnergy = 0.;
483 
484  MapType::iterator iter;
485  for (iter = themap.begin(); iter != themap.end(); iter++) {
486  if (maxEnergy < (*iter).second) {
487  maxEnergy = (*iter).second;
488  unitWithMaxEnergy = (*iter).first;
489  }
490  }
491 
492  LogDebug("GeomInfo") << " max energy of " << maxEnergy << " GeV in Unit id " << unitWithMaxEnergy;
493  return unitWithMaxEnergy;
494 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
int ix() const
Definition: EEDetId.h:77
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
~EcalEndcapSimHitsValidation() override
Destructor.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::EDGetTokenT< PEcalValidInfo > ValidationCollectionToken
virtual float energyInMatrixEE(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
std::map< uint32_t, float, std::less< uint32_t > > MapType
void Fill(long long x)
virtual void Reset()
reset ME (ie. contents, errors, etc)
float eCluster4x4(float e33, MapType &themap)
int zside() const
Definition: EEDetId.h:71
int iy() const
Definition: EEDetId.h:83
bool isValid() const
Definition: HandleBase.h:70
bool fillEEMatrix(int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap)
Namespace of DDCMS conversion namespace.
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsToken
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
uint32_t getUnitWithMaxEnergy(MapType &themap)
FloatVector eX0() const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
float ee1x1() const
std::vector< uint32_t > getIdsAroundMax(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
EcalEndcapSimHitsValidation(const edm::ParameterSet &ps)
Constructor.