CMS 3D CMS Logo

HcalDigisClient.cc
Go to the documentation of this file.
2 // -*- C++ -*-
3 //
4 // Package: HcalDigisClient
5 // Class: HcalDigisClient
6 //
14 //
15 // Original Author: Ali Fahim,22 R-013,+41227672649,
16 // Created: Wed Mar 23 22:54:28 CET 2011
17 //
18 //
19 
20 
21 // system include files
22 
24  outputFile_ = iConfig.getUntrackedParameter<std::string > ("outputFile", "HcalDigisClient.root");
25  dirName_ = iConfig.getParameter<std::string > ("DQMDirName");
26  msm_ = new std::map<std::string, MonitorElement*>();
27 
28 
29 }
30 
31 
33  delete msm_;
34 }
35 
36 
39  std::vector<MonitorElement*> hcalMEs;
40  // Since out folders are fixed to three, we can just go over these three folders
41  // i.e., CaloTowersV/CaloTowersTask, HcalRecHitsV/HcalRecHitTask, NoiseRatesV/NoiseRatesTask.
42  std::vector<std::string> fullPathHLTFolders = ig.getSubdirs();
43  for (unsigned int i = 0; i < fullPathHLTFolders.size(); i++) {
44  ig.setCurrentFolder(fullPathHLTFolders[i]);
45  std::vector<std::string> fullSubPathHLTFolders = ig.getSubdirs();
46  for (unsigned int j = 0; j < fullSubPathHLTFolders.size(); j++) {
47  if (strcmp(fullSubPathHLTFolders[j].c_str(), "HcalDigisV/HcalDigiTask") == 0) {
48  hcalMEs = ig.getContents(fullSubPathHLTFolders[j]);
49  ig.setCurrentFolder("HcalDigisV/HcalDigiTask");
50  if (!HcalDigisEndjob(hcalMEs, "HB", ib))
51  edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HB";
52  if (!HcalDigisEndjob(hcalMEs, "HE", ib))
53  edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HE";
54  if (!HcalDigisEndjob(hcalMEs, "HO", ib))
55  edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HO";
56  if (!HcalDigisEndjob(hcalMEs, "HF", ib))
57  edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HF";
58  }
59  }
60  }
61 }
62 
63 int HcalDigisClient::HcalDigisEndjob(const std::vector<MonitorElement*> &hcalMEs, std::string subdet_, DQMStore::IBooker &ib) {
64 
65  using namespace std;
66  string strtmp;
67 
68 
69  MonitorElement * nevtot(nullptr);
70 
71  std::vector<MonitorElement*> ieta_iphi_occupancy_maps;
72  std::vector<std::string> depthID;
73 
74  // std::cout << " Number of histos " << hcalMEs.size() << std::endl;
75 
76  for (unsigned int ih = 0; ih < hcalMEs.size(); ih++) {
77 
78  if (hcalMEs[ih]->getName() == "nevtot"){
79  nevtot = hcalMEs[ih];
80  continue;
81  }
82 
83  //We search the occupancy maps corresponding to this subdetector
84  if ( (hcalMEs[ih]->getName().find("HcalDigiTask_ieta_iphi_occupancy_map_depth") != std::string::npos)
85  &&(hcalMEs[ih]->getName().find(subdet_) != std::string::npos) ){
86 
87  ieta_iphi_occupancy_maps.push_back(hcalMEs[ih]);
88 
89  std::string start = "depth";
90  std::string end = "_H";
91 
92  int position = hcalMEs[ih]->getName().find(start) + start.length();
93  int length = hcalMEs[ih]->getName().find(end) - position;
94 
95  depthID.push_back(hcalMEs[ih]->getName().substr(position, length));
96 
97  continue;
98  }
99 
100 
101  }
102 
103 
104  if ( hcalMEs.empty()){
105  edm::LogError("HcalDigisClient") << "No nevtot or maps histo found...";
106  return 0;
107  }
108  if( !nevtot){
109  edm::LogError("HcalDigisClient") << "No nevtot histoo found...";
110  return 0;
111  }
112  if( ieta_iphi_occupancy_maps.empty()){
113  edm::LogError("HcalDigisClient") << "No maps histos found...";
114  return 0;
115  }
116 
117 
118  int ev = nevtot->getEntries();
119 
120 
121  if(ev <= 0) {
122  edm::LogError("HcalDigisClient") << "normalization factor <= 0!";
123  return 0;
124  }
125 
126  float fev = (float) nevtot->getEntries();
127 
128  int depths = ieta_iphi_occupancy_maps.size();
129 
130  HistLim ietaLim(85, -42.5, 42.5);
131 
132  for (int depth = 1; depth <= depths; depth++) {
133  strtmp = "HcalDigiTask_occupancy_vs_ieta_depth" + str(depth) + "_" + subdet_;
134  book1D(ib,strtmp, ietaLim);
135  }
136 
137  std::vector<float> sumphi(depths,0);
138  std::vector<float> sumphie(depths,0);
139 
140 
141  float phi_factor;
142  float cnorm;
143  float enorm;
144 
145 
146  for(int depth = 1; depth <= depths; depth++){
147  int nx = ieta_iphi_occupancy_maps[depth-1]->getNbinsX();
148  int ny = ieta_iphi_occupancy_maps[depth-1]->getNbinsY();
149 
150 
151  for (int i = 1; i <= nx; i++) {
152  for (int j = 1; j <= ny; j++) {
153 
154  // occupancies
155  cnorm = ieta_iphi_occupancy_maps[depth-1]->getBinContent(i, j) / fev;
156  enorm = ieta_iphi_occupancy_maps[depth-1]->getBinError(i, j) / fev;
157  ieta_iphi_occupancy_maps[depth-1]->setBinContent(i, j, cnorm);
158  ieta_iphi_occupancy_maps[depth-1]->setBinError(i, j, enorm);
159 
160  } //for loop over NbinsYU
161  } //for loop over NbinsX
162  } //for loop over the occupancy maps
163 
164  for (int i = 1; i <= 82; i++) {
165 
166  int ieta = i - 42; // -41 -1, 0 40
167  if (ieta >= 0) ieta += 1; // -41 -1, 1 41 - to make it detector-like
168 
169  if (ieta >= -20 && ieta <= 20) {
170  phi_factor = 72.;
171  } else {
172  if (ieta >= 40 || ieta <= -40)
173  phi_factor = 18.;
174  else
175  phi_factor = 36.;
176  }
177 
178  //zero the sumphi and sumphie vector at the start of each ieta ring
179  sumphi.assign(depths,0);
180  sumphie.assign(depths,0);
181 
182  for (int iphi = 1; iphi <= 72; iphi++) {
183  for(int depth = 1; depth <= depths; depth++){
184  int binIeta = ieta_iphi_occupancy_maps[depth-1]->getTH2F()->GetXaxis()->FindBin(ieta);
185  int binIphi = ieta_iphi_occupancy_maps[depth-1]->getTH2F()->GetYaxis()->FindBin(iphi);
186 
187  float content = ieta_iphi_occupancy_maps[depth-1]->getBinContent(binIeta,binIphi);
188  float econtent = ieta_iphi_occupancy_maps[depth-1]->getBinError(binIeta,binIphi);
189 
190  sumphi[depth-1] += content;
191  sumphie[depth-1] += econtent*econtent;
192 
193  }//for loop over depths
194  }//for loop over phi
195 
196  //double deta = double(ieta);
197 
198  // occupancies vs ieta
199  for(int depth = 1; depth <= depths; depth++){
200  strtmp = "HcalDigiTask_occupancy_vs_ieta_depth" + depthID[depth-1] + "_" + subdet_;
201  MonitorElement* ME = msm_->find(strtmp)->second;
202  int ietabin = ME->getTH1F()->GetXaxis()->FindBin(float(ieta));
203 
204  if (sumphi[depth-1]>1.e-30){
205  cnorm = sumphi[depth-1] / phi_factor;
206  enorm = sqrt(sumphie[depth-1]) / phi_factor;
207  ME->setBinContent(ietabin,cnorm);
208  ME->setBinError(ietabin,enorm);
209  }
210  }
211  } // end of i-loop
212 
213  return 1;
214 }
215 
217  if (!msm_->count(name)) return nullptr;
218  else return msm_->find(name)->second;
219 }
220 
222  std::stringstream out;
223  out << x;
224  return out.str();
225 }
226 
227 double HcalDigisClient::integralMETH2D(MonitorElement* ME, int i0, int i1, int j0, int j1) {
228  double sum(0);
229  for (int i = i0; i <= i1; i++) {
230  for (int j = j0; j <= j1; j++) {
231  sum += ME->getBinContent(i, j);
232  }
233  }
234 
235  return sum;
236 }
237 
239  int nx = ME->getNbinsX();
240  int ny = ME->getNbinsY();
241 
242  double content(0);
243  double error(0);
244  for (int i = 1; i <= nx; i++) {
245  for (int j = 1; j <= ny; j++) {
246  content = ME->getBinContent(i, j);
247  error = ME->getBinError(i, j);
248  content *= s;
249  error *= s;
250  ME->setBinContent(i, j, content);
251  ME->setBinError(i, j, error);
252  }
253  }
254 }
255 
256 //define this as a plug-in
258 
Definition: start.py:1
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
TH1F * getTH1F() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string dirName_
void scaleMETH2D(MonitorElement *ME, double s)
virtual void runClient(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:361
bool ev
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
HcalDigisClient(const edm::ParameterSet &)
int HcalDigisEndjob(const std::vector< MonitorElement * > &hcalMEs, std::string subdet_, DQMStore::IBooker &ib)
std::string outputFile_
Definition: ME.h:11
~HcalDigisClient() override
T sqrt(T t)
Definition: SSEVec.h:18
MonitorElement * monitor(std::string name)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
#define end
Definition: vmac.h:39
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:192
std::string str(int x)
void book1D(DQMStore::IBooker &ib, std::string name, int n, double min, double max)
std::map< std::string, MonitorElement * > * msm_
double getEntries() const
get # of entries
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
double integralMETH2D(MonitorElement *ME, int i0, int i1, int j0, int j1)
int getNbinsY() const
get # of bins in Y-axis
double getBinContent(int binx) const
get content of bin (1-D)
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
int getNbinsX() const
get # of bins in X-axis
ib
Definition: cuy.py:662