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, 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 {
672  depth = hgcons_[type]->simToReco(cell, layer, sector, true).second;
673  idx = sector * 1000 + cell;
674 #ifdef EDM_ML_DEBUG
675  std::pair<float, float> xy = hgcons_[type]->locateCell(cell, layer, sector, false);
676  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer::detId " << std::hex << id << std::dec << " Layer:Wafer:Cell "
677  << layer << ":" << sector << ":" << cell << " Position " << xy.first << ":"
678  << xy.second << ":" << hgcons_[type]->waferZ(layer, false);
679 #endif
680  }
681 #ifdef EDM_ML_DEBUG
682  edm::LogVerbatim("HGCSim") << "SimHit:Hit[" << i << "] Id " << subdet << ":" << zside << ":" << layer << ":"
683  << sector << ":" << subsector << ":" << cell << ":" << depth << " Energy " << energy
684  << " Time " << time;
685 #endif
686  if (map_hits.count(id) != 0) {
687  map_hits[id] += energy;
688  } else {
689  map_hits[id] = energy;
690  }
691  if (map_hitLayer.count(layer) != 0) {
692  double ee = energy + map_hitLayer[layer].second;
693  map_hitLayer[layer] = std::make_pair(id, ee);
694  } else {
695  map_hitLayer[layer] = std::make_pair(id, energy);
696  }
697  if (map_hitWafer.count(sector) != 0)
698  map_hitWafer[sector] += energy;
699  else
700  map_hitWafer[sector] = energy;
701  if (depth >= 0) {
702  if (map_hitCell.count(idx) != 0) {
703  double ee = energy + map_hitCell[idx].second;
704  map_hitCell[idx] = std::make_pair(id, ee);
705  } else {
706  map_hitCell[idx] = std::make_pair(id, energy);
707  }
708  if (debug) {
709  if (type == 1)
710  edm::LogVerbatim("HGCSim") << "EE, depth is and map_hitDepth[depth] " << depth << " " << map_hitDepth[depth];
711  if (type == 2)
712  edm::LogVerbatim("HGCSim") << "BH, depth is and map_hitDepth[depth] " << depth << " " << map_hitDepth[depth];
713  }
714  if (map_hitDepth.count(depth) != 0) {
715  map_hitDepth[depth] += energy;
716  } else {
717  map_hitDepth[depth] = energy;
718  }
719  uint32_t idn =
720  (type >= 2) ? id : HGCalTestNumbering::packHexagonIndex(subdet, zside, depth, sector, subsector, cell);
721  map_hitTimeEn[idn].push_back(std::make_pair(time, energy));
722  GeV2Mip[idn] = gev2mip300_;
723  StochTermTime[idn] = stoc_smear_time_300_;
724  ID[idn] = id;
725  Depth[idn] = depth;
726  if (map_hitn.count(idn) != 0) {
727  map_hitn[idn] += energy;
728  ++nhits[idn];
729  } else {
730  map_hitn[idn] = energy;
731  nhits[idn] = 1;
732  }
733  }
734  hSimHitT_[type]->Fill(time, energy);
735  }
736 
737  if (type < 2) { //store only for EE and FH
738  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer:: " << map_hitWafer.size() << " wafers are hit in type " << type;
739  for (auto itr = map_hitWafer.begin(); itr != map_hitWafer.end(); ++itr)
740  edm::LogVerbatim("HGCSim") << "Wafer: " << itr->first << " Deposited Energy " << itr->second;
742  for (const auto& itr : map_hitTimeEn) {
743  uint32_t id = itr.first;
744  int waferU(-99), waferV(-99);
746  waferU = HGCSiliconDetId(ID[id]).waferU();
747  waferV = HGCSiliconDetId(ID[id]).waferV();
748  double layer = HGCSiliconDetId(id).layer();
750  if (debug)
751  edm::LogVerbatim("HGCSim") << "wafer is : depth (reco) " << waferU << ":" << waferV << " " << Depth[id]
752  << "\ntype : layer : wafer thickness " << type << " " << layer << " " << thickness
753  << "\nID(sim) and id(reco) " << std::hex << ID[id] << " " << id << std::dec;
754  if (thickness == 300) {
755  GeV2Mip[id] = gev2mip300_;
756  StochTermTime[id] = stoc_smear_time_300_;
757  } else if (thickness == 200) {
758  GeV2Mip[id] = gev2mip200_;
759  StochTermTime[id] = stoc_smear_time_200_;
760  }
761  //first sort
762  std::sort(map_hitTimeEn[id].begin(), map_hitTimeEn[id].end(), sortTime);
764  double threshold = 15.;
765  double totE = 0.;
766  double totEbeforeThreshold = 0.;
767  double timebeforeThreshold = 0.;
768  double timeAtThresohld = 0.;
769  for (unsigned int ihit = 0; ihit < map_hitTimeEn[id].size(); ihit++) {
770  double energy = (map_hitTimeEn[id].at(ihit)).second / GeV2Mip[id];
771  totE += energy;
772  double time = (map_hitTimeEn[id].at(ihit)).first;
773  if (debug)
774  edm::LogVerbatim("HGCSim") << "Tot E till now : time of that E : GeV2Mip[id] is " << totE << " " << time
775  << " " << GeV2Mip[id];
776  if (totE < threshold) {
777  totEbeforeThreshold = totE;
778  timebeforeThreshold = time;
779  } else {
780  timeAtThresohld =
781  (threshold - totEbeforeThreshold) * (time - timebeforeThreshold) / (totE - totEbeforeThreshold) +
782  timebeforeThreshold;
783  map_hittime_15Mip[id] = timeAtThresohld;
784  if (debug)
785  edm::LogVerbatim("HGCSim") << "ihit : energyBefore : timeBefore : energyTot : timeTot : timeAt15MIP "
786  << ihit << " " << totEbeforeThreshold << " " << timebeforeThreshold << " "
787  << totE << " " << time << " " << map_hittime_15Mip[id];
788  break;
789  }
790  }
791  if (!map_hitTimeEn[id].empty()) {
792  map_hittime_firsthit[id] = (map_hitTimeEn[id].at(0)).first;
793  map_hittime_lasthit[id] = (map_hitTimeEn[id].at(map_hitTimeEn[id].size() - 1)).first;
794  if (map_hittime_15Mip[id] < map_hittime_firsthit[id])
795  map_hittime_15Mip[id] = map_hittime_firsthit[id];
796  /*
798  double firsthit_sm = ran3.Gaus(map_hittime_firsthit_vtxCorr[id], StochTermTime[id]);
799  double lasthit_sm = ran3.Gaus(map_hittime_lasthit_vtxCorr[id], StochTermTime[id]);
800  double threshmiphit_sm = ran3.Gaus(map_hittime_15Mip_vtxCorr[id], StochTermTime[id]);
801  */
802  }
803 
804  if (totE < threshold)
805  map_hittime_15Mip[id] = -99;
806  if (debug)
807  edm::LogVerbatim("HGCSim") << "id : first hit time : last hit time " << id << " " << map_hittime_firsthit[id]
808  << " " << map_hittime_lasthit[id] << "\nFinally for this cell, time is "
809  << map_hittime_15Mip[id];
810  }
811  }
812 
813  hSimHitEn_[type]->Fill(entot);
814  for (const auto& itr : map_hits) {
815  hSimHitE_[type]->Fill(itr.second);
816  }
817 
818  if (debug)
819  edm::LogVerbatim("HGCSim") << "Now looping over map_hitLayer";
820  for (const auto& itr : map_hitLayer) {
821  int layer = (type == 2) ? itr.first : (itr.first - 1);
822  double energy = (itr.second).second;
823  double zp(0);
824  if (type < 2)
825  zp = hgcons_[type]->waferZ(layer + 1, false);
826  else if (type == 2)
827  zp = ahcalGeom_->getZ(AHCalDetId((itr.second).first));
828 #ifdef EDM_ML_DEBUG
829  edm::LogVerbatim("HGCSim") << "SimHit:Layer " << layer + 1 << " Z " << zp << ":" << zp - zFront << " E " << energy;
830 #endif
831  if (type < 3) {
832  hSimHitLng_[type]->Fill(zp - zFront, energy);
833  hSimHitLng2_[type]->Fill(layer + 1, energy);
834  }
835  if (type == 0) {
836  if (layer < static_cast<int>(hSimHitLayEn1EE_.size())) {
838  hSimHitLayEn1EE_[layer]->Fill(energy);
839  }
840  } else if (type == 1) {
841  if (layer < static_cast<int>(hSimHitLayEn1FH_.size())) {
843  hSimHitLayEn1FH_[layer]->Fill(energy);
844  }
845  } else if (type == 2) {
846  if (debug)
847  edm::LogVerbatim("HGCSim") << "layer < hSimHitLayEn1BH_.size()";
848  if (layer < static_cast<int>(hSimHitLayEn1BH_.size())) {
850  hSimHitLayEn1BH_[layer]->Fill(energy);
851  }
852  } else {
853  for (unsigned int k = 0; k < idBeams_.size(); ++k) {
854  if (layer + 1 == idBeams_[k]) {
856  hSimHitLayEnBeam_[k]->Fill(energy);
857  break;
858  }
859  }
860  }
861  }
862  for (const auto& itr : map_hitDepth) {
863  int layer = (type == 2) ? itr.first : (itr.first - 1);
864  double energy = itr.second;
865 #ifdef EDM_ML_DEBUG
866  edm::LogVerbatim("HGCSim") << "SimHit:Layer " << layer + 1 << " " << energy;
867 #endif
868  hSimHitLng1_[type]->Fill(layer + 1, energy);
869  if (type == 0) {
870  if (layer < static_cast<int>(hSimHitLayEn2EE_.size())) {
872  hSimHitLayEn2EE_[layer]->Fill(energy);
873  }
874  } else if (type == 1) {
875  if (layer < static_cast<int>(hSimHitLayEn2FH_.size())) {
877  hSimHitLayEn2FH_[layer]->Fill(energy);
878  }
879  } else if (type == 2) {
880  if (debug)
881  edm::LogVerbatim("HGCSim") << "Inside map_hitDepth, layer no. " << layer;
882  if (layer < static_cast<int>(hSimHitLayEn2BH_.size())) {
884  hSimHitLayEn2BH_[layer]->Fill(energy);
885  }
886  }
887  }
888 
889  if (debug)
890  edm::LogVerbatim("HGCSim") << "Now looping over map_hitCell";
891  if (type < 3) {
892  for (const auto& itr : map_hitCell) {
893  uint32_t id = ((itr.second).first);
894  double energy = ((itr.second).second);
895  std::pair<float, float> xy(0, 0);
896  double xx(0);
897  if (type == 2) {
898  xy = ahcalGeom_->getXY(AHCalDetId(id));
899  xx = xy.first;
900  } else {
901  int subdet, zside, layer, sector, subsector, cell;
903  xy = hgcons_[type]->locateCell(cell, layer, sector, false);
904  double zp = hgcons_[type]->waferZ(layer, false);
905  xx = (zp < 0) ? -xy.first : xy.first;
906  }
907  hSimHitLat_[type]->Fill(xx, xy.second, energy);
908  }
909  }
910 
911  for (const auto& itr : map_hitn) {
912  uint32_t id = itr.first;
913  double energy = itr.second;
914  if (type == 0) {
915  double time_firsthit = map_hittime_firsthit[id];
916  double time15Mip = map_hittime_15Mip[id];
917  double time_lasthit = map_hittime_lasthit[id];
918  simHitCellIdEE_.push_back(id);
919  simHitCellEnEE_.push_back(energy);
920  simHitCellTimeFirstHitEE_.push_back(time_firsthit);
921  simHitCellTime15MipEE_.push_back(time15Mip);
922  simHitCellTimeLastHitEE_.push_back(time_lasthit);
923  if (debug && (energy / GeV2Mip[id] < 15) && (map_hittime_15Mip[id] > 0))
924  edm::LogVerbatim("HGCSim") << "FOUND!!!!rechit energy : Finally for this cell, time is " << energy / GeV2Mip[id]
925  << " " << map_hittime_15Mip[id];
926  } else if (type == 1) {
927  double time_firsthit = map_hittime_firsthit[id];
928  double time15Mip = map_hittime_15Mip[id];
929  double time_lasthit = map_hittime_lasthit[id];
930  simHitCellIdFH_.push_back(id);
931  simHitCellEnFH_.push_back(energy);
932  simHitCellTimeFirstHitFH_.push_back(time_firsthit);
933  simHitCellTime15MipFH_.push_back(time15Mip);
934  simHitCellTimeLastHitFH_.push_back(time_lasthit);
935  } else if (type == 2) {
936  simHitCellIdBH_.push_back(id);
937  simHitCellEnBH_.push_back(energy);
938  AHCalDetId hid(id);
939  int row = hid.irow();
940  int col = hid.icol();
941  int layer = hid.depth();
942  simHitCellColBH_.push_back(col);
943  simHitCellRowBH_.push_back(row);
944  simHitCellLayerBH_.push_back(layer);
945 #ifdef EDM_ML_DEBUG
946  edm::LogVerbatim("HGCSim") << "ID: " << std::hex << id << std::dec << " Layer: " << layer << " col: " << col
947  << " row: " << row;
948 #endif
949  } else if (type == 3) {
950  simHitCellIdBeam_.push_back(id);
951  simHitCellEnBeam_.push_back(energy);
952  }
953  }
954 }
955 
957  edm::Handle<edm::SimVertexContainer> const& SimVtx) {
958  xBeam_ = yBeam_ = zBeam_ = pBeam_ = -9999;
959  nBeamMC_ = thetaBeam_ = phiBeam_ = -9999;
960  int nParBeam = 0;
961  int vertIndex(-1);
962  if (doBeam_) {
963  pdgIdBeamMC_.clear();
964  xBeamMC_.clear();
965  yBeamMC_.clear();
966  zBeamMC_.clear();
967  pxBeamMC_.clear();
968  pyBeamMC_.clear();
969  pzBeamMC_.clear();
970  pBeamMC_.clear();
971  }
972  std::vector<float> verX, verY, verZ;
973  verX.clear();
974  verY.clear();
975  verZ.clear();
976  for (const auto& simVtxItr : *SimVtx) {
977  verX.push_back(simVtxItr.position().X());
978  verY.push_back(simVtxItr.position().Y());
979  verZ.push_back(simVtxItr.position().Z());
980  }
981 #ifdef EDM_ML_DEBUG
982  edm::LogVerbatim("HGCSim") << "Size of track " << SimTk->size();
983 #endif
984  HepMC::FourVector pxyz(0, 0, 0, 0);
985  for (const auto& simTrkItr : *SimTk) {
986  if (addP_ && !(simTrkItr.noGenpart())) {
987  pxyz.setPx(pxyz.px() + simTrkItr.momentum().px());
988  pxyz.setPy(pxyz.py() + simTrkItr.momentum().py());
989  pxyz.setPz(pxyz.pz() + simTrkItr.momentum().pz());
990  pxyz.setE(pxyz.e() + simTrkItr.momentum().e());
991 #ifdef EDM_ML_DEBUG
992  edm::LogVerbatim("HGCSim") << "Track " << simTrkItr.trackId() << " Vertex " << simTrkItr.vertIndex() << " Type "
993  << simTrkItr.type() << " Charge " << simTrkItr.charge() << " px "
994  << simTrkItr.momentum().px() << " py " << simTrkItr.momentum().py() << " pz "
995  << simTrkItr.momentum().pz() << " P " << simTrkItr.momentum().P() << " GenIndex "
996  << simTrkItr.genpartIndex();
997  edm::LogVerbatim("HGCSim") << "Vertex " << simTrkItr.vertIndex()
998  << " position-> X: " << verX[simTrkItr.vertIndex()]
999  << " Y: " << verY[simTrkItr.vertIndex()] << " Z: " << verZ[simTrkItr.vertIndex()];
1000 #endif
1001  }
1002  if (doBeam_ && !(simTrkItr.noGenpart())) {
1003  nParBeam++;
1004  pdgIdBeamMC_.push_back(simTrkItr.type());
1005  xBeamMC_.push_back(verX[simTrkItr.vertIndex()]);
1006  yBeamMC_.push_back(verY[simTrkItr.vertIndex()]);
1007  zBeamMC_.push_back(verZ[simTrkItr.vertIndex()]);
1008  pxBeamMC_.push_back(simTrkItr.momentum().px());
1009  pyBeamMC_.push_back(simTrkItr.momentum().py());
1010  pzBeamMC_.push_back(simTrkItr.momentum().pz());
1011  pBeamMC_.push_back(simTrkItr.momentum().P());
1012  } else if (!addP_ && (vertIndex == -1)) {
1013  pxyz = simTrkItr.momentum();
1014  }
1015  if (vertIndex == -1)
1016  vertIndex = simTrkItr.vertIndex();
1017  }
1018  nBeamMC_ = nParBeam;
1019  pBeam_ = pxyz.rho();
1020  thetaBeam_ = pxyz.theta();
1021  phiBeam_ = pxyz.phi();
1022  if (phiBeam_ < 0)
1023  phiBeam_ += (2 * M_PI);
1024  if (vertIndex != -1 && vertIndex < static_cast<int>(SimVtx->size())) {
1025  edm::SimVertexContainer::const_iterator simVtxItr = SimVtx->begin();
1026  for (int iv = 0; iv < vertIndex; iv++)
1027  simVtxItr++;
1028  edm::LogVerbatim("HGCSim") << "Vertex " << vertIndex << " position " << simVtxItr->position();
1029  xBeam_ = verX[0];
1030  yBeam_ = verY[0];
1031  zBeam_ = verZ[0];
1032  }
1033 }
1034 
1036  for (const auto& v : *hgcPH) {
1037  double energy = v.energy();
1038  std::string name = v.vname();
1039  unsigned int id = v.id();
1040 #ifdef EDM_ML_DEBUG
1041  double time = v.time();
1042  edm::LogVerbatim("HGCSim") << "HGCalTB23Analyzer::analyzePassiveHits:Energy:"
1043  << "Time:Name:Id : " << energy << ":" << time << ":" << name << ":" << id;
1044 #endif
1045 
1046  if (subdet == 1) {
1047  hgcPassiveEEEnergy_.push_back(energy);
1048  hgcPassiveEEName_.push_back(name);
1049  hgcPassiveEEID_.push_back(id);
1050  } else if (subdet == 2) {
1051  hgcPassiveFHEnergy_.push_back(energy);
1052  hgcPassiveFHName_.push_back(name);
1053  hgcPassiveFHID_.push_back(id);
1054  } else if (subdet == 3) {
1055  hgcPassiveBHEnergy_.push_back(energy);
1056  hgcPassiveBHName_.push_back(name);
1057  hgcPassiveBHID_.push_back(id);
1058  } else if (subdet == 4) {
1059  hgcPassiveCMSEEnergy_.push_back(energy);
1060  hgcPassiveCMSEName_.push_back(name);
1061  hgcPassiveCMSEID_.push_back(id);
1062  } else if (subdet == 5) {
1063  hgcPassiveBeamEnergy_.push_back(energy);
1064  hgcPassiveBeamName_.push_back(name);
1065  hgcPassiveBeamID_.push_back(id);
1066  }
1067  }
1068 }
1069 
1070 bool HGCalTB23Analyzer::sortTime(const std::pair<double, double>& i, const std::pair<double, double>& j) {
1071  return i.first < j.first;
1072 }
1073 
1074 // 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_
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_