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 
11 
15 
25 
30 
32 
33 private:
34 
35  //member data
38  unsigned int layers_;
39 
40 public:
41  explicit HGCalSimHitsClient(const edm::ParameterSet& );
42  ~HGCalSimHitsClient() override {}
43 
44  void beginRun(const edm::Run& run, const edm::EventSetup& c) override;
45  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
46  virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig);
47  int simHitsEndjob(const std::vector<MonitorElement*> &hcalMEs);
48 };
49 
51  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
52  nTimes_(iConfig.getParameter<int>("TimeSlices")),
53  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)) { }
54 
56 
57  if (nameDetector_ == "HCal") {
59  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
60  const HcalDDDRecConstants *hcons = &(*pHRNDC);
61  layers_ = hcons->getMaxDepth(1);
62  } else {
64  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
65  const HGCalDDDConstants & hgcons = (*pHGDC);
66  layers_ = hgcons.layers(false);
67  }
68  if (verbosity_>0)
69  edm::LogVerbatim("HGCalValidation") << "Initialize HGCalSimHitsClient for "
70  << nameDetector_ << " : " << layers_;
71 }
72 
74  runClient_(ib, ig);
75 }
76 
78 
79  ig.setCurrentFolder("/");
80  if (verbosity_>0) edm::LogVerbatim("HGCalValidation") << " runClient";
81  std::vector<MonitorElement*> hgcalMEs;
82  std::vector<std::string> fullDirPath = ig.getSubdirs();
83 
84  for (unsigned int i=0; i<fullDirPath.size(); i++) {
85  if (verbosity_>0)
86  edm::LogVerbatim("HGCalValidation") << "fullPath: " << fullDirPath.at(i);
87  ig.setCurrentFolder(fullDirPath.at(i));
88  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
89 
90  for (unsigned int j=0; j<fullSubDirPath.size(); j++) {
91  if (verbosity_>0)
92  edm::LogVerbatim("HGCalValidation") << "fullSubPath: "
93  << fullSubDirPath.at(j);
94  std::string nameDirectory = "HGCAL/HGCalSimHitsV/"+nameDetector_;
95 
96  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
97  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
98  if (verbosity_>0)
99  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : "
100  << hgcalMEs.size();
101  if (!simHitsEndjob(hgcalMEs))
102  edm::LogWarning("HGCalValidation") << "\nError in SimhitsEndjob!";
103  }
104  }
105  }
106 }
107 
108 int HGCalSimHitsClient::simHitsEndjob(const std::vector<MonitorElement*>& hgcalMEs) {
109 
110  std::vector<MonitorElement*> energy_[6];
111  std::vector<MonitorElement*> EtaPhi_Plus_, EtaPhi_Minus_;
112  std::vector<MonitorElement*> HitOccupancy_Plus_, HitOccupancy_Minus_;
113  MonitorElement *MeanHitOccupancy_Plus_, *MeanHitOccupancy_Minus_;
114 
115  std::ostringstream name;
116  double nevent;
117  int nbinsx, nbinsy;
118  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++ ){
119  for (int itimeslice = 0; itimeslice < nTimes_; itimeslice++ ) {
120  //Energy
121  name.str(""); name << "energy_time_" << itimeslice << "_layer_" << ilayer;
122  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
123  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
124  energy_[itimeslice].push_back(hgcalMEs[ih]);
125  }
126  }
127  //normalization
128  nevent = energy_[itimeslice].at(ilayer)->getEntries();
129  nbinsx = energy_[itimeslice].at(ilayer)->getNbinsX();
130  for(int i=1; i <= nbinsx; i++) {
131  double binValue = energy_[itimeslice].at(ilayer)->getBinContent(i)/nevent;
132  energy_[itimeslice].at(ilayer)->setBinContent(i,binValue);
133  }
134  }
135 
136  //EtaPhi 2d plots
137  name.str(""); name << "EtaPhi_Plus_" << "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_Plus_.push_back(hgcalMEs[ih]);
141  }
142  }
143 
144  name.str(""); name << "EtaPhi_Minus_" << "layer_" << ilayer;
145  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
146  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
147  EtaPhi_Minus_.push_back(hgcalMEs[ih]);
148  }
149  }
150  //normalization EtaPhi
151  nevent = EtaPhi_Plus_.at(ilayer)->getEntries();
152  nbinsx = EtaPhi_Plus_.at(ilayer)->getNbinsX();
153  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
154  for(int i=1; i<= nbinsx; ++i) {
155  for(int j=1; j<= nbinsy; ++j) {
156  double binValue = EtaPhi_Plus_.at(ilayer)->getBinContent(i, j)/nevent;
157  EtaPhi_Plus_.at(ilayer)->setBinContent(i, j, binValue);
158  }
159  }
160 
161  nevent = EtaPhi_Minus_.at(ilayer)->getEntries();
162  nbinsx = EtaPhi_Minus_.at(ilayer)->getNbinsX();
163  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
164  for(int i=1; i<= nbinsx; ++i) {
165  for(int j=1; j<= nbinsy; ++j) {
166  double binValue = EtaPhi_Minus_.at(ilayer)->getBinContent(i, j)/nevent;
167  EtaPhi_Minus_.at(ilayer)->setBinContent(i, j, binValue);
168  }
169  }
170 
171  //HitOccupancy
172  name.str(""); name << "HitOccupancy_Plus_layer_" << ilayer;
173  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
174  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
175  HitOccupancy_Plus_.push_back(hgcalMEs[ih]);
176  }
177  }
178  name.str(""); name << "HitOccupancy_Minus_layer_" << ilayer;
179  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
180  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
181  HitOccupancy_Minus_.push_back(hgcalMEs[ih]);
182  }
183  }
184 
185  nevent = HitOccupancy_Plus_.at(ilayer)->getEntries();
186  nbinsx = HitOccupancy_Plus_.at(ilayer)->getNbinsX();
187  for (int i=1; i<= nbinsx; ++i) {
188  double binValue = HitOccupancy_Plus_.at(ilayer)->getBinContent(i)/nevent;
189  HitOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
190  }
191 
192  nevent = HitOccupancy_Minus_.at(ilayer)->getEntries();
193  nbinsx = HitOccupancy_Minus_.at(ilayer)->getNbinsX();
194  for (int i=1; i<= nbinsx; ++i) {
195  double binValue = HitOccupancy_Minus_.at(ilayer)->getBinContent(i)/nevent;
196  HitOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
197  }
198 
199  }//loop over layers
200 
201  name.str(""); name << "MeanHitOccupancy_Plus";
202  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
203  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
204  MeanHitOccupancy_Plus_ = hgcalMEs[ih];
205  for (int ilayer=0; ilayer < (int)layers_; ++ilayer) {
206  double meanVal = HitOccupancy_Plus_.at(ilayer)->getMean();
207  MeanHitOccupancy_Plus_->setBinContent(ilayer+1, meanVal);
208  }
209  break;
210  }
211  }
212 
213  name.str(""); name << "MeanHitOccupancy_Minus";
214  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
215  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
216  MeanHitOccupancy_Minus_ = hgcalMEs[ih];
217  for (int ilayer=0; ilayer < (int)layers_; ++ilayer) {
218  double meanVal = HitOccupancy_Minus_.at(ilayer)->getMean();
219  MeanHitOccupancy_Minus_->setBinContent(ilayer+1, meanVal);
220  }
221  break;
222  }
223  }
224 
225  return 1;
226 }
227 
229 
~HGCalSimHitsClient() override
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:361
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
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:74
unsigned int layers(bool reco) const
HGCalSimHitsClient(const edm::ParameterSet &)
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:192
int getMaxDepth(const int &type) const
T get() const
Definition: EventSetup.h:62
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
int simHitsEndjob(const std::vector< MonitorElement * > &hcalMEs)
Definition: Run.h:44
ib
Definition: cuy.py:662