CMS 3D CMS Logo

HGCalTBMBAnalyzer.cc
Go to the documentation of this file.
12 
14 
15 #include <TH1F.h>
16 
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 
21 //#define EDM_ML_DEBUG
22 
23 class HGCalTBMBAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
24 public:
26  ~HGCalTBMBAnalyzer() override = default;
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
29 
30 private:
31  void analyze(edm::Event const &, edm::EventSetup const &) override;
32 
33  const std::vector<std::string> listNames_;
35  const unsigned int nList_;
37  std::vector<TH1D *> me100_, me200_, me300_;
38 };
39 
41  : listNames_(p.getParameter<std::vector<std::string>>("detectorNames")),
42  labelMBCalo_(p.getParameter<edm::InputTag>("labelMBCalo")),
43  nList_(listNames_.size()),
44  tokMBCalo_(consumes<MaterialAccountingCaloCollection>(labelMBCalo_)) {
45  edm::LogVerbatim("HGCSim") << "HGCalTBMBAnalyzer initialized for " << nList_ << " volumes";
46  for (unsigned int k = 0; k < nList_; ++k)
47  edm::LogVerbatim("HGCSim") << " [" << k << "] " << listNames_[k];
48 
50  if (!tfile.isAvailable())
51  throw cms::Exception("BadConfig") << "TFileService unavailable: "
52  << "please add it to config file";
53  char name[20], title[80];
54  TH1D *hist;
55  for (unsigned int i = 0; i <= nList_; i++) {
56  std::string named = (i == nList_) ? "Total" : listNames_[i];
57  sprintf(name, "RadL%d", i);
58  sprintf(title, "MB(X0) for (%s)", named.c_str());
59  hist = tfile->make<TH1D>(name, title, 100000, 0.0, 100.0);
60  hist->Sumw2(true);
61  me100_.push_back(hist);
62  sprintf(name, "IntL%d", i);
63  sprintf(title, "MB(L0) for (%s)", named.c_str());
64  hist = tfile->make<TH1D>(name, title, 100000, 0.0, 10.0);
65  hist->Sumw2(true);
66  me200_.push_back(hist);
67  sprintf(name, "StepL%d", i);
68  sprintf(title, "MB(Step) for (%s)", named.c_str());
69  hist = tfile->make<TH1D>(name, title, 100000, 0.0, 50000.0);
70  hist->Sumw2(true);
71  me300_.push_back(hist);
72  }
73  edm::LogVerbatim("HGCSim") << "HGCalTBMBAnalyzer: Booking user histos done ===";
74 }
75 
78  std::vector<std::string> names = {"HGCalBeamWChamb",
79  "HGCalBeamS1",
80  "HGCalBeamS2",
81  "HGCalBeamS3",
82  "HGCalBeamS4",
83  "HGCalBeamS5",
84  "HGCalBeamS6",
85  "HGCalBeamCK3",
86  "HGCalBeamHaloCounter",
87  "HGCalBeamMuonCounter",
88  "HGCalEE",
89  "HGCalHE",
90  "HGCalAH"};
91  desc.add<std::vector<std::string>>("detectorNames", names);
92  desc.add<edm::InputTag>("labelMBCalo", edm::InputTag("g4SimHits", "HGCalTBMB"));
93  descriptions.add("hgcalTBMBAnalyzer", desc);
94 }
95 
97 #ifdef EDM_ML_DEBUG
98  edm::LogVerbatim("HGCSim") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
99  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing();
100 #endif
101 
102  // Fill from the MB collection
103  auto const &hgcalMBColl = iEvent.getHandle(tokMBCalo_);
104  if (hgcalMBColl.isValid()) {
105  auto hgcalMB = hgcalMBColl.product();
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("HGCSim") << "Finds MaterialBudegetCollection with " << hgcalMB->size() << " entries";
108 #endif
109 
110  for (auto itr = hgcalMB->begin(); itr != hgcalMB->end(); ++itr) {
111  for (uint32_t ii = 0; ii < itr->m_stepLen.size(); ++ii) {
112 #ifdef EDM_ML_DEBUG
113  edm::LogVerbatim("HGCSim") << "HGCalTBMBAnalyzer:index " << ii << " integrated step " << itr->m_stepLen[ii]
114  << " X0 " << itr->m_radLen[ii] << " Lamda " << itr->m_intLen[ii];
115 #endif
116  if (ii < nList_) {
117  me100_[ii]->Fill(itr->m_radLen[ii]);
118  me200_[ii]->Fill(itr->m_intLen[ii]);
119  me300_[ii]->Fill(itr->m_stepLen[ii]);
120  }
121  }
122  }
123  }
124 }
125 
size
Write out results.
Log< level::Info, true > LogVerbatim
const std::vector< std::string > listNames_
const unsigned int nList_
~HGCalTBMBAnalyzer() override=default
void analyze(edm::Event const &, edm::EventSetup const &) override
std::vector< MaterialAccountingCalo > MaterialAccountingCaloCollection
const edm::EDGetTokenT< MaterialAccountingCaloCollection > tokMBCalo_
HGCalTBMBAnalyzer(const edm::ParameterSet &)
const edm::InputTag labelMBCalo_
const std::string names[nVars_]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
Definition: tfile.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TH1D * > me300_
ii
Definition: cuy.py:589
__shared__ Hist hist
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
std::vector< TH1D * > me200_
std::vector< TH1D * > me100_