CMS 3D CMS Logo

HGCalSimHitsClient.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <unistd.h>
4 #include <vector>
5 
9 
12 
22 
27 
29 private:
30  //member data
33  unsigned int layers_;
34 
35 public:
36  explicit HGCalSimHitsClient(const edm::ParameterSet &);
37  ~HGCalSimHitsClient() override {}
38 
39  void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
40  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
42  int simHitsEndjob(const std::vector<MonitorElement *> &hcalMEs);
43 };
44 
46  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
47  nTimes_(iConfig.getParameter<int>("TimeSlices")),
48  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)) {}
49 
51  if (nameDetector_ == "HCal") {
53  iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
54  const HcalDDDRecConstants *hcons = &(*pHRNDC);
55  layers_ = hcons->getMaxDepth(1);
56  } else {
58  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
59  const HGCalDDDConstants &hgcons = (*pHGDC);
60  layers_ = hgcons.layers(false);
61  }
62  if (verbosity_ > 0)
63  edm::LogVerbatim("HGCalValidation") << "Initialize HGCalSimHitsClient for " << nameDetector_ << " : " << layers_;
64 }
65 
67 
69  ig.setCurrentFolder("/");
70  if (verbosity_ > 0)
71  edm::LogVerbatim("HGCalValidation") << " runClient";
72  std::vector<MonitorElement *> hgcalMEs;
73  std::vector<std::string> fullDirPath = ig.getSubdirs();
74 
75  for (unsigned int i = 0; i < fullDirPath.size(); i++) {
76  if (verbosity_ > 0)
77  edm::LogVerbatim("HGCalValidation") << "fullPath: " << fullDirPath.at(i);
78  ig.setCurrentFolder(fullDirPath.at(i));
79  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
80 
81  for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
82  if (verbosity_ > 0)
83  edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
84  std::string nameDirectory = "HGCAL/HGCalSimHitsV/" + nameDetector_;
85 
86  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
87  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
88  if (verbosity_ > 0)
89  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
90  if (!simHitsEndjob(hgcalMEs))
91  edm::LogWarning("HGCalValidation") << "\nError in SimhitsEndjob!";
92  }
93  }
94  }
95 }
96 
97 int HGCalSimHitsClient::simHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs) {
98  std::vector<MonitorElement *> energy_[6];
99  std::vector<MonitorElement *> EtaPhi_Plus_, EtaPhi_Minus_;
100  std::vector<MonitorElement *> HitOccupancy_Plus_, HitOccupancy_Minus_;
101  MonitorElement *MeanHitOccupancy_Plus_, *MeanHitOccupancy_Minus_;
102 
103  std::ostringstream name;
104  double nevent;
105  int nbinsx, nbinsy;
106  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++) {
107  for (int itimeslice = 0; itimeslice < nTimes_; itimeslice++) {
108  //Energy
109  name.str("");
110  name << "energy_time_" << itimeslice << "_layer_" << ilayer;
111  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
112  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
113  energy_[itimeslice].push_back(hgcalMEs[ih]);
114  }
115  }
116  //normalization
117  nevent = energy_[itimeslice].at(ilayer)->getEntries();
118  nbinsx = energy_[itimeslice].at(ilayer)->getNbinsX();
119  for (int i = 1; i <= nbinsx; i++) {
120  double binValue = energy_[itimeslice].at(ilayer)->getBinContent(i) / nevent;
121  energy_[itimeslice].at(ilayer)->setBinContent(i, binValue);
122  }
123  }
124 
125  //EtaPhi 2d plots
126  name.str("");
127  name << "EtaPhi_Plus_"
128  << "layer_" << ilayer;
129  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
130  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
131  EtaPhi_Plus_.push_back(hgcalMEs[ih]);
132  }
133  }
134 
135  name.str("");
136  name << "EtaPhi_Minus_"
137  << "layer_" << ilayer;
138  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
139  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
140  EtaPhi_Minus_.push_back(hgcalMEs[ih]);
141  }
142  }
143  //normalization EtaPhi
144  nevent = EtaPhi_Plus_.at(ilayer)->getEntries();
145  nbinsx = EtaPhi_Plus_.at(ilayer)->getNbinsX();
146  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
147  for (int i = 1; i <= nbinsx; ++i) {
148  for (int j = 1; j <= nbinsy; ++j) {
149  double binValue = EtaPhi_Plus_.at(ilayer)->getBinContent(i, j) / nevent;
150  EtaPhi_Plus_.at(ilayer)->setBinContent(i, j, binValue);
151  }
152  }
153 
154  nevent = EtaPhi_Minus_.at(ilayer)->getEntries();
155  nbinsx = EtaPhi_Minus_.at(ilayer)->getNbinsX();
156  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
157  for (int i = 1; i <= nbinsx; ++i) {
158  for (int j = 1; j <= nbinsy; ++j) {
159  double binValue = EtaPhi_Minus_.at(ilayer)->getBinContent(i, j) / nevent;
160  EtaPhi_Minus_.at(ilayer)->setBinContent(i, j, binValue);
161  }
162  }
163 
164  //HitOccupancy
165  name.str("");
166  name << "HitOccupancy_Plus_layer_" << ilayer;
167  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
168  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
169  HitOccupancy_Plus_.push_back(hgcalMEs[ih]);
170  }
171  }
172  name.str("");
173  name << "HitOccupancy_Minus_layer_" << ilayer;
174  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
175  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
176  HitOccupancy_Minus_.push_back(hgcalMEs[ih]);
177  }
178  }
179 
180  nevent = HitOccupancy_Plus_.at(ilayer)->getEntries();
181  nbinsx = HitOccupancy_Plus_.at(ilayer)->getNbinsX();
182  for (int i = 1; i <= nbinsx; ++i) {
183  double binValue = HitOccupancy_Plus_.at(ilayer)->getBinContent(i) / nevent;
184  HitOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
185  }
186 
187  nevent = HitOccupancy_Minus_.at(ilayer)->getEntries();
188  nbinsx = HitOccupancy_Minus_.at(ilayer)->getNbinsX();
189  for (int i = 1; i <= nbinsx; ++i) {
190  double binValue = HitOccupancy_Minus_.at(ilayer)->getBinContent(i) / nevent;
191  HitOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
192  }
193 
194  } //loop over layers
195 
196  name.str("");
197  name << "MeanHitOccupancy_Plus";
198  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
199  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
200  MeanHitOccupancy_Plus_ = hgcalMEs[ih];
201  for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
202  double meanVal = HitOccupancy_Plus_.at(ilayer)->getMean();
203  MeanHitOccupancy_Plus_->setBinContent(ilayer + 1, meanVal);
204  }
205  break;
206  }
207  }
208 
209  name.str("");
210  name << "MeanHitOccupancy_Minus";
211  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
212  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
213  MeanHitOccupancy_Minus_ = hgcalMEs[ih];
214  for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
215  double meanVal = HitOccupancy_Minus_.at(ilayer)->getMean();
216  MeanHitOccupancy_Minus_->setBinContent(ilayer + 1, meanVal);
217  }
218  break;
219  }
220  }
221 
222  return 1;
223 }
224 
226 
DQMEDHarvester.h
nevent
int nevent
Definition: AMPTWrapper.h:84
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
dqm::implementation::IGetter::getContents
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:593
ESTransientHandle.h
MessageLogger.h
ESHandle.h
edm::Run
Definition: Run.h:45
HGCalSimHitsClient
Definition: HGCalSimHitsClient.cc:28
HGCalSimHitsClient::nTimes_
int nTimes_
Definition: HGCalSimHitsClient.cc:32
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DQMStore.h
dqm::implementation::IGetter::getSubdirs
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:678
HcalRecNumberingRecord.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
HGCalSimHitsClient::nameDetector_
std::string nameDetector_
Definition: HGCalSimHitsClient.cc:31
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HGCalDDDConstants
Definition: HGCalDDDConstants.h:26
HGCalSimHitsClient::layers_
unsigned int layers_
Definition: HGCalSimHitsClient.cc:33
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
getName
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:235
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
HGCalSimHitsClient::simHitsEndjob
int simHitsEndjob(const std::vector< MonitorElement * > &hcalMEs)
Definition: HGCalSimHitsClient.cc:97
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
HGCalDDDConstants::layers
unsigned int layers(bool reco) const
Definition: HGCalDDDConstants.cc:561
LorentzVector.h
createfilelist.int
int
Definition: createfilelist.py:10
HGCalSimHitsClient::verbosity_
int verbosity_
Definition: HGCalSimHitsClient.cc:32
cuy.ib
ib
Definition: cuy.py:662
HGCalSimHitsClient::runClient_
virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
Definition: HGCalSimHitsClient.cc:68
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
HGCalSimHitsClient::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
Definition: HGCalSimHitsClient.cc:50
DQMEDHarvester
Definition: DQMEDHarvester.py:1
dqm::impl::MonitorElement::setBinContent
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
Definition: MonitorElement.cc:691
HGCalDetId.h
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
HGCalSimHitsClient::~HGCalSimHitsClient
~HGCalSimHitsClient() override
Definition: HGCalSimHitsClient.cc:37
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dqm::implementation::IGetter
Definition: DQMStore.h:484
HcalDDDRecConstants.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
dqm::impl::MonitorElement::getMean
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:549
dqm::implementation::IBooker
Definition: DQMStore.h:43
HcalDDDRecConstants::getMaxDepth
int getMaxDepth(const int &type) const
Definition: HcalDDDRecConstants.h:88
HcalDDDRecConstants
Definition: HcalDDDRecConstants.h:23
HGCalSimHitsClient::HGCalSimHitsClient
HGCalSimHitsClient(const edm::ParameterSet &)
Definition: HGCalSimHitsClient.cc:45
HGCalDDDConstants.h
ParameterSet.h
HGCalSimHitsClient::dqmEndJob
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
Definition: HGCalSimHitsClient.cc:66
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
IdealGeometryRecord
Definition: IdealGeometryRecord.h:25