CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HOSimHitStudy.cc
Go to the documentation of this file.
3 
7 
12 
15 
21 
24 
25 #include <CLHEP/Units/GlobalPhysicalConstants.h>
26 #include <CLHEP/Units/GlobalSystemOfUnits.h>
27 
28 #include <TH1F.h>
29 #include <TProfile.h>
30 #include <TProfile2D.h>
31 
32 #include <fstream>
33 #include <iostream>
34 #include <iomanip>
35 #include <memory>
36 #include <map>
37 #include <string>
38 #include <vector>
39 
40 class HOSimHitStudy : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
41 public:
43  ~HOSimHitStudy() override {}
44  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
45 
46 protected:
47  void beginJob() override;
48  void beginRun(edm::Run const &, edm::EventSetup const &) override {}
49  void endJob() override {}
50  void endRun(edm::Run const &, edm::EventSetup const &) override {}
51  void analyze(const edm::Event &e, const edm::EventSetup &c) override;
52 
53  void analyzeHits();
54 
55 private:
59  std::vector<PCaloHit> ecalHits, hcalHits;
61  bool scheme_, print_;
62  double tcut_;
63  TH1F *hit_[3], *time_[3], *edepTW_[3], *edepTWT_[3];
64  TH1F *edep_[3], *hitTow_[3], *eneInc_, *etaInc_, *phiInc_;
65  TH1F *edepT_[3], *eEB_, *eEBHB_, *eEBHBHO_, *eEBHBHOT_;
66  TH1F *edepZon_[3], *edepZonT_[3], *eEBT_, *eEBHBT_;
67  TH1F *eHOE17_[15], *eHOE18_[15], *eHOE_[15];
68  TH1F *eHOE17T_[15], *eHOE18T_[15], *eHOET_[15];
69  TH1F *eHOEta17_[15], *eHOEta18_[15], *eHOEta_[15];
70  TH1F *eHOEta17T_[15], *eHOEta18T_[15], *eHOEtaT_[15];
71  TH1F *nHOE1_[15], *nHOE1T_[15], *nHOEta1_[15], *nHOEta1T_[15];
72  TProfile *eHO1_, *eHO1T_, *eHO17_, *eHO17T_, *eHO18_, *eHO18T_;
73  TProfile *nHO1_, *nHO1T_, *nHOE2_[15], *nHOE2T_[15];
74  TProfile *nHOEta2_[15], *nHOEta2T_[15];
75  TProfile2D *eHO2_, *eHO2T_, *nHO2_, *nHO2T_;
76  double eInc, etaInc, phiInc;
77 };
78 
80  usesResource(TFileService::kSharedResource);
81 
82  tok_evt_ =
83  consumes<edm::HepMCProduct>(edm::InputTag(ps.getUntrackedParameter<std::string>("SourceLabel", "VtxSmeared")));
84  g4Label = ps.getUntrackedParameter<std::string>("ModuleLabel", "g4SimHits");
85  hitLab[0] = ps.getUntrackedParameter<std::string>("EBCollection", "EcalHitsEB");
86  hitLab[1] = ps.getUntrackedParameter<std::string>("HCCollection", "HcalHits");
87 
88  for (unsigned i = 0; i != 2; i++)
89  toks_calo_[i] = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label, hitLab[i]));
90 
91  maxEnergy = ps.getUntrackedParameter<double>("MaxEnergy", 200.0);
92  scaleEB = ps.getUntrackedParameter<double>("ScaleEB", 1.0);
93  scaleHB = ps.getUntrackedParameter<double>("ScaleHB", 100.0);
94  scaleHO = ps.getUntrackedParameter<double>("ScaleHO", 2.0);
95  tcut_ = ps.getUntrackedParameter<double>("TimeCut", 100.0);
96  scheme_ = ps.getUntrackedParameter<bool>("TestNumbering", false);
97  print_ = ps.getUntrackedParameter<bool>("PrintExcessEnergy", true);
98  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Module Label: " << g4Label << " Hits: " << hitLab[0] << ", "
99  << hitLab[1] << " MaxEnergy: " << maxEnergy << " Scale factor for EB " << scaleEB
100  << ", for HB " << scaleHB << " and for HO " << scaleHO << " time Cut " << tcut_;
101 }
102 
105  desc.addUntracked<std::string>("SourceLabel", "generatorSmeared");
106  desc.addUntracked<std::string>("ModuleLabel", "g4SimHits");
107  desc.addUntracked<std::string>("EBCollection", "EcalHitsEB");
108  desc.addUntracked<std::string>("HCCollection", "HcalHits");
109  desc.addUntracked<double>("MaxEnergy", 50.0);
110  desc.addUntracked<double>("ScaleEB", 1.02);
111  desc.addUntracked<double>("ScaleHB", 104.4);
112  desc.addUntracked<double>("ScaleHO", 2.33);
113  desc.addUntracked<double>("TimeCut", 100.0);
114  desc.addUntracked<bool>("PrintExcessEnergy", true);
115  desc.addUntracked<bool>("TestNumbering", false);
116  descriptions.add("HOSimHitStudy", desc);
117 }
118 
121 
122  if (!tfile.isAvailable())
123  throw cms::Exception("BadConfig") << "TFileService unavailable: "
124  << "please add it to config file";
125  std::string dets[3] = {"EB", "HB", "HO"};
126  char name[60], title[100];
127  double ymax = maxEnergy;
128  sprintf(title, "Incident Energy (GeV)");
129  eneInc_ = tfile->make<TH1F>("EneInc", title, 1000, 0., ymax);
130  eneInc_->GetXaxis()->SetTitle(title);
131  eneInc_->GetYaxis()->SetTitle("Events");
132  sprintf(title, "Incident #eta");
133  etaInc_ = tfile->make<TH1F>("EtaInc", title, 200, -5., 5.);
134  etaInc_->GetXaxis()->SetTitle(title);
135  etaInc_->GetYaxis()->SetTitle("Events");
136  sprintf(title, "Incident #phi");
137  phiInc_ = tfile->make<TH1F>("PhiInc", title, 200, -3.1415926, 3.1415926);
138  phiInc_->GetXaxis()->SetTitle(title);
139  phiInc_->GetYaxis()->SetTitle("Events");
140  int itcut = (int)(tcut_);
141  for (int i = 0; i < 3; i++) {
142  sprintf(name, "Hit%d", i);
143  sprintf(title, "Number of hits in %s", dets[i].c_str());
144  hit_[i] = tfile->make<TH1F>(name, title, 1000, 0., 20000.);
145  hit_[i]->GetXaxis()->SetTitle(title);
146  hit_[i]->GetYaxis()->SetTitle("Events");
147  sprintf(name, "Time%d", i);
148  sprintf(title, "Time of the hit (ns) in %s", dets[i].c_str());
149  time_[i] = tfile->make<TH1F>(name, title, 1200, 0., 1200.);
150  time_[i]->GetXaxis()->SetTitle(title);
151  time_[i]->GetYaxis()->SetTitle("Hits");
152  if (i > 0)
153  ymax = 1.0;
154  else
155  ymax = 50.0;
156  sprintf(name, "Edep%d", i);
157  sprintf(title, "Energy deposit (GeV) in %s", dets[i].c_str());
158  edep_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
159  edep_[i]->GetXaxis()->SetTitle(title);
160  edep_[i]->GetYaxis()->SetTitle("Hits");
161  sprintf(name, "EdepT%d", i);
162  sprintf(title, "Energy deposit (GeV) in %s for t < %d ns", dets[i].c_str(), itcut);
163  edepT_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
164  edepT_[i]->GetXaxis()->SetTitle(title);
165  edepT_[i]->GetYaxis()->SetTitle("Hits");
166  sprintf(name, "HitTow%d", i);
167  sprintf(title, "Number of towers with hits in %s", dets[i].c_str());
168  hitTow_[i] = tfile->make<TH1F>(name, title, 1000, 0., 20000.);
169  hitTow_[i]->GetXaxis()->SetTitle(title);
170  hitTow_[i]->GetYaxis()->SetTitle("Events");
171  if (i > 0)
172  ymax = 0.05 * maxEnergy;
173  else
174  ymax = maxEnergy;
175  sprintf(name, "EdepTW%d", i);
176  sprintf(title, "Energy deposit (GeV) in %s Tower", dets[i].c_str());
177  edepTW_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
178  edepTW_[i]->GetXaxis()->SetTitle(title);
179  edepTW_[i]->GetYaxis()->SetTitle("Towers");
180  sprintf(name, "EdepTWT%d", i);
181  sprintf(title, "Energy deposit (GeV) in %s Tower for t < %d ns", dets[i].c_str(), itcut);
182  edepTWT_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
183  edepTWT_[i]->GetXaxis()->SetTitle(title);
184  edepTWT_[i]->GetYaxis()->SetTitle("Towers");
185  sprintf(name, "EdepZone%d", i);
186  sprintf(title, "Energy deposit (GeV) in %s", dets[i].c_str());
187  edepZon_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
188  edepZon_[i]->GetXaxis()->SetTitle(title);
189  edepZon_[i]->GetYaxis()->SetTitle("Events");
190  sprintf(name, "EdepZoneT%d", i);
191  sprintf(title, "Energy deposit (GeV) in %s for t < %d ns", dets[i].c_str(), itcut);
192  edepZonT_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
193  edepZonT_[i]->GetXaxis()->SetTitle(title);
194  edepZonT_[i]->GetYaxis()->SetTitle("Events");
195  }
196  sprintf(title, "Energy Measured in EB (GeV)");
197  eEB_ = tfile->make<TH1F>("EEB", title, 5000, 0., maxEnergy);
198  eEB_->GetXaxis()->SetTitle(title);
199  eEB_->GetYaxis()->SetTitle("Events");
200  sprintf(title, "Energy Measured in EB+HB (GeV)");
201  eEBHB_ = tfile->make<TH1F>("EEBHB", title, 5000, 0., maxEnergy);
202  eEBHB_->GetXaxis()->SetTitle(title);
203  eEBHB_->GetYaxis()->SetTitle("Events");
204  sprintf(title, "Energy Measured in EB+HB+HO (GeV)");
205  eEBHBHO_ = tfile->make<TH1F>("EEBHBHO", title, 5000, 0., maxEnergy);
206  eEBHBHO_->GetXaxis()->SetTitle(title);
207  eEBHBHO_->GetYaxis()->SetTitle("Events");
208  sprintf(title, "Energy Measured in EB (GeV) for t < %d ns", itcut);
209  eEBT_ = tfile->make<TH1F>("EEBT", title, 5000, 0., maxEnergy);
210  eEBT_->GetXaxis()->SetTitle(title);
211  eEBT_->GetYaxis()->SetTitle("Events");
212  sprintf(title, "Energy Measured in EB+HB (GeV) for t < %d ns", itcut);
213  eEBHBT_ = tfile->make<TH1F>("EEBHBT", title, 5000, 0., maxEnergy);
214  eEBHBT_->GetXaxis()->SetTitle(title);
215  eEBHBT_->GetYaxis()->SetTitle("Events");
216  sprintf(title, "Energy Measured in EB+HB+HO (GeV) for t < %d ns", itcut);
217  eEBHBHOT_ = tfile->make<TH1F>("EEBHBHOT", title, 5000, 0., maxEnergy);
218  eEBHBHOT_->GetXaxis()->SetTitle(title);
219  eEBHBHOT_->GetYaxis()->SetTitle("Events");
220  sprintf(title, "SimHit energy in HO");
221  eHO1_ = tfile->make<TProfile>("EHO1", title, 30, -1.305, 1.305);
222  eHO1_->GetXaxis()->SetTitle(title);
223  eHO1_->GetYaxis()->SetTitle("Events");
224  eHO2_ = tfile->make<TProfile2D>("EHO2", title, 30, -1.305, 1.305, 72, -3.1415926, 3.1415926);
225  eHO2_->GetXaxis()->SetTitle(title);
226  eHO2_->GetYaxis()->SetTitle("Events");
227  sprintf(title, "SimHit energy in HO Layer 17");
228  eHO17_ = tfile->make<TProfile>("EHO17", title, 30, -1.305, 1.305);
229  eHO17_->GetXaxis()->SetTitle(title);
230  eHO17_->GetYaxis()->SetTitle("Events");
231  sprintf(title, "SimHit energy in HO Layer 18");
232  eHO18_ = tfile->make<TProfile>("EHO18", title, 30, -1.305, 1.305);
233  eHO18_->GetXaxis()->SetTitle(title);
234  eHO18_->GetYaxis()->SetTitle("Events");
235  sprintf(title, "SimHit energy in HO for t < %d ns", itcut);
236  eHO1T_ = tfile->make<TProfile>("EHO1T", title, 30, -1.305, 1.305);
237  eHO1T_->GetXaxis()->SetTitle(title);
238  eHO1T_->GetYaxis()->SetTitle("Events");
239  eHO2T_ = tfile->make<TProfile2D>("EHO2T", title, 30, -1.305, 1.305, 72, -3.1415926, 3.1415926);
240  eHO2T_->GetXaxis()->SetTitle(title);
241  eHO2T_->GetYaxis()->SetTitle("Events");
242  sprintf(title, "SimHit energy in HO Layer 17 for t < %d ns", itcut);
243  eHO17T_ = tfile->make<TProfile>("EHO17T", title, 30, -1.305, 1.305);
244  eHO17T_->GetXaxis()->SetTitle(title);
245  eHO17T_->GetYaxis()->SetTitle("Events");
246  sprintf(title, "SimHit energy in HO Layer 18 for t < %d ns", itcut);
247  eHO18T_ = tfile->make<TProfile>("EHO18T", title, 30, -1.305, 1.305);
248  eHO18T_->GetXaxis()->SetTitle(title);
249  eHO18T_->GetYaxis()->SetTitle("Events");
250  sprintf(title, "Number of layers hit in HO");
251  nHO1_ = tfile->make<TProfile>("NHO1", title, 30, -1.305, 1.305);
252  nHO1_->GetXaxis()->SetTitle(title);
253  nHO1_->GetYaxis()->SetTitle("Events");
254  nHO2_ = tfile->make<TProfile2D>("NHO2", title, 30, -1.305, 1.305, 72, -3.1415926, 3.1415926);
255  nHO2_->GetXaxis()->SetTitle(title);
256  nHO2_->GetYaxis()->SetTitle("Events");
257  sprintf(title, "Number of layers hit in HO for t < %d ns", itcut);
258  nHO1T_ = tfile->make<TProfile>("NHO1T", title, 30, -1.305, 1.305);
259  nHO1T_->GetXaxis()->SetTitle(title);
260  nHO1T_->GetYaxis()->SetTitle("Events");
261  nHO2T_ = tfile->make<TProfile2D>("NHO2T", title, 30, -1.305, 1.305, 72, -3.1415926, 3.1415926);
262  nHO2T_->GetXaxis()->SetTitle(title);
263  nHO2T_->GetYaxis()->SetTitle("Events");
264  for (int i = 0; i < 15; i++) {
265  sprintf(name, "EHOE%d", i + 1);
266  sprintf(title, "SimHit energy in HO (Beam in #eta=%d bin)", i + 1);
267  eHOE_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
268  eHOE_[i]->GetXaxis()->SetTitle(title);
269  eHOE_[i]->GetYaxis()->SetTitle("Events");
270  sprintf(name, "EHOE17%d", i + 1);
271  sprintf(title, "SimHit energy in Layer 17 (Beam in #eta=%d bin)", i + 1);
272  eHOE17_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
273  eHOE17_[i]->GetXaxis()->SetTitle(title);
274  eHOE17_[i]->GetYaxis()->SetTitle("Events");
275  sprintf(name, "EHOE18%d", i + 1);
276  sprintf(title, "SimHit energy in Layer 18 (Beam in #eta=%d bin)", i + 1);
277  eHOE18_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
278  eHOE18_[i]->GetXaxis()->SetTitle(title);
279  eHOE18_[i]->GetYaxis()->SetTitle("Events");
280  sprintf(name, "EHOE%dT", i + 1);
281  sprintf(title, "SimHit energy in HO (Beam in #eta=%d bin, t < %d ns)", i + 1, itcut);
282  eHOET_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
283  eHOET_[i]->GetXaxis()->SetTitle(title);
284  eHOET_[i]->GetYaxis()->SetTitle("Events");
285  sprintf(name, "EHOE17%dT", i + 1);
286  sprintf(title, "SimHit energy in Layer 17 (Beam in #eta=%d bin, t < %d ns)", i + 1, itcut);
287  eHOE17T_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
288  eHOE17T_[i]->GetXaxis()->SetTitle(title);
289  eHOE17T_[i]->GetYaxis()->SetTitle("Events");
290  sprintf(name, "EHOE18%dT", i + 1);
291  sprintf(title, "SimHit energy in Layer 18 (Beam in #eta=%d bin, t < %d ns)", i + 1, itcut);
292  eHOE18T_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
293  eHOE18T_[i]->GetXaxis()->SetTitle(title);
294  eHOE18T_[i]->GetYaxis()->SetTitle("Events");
295  sprintf(name, "EHOEta%d", i + 1);
296  sprintf(title, "SimHit energy in HO #eta bin %d (Beam in #eta=%d bin)", i + 1, i + 1);
297  eHOEta_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
298  eHOEta_[i]->GetXaxis()->SetTitle(title);
299  eHOEta_[i]->GetYaxis()->SetTitle("Events");
300  sprintf(name, "EHOEta17%d", i + 1);
301  sprintf(title, "SimHit energy in Layer 17 #eta bin %d (Beam in #eta=%d bin)", i + 1, i + 1);
302  eHOEta17_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
303  eHOEta17_[i]->GetXaxis()->SetTitle(title);
304  eHOEta17_[i]->GetYaxis()->SetTitle("Events");
305  sprintf(name, "EHOEta18%d", i + 1);
306  sprintf(title, "SimHit energy in Layer 18 #eta bin %d (Beam in #eta=%d bin)", i + 1, i + 1);
307  eHOEta18_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
308  eHOEta18_[i]->GetXaxis()->SetTitle(title);
309  eHOEta18_[i]->GetYaxis()->SetTitle("Events");
310  sprintf(name, "EHOEta%dT", i + 1);
311  sprintf(title, "SimHit energy in HO #eta bin %d (Beam in #eta=%d bin, t < %d ns)", i + 1, i + 1, itcut);
312  eHOEtaT_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
313  eHOEtaT_[i]->GetXaxis()->SetTitle(title);
314  eHOEtaT_[i]->GetYaxis()->SetTitle("Events");
315  sprintf(name, "EHOEta17%dT", i + 1);
316  sprintf(title, "SimHit energy in Layer 17 #eta bin %d (Beam in #eta=%d bin, t < %d ns)", i + 1, i + 1, itcut);
317  eHOEta17T_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
318  eHOEta17T_[i]->GetXaxis()->SetTitle(title);
319  eHOEta17T_[i]->GetYaxis()->SetTitle("Events");
320  sprintf(name, "EHOEta18%dT", i + 1);
321  sprintf(title, "SimHit energy in Layer 18 #eta bin %d (Beam in #eta=%d bin, t < %d ns)", i + 1, i + 1, itcut);
322  eHOEta18T_[i] = tfile->make<TH1F>(name, title, 1000, 0., 0.25);
323  eHOEta18T_[i]->GetXaxis()->SetTitle(title);
324  eHOEta18T_[i]->GetYaxis()->SetTitle("Events");
325  sprintf(name, "NHOE1%d", i + 1);
326  sprintf(title, "Number of layers hit in HO (Beam in #eta=%d bin)", i + 1);
327  nHOE1_[i] = tfile->make<TH1F>(name, title, 20, 0, 20.);
328  nHOE1_[i]->GetXaxis()->SetTitle(title);
329  nHOE1_[i]->GetYaxis()->SetTitle("Events");
330  sprintf(name, "NHOE2%d", i + 1);
331  nHOE2_[i] = tfile->make<TProfile>(name, title, 72, -3.1415926, 3.1415926);
332  nHOE2_[i]->GetXaxis()->SetTitle(title);
333  nHOE2_[i]->GetYaxis()->SetTitle("Events");
334  sprintf(name, "NHOE1%dT", i + 1);
335  sprintf(title, "Number of layers hit in HO (Beam in #eta=%d bin, t < %d ns)", i + 1, itcut);
336  nHOE1T_[i] = tfile->make<TH1F>(name, title, 20, 0, 20.);
337  nHOE1T_[i]->GetXaxis()->SetTitle(title);
338  nHOE1T_[i]->GetYaxis()->SetTitle("Events");
339  sprintf(name, "NHOE2%dT", i + 1);
340  nHOE2T_[i] = tfile->make<TProfile>(name, title, 72, -3.1415926, 3.1415926);
341  nHOE2T_[i]->GetXaxis()->SetTitle(title);
342  nHOE2T_[i]->GetYaxis()->SetTitle("Events");
343  sprintf(name, "NHOEta1%d", i + 1);
344  sprintf(title, "Number of layers hit in HO #eta bin %d (Beam in #eta=%d bin)", i + 1, i + 1);
345  nHOEta1_[i] = tfile->make<TH1F>(name, title, 20, 0, 20.);
346  nHOEta1_[i]->GetXaxis()->SetTitle(title);
347  nHOEta1_[i]->GetYaxis()->SetTitle("Events");
348  sprintf(name, "NHOEta2%d", i + 1);
349  nHOEta2_[i] = tfile->make<TProfile>(name, title, 72, -3.1415926, 3.1415926);
350  nHOEta2_[i]->GetXaxis()->SetTitle(title);
351  nHOEta2_[i]->GetYaxis()->SetTitle("Events");
352  sprintf(name, "NHOEta1%dT", i + 1);
353  sprintf(title, "Number of layers hit in HO #eta bin %d (Beam in #eta=%d bin, t < %d ns)", i + 1, i + 1, itcut);
354  nHOEta1T_[i] = tfile->make<TH1F>(name, title, 20, 0, 20.);
355  nHOEta1T_[i]->GetXaxis()->SetTitle(title);
356  nHOEta1T_[i]->GetYaxis()->SetTitle("Events");
357  sprintf(name, "NHOEta2%dT", i + 1);
358  nHOEta2T_[i] = tfile->make<TProfile>(name, title, 72, -3.1415926, 3.1415926);
359  nHOEta2T_[i]->GetXaxis()->SetTitle(title);
360  nHOEta2T_[i]->GetYaxis()->SetTitle("Events");
361  }
362 }
363 
365  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Run = " << e.id().run() << " Event = " << e.id().event();
366 
368  e.getByToken(tok_evt_, EvtHandle);
369  const HepMC::GenEvent *myGenEvent = EvtHandle->GetEvent();
370 
371  eInc = etaInc = phiInc = 0;
372  HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
373  if (p != myGenEvent->particles_end()) {
374  eInc = (*p)->momentum().e();
375  etaInc = (*p)->momentum().eta();
376  phiInc = (*p)->momentum().phi();
377  }
378 
379  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Energy = " << eInc << " Eta = " << etaInc
380  << " Phi = " << phiInc / CLHEP::deg;
381 
382  for (int i = 0; i < 2; i++) {
383  bool getHits = false;
384  if (i == 0)
385  ecalHits.clear();
386  else
387  hcalHits.clear();
389  e.getByToken(toks_calo_[i], hitsCalo);
390  if (hitsCalo.isValid())
391  getHits = true;
392  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Input flag " << hitLab[i] << " getHits flag " << getHits;
393 
394  if (getHits) {
395  unsigned int isiz;
396  if (i == 0) {
397  ecalHits.insert(ecalHits.end(), hitsCalo->begin(), hitsCalo->end());
398  isiz = ecalHits.size();
399  } else {
400  hcalHits.insert(hcalHits.end(), hitsCalo->begin(), hitsCalo->end());
401  isiz = hcalHits.size();
402  }
403  edm::LogVerbatim("HitStudy") << "HOSimHitStudy:: Hit buffer for " << hitLab[i] << " has " << isiz << " hits";
404  }
405  }
406  analyzeHits();
407 }
408 
410  //initialize
411  int nhit[3];
412  double etot[3], etotT[3];
413  std::vector<unsigned int> ebID, hbID, hoID;
414  std::vector<double> ebEtow, hbEtow, hoEtow;
415  std::vector<double> ebEtowT, hbEtowT, hoEtowT;
416  for (int k = 0; k < 3; k++) {
417  nhit[k] = 0;
418  etot[k] = 0;
419  etotT[k] = 0;
420  }
421  eneInc_->Fill(eInc);
422  etaInc_->Fill(etaInc);
423  phiInc_->Fill(phiInc);
424 
425  double eHO17 = 0, eHO18 = 0, eHO17T = 0, eHO18T = 0;
426  double eHOE17[15], eHOE18[15], eHOE17T[15], eHOE18T[15];
427  for (int k = 0; k < 15; k++) {
428  eHOE17[k] = eHOE18[k] = eHOE17T[k] = eHOE18T[k] = 0;
429  }
430  // Loop over containers
431  for (int k = 0; k < 2; k++) {
432  int nHit;
433  if (k == 0) {
434  nHit = ecalHits.size();
435  } else {
436  nHit = hcalHits.size();
437  }
438  for (int i = 0; i < nHit; i++) {
439  double edep, time;
440  int indx = -1;
441  unsigned int id_;
442  if (k == 0) {
443  indx = 0;
444  edep = ecalHits[i].energy();
445  time = ecalHits[i].time();
446  id_ = ecalHits[i].id();
447  } else {
448  edep = hcalHits[i].energy();
449  time = hcalHits[i].time();
450  id_ = hcalHits[i].id();
451  int subdet, zside, depth, eta, phi, lay;
452  if (scheme_) {
453  HcalTestNumberingScheme::unpackHcalIndex(id_, subdet, zside, depth, eta, phi, lay);
454  } else {
455  HcalDetId id = HcalDetId(id_);
456  subdet = id.subdet();
457  zside = id.zside();
458  depth = id.depth();
459  eta = id.ietaAbs();
460  phi = id.iphi();
461  lay = -1;
462  }
463  edm::LogVerbatim("HitStudy") << "HOSimHitStudy:: Hit " << k << " Subdet:" << subdet << " zside:" << zside
464  << " depth:" << depth << " layer:" << lay << " eta:" << eta << " phi:" << phi;
465  if (subdet == static_cast<int>(HcalBarrel))
466  indx = 1;
467  else if (subdet == static_cast<int>(HcalOuter)) {
468  indx = 2;
469  if (lay == 18) {
470  eHO17 += edep;
471  if (time < tcut_)
472  eHO17T += edep;
473  if (eta >= 0 && eta < 15) {
474  eHOE17[eta] += edep;
475  if (time < tcut_)
476  eHOE17T[eta] += edep;
477  }
478  } else {
479  eHO18 += edep;
480  if (time < tcut_)
481  eHO18T += edep;
482  if (eta >= 0 && eta < 15) {
483  eHOE18[eta] += edep;
484  if (time < tcut_)
485  eHOE18T[eta] += edep;
486  }
487  }
488  }
489  }
490  if (indx >= 0) {
491  double edepT = edep;
492  time_[indx]->Fill(time);
493  edep_[indx]->Fill(edep);
494  etot[indx] += edep;
495  if (time < tcut_) {
496  etotT[indx] += edep;
497  edepT_[indx]->Fill(edep);
498  edepT = 0;
499  }
500  nhit[indx]++;
501  if (indx == 0) {
502  bool ok = false;
503  for (unsigned int j = 0; j < ebID.size(); j++) {
504  if (id_ == ebID[j]) {
505  ebEtow[j] += edep;
506  ebEtowT[j] += edepT;
507  ok = true;
508  break;
509  }
510  }
511  if (!ok) {
512  ebID.push_back(id_);
513  ebEtow.push_back(edep);
514  ebEtowT.push_back(edepT);
515  }
516  } else if (indx == 1) {
517  bool ok = false;
518  for (unsigned int j = 0; j < hbID.size(); j++) {
519  if (id_ == hbID[j]) {
520  hbEtow[j] += edep;
521  hbEtowT[j] += edepT;
522  ok = true;
523  break;
524  }
525  }
526  if (!ok) {
527  hbID.push_back(id_);
528  hbEtow.push_back(edep);
529  hbEtowT.push_back(edepT);
530  }
531  } else {
532  bool ok = false;
533  for (unsigned int j = 0; j < hoID.size(); j++) {
534  if (id_ == hoID[j]) {
535  hoEtow[j] += edep;
536  hoEtowT[j] += edepT;
537  ok = true;
538  break;
539  }
540  }
541  if (!ok) {
542  hoID.push_back(id_);
543  hoEtow.push_back(edep);
544  hoEtowT.push_back(edepT);
545  }
546  }
547  }
548  }
549  }
550 
551  // Now for towers and total energy deposits
552  for (int k = 0; k < 3; k++) {
553  hit_[k]->Fill(double(nhit[k]));
554  edepZon_[k]->Fill(etot[k]);
555  edepZonT_[k]->Fill(etotT[k]);
556  }
557  hitTow_[0]->Fill(double(ebEtow.size()));
558  for (unsigned int i = 0; i < ebEtow.size(); i++) {
559  edepTW_[0]->Fill(ebEtow[i]);
560  edepTWT_[0]->Fill(ebEtowT[i]);
561  }
562  hitTow_[1]->Fill(double(hbEtow.size()));
563  for (unsigned int i = 0; i < hbEtow.size(); i++) {
564  edepTW_[1]->Fill(hbEtow[i]);
565  edepTWT_[1]->Fill(hbEtowT[i]);
566  }
567  hitTow_[2]->Fill(double(hoEtow.size()));
568  for (unsigned int i = 0; i < hoEtow.size(); i++) {
569  edepTW_[2]->Fill(hoEtow[i]);
570  edepTWT_[2]->Fill(hoEtowT[i]);
571  }
572  double eEB = scaleEB * etot[0];
573  double eEBHB = eEB + scaleHB * etot[1];
574  double eEBHBHO = eEBHB + scaleHB * scaleHO * etot[2];
575  eEB_->Fill(eEB);
576  eEBHB_->Fill(eEBHB);
577  eEBHBHO_->Fill(eEBHBHO);
578  double eEBT = scaleEB * etotT[0];
579  double eEBHBT = eEBT + scaleHB * etotT[1];
580  double eEBHBHOT = eEBHBT + scaleHB * scaleHO * etotT[2];
581  eEBT_->Fill(eEBT);
582  eEBHBT_->Fill(eEBHBT);
583  eEBHBHOT_->Fill(eEBHBHOT);
584  eHO1_->Fill(etaInc, eHO17 + eHO18);
585  eHO2_->Fill(etaInc, phiInc, eHO17 + eHO18);
586  eHO17_->Fill(etaInc, eHO17);
587  eHO18_->Fill(etaInc, eHO18);
588  eHO1T_->Fill(etaInc, eHO17T + eHO18T);
589  eHO2T_->Fill(etaInc, phiInc, eHO17T + eHO18T);
590  eHO17T_->Fill(etaInc, eHO17T);
591  eHO18T_->Fill(etaInc, eHO18T);
592  int nHO = 0, nHOT = 0;
593  if (eHO17 > 0)
594  nHO++;
595  if (eHO17T > 0)
596  nHOT++;
597  if (eHO18 > 0)
598  nHO++;
599  if (eHO18T > 0)
600  nHOT++;
601  nHO1_->Fill(etaInc, (double)(nHO));
602  nHO2_->Fill(etaInc, phiInc, (double)(nHO));
603  nHO1T_->Fill(etaInc, (double)(nHOT));
604  nHO2T_->Fill(etaInc, phiInc, (double)(nHOT));
605  int ieta = 15;
606  for (int k = 0; k < 15; ++k) {
607  if (std::abs(etaInc) < 0.087 * (k + 1)) {
608  ieta = k;
609  break;
610  }
611  }
612  if (ieta >= 0 && ieta < 15) {
613  eHOE_[ieta]->Fill(eHO17 + eHO18);
614  eHOE17_[ieta]->Fill(eHO17);
615  eHOE18_[ieta]->Fill(eHO18);
616  eHOET_[ieta]->Fill(eHO17T + eHO18T);
617  eHOE17T_[ieta]->Fill(eHO17T);
618  eHOE18T_[ieta]->Fill(eHO18T);
619  eHOEta_[ieta]->Fill(eHOE17[ieta] + eHOE18[ieta]);
620  eHOEta17_[ieta]->Fill(eHOE17[ieta]);
621  eHOEta18_[ieta]->Fill(eHOE18[ieta]);
622  nHOE1_[ieta]->Fill((double)(nHO));
623  nHOE2_[ieta]->Fill(phiInc, (double)(nHO));
624  nHOE1T_[ieta]->Fill((double)(nHOT));
625  nHOE2T_[ieta]->Fill(phiInc, (double)(nHOT));
626  int nHOE = 0, nHOET = 0;
627  if (eHOE17[ieta] > 0)
628  nHOE++;
629  if (eHOE17T[ieta] > 0)
630  nHOET++;
631  if (eHOE18[ieta] > 0)
632  nHOE++;
633  if (eHOE18T[ieta] > 0)
634  nHOET++;
635  nHOEta1_[ieta]->Fill((double)(nHOE));
636  nHOEta2_[ieta]->Fill(phiInc, (double)(nHOE));
637  nHOEta1T_[ieta]->Fill((double)(nHOET));
638  nHOEta2T_[ieta]->Fill(phiInc, (double)(nHOET));
639  }
640 
641  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::analyzeHits: Hits in EB " << nhit[0] << " in " << ebEtow.size()
642  << " towers with total E " << etot[0] << "|" << etotT[0]
643  << "\n Hits in HB " << nhit[1] << " in " << hbEtow.size()
644  << " towers with total E " << etot[1] << "|" << etotT[1]
645  << "\n Hits in HO " << nhit[2] << " in " << hoEtow.size()
646  << " towers with total E " << etot[2] << "|" << etotT[2]
647  << "\n Energy in EB " << eEB << "|" << eEBT << " with HB "
648  << eEBHB << "|" << eEBHBT << " and with HO " << eEBHBHO << "|" << eEBHBHOT
649  << "\n E in HO layers " << eHO17 << "|" << eHO17T << " "
650  << eHO18 << "|" << eHO18T << " number of HO hits " << nHO << "|" << nHOT;
651 
652  if (eEBHBHO > 0.75 * maxEnergy && print_) {
653  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Event with excessive energy: EB = " << eEB << " EB+HB = " << eEBHB
654  << " EB+HB+HO = " << eEBHBHO;
655  const std::string Dets[3] = {"EB", "HB", "HO"};
656  for (int k = 0; k < 2; k++) {
657  int nHit;
658  if (k == 0) {
659  nHit = ecalHits.size();
660  } else {
661  nHit = hcalHits.size();
662  }
663  for (int i = 0; i < nHit; i++) {
664  double edep, time;
665  int indx = -1;
666  unsigned int id_;
667  int ieta, iphi, depth = 0;
668  if (k == 0) {
669  indx = 0;
670  edep = ecalHits[i].energy();
671  time = ecalHits[i].time();
672  id_ = ecalHits[i].id();
673  EBDetId id = EBDetId(id_);
674  ieta = id.ieta();
675  iphi = id.iphi();
676  } else {
677  indx = -1;
678  edep = hcalHits[i].energy();
679  time = hcalHits[i].time();
680  id_ = hcalHits[i].id();
681  HcalDetId id = HcalDetId(id_);
682  int subdet = id.subdet();
683  if (subdet == static_cast<int>(HcalBarrel))
684  indx = 1;
685  else if (subdet == static_cast<int>(HcalOuter))
686  indx = 2;
687  ieta = id.ieta();
688  iphi = id.iphi();
689  depth = id.depth();
690  }
691  if (indx >= 0) {
692  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::" << Dets[indx] << " " << i << std::hex << id_ << std::dec
693  << " (" << ieta << "|" << iphi << "|" << depth << ") " << std::setw(8) << edep
694  << " " << std::setw(8) << time;
695  }
696  }
697  }
698  }
699 }
700 
701 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
const edm::EventSetup & c
void beginRun(edm::Run const &, edm::EventSetup const &) override
TProfile * nHOE2_[15]
TProfile * nHOE2T_[15]
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
TProfile * eHO1_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string g4Label
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TProfile * eHO18_
TProfile2D * eHO2_
TH1F * eHOE18_[15]
edm::EDGetTokenT< edm::HepMCProduct > tok_evt_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
TH1F * eHOE18T_[15]
TProfile2D * eHO2T_
int zside(DetId const &)
TH1F * eHOE17T_[15]
void endRun(edm::Run const &, edm::EventSetup const &) override
TH1F * time_[3]
TH1F * eHOEta18_[15]
TH1F * eHOEta17T_[15]
TH1F * edepZonT_[3]
TH1F * nHOE1T_[15]
TH1F * edepTWT_[3]
TH1F * eHOE17_[15]
TH1F * eHOEta18T_[15]
TH1F * edep_[3]
void endJob() override
TProfile * eHO17_
TH1F * nHOE1_[15]
bool isAvailable() const
Definition: Service.h:40
TH1F * edepTW_[3]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TProfile * nHOEta2_[15]
TProfile * eHO18T_
TProfile * eHO17T_
TProfile * nHO1T_
TProfile2D * nHO2_
bool isValid() const
Definition: HandleBase.h:70
TH1F * eHOE_[15]
~HOSimHitStudy() override
TH1F * eHOET_[15]
TH1F * nHOEta1T_[15]
TProfile * nHOEta2T_[15]
void beginJob() override
TH1F * hitTow_[3]
TProfile2D * nHO2T_
TH1F * edepZon_[3]
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TH1F * eHOEta_[15]
TProfile * nHO1_
edm::EDGetTokenT< edm::PCaloHitContainer > toks_calo_[2]
edm::EventID id() const
Definition: EventBase.h:59
std::vector< PCaloHit > hcalHits
std::vector< PCaloHit > ecalHits
TH1F * edepT_[3]
TProfile * eHO1T_
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
TH1F * hit_[3]
tuple tfile
Definition: compare.py:324
TH1F * eHOEta17_[15]
HOSimHitStudy(const edm::ParameterSet &ps)
std::string hitLab[2]
Definition: Run.h:45
TH1F * nHOEta1_[15]
TH1F * eHOEtaT_[15]