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 
16 
17 //#define EDM_ML_DEBUG
18 
20 public:
21  explicit HGCalHitClient(const edm::ParameterSet&);
22  ~HGCalHitClient() override;
23 
24  void beginRun(const edm::Run& run, const edm::EventSetup& c) override {}
25  void dqmEndJob(DQMStore::IBooker& ib, DQMStore::IGetter& ig) override;
26 
27 private:
29 
30  int geometryEndjob(const std::vector<MonitorElement*>& hcalMEs);
31 };
32 
34  subDirectory_ = iConfig.getParameter<std::string>("DirectoryName");
35 }
36 
38 
40  ig.setCurrentFolder("/");
41 #ifdef EDM_ML_DEBUG
42  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation :: runClient";
43 #endif
44  std::vector<MonitorElement*> hgcalMEs;
45  std::vector<std::string> fullDirPath = ig.getSubdirs();
46 
47  for (unsigned int i = 0; i < fullDirPath.size(); i++) {
48 #ifdef EDM_ML_DEBUG
49  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation::fullPath: " << fullDirPath.at(i);
50 #endif
51  ig.setCurrentFolder(fullDirPath.at(i));
52  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
53 
54  for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
55 #ifdef EDM_ML_DEBUG
56  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation:: fullSubPath: " << fullSubDirPath.at(j);
57 #endif
58  if (strcmp(fullSubDirPath.at(j).c_str(), subDirectory_.c_str()) == 0) {
59  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
60 #ifdef EDM_ML_DEBUG
61  edm::LogVerbatim("HGCalValid") << "HGCalHitValidation:: hgcalMES size : " << hgcalMEs.size();
62 #endif
63  if (!geometryEndjob(hgcalMEs))
64  edm::LogWarning("HGCalValid") << "\nError in HGcalHitEndjob!";
65  }
66  }
67  }
68 }
69 
70 int HGCalHitClient::geometryEndjob(const std::vector<MonitorElement*>& hgcalMEs) {
71  std::string dets[3] = {"hee", "hef", "heb"};
72  std::string hist1[2] = {"EnRec", "EnSim"};
73  std::string hist2[7] = {"dzVsZ", "dyVsY", "dxVsX", "RecVsSimZ", "RecVsSimY", "RecVsSimX", "EnSimRec"};
74 
75  std::vector<MonitorElement*> hist1_;
76  std::vector<MonitorElement*> hist2_;
77 
78  //Normalize the histograms
79  for (unsigned int idet = 0; idet < 3; ++idet) {
80  char name[100];
81  for (unsigned int kh = 0; kh < 2; ++kh) {
82  sprintf(name, "%s%s", dets[idet].c_str(), hist1[kh].c_str());
83  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
84  if (strcmp(hgcalMEs[ih]->getName().c_str(), name) == 0) {
85  hist1_.push_back(hgcalMEs[ih]);
86  double nevent = hist1_.back()->getEntries();
87  int nbinsx = hist1_.back()->getNbinsX();
88  for (int i = 1; i <= nbinsx; ++i) {
89  double binValue = hist1_.back()->getBinContent(i) / nevent;
90  hist1_.back()->setBinContent(i, binValue);
91  }
92  }
93  }
94  }
95  for (unsigned int kh = 0; kh < 7; ++kh) {
96  sprintf(name, "%s%s", dets[idet].c_str(), hist2[kh].c_str());
97  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
98  if (strcmp(hgcalMEs[ih]->getName().c_str(), name) == 0) {
99  hist2_.push_back(hgcalMEs[ih]);
100  double nevent = hist2_.back()->getEntries();
101  int nbinsx = hist2_.back()->getNbinsX();
102  int nbinsy = hist2_.back()->getNbinsY();
103  for (int i = 1; i <= nbinsx; ++i) {
104  for (int j = 1; j <= nbinsy; ++j) {
105  double binValue = hist2_.back()->getBinContent(i, j) / nevent;
106  hist2_.back()->setBinContent(i, j, binValue);
107  }
108  }
109  }
110  }
111  }
112  }
113 
114  return 1;
115 }
116 
118 
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int geometryEndjob(const std::vector< MonitorElement *> &hcalMEs)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HGCalHitClient(const edm::ParameterSet &)
std::string subDirectory_
int nevent
Definition: AMPTWrapper.h:84
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:236
~HGCalHitClient() override
Log< level::Warning, false > LogWarning
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
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:700