CMS 3D CMS Logo

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 
18 
21 
23 private:
24  //member data
26  const int verbosity_;
28  unsigned int layers_;
29 
30 public:
31  explicit HGCalRecHitsClient(const edm::ParameterSet &);
32  ~HGCalRecHitsClient() override = default;
33 
34  void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
35  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
37 
38  int recHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs);
39 };
40 
42  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
43  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
45  edm::ESInputTag{"", nameDetector_})) {}
46 
48  const HGCalDDDConstants &hgcons_ = iSetup.getData(ddc_token_);
49  layers_ = hgcons_.layers(true);
50 }
51 
53 
55  ig.setCurrentFolder("/");
56  if (verbosity_ > 0)
57  edm::LogVerbatim("HGCalValidation") << "\nrunClient";
58  std::vector<MonitorElement *> hgcalMEs;
59  std::vector<std::string> fullDirPath = ig.getSubdirs();
60 
61  for (unsigned int i = 0; i < fullDirPath.size(); i++) {
62  if (verbosity_ > 0)
63  edm::LogVerbatim("HGCalValidation") << "\nfullPath: " << fullDirPath.at(i);
64  ig.setCurrentFolder(fullDirPath.at(i));
65  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
66 
67  for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
68  if (verbosity_ > 1)
69  edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
70  std::string nameDirectory = "HGCAL/HGCalRecHitsV/" + nameDetector_;
71  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
72  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
73  if (verbosity_ > 1)
74  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
75  if (!recHitsEndjob(hgcalMEs))
76  edm::LogWarning("HGCalValidation") << "\nError in RecHitsEndjob!";
77  }
78  }
79  }
80 }
81 
82 int HGCalRecHitsClient::recHitsEndjob(const std::vector<MonitorElement *> &hgcalMEs) {
83  std::vector<MonitorElement *> energy_;
84  std::vector<MonitorElement *> EtaPhi_Plus_;
85  std::vector<MonitorElement *> EtaPhi_Minus_;
86  std::vector<MonitorElement *> HitOccupancy_Plus_;
87  std::vector<MonitorElement *> HitOccupancy_Minus_;
88  std::vector<MonitorElement *> MeanHitOccupancy_Plus_;
89  std::vector<MonitorElement *> MeanHitOccupancy_Minus_;
90 
91  std::ostringstream name;
92  double nevent;
93  int nbinsx, nbinsy;
94 
95  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++) {
96  name.str("");
97  name << "energy_layer_" << ilayer;
98  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
99  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
100  energy_.push_back(hgcalMEs[ih]);
101  }
102  }
103 
104  //normalization
105  nevent = energy_.at(ilayer)->getEntries();
106  nbinsx = energy_.at(ilayer)->getNbinsX();
107  for (int i = 1; i <= nbinsx; i++) {
108  double binValue = energy_.at(ilayer)->getBinContent(i) / nevent;
109  energy_.at(ilayer)->setBinContent(i, binValue);
110  }
111 
112  //EtaPhi 2d plots
113  name.str("");
114  name << "EtaPhi_Plus_"
115  << "layer_" << ilayer;
116  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
117  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
118  EtaPhi_Plus_.push_back(hgcalMEs[ih]);
119  }
120  }
121 
122  name.str("");
123  name << "EtaPhi_Minus_"
124  << "layer_" << ilayer;
125  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
126  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
127  EtaPhi_Minus_.push_back(hgcalMEs[ih]);
128  }
129  }
130 
131  //normalization EtaPhi
132  nevent = EtaPhi_Plus_.at(ilayer)->getEntries();
133  nbinsx = EtaPhi_Plus_.at(ilayer)->getNbinsX();
134  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
135  for (int i = 1; i <= nbinsx; ++i) {
136  for (int j = 1; j <= nbinsy; ++j) {
137  double binValue = EtaPhi_Plus_.at(ilayer)->getBinContent(i, j) / nevent;
138  EtaPhi_Plus_.at(ilayer)->setBinContent(i, j, binValue);
139  }
140  }
141 
142  nevent = EtaPhi_Minus_.at(ilayer)->getEntries();
143  nbinsx = EtaPhi_Minus_.at(ilayer)->getNbinsX();
144  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
145  for (int i = 1; i <= nbinsx; ++i) {
146  for (int j = 1; j <= nbinsy; ++j) {
147  double binValue = EtaPhi_Minus_.at(ilayer)->getBinContent(i, j) / nevent;
148  EtaPhi_Minus_.at(ilayer)->setBinContent(i, j, binValue);
149  }
150  }
151 
152  //HitOccupancy
153  name.str("");
154  name << "HitOccupancy_Plus_layer_" << ilayer;
155  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
156  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
157  HitOccupancy_Plus_.push_back(hgcalMEs[ih]);
158  }
159  }
160 
161  name.str("");
162  name << "HitOccupancy_Minus_layer_" << ilayer;
163  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
164  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
165  HitOccupancy_Minus_.push_back(hgcalMEs[ih]);
166  }
167  }
168 
169  //normalization of hit occupancy histos
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 << "SUMOfRecHitOccupancy_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_.push_back(hgcalMEs[ih]);
191  unsigned int indx = MeanHitOccupancy_Plus_.size() - 1;
192  for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
193  double meanVal = HitOccupancy_Plus_.at(ilayer)->getMean();
194  MeanHitOccupancy_Plus_[indx]->setBinContent(ilayer + 1, meanVal);
195  }
196  break;
197  }
198  }
199 
200  name.str("");
201  name << "SUMOfRecHitOccupancy_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_Minus_.push_back(hgcalMEs[ih]);
205  unsigned indx = MeanHitOccupancy_Minus_.size() - 1;
206  for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
207  double meanVal = HitOccupancy_Minus_.at(ilayer)->getMean();
208  MeanHitOccupancy_Minus_[indx]->setBinContent(ilayer + 1, meanVal);
209  }
210  break;
211  }
212  }
213 
214  return 1;
215 }
216 
218 
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
int recHitsEndjob(const std::vector< MonitorElement *> &hgcalMEs)
int nevent
Definition: AMPTWrapper.h:84
HGCalRecHitsClient(const edm::ParameterSet &)
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int layers(bool reco) const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const std::string nameDetector_
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
~HGCalRecHitsClient() override=default
HLT enums.
std::string getName(const G4String &)
Definition: ForwardName.cc:3
Log< level::Warning, false > LogWarning
Definition: Run.h:45
ib
Definition: cuy.py:661
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > ddc_token_
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:610
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:717