CMS 3D CMS Logo

HGCalHitClient.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <unistd.h>
3 #include <iostream>
4 #include <fstream>
5 #include <vector>
6 
17 
18 //#define EDM_ML_DEBUG
19 
21 
22 public:
23  explicit HGCalHitClient(const edm::ParameterSet& );
24  ~HGCalHitClient() override;
25 
26  void beginRun(const edm::Run& run, const edm::EventSetup& c) override {}
27  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
28 
29 private:
31 
32  int geometryEndjob(const std::vector<MonitorElement*> &hcalMEs);
33 };
34 
36 
37  subDirectory_ = iConfig.getParameter<std::string>("DirectoryName");
38 }
39 
41 
43  ig.setCurrentFolder("/");
44 #ifdef EDM_ML_DEBUG
45  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation :: runClient";
46 #endif
47  std::vector<MonitorElement*> hgcalMEs;
48  std::vector<std::string> fullDirPath = ig.getSubdirs();
49 
50  for (unsigned int i=0; i<fullDirPath.size(); i++) {
51 #ifdef EDM_ML_DEBUG
52  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation::fullPath: "
53  << fullDirPath.at(i);
54 #endif
55  ig.setCurrentFolder(fullDirPath.at(i));
56  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
57 
58  for (unsigned int j=0; j<fullSubDirPath.size(); j++) {
59 #ifdef EDM_ML_DEBUG
60  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation:: fullSubPath: "
61  << fullSubDirPath.at(j);
62 #endif
63  if (strcmp(fullSubDirPath.at(j).c_str(), subDirectory_.c_str()) == 0) {
64  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation:: hgcalMES size : "
67  << hgcalMEs.size();
68 #endif
69  if (!geometryEndjob(hgcalMEs))
70  edm::LogWarning("HGCalValid") << "\nError in HGcalHitEndjob!";
71  }
72  }
73  }
74 }
75 
76 int HGCalHitClient::geometryEndjob(const std::vector<MonitorElement*>& hgcalMEs) {
77  std::string dets[3] = {"hee", "hef", "heb"};
78  std::string hist1[2] = {"EnRec","EnSim"};
79  std::string hist2[7] = {"dzVsZ","dyVsY","dxVsX","RecVsSimZ","RecVsSimY",
80  "RecVsSimX","EnSimRec"};
81 
82  std::vector<MonitorElement*> hist1_;
83  std::vector<MonitorElement*> hist2_;
84 
85  //Normalize the histograms
86  for (unsigned int idet=0; idet<3; ++idet) {
87  char name[100];
88  for (unsigned int kh=0; kh<2; ++kh) {
89  sprintf(name, "%s%s", dets[idet].c_str(), hist1[kh].c_str());
90  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
91  if (strcmp(hgcalMEs[ih]->getName().c_str(), name) == 0) {
92  hist1_.push_back(hgcalMEs[ih]);
93  double nevent = hist1_.back()->getEntries();
94  int nbinsx = hist1_.back()->getNbinsX();
95  for (int i=1; i<= nbinsx; ++i) {
96  double binValue = hist1_.back()->getBinContent(i)/nevent;
97  hist1_.back()->setBinContent(i,binValue);
98  }
99  }
100  }
101  }
102  for (unsigned int kh=0; kh<7; ++kh) {
103  sprintf(name, "%s%s", dets[idet].c_str(), hist2[kh].c_str());
104  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
105  if (strcmp(hgcalMEs[ih]->getName().c_str(), name) == 0) {
106  hist2_.push_back(hgcalMEs[ih]);
107  double nevent = hist2_.back()->getEntries();
108  int nbinsx = hist2_.back()->getNbinsX();
109  int nbinsy = hist2_.back()->getNbinsY();
110  for (int i=1; i<= nbinsx; ++i) {
111  for (int j=1; j<= nbinsy; ++j) {
112  double binValue = hist2_.back()->getBinContent(i,j)/nevent;
113  hist2_.back()->setBinContent(i,j,binValue);
114  }
115  }
116  }
117  }
118  }
119  }
120 
121  return 1;
122 }
123 
125 
T getParameter(std::string const &) const
int geometryEndjob(const std::vector< MonitorElement * > &hcalMEs)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:361
HGCalHitClient(const edm::ParameterSet &)
std::string subDirectory_
int nevent
Definition: AMPTWrapper.h:74
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:192
~HGCalHitClient() override
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
Definition: Run.h:44
ib
Definition: cuy.py:662