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 
20 
23 
25 private:
26  //member data
28  const int nTimes_, verbosity_;
30  unsigned int layers_;
31 
32 public:
33  explicit HGCalSimHitsClient(const edm::ParameterSet &);
34  ~HGCalSimHitsClient() override {}
35 
36  void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
37  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
39  int simHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs);
40 };
41 
43  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
44  nTimes_(iConfig.getParameter<int>("TimeSlices")),
45  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
47  edm::ESInputTag{"", nameDetector_})) {}
48 
50  const HGCalDDDConstants *hgcons = &iSetup.getData(tok_hgcal_);
51  layers_ = hgcons->layers(true);
52  if (verbosity_ > 0)
53  edm::LogVerbatim("HGCalValidation") << "Initialize HGCalSimHitsClient for " << nameDetector_ << " : " << layers_;
54 }
55 
57 
59  ig.setCurrentFolder("/");
60  if (verbosity_ > 0)
61  edm::LogVerbatim("HGCalValidation") << " runClient";
62  std::vector<MonitorElement *> hgcalMEs;
63  std::vector<std::string> fullDirPath = ig.getSubdirs();
64 
65  for (unsigned int i = 0; i < fullDirPath.size(); i++) {
66  if (verbosity_ > 0)
67  edm::LogVerbatim("HGCalValidation") << "fullPath: " << fullDirPath.at(i);
68  ig.setCurrentFolder(fullDirPath.at(i));
69  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
70 
71  for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
72  if (verbosity_ > 0)
73  edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
74  std::string nameDirectory = "HGCAL/HGCalSimHitsV/" + nameDetector_;
75 
76  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
77  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
78  if (verbosity_ > 0)
79  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
80  if (!simHitsEndjob(hgcalMEs))
81  edm::LogWarning("HGCalValidation") << "\nError in SimhitsEndjob!";
82  }
83  }
84  }
85 }
86 
87 int HGCalSimHitsClient::simHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs) {
88  std::vector<MonitorElement *> energy_[6];
89  std::vector<MonitorElement *> EtaPhi_Plus_, EtaPhi_Minus_;
90  std::vector<MonitorElement *> HitOccupancy_Plus_, HitOccupancy_Minus_;
91  MonitorElement *MeanHitOccupancy_Plus_, *MeanHitOccupancy_Minus_;
92 
93  std::ostringstream name;
94  double nevent;
95  int nbinsx, nbinsy;
96  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++) {
97  for (int itimeslice = 0; itimeslice < nTimes_; itimeslice++) {
98  //Energy
99  name.str("");
100  name << "energy_time_" << itimeslice << "_layer_" << ilayer;
101  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
102  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
103  energy_[itimeslice].push_back(hgcalMEs[ih]);
104  }
105  }
106  //normalization
107  nevent = energy_[itimeslice].at(ilayer)->getEntries();
108  nbinsx = energy_[itimeslice].at(ilayer)->getNbinsX();
109  for (int i = 1; i <= nbinsx; i++) {
110  double binValue = energy_[itimeslice].at(ilayer)->getBinContent(i) / nevent;
111  energy_[itimeslice].at(ilayer)->setBinContent(i, binValue);
112  }
113  }
114 
115  //EtaPhi 2d plots
116  name.str("");
117  name << "EtaPhi_Plus_"
118  << "layer_" << ilayer;
119  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
120  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
121  EtaPhi_Plus_.push_back(hgcalMEs[ih]);
122  }
123  }
124 
125  name.str("");
126  name << "EtaPhi_Minus_"
127  << "layer_" << ilayer;
128  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
129  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
130  EtaPhi_Minus_.push_back(hgcalMEs[ih]);
131  }
132  }
133  //normalization EtaPhi
134  nevent = EtaPhi_Plus_.at(ilayer)->getEntries();
135  nbinsx = EtaPhi_Plus_.at(ilayer)->getNbinsX();
136  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
137  for (int i = 1; i <= nbinsx; ++i) {
138  for (int j = 1; j <= nbinsy; ++j) {
139  double binValue = EtaPhi_Plus_.at(ilayer)->getBinContent(i, j) / nevent;
140  EtaPhi_Plus_.at(ilayer)->setBinContent(i, j, binValue);
141  }
142  }
143 
144  nevent = EtaPhi_Minus_.at(ilayer)->getEntries();
145  nbinsx = EtaPhi_Minus_.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_Minus_.at(ilayer)->getBinContent(i, j) / nevent;
150  EtaPhi_Minus_.at(ilayer)->setBinContent(i, j, binValue);
151  }
152  }
153 
154  //HitOccupancy
155  name.str("");
156  name << "HitOccupancy_Plus_layer_" << ilayer;
157  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
158  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
159  HitOccupancy_Plus_.push_back(hgcalMEs[ih]);
160  }
161  }
162  name.str("");
163  name << "HitOccupancy_Minus_layer_" << ilayer;
164  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
165  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
166  HitOccupancy_Minus_.push_back(hgcalMEs[ih]);
167  }
168  }
169 
170  nevent = HitOccupancy_Plus_.at(ilayer)->getEntries();
171  nbinsx = HitOccupancy_Plus_.at(ilayer)->getNbinsX();
172  for (int i = 1; i <= nbinsx; ++i) {
173  double binValue = HitOccupancy_Plus_.at(ilayer)->getBinContent(i) / nevent;
174  HitOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
175  }
176 
177  nevent = HitOccupancy_Minus_.at(ilayer)->getEntries();
178  nbinsx = HitOccupancy_Minus_.at(ilayer)->getNbinsX();
179  for (int i = 1; i <= nbinsx; ++i) {
180  double binValue = HitOccupancy_Minus_.at(ilayer)->getBinContent(i) / nevent;
181  HitOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
182  }
183 
184  } //loop over layers
185 
186  name.str("");
187  name << "MeanHitOccupancy_Plus";
188  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
189  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
190  MeanHitOccupancy_Plus_ = hgcalMEs[ih];
191  for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
192  double meanVal = HitOccupancy_Plus_.at(ilayer)->getMean();
193  MeanHitOccupancy_Plus_->setBinContent(ilayer + 1, meanVal);
194  }
195  break;
196  }
197  }
198 
199  name.str("");
200  name << "MeanHitOccupancy_Minus";
201  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
202  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
203  MeanHitOccupancy_Minus_ = hgcalMEs[ih];
204  for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
205  double meanVal = HitOccupancy_Minus_.at(ilayer)->getMean();
206  MeanHitOccupancy_Minus_->setBinContent(ilayer + 1, meanVal);
207  }
208  break;
209  }
210  }
211 
212  return 1;
213 }
214 
216 
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
~HGCalSimHitsClient() override
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int simHitsEndjob(const std::vector< MonitorElement *> &hgcalMEs)
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
int nevent
Definition: AMPTWrapper.h:84
Transition
Definition: Transition.h:12
unsigned int layers(bool reco) const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
HGCalSimHitsClient(const edm::ParameterSet &)
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > tok_hgcal_
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:236
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
HLT enums.
const std::string nameDetector_
Log< level::Warning, false > LogWarning
Definition: Run.h:45
ib
Definition: cuy.py:661
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:593
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:707