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 int HcalDigisClient::HcalDigisEndjob(const std::vector<MonitorElement*> &hcalMEs, std::string subdet_, DQMStore::IBooker &ib) {
63 
64  using namespace std;
65  string strtmp;
66 
67 
68  MonitorElement * nevtot(0);
69 
70  std::vector<MonitorElement*> ieta_iphi_occupancy_maps;
71  std::vector<std::string> depthID;
72 
73  // std::cout << " Number of histos " << hcalMEs.size() << std::endl;
74 
75  for (unsigned int ih = 0; ih < hcalMEs.size(); ih++) {
76 
77  if (hcalMEs[ih]->getName() == "nevtot"){
78  nevtot = hcalMEs[ih];
79  continue;
80  }
81 
82  //We search the occupancy maps corresponding to this subdetector
83  if ( (hcalMEs[ih]->getName().find("HcalDigiTask_ieta_iphi_occupancy_map_depth") != std::string::npos)
84  &&(hcalMEs[ih]->getName().find(subdet_) != std::string::npos) ){
85 
86  ieta_iphi_occupancy_maps.push_back(hcalMEs[ih]);
87 
88  std::string start = "depth";
89  std::string end = "_H";
90 
91  int position = hcalMEs[ih]->getName().find(start) + start.length();
92  int length = hcalMEs[ih]->getName().find(end) - position;
93 
94  depthID.push_back(hcalMEs[ih]->getName().substr(position, length));
95 
96  continue;
97  }
98 
99 
100  }
101 
102 
103  if ( hcalMEs.size() == 0){
104  edm::LogError("HcalDigisClient") << "No nevtot or maps histo found...";
105  return 0;
106  }
107  if( !nevtot){
108  edm::LogError("HcalDigisClient") << "No nevtot histoo found...";
109  return 0;
110  }
111  if( ieta_iphi_occupancy_maps.size() < 1){
112  edm::LogError("HcalDigisClient") << "No maps histos found...";
113  return 0;
114  }
115 
116 
117  int ev = nevtot->getEntries();
118 
119 
120  if(ev <= 0) {
121  edm::LogError("HcalDigisClient") << "normalization factor <= 0!";
122  return 0;
123  }
124 
125  float fev = (float) nevtot->getEntries();
126 
127  int depths = ieta_iphi_occupancy_maps.size();
128 
129  HistLim ietaLim(85, -42.5, 42.5);
130 
131  for (int depth = 1; depth <= depths; depth++) {
132  strtmp = "HcalDigiTask_occupancy_vs_ieta_depth" + str(depth) + "_" + subdet_;
133  book1D(ib,strtmp, ietaLim);
134  }
135 
136  std::vector<float> sumphi;
137  for(int depth = 1; depth <= depths; depth++) sumphi.push_back(0.);
138 
139  float phi_factor;
140  float cnorm;
141  float enorm;
142 
143 
144  for(int depth = 1; depth <= depths; depth++){
145  int nx = ieta_iphi_occupancy_maps[depth-1]->getNbinsX();
146  int ny = ieta_iphi_occupancy_maps[depth-1]->getNbinsY();
147 
148 
149  for (int i = 1; i <= nx; i++) {
150  for (int j = 1; j <= ny; j++) {
151 
152  // occupancies
153  cnorm = ieta_iphi_occupancy_maps[depth-1]->getBinContent(i, j) / fev;
154  enorm = ieta_iphi_occupancy_maps[depth-1]->getBinError(i, j) / fev;
155  ieta_iphi_occupancy_maps[depth-1]->setBinContent(i, j, cnorm);
156  ieta_iphi_occupancy_maps[depth-1]->setBinError(i, j, enorm);
157 
158  } //for loop over NbinsYU
159  } //for loop over NbinsX
160  } //for loop over the occupancy maps
161 
162  for (int i = 1; i <= 82; i++) {
163 
164  int ieta = i - 42; // -41 -1, 0 40
165  if (ieta >= 0) ieta += 1; // -41 -1, 1 41 - to make it detector-like
166 
167  if (ieta >= -20 && ieta <= 20) {
168  phi_factor = 72.;
169  } else {
170  if (ieta >= 40 || ieta <= -40)
171  phi_factor = 18.;
172  else
173  phi_factor = 36.;
174  }
175 
176  //zero the sumphi vector at the start of each ieta ring
177  for(int depth = 1; depth <= depths; depth++) sumphi[depth-1] = 0;
178 
179  for (int iphi = 1; iphi <= 72; iphi++) {
180  for(int depth = 1; depth <= depths; depth++){
181  int binIeta = ieta_iphi_occupancy_maps[depth-1]->getTH2F()->GetXaxis()->FindBin(ieta);
182  int binIphi = ieta_iphi_occupancy_maps[depth-1]->getTH2F()->GetYaxis()->FindBin(iphi);
183 
184  float content = ieta_iphi_occupancy_maps[depth-1]->getBinContent(binIeta,binIphi);
185 
186  sumphi[depth-1] += content;
187 
188  }//for loop over depths
189  }//for loop over phi
190 
191  double deta = double(ieta);
192 
193  // occupancies vs ieta
194  for(int depth = 1; depth <= depths; depth++){
195  cnorm = sumphi[depth-1] / phi_factor;
196  strtmp = "HcalDigiTask_occupancy_vs_ieta_depth" + depthID[depth-1] + "_" + subdet_;
197  fill1D(strtmp, deta, cnorm);
198  }
199  } // end of i-loop
200 
201  return 1;
202 }
203 
205  if (!msm_->count(name)) return NULL;
206  else return msm_->find(name)->second;
207 }
208 
210  std::stringstream out;
211  out << x;
212  return out.str();
213 }
214 
215 double HcalDigisClient::integralMETH2D(MonitorElement* ME, int i0, int i1, int j0, int j1) {
216  double sum(0);
217  for (int i = i0; i <= i1; i++) {
218  for (int j = j0; j <= j1; j++) {
219  sum += ME->getBinContent(i, j);
220  }
221  }
222 
223  return sum;
224 }
225 
227  int nx = ME->getNbinsX();
228  int ny = ME->getNbinsY();
229 
230  double content(0);
231  double error(0);
232  for (int i = 1; i <= nx; i++) {
233  for (int j = 1; j <= ny; j++) {
234  content = ME->getBinContent(i, j);
235  error = ME->getBinError(i, j);
236  content *= s;
237  error *= s;
238  ME->setBinContent(i, j, content);
239  ME->setBinError(i, j, error);
240  }
241  }
242 }
243 
244 //define this as a plug-in
246 
Definition: start.py:1
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:197
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)
#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)
#define NULL
Definition: scimark2.h:8
bool ev
double getEntries(void) const
get # of entries
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 getNbinsY(void) const
get # of bins in Y-axis
int HcalDigisEndjob(const std::vector< MonitorElement * > &hcalMEs, std::string subdet_, DQMStore::IBooker &ib)
std::string outputFile_
Definition: ME.h:11
void fill1D(std::string name, double X, double weight=1)
MonitorElement * monitor(std::string name)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
#define end
Definition: vmac.h:37
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 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)
std::vector< std::string > getSubdirs(void)
Definition: DQMStore.cc:323
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:347
double getBinContent(int binx) const
get content of bin (1-D)
static int position[264][3]
Definition: ReadPGInfo.cc:509
int getNbinsX(void) const
get # of bins in X-axis
ib
Definition: cuy.py:660