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  myEntries = 0;
29  for (int myStep = 0; myStep < 26; myStep++) {
30  eRLength[myStep] = 0.0;
31  }
32 }
33 
35  ib.setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
36  ib.setScope(MonitorElementData::Scope::RUN);
37 
38  std::string histo = "EB hits multiplicity";
39  menEBHits_ = ib.book1D(histo, histo, 50, 0., 5000.);
40 
41  histo = "EB crystals multiplicity";
42  menEBCrystals_ = ib.book1D(histo, histo, 200, 0., 2000.);
43 
44  histo = "EB occupancy";
45  meEBOccupancy_ = ib.book2D(histo, histo, 360, 0., 360., 170, -85., 85.);
46 
47  histo = "EB longitudinal shower profile";
48  meEBLongitudinalShower_ = ib.bookProfile(histo, histo, 26, 0., 26., 100, 0., 20000.);
49 
50  histo = "EB hits energy spectrum";
51  meEBhitEnergy_ = ib.book1D(histo, histo, 4000, 0., 400.);
52 
53  histo = "EB hits log10energy spectrum";
54  meEBhitLog10Energy_ = ib.book1D(histo, histo, 140, -10., 4.);
55 
56  histo = "EB hits log10energy spectrum vs normalized energy";
57  meEBhitLog10EnergyNorm_ = ib.bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
58 
59  histo = "EB hits log10energy spectrum vs normalized energy25";
60  meEBhitLog10Energy25Norm_ = ib.bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
61 
62  histo = "EB hits energy spectrum 2";
63  meEBhitEnergy2_ = ib.book1D(histo, histo, 1000, 0., 0.001);
64 
65  histo = "EB crystal energy spectrum";
66  meEBcrystalEnergy_ = ib.book1D(histo, histo, 5000, 0., 50.);
67 
68  histo = "EB crystal energy spectrum 2";
69  meEBcrystalEnergy2_ = ib.book1D(histo, histo, 1000, 0., 0.001);
70 
71  histo = "EB E1";
72  meEBe1_ = ib.book1D(histo, histo, 400, 0., 400.);
73 
74  histo = "EB E4";
75  meEBe4_ = ib.book1D(histo, histo, 400, 0., 400.);
76 
77  histo = "EB E9";
78  meEBe9_ = ib.book1D(histo, histo, 400, 0., 400.);
79 
80  histo = "EB E16";
81  meEBe16_ = ib.book1D(histo, histo, 400, 0., 400.);
82 
83  histo = "EB E25";
84  meEBe25_ = ib.book1D(histo, histo, 400, 0., 400.);
85 
86  histo = "EB E1oE4";
87  meEBe1oe4_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
88 
89  histo = "EB E1oE9";
90  meEBe1oe9_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
91 
92  histo = "EB E4oE9";
93  meEBe4oe9_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
94 
95  histo = "EB E9oE16";
96  meEBe9oe16_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
97 
98  histo = "EB E1oE25";
99  meEBe1oe25_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
100 
101  histo = "EB E9oE25";
102  meEBe9oe25_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
103 
104  histo = "EB E16oE25";
105  meEBe16oe25_ = ib.book1D(histo, histo, 100, 0.4, 1.1);
106 }
107 
109  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
110 
112  e.getByToken(EBHitsToken, EcalHitsEB);
113 
114  // Do nothing if no Barrel data available
115  if (!EcalHitsEB.isValid())
116  return;
117 
118  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
119  e.getByToken(ValidationCollectionToken, MyPEcalValidInfo);
120 
121  std::vector<PCaloHit> theEBCaloHits;
122  theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
123 
124  myEntries++;
125 
126  double EBEnergy_ = 0.;
127  std::map<unsigned int, std::vector<PCaloHit *>, std::less<unsigned int>> CaloHitMap;
128 
129  double eb1 = 0.0;
130  double eb4 = 0.0;
131  double eb9 = 0.0;
132  double eb16 = 0.0;
133  double eb25 = 0.0;
134  std::vector<double> econtr(140, 0.);
135  std::vector<double> econtr25(140, 0.);
136 
137  MapType ebmap;
138  uint32_t nEBHits = 0;
139 
140  for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin(); isim != theEBCaloHits.end(); ++isim) {
141  if (isim->time() > 500.) {
142  continue;
143  }
144 
145  CaloHitMap[isim->id()].push_back(&(*isim));
146 
147  EBDetId ebid(isim->id());
148 
149  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
150  << " DetID = " << isim->id() << " EBDetId = " << ebid.ieta() << " " << ebid.iphi() << "\n"
151  << " Time = " << isim->time() << "\n"
152  << " Track Id = " << isim->geantTrackId() << "\n"
153  << " Energy = " << isim->energy();
154 
155  meEBOccupancy_->Fill(ebid.iphi(), ebid.ieta());
156 
157  uint32_t crystid = ebid.rawId();
158  ebmap[crystid] += isim->energy();
159 
160  EBEnergy_ += isim->energy();
161  nEBHits++;
162  meEBhitEnergy_->Fill(isim->energy());
163  if (isim->energy() > 0) {
164  meEBhitLog10Energy_->Fill(log10(isim->energy()));
165  int log10i = int((log10(isim->energy()) + 10.) * 10.);
166  if (log10i >= 0 && log10i < 140)
167  econtr[log10i] += isim->energy();
168  }
169  meEBhitEnergy2_->Fill(isim->energy());
170  }
171 
172  menEBCrystals_->Fill(ebmap.size());
173  if (meEBcrystalEnergy_) {
174  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = ebmap.begin(); it != ebmap.end(); ++it)
175  meEBcrystalEnergy_->Fill((*it).second);
176  }
177  if (meEBcrystalEnergy2_) {
178  for (std::map<uint32_t, float, std::less<uint32_t>>::iterator it = ebmap.begin(); it != ebmap.end(); ++it)
179  meEBcrystalEnergy2_->Fill((*it).second);
180  }
181 
182  menEBHits_->Fill(nEBHits);
183 
184  if (nEBHits > 0) {
185  uint32_t ebcenterid = getUnitWithMaxEnergy(ebmap);
186  EBDetId myEBid(ebcenterid);
187  int bx = myEBid.ietaAbs();
188  int by = myEBid.iphi();
189  int bz = myEBid.zside();
190  eb1 = energyInMatrixEB(1, 1, bx, by, bz, ebmap);
191  meEBe1_->Fill(eb1);
192  eb9 = energyInMatrixEB(3, 3, bx, by, bz, ebmap);
193  meEBe9_->Fill(eb9);
194  eb25 = energyInMatrixEB(5, 5, bx, by, bz, ebmap);
195  meEBe25_->Fill(eb25);
196 
197  std::vector<uint32_t> ids25;
198  ids25 = getIdsAroundMax(5, 5, bx, by, bz, ebmap);
199 
200  for (unsigned i = 0; i < 25; i++) {
201  for (unsigned int j = 0; j < CaloHitMap[ids25[i]].size(); j++) {
202  if (CaloHitMap[ids25[i]][j]->energy() > 0) {
203  int log10i = int((log10(CaloHitMap[ids25[i]][j]->energy()) + 10.) * 10.);
204  if (log10i >= 0 && log10i < 140)
205  econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
206  }
207  }
208  }
209 
210  MapType newebmap;
211  if (fillEBMatrix(3, 3, bx, by, bz, newebmap, ebmap)) {
212  eb4 = eCluster2x2(newebmap);
213  meEBe4_->Fill(eb4);
214  }
215  if (fillEBMatrix(5, 5, bx, by, bz, newebmap, ebmap)) {
216  eb16 = eCluster4x4(eb9, newebmap);
217  meEBe16_->Fill(eb16);
218  }
219 
220  if (eb4 > 0.1)
221  meEBe1oe4_->Fill(eb1 / eb4);
222  if (eb9 > 0.1)
223  meEBe1oe9_->Fill(eb1 / eb9);
224  if (eb9 > 0.1)
225  meEBe4oe9_->Fill(eb4 / eb9);
226  if (eb16 > 0.1)
227  meEBe9oe16_->Fill(eb9 / eb16);
228  if (eb25 > 0.1)
229  meEBe1oe25_->Fill(eb1 / eb25);
230  if (eb25 > 0.1)
231  meEBe9oe25_->Fill(eb9 / eb25);
232  if (eb25 > 0.1)
233  meEBe16oe25_->Fill(eb16 / eb25);
234 
235  if (EBEnergy_ != 0) {
236  for (int i = 0; i < 140; i++) {
237  meEBhitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / EBEnergy_);
238  }
239  }
240 
241  if (eb25 != 0) {
242  for (int i = 0; i < 140; i++) {
243  meEBhitLog10Energy25Norm_->Fill(-10. + (float(i) + 0.5) / 10., econtr25[i] / eb25);
244  }
245  }
246  }
247 
248  if (MyPEcalValidInfo.isValid()) {
249  if (MyPEcalValidInfo->eb1x1() > 0.) {
250  std::vector<float> BX0 = MyPEcalValidInfo->bX0();
252  for (int myStep = 0; myStep < 26; myStep++) {
253  eRLength[myStep] += BX0[myStep];
254  meEBLongitudinalShower_->Fill(float(myStep), eRLength[myStep] / myEntries);
255  }
256  }
257  }
258 }
259 
261  int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap) {
262  int ncristals = 0;
263  float totalEnergy = 0.;
264 
265  int goBackInEta = nCellInEta / 2;
266  int goBackInPhi = nCellInPhi / 2;
267  int startEta = centralZ * centralEta - goBackInEta;
268  int startPhi = centralPhi - goBackInPhi;
269 
270  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
271  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
272  uint32_t index;
273  if (abs(ieta) > 85 || abs(ieta) < 1) {
274  continue;
275  }
276  if (iphi < 1) {
277  index = EBDetId(ieta, iphi + 360).rawId();
278  } else if (iphi > 360) {
279  index = EBDetId(ieta, iphi - 360).rawId();
280  } else {
281  index = EBDetId(ieta, iphi).rawId();
282  }
283 
284  totalEnergy += themap[index];
285  ncristals += 1;
286  }
287  }
288 
289  LogDebug("GeomInfo") << nCellInEta << " x " << nCellInPhi << " EB matrix energy = " << totalEnergy << " for "
290  << ncristals << " crystals";
291  return totalEnergy;
292 }
293 
295  int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap) {
296  int ncristals = 0;
297  std::vector<uint32_t> ids(nCellInEta * nCellInPhi);
298 
299  int goBackInEta = nCellInEta / 2;
300  int goBackInPhi = nCellInPhi / 2;
301  int startEta = centralZ * centralEta - goBackInEta;
302  int startPhi = centralPhi - goBackInPhi;
303 
304  for (int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
305  for (int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
306  uint32_t index;
307  if (abs(ieta) > 85 || abs(ieta) < 1) {
308  continue;
309  }
310  if (iphi < 1) {
311  index = EBDetId(ieta, iphi + 360).rawId();
312  } else if (iphi > 360) {
313  index = EBDetId(ieta, iphi - 360).rawId();
314  } else {
315  index = EBDetId(ieta, iphi).rawId();
316  }
317  ids[ncristals] = index;
318  ncristals += 1;
319  }
320  }
321 
322  return ids;
323 }
324 
326  int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap) {
327  int goBackInEta = nCellInEta / 2;
328  int goBackInPhi = nCellInPhi / 2;
329 
330  int startEta = CentralZ * CentralEta - goBackInEta;
331  int startPhi = CentralPhi - goBackInPhi;
332 
333  int i = 0;
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  fillmap[i++] = themap[index];
348  }
349  }
350 
351  uint32_t ebcenterid = getUnitWithMaxEnergy(themap);
352 
353  if (fillmap[i / 2] == themap[ebcenterid])
354  return true;
355  else
356  return false;
357 }
358 
360  float E22 = 0.;
361  float e012 = themap[0] + themap[1] + themap[2];
362  float e036 = themap[0] + themap[3] + themap[6];
363  float e678 = themap[6] + themap[7] + themap[8];
364  float e258 = themap[2] + themap[5] + themap[8];
365 
366  if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
367  E22 = themap[0] + themap[1] + themap[3] + themap[4];
368  else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
369  E22 = themap[1] + themap[2] + themap[4] + themap[5];
370  else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
371  E22 = themap[3] + themap[4] + themap[6] + themap[7];
372  else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
373  E22 = themap[4] + themap[5] + themap[7] + themap[8];
374 
375  return E22;
376 }
377 
379  float E44 = 0.;
380  float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
381  float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
382  float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
383  float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
384 
385  if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
386  E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
387  else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
388  E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
389  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
390  E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
391  else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
392  E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
393 
394  return E44;
395 }
396 
398  // look for max
399  uint32_t unitWithMaxEnergy = 0;
400  float maxEnergy = 0.;
401 
402  MapType::iterator iter;
403  for (iter = themap.begin(); iter != themap.end(); iter++) {
404  if (maxEnergy < (*iter).second) {
405  maxEnergy = (*iter).second;
406  unitWithMaxEnergy = (*iter).first;
407  }
408  }
409 
410  LogDebug("GeomInfo") << " max energy of " << maxEnergy << " GeV in Unit id " << unitWithMaxEnergy;
411  return unitWithMaxEnergy;
412 }
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
float eb1x1() const
std::vector< uint32_t > getIdsAroundMax(int nCellInEta, int nCellInPhi, int centralEta, int centralPhi, int centralZ, MapType &themap)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
void bookHistograms(DQMStore::IBooker &ib, edm::Run const &, edm::EventSetup const &c) override
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
float eCluster4x4(float e33, MapType &themap)
FloatVector bX0() const
std::map< uint32_t, float, std::less< uint32_t > > MapType
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
edm::EDGetTokenT< edm::PCaloHitContainer > EBHitsToken
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)
Log< level::Info, false > LogInfo
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
bool fillEBMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
Definition: Run.h:45
ib
Definition: cuy.py:661
#define LogDebug(id)
EcalBarrelSimHitsValidation(const edm::ParameterSet &ps)
Constructor.