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 = default;
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 
45 private:
49  const int iSample_;
50  const double threshold_;
53  const int ringMax_;
54 
55  TH1D *hsimE1_, *hsimE2_, *hsimTm_;
56  TH1D *hsimLn_, *hdigEn_, *hdigLn_;
57  TH2D *hsimOc_, *hsi2Oc_, *hsi3Oc_;
58  TH2D *hdigOc_, *hdi2Oc_, *hdi3Oc_;
59 };
60 
62  : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
63  hits_((ps.getParameter<std::string>("HitCollection"))),
64  digis_(ps.getParameter<edm::InputTag>("DigiCollection")),
65  iSample_(ps.getParameter<int>("Sample")),
66  threshold_(ps.getParameter<double>("Threshold")),
67  tok_hits_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hits_))),
68  tok_digi_(consumes<HGCalDigiCollection>(digis_)),
69  ringMax_(50) {
70  usesResource(TFileService::kSharedResource);
71 
72  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation::Input for SimHit:" << edm::InputTag(g4Label_, hits_)
73  << " Digits:" << digis_ << " Sample: " << iSample_ << " Threshold "
74  << threshold_;
75 }
76 
79  desc.add<std::string>("ModuleLabel", "g4SimHits");
80  desc.add<std::string>("HitCollection", "HGCHitsHEback");
81  desc.add<edm::InputTag>("DigiCollection", edm::InputTag("simHGCalUnsuppressedDigis", "HEback"));
82  desc.add<int>("Sample", 5);
83  desc.add<double>("Threshold", 15.0);
84  descriptions.add("hgcalBHAnalysis", desc);
85 }
86 
88  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation::Maximum Number of"
89  << " ring sectors:" << ringMax_ << "\nHitsValidationHcal::Booking the Histograms";
90 
91  //Histograms for Sim Hits
92  hsimE1_ = fs_->make<TH1D>("SimHitEn1", "Sim Hit Energy", 1000, 0.0, 1.0);
93  hsimE2_ = fs_->make<TH1D>("SimHitEn2", "Sim Hit Energy", 1000, 0.0, 1.0);
94  hsimTm_ = fs_->make<TH1D>("SimHitTime", "Sim Hit Time", 1000, 0.0, 500.0);
95  hsimLn_ = fs_->make<TH1D>("SimHitLong", "Sim Hit Long. Profile", 50, 0.0, 25.0);
96  hsimOc_ = fs_->make<TH2D>("SimHitOccup", "Sim Hit Occupnacy", 2 * ringMax_ + 1, -ringMax_, ringMax_ + 1, 360, 0, 360);
97  hsi2Oc_ = fs_->make<TH2D>("SimHitOccu2", "Sim Hit Occupnacy", 2 * ringMax_ + 1, -ringMax_, ringMax_ + 1, 360, 0, 360);
98  hsi3Oc_ = fs_->make<TH2D>("SimHitOccu3", "Sim Hit Occupnacy", 2 * ringMax_ + 1, -ringMax_, ringMax_ + 1, 50, 0, 25);
99  //Histograms for Digis
100  hdigEn_ = fs_->make<TH1D>("DigiEnergy", "Digi ADC Sample", 1000, 0.0, 1000.0);
101  hdigLn_ = fs_->make<TH1D>("DigiLong", "Digi Long. Profile", 50, 0.0, 25.0);
102  hdigOc_ = fs_->make<TH2D>("DigiOccup", "Digi Occupnacy", 2 * ringMax_ + 1, -ringMax_, ringMax_ + 1, 360, 0, 360);
103  hdi2Oc_ = fs_->make<TH2D>("DigiOccu2", "Digi Occupnacy", 2 * ringMax_ + 1, -ringMax_, ringMax_ + 1, 360, 0, 360);
104  hdi3Oc_ = fs_->make<TH2D>("DigiOccu3", "Digi Occupnacy", 2 * ringMax_ + 1, -ringMax_, ringMax_ + 1, 50, 0, 25);
105 }
106 
108  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation:Run = " << e.id().run() << " Event = " << e.id().event();
109 
110  //SimHits
111  const edm::Handle<edm::PCaloHitContainer>& hitsHE = e.getHandle(tok_hits_);
112  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: PCaloHitContainer"
113  << " obtained with flag " << hitsHE.isValid();
114  if (hitsHE.isValid()) {
115  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: PCaloHit buffer " << hitsHE->size();
116  unsigned i(0);
117  std::map<unsigned int, double> map_try;
118  for (edm::PCaloHitContainer::const_iterator it = hitsHE->begin(); it != hitsHE->end(); ++it) {
119  double energy = it->energy();
120  double time = it->time();
121  unsigned int id = it->id();
122  if (DetId(id).det() == DetId::HGCalHSc) {
123  double ring = 0.01 + HGCScintillatorDetId(id).ring();
124  double phi = HGCScintillatorDetId(id).iphi() - 0.01;
125  int lay = HGCScintillatorDetId(id).layer();
126  double ring1 = ring * HGCScintillatorDetId(id).zside();
127  hsi2Oc_->Fill(ring1, phi, energy);
128  hsimE1_->Fill(energy);
129  hsimTm_->Fill(time, energy);
130  hsimOc_->Fill(ring1, phi, energy);
131  hsimLn_->Fill(lay, energy);
132  hsi3Oc_->Fill(ring1, lay, energy);
133  double ensum(0);
134  if (map_try.count(id) != 0)
135  ensum = map_try[id];
136  ensum += energy;
137  map_try[id] = ensum;
138  edm::LogVerbatim("HGCalValidation") << "HGCalBHHit[" << ++i << "] ID " << std::hex << " " << id << std::dec
139  << " " << HGCScintillatorDetId(id) << " E " << energy << " time " << time;
140  }
141  }
142  for (std::map<unsigned int, double>::iterator itr = map_try.begin(); itr != map_try.end(); ++itr) {
143  hsimE2_->Fill((*itr).second);
144  }
145  }
146 
147  //Digits
148  unsigned int kount(0);
149  const edm::Handle<HGCalDigiCollection>& hecoll = e.getHandle(tok_digi_);
150  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: "
151  << "HGCalDigiCollection obtained with"
152  << " flag " << hecoll.isValid();
153  if (hecoll.isValid()) {
154  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: HGCalDigi "
155  << "buffer " << hecoll->size();
156  for (HGCalDigiCollection::const_iterator it = hecoll->begin(); it != hecoll->end(); ++it) {
157  const HGCalDataFrame& df(*it);
158  double energy = df[iSample_].data();
159  if (DetId(df.id()).det() == DetId::HGCalHSc) {
160  HGCScintillatorDetId cell(df.id());
161  int depth = cell.layer();
162  if (energy > threshold_) {
163  double ring = 0.01 + cell.ring();
164  double phi = cell.iphi() - 0.01;
165  double ring1 = cell.zside() * ring;
166  hdi2Oc_->Fill(ring1, phi);
167  hdigEn_->Fill(energy);
168  hdigOc_->Fill(ring1, phi);
169  hdigLn_->Fill(depth);
170  hdi3Oc_->Fill(ring1, depth);
171  edm::LogVerbatim("HGCalValidation")
172  << "HGCalBHDigit[" << ++kount << "] ID " << cell << " E " << energy << ":" << (energy > threshold_);
173  }
174  }
175  }
176  }
177 }
178 
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
std::vector< PCaloHit > PCaloHitContainer
constexpr int iphi() const
get the phi index
const std::string hits_
size_type size() const
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
const edm::InputTag digis_
std::vector< T >::const_iterator const_iterator
constexpr int zside() const
get the z-side of the cell (1/-1)
~HGCalBHValidation() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string g4Label_
edm::Service< TFileService > fs_
HGCalBHValidation(const edm::ParameterSet &ps)
const edm::EDGetTokenT< HGCalDigiCollection > tok_digi_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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.
constexpr int layer() const
get the layer #
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
constexpr int ring() const
get the eta index
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45