CMS 3D CMS Logo

HGCalDigiClient.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <unistd.h>
5 
13 
18 
20 private:
22  const int verbosity_;
24  int layers_;
25 
26 public:
27  explicit HGCalDigiClient(const edm::ParameterSet &);
28  ~HGCalDigiClient() override {}
29 
30  void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
31  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
33  int digisEndjob(const std::vector<MonitorElement *> &hgcalMEs);
34 };
35 
37  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
38  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
40  edm::ESInputTag{"", nameDetector_})) {}
41 
43  const HGCalDDDConstants *hgcons = &iSetup.getData(tok_hgcal_);
44  layers_ = hgcons->layers(true);
45 }
46 
48 
50  ig.setCurrentFolder("/");
51  if (verbosity_)
52  edm::LogVerbatim("HGCalValidation") << "\nrunClient";
53  std::vector<MonitorElement *> hgcalMEs;
54  std::vector<std::string> fullDirPath = ig.getSubdirs();
55 
56  for (unsigned int i = 0; i < fullDirPath.size(); i++) {
57  if (verbosity_)
58  edm::LogVerbatim("HGCalValidation") << "\nfullPath: " << fullDirPath.at(i);
59  ig.setCurrentFolder(fullDirPath.at(i));
60  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
61 
62  for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
63  if (verbosity_)
64  edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
65  std::string nameDirectory = "HGCAL/HGCalDigisV/" + nameDetector_;
66  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
67  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
68  if (verbosity_)
69  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
70  if (!digisEndjob(hgcalMEs))
71  edm::LogVerbatim("HGCalValidation") << "\nError in DigisEndjob!";
72  }
73  }
74  }
75 }
76 
77 int HGCalDigiClient::digisEndjob(const std::vector<MonitorElement *> &hgcalMEs) {
78  std::vector<MonitorElement *> charge_;
79  std::vector<MonitorElement *> DigiOccupancy_XY_;
80  std::vector<MonitorElement *> ADC_;
81  std::vector<MonitorElement *> DigiOccupancy_Plus_;
82  std::vector<MonitorElement *> DigiOccupancy_Minus_;
83  std::vector<MonitorElement *> MeanDigiOccupancy_Plus_;
84  std::vector<MonitorElement *> MeanDigiOccupancy_Minus_;
85  std::ostringstream name;
86  double nevent;
87  int nbinsx, nbinsy;
88 
89  for (int ilayer = 0; ilayer < layers_; ilayer++) {
90  //charge
91  name.str("");
92  name << "charge_layer_" << ilayer;
93  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
94  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
95  charge_.push_back(hgcalMEs[ih]);
96  }
97  //normalization
98  nevent = charge_.at(ilayer)->getEntries();
99  nbinsx = charge_.at(ilayer)->getNbinsX();
100  for (int i = 1; i <= nbinsx; i++) {
101  double binValue = charge_.at(ilayer)->getBinContent(i) / nevent;
102  charge_.at(ilayer)->setBinContent(i, binValue);
103  }
104 
105  //XY 2d plots
106  name.str("");
107  name << "DigiOccupancy_XY_"
108  << "layer_" << ilayer;
109  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
110  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
111  DigiOccupancy_XY_.push_back(hgcalMEs[ih]);
112  }
113 
114  //normalization of XY 2d
115  nevent = DigiOccupancy_XY_.at(ilayer)->getEntries();
116  nbinsx = DigiOccupancy_XY_.at(ilayer)->getNbinsX();
117  nbinsy = DigiOccupancy_XY_.at(ilayer)->getNbinsY();
118  for (int i = 1; i <= nbinsx; ++i) {
119  for (int j = 1; j <= nbinsy; ++j) {
120  double binValue = DigiOccupancy_XY_.at(ilayer)->getBinContent(i, j) / nevent;
121  DigiOccupancy_XY_.at(ilayer)->setBinContent(i, j, binValue);
122  }
123  }
124 
125  //ADC
126  name.str("");
127  name << "ADC_layer_" << ilayer;
128  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
129  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
130  ADC_.push_back(hgcalMEs[ih]);
131  }
132 
133  //normalization of ADC Histos
134  nevent = ADC_.at(ilayer)->getEntries();
135  nbinsx = ADC_.at(ilayer)->getNbinsX();
136  for (int i = 1; i <= nbinsx; ++i) {
137  double binValue = ADC_.at(ilayer)->getBinContent(i) / nevent;
138  ADC_.at(ilayer)->setBinContent(i, binValue);
139  }
140 
141  //Digi Occupancy
142  name.str("");
143  name << "DigiOccupancy_Plus_layer_" << ilayer;
144  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
145  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
146  DigiOccupancy_Plus_.push_back(hgcalMEs[ih]);
147  }
148  }
149 
150  name.str("");
151  name << "DigiOccupancy_Minus_layer_" << ilayer;
152  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
153  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
154  DigiOccupancy_Minus_.push_back(hgcalMEs[ih]);
155  }
156  }
157 
158  //normalization of Digi Occupancy histos
159  nevent = DigiOccupancy_Plus_.at(ilayer)->getEntries();
160  nbinsx = DigiOccupancy_Plus_.at(ilayer)->getNbinsX();
161  for (int i = 1; i <= nbinsx; ++i) {
162  double binValue = DigiOccupancy_Plus_.at(ilayer)->getBinContent(i) / nevent;
163  DigiOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
164  }
165 
166  nevent = DigiOccupancy_Minus_.at(ilayer)->getEntries();
167  nbinsx = DigiOccupancy_Minus_.at(ilayer)->getNbinsX();
168  for (int i = 1; i <= nbinsx; ++i) {
169  double binValue = DigiOccupancy_Minus_.at(ilayer)->getBinContent(i) / nevent;
170  DigiOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
171  }
172 
173  } //loop over layers
174 
175  name.str("");
176  name << "SUMOfDigiOccupancy_Plus";
177  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
178  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
179  MeanDigiOccupancy_Plus_.push_back(hgcalMEs[ih]);
180  unsigned indx = MeanDigiOccupancy_Plus_.size() - 1;
181  for (int ilayer = 0; ilayer < (int)layers_; ++ilayer) {
182  double meanVal = DigiOccupancy_Plus_.at(ilayer)->getMean();
183  MeanDigiOccupancy_Plus_[indx]->setBinContent(ilayer + 1, meanVal);
184  }
185  break;
186  }
187  }
188 
189  name.str("");
190  name << "SUMOfDigiOccupancy_Plus";
191  for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
192  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
193  MeanDigiOccupancy_Minus_.push_back(hgcalMEs[ih]);
194  unsigned indx = MeanDigiOccupancy_Minus_.size() - 1;
195  for (int ilayer = 0; ilayer < (int)layers_; ++ilayer) {
196  double meanVal = DigiOccupancy_Minus_.at(ilayer)->getMean();
197  MeanDigiOccupancy_Minus_[indx]->setBinContent(ilayer + 1, meanVal);
198  }
199  break;
200  }
201  }
202  return 1;
203 }
204 
206 
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const int verbosity_
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
~HGCalDigiClient() override
int nevent
Definition: AMPTWrapper.h:84
Transition
Definition: Transition.h:12
unsigned int layers(bool reco) const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
HGCalDigiClient(const edm::ParameterSet &)
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > tok_hgcal_
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:236
const std::string nameDetector_
void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
int digisEndjob(const std::vector< MonitorElement *> &hgcalMEs)
HLT enums.
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