CMS 3D CMS Logo

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