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
14 
24 
30 
31 // Root objects
32 #include "TROOT.h"
33 #include "TSystem.h"
34 #include "TFile.h"
35 #include "TH1.h"
36 #include "TH2.h"
37 
38 class HGCalBHValidation : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
39 public:
40  explicit HGCalBHValidation(const edm::ParameterSet& ps);
41  ~HGCalBHValidation() override {}
42 
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44 
45 protected:
46  virtual void beginJob() override {}
47  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
48  virtual void endRun(edm::Run const&, edm::EventSetup const&) override {}
49  virtual void analyze(edm::Event const&, edm::EventSetup const&) override;
50  template <class T>
51  void analyzeDigi(const T&, double const&, bool const&, int const&, unsigned int&);
52 
53 private:
57  const int iSample_, geomType_;
58  const double threshold_;
59  const bool ifHCAL_;
62  int etaMax_;
63 
64  TH1D *hsimE1_, *hsimE2_, *hsimTm_;
65  TH1D *hsimLn_, *hdigEn_, *hdigLn_;
66  TH2D *hsimOc_, *hsi2Oc_, *hsi3Oc_;
67  TH2D *hdigOc_, *hdi2Oc_, *hdi3Oc_;
68 };
69 
71  : g4Label_(ps.getUntrackedParameter<std::string>("ModuleLabel", "g4SimHits")),
72  hcalHits_((ps.getUntrackedParameter<std::string>("HitCollection", "HcalHits"))),
73  hcalDigis_(ps.getUntrackedParameter<edm::InputTag>("DigiCollection")),
74  iSample_(ps.getUntrackedParameter<int>("Sample", 5)),
75  geomType_(ps.getUntrackedParameter<int>("GeometryType", 0)),
76  threshold_(ps.getUntrackedParameter<double>("Threshold", 12.0)),
77  ifHCAL_(ps.getUntrackedParameter<bool>("ifHCAL", false)),
78  etaMax_(100) {
79  usesResource(TFileService::kSharedResource);
80 
81  tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hcalHits_));
82  if (ifHCAL_)
83  tok_hbhe_ = consumes<QIE11DigiCollection>(hcalDigis_);
84  else
85  tok_hbhe_ = consumes<HGCalDigiCollection>(hcalDigis_);
86  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation::Input for SimHit:" << edm::InputTag(g4Label_, hcalHits_)
87  << " Digits:" << hcalDigis_ << " Sample: " << iSample_ << " Threshold "
88  << threshold_;
89 }
90 
93  desc.addUntracked<std::string>("ModuleLabel", "g4SimHits");
94  desc.addUntracked<std::string>("HitCollection", "HcalHits");
95  desc.addUntracked<edm::InputTag>("DigiCollection", edm::InputTag("hgcalDigis", "HEback"));
96  desc.addUntracked<int>("Sample", 5);
97  desc.addUntracked<int>("GeometryType", 0);
98  desc.addUntracked<double>("Threshold", 15.0);
99  desc.addUntracked<bool>("ifHCAL", false);
100  descriptions.add("hgcalBHAnalysis", desc);
101 }
102 
104  if (geomType_ == 0) {
107  es.get<HcalParametersRcd>().get(label, parHandle);
108  const HcalParameters* hpar = &(*parHandle);
109  const std::vector<int> etaM = hpar->etaMax;
110  etaMax_ = etaM[1];
111  }
112  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation::Maximum Number of"
113  << " eta sectors:" << etaMax_ << "\nHitsValidationHcal::Booking the Histograms";
114 
115  //Histograms for Sim Hits
116  hsimE1_ = fs_->make<TH1D>("SimHitEn1", "Sim Hit Energy", 1000, 0.0, 1.0);
117  hsimE2_ = fs_->make<TH1D>("SimHitEn2", "Sim Hit Energy", 1000, 0.0, 1.0);
118  hsimTm_ = fs_->make<TH1D>("SimHitTime", "Sim Hit Time", 1000, 0.0, 500.0);
119  hsimLn_ = fs_->make<TH1D>("SimHitLong", "Sim Hit Long. Profile", 40, 0.0, 20.0);
120  hsimOc_ = fs_->make<TH2D>("SimHitOccup", "Sim Hit Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
121  hsi2Oc_ = fs_->make<TH2D>("SimHitOccu2", "Sim Hit Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
122  hsi3Oc_ = fs_->make<TH2D>("SimHitOccu3", "Sim Hit Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 40, 0, 20);
123  //Histograms for Digis
124  hdigEn_ = fs_->make<TH1D>("DigiEnergy", "Digi ADC Sample", 1000, 0.0, 1000.0);
125  hdigLn_ = fs_->make<TH1D>("DigiLong", "Digi Long. Profile", 40, 0.0, 20.0);
126  hdigOc_ = fs_->make<TH2D>("DigiOccup", "Digi Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
127  hdi2Oc_ = fs_->make<TH2D>("DigiOccu2", "Digi Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 360, 0, 360);
128  hdi3Oc_ = fs_->make<TH2D>("DigiOccu3", "Digi Occupnacy", 2 * etaMax_ + 1, -etaMax_, etaMax_ + 1, 40, 0, 20);
129 }
130 
132  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation:Run = " << e.id().run() << " Event = " << e.id().event();
133 
134  //SimHits
136  e.getByToken(tok_hits_, hitsHcal);
137  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: PCaloHitContainer"
138  << " obtained with flag " << hitsHcal.isValid();
139  if (hitsHcal.isValid()) {
140  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: PCaloHit buffer " << hitsHcal->size();
141  unsigned i(0);
142  std::map<unsigned int, double> map_try;
143  for (edm::PCaloHitContainer::const_iterator it = hitsHcal->begin(); it != hitsHcal->end(); ++it) {
144  double energy = it->energy();
145  double time = it->time();
146  unsigned int id = it->id();
147  int subdet, z, depth, eta, phi, lay;
148  bool hbhe, bh;
149  if (geomType_ == 0) {
150  HcalTestNumbering::unpackHcalIndex(id, subdet, z, depth, eta, phi, lay);
151  if (z == 0)
152  eta = -eta;
153  hbhe = ((subdet == static_cast<int>(HcalEndcap)) || (subdet == static_cast<int>(HcalBarrel)));
154  bh = (subdet == static_cast<int>(HcalEndcap));
155  } else {
156  hbhe = bh = (DetId(id).det() == DetId::HGCalHSc);
157  if (bh) {
158  eta = HGCScintillatorDetId(id).ieta();
159  phi = HGCScintillatorDetId(id).iphi();
160  lay = HGCScintillatorDetId(id).layer();
161  }
162  }
163  if (hbhe)
164  hsi2Oc_->Fill((eta + 0.1), (phi - 0.1), energy);
165  if (bh) {
166  hsimE1_->Fill(energy);
167  hsimTm_->Fill(time, energy);
168  hsimOc_->Fill((eta + 0.1), (phi - 0.1), energy);
169  hsimLn_->Fill(lay, energy);
170  hsi3Oc_->Fill((eta + 0.1), lay, energy);
171  double ensum(0);
172  if (map_try.count(id) != 0)
173  ensum = map_try[id];
174  ensum += energy;
175  map_try[id] = ensum;
176  ++i;
177  edm::LogVerbatim("HGCalValidation")
178  << "HGCalBHHit[" << i << "] ID " << std::hex << " " << id << std::dec << " SubDet " << subdet << " depth "
179  << depth << " Eta " << eta << " Phi " << phi << " layer " << lay << " E " << energy << " time " << time;
180  }
181  }
182  for (std::map<unsigned int, double>::iterator itr = map_try.begin(); itr != map_try.end(); ++itr) {
183  hsimE2_->Fill((*itr).second);
184  }
185  }
186 
187  //Digits
188  unsigned int kount(0);
189  if ((geomType_ == 0) && ifHCAL_) {
191  e.getByToken(tok_hbhe_, hbhecoll);
192  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: "
193  << "HBHEQIE11DigiCollection obtained "
194  << "with flag " << hbhecoll.isValid();
195  if (hbhecoll.isValid()) {
196  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: HBHEDigit "
197  << "buffer " << hbhecoll->size();
198  for (QIE11DigiCollection::const_iterator it = hbhecoll->begin(); it != hbhecoll->end(); ++it) {
199  QIE11DataFrame df(*it);
200  HcalDetId cell(df.id());
201  bool hbhe =
202  ((cell.subdetId() == static_cast<int>(HcalEndcap)) || (cell.subdetId() == static_cast<int>(HcalBarrel)));
203  if (hbhe) {
204  bool bh = (cell.subdetId() == static_cast<int>(HcalEndcap));
205  int depth = cell.depth();
206  double energy = df[iSample_].adc();
207  analyzeDigi(cell, energy, bh, depth, kount);
208  }
209  }
210  }
211  } else {
213  e.getByToken(tok_hbhe_, hbhecoll);
214  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: "
215  << "HGCalDigiCollection obtained with"
216  << " flag " << hbhecoll.isValid();
217  if (hbhecoll.isValid()) {
218  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: HGCalDigi "
219  << "buffer " << hbhecoll->size();
220  for (HGCalDigiCollection::const_iterator it = hbhecoll->begin(); it != hbhecoll->end(); ++it) {
221  HGCalDataFrame df(*it);
222  double energy = df[iSample_].data();
223  if (geomType_ == 0) {
224  HcalDetId cell(df.id());
225  bool hbhe =
226  ((cell.subdetId() == static_cast<int>(HcalEndcap)) || (cell.subdetId() == static_cast<int>(HcalBarrel)));
227  if (hbhe) {
228  bool bh = (cell.subdetId() == static_cast<int>(HcalEndcap));
229  int depth = cell.depth();
230  analyzeDigi(cell, energy, bh, depth, kount);
231  }
232  } else {
233  bool bh = (DetId(df.id()).det() == DetId::HGCalHSc);
234  if (bh) {
235  HGCScintillatorDetId cell(df.id());
236  int depth = cell.layer();
237  analyzeDigi(cell, energy, bh, depth, kount);
238  }
239  }
240  }
241  }
242  }
243 }
244 
245 template <class T>
247  const T& cell, double const& energy, bool const& bh, int const& depth, unsigned int& kount) {
248  if (energy > threshold_) {
249  int eta = cell.ieta();
250  int phi = cell.iphi();
251  hdi2Oc_->Fill((eta + 0.1), (phi - 0.1));
252  if (bh) {
253  hdigEn_->Fill(energy);
254  hdigOc_->Fill((eta + 0.1), (phi - 0.1));
255  hdigLn_->Fill(depth);
256  hdi3Oc_->Fill((eta + 0.1), depth);
257  ++kount;
258  edm::LogVerbatim("HGCalValidation")
259  << "HGCalBHDigit[" << kount << "] ID " << cell << " E " << energy << ":" << (energy > threshold_);
260  }
261  }
262 }
263 
RunNumber_t run() const
Definition: EventID.h:38
static const std::string kSharedResource
Definition: TFileService.h:76
EventNumber_t event() const
Definition: EventID.h:40
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
const std::vector< S > & data() const
Definition: HGCDataFrame.h:58
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual void beginJob() override
~HGCalBHValidation() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< T >::const_iterator const_iterator
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
const_iterator begin() const
std::vector< int > etaMax
char const * label
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string g4Label_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Service< TFileService > fs_
HGCalBHValidation(const edm::ParameterSet &ps)
edm::DataFrame::id_type id() const
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
int iphi() const
get the phi index
bool isValid() const
Definition: HandleBase.h:70
const D & id() const
det id
Definition: HGCDataFrame.h:31
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
const double threshold_
const_iterator end() const
Definition: DetId.h:17
const edm::InputTag hcalDigis_
virtual void analyze(edm::Event const &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetToken tok_hbhe_
Readout digi for HGC.
Definition: HGCDataFrame.h:14
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
int layer() const
get the layer #
const_iterator end() const
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:73
long double T
const std::string hcalHits_
const_iterator begin() const
Definition: Run.h:45
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
void analyzeDigi(const T &, double const &, bool const &, int const &, unsigned int &)