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 
14 
23 
24 
26 
27 private:
30  int layers_;
31 
32 public:
33  explicit HGCalDigiClient(const edm::ParameterSet&);
34  ~HGCalDigiClient() override { }
35 
36  void beginRun(const edm::Run& run, const edm::EventSetup& c) override;
37  void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
39  int digisEndjob(const std::vector<MonitorElement*> &hcalMEs);
40 };
41 
43  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
44  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)) { }
45 
46 void HGCalDigiClient::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
47 
48  if (nameDetector_ == "HCal") {
50  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
51  const HcalDDDRecConstants *hcons = &(*pHRNDC);
52  layers_ = hcons->getMaxDepth(1);
53  } else {
55  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
56  const HGCalDDDConstants & hgcons_ = (*pHGDC);
57  layers_ = hgcons_.layers(true);
58  }
59 }
60 
62  runClient_(ib, ig);
63 }
64 
66 
67  ig.setCurrentFolder("/");
68  if (verbosity_) edm::LogVerbatim("HGCalValidation") << "\nrunClient";
69  std::vector<MonitorElement*> hgcalMEs;
70  std::vector<std::string> fullDirPath = ig.getSubdirs();
71 
72  for (unsigned int i=0; i<fullDirPath.size(); i++) {
73  if (verbosity_)
74  edm::LogVerbatim("HGCalValidation") << "\nfullPath: " << fullDirPath.at(i);
75  ig.setCurrentFolder(fullDirPath.at(i));
76  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
77 
78  for (unsigned int j=0; j<fullSubDirPath.size(); j++) {
79  if (verbosity_)
80  edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
81  std::string nameDirectory = "HGCalDigiV/"+nameDetector_;
82  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
83  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
84  if (verbosity_)
85  edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
86  if (!digisEndjob(hgcalMEs))
87  edm::LogVerbatim("HGCalValidation") << "\nError in DigisEndjob!";
88  }
89  }
90  }
91 }
92 
93 int HGCalDigiClient::digisEndjob(const std::vector<MonitorElement*>& hgcalMEs) {
94 
95  std::vector<MonitorElement*> charge_;
96  std::vector<MonitorElement*> DigiOccupancy_XY_;
97  std::vector<MonitorElement*> ADC_;
98  std::vector<MonitorElement*> DigiOccupancy_Plus_;
99  std::vector<MonitorElement*> DigiOccupancy_Minus_;
100  std::vector<MonitorElement*> MeanDigiOccupancy_Plus_;
101  std::vector<MonitorElement*> MeanDigiOccupancy_Minus_;
102  std::ostringstream name;
103  double nevent;
104  int nbinsx, nbinsy;
105 
106  for (int ilayer = 0; ilayer < layers_; ilayer++ ){
107  //charge
108  name.str(""); name << "charge_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  charge_.push_back(hgcalMEs[ih]);
112  }
113  //normalization
114  nevent = charge_.at(ilayer)->getEntries();
115  nbinsx = charge_.at(ilayer)->getNbinsX();
116  for(int i=1; i <= nbinsx; i++) {
117  double binValue = charge_.at(ilayer)->getBinContent(i)/nevent;
118  charge_.at(ilayer)->setBinContent(i,binValue);
119  }
120 
121  //XY 2d plots
122  name.str(""); name << "DigiOccupancy_XY_" << "layer_" << ilayer;
123  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
124  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
125  DigiOccupancy_XY_.push_back(hgcalMEs[ih]);
126  }
127 
128  //normalization of XY 2d
129  nevent = DigiOccupancy_XY_.at(ilayer)->getEntries();
130  nbinsx = DigiOccupancy_XY_.at(ilayer)->getNbinsX();
131  nbinsy = DigiOccupancy_XY_.at(ilayer)->getNbinsY();
132  for(int i=1; i<= nbinsx; ++i) {
133  for(int j=1; j<= nbinsy; ++j) {
134  double binValue = DigiOccupancy_XY_.at(ilayer)->getBinContent(i, j)/nevent;
135  DigiOccupancy_XY_.at(ilayer)->setBinContent(i, j, binValue);
136  }
137  }
138 
139  //ADC
140  name.str(""); name << "ADC_layer_" << ilayer;
141  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
142  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
143  ADC_.push_back(hgcalMEs[ih]);
144  }
145 
146  //normalization of ADC Histos
147  nevent = ADC_.at(ilayer)->getEntries();
148  nbinsx = ADC_.at(ilayer)->getNbinsX();
149  for(int i=1; i<= nbinsx; ++i) {
150  double binValue = ADC_.at(ilayer)->getBinContent(i)/nevent;
151  ADC_.at(ilayer)->setBinContent(i, binValue);
152  }
153 
154  //Digi Occupancy
155  name.str(""); name << "DigiOccupancy_Plus_layer_" << ilayer;
156  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
157  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
158  DigiOccupancy_Plus_.push_back(hgcalMEs[ih]);
159  }
160  }
161 
162  name.str(""); name << "DigiOccupancy_Minus_layer_" << ilayer;
163  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
164  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
165  DigiOccupancy_Minus_.push_back(hgcalMEs[ih]);
166  }
167  }
168 
169  //normalization of Digi Occupancy histos
170  nevent = DigiOccupancy_Plus_.at(ilayer)->getEntries();
171  nbinsx = DigiOccupancy_Plus_.at(ilayer)->getNbinsX();
172  for(int i=1; i<= nbinsx; ++i) {
173  double binValue = DigiOccupancy_Plus_.at(ilayer)->getBinContent(i)/nevent;
174  DigiOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
175  }
176 
177  nevent = DigiOccupancy_Minus_.at(ilayer)->getEntries();
178  nbinsx = DigiOccupancy_Minus_.at(ilayer)->getNbinsX();
179  for(int i=1; i<= nbinsx; ++i) {
180  double binValue = DigiOccupancy_Minus_.at(ilayer)->getBinContent(i)/nevent;
181  DigiOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
182  }
183 
184  }//loop over layers
185 
186  name.str(""); name << "SUMOfDigiOccupancy_Plus";
187  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
188  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
189  MeanDigiOccupancy_Plus_.push_back(hgcalMEs[ih]);
190  unsigned indx = MeanDigiOccupancy_Plus_.size()-1;
191  for(int ilayer=0; ilayer < (int)layers_; ++ilayer) {
192  double meanVal = DigiOccupancy_Plus_.at(ilayer)->getMean();
193  MeanDigiOccupancy_Plus_[indx]->setBinContent(ilayer+1, meanVal);
194  }
195  break;
196  }
197  }
198 
199  name.str(""); name << "SUMOfDigiOccupancy_Plus";
200  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
201  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
202  MeanDigiOccupancy_Minus_.push_back(hgcalMEs[ih]);
203  unsigned indx = MeanDigiOccupancy_Minus_.size()-1;
204  for(int ilayer=0; ilayer < (int)layers_; ++ilayer) {
205  double meanVal = DigiOccupancy_Minus_.at(ilayer)->getMean();
206  MeanDigiOccupancy_Minus_[indx]->setBinContent(ilayer+1, meanVal);
207  }
208  break;
209  }
210  }
211  return 1;
212 }
213 
215 
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:305
int digisEndjob(const std::vector< MonitorElement * > &hcalMEs)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override
~HGCalDigiClient() override
int nevent
Definition: AMPTWrapper.h:74
unsigned int layers(bool reco) const
HGCalDigiClient(const edm::ParameterSet &)
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
int getMaxDepth(const int &type) const
const T & get() const
Definition: EventSetup.h:59
void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:349
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
std::string nameDetector_
Definition: Run.h:43
ib
Definition: cuy.py:660