CMS 3D CMS Logo

HGCalTB23Analyzer.cc
Go to the documentation of this file.
1 // system include files
2 #include <cmath>
3 #include <fstream>
4 #include <iostream>
5 #include <map>
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
10 // user include files
13 
24 
37 
39 
40 // Root objects
41 #include "TH1.h"
42 #include "TH2.h"
43 #include "TProfile.h"
44 #include "TProfile2D.h"
45 #include "TROOT.h"
46 #include "TSystem.h"
47 #include "TTree.h"
48 
49 //#define EDM_ML_DEBUG
50 
51 class HGCalTB23Analyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
52 public:
53  explicit HGCalTB23Analyzer(edm::ParameterSet const&);
54  ~HGCalTB23Analyzer() override = default;
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58 private:
59  void beginJob() override;
60  void beginRun(edm::Run const&, edm::EventSetup const&) override;
61  void endRun(edm::Run const&, edm::EventSetup const&) override {}
62  void analyze(edm::Event const&, edm::EventSetup const&) override;
63  void analyzeSimHits(int type, std::vector<PCaloHit>& hits, double zFront);
66  void analyzePassiveHits(edm::Handle<edm::PassiveHitContainer> const& hgcPh, int subdet);
67  static bool sortTime(const std::pair<double, double>& i, const std::pair<double, double>& j);
68 
70  std::unique_ptr<AHCalGeometry> ahcalGeom_;
72  const bool ifEE_, ifFH_, ifBH_, ifBeam_;
77  const double zFrontEE_, zFrontFH_, zFrontBH_;
79  std::vector<int> idBeams_;
84 
94 
95  TTree* tree_;
96  TH1D *hSimHitE_[4], *hSimHitEn_[4], *hSimHitT_[4], *hBeam_;
97  TProfile *hSimHitLng_[3], *hSimHitLng1_[3];
98  TProfile* hSimHitLng2_[3];
99  TProfile2D* hSimHitLat_[3];
100  std::vector<TH1D*> hSimHitLayEn1EE_, hSimHitLayEn2EE_;
101  std::vector<TH1D*> hSimHitLayEn1FH_, hSimHitLayEn2FH_;
102  std::vector<TH1D*> hSimHitLayEn1BH_, hSimHitLayEn2BH_;
103  std::vector<TH1D*> hSimHitLayEnBeam_;
104  std::vector<float> simHitLayEn1EE_, simHitLayEn2EE_;
105  std::vector<float> simHitLayEn1FH_, simHitLayEn2FH_;
106  std::vector<float> simHitLayEn1BH_, simHitLayEn2BH_;
107  std::vector<float> simHitLayEnBeam_;
108  std::vector<uint32_t> simHitCellIdEE_, simHitCellIdFH_;
109  std::vector<uint32_t> simHitCellIdBH_, simHitCellIdBeam_;
110  std::vector<float> simHitCellEnEE_, simHitCellEnFH_;
111  std::vector<float> simHitCellEnBH_, simHitCellEnBeam_;
116 
118  std::vector<float> hgcPassiveBeamEnergy_;
120  std::vector<std::string> hgcPassiveBeamName_;
122 
125  int nBeamMC_;
126  std::vector<int> pdgIdBeamMC_;
127  std::vector<float> xBeamMC_, yBeamMC_, zBeamMC_;
128  std::vector<float> pxBeamMC_, pyBeamMC_, pzBeamMC_, pBeamMC_;
129 };
130 
132  : ifEE_(iConfig.getParameter<bool>("useEE")),
133  ifFH_(iConfig.getParameter<bool>("useFH")),
134  ifBH_(iConfig.getParameter<bool>("useBH")),
135  ifBeam_(iConfig.getParameter<bool>("useBeam")),
136  doSimHits_(iConfig.getParameter<bool>("doSimHits")),
137  doTree_(iConfig.getParameter<bool>("doTree")),
138  doTreeCell_(iConfig.getParameter<bool>("doTreeCell")),
139  doPassive_(iConfig.getParameter<bool>("doPassive")),
140  doPassiveEE_(iConfig.getParameter<bool>("doPassiveEE")),
141  doPassiveHE_(iConfig.getParameter<bool>("doPassiveHE")),
142  doPassiveBH_(iConfig.getParameter<bool>("doPassiveBH")),
143  addP_(iConfig.getParameter<bool>("addP")),
144  doBeam_(iConfig.getParameter<bool>("doBeam")),
145  detectorEE_(iConfig.getParameter<std::string>("detectorEE")),
146  detectorFH_(iConfig.getParameter<std::string>("detectorFH")),
147  detectorBH_(iConfig.getParameter<std::string>("detectorBH")),
148  detectorBeam_(iConfig.getParameter<std::string>("detectorBeam")),
149  zFrontEE_(iConfig.getParameter<double>("zFrontEE")),
150  zFrontFH_(iConfig.getParameter<double>("zFrontFH")),
151  zFrontBH_(iConfig.getParameter<double>("zFrontBH")),
152  gev2mip200_(iConfig.getUntrackedParameter<double>("gev2mip200", 57.0e-6)),
153  gev2mip300_(iConfig.getUntrackedParameter<double>("gev2mip300", 85.5e-6)),
154  stoc_smear_time_200_(iConfig.getUntrackedParameter<double>("stoc_smear_time_200", 10.24)),
155  stoc_smear_time_300_(iConfig.getUntrackedParameter<double>("stoc_smear_time_300", 15.5)),
156  labelGen_(iConfig.getParameter<edm::InputTag>("generatorSrc")),
157  labelHitEE_(iConfig.getParameter<std::string>("caloHitSrcEE")),
158  labelHitFH_(iConfig.getParameter<std::string>("caloHitSrcFH")),
159  labelHitBH_(iConfig.getParameter<std::string>("caloHitSrcBH")),
160  labelHitBeam_(iConfig.getParameter<std::string>("caloHitSrcBeam")),
161  labelPassiveEE_(iConfig.getParameter<edm::InputTag>("passiveEE")),
162  labelPassiveFH_(iConfig.getParameter<edm::InputTag>("passiveFH")),
163  labelPassiveBH_(iConfig.getParameter<edm::InputTag>("passiveBH")),
164  labelPassiveCMSE_(iConfig.getParameter<edm::InputTag>("passiveCMSE")),
165  labelPassiveBeam_(iConfig.getParameter<edm::InputTag>("passiveBeam")),
166  tok_hepMC_(consumes<edm::HepMCProduct>(labelGen_)),
167  tok_simTk_(consumes<edm::SimTrackContainer>(edm::InputTag("g4SimHits"))),
168  tok_simVtx_(consumes<edm::SimVertexContainer>(edm::InputTag("g4SimHits"))),
169  tok_hitsEE_(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", labelHitEE_))),
170  tok_hitsFH_(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", labelHitFH_))),
171  tok_hitsBH_(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", labelHitBH_))),
172  tok_hitsBeam_(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", labelHitBeam_))),
173  tok_hgcPHEE_(consumes<edm::PassiveHitContainer>(labelPassiveEE_)),
174  tok_hgcPHFH_(consumes<edm::PassiveHitContainer>(labelPassiveFH_)),
175  tok_hgcPHBH_(consumes<edm::PassiveHitContainer>(labelPassiveBH_)),
176  tok_hgcPHCMSE_(consumes<edm::PassiveHitContainer>(labelPassiveCMSE_)),
177  tok_hgcPHBeam_(consumes<edm::PassiveHitContainer>(labelPassiveBeam_)),
179  edm::ESInputTag("", detectorEE_))),
181  edm::ESInputTag("", detectorFH_))) {
182  usesResource("TFileService");
183  ahcalGeom_ = std::make_unique<AHCalGeometry>(iConfig);
184 
185  // now do whatever initialization is needed
191  idBeams_ = (iConfig.getParameter<std::vector<int>>("idBeams"));
192 #ifdef EDM_ML_DEBUG
193  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: SimHits = " << doSimHits_ << " useDets " << ifEE_ << ":" << ifFH_
194  << ":" << ifBH_ << ":" << ifBeam_ << " zFront " << zFrontEE_ << ":" << zFrontFH_ << ":"
195  << zFrontBH_ << " IdBeam " << idBeams_.size() << ":";
196  for (unsigned int k = 0; k < idBeams_.size(); ++k)
197  edm::LogVerbatim("HGCSim") << " [" << k << "] " << idBeams_[k];
198  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: DoPassive " << doPassive_ << ":" << doPassiveEE_ << ":"
199  << doPassiveHE_ << ":" << doPassiveBH_;
200  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: MIP conversion factors " << gev2mip200_ << ":" << gev2mip300_
201  << " Time smearing " << stoc_smear_time_200_ << ":" << stoc_smear_time_300_ << " AddP "
202  << addP_;
203 #endif
204  if (idBeams_.empty())
205  idBeams_.push_back(1001);
206 
207 #ifdef EDM_ML_DEBUG
208  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: GeneratorSource = " << labelGen_;
209  if (ifEE_)
210  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: Detector " << detectorEE_ << " with tags " << labelHitEE_;
211  if (ifFH_)
212  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: Detector " << detectorFH_ << " with tags " << labelHitFH_;
213  if (ifBH_)
214  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: Detector " << detectorBH_ << " with tags " << labelHitBH_;
215  if (ifBeam_)
216  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: Detector " << detectorBeam_ << " with tags " << labelHitBeam_;
217 #endif
218 }
219 
222  desc.add<std::string>("detectorEE", "HGCalEESensitive");
223  desc.add<bool>("useEE", true);
224  desc.add<double>("zFrontEE", 0.0);
225  desc.add<std::string>("caloHitSrcEE", "HGCHitsEE");
226  desc.add<std::string>("detectorFH", "HGCalHESiliconSensitive");
227  desc.add<bool>("useFH", false);
228  desc.add<double>("zFrontFH", 0.0);
229  desc.add<std::string>("caloHitSrcFH", "HGCHitsHEfront");
230  desc.add<std::string>("detectorBH", "AHCal");
231  desc.add<bool>("useBH", false);
232  desc.add<double>("zFrontBH", 0.0);
233  desc.add<std::string>("caloHitSrcBH", "HcalHits");
234  desc.add<std::string>("detectorBeam", "HcalTB06BeamDetector");
235  desc.add<bool>("useBeam", false);
236  desc.add<std::string>("caloHitSrcBeam", "HcalTB06BeamHits");
237  std::vector<int> ids = {
238  1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1011, 1012, 1013, 1014, 2001, 2002, 2003, 2004, 2005};
239  desc.add<std::vector<int>>("idBeams", ids);
240  desc.add<edm::InputTag>("generatorSrc", edm::InputTag("generatorSmeared"));
241  desc.add<edm::InputTag>("passiveEE", edm::InputTag("g4SimHits", "HGCalEEPassiveHits"));
242  desc.add<edm::InputTag>("passiveFH", edm::InputTag("g4SimHits", "HGCalHEPassiveHits"));
243  desc.add<edm::InputTag>("passiveBH", edm::InputTag("g4SimHits", "HGCalAHPassiveHits"));
244  desc.add<edm::InputTag>("passiveCMSE", edm::InputTag("g4SimHits", "CMSEPassiveHits"));
245  desc.add<edm::InputTag>("passiveBeam", edm::InputTag("g4SimHits", "HGCalBeamPassiveHits"));
246 
247  desc.add<bool>("doSimHits", true);
248  desc.add<bool>("doTree", true);
249  desc.add<bool>("doTreeCell", true);
250  desc.add<bool>("doPassive", false);
251  desc.add<bool>("doPassiveEE", false);
252  desc.add<bool>("doPassiveHE", false);
253  desc.add<bool>("doPassiveBH", false);
254  desc.add<bool>("addP", false);
255  desc.add<bool>("doBeam", false);
256  desc.addUntracked<double>("gev2mip200", 57.0e-6);
257  desc.addUntracked<double>("gev2mip300", 85.5e-6);
258  desc.addUntracked<double>("stoc_smear_time_200", 10.24);
259  desc.addUntracked<double>("stoc_smear_time_300", 15.5);
260  desc.addUntracked<int>("maxDepth", 12);
261  desc.addUntracked<double>("deltaX", 30.0); // Size of tile along X
262  desc.addUntracked<double>("deltaY", 30.0); // Size of tile along Y
263  desc.addUntracked<double>("deltaZ", 81.0); // Thickness of a single layer
264  desc.addUntracked<double>("zFirst", 17.6); // Position of the center
265  descriptions.add("HGCalTB23Analyzer", desc);
266 }
267 
269  char name[40], title[100];
270  hBeam_ = fs_->make<TH1D>("BeamP", "Beam Momentum", 1000, 0, 1000.0);
271  for (int i = 0; i < 3; ++i) {
272  bool book(ifEE_);
274  if (i == 1) {
275  book = ifFH_;
276  det = detectorFH_;
277  } else if (i == 2) {
278  book = ifBH_;
279  det = detectorBH_;
280  }
281 
282  if (doSimHits_ && book) {
283  sprintf(name, "SimHitEn%s", det.c_str());
284  sprintf(title, "Sim Hit Energy for %s", det.c_str());
285  hSimHitE_[i] = fs_->make<TH1D>(name, title, 100000, 0., 0.2);
286  sprintf(name, "SimHitEnX%s", det.c_str());
287  sprintf(title, "Sim Hit Energy for %s", det.c_str());
288  hSimHitEn_[i] = fs_->make<TH1D>(name, title, 100000, 0., 0.2);
289  sprintf(name, "SimHitTm%s", det.c_str());
290  sprintf(title, "Sim Hit Timing for %s", det.c_str());
291  hSimHitT_[i] = fs_->make<TH1D>(name, title, 5000, 0., 500.0);
292  sprintf(name, "SimHitLat%s", det.c_str());
293  sprintf(title, "Lateral Shower profile (Sim Hit) for %s", det.c_str());
294  hSimHitLat_[i] = fs_->make<TProfile2D>(name, title, 100, -100., 100., 100, -100., 100.);
295  sprintf(name, "SimHitLng%s", det.c_str());
296  sprintf(title, "Longitudinal Shower profile (Sim Hit) for %s", det.c_str());
297  hSimHitLng_[i] = fs_->make<TProfile>(name, title, 50, 0., 100.);
298  sprintf(name, "SimHitLng1%s", det.c_str());
299  sprintf(title, "Longitudinal Shower profile (Layer) for %s", det.c_str());
300  hSimHitLng1_[i] = fs_->make<TProfile>(name, title, 200, 0., 100.);
301  sprintf(name, "SimHitLng2%s", det.c_str());
302  sprintf(title, "Longitudinal Shower profile (Layer) for %s", det.c_str());
303  hSimHitLng2_[i] = fs_->make<TProfile>(name, title, 200, 0., 100.);
304  }
305  }
306  if (ifBeam_ && doSimHits_) {
307  sprintf(name, "SimHitEn%s", detectorBeam_.c_str());
308  sprintf(title, "Sim Hit Energy for %s", detectorBeam_.c_str());
309  hSimHitE_[3] = fs_->make<TH1D>(name, title, 100000, 0., 0.2);
310  sprintf(name, "SimHitEnX%s", detectorBeam_.c_str());
311  sprintf(title, "Sim Hit Energy for %s", detectorBeam_.c_str());
312  hSimHitEn_[3] = fs_->make<TH1D>(name, title, 100000, 0., 0.2);
313  sprintf(name, "SimHitTm%s", detectorBeam_.c_str());
314  sprintf(title, "Sim Hit Timing for %s", detectorBeam_.c_str());
315  hSimHitT_[3] = fs_->make<TH1D>(name, title, 5000, 0., 500.0);
316  }
317  if (doSimHits_ && doTree_) {
318  tree_ = fs_->make<TTree>("HGCTB", "SimHitEnergy");
319  tree_->Branch("simHitLayEn1EE", &simHitLayEn1EE_);
320  tree_->Branch("simHitLayEn2EE", &simHitLayEn2EE_);
321  tree_->Branch("simHitLayEn1FH", &simHitLayEn1FH_);
322  tree_->Branch("simHitLayEn2FH", &simHitLayEn2FH_);
323  tree_->Branch("simHitLayEn1BH", &simHitLayEn1BH_);
324  tree_->Branch("simHitLayEn2BH", &simHitLayEn2BH_);
325  tree_->Branch("xBeam", &xBeam_, "xBeam/D");
326  tree_->Branch("yBeam", &yBeam_, "yBeam/D");
327  tree_->Branch("zBeam", &zBeam_, "zBeam/D");
328  tree_->Branch("pBeam", &pBeam_, "pBeam/D");
329  tree_->Branch("thetaBeam", &thetaBeam_, "thetaBeam/D");
330  tree_->Branch("phiBeam", &phiBeam_, "phiBeam/D");
331  if (doBeam_) {
332  tree_->Branch("nBeamMC", &nBeamMC_, "nBeamMC/I");
333  tree_->Branch("pdgIdBeamMC", &pdgIdBeamMC_);
334  tree_->Branch("xBeamMC", &xBeamMC_);
335  tree_->Branch("yBeamMC", &yBeamMC_);
336  tree_->Branch("zBeamMC", &zBeamMC_);
337  tree_->Branch("pxBeamMC", &pxBeamMC_);
338  tree_->Branch("pyBeamMC", &pyBeamMC_);
339  tree_->Branch("pzBeamMC", &pzBeamMC_);
340  tree_->Branch("pBeamMC", &pBeamMC_);
341  }
342  if (doTreeCell_) {
343  tree_->Branch("simHitCellIdEE", &simHitCellIdEE_);
344  tree_->Branch("simHitCellEnEE", &simHitCellEnEE_);
345  tree_->Branch("simHitCellIdFH", &simHitCellIdFH_);
346  tree_->Branch("simHitCellEnFH", &simHitCellEnFH_);
347  tree_->Branch("simHitCellIdBH", &simHitCellIdBH_);
348  tree_->Branch("simHitCellEnBH", &simHitCellEnBH_);
349  tree_->Branch("simHitCellIdBeam", &simHitCellIdBeam_);
350  tree_->Branch("simHitCellEnBeam", &simHitCellEnBeam_);
351 
352  tree_->Branch("simHitCellColBH", &simHitCellColBH_);
353  tree_->Branch("simHitCellRowBH", &simHitCellRowBH_);
354  tree_->Branch("simHitCellLayerBH", &simHitCellLayerBH_);
355  tree_->Branch("simHitCellTimeFirstHitEE", &simHitCellTimeFirstHitEE_);
356  tree_->Branch("simHitCellTimeFirstHitFH", &simHitCellTimeFirstHitFH_);
357  //tree_->Branch("simHitCellTimeFirstHitBH", &simHitCellTimeFirstHitBH_);
358  tree_->Branch("simHitCellTime15MipEE", &simHitCellTime15MipEE_);
359  tree_->Branch("simHitCellTime15MipFH", &simHitCellTime15MipFH_);
360  //tree_->Branch("simHitCellTime15MipBH", &simHitCellTime15MipBH_);
361  tree_->Branch("simHitCellTimeLastHitEE", &simHitCellTimeLastHitEE_);
362  tree_->Branch("simHitCellTimeLastHitFH", &simHitCellTimeLastHitFH_);
363  //tree_->Branch("simHitCellTimeLastHitBH", &simHitCellTimeLastHitBH_);
364  }
365  }
366 
367  if (doPassive_ && doTree_) {
368  if (doPassiveEE_) {
369  tree_->Branch("hgcPassiveEEEnergy", &hgcPassiveEEEnergy_);
370  tree_->Branch("hgcPassiveEEName", &hgcPassiveEEName_);
371  tree_->Branch("hgcPassiveEEID", &hgcPassiveEEID_);
372  }
373  if (doPassiveHE_) {
374  tree_->Branch("hgcPassiveFHEnergy", &hgcPassiveFHEnergy_);
375  tree_->Branch("hgcPassiveFHName", &hgcPassiveFHName_);
376  tree_->Branch("hgcPassiveFHID", &hgcPassiveFHID_);
377  }
378  if (doPassiveBH_) {
379  tree_->Branch("hgcPassiveBHEnergy", &hgcPassiveBHEnergy_);
380  tree_->Branch("hgcPassiveBHName", &hgcPassiveBHName_);
381  tree_->Branch("hgcPassiveBHID", &hgcPassiveBHID_);
382  }
383  tree_->Branch("hgcPassiveCMSEEnergy", &hgcPassiveCMSEEnergy_);
384  tree_->Branch("hgcPassiveCMSEName", &hgcPassiveCMSEName_);
385  tree_->Branch("hgcPassiveCMSEID", &hgcPassiveCMSEID_);
386  tree_->Branch("hgcPassiveBeamEnergy", &hgcPassiveBeamEnergy_);
387  tree_->Branch("hgcPassiveBeamName", &hgcPassiveBeamName_);
388  tree_->Branch("hgcPassiveBeamID", &hgcPassiveBeamID_);
389  }
390 }
391 
393  char name[40], title[100];
394  if (ifEE_) {
395  hgcons_[0] = &iSetup.getData(tokDDDEE_);
396  for (unsigned int l = 0; l < hgcons_[0]->layers(false); ++l) {
397  sprintf(name, "SimHitEnA%d%s", l, detectorEE_.c_str());
398  sprintf(title, "Sim Hit Energy in SIM layer %d for %s", l + 1, detectorEE_.c_str());
399  hSimHitLayEn1EE_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
400  if (l % 3 == 0) {
401  sprintf(name, "SimHitEnB%d%s", (l / 3 + 1), detectorEE_.c_str());
402  sprintf(title, "Sim Hit Energy in layer %d for %s", (l / 3 + 1), detectorEE_.c_str());
403  hSimHitLayEn2EE_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
404  }
405  }
406 #ifdef EDM_ML_DEBUG
407  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer::" << detectorEE_ << " defined with " << hgcons_[0]->layers(false)
408  << " layers";
409 #endif
410  } else {
411  hgcons_[0] = nullptr;
412  }
413 
414  if (ifFH_) {
415  hgcons_[1] = &iSetup.getData(tokDDDFH_);
416  for (unsigned int l = 0; l < hgcons_[1]->layers(false); ++l) {
417  sprintf(name, "SimHitEnA%d%s", l, detectorFH_.c_str());
418  sprintf(title, "Sim Hit Energy in layer %d for %s", l + 1, detectorFH_.c_str());
419  hSimHitLayEn1FH_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
420  if (l % 3 == 0) {
421  sprintf(name, "SimHitEnB%d%s", (l / 3 + 1), detectorFH_.c_str());
422  sprintf(title, "Sim Hit Energy in layer %d for %s", (l / 3 + 1), detectorFH_.c_str());
423  hSimHitLayEn2FH_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
424  }
425  }
426 #ifdef EDM_ML_DEBUG
427  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer::" << detectorFH_ << " defined with " << hgcons_[1]->layers(false)
428  << " layers";
429 #endif
430  } else {
431  hgcons_[1] = nullptr;
432  }
433 
434  if (ifBH_) {
435  for (int l = 0; l < ahcalGeom_->maxDepth(); ++l) {
436  sprintf(name, "SimHitEnA%d%s", l, detectorBH_.c_str());
437  sprintf(title, "Sim Hit Energy in layer %d for %s", l + 1, detectorBH_.c_str());
438  hSimHitLayEn1BH_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
439  sprintf(name, "SimHitEnB%d%s", l, detectorBH_.c_str());
440  sprintf(title, "Sim Hit Energy in layer %d for %s", l + 1, detectorBH_.c_str());
441  hSimHitLayEn2BH_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
442  }
443  }
444 
445  if (ifBeam_) {
446  for (unsigned int l = 0; l < idBeams_.size(); ++l) {
447  sprintf(name, "SimHitEna%d%s", l, detectorBeam_.c_str());
448  sprintf(title, "Sim Hit Energy in type %d for %s", idBeams_[l], detectorBeam_.c_str());
449  hSimHitLayEnBeam_.push_back(fs_->make<TH1D>(name, title, 100000, 0., 0.2));
450  }
451  }
452 }
453 
455  // Generator input
456  const edm::Handle<edm::HepMCProduct>& evtMC = iEvent.getHandle(tok_hepMC_);
457  if (!evtMC.isValid()) {
458  edm::LogWarning("HGCal") << "no HepMCProduct found";
459  } else {
460  const HepMC::GenEvent* myGenEvent = evtMC->GetEvent();
461  unsigned int k(0);
462  HepMC::FourVector pxyz(0, 0, 0, 0);
463  for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
464  ++p, ++k) {
465  edm::LogVerbatim("HGCSim") << "Particle [" << k << "] with p " << (*p)->momentum().rho() << " theta "
466  << (*p)->momentum().theta() << " phi " << (*p)->momentum().phi() << " pxyz ("
467  << (*p)->momentum().px() << ", " << (*p)->momentum().py() << ", "
468  << (*p)->momentum().pz() << ")";
469  if (addP_) {
470  pxyz.setPx(pxyz.px() + (*p)->momentum().px());
471  pxyz.setPy(pxyz.py() + (*p)->momentum().py());
472  pxyz.setPz(pxyz.pz() + (*p)->momentum().pz());
473  pxyz.setE(pxyz.e() + (*p)->momentum().e());
474  } else if (!addP_ && (k == 0)) {
475  pxyz = (*p)->momentum();
476  }
477  }
478  hBeam_->Fill(pxyz.rho());
479  edm::LogVerbatim("HGCSim") << "Particle with p " << pxyz.rho() << " theta " << pxyz.theta() << " phi "
480  << pxyz.phi();
481  }
482 
483  // Now the Simhits
484  if (doSimHits_) {
485  const edm::Handle<edm::SimTrackContainer>& SimTk = iEvent.getHandle(tok_simTk_);
486  const edm::Handle<edm::SimVertexContainer>& SimVtx = iEvent.getHandle(tok_simVtx_);
487  analyzeSimTracks(SimTk, SimVtx);
488 
489  simHitLayEn1EE_.clear();
490  simHitLayEn2EE_.clear();
491  simHitLayEn1FH_.clear();
492  simHitLayEn2FH_.clear();
493  simHitLayEn1BH_.clear();
494  simHitLayEn2BH_.clear();
495  simHitLayEnBeam_.clear();
496  simHitCellIdEE_.clear();
497  simHitCellEnEE_.clear();
498  simHitCellIdFH_.clear();
499  simHitCellEnFH_.clear();
500  simHitCellIdBH_.clear();
501  simHitCellEnBH_.clear();
502  simHitCellIdBeam_.clear();
503  simHitCellEnBeam_.clear();
504  simHitCellColBH_.clear();
505  simHitCellRowBH_.clear();
506  simHitCellLayerBH_.clear();
508  simHitCellTime15MipEE_.clear();
509  simHitCellTimeLastHitEE_.clear();
511  simHitCellTime15MipFH_.clear();
512  simHitCellTimeLastHitFH_.clear();
513  std::vector<PCaloHit> caloHits;
514  if (ifEE_) {
515  simHitLayEn1EE_ = std::vector<float>(hgcons_[0]->layers(false), 0);
516  simHitLayEn2EE_ = std::vector<float>(hgcons_[0]->layers(true), 0);
517  const edm::Handle<edm::PCaloHitContainer>& theCaloHitContainers = iEvent.getHandle(tok_hitsEE_);
518  if (theCaloHitContainers.isValid()) {
519 #ifdef EDM_ML_DEBUG
520  edm::LogVerbatim("HGCSim") << "PcalohitContainer for " << detectorEE_ << " has " << theCaloHitContainers->size()
521  << " hits";
522 #endif
523  caloHits.clear();
524  caloHits.insert(caloHits.end(), theCaloHitContainers->begin(), theCaloHitContainers->end());
525  analyzeSimHits(0, caloHits, zFrontEE_);
526  } else {
527 #ifdef EDM_ML_DEBUG
528  edm::LogVerbatim("HGCSim") << "PCaloHitContainer does not exist for " << detectorEE_ << " !!!";
529 #endif
530  }
531  }
532  if (ifFH_) {
533  simHitLayEn1FH_ = std::vector<float>(hgcons_[1]->layers(false), 0);
534  simHitLayEn2FH_ = std::vector<float>(hgcons_[1]->layers(true), 0);
535  const edm::Handle<edm::PCaloHitContainer>& theCaloHitContainers = iEvent.getHandle(tok_hitsFH_);
536  if (theCaloHitContainers.isValid()) {
537 #ifdef EDM_ML_DEBUG
538  edm::LogVerbatim("HGCSim") << "PcalohitContainer for " << detectorFH_ << " has " << theCaloHitContainers->size()
539  << " hits";
540 #endif
541  caloHits.clear();
542  caloHits.insert(caloHits.end(), theCaloHitContainers->begin(), theCaloHitContainers->end());
543  analyzeSimHits(1, caloHits, zFrontFH_);
544  } else {
545 #ifdef EDM_ML_DEBUG
546  edm::LogVerbatim("HGCSim") << "PCaloHitContainer does not exist for " << detectorFH_ << " !!!";
547 #endif
548  }
549  }
550  if (ifBH_) {
551  simHitLayEn1BH_ = std::vector<float>(ahcalGeom_->maxDepth(), 0);
552  simHitLayEn2BH_ = std::vector<float>(ahcalGeom_->maxDepth(), 0);
553  const edm::Handle<edm::PCaloHitContainer>& theCaloHitContainers = iEvent.getHandle(tok_hitsBH_);
554  if (theCaloHitContainers.isValid()) {
555 #ifdef EDM_ML_DEBUG
556  edm::LogVerbatim("HGCSim") << "PcalohitContainer for " << detectorBH_ << " has " << theCaloHitContainers->size()
557  << " hits";
558 #endif
559  caloHits.clear();
560  caloHits.insert(caloHits.end(), theCaloHitContainers->begin(), theCaloHitContainers->end());
561  analyzeSimHits(2, caloHits, zFrontBH_);
562  } else {
563 #ifdef EDM_ML_DEBUG
564  edm::LogVerbatim("HGCSim") << "PCaloHitContainer does not exist for " << detectorBH_ << " !!!";
565 #endif
566  }
567  }
568  if (ifBeam_) {
569  simHitLayEnBeam_ = std::vector<float>(idBeams_.size(), 0);
570  const edm::Handle<edm::PCaloHitContainer>& theCaloHitContainers = iEvent.getHandle(tok_hitsBeam_);
571  if (theCaloHitContainers.isValid()) {
572 #ifdef EDM_ML_DEBUG
573  edm::LogVerbatim("HGCSim") << "PcalohitContainer for " << detectorBeam_ << " has "
574  << theCaloHitContainers->size() << " hits";
575 #endif
576  caloHits.clear();
577  caloHits.insert(caloHits.end(), theCaloHitContainers->begin(), theCaloHitContainers->end());
578  analyzeSimHits(3, caloHits, 0.0);
579  } else {
580 #ifdef EDM_ML_DEBUG
581  edm::LogVerbatim("HGCSim") << "PCaloHitContainer does not exist for " << detectorBeam_ << " !!!";
582 #endif
583  }
584  }
585  } // if (doSimHits_)
586 
588  if (doPassive_) {
590  hgcPassiveEEEnergy_.clear();
591  hgcPassiveEEName_.clear();
592  hgcPassiveEEID_.clear();
593  if (doPassiveEE_) {
594  const edm::Handle<edm::PassiveHitContainer>& hgcPHEE = iEvent.getHandle(tok_hgcPHEE_);
595  analyzePassiveHits(hgcPHEE, 1);
596  }
598  hgcPassiveFHEnergy_.clear();
599  hgcPassiveFHName_.clear();
600  hgcPassiveFHID_.clear();
601  if (doPassiveHE_) {
602  const edm::Handle<edm::PassiveHitContainer>& hgcPHFH = iEvent.getHandle(tok_hgcPHFH_);
603  analyzePassiveHits(hgcPHFH, 2);
604  }
606  hgcPassiveBHEnergy_.clear();
607  hgcPassiveBHName_.clear();
608  hgcPassiveBHID_.clear();
609  if (doPassiveBH_) {
610  const edm::Handle<edm::PassiveHitContainer>& hgcPHBH = iEvent.getHandle(tok_hgcPHBH_);
611  analyzePassiveHits(hgcPHBH, 3);
612  }
614  hgcPassiveCMSEEnergy_.clear();
615  hgcPassiveCMSEName_.clear();
616  hgcPassiveCMSEID_.clear();
617  const edm::Handle<edm::PassiveHitContainer>& hgcPHCMSE = iEvent.getHandle(tok_hgcPHCMSE_);
618  analyzePassiveHits(hgcPHCMSE, 4);
620  hgcPassiveBeamName_.clear();
621  hgcPassiveBeamEnergy_.clear();
622  hgcPassiveBeamID_.clear();
623  const edm::Handle<edm::PassiveHitContainer>& hgcPHBeam = iEvent.getHandle(tok_hgcPHBeam_);
624  analyzePassiveHits(hgcPHBeam, 5);
625  }
626 
627  if ((doSimHits_ || doPassive_) && (doTree_))
628  tree_->Fill();
629 } // void HGCalTB23Analyzer::analyze
630 
631 void HGCalTB23Analyzer::analyzeSimHits(int type, std::vector<PCaloHit>& hits, double zFront) {
632  std::map<uint32_t, double> map_hits, map_hitn;
633  std::map<uint32_t, double> map_hittime_firsthit, map_hittime_lasthit, map_hittime_15Mip;
634  std::map<int, double> map_hitDepth, map_hitWafer;
635  std::map<int, std::pair<uint32_t, double>> map_hitLayer, map_hitCell;
636  double entot(0);
637  std::map<uint32_t, double> nhits;
638  std::map<uint32_t, int> ID, Depth;
639  std::map<uint32_t, double> GeV2Mip;
640  std::map<uint32_t, double> StochTermTime;
641  std::vector<int> nSimLayers;
643  std::map<uint32_t, std::vector<std::pair<double, double>>> map_hitTimeEn;
644  //bool debug = true;
645  bool debug = false;
646  for (unsigned int i = 0; i < hits.size(); i++) {
647  double energy = hits[i].energy();
648  double time = hits[i].time();
649  uint32_t id = hits[i].id();
650  entot += energy;
651  int subdet, zside, layer, sector, subsector(0), cell, cell2(0), depth(0), idx(0);
652  if (type == 2) {
653  subdet = HcalDetId(id).subdet();
654  if (subdet != HcalOther)
655  continue;
656  AHCalDetId hid(id);
657  layer = depth = hid.depth();
658  zside = hid.zside();
659  sector = hid.irow();
660  cell = hid.icol();
661  idx = ((hid.irowAbs() * 100) + (hid.icolAbs()));
662  if (debug)
663  edm::LogVerbatim("HGCSim") << "depth, sector, cell " << depth << ":" << sector << ":" << cell;
664  } else if (type == 3) {
665  HcalTestBeamNumbering::unpackIndex(id, subdet, layer, sector, cell);
666  depth = layer;
667  zside = 1;
668  idx = subdet * 1000 + layer;
669  layer = idx;
670  } else {
671 #ifdef EDM_ML_DEBUG
672  edm::LogVerbatim("HGCSim") << "ID " << std::hex << id << std::dec << " " << HGCSiliconDetId(id);
673 #endif
674  HGCSiliconDetId(id).unpack(subdet, zside, layer, sector, subsector, cell, cell2);
675 #ifdef EDM_ML_DEBUG
676  edm::LogVerbatim("HGCSim") << "Unpack ID " << subdet << " " << zside << " " << layer << " " << sector << " "
677  << subsector << " " << cell << " " << cell2;
678 #endif
679  depth = hgcons_[type]->simToReco(cell, layer, sector, true).second;
680  static constexpr uint32_t mask = 0xFFFFF;
681  static constexpr uint32_t maskcell = 0x3FF;
682  idx = (id & mask);
683 #ifdef EDM_ML_DEBUG
684  std::pair<float, float> xy = hgcons_[type]->locateCell(HGCSiliconDetId(id), false);
685  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer::detId " << std::hex << id << std::dec << " Layer:Wafer:Cell "
686  << layer << ":" << sector << ":" << subsector << ":" << cell << ":" << cell2
687  << " Position " << xy.first << ":" << xy.second << ":"
688  << hgcons_[type]->waferZ(layer, false);
689 #endif
690  cell = (idx & maskcell);
691  sector = (idx >> 10) & maskcell;
692  }
693 #ifdef EDM_ML_DEBUG
694  edm::LogVerbatim("HGCSim") << "SimHit:Hit[" << i << "] Id " << subdet << ":" << zside << ":" << layer << ":"
695  << sector << ":" << cell << " Energy " << energy << " Time " << time;
696 #endif
697  if (map_hits.count(id) != 0) {
698  map_hits[id] += energy;
699  } else {
700  map_hits[id] = energy;
701  }
702  if (map_hitLayer.count(layer) != 0) {
703  double ee = energy + map_hitLayer[layer].second;
704  map_hitLayer[layer] = std::make_pair(id, ee);
705  } else {
706  map_hitLayer[layer] = std::make_pair(id, energy);
707  }
708  if (map_hitWafer.count(sector) != 0)
709  map_hitWafer[sector] += energy;
710  else
711  map_hitWafer[sector] = energy;
712  if (depth >= 0) {
713  if (map_hitCell.count(idx) != 0) {
714  double ee = energy + map_hitCell[idx].second;
715  map_hitCell[idx] = std::make_pair(id, ee);
716  } else {
717  map_hitCell[idx] = std::make_pair(id, energy);
718  }
719  if (debug) {
720  if (type == 1)
721  edm::LogVerbatim("HGCSim") << "EE, depth is and map_hitDepth[depth] " << depth << " " << map_hitDepth[depth];
722  if (type == 2)
723  edm::LogVerbatim("HGCSim") << "BH, depth is and map_hitDepth[depth] " << depth << " " << map_hitDepth[depth];
724  }
725  if (map_hitDepth.count(depth) != 0) {
726  map_hitDepth[depth] += energy;
727  } else {
728  map_hitDepth[depth] = energy;
729  }
730  uint32_t idn =
731  (type >= 2) ? id : HGCalTestNumbering::packHexagonIndex(subdet, zside, depth, sector, subsector, cell);
732  map_hitTimeEn[idn].push_back(std::make_pair(time, energy));
733  GeV2Mip[idn] = gev2mip300_;
734  StochTermTime[idn] = stoc_smear_time_300_;
735  ID[idn] = id;
736  Depth[idn] = depth;
737  if (map_hitn.count(idn) != 0) {
738  map_hitn[idn] += energy;
739  ++nhits[idn];
740  } else {
741  map_hitn[idn] = energy;
742  nhits[idn] = 1;
743  }
744  }
745  hSimHitT_[type]->Fill(time, energy);
746  }
747 
748  if (type < 2) { //store only for EE and FH
749  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: " << map_hitWafer.size() << " wafers are hit in type " << type;
750  for (auto itr = map_hitWafer.begin(); itr != map_hitWafer.end(); ++itr)
751  edm::LogVerbatim("HGCSim") << "Wafer: " << itr->first << " Deposited Energy " << itr->second;
753  for (const auto& itr : map_hitTimeEn) {
754  uint32_t id = itr.first;
755  int waferU(-99), waferV(-99);
757  waferU = HGCSiliconDetId(ID[id]).waferU();
758  waferV = HGCSiliconDetId(ID[id]).waferV();
759  double layer = HGCSiliconDetId(id).layer();
761  if (debug)
762  edm::LogVerbatim("HGCSim") << "wafer is : depth (reco) " << waferU << ":" << waferV << " " << Depth[id]
763  << "\ntype : layer : wafer thickness " << type << " " << layer << " " << thickness
764  << "\nID(sim) and id(reco) " << std::hex << ID[id] << " " << id << std::dec;
765  if (thickness == 300) {
766  GeV2Mip[id] = gev2mip300_;
767  StochTermTime[id] = stoc_smear_time_300_;
768  } else if (thickness == 200) {
769  GeV2Mip[id] = gev2mip200_;
770  StochTermTime[id] = stoc_smear_time_200_;
771  }
772  //first sort
773  std::sort(map_hitTimeEn[id].begin(), map_hitTimeEn[id].end(), sortTime);
775  double threshold = 15.;
776  double totE = 0.;
777  double totEbeforeThreshold = 0.;
778  double timebeforeThreshold = 0.;
779  double timeAtThresohld = 0.;
780  for (unsigned int ihit = 0; ihit < map_hitTimeEn[id].size(); ihit++) {
781  double energy = (map_hitTimeEn[id].at(ihit)).second / GeV2Mip[id];
782  totE += energy;
783  double time = (map_hitTimeEn[id].at(ihit)).first;
784  if (debug)
785  edm::LogVerbatim("HGCSim") << "Tot E till now : time of that E : GeV2Mip[id] is " << totE << " " << time
786  << " " << GeV2Mip[id];
787  if (totE < threshold) {
788  totEbeforeThreshold = totE;
789  timebeforeThreshold = time;
790  } else {
791  timeAtThresohld =
792  (threshold - totEbeforeThreshold) * (time - timebeforeThreshold) / (totE - totEbeforeThreshold) +
793  timebeforeThreshold;
794  map_hittime_15Mip[id] = timeAtThresohld;
795  if (debug)
796  edm::LogVerbatim("HGCSim") << "ihit : energyBefore : timeBefore : energyTot : timeTot : timeAt15MIP "
797  << ihit << " " << totEbeforeThreshold << " " << timebeforeThreshold << " "
798  << totE << " " << time << " " << map_hittime_15Mip[id];
799  break;
800  }
801  }
802  if (!map_hitTimeEn[id].empty()) {
803  map_hittime_firsthit[id] = (map_hitTimeEn[id].at(0)).first;
804  map_hittime_lasthit[id] = (map_hitTimeEn[id].at(map_hitTimeEn[id].size() - 1)).first;
805  if (map_hittime_15Mip[id] < map_hittime_firsthit[id])
806  map_hittime_15Mip[id] = map_hittime_firsthit[id];
807  /*
809  double firsthit_sm = ran3.Gaus(map_hittime_firsthit_vtxCorr[id], StochTermTime[id]);
810  double lasthit_sm = ran3.Gaus(map_hittime_lasthit_vtxCorr[id], StochTermTime[id]);
811  double threshmiphit_sm = ran3.Gaus(map_hittime_15Mip_vtxCorr[id], StochTermTime[id]);
812  */
813  }
814 
815  if (totE < threshold)
816  map_hittime_15Mip[id] = -99;
817  if (debug)
818  edm::LogVerbatim("HGCSim") << "id : first hit time : last hit time " << id << " " << map_hittime_firsthit[id]
819  << " " << map_hittime_lasthit[id] << "\nFinally for this cell, time is "
820  << map_hittime_15Mip[id];
821  }
822  }
823 
824  hSimHitEn_[type]->Fill(entot);
825  for (const auto& itr : map_hits) {
826  hSimHitE_[type]->Fill(itr.second);
827  }
828 
829  if (debug)
830  edm::LogVerbatim("HGCSim") << "Now looping over map_hitLayer";
831  for (const auto& itr : map_hitLayer) {
832  int layer = (type == 2) ? itr.first : (itr.first - 1);
833  double energy = (itr.second).second;
834  double zp(0);
835  if (type < 2)
836  zp = hgcons_[type]->waferZ(layer + 1, false);
837  else if (type == 2)
838  zp = ahcalGeom_->getZ(AHCalDetId((itr.second).first));
839 #ifdef EDM_ML_DEBUG
840  edm::LogVerbatim("HGCSim") << "SimHit:Layer " << layer + 1 << " Z " << zp << ":" << zp - zFront << " E " << energy;
841 #endif
842  if (type < 3) {
843  hSimHitLng_[type]->Fill(zp - zFront, energy);
844  hSimHitLng2_[type]->Fill(layer + 1, energy);
845  }
846  if (type == 0) {
847  if (layer < static_cast<int>(hSimHitLayEn1EE_.size())) {
849  hSimHitLayEn1EE_[layer]->Fill(energy);
850  }
851  } else if (type == 1) {
852  if (layer < static_cast<int>(hSimHitLayEn1FH_.size())) {
854  hSimHitLayEn1FH_[layer]->Fill(energy);
855  }
856  } else if (type == 2) {
857  if (debug)
858  edm::LogVerbatim("HGCSim") << "layer < hSimHitLayEn1BH_.size()";
859  if (layer < static_cast<int>(hSimHitLayEn1BH_.size())) {
861  hSimHitLayEn1BH_[layer]->Fill(energy);
862  }
863  } else {
864  for (unsigned int k = 0; k < idBeams_.size(); ++k) {
865  if (layer + 1 == idBeams_[k]) {
867  hSimHitLayEnBeam_[k]->Fill(energy);
868  break;
869  }
870  }
871  }
872  }
873  for (const auto& itr : map_hitDepth) {
874  int layer = (type == 2) ? itr.first : (itr.first - 1);
875  double energy = itr.second;
876 #ifdef EDM_ML_DEBUG
877  edm::LogVerbatim("HGCSim") << "SimHit:Layer " << layer + 1 << " " << energy;
878 #endif
879  hSimHitLng1_[type]->Fill(layer + 1, energy);
880  if (type == 0) {
881  if (layer < static_cast<int>(hSimHitLayEn2EE_.size())) {
883  hSimHitLayEn2EE_[layer]->Fill(energy);
884  }
885  } else if (type == 1) {
886  if (layer < static_cast<int>(hSimHitLayEn2FH_.size())) {
888  hSimHitLayEn2FH_[layer]->Fill(energy);
889  }
890  } else if (type == 2) {
891  if (debug)
892  edm::LogVerbatim("HGCSim") << "Inside map_hitDepth, layer no. " << layer;
893  if (layer < static_cast<int>(hSimHitLayEn2BH_.size())) {
895  hSimHitLayEn2BH_[layer]->Fill(energy);
896  }
897  }
898  }
899 
900  if (debug)
901  edm::LogVerbatim("HGCSim") << "Now looping over map_hitCell";
902  if (type < 3) {
903  for (const auto& itr : map_hitCell) {
904  uint32_t id = ((itr.second).first);
905  double energy = ((itr.second).second);
906  std::pair<float, float> xy(0, 0);
907  double xx(0);
908  if (type == 2) {
909  xy = ahcalGeom_->getXY(AHCalDetId(id));
910  xx = xy.first;
911  } else {
912  int subdet, zside, layer, sector, subsector, cell;
914  xy = hgcons_[type]->locateCell(cell, layer, sector, false);
915  double zp = hgcons_[type]->waferZ(layer, false);
916  xx = (zp < 0) ? -xy.first : xy.first;
917  }
918  hSimHitLat_[type]->Fill(xx, xy.second, energy);
919  }
920  }
921 
922  for (const auto& itr : map_hitn) {
923  uint32_t id = itr.first;
924  double energy = itr.second;
925  if (type == 0) {
926  double time_firsthit = map_hittime_firsthit[id];
927  double time15Mip = map_hittime_15Mip[id];
928  double time_lasthit = map_hittime_lasthit[id];
929  simHitCellIdEE_.push_back(id);
930  simHitCellEnEE_.push_back(energy);
931  simHitCellTimeFirstHitEE_.push_back(time_firsthit);
932  simHitCellTime15MipEE_.push_back(time15Mip);
933  simHitCellTimeLastHitEE_.push_back(time_lasthit);
934  if (debug && (energy / GeV2Mip[id] < 15) && (map_hittime_15Mip[id] > 0))
935  edm::LogVerbatim("HGCSim") << "FOUND!!!!rechit energy : Finally for this cell, time is " << energy / GeV2Mip[id]
936  << " " << map_hittime_15Mip[id];
937  } else if (type == 1) {
938  double time_firsthit = map_hittime_firsthit[id];
939  double time15Mip = map_hittime_15Mip[id];
940  double time_lasthit = map_hittime_lasthit[id];
941  simHitCellIdFH_.push_back(id);
942  simHitCellEnFH_.push_back(energy);
943  simHitCellTimeFirstHitFH_.push_back(time_firsthit);
944  simHitCellTime15MipFH_.push_back(time15Mip);
945  simHitCellTimeLastHitFH_.push_back(time_lasthit);
946  } else if (type == 2) {
947  simHitCellIdBH_.push_back(id);
948  simHitCellEnBH_.push_back(energy);
949  AHCalDetId hid(id);
950  int row = hid.irow();
951  int col = hid.icol();
952  int layer = hid.depth();
953  simHitCellColBH_.push_back(col);
954  simHitCellRowBH_.push_back(row);
955  simHitCellLayerBH_.push_back(layer);
956 #ifdef EDM_ML_DEBUG
957  edm::LogVerbatim("HGCSim") << "ID: " << std::hex << id << std::dec << " Layer: " << layer << " col: " << col
958  << " row: " << row;
959 #endif
960  } else if (type == 3) {
961  simHitCellIdBeam_.push_back(id);
962  simHitCellEnBeam_.push_back(energy);
963  }
964  }
965 }
966 
968  edm::Handle<edm::SimVertexContainer> const& SimVtx) {
969  xBeam_ = yBeam_ = zBeam_ = pBeam_ = -9999;
970  nBeamMC_ = thetaBeam_ = phiBeam_ = -9999;
971  int nParBeam = 0;
972  int vertIndex(-1);
973  if (doBeam_) {
974  pdgIdBeamMC_.clear();
975  xBeamMC_.clear();
976  yBeamMC_.clear();
977  zBeamMC_.clear();
978  pxBeamMC_.clear();
979  pyBeamMC_.clear();
980  pzBeamMC_.clear();
981  pBeamMC_.clear();
982  }
983  std::vector<float> verX, verY, verZ;
984  verX.clear();
985  verY.clear();
986  verZ.clear();
987  for (const auto& simVtxItr : *SimVtx) {
988  verX.push_back(simVtxItr.position().X());
989  verY.push_back(simVtxItr.position().Y());
990  verZ.push_back(simVtxItr.position().Z());
991  }
992 #ifdef EDM_ML_DEBUG
993  edm::LogVerbatim("HGCSim") << "Size of track " << SimTk->size();
994 #endif
995  HepMC::FourVector pxyz(0, 0, 0, 0);
996  for (const auto& simTrkItr : *SimTk) {
997  if (addP_ && !(simTrkItr.noGenpart())) {
998  pxyz.setPx(pxyz.px() + simTrkItr.momentum().px());
999  pxyz.setPy(pxyz.py() + simTrkItr.momentum().py());
1000  pxyz.setPz(pxyz.pz() + simTrkItr.momentum().pz());
1001  pxyz.setE(pxyz.e() + simTrkItr.momentum().e());
1002 #ifdef EDM_ML_DEBUG
1003  edm::LogVerbatim("HGCSim") << "Track " << simTrkItr.trackId() << " Vertex " << simTrkItr.vertIndex() << " Type "
1004  << simTrkItr.type() << " Charge " << simTrkItr.charge() << " px "
1005  << simTrkItr.momentum().px() << " py " << simTrkItr.momentum().py() << " pz "
1006  << simTrkItr.momentum().pz() << " P " << simTrkItr.momentum().P() << " GenIndex "
1007  << simTrkItr.genpartIndex();
1008  edm::LogVerbatim("HGCSim") << "Vertex " << simTrkItr.vertIndex()
1009  << " position-> X: " << verX[simTrkItr.vertIndex()]
1010  << " Y: " << verY[simTrkItr.vertIndex()] << " Z: " << verZ[simTrkItr.vertIndex()];
1011 #endif
1012  }
1013  if (doBeam_ && !(simTrkItr.noGenpart())) {
1014  nParBeam++;
1015  pdgIdBeamMC_.push_back(simTrkItr.type());
1016  xBeamMC_.push_back(verX[simTrkItr.vertIndex()]);
1017  yBeamMC_.push_back(verY[simTrkItr.vertIndex()]);
1018  zBeamMC_.push_back(verZ[simTrkItr.vertIndex()]);
1019  pxBeamMC_.push_back(simTrkItr.momentum().px());
1020  pyBeamMC_.push_back(simTrkItr.momentum().py());
1021  pzBeamMC_.push_back(simTrkItr.momentum().pz());
1022  pBeamMC_.push_back(simTrkItr.momentum().P());
1023  } else if (!addP_ && (vertIndex == -1)) {
1024  pxyz = simTrkItr.momentum();
1025  }
1026  if (vertIndex == -1)
1027  vertIndex = simTrkItr.vertIndex();
1028  }
1029  nBeamMC_ = nParBeam;
1030  pBeam_ = pxyz.rho();
1031  thetaBeam_ = pxyz.theta();
1032  phiBeam_ = pxyz.phi();
1033  if (phiBeam_ < 0)
1034  phiBeam_ += (2 * M_PI);
1035  if (vertIndex != -1 && vertIndex < static_cast<int>(SimVtx->size())) {
1036  edm::SimVertexContainer::const_iterator simVtxItr = SimVtx->begin();
1037  for (int iv = 0; iv < vertIndex; iv++)
1038  simVtxItr++;
1039  edm::LogVerbatim("HGCSim") << "Vertex " << vertIndex << " position " << simVtxItr->position();
1040  xBeam_ = verX[0];
1041  yBeam_ = verY[0];
1042  zBeam_ = verZ[0];
1043  }
1044 }
1045 
1047  for (const auto& v : *hgcPH) {
1048  double energy = v.energy();
1049  std::string name = v.vname();
1050  unsigned int id = v.id();
1051 #ifdef EDM_ML_DEBUG
1052  double time = v.time();
1053  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer::analyzePassiveHits:Energy:"
1054  << "Time:Name:Id : " << energy << ":" << time << ":" << name << ":" << id;
1055 #endif
1056 
1057  if (subdet == 1) {
1058  hgcPassiveEEEnergy_.push_back(energy);
1059  hgcPassiveEEName_.push_back(name);
1060  hgcPassiveEEID_.push_back(id);
1061  } else if (subdet == 2) {
1062  hgcPassiveFHEnergy_.push_back(energy);
1063  hgcPassiveFHName_.push_back(name);
1064  hgcPassiveFHID_.push_back(id);
1065  } else if (subdet == 3) {
1066  hgcPassiveBHEnergy_.push_back(energy);
1067  hgcPassiveBHName_.push_back(name);
1068  hgcPassiveBHID_.push_back(id);
1069  } else if (subdet == 4) {
1070  hgcPassiveCMSEEnergy_.push_back(energy);
1071  hgcPassiveCMSEName_.push_back(name);
1072  hgcPassiveCMSEID_.push_back(id);
1073  } else if (subdet == 5) {
1074  hgcPassiveBeamEnergy_.push_back(energy);
1075  hgcPassiveBeamName_.push_back(name);
1076  hgcPassiveBeamID_.push_back(id);
1077  }
1078  }
1079 }
1080 
1081 bool HGCalTB23Analyzer::sortTime(const std::pair<double, double>& i, const std::pair<double, double>& j) {
1082  return i.first < j.first;
1083 }
1084 
1085 // define this as a plug-in
edm::Service< TFileService > fs_
size
Write out results.
const edm::EDGetTokenT< edm::HepMCProduct > tok_hepMC_
std::vector< TH1D * > hSimHitLayEn2BH_
double waferZ(int layer, bool reco) const
std::vector< std::string > hgcPassiveEEName_
std::vector< float > simHitCellTimeLastHitFH_
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< PCaloHit > PCaloHitContainer
std::vector< int > pdgIdBeamMC_
int zside() const
get the z-side of the cell (1/-1)
Definition: AHCalDetId.h:32
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
int icol() const
get the column number
Definition: AHCalDetId.cc:36
std::vector< uint32_t > simHitCellIdFH_
const edm::InputTag labelPassiveFH_
std::vector< float > hgcPassiveFHEnergy_
const double zFrontBH_
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsEE_
TProfile * hSimHitLng1_[3]
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsBeam_
std::vector< float > simHitLayEnBeam_
int32_t waferU(const int32_t index)
std::unique_ptr< AHCalGeometry > ahcalGeom_
std::vector< float > hgcPassiveBeamEnergy_
std::vector< float > hgcPassiveCMSEEnergy_
static bool sortTime(const std::pair< double, double > &i, const std::pair< double, double > &j)
uint32_t ID
Definition: Definitions.h:24
std::vector< float > zBeamMC_
std::vector< int > hgcPassiveFHID_
static uint32_t packHexagonIndex(int subdet, int z, int lay, int wafer, int celltyp, int cell)
const HGCalDDDConstants * hgcons_[2]
std::vector< float > pxBeamMC_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< float > simHitLayEn1EE_
const edm::InputTag labelGen_
std::vector< std::string > hgcPassiveCMSEName_
int zside(DetId const &)
void beginJob() override
const std::string labelHitBH_
std::vector< std::string > hgcPassiveFHName_
std::vector< float > simHitLayEn2EE_
std::vector< float > simHitLayEn1BH_
const edm::InputTag labelPassiveEE_
std::vector< int > hgcPassiveCMSEID_
const edm::InputTag labelPassiveBeam_
std::vector< TH1D * > hSimHitLayEnBeam_
~HGCalTB23Analyzer() override=default
U second(std::pair< T, U > const &p)
const edm::InputTag labelPassiveCMSE_
const std::string detectorEE_
std::vector< float > simHitCellEnBH_
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsBH_
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
constexpr int32_t waferV() const
std::vector< float > hgcPassiveBHEnergy_
constexpr void unpack(int32_t &ty, int32_t &zs, int32_t &ly, int32_t &wU, int32_t &wV, int32_t &cU, int32_t &cV) const
std::vector< TH1D * > hSimHitLayEn2FH_
int iEvent
Definition: GenABIO.cc:224
std::vector< float > pBeamMC_
const edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHCMSE_
std::vector< float > hgcPassiveEEEnergy_
std::vector< TH1D * > hSimHitLayEn1BH_
std::vector< uint32_t > simHitCellIdBeam_
void beginRun(edm::Run const &, edm::EventSetup const &) override
const std::string labelHitFH_
const double gev2mip200_
const double gev2mip300_
void analyzeSimTracks(edm::Handle< edm::SimTrackContainer > const &SimTk, edm::Handle< edm::SimVertexContainer > const &SimVtx)
void analyzeSimHits(int type, std::vector< PCaloHit > &hits, double zFront)
const std::string labelHitEE_
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
void analyze(edm::Event const &, edm::EventSetup const &) override
Transition
Definition: Transition.h:12
std::vector< float > simHitLayEn1FH_
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< uint32_t > simHitCellIdEE_
const std::string detectorBH_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HGCalTB23Analyzer(edm::ParameterSet const &)
unsigned int layers(bool reco) const
std::vector< int > hgcPassiveEEID_
std::vector< float > simHitLayEn2BH_
const edm::InputTag labelPassiveBH_
int icolAbs() const
Definition: AHCalDetId.h:38
std::vector< TH1D * > hSimHitLayEn2EE_
std::vector< PassiveHit > PassiveHitContainer
Definition: PassiveHit.h:100
TProfile * hSimHitLng2_[3]
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
std::vector< uint32_t > simHitCellIdBH_
#define M_PI
std::vector< float > simHitLayEn2FH_
std::vector< float > simHitCellEnEE_
const edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHBeam_
std::vector< int > hgcPassiveBeamID_
const edm::EDGetTokenT< edm::SimTrackContainer > tok_simTk_
std::vector< TH1D * > hSimHitLayEn1EE_
std::vector< float > pyBeamMC_
std::vector< int > simHitCellLayerBH_
std::vector< float > simHitCellTime15MipBH_
#define debug
Definition: HDRShower.cc:19
std::vector< float > simHitCellEnFH_
std::vector< float > simHitCellTimeFirstHitBH_
std::vector< float > simHitCellTime15MipEE_
std::vector< float > simHitCellTimeFirstHitEE_
std::vector< int > hgcPassiveBHID_
std::vector< float > simHitCellTime15MipFH_
const edm::EDGetTokenT< edm::SimVertexContainer > tok_simVtx_
double cellThickness(int layer, int waferU, int waferV) const
std::vector< float > simHitCellTimeFirstHitFH_
std::vector< SimVertex > SimVertexContainer
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int irow() const
get the row number
Definition: AHCalDetId.cc:29
constexpr int32_t layer() const
get the layer #
std::vector< int > simHitCellColBH_
const edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHBH_
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
const edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHFH_
bool isValid() const
Definition: HandleBase.h:70
const double stoc_smear_time_200_
std::vector< int > idBeams_
std::vector< float > simHitCellTimeLastHitEE_
HLT enums.
const double zFrontFH_
const std::string detectorBeam_
int32_t waferV(const int32_t index)
void analyzePassiveHits(edm::Handle< edm::PassiveHitContainer > const &hgcPh, int subdet)
col
Definition: cuy.py:1009
std::vector< std::string > hgcPassiveBeamName_
std::vector< float > simHitCellTimeLastHitBH_
int irowAbs() const
Definition: AHCalDetId.h:35
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< float > simHitCellEnBeam_
TProfile * hSimHitLng_[3]
static void unpackIndex(const uint32_t &idx, int &det, int &lay, int &x, int &y)
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > tokDDDFH_
Log< level::Warning, false > LogWarning
const edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHEE_
constexpr int32_t waferU() const
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsFH_
std::vector< float > yBeamMC_
const double zFrontEE_
std::vector< std::string > hgcPassiveBHName_
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > tokDDDEE_
const std::string detectorFH_
std::vector< SimTrack > SimTrackContainer
std::vector< float > xBeamMC_
std::vector< int > simHitCellRowBH_
const std::string labelHitBeam_
int depth() const
get the layer number
Definition: AHCalDetId.cc:43
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
TProfile2D * hSimHitLat_[3]
Definition: Run.h:45
const double stoc_smear_time_300_
std::vector< TH1D * > hSimHitLayEn1FH_
std::vector< float > pzBeamMC_