CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalRecHitsClient.cc
Go to the documentation of this file.
1 #include <unistd.h>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 
8 
11 
19 
22 
24 private:
25  //member data
27  const int verbosity_;
29  unsigned int layers_;
30 
31 public:
32  explicit HGCalRecHitsClient(const edm::ParameterSet &);
33  ~HGCalRecHitsClient() override {}
34 
35  void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
36  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
38 
39  int recHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs);
40 };
41 
43  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
44  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
45  ddc_token_(esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
46  edm::ESInputTag{"", nameDetector_})) {}
47 
49  const HGCalDDDConstants &hgcons_ = iSetup.getData(ddc_token_);
50  layers_ = hgcons_.layers(true);
51 }
52 
54 
56  ig.setCurrentFolder("/");
57  if (verbosity_ > 0)
58  edm::LogVerbatim("HGCalValidation") << "\nrunClient";
59  std::vector<MonitorElement *> hgcalMEs;
60  std::vector<std::string> fullDirPath = ig.getSubdirs();
61 
62  for (unsigned int i = 0; i < fullDirPath.size(); i++) {
63  if (verbosity_ > 0)
64  edm::LogVerbatim("HGCalValidation") << "\nfullPath: " << fullDirPath.at(i);
65  ig.setCurrentFolder(fullDirPath.at(i));
66  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
67 
68  for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
69  if (verbosity_ > 1)
70  edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
71  std::string nameDirectory = "HGCAL/HGCalRecHitsV/" + nameDetector_;
72  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
73  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
74  if (verbosity_ > 1)
75  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
76  if (!recHitsEndjob(hgcalMEs))
77  edm::LogWarning("HGCalValidation") << "\nError in RecHitsEndjob!";
78  }
79  }
80  }
81 }
82 
83 int HGCalRecHitsClient::recHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs) {
84  std::vector<MonitorElement *> energy_;
85  std::vector<MonitorElement *> EtaPhi_Plus_;
86  std::vector<MonitorElement *> EtaPhi_Minus_;
87  std::vector<MonitorElement *> HitOccupancy_Plus_;
88  std::vector<MonitorElement *> HitOccupancy_Minus_;
89  std::vector<MonitorElement *> MeanHitOccupancy_Plus_;
90  std::vector<MonitorElement *> MeanHitOccupancy_Minus_;
91 
92  std::ostringstream name;
93  double nevent;
94  int nbinsx, nbinsy;
95 
96  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++) {
97  name.str("");
98  name << "energy_layer_" << ilayer;
99  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
100  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
101  energy_.push_back(hgcalMEs[ih]);
102  }
103  }
104 
105  //normalization
106  nevent = energy_.at(ilayer)->getEntries();
107  nbinsx = energy_.at(ilayer)->getNbinsX();
108  for (int i = 1; i <= nbinsx; i++) {
109  double binValue = energy_.at(ilayer)->getBinContent(i) / nevent;
110  energy_.at(ilayer)->setBinContent(i, binValue);
111  }
112 
113  //EtaPhi 2d plots
114  name.str("");
115  name << "EtaPhi_Plus_"
116  << "layer_" << ilayer;
117  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
118  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
119  EtaPhi_Plus_.push_back(hgcalMEs[ih]);
120  }
121  }
122 
123  name.str("");
124  name << "EtaPhi_Minus_"
125  << "layer_" << ilayer;
126  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
127  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
128  EtaPhi_Minus_.push_back(hgcalMEs[ih]);
129  }
130  }
131 
132  //normalization EtaPhi
133  nevent = EtaPhi_Plus_.at(ilayer)->getEntries();
134  nbinsx = EtaPhi_Plus_.at(ilayer)->getNbinsX();
135  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
136  for (int i = 1; i <= nbinsx; ++i) {
137  for (int j = 1; j <= nbinsy; ++j) {
138  double binValue = EtaPhi_Plus_.at(ilayer)->getBinContent(i, j) / nevent;
139  EtaPhi_Plus_.at(ilayer)->setBinContent(i, j, binValue);
140  }
141  }
142 
143  nevent = EtaPhi_Minus_.at(ilayer)->getEntries();
144  nbinsx = EtaPhi_Minus_.at(ilayer)->getNbinsX();
145  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
146  for (int i = 1; i <= nbinsx; ++i) {
147  for (int j = 1; j <= nbinsy; ++j) {
148  double binValue = EtaPhi_Minus_.at(ilayer)->getBinContent(i, j) / nevent;
149  EtaPhi_Minus_.at(ilayer)->setBinContent(i, j, binValue);
150  }
151  }
152 
153  //HitOccupancy
154  name.str("");
155  name << "HitOccupancy_Plus_layer_" << ilayer;
156  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
157  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
158  HitOccupancy_Plus_.push_back(hgcalMEs[ih]);
159  }
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  //normalization of hit occupancy histos
171  nevent = HitOccupancy_Plus_.at(ilayer)->getEntries();
172  nbinsx = HitOccupancy_Plus_.at(ilayer)->getNbinsX();
173  for (int i = 1; i <= nbinsx; ++i) {
174  double binValue = HitOccupancy_Plus_.at(ilayer)->getBinContent(i) / nevent;
175  HitOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
176  }
177 
178  nevent = HitOccupancy_Minus_.at(ilayer)->getEntries();
179  nbinsx = HitOccupancy_Minus_.at(ilayer)->getNbinsX();
180  for (int i = 1; i <= nbinsx; ++i) {
181  double binValue = HitOccupancy_Minus_.at(ilayer)->getBinContent(i) / nevent;
182  HitOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
183  }
184 
185  } //loop over layers
186 
187  name.str("");
188  name << "SUMOfRecHitOccupancy_Plus";
189  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
190  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
191  MeanHitOccupancy_Plus_.push_back(hgcalMEs[ih]);
192  unsigned int indx = MeanHitOccupancy_Plus_.size() - 1;
193  for (int ilayer = 0; ilayer < (int)layers_; ++ilayer) {
194  double meanVal = HitOccupancy_Plus_.at(ilayer)->getMean();
195  MeanHitOccupancy_Plus_[indx]->setBinContent(ilayer + 1, meanVal);
196  }
197  break;
198  }
199  }
200 
201  name.str("");
202  name << "SUMOfRecHitOccupancy_Plus";
203  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
204  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
205  MeanHitOccupancy_Minus_.push_back(hgcalMEs[ih]);
206  unsigned indx = MeanHitOccupancy_Minus_.size() - 1;
207  for (int ilayer = 0; ilayer < (int)layers_; ++ilayer) {
208  double meanVal = HitOccupancy_Minus_.at(ilayer)->getMean();
209  MeanHitOccupancy_Minus_[indx]->setBinContent(ilayer + 1, meanVal);
210  }
211  break;
212  }
213  }
214 
215  return 1;
216 }
217 
219 
Log< level::Info, true > LogVerbatim
const edm::EventSetup & c
int ib
Definition: cuy.py:661
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:700
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:593
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int nevent
Definition: AMPTWrapper.h:84
unsigned int layers(bool reco) const
~HGCalRecHitsClient() override
HGCalRecHitsClient(const edm::ParameterSet &)
Transition
Definition: Transition.h:12
const std::string nameDetector_
int recHitsEndjob(const std::vector< MonitorElement * > &hgcalMEs)
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:236
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
Log< level::Warning, false > LogWarning
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > ddc_token_