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  void beginJob() override {}
47  void beginRun(edm::Run const&, edm::EventSetup const&) override;
48  void endRun(edm::Run const&, edm::EventSetup const&) override {}
49  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 
HGCalBHValidation::hdi3Oc_
TH2D * hdi3Oc_
Definition: HGCalBHValidation.cc:67
HGCalBHValidation
Definition: HGCalBHValidation.cc:38
electrons_cff.bool
bool
Definition: electrons_cff.py:372
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
HGCScintillatorDetId::iphi
int iphi() const
get the phi index
Definition: HGCScintillatorDetId.cc:57
HGCalBHValidation::hsimTm_
TH1D * hsimTm_
Definition: HGCalBHValidation.cc:64
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
HGCScintillatorDetId.h
HGCalBHValidation::hdigEn_
TH1D * hdigEn_
Definition: HGCalBHValidation.cc:65
HGCalBHValidation::hsimE1_
TH1D * hsimE1_
Definition: HGCalBHValidation.cc:64
ESHandle.h
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
HGCScintillatorDetId::ieta
int ieta() const
Definition: HGCScintillatorDetId.h:53
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< edm::PCaloHitContainer >
edm
HLT enums.
Definition: AlignableModifier.h:19
HGCalBHValidation::iSample_
const int iSample_
Definition: HGCalBHValidation.cc:57
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HGCalBHValidation::hdi2Oc_
TH2D * hdi2Oc_
Definition: HGCalBHValidation.cc:67
HcalParameters.h
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
HcalParametersRcd
Definition: HcalParametersRcd.h:8
HGCalBHValidation::hsimE2_
TH1D * hsimE2_
Definition: HGCalBHValidation.cc:64
HGCalBHValidation::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HGCalBHValidation.cc:91
HcalTestNumbering.h
HGCalBHValidation::hdigLn_
TH1D * hdigLn_
Definition: HGCalBHValidation.cc:65
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
HGCalBHValidation::g4Label_
const std::string g4Label_
Definition: HGCalBHValidation.cc:55
HGCalBHValidation::hsimOc_
TH2D * hsimOc_
Definition: HGCalBHValidation.cc:66
HcalBarrel
Definition: HcalAssistant.h:33
edm::Handle
Definition: AssociativeIterator.h:50
HGCalBHValidation::~HGCalBHValidation
~HGCalBHValidation() override
Definition: HGCalBHValidation.cc:41
HGCalBHValidation::ifHCAL_
const bool ifHCAL_
Definition: HGCalBHValidation.cc:59
HcalParameters::etaMax
std::vector< int > etaMax
Definition: HcalParameters.h:55
HGCScintillatorDetId::layer
int layer() const
get the layer #
Definition: HGCScintillatorDetId.h:47
DetId
Definition: DetId.h:17
MakerMacros.h
HcalParametersRcd.h
HcalTestNumbering::unpackHcalIndex
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
Definition: HcalTestNumbering.cc:18
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
Service.h
HcalDigiCollections.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
DDAxes::z
edm::ESHandle
Definition: DTSurvey.h:22
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HGCalBHValidation::fs_
edm::Service< TFileService > fs_
Definition: HGCalBHValidation.cc:54
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TFileService.h
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
HGCalBHValidation::hdigOc_
TH2D * hdigOc_
Definition: HGCalBHValidation.cc:67
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
HGCalBHValidation::analyze
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: HGCalBHValidation.cc:131
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
HGCalBHValidation::threshold_
const double threshold_
Definition: HGCalBHValidation.cc:58
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
HGCalBHValidation::tok_hbhe_
edm::EDGetToken tok_hbhe_
Definition: HGCalBHValidation.cc:61
HcalDetId.h
QIE11DataFrame::id
constexpr edm::DataFrame::id_type id() const
Definition: QIE11DataFrame.h:68
PCaloHit.h
HGCDataFrame
Readout digi for HGC.
Definition: HGCDataFrame.h:14
HcalDetId
Definition: HcalDetId.h:12
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
HGCalBHValidation::HGCalBHValidation
HGCalBHValidation(const edm::ParameterSet &ps)
Definition: HGCalBHValidation.cc:70
HGCDigiCollections.h
edm::DataFrameContainer::begin
const_iterator begin() const
The iterator returned can not safely be used across threads.
Definition: DataFrameContainer.h:149
edm::LogVerbatim
Definition: MessageLogger.h:297
edm::EventSetup
Definition: EventSetup.h:57
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:28
edm::EDGetToken
Definition: EDGetToken.h:35
HGCalBHValidation::etaMax_
int etaMax_
Definition: HGCalBHValidation.cc:62
get
#define get
HGCalBHValidation::hsi2Oc_
TH2D * hsi2Oc_
Definition: HGCalBHValidation.cc:66
photonIsolationHIProducer_cfi.hbhe
hbhe
Definition: photonIsolationHIProducer_cfi.py:8
DDAxes::phi
HGCalBHValidation::hcalDigis_
const edm::InputTag hcalDigis_
Definition: HGCalBHValidation.cc:56
HGCalBHValidation::geomType_
const int geomType_
Definition: HGCalBHValidation.cc:57
HGCalBHValidation::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: HGCalBHValidation.cc:103
std
Definition: JetResolutionObject.h:76
HcalEndcap
Definition: HcalAssistant.h:34
Frameworkfwd.h
HGCScintillatorDetId
Definition: HGCScintillatorDetId.h:21
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
T
long double T
Definition: Basic3DVectorLD.h:48
DetId::HGCalHSc
Definition: DetId.h:34
HGCDataFrame::data
const std::vector< S > & data() const
Definition: HGCDataFrame.h:58
QIE11DataFrame
Definition: QIE11DataFrame.h:11
HcalParameters
Definition: HcalParameters.h:6
TFileService::kSharedResource
static const std::string kSharedResource
Definition: TFileService.h:76
HGCalBHValidation::hcalHits_
const std::string hcalHits_
Definition: HGCalBHValidation.cc:55
EventSetup.h
PCaloHitContainer.h
HGCalBHValidation::analyzeDigi
void analyzeDigi(const T &, double const &, bool const &, int const &, unsigned int &)
Definition: HGCalBHValidation.cc:246
HGCalBHValidation::beginJob
void beginJob() override
Definition: HGCalBHValidation.cc:46
HGCalBHValidation::tok_hits_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
Definition: HGCalBHValidation.cc:60
ParameterSet.h
HGCDataFrame::id
const D & id() const
det id
Definition: HGCDataFrame.h:31
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
ntuplemaker.time
time
Definition: ntuplemaker.py:310
HGCalBHValidation::hsi3Oc_
TH2D * hsi3Oc_
Definition: HGCalBHValidation.cc:66
edm::Event
Definition: Event.h:73
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::DataFrameContainer::end
const_iterator end() const
Definition: DataFrameContainer.h:152
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
HGCalBHValidation::hsimLn_
TH1D * hsimLn_
Definition: HGCalBHValidation.cc:65
HGCalBHValidation::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: HGCalBHValidation.cc:48
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
edm::DataFrameContainer::size
size_type size() const
Definition: DataFrameContainer.h:162
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37