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", "HGCHitsHEback");
95  desc.addUntracked<edm::InputTag>("DigiCollection", edm::InputTag("simHGCalUnsuppressedDigis", "HEback"));
96  desc.addUntracked<int>("Sample", 5);
97  desc.addUntracked<int>("GeometryType", 1);
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", 50, 0.0, 25.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, 50, 0, 25);
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", 50, 0.0, 25.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, 50, 0, 25);
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(0), z(0), depth(0), eta(0), phi(0), lay(0);
148  bool hbhe(false), bh(false);
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  double eta1 = (eta >= 0) ? (eta + 0.1) : (eta - 0.1);
164  if (hbhe)
165  hsi2Oc_->Fill(eta1, (phi - 0.1), energy);
166  if (bh) {
167  hsimE1_->Fill(energy);
168  hsimTm_->Fill(time, energy);
169  hsimOc_->Fill(eta1, (phi - 0.1), energy);
170  hsimLn_->Fill(lay, energy);
171  hsi3Oc_->Fill(eta1, lay, energy);
172  double ensum(0);
173  if (map_try.count(id) != 0)
174  ensum = map_try[id];
175  ensum += energy;
176  map_try[id] = ensum;
177  ++i;
178  edm::LogVerbatim("HGCalValidation")
179  << "HGCalBHHit[" << i << "] ID " << std::hex << " " << id << std::dec << " SubDet " << subdet << " depth "
180  << depth << " Eta " << eta << " Phi " << phi << " layer " << lay << " E " << energy << " time " << time;
181  }
182  }
183  for (std::map<unsigned int, double>::iterator itr = map_try.begin(); itr != map_try.end(); ++itr) {
184  hsimE2_->Fill((*itr).second);
185  }
186  }
187 
188  //Digits
189  unsigned int kount(0);
190  if ((geomType_ == 0) && ifHCAL_) {
192  e.getByToken(tok_hbhe_, hbhecoll);
193  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: "
194  << "HBHEQIE11DigiCollection obtained "
195  << "with flag " << hbhecoll.isValid();
196  if (hbhecoll.isValid()) {
197  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: HBHEDigit "
198  << "buffer " << hbhecoll->size();
199  for (QIE11DigiCollection::const_iterator it = hbhecoll->begin(); it != hbhecoll->end(); ++it) {
200  QIE11DataFrame df(*it);
201  HcalDetId cell(df.id());
202  bool hbhe =
203  ((cell.subdetId() == static_cast<int>(HcalEndcap)) || (cell.subdetId() == static_cast<int>(HcalBarrel)));
204  if (hbhe) {
205  bool bh = (cell.subdetId() == static_cast<int>(HcalEndcap));
206  int depth = cell.depth();
207  double energy = df[iSample_].adc();
208  analyzeDigi(cell, energy, bh, depth, kount);
209  }
210  }
211  }
212  } else {
214  e.getByToken(tok_hbhe_, hbhecoll);
215  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation.: "
216  << "HGCalDigiCollection obtained with"
217  << " flag " << hbhecoll.isValid();
218  if (hbhecoll.isValid()) {
219  edm::LogVerbatim("HGCalValidation") << "HGCalBHValidation: HGCalDigi "
220  << "buffer " << hbhecoll->size();
221  for (HGCalDigiCollection::const_iterator it = hbhecoll->begin(); it != hbhecoll->end(); ++it) {
222  HGCalDataFrame df(*it);
223  double energy = df[iSample_].data();
224  if (geomType_ == 0) {
225  HcalDetId cell(df.id());
226  bool hbhe =
227  ((cell.subdetId() == static_cast<int>(HcalEndcap)) || (cell.subdetId() == static_cast<int>(HcalBarrel)));
228  if (hbhe) {
229  bool bh = (cell.subdetId() == static_cast<int>(HcalEndcap));
230  int depth = cell.depth();
231  analyzeDigi(cell, energy, bh, depth, kount);
232  }
233  } else {
234  bool bh = (DetId(df.id()).det() == DetId::HGCalHSc);
235  if (bh) {
236  HGCScintillatorDetId cell(df.id());
237  int depth = cell.layer();
238  analyzeDigi(cell, energy, bh, depth, kount);
239  }
240  }
241  }
242  }
243  }
244 }
245 
246 template <class T>
248  const T& cell, double const& energy, bool const& bh, int const& depth, unsigned int& kount) {
249  if (energy > threshold_) {
250  int eta = cell.ieta();
251  int phi = cell.iphi();
252  double eta1 = (eta >= 0) ? (eta + 0.1) : (eta - 0.1);
253  hdi2Oc_->Fill(eta1, (phi - 0.1));
254  if (bh) {
255  hdigEn_->Fill(energy);
256  hdigOc_->Fill(eta1, (phi - 0.1));
257  hdigLn_->Fill(depth);
258  hdi3Oc_->Fill(eta1, depth);
259  ++kount;
260  edm::LogVerbatim("HGCalValidation")
261  << "HGCalBHDigit[" << kount << "] ID " << cell << " E " << energy << ":" << (energy > threshold_);
262  }
263  }
264 }
265 
HGCalBHValidation::hdi3Oc_
TH2D * hdi3Oc_
Definition: HGCalBHValidation.cc:67
HGCalBHValidation
Definition: HGCalBHValidation.cc:38
electrons_cff.bool
bool
Definition: electrons_cff.py:366
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
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:58
HGCalBHValidation::hsimTm_
TH1D * hsimTm_
Definition: HGCalBHValidation.cc:64
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
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:57
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
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HGCalBHValidation::hdi2Oc_
TH2D * hdi2Oc_
Definition: HGCalBHValidation.cc:67
protons_cff.time
time
Definition: protons_cff.py:39
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:50
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:87
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:70
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
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
HGCalBHValidation::hdigOc_
TH2D * hdigOc_
Definition: HGCalBHValidation.cc:67
HGCalBHValidation::analyze
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: HGCalBHValidation.cc:131
edm::ParameterSet
Definition: ParameterSet.h:47
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
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::EventSetup
Definition: EventSetup.h:58
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
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HGCalBHValidation::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: HGCalBHValidation.cc:103
std
Definition: JetResolutionObject.h:76
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:733
HcalEndcap
Definition: HcalAssistant.h:34
Frameworkfwd.h
HGCScintillatorDetId
Definition: HGCScintillatorDetId.h:23
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
T
long double T
Definition: Basic3DVectorLD.h:48
DetId::HGCalHSc
Definition: DetId.h:34
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:247
HGCalBHValidation::beginJob
void beginJob() override
Definition: HGCalBHValidation.cc:46
HGCalBHValidation::tok_hits_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
Definition: HGCalBHValidation.cc:60
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
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