CMS 3D CMS Logo

HGCalBHValidation.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 #include <map>
6 #include <string>
7 
8 // user include files
11 
20 
24 
25 // Root objects
26 #include "TROOT.h"
27 #include "TSystem.h"
28 #include "TFile.h"
29 #include "TH1.h"
30 #include "TH2.h"
31 
32 class HGCalBHValidation : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
33 public:
34  explicit HGCalBHValidation(const edm::ParameterSet& ps);
35  ~HGCalBHValidation() override {}
36 
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39 protected:
40  void beginJob() override {}
41  void beginRun(edm::Run const&, edm::EventSetup const&) override;
42  void endRun(edm::Run const&, edm::EventSetup const&) override {}
43  void analyze(edm::Event const&, edm::EventSetup const&) override;
44  template <class T>
45  void analyzeDigi(const T&, double const&, bool const&, int const&, unsigned int&);
46 
47 private:
51  const int iSample_;
52  const double threshold_;
55  const int etaMax_;
56 
57  TH1D *hsimE1_, *hsimE2_, *hsimTm_;
58  TH1D *hsimLn_, *hdigEn_, *hdigLn_;
59  TH2D *hsimOc_, *hsi2Oc_, *hsi3Oc_;
60  TH2D *hdigOc_, *hdi2Oc_, *hdi3Oc_;
61 };
62 
64  : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
65  hits_((ps.getParameter<std::string>("HitCollection"))),
66  digis_(ps.getParameter<edm::InputTag>("DigiCollection")),
67  iSample_(ps.getParameter<int>("Sample")),
68  threshold_(ps.getParameter<double>("Threshold")),
69  tok_hits_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hits_))),
70  tok_digi_(consumes<HGCalDigiCollection>(digis_)),
71  etaMax_(100) {
72  usesResource(TFileService::kSharedResource);
73 
74  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation::Input for SimHit:" << edm::InputTag(g4Label_, hits_)
75  << " Digits:" << digis_ << " Sample: " << iSample_ << " Threshold "
76  << threshold_;
77 }
78 
81  desc.add<std::string>("ModuleLabel", "g4SimHits");
82  desc.add<std::string>("HitCollection", "HGCHitsHEback");
83  desc.add<edm::InputTag>("DigiCollection", edm::InputTag("simHGCalUnsuppressedDigis", "HEback"));
84  desc.add<int>("Sample", 5);
85  desc.add<double>("Threshold", 15.0);
86  descriptions.add("hgcalBHAnalysis", desc);
87 }
88 
90  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation::Maximum Number of"
91  << " eta sectors:" << etaMax_ << "\nHitsValidationHcal::Booking the Histograms";
92 
93  //Histograms for Sim Hits
94  hsimE1_ = fs_->make<TH1D>("SimHitEn1", "Sim Hit Energy", 1000, 0.0, 1.0);
95  hsimE2_ = fs_->make<TH1D>("SimHitEn2", "Sim Hit Energy", 1000, 0.0, 1.0);
96  hsimTm_ = fs_->make<TH1D>("SimHitTime", "Sim Hit Time", 1000, 0.0, 500.0);
97  hsimLn_ = fs_->make<TH1D>("SimHitLong", "Sim Hit Long. Profile", 50, 0.0, 25.0);
98  hsimOc_ = fs_->make<TH2D>("SimHitOccup", "Sim Hit Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
99  hsi2Oc_ = fs_->make<TH2D>("SimHitOccu2", "Sim Hit Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
100  hsi3Oc_ = fs_->make<TH2D>("SimHitOccu3", "Sim Hit Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 50, 0, 25);
101  //Histograms for Digis
102  hdigEn_ = fs_->make<TH1D>("DigiEnergy", "Digi ADC Sample", 1000, 0.0, 1000.0);
103  hdigLn_ = fs_->make<TH1D>("DigiLong", "Digi Long. Profile", 50, 0.0, 25.0);
104  hdigOc_ = fs_->make<TH2D>("DigiOccup", "Digi Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
105  hdi2Oc_ = fs_->make<TH2D>("DigiOccu2", "Digi Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
106  hdi3Oc_ = fs_->make<TH2D>("DigiOccu3", "Digi Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 50, 0, 25);
107 }
108 
110  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation:Run = " << e.id().run() << " Event = " << e.id().event();
111 
112  //SimHits
114  e.getByToken(tok_hits_, hitsHE);
115  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: PCaloHitContainer"
116  << " obtained with flag " << hitsHE.isValid();
117  if (hitsHE.isValid()) {
118  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: PCaloHit buffer " << hitsHE->size();
119  unsigned i(0);
120  std::map<unsigned int, double> map_try;
121  for (edm::PCaloHitContainer::const_iterator it = hitsHE->begin(); it != hitsHE->end(); ++it) {
122  double energy = it->energy();
123  double time = it->time();
124  unsigned int id = it->id();
125  int eta(0), phi(0), lay(0);
126  bool bh = (DetId(id).det() == DetId::HGCalHSc);
127  if (bh) {
128  eta = HGCScintillatorDetId(id).ieta();
129  phi = HGCScintillatorDetId(id).iphi();
130  lay = HGCScintillatorDetId(id).layer();
131  }
132  double eta1 = (eta >= 0) ? (eta + 0.1) : (eta - 0.1);
133  if (bh) {
134  hsi2Oc_->Fill(eta1, (phi - 0.1), energy);
135  hsimE1_->Fill(energy);
136  hsimTm_->Fill(time, energy);
137  hsimOc_->Fill(eta1, (phi - 0.1), energy);
138  hsimLn_->Fill(lay, energy);
139  hsi3Oc_->Fill(eta1, lay, energy);
140  double ensum(0);
141  if (map_try.count(id) != 0)
142  ensum = map_try[id];
143  ensum += energy;
144  map_try[id] = ensum;
145  ++i;
146  edm::LogVerbatim("HGCalValidation") << "HGCalBHHit[" << i << "] ID " << std::hex << " " << id << std::dec << " "
147  << HGCScintillatorDetId(id) << " E " << energy << " time " << time;
148  }
149  }
150  for (std::map<unsigned int, double>::iterator itr = map_try.begin(); itr != map_try.end(); ++itr) {
151  hsimE2_->Fill((*itr).second);
152  }
153  }
154 
155  //Digits
156  unsigned int kount(0);
158  e.getByToken(tok_digi_, hecoll);
159  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: "
160  << "HGCalDigiCollection obtained with"
161  << " flag " << hecoll.isValid();
162  if (hecoll.isValid()) {
163  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: HGCalDigi "
164  << "buffer " << hecoll->size();
165  for (HGCalDigiCollection::const_iterator it = hecoll->begin(); it != hecoll->end(); ++it) {
166  HGCalDataFrame df(*it);
167  double energy = df[iSample_].data();
168  bool bh = (DetId(df.id()).det() == DetId::HGCalHSc);
169  if (bh) {
170  HGCScintillatorDetId cell(df.id());
171  int depth = cell.layer();
172  analyzeDigi(cell, energy, bh, depth, kount);
173  }
174  }
175  }
176 }
177 
178 template <class T>
180  const T& cell, double const& energy, bool const& bh, int const& depth, unsigned int& kount) {
181  if (energy > threshold_) {
182  int eta = cell.ieta();
183  int phi = cell.iphi();
184  double eta1 = (eta >= 0) ? (eta + 0.1) : (eta - 0.1);
185  hdi2Oc_->Fill(eta1, (phi - 0.1));
186  if (bh) {
187  hdigEn_->Fill(energy);
188  hdigOc_->Fill(eta1, (phi - 0.1));
189  hdigLn_->Fill(depth);
190  hdi3Oc_->Fill(eta1, depth);
191  ++kount;
192  edm::LogVerbatim("HGCalValidation")
193  << "HGCalBHDigit[" << kount << "] ID " << cell << " E " << energy << ":" << (energy > threshold_);
194  }
195  }
196 }
197 
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
std::vector< PCaloHit > PCaloHitContainer
const std::string hits_
~HGCalBHValidation() override
size_type size() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
const edm::InputTag digis_
std::vector< T >::const_iterator const_iterator
const edm::EDGetToken tok_digi_
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string g4Label_
int iphi() const
get the phi index
edm::Service< TFileService > fs_
HGCalBHValidation(const edm::ParameterSet &ps)
int layer() const
get the layer #
const_iterator begin() const
void beginRun(edm::Run const &, edm::EventSetup const &) override
const double threshold_
const_iterator end() const
Definition: DetId.h:17
void analyze(edm::Event const &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void beginJob() override
Readout digi for HGC.
Definition: HGCDataFrame.h:14
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
long double T
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45
void analyzeDigi(const T &, double const &, bool const &, int const &, unsigned int &)