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