CMS 3D CMS Logo

CaloSimHitStudy.cc
Go to the documentation of this file.
3 
7 
14 
17 
20 
27 
28 #include <TH1F.h>
29 
30 #include <memory>
31 #include <iostream>
32 #include <fstream>
33 #include <vector>
34 #include <map>
35 #include <string>
36 
37 //#define EDM_ML_DEBUG
38 
39 class CaloSimHitStudy : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
40 public:
42  ~CaloSimHitStudy() override {}
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44 
45 protected:
46  void beginJob() override {}
47  void analyze(edm::Event const&, edm::EventSetup const&) override;
48  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
49  void endRun(edm::Run const&, edm::EventSetup const&) override {}
50 
51  void analyzeHits(std::vector<PCaloHit>&, int);
53  void analyzeHits(std::vector<PCaloHit>&, std::vector<PCaloHit>&, std::vector<PCaloHit>&);
54 
55 private:
57  const std::vector<std::string> hitLab_;
58  const double maxEnergy_, tmax_, eMIP_;
59  const bool storeRL_, testNumber_;
61  std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>> toks_calo_;
62  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toks_track_;
63  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toks_tkHigh_;
64  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toks_tkLow_;
65 
66  const std::vector<std::string> muonLab_ = {"MuonRPCHits", "MuonCSCHits", "MuonDTHits", "MuonGEMHits"};
67  const std::vector<std::string> tkHighLab_ = {"TrackerHitsPixelBarrelHighTof",
68  "TrackerHitsPixelEndcapHighTof",
69  "TrackerHitsTECHighTof",
70  "TrackerHitsTIBHighTof",
71  "TrackerHitsTIDHighTof",
72  "TrackerHitsTOBHighTof"};
73  const std::vector<std::string> tkLowLab_ = {"TrackerHitsPixelBarrelLowTof",
74  "TrackerHitsPixelEndcapLowTof",
75  "TrackerHitsTECLowTof",
76  "TrackerHitsTIBLowTof",
77  "TrackerHitsTIDLowTof",
78  "TrackerHitsTOBLowTof"};
79 
80  TH1F *hit_[9], *time_[9], *edepEM_[9], *edepHad_[9], *edep_[9];
81  TH1F *etot_[9], *etotg_[9], *timeAll_[9], *hitMu, *hitHigh;
83  TH1F *hitTk_[16], *edepTk_[16], *tofTk_[16], *edepC_[9], *edepT_[9];
84 };
85 
87  : g4Label_(ps.getUntrackedParameter<std::string>("ModuleLabel")),
88  hitLab_(ps.getUntrackedParameter<std::vector<std::string>>("CaloCollection")),
89  maxEnergy_(ps.getUntrackedParameter<double>("MaxEnergy", 200.0)),
90  tmax_(ps.getUntrackedParameter<double>("TimeCut", 100.0)),
91  eMIP_(ps.getUntrackedParameter<double>("MIPCut", 0.70)),
92  storeRL_(ps.getUntrackedParameter<bool>("StoreRL", false)),
93  testNumber_(ps.getUntrackedParameter<bool>("TestNumbering", true)) {
94  usesResource(TFileService::kSharedResource);
95 
96  tok_evt_ =
97  consumes<edm::HepMCProduct>(edm::InputTag(ps.getUntrackedParameter<std::string>("SourceLabel", "VtxSmeared")));
98  for (unsigned i = 0; i != hitLab_.size(); i++)
99  toks_calo_.emplace_back(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLab_[i])));
100  for (unsigned i = 0; i != muonLab_.size(); i++)
101  toks_track_.emplace_back(consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, muonLab_[i])));
102  for (unsigned i = 0; i != tkHighLab_.size(); i++)
103  toks_tkHigh_.emplace_back(consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, tkHighLab_[i])));
104  for (unsigned i = 0; i != tkLowLab_.size(); i++)
105  toks_tkLow_.emplace_back(consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, tkLowLab_[i])));
106 
107  edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << " Hits: " << hitLab_[0] << ", " << hitLab_[1]
108  << ", " << hitLab_[2] << ", " << hitLab_[3] << " MaxEnergy: " << maxEnergy_
109  << " Tmax: " << tmax_ << " MIP Cut: " << eMIP_;
110 
112 
113  if (!tfile.isAvailable())
114  throw cms::Exception("BadConfig") << "TFileService unavailable: "
115  << "please add it to config file";
116  char name[20], title[120];
117  sprintf(title, "Incident PT (GeV)");
118  ptInc_ = tfile->make<TH1F>("PtInc", title, 1000, 0., maxEnergy_);
119  ptInc_->GetXaxis()->SetTitle(title);
120  ptInc_->GetYaxis()->SetTitle("Events");
121  sprintf(title, "Incident Energy (GeV)");
122  eneInc_ = tfile->make<TH1F>("EneInc", title, 1000, 0., maxEnergy_);
123  eneInc_->GetXaxis()->SetTitle(title);
124  eneInc_->GetYaxis()->SetTitle("Events");
125  sprintf(title, "Incident #eta");
126  etaInc_ = tfile->make<TH1F>("EtaInc", title, 200, -5., 5.);
127  etaInc_->GetXaxis()->SetTitle(title);
128  etaInc_->GetYaxis()->SetTitle("Events");
129  sprintf(title, "Incident #phi");
130  phiInc_ = tfile->make<TH1F>("PhiInc", title, 200, -3.1415926, 3.1415926);
131  phiInc_->GetXaxis()->SetTitle(title);
132  phiInc_->GetYaxis()->SetTitle("Events");
133 #ifdef EDM_ML_DEBUG
134  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for incident particle";
135 #endif
136  std::string dets[9] = {"EB", "EB(APD)", "EB(ATJ)", "EE", "ES", "HB", "HE", "HO", "HF"};
137  double nhcMax[9] = {40000., 2000., 2000., 40000., 10000., 10000., 10000., 2000., 10000.};
138  for (int i = 0; i < 9; i++) {
139  sprintf(name, "Hit%d", i);
140  sprintf(title, "Number of hits in %s", dets[i].c_str());
141  hit_[i] = tfile->make<TH1F>(name, title, 1000, 0., nhcMax[i]);
142  hit_[i]->GetXaxis()->SetTitle(title);
143  hit_[i]->GetYaxis()->SetTitle("Events");
144  sprintf(name, "Time%d", i);
145  sprintf(title, "Time of the hit (ns) in %s", dets[i].c_str());
146  time_[i] = tfile->make<TH1F>(name, title, 1000, 0., 1000.);
147  time_[i]->GetXaxis()->SetTitle(title);
148  time_[i]->GetYaxis()->SetTitle("Hits");
149  sprintf(name, "TimeAll%d", i);
150  sprintf(title, "Hit time (ns) in %s with no check on Track ID", dets[i].c_str());
151  timeAll_[i] = tfile->make<TH1F>(name, title, 1000, 0., 1000.);
152  timeAll_[i]->GetXaxis()->SetTitle(title);
153  timeAll_[i]->GetYaxis()->SetTitle("Hits");
154  double ymax = maxEnergy_;
155  if (i == 1 || i == 2 || i == 4)
156  ymax = 1.0;
157  else if (i > 4 && i < 8)
158  ymax = 10.0;
159  sprintf(name, "Edep%d", i);
160  sprintf(title, "Energy deposit (GeV) in %s", dets[i].c_str());
161  edep_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
162  edep_[i]->GetXaxis()->SetTitle(title);
163  edep_[i]->GetYaxis()->SetTitle("Hits");
164  sprintf(name, "EdepEM%d", i);
165  sprintf(title, "Energy deposit (GeV) by EM particles in %s", dets[i].c_str());
166  edepEM_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
167  edepEM_[i]->GetXaxis()->SetTitle(title);
168  edepEM_[i]->GetYaxis()->SetTitle("Hits");
169  sprintf(name, "EdepHad%d", i);
170  sprintf(title, "Energy deposit (GeV) by hadrons in %s", dets[i].c_str());
171  edepHad_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
172  edepHad_[i]->GetXaxis()->SetTitle(title);
173  edepHad_[i]->GetYaxis()->SetTitle("Hits");
174  sprintf(name, "Etot%d", i);
175  sprintf(title, "Total energy deposit (GeV) in %s", dets[i].c_str());
176  etot_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
177  etot_[i]->GetXaxis()->SetTitle(title);
178  etot_[i]->GetYaxis()->SetTitle("Events");
179  sprintf(name, "EtotG%d", i);
180  sprintf(title, "Total energy deposit (GeV) in %s (t < 100 ns)", dets[i].c_str());
181  etotg_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
182  etotg_[i]->GetXaxis()->SetTitle(title);
183  etotg_[i]->GetYaxis()->SetTitle("Events");
184  }
185 #ifdef EDM_ML_DEBUG
186  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for first level of Calorimeter";
187 #endif
188  std::string detx[9] = {"EB/EE (MIP)",
189  "HB/HE (MIP)",
190  "HB/HE/HO (MIP)",
191  "EB/EE (no MIP)",
192  "HB/HE (no MIP)",
193  "HB/HE/HO (no MIP)",
194  "EB/EE (All)",
195  "HB/HE (All)",
196  "HB/HE/HO (All)"};
197  for (int i = 0; i < 9; i++) {
198  double ymax = 1.0;
199  if (i == 0 || i == 3 || i == 6)
200  ymax = maxEnergy_;
201  sprintf(name, "EdepCal%d", i);
202  sprintf(title, "Energy deposit in %s", detx[i].c_str());
203  edepC_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
204  edepC_[i]->GetXaxis()->SetTitle(title);
205  edepC_[i]->GetYaxis()->SetTitle("Events");
206  sprintf(name, "EdepCalT%d", i);
207  sprintf(title, "Energy deposit (t < %f ns) in %s", tmax_, detx[i].c_str());
208  edepT_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
209  edepT_[i]->GetXaxis()->SetTitle(title);
210  edepT_[i]->GetYaxis()->SetTitle("Events");
211  }
212 #ifdef EDM_ML_DEBUG
213  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for second level of Calorimeter";
214 #endif
215  hitLow = tfile->make<TH1F>("HitLow", "Number of hits in Track (Low)", 1000, 0, 20000.);
216  hitLow->GetXaxis()->SetTitle("Number of hits in Track (Low)");
217  hitLow->GetYaxis()->SetTitle("Events");
218  hitHigh = tfile->make<TH1F>("HitHigh", "Number of hits in Track (High)", 1000, 0, 5000.);
219  hitHigh->GetXaxis()->SetTitle("Number of hits in Track (High)");
220  hitHigh->GetYaxis()->SetTitle("Events");
221  hitMu = tfile->make<TH1F>("HitMu", "Number of hits in Track (Muon)", 1000, 0, 2000.);
222  hitMu->GetXaxis()->SetTitle("Number of hits in Muon");
223  hitMu->GetYaxis()->SetTitle("Events");
224 #ifdef EDM_ML_DEBUG
225  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for general tracking hits";
226 #endif
227  std::string dett[16] = {"Pixel Barrel (High)",
228  "Pixel Endcap (High)",
229  "TEC (High)",
230  "TIB (High)",
231  "TID (High)",
232  "TOB (High)",
233  "Pixel Barrel (Low)",
234  "Pixel Endcap (Low)",
235  "TEC (Low)",
236  "TIB (Low)",
237  "TID (Low)",
238  "TOB (Low)",
239  "RPC",
240  "CSC",
241  "DT",
242  "GEM"};
243  double nhtMax[16] = {
244  500., 500., 1000., 1000., 500., 1000., 5000., 2000., 10000., 5000., 2000., 5000., 500., 1000., 1000., 500.};
245  for (int i = 0; i < 16; i++) {
246  sprintf(name, "HitTk%d", i);
247  sprintf(title, "Number of hits in %s", dett[i].c_str());
248  hitTk_[i] = tfile->make<TH1F>(name, title, 1000, 0., nhtMax[i]);
249  hitTk_[i]->GetXaxis()->SetTitle(title);
250  hitTk_[i]->GetYaxis()->SetTitle("Events");
251  sprintf(name, "TimeTk%d", i);
252  sprintf(title, "Time of the hit (ns) in %s", dett[i].c_str());
253  tofTk_[i] = tfile->make<TH1F>(name, title, 1000, 0., 200.);
254  tofTk_[i]->GetXaxis()->SetTitle(title);
255  tofTk_[i]->GetYaxis()->SetTitle("Hits");
256  sprintf(name, "EdepTk%d", i);
257  sprintf(title, "Energy deposit (GeV) in %s", dett[i].c_str());
258  double ymax = (i < 12) ? 0.25 : 0.005;
259  edepTk_[i] = tfile->make<TH1F>(name, title, 250, 0., ymax);
260  edepTk_[i]->GetXaxis()->SetTitle(title);
261  edepTk_[i]->GetYaxis()->SetTitle("Hits");
262  }
263 #ifdef EDM_ML_DEBUG
264  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for SimHit objects";
265 #endif
266 }
267 
270  std::vector<std::string> calonames = {"EcalHitsEB", "EcalHitsEE", "EcalHitsES", "HcalHits"};
271  desc.addUntracked<std::string>("SourceLabel", "generatorSmeared");
272  desc.addUntracked<std::string>("ModuleLabel", "g4SimHits");
273  desc.addUntracked<std::vector<std::string>>("CaloCollection", calonames);
274  desc.addUntracked<double>("MaxEnergy", 200.0);
275  desc.addUntracked<double>("TimeCut", 100.0);
276  desc.addUntracked<double>("MIPCut", 0.70);
277  desc.addUntracked<bool>("StoreRL", false);
278  desc.addUntracked<bool>("TestNumbering", true);
279  descriptions.add("CaloSimHitStudy", desc);
280 }
281 
283  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy:Run = " << e.id().run() << " Event = " << e.id().event();
284 
285  const edm::Handle<edm::HepMCProduct> EvtHandle = e.getHandle(tok_evt_);
286  const HepMC::GenEvent* myGenEvent = EvtHandle->GetEvent();
287 
288  double eInc = 0, etaInc = 0, phiInc = 0;
289  HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
290  if (p != myGenEvent->particles_end()) {
291  eInc = (*p)->momentum().e();
292  etaInc = (*p)->momentum().eta();
293  phiInc = (*p)->momentum().phi();
294  }
295  double ptInc = eInc / std::cosh(etaInc);
296  ptInc_->Fill(ptInc);
297  eneInc_->Fill(eInc);
298  etaInc_->Fill(etaInc);
299  phiInc_->Fill(phiInc);
300 
301  std::vector<PCaloHit> ebHits, eeHits, hcHits;
302  for (unsigned int i = 0; i < toks_calo_.size(); i++) {
303  bool getHits = false;
304  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(toks_calo_[i]);
305  if (hitsCalo.isValid())
306  getHits = true;
307 #ifdef EDM_ML_DEBUG
308  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Input flags Hits " << getHits;
309 #endif
310  if (getHits) {
311  std::vector<PCaloHit> caloHits;
312  caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
313  if (i == 0)
314  ebHits.insert(ebHits.end(), hitsCalo->begin(), hitsCalo->end());
315  else if (i == 1)
316  eeHits.insert(eeHits.end(), hitsCalo->begin(), hitsCalo->end());
317  else if (i == 3)
318  hcHits.insert(hcHits.end(), hitsCalo->begin(), hitsCalo->end());
319 #ifdef EDM_ML_DEBUG
320  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Hit buffer " << caloHits.size();
321 #endif
322  analyzeHits(caloHits, i);
323  }
324  }
325  analyzeHits(ebHits, eeHits, hcHits);
326 
327  std::vector<PSimHit> muonHits;
328  for (unsigned int i = 0; i < toks_track_.size(); i++) {
329  const edm::Handle<edm::PSimHitContainer>& hitsTrack = e.getHandle(toks_track_[i]);
330  if (hitsTrack.isValid()) {
331  muonHits.insert(muonHits.end(), hitsTrack->begin(), hitsTrack->end());
332  analyzeHits(hitsTrack, i + 12);
333  }
334  }
335  unsigned int nhmu = muonHits.size();
336  hitMu->Fill(double(nhmu));
337  std::vector<PSimHit> tkHighHits;
338  for (unsigned int i = 0; i < toks_tkHigh_.size(); i++) {
339  const edm::Handle<edm::PSimHitContainer>& hitsTrack = e.getHandle(toks_tkHigh_[i]);
340  if (hitsTrack.isValid()) {
341  tkHighHits.insert(tkHighHits.end(), hitsTrack->begin(), hitsTrack->end());
342  analyzeHits(hitsTrack, i);
343  }
344  }
345  unsigned int nhtkh = tkHighHits.size();
346  hitHigh->Fill(double(nhtkh));
347  std::vector<PSimHit> tkLowHits;
348  for (unsigned int i = 0; i < toks_tkLow_.size(); i++) {
349  const edm::Handle<edm::PSimHitContainer>& hitsTrack = e.getHandle(toks_tkLow_[i]);
350  if (hitsTrack.isValid()) {
351  tkLowHits.insert(tkLowHits.end(), hitsTrack->begin(), hitsTrack->end());
352  analyzeHits(hitsTrack, i + 6);
353  }
354  }
355  unsigned int nhtkl = tkLowHits.size();
356  hitLow->Fill(double(nhtkl));
357 }
358 
359 void CaloSimHitStudy::analyzeHits(std::vector<PCaloHit>& hits, int indx) {
360  int nHit = hits.size();
361  int nHB(0), nHE(0), nHO(0), nHF(0), nEB(0), nEBAPD(0), nEBATJ(0), nEE(0), nES(0);
362 #ifdef EDM_ML_DEBUG
363  int nBad(0);
364 #endif
365  std::map<unsigned int, double> hitMap;
366  std::vector<double> etot(9, 0), etotG(9, 0);
367  for (int i = 0; i < nHit; i++) {
368  double edep = hits[i].energy();
369  double time = hits[i].time();
370  unsigned int id_ = hits[i].id();
371  double edepEM = hits[i].energyEM();
372  double edepHad = hits[i].energyHad();
373  if (indx == 0) {
374  int dep = (hits[i].depth()) & PCaloHit::kEcalDepthIdMask;
375  if (dep == 1)
376  id_ |= 0x20000;
377  else if (dep == 2)
378  id_ |= 0x40000;
379  }
380  std::map<unsigned int, double>::const_iterator it = hitMap.find(id_);
381  if (it == hitMap.end()) {
382  hitMap.insert(std::pair<unsigned int, double>(id_, time));
383  }
384  int idx = -1;
385  if (indx != 3) {
386  if (indx == 0) {
387  if (storeRL_)
388  idx = 0;
389  else
390  idx = ((hits[i].depth()) & PCaloHit::kEcalDepthIdMask);
391  } else
392  idx = indx + 2;
393  time_[idx]->Fill(time);
394  edep_[idx]->Fill(edep);
395  edepEM_[idx]->Fill(edepEM);
396  edepHad_[idx]->Fill(edepHad);
397  if (idx == 0)
398  nEB++;
399  else if (idx == 1)
400  nEBAPD++;
401  else if (idx == 2)
402  nEBATJ++;
403  else if (idx == 3)
404  nEE++;
405  else if (idx == 4)
406  nES++;
407 #ifdef EDM_ML_DEBUG
408  else
409  nBad++;
410 #endif
411  if (indx >= 0 && indx < 3) {
412  etot[idx] += edep;
413  if (time < 100)
414  etotG[idx] += edep;
415  }
416  } else {
417  int subdet(0);
418  if (testNumber_) {
419  int ieta(0), phi(0), z(0), lay(0), depth(0);
420  HcalTestNumbering::unpackHcalIndex(id_, subdet, z, depth, ieta, phi, lay);
421  } else {
422  HcalDetId id = HcalDetId(id_);
423  subdet = id.subdet();
424  }
425  if (subdet == static_cast<int>(HcalBarrel)) {
426  idx = indx + 2;
427  nHB++;
428  } else if (subdet == static_cast<int>(HcalEndcap)) {
429  idx = indx + 3;
430  nHE++;
431  } else if (subdet == static_cast<int>(HcalOuter)) {
432  idx = indx + 4;
433  nHO++;
434  } else if (subdet == static_cast<int>(HcalForward)) {
435  idx = indx + 5;
436  nHF++;
437  }
438  if (idx > 0) {
439  time_[idx]->Fill(time);
440  edep_[idx]->Fill(edep);
441  edepEM_[idx]->Fill(edepEM);
442  edepHad_[idx]->Fill(edepHad);
443  etot[idx] += edep;
444  if (time < 100)
445  etotG[idx] += edep;
446  } else {
447 #ifdef EDM_ML_DEBUG
448  nBad++;
449 #endif
450  }
451  }
452  }
453  if (indx < 3) {
454  etot_[indx + 2]->Fill(etot[indx + 2]);
455  etotg_[indx + 2]->Fill(etotG[indx + 2]);
456  if (indx == 0) {
457  etot_[indx]->Fill(etot[indx]);
458  etotg_[indx]->Fill(etotG[indx]);
459  etot_[indx + 1]->Fill(etot[indx + 1]);
460  etotg_[indx + 1]->Fill(etotG[indx + 1]);
461  hit_[indx]->Fill(double(nEB));
462  hit_[indx + 1]->Fill(double(nEBAPD));
463  hit_[indx + 2]->Fill(double(nEBATJ));
464  } else {
465  hit_[indx + 2]->Fill(double(nHit));
466  }
467  } else if (indx == 3) {
468  hit_[5]->Fill(double(nHB));
469  hit_[6]->Fill(double(nHE));
470  hit_[7]->Fill(double(nHO));
471  hit_[8]->Fill(double(nHF));
472  for (int idx = 5; idx < 9; idx++) {
473  etot_[idx]->Fill(etot[idx]);
474  etotg_[idx]->Fill(etotG[idx]);
475  }
476  }
477 
478 #ifdef EDM_ML_DEBUG
479  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy::analyzeHits: EB " << nEB << ", " << nEBAPD << ", " << nEBATJ
480  << " EE " << nEE << " ES " << nES << " HB " << nHB << " HE " << nHE << " HO " << nHO
481  << " HF " << nHF << " Bad " << nBad << " All " << nHit << " Reduced " << hitMap.size();
482 #endif
483  std::map<unsigned int, double>::const_iterator it = hitMap.begin();
484  for (; it != hitMap.end(); it++) {
485  double time = it->second;
486  unsigned int id_ = (it->first);
487  int idx = -1;
488  if (indx < 3) {
489  if (indx == 0) {
490  if ((id_ & 0x20000) != 0)
491  idx = indx + 1;
492  else if ((id_ & 0x40000) != 0)
493  idx = indx + 1;
494  else
495  idx = indx;
496  } else {
497  idx = indx + 2;
498  }
499  if (idx >= 0 && idx < 5)
500  timeAll_[idx]->Fill(time);
501  } else if (indx == 3) {
502  int idx(-1), subdet(0);
503  if (testNumber_) {
504  int ieta(0), phi(0), z(0), lay(0), depth(0);
505  HcalTestNumbering::unpackHcalIndex(id_, subdet, z, depth, ieta, phi, lay);
506  } else {
507  HcalDetId id = HcalDetId(id_);
508  subdet = id.subdet();
509  }
510  if (subdet == static_cast<int>(HcalBarrel)) {
511  idx = indx + 2;
512  } else if (subdet == static_cast<int>(HcalEndcap)) {
513  idx = indx + 3;
514  } else if (subdet == static_cast<int>(HcalOuter)) {
515  idx = indx + 4;
516  } else if (subdet == static_cast<int>(HcalForward)) {
517  idx = indx + 5;
518  }
519  if (idx > 0) {
520  timeAll_[idx]->Fill(time);
521  }
522  }
523  }
524 }
525 
527  int nHit = 0;
528  edm::PSimHitContainer::const_iterator ihit;
529  std::string label(" ");
530  if (indx >= 0 && indx < 6)
531  label = tkHighLab_[indx];
532  else if (indx >= 6 && indx < 12)
533  label = tkLowLab_[indx - 6];
534  else if (indx >= 12 && indx < 16)
535  label = muonLab_[indx - 12];
536  for (ihit = hits->begin(); ihit != hits->end(); ihit++) {
537  edepTk_[indx]->Fill(ihit->energyLoss());
538  tofTk_[indx]->Fill(ihit->timeOfFlight());
539  nHit++;
540  }
541  hitTk_[indx]->Fill(float(nHit));
542 #ifdef EDM_ML_DEBUG
543  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy::analyzeHits: for " << label << " Index " << indx << " # of Hits "
544  << nHit;
545 #endif
546 }
547 
548 void CaloSimHitStudy::analyzeHits(std::vector<PCaloHit>& ebHits,
549  std::vector<PCaloHit>& eeHits,
550  std::vector<PCaloHit>& hcHits) {
551  double edepEB = 0, edepEBT = 0;
552  for (unsigned int i = 0; i < ebHits.size(); i++) {
553  double edep = ebHits[i].energy();
554  double time = ebHits[i].time();
555  if (((ebHits[i].depth()) & PCaloHit::kEcalDepthIdMask) == 0) {
556  edepEB += edep;
557  if (time < tmax_)
558  edepEBT += edep;
559  }
560  }
561  double edepEE = 0, edepEET = 0;
562  for (unsigned int i = 0; i < eeHits.size(); i++) {
563  double edep = eeHits[i].energy();
564  double time = eeHits[i].time();
565  edepEE += edep;
566  if (time < tmax_)
567  edepEET += edep;
568  }
569  double edepH = 0, edepHT = 0, edepHO = 0, edepHOT = 0;
570  for (unsigned int i = 0; i < hcHits.size(); i++) {
571  double edep = hcHits[i].energy();
572  double time = hcHits[i].time();
573  int subdet(0);
574  if (testNumber_) {
575  int ieta(0), phi(0), z(0), lay(0), depth(0);
576  HcalTestNumbering::unpackHcalIndex(hcHits[i].id(), subdet, z, depth, ieta, phi, lay);
577  } else {
578  HcalDetId id = HcalDetId(hcHits[i].id());
579  subdet = id.subdet();
580  }
581  if (subdet == static_cast<int>(HcalBarrel) || subdet == static_cast<int>(HcalEndcap)) {
582  edepH += edep;
583  if (time < tmax_)
584  edepHT += edep;
585  } else if (subdet == static_cast<int>(HcalOuter)) {
586  edepHO += edep;
587  if (time < tmax_)
588  edepHOT += edep;
589  }
590  }
591  double edepE = edepEB + edepEE;
592  double edepET = edepEBT + edepEET;
593  double edepHC = edepH + edepHO;
594  double edepHCT = edepHT + edepHOT;
595 #ifdef EDM_ML_DEBUG
596  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy::energy in EB " << edepEB << " (" << edepEBT << ") from "
597  << ebHits.size() << " hits; "
598  << " energy in EE " << edepEE << " (" << edepEET << ") from " << eeHits.size()
599  << " hits; energy in HC " << edepH << ", " << edepHO << " (" << edepHT << ", " << edepHOT
600  << ") from " << hcHits.size() << " hits";
601 #endif
602  edepC_[6]->Fill(edepE);
603  edepT_[6]->Fill(edepET);
604  edepC_[7]->Fill(edepH);
605  edepT_[7]->Fill(edepHT);
606  edepC_[8]->Fill(edepHC);
607  edepT_[8]->Fill(edepHCT);
608  if (edepE < eMIP_) {
609  edepC_[0]->Fill(edepE);
610  edepC_[1]->Fill(edepH);
611  edepC_[2]->Fill(edepHC);
612  } else {
613  edepC_[3]->Fill(edepE);
614  edepC_[4]->Fill(edepH);
615  edepC_[5]->Fill(edepHC);
616  }
617  if (edepET < eMIP_) {
618  edepT_[0]->Fill(edepET);
619  edepT_[1]->Fill(edepHT);
620  edepT_[2]->Fill(edepHCT);
621  } else {
622  edepT_[3]->Fill(edepET);
623  edepT_[4]->Fill(edepHT);
624  edepT_[5]->Fill(edepHCT);
625  }
626 }
627 
628 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkLow_
const std::vector< std::string > tkLowLab_
void analyzeHits(std::vector< PCaloHit > &, int)
edm::EDGetTokenT< edm::HepMCProduct > tok_evt_
T getUntrackedParameter(std::string const &, T const &) const
void beginRun(edm::Run const &, edm::EventSetup const &) override
char const * label
const double eMIP_
const std::vector< std::string > muonLab_
const std::string g4Label_
Definition: tfile.py:1
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
CaloSimHitStudy(const edm::ParameterSet &ps)
const double maxEnergy_
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
void beginJob() override
const std::vector< std::string > tkHighLab_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const bool testNumber_
std::vector< edm::EDGetTokenT< edm::PCaloHitContainer > > toks_calo_
bool isValid() const
Definition: HandleBase.h:70
~CaloSimHitStudy() override
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkHigh_
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_track_
const bool storeRL_
const double tmax_
void analyze(edm::Event const &, edm::EventSetup const &) override
const std::vector< std::string > hitLab_
Definition: Run.h:45
TH1F * edepTk_[16]
static const int kEcalDepthIdMask
Definition: PCaloHit.h:60