CMS 3D CMS Logo

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