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