CMS 3D CMS Logo

SimHitsValidationHcal.cc
Go to the documentation of this file.
5 
6 //#define DebugLog
7 
9  g4Label_ = ps.getParameter<std::string>("ModuleLabel");
10  hcalHits_ = ps.getParameter<std::string>("HitCollection");
11  verbose_ = ps.getParameter<bool>("Verbose");
12  testNumber_ = ps.getParameter<bool>("TestNumber");
13 
14  tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hcalHits_));
15 
16  edm::LogVerbatim("HitsValidationHcal") << "Module Label: " << g4Label_ << " Hits: " << hcalHits_
17  << " TestNumbering " << testNumber_;
18 }
19 
21 
24  es.get<HcalRecNumberingRecord>().get(pHRNDC);
25  hcons = &(*pHRNDC);
30 
31  // Get Phi segmentation from geometry, use the max phi number so that all iphi
32  // values are included.
33 
34  int NphiMax = hcons->getNPhi(0);
35 
36  NphiMax = (hcons->getNPhi(1) > NphiMax ? hcons->getNPhi(1) : NphiMax);
37  NphiMax = (hcons->getNPhi(2) > NphiMax ? hcons->getNPhi(2) : NphiMax);
38  NphiMax = (hcons->getNPhi(3) > NphiMax ? hcons->getNPhi(3) : NphiMax);
39 
40  // Center the iphi bins on the integers
41  float iphi_min = 0.5;
42  float iphi_max = NphiMax + 0.5;
43  int iphi_bins = (int)(iphi_max - iphi_min);
44 
45  int iEtaHBMax = hcons->getEtaRange(0).second;
46  int iEtaHEMax = std::max(hcons->getEtaRange(1).second, 1);
47  int iEtaHFMax = hcons->getEtaRange(2).second;
48  int iEtaHOMax = hcons->getEtaRange(3).second;
49 
50  // Retain classic behavior, all plots have same ieta range.
51  // Comment out code to allow each subdetector to have its on range
52 
53  int iEtaMax = (iEtaHBMax > iEtaHEMax ? iEtaHBMax : iEtaHEMax);
54  iEtaMax = (iEtaMax > iEtaHFMax ? iEtaMax : iEtaHFMax);
55  iEtaMax = (iEtaMax > iEtaHOMax ? iEtaMax : iEtaHOMax);
56 
57  iEtaHBMax = iEtaMax;
58  iEtaHEMax = iEtaMax;
59  iEtaHFMax = iEtaMax;
60  iEtaHOMax = iEtaMax;
61 
62  // Give an empty bin around the subdet ieta range to make it clear that all
63  // ieta rings have been included float ieta_min_HB = -iEtaHBMax - 1.5; float
64  // ieta_max_HB = iEtaHBMax + 1.5; int ieta_bins_HB = (int) (ieta_max_HB -
65  // ieta_min_HB);
66 
67  // float ieta_min_HE = -iEtaHEMax - 1.5;
68  // float ieta_max_HE = iEtaHEMax + 1.5;
69  // int ieta_bins_HE = (int) (ieta_max_HE - ieta_min_HE);
70 
71  // float ieta_min_HF = -iEtaHFMax - 1.5;
72  // float ieta_max_HF = iEtaHFMax + 1.5;
73  // int ieta_bins_HF = (int) (ieta_max_HF - ieta_min_HF);
74 
75  // float ieta_min_HO = -iEtaHOMax - 1.5;
76  // float ieta_max_HO = iEtaHOMax + 1.5;
77  // int ieta_bins_HO = (int) (ieta_max_HO - ieta_min_HO);
78 
79 #ifdef DebugLog
80  edm::LogVerbatim("HitsValidationHcal") << " Maximum Depths HB:" << maxDepthHB_ << " HE:" << maxDepthHE_
81  << " HO:" << maxDepthHO_ << " HF:" << maxDepthHF_;
82 #endif
83  std::vector<std::pair<std::string, std::string>> divisions = getHistogramTypes();
84 
85  edm::LogVerbatim("HitsValidationHcal") << "Booking the Histograms";
86  ib.setCurrentFolder("HcalHitsV/SimHitsValidationHcal");
87 
88  // Histograms for Hits
89 
90  char name[100], title[200];
91  for (unsigned int i = 0; i < types.size(); ++i) {
93  sprintf(name, "HcalHitEta%s", divisions[i].first.c_str());
94  sprintf(title, "Hit energy as a function of eta tower index in %s", divisions[i].second.c_str());
95  meHcalHitEta_.push_back(ib.book1D(name, title, limit.bins, limit.low, limit.high));
96 
97  sprintf(name, "HcalHitTimeAEta%s", divisions[i].first.c_str());
98  sprintf(title, "Hit time as a function of eta tower index in %s", divisions[i].second.c_str());
99  meHcalHitTimeEta_.push_back(ib.book1D(name, title, limit.bins, limit.low, limit.high));
100 
101  sprintf(name, "HcalHitE25%s", divisions[i].first.c_str());
102  sprintf(title, "Energy in time window 0 to 25 for a tower in %s", divisions[i].second.c_str());
103  meHcalEnergyl25_.push_back(
104  ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
105 
106  sprintf(name, "HcalHitE50%s", divisions[i].first.c_str());
107  sprintf(title, "Energy in time window 0 to 50 for a tower in %s", divisions[i].second.c_str());
108  meHcalEnergyl50_.push_back(
109  ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
110 
111  sprintf(name, "HcalHitE100%s", divisions[i].first.c_str());
112  sprintf(title, "Energy in time window 0 to 100 for a tower in %s", divisions[i].second.c_str());
113  meHcalEnergyl100_.push_back(
114  ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
115 
116  sprintf(name, "HcalHitE250%s", divisions[i].first.c_str());
117  sprintf(title, "Energy in time window 0 to 250 for a tower in %s", divisions[i].second.c_str());
118  meHcalEnergyl250_.push_back(
119  ib.book2D(name, title, limit.bins, limit.low, limit.high, iphi_bins, iphi_min, iphi_max));
120  }
121 
122  sprintf(name, "Energy_HB");
123  meEnergy_HB = ib.book1D(name, name, 100, 0, 1);
124  sprintf(name, "Energy_HE");
125  meEnergy_HE = ib.book1D(name, name, 100, 0, 1);
126  sprintf(name, "Energy_HO");
127  meEnergy_HO = ib.book1D(name, name, 100, 0, 1);
128  sprintf(name, "Energy_HF");
129  meEnergy_HF = ib.book1D(name, name, 100, 0, 50);
130 
131  sprintf(name, "Time_HB");
132  metime_HB = ib.book1D(name, name, 300, -150, 150);
133  sprintf(name, "Time_HE");
134  metime_HE = ib.book1D(name, name, 300, -150, 150);
135  sprintf(name, "Time_HO");
136  metime_HO = ib.book1D(name, name, 300, -150, 150);
137  sprintf(name, "Time_HF");
138  metime_HF = ib.book1D(name, name, 300, -150, 150);
139 
140  sprintf(name, "Time_Enweighted_HB");
141  metime_enweighted_HB = ib.book1D(name, name, 300, -150, 150);
142  sprintf(name, "Time_Enweighted_HE");
143  metime_enweighted_HE = ib.book1D(name, name, 300, -150, 150);
144  sprintf(name, "Time_Enweighted_HO");
145  metime_enweighted_HO = ib.book1D(name, name, 300, -150, 150);
146  sprintf(name, "Time_Enweighted_HF");
147  metime_enweighted_HF = ib.book1D(name, name, 300, -150, 150);
148 }
149 
151 #ifdef DebugLog
152  edm::LogVerbatim("HitsValidationHcal") << "Run = " << e.id().run() << " Event = " << e.id().event();
153 #endif
154  std::vector<PCaloHit> caloHits;
156 
157  bool getHits = false;
158  e.getByToken(tok_hits_, hitsHcal);
159  if (hitsHcal.isValid())
160  getHits = true;
161 #ifdef DebugLog
162  edm::LogVerbatim("HitsValidationHcal") << "HitsValidationHcal.: Input flags Hits " << getHits;
163 #endif
164  if (getHits) {
165  caloHits.insert(caloHits.end(), hitsHcal->begin(), hitsHcal->end());
166 #ifdef DebugLog
167  edm::LogVerbatim("HitsValidationHcal") << "testNumber_:" << testNumber_;
168 #endif
169  if (testNumber_) {
170  for (unsigned int i = 0; i < caloHits.size(); ++i) {
171  unsigned int id_ = caloHits[i].id();
173  caloHits[i].setID(hid.rawId());
174 #ifdef DebugLog
175  edm::LogVerbatim("HitsValidationHcal") << "Hit[" << i << "] " << hid;
176 #endif
177  }
178  }
179 #ifdef DebugLog
180  edm::LogVerbatim("HitsValidationHcal") << "HitsValidationHcal: Hit buffer " << caloHits.size();
181 #endif
182  analyzeHits(caloHits);
183  }
184 }
185 
186 void SimHitsValidationHcal::analyzeHits(std::vector<PCaloHit> &hits) {
187  int nHit = hits.size();
188  double entotHB = 0, entotHE = 0, entotHF = 0, entotHO = 0;
189  double timetotHB = 0, timetotHE = 0, timetotHF = 0, timetotHO = 0;
190  int nHB = 0, nHE = 0, nHO = 0, nHF = 0;
191 
192  std::map<std::pair<HcalDetId, unsigned int>, energysum> map_try;
193  map_try.clear();
194  std::map<std::pair<HcalDetId, unsigned int>, energysum>::iterator itr;
195 
196  for (int i = 0; i < nHit; i++) {
197  double energy = hits[i].energy();
198  double time = hits[i].time();
199  HcalDetId id = HcalDetId(hits[i].id());
200  int itime = (int)(time);
201  int subdet = id.subdet();
202  int depth = id.depth();
203  int eta = id.ieta();
204  unsigned int dep = hits[i].depth();
205 
206  std::pair<int, int> types = histId(subdet, eta, depth, dep);
207  if (subdet == static_cast<int>(HcalBarrel)) {
208  entotHB += energy;
209  timetotHB += time;
210  nHB++;
211  } else if (subdet == static_cast<int>(HcalEndcap)) {
212  entotHE += energy;
213  timetotHE += time;
214  nHE++;
215  } else if (subdet == static_cast<int>(HcalOuter)) {
216  entotHO += energy;
217  timetotHO += time;
218  nHO++;
219  } else if (subdet == static_cast<int>(HcalForward)) {
220  entotHF += energy;
221  timetotHF += time;
222  nHF++;
223  }
224 
225  std::pair<HcalDetId, unsigned int> id0(id, dep);
226  energysum ensum;
227  if (map_try.count(id0) != 0)
228  ensum = map_try[id0];
229  if (itime < 250) {
230  ensum.e250 += energy;
231  if (itime < 100) {
232  ensum.e100 += energy;
233  if (itime < 50) {
234  ensum.e50 += energy;
235  if (itime < 25)
236  ensum.e25 += energy;
237  }
238  }
239  }
240  map_try[id0] = ensum;
241 
242 #ifdef DebugLog
243  edm::LogVerbatim("HitsValidationHcal")
244  << "Hit[" << i << "] ID " << std::dec << " " << id << std::dec << " Det " << id.det() << " Sub " << subdet
245  << " depth " << depth << " depthX " << dep << " Eta " << eta << " Phi " << id.iphi() << " E " << energy
246  << " time " << time << " type " << types.first << " " << types.second;
247 #endif
248 
249  double etax = eta - 0.5;
250  if (eta < 0)
251  etax += 1;
252  if (types.first >= 0) {
253  meHcalHitEta_[types.first]->Fill(etax, energy);
254  meHcalHitTimeEta_[types.first]->Fill(etax, time);
255  }
256  if (types.second >= 0) {
257  meHcalHitEta_[types.second]->Fill(etax, energy);
258  meHcalHitTimeEta_[types.second]->Fill(etax, time);
259  }
260  }
261 
262  meEnergy_HB->Fill(entotHB);
263  meEnergy_HE->Fill(entotHE);
264  meEnergy_HF->Fill(entotHF);
265  meEnergy_HO->Fill(entotHO);
266 
267  metime_HB->Fill(timetotHB);
268  metime_HE->Fill(timetotHE);
269  metime_HF->Fill(timetotHF);
270  metime_HO->Fill(timetotHO);
271 
272  metime_enweighted_HB->Fill(timetotHB, entotHB);
273  metime_enweighted_HE->Fill(timetotHE, entotHE);
274  metime_enweighted_HF->Fill(timetotHF, entotHF);
275  metime_enweighted_HO->Fill(timetotHO, entotHO);
276 
277  for (itr = map_try.begin(); itr != map_try.end(); ++itr) {
278  HcalDetId id = (*itr).first.first;
279  energysum ensum = (*itr).second;
280  std::pair<int, int> types = histId((int)(id.subdet()), id.ieta(), id.depth(), (*itr).first.second);
281  int eta = id.ieta();
282  int phi = id.iphi();
283  double etax = eta - 0.5;
284  double phix = phi - 0.5;
285  if (types.first >= 0) {
286  meHcalEnergyl25_[types.first]->Fill(etax, phix, ensum.e25);
287  meHcalEnergyl50_[types.first]->Fill(etax, phix, ensum.e50);
288  meHcalEnergyl100_[types.first]->Fill(etax, phix, ensum.e100);
289  meHcalEnergyl250_[types.first]->Fill(etax, phix, ensum.e250);
290  }
291  if (types.second >= 0) {
292  meHcalEnergyl25_[types.second]->Fill(etax, phix, ensum.e25);
293  meHcalEnergyl50_[types.second]->Fill(etax, phix, ensum.e50);
294  meHcalEnergyl100_[types.second]->Fill(etax, phix, ensum.e100);
295  meHcalEnergyl250_[types.second]->Fill(etax, phix, ensum.e250);
296  }
297 
298 #ifdef DebugLog
299  edm::LogVerbatim("HitsValidationHcal")
300  << " energy of tower =" << (*itr).first.first << " in time 25ns is == " << (*itr).second.e25
301  << " in time 25-50ns == " << (*itr).second.e50 << " in time 50-100ns == " << (*itr).second.e100
302  << " in time 100-250 ns == " << (*itr).second.e250;
303 #endif
304  }
305 }
306 
308  int bins;
309  std::pair<int, int> range;
310  double low, high;
311 
312  if (type.subdet == HcalBarrel) {
313  range = hcons->getEtaRange(0);
314  low = -range.second;
315  high = range.second;
316  bins = (high - low);
317  } else if (type.subdet == HcalEndcap) {
318  range = hcons->getEtaRange(1);
319  bins = range.second - range.first;
320  if (type.z == 1) {
321  low = range.first;
322  high = range.second;
323  } else {
324  low = -range.second;
325  high = -range.first;
326  }
327  } else if (type.subdet == HcalOuter) {
328  range = hcons->getEtaRange(3);
329  low = -range.second;
330  high = range.second;
331  bins = high - low;
332  } else if (type.subdet == HcalForward) {
333  range = hcons->getEtaRange(2);
334  bins = range.second - range.first;
335  if (type.z == 1) {
336  low = range.first;
337  high = range.second;
338  } else {
339  low = -range.second;
340  high = -range.first;
341  }
342  } else {
343  bins = 82;
344  low = -41;
345  high = 41;
346  }
347 #ifdef DebugLog
348  edm::LogVerbatim("HitsValidationHcal") << "Subdetector:" << type.subdet << " z:" << type.z
349  << " range.first:" << range.first << " and second:" << range.second;
350  edm::LogVerbatim("HitsValidationHcal") << "bins: " << bins << " low:" << low << " high:" << high;
351 #endif
352  return SimHitsValidationHcal::etaRange(bins, low, high);
353 }
354 
355 std::pair<int, int> SimHitsValidationHcal::histId(int subdet, int eta, int depth, unsigned int dep) {
356  int id1(-1), id2(-1);
357  for (unsigned int k = 0; k < types.size(); ++k) {
358  if (subdet == HcalForward) {
359  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1 && eta * types[k].z > 0 &&
360  dep == (unsigned int)(types[k].depth2)) {
361  id1 = k;
362  break;
363  }
364  } else if (subdet == HcalEndcap) {
365  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1 && eta * types[k].z > 0) {
366  id1 = k;
367  break;
368  }
369  } else {
370  if (subdet == (int)(types[k].subdet) && depth == types[k].depth1) {
371  id1 = k;
372  break;
373  }
374  }
375  }
376  if (subdet == HcalForward)
377  depth += 2 * dep;
378  for (unsigned int k = 0; k < types.size(); ++k) {
379  if (types[k].subdet == HcalEmpty && types[k].depth1 == depth) {
380  id2 = k;
381  break;
382  }
383  }
384  return std::pair<int, int>(id1, id2);
385 }
386 
387 std::vector<std::pair<std::string, std::string>> SimHitsValidationHcal::getHistogramTypes() {
389  maxDepth = std::max(maxDepth, maxDepthHF_);
390  maxDepth = std::max(maxDepth, maxDepthHO_);
391 
392  std::vector<std::pair<std::string, std::string>> divisions;
393  std::pair<std::string, std::string> names;
394  char name1[40], name2[40];
396  // first overall Hcal
397  for (int depth = 0; depth < maxDepth; ++depth) {
398  snprintf(name1, 40, "HC%d", depth);
399  snprintf(name2, 40, "HCAL depth%d", depth + 1);
400  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
401  type = SimHitsValidationHcal::idType(HcalEmpty, 0, depth + 1, depth + 1);
402  divisions.push_back(names);
403  types.push_back(type);
404  }
405  // HB
406  for (int depth = 0; depth < maxDepthHB_; ++depth) {
407  snprintf(name1, 40, "HB%d", depth);
408  snprintf(name2, 40, "HB depth%d", depth + 1);
409  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
411  divisions.push_back(names);
412  types.push_back(type);
413  }
414  // HE
415  for (int depth = 0; depth < maxDepthHE_; ++depth) {
416  snprintf(name1, 40, "HE%d+z", depth);
417  snprintf(name2, 40, "HE +z depth%d", depth + 1);
418  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
420  divisions.push_back(names);
421  types.push_back(type);
422  snprintf(name1, 40, "HE%d-z", depth);
423  snprintf(name2, 40, "HE -z depth%d", depth + 1);
424  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
425  type = SimHitsValidationHcal::idType(HcalEndcap, -1, depth + 1, depth + 1);
426  divisions.push_back(names);
427  types.push_back(type);
428  }
429  // HO
430  {
431  int depth = maxDepthHO_;
432  snprintf(name1, 40, "HO%d", depth);
433  snprintf(name2, 40, "HO depth%d", depth);
434  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
435  type = SimHitsValidationHcal::idType(HcalOuter, 0, depth, depth);
436  divisions.push_back(names);
437  types.push_back(type);
438  }
439  // HF (first absorber, then different types of abnormal hits)
440  std::string hfty1[4] = {"A", "W", "B", "J"};
441  std::string hfty2[4] = {"Absorber", "Window", "Bundle", "Jungle"};
442  int dept0[4] = {0, 1, 2, 3};
443  for (int k = 0; k < 4; ++k) {
444  for (int depth = 0; depth < maxDepthHF_; ++depth) {
445  snprintf(name1, 40, "HF%s%d+z", hfty1[k].c_str(), depth);
446  snprintf(name2, 40, "HF (%s) +z depth%d", hfty2[k].c_str(), depth + 1);
447  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
448  type = SimHitsValidationHcal::idType(HcalForward, 1, depth + 1, dept0[k]);
449  divisions.push_back(names);
450  types.push_back(type);
451  snprintf(name1, 40, "HF%s%d-z", hfty1[k].c_str(), depth);
452  snprintf(name2, 40, "HF (%s) -z depth%d", hfty2[k].c_str(), depth + 1);
453  names = std::pair<std::string, std::string>(std::string(name1), std::string(name2));
454  type = SimHitsValidationHcal::idType(HcalForward, -1, depth + 1, dept0[k]);
455  divisions.push_back(names);
456  types.push_back(type);
457  }
458  }
459 
460  return divisions;
461 }
462 
465  desc.add<std::string>("ModuleLabel", "g4SimHits");
466  desc.add<std::string>("HitCollection", "HcalHits");
467  desc.add<bool>("Verbose", false);
468  desc.add<bool>("TestNumber", false);
469 
470  descriptions.addDefault(desc);
471 }
472 
RunNumber_t run() const
Definition: EventID.h:38
SimHitsValidationHcal(const edm::ParameterSet &ps)
type
Definition: HCALResponse.h:21
MonitorElement * meEnergy_HF
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
const HcalDDDRecConstants * hcons
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
MonitorElement * metime_enweighted_HO
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void analyze(const edm::Event &e, const edm::EventSetup &c) override
const std::string names[nVars_]
MonitorElement * metime_enweighted_HB
void Fill(long long x)
std::vector< MonitorElement * > meHcalEnergyl25_
U second(std::pair< T, U > const &p)
MonitorElement * meEnergy_HB
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< MonitorElement * > meHcalEnergyl100_
MonitorElement * metime_enweighted_HF
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
MonitorElement * metime_enweighted_HE
std::vector< MonitorElement * > meHcalEnergyl250_
std::vector< MonitorElement * > meHcalHitEta_
int getMaxDepth(const int &type) const
MonitorElement * meEnergy_HE
std::vector< MonitorElement * > meHcalEnergyl50_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EventID id() const
Definition: EventBase.h:59
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
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > meHcalHitTimeEta_
std::pair< int, int > histId(int subdet, int eta, int depth, unsigned int dep)
DetId relabel(const uint32_t testId) const
std::pair< int, int > getEtaRange(const int &i) const
MonitorElement * meEnergy_HO
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
Definition: Run.h:45
int getNPhi(const int &type) const
ib
Definition: cuy.py:662
std::vector< std::pair< std::string, std::string > > getHistogramTypes()
void analyzeHits(std::vector< PCaloHit > &)