CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripSummaryCreator.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 //
9 // -- Constructor
10 //
12  edm::LogInfo("SiStripSummaryCreator") <<
13  " Creating SiStripSummaryCreator " << "\n" ;
14  summaryMEMap.clear();
15  summaryFrequency_ = -1;
16 }
17 //
18 // -- Destructor
19 //
21  edm::LogInfo("SiStripSummaryCreator") <<
22  " Deleting SiStripSummaryCreator " << "\n" ;
23  summaryMEMap.clear();
24 }
25 //
26 // -- Read Configuration
27 //
29  summaryMEMap.clear();
30  SiStripConfigParser config_parser;
31  config_parser.getDocument(edm::FileInPath(file_path).fullPath());
32  if (!config_parser.getFrequencyForSummary(summaryFrequency_)){
33  std::cout << "SiStripSummaryCreator::readConfiguration: Failed to read Summary configuration parameters!! ";
34  summaryFrequency_ = -1;
35  return false;
36  }
37  if (!config_parser.getMENamesForSummary(summaryMEMap)) {
38  std::cout << "SiStripSummaryCreator::readConfiguration: Failed to read Summary configuration parameters!! ";
39  return false;
40  }
41  return true;
42 }
43 //
44 // -- Set Summary ME names
45 //
46 void SiStripSummaryCreator::setSummaryMENames(std::map<std::string, std::string>& me_names) {
47 
48  summaryMEMap.clear();
49  for (std::map<std::string,std::string>::const_iterator isum = me_names.begin();
50  isum != me_names.end(); isum++) {
51  summaryMEMap.insert(std::pair<std::string,std::string>(isum->first, isum->second));
52  }
53 }
54 //
55 // -- Browse through the Folder Structure
56 //
58  if (summaryMEMap.size() == 0) return;
59  std::string currDir = dqm_store->pwd();
60  std::vector<std::string> subdirs = dqm_store->getSubdirs();
61  int nmod = 0;
62  for (std::vector<std::string>::const_iterator it = subdirs.begin();
63  it != subdirs.end(); it++) {
64  if ( (*it).find("module_") == std::string::npos) continue;
65  nmod++;
66  }
67  if (nmod > 0) {
68  fillSummaryHistos(dqm_store);
69  } else {
70  for (std::vector<std::string>::const_iterator it = subdirs.begin();
71  it != subdirs.end(); it++) {
72  dqm_store->cd(*it);
73  createSummary(dqm_store);
74  dqm_store->goUp();
75  }
76  fillGrandSummaryHistos(dqm_store);
77  }
78 }
79 //
80 // -- Create and Fill Summary Histograms at the lowest level of the structure
81 //
83  std::string currDir = dqm_store->pwd();
84  std::map<std::string, MonitorElement*> MEMap;
85  std::vector<std::string> subdirs = dqm_store->getSubdirs();
86  if (subdirs.size() ==0) return;
87 
88 
89  for (std::map<std::string,std::string>::const_iterator isum = summaryMEMap.begin();
90  isum != summaryMEMap.end(); isum++) {
91  std::string name = isum->first;
92  int iBinStep = 0;
93  int ndet = 0;
94  std::string htype = isum->second;
95  for (std::vector<std::string>::const_iterator it = subdirs.begin();
96  it != subdirs.end(); it++) {
97  if ( (*it).find("module_") == std::string::npos) continue;
98  dqm_store->cd(*it);
99  ndet++;
100  std::vector<MonitorElement*> contents = dqm_store->getContents(dqm_store->pwd());
101  dqm_store->goUp();
102  for (std::vector<MonitorElement *>::const_iterator im = contents.begin();
103  im != contents.end(); im++) {
104  MonitorElement * me_i = (*im);
105  if (!me_i) continue;
106  std::string name_i = me_i->getName();
107  if (name_i.find(name) == std::string::npos) continue;
108  std::map<std::string, MonitorElement*>::iterator iPos = MEMap.find(name);
110  // Get the Summary ME
111  if (iPos == MEMap.end()){
112  me = getSummaryME(dqm_store, name, htype);
113  MEMap.insert(std::pair<std::string, MonitorElement*>(name, me));
114  } else me = iPos->second;
115  // Fill it now
116  fillHistos(ndet, iBinStep, htype, me_i, me);
117  iBinStep += me_i->getNbinsX();
118  break;
119  }
120  }
121  }
122 }
123 //
124 // -- Fill Summary Histogram at higher level
125 //
127  std::map<std::string, MonitorElement*> MEMap;
128  std::string currDir = dqm_store->pwd();
129  std::string dir_name = currDir.substr(currDir.find_last_of("/")+1);
130  if ((dir_name.find("SiStrip") == 0) ||
131  (dir_name.find("Collector") == 0) ||
132  (dir_name.find("MechanicalView") == 0) ||
133  (dir_name.find("FU") == 0) ) return;
134  std::vector<std::string> subdirs = dqm_store->getSubdirs();
135  if (subdirs.size() == 0) return;;
136  for (std::map<std::string,std::string>::const_iterator isum = summaryMEMap.begin();
137  isum != summaryMEMap.end(); isum++) {
138  std::string name, summary_name;
139  name = isum->first;
140  if (isum->second == "sum" || isum->second == "sum")
141  summary_name = "Summary_" + isum->first;
142  else
143  summary_name = "Summary_Mean" + isum->first;
144  std::string htype = isum->second;
145  int ibinStep =0;
146  for (std::vector<std::string>::const_iterator it = subdirs.begin();
147  it != subdirs.end(); it++) {
148  dqm_store->cd(*it);
149  std::vector<MonitorElement*> contents = dqm_store->getContents(dqm_store->pwd());
150  dqm_store->goUp();
151  for (std::vector<MonitorElement *>::const_iterator im = contents.begin();
152  im != contents.end(); im++) {
153  MonitorElement * me_i = (*im);
154  if (!me_i) continue;
155  std::string name_i = me_i->getName();
156  if (name_i.find((summary_name)) != std::string::npos) {
157 
158  std::map<std::string, MonitorElement*>::iterator iPos = MEMap.find(name);
159  MonitorElement* me;
160  if (iPos == MEMap.end()) {
161  if (htype == "sum" || htype == "Sum") {
162  me = getSummaryME(dqm_store, name, htype);
163  } else {
164  me = getSummaryME(dqm_store, name, "bin-by-bin");
165  }
166  MEMap.insert(std::pair<std::string, MonitorElement*>(name, me));
167  } else me = iPos->second;
168  if (htype == "sum" || htype == "Sum") {
169  fillHistos(0, ibinStep, htype, me_i, me);
170  } else {
171  fillHistos(0, ibinStep,"bin-by-bin", me_i, me);
172  }
173  ibinStep += me_i->getNbinsX();
174  break;
175  }
176  }
177  }
178  }
179 }
180 //
181 // -- Get Summary ME
182 //
184  std::string& name, std::string htype) {
185  MonitorElement* me = 0;
186  std::string currDir = dqm_store->pwd();
187  std::string sum_name, tag_name;
188 
189  std::string dname = currDir.substr(currDir.find_last_of("/")+1);
190  if (dname.find("_") != std::string::npos) dname.insert(dname.find("_"),"_");
191  if (htype == "sum" && htype == "Sum") {
192  sum_name = "Summary" + name + "__" + dname;
193  tag_name = "Summary" + name;
194  } else {
195  sum_name = "Summary_Mean" + name + "__" + dname;
196  tag_name = "Summary_Mean" + name;
197  }
198  // If already booked
199  std::vector<MonitorElement*> contents = dqm_store->getContents(currDir);
200  for (std::vector<MonitorElement *>::const_iterator im = contents.begin();
201  im != contents.end(); im++) {
202  MonitorElement * me = (*im);
203  if (!me) continue;
204  std::string me_name = me->getName();
205  if (me_name.find(sum_name) == 0) {
206  if (me->kind() == MonitorElement::DQM_KIND_TH1F ||
209  TH1* hist1 = me->getTH1();
210  if (hist1) {
211  hist1->Reset();
212  return me;
213  }
214  }
215  }
216  }
217  std::map<int, std::string> tags;
218  if (!me) {
219  int nBins = 0;
220  std::vector<std::string> subdirs = dqm_store->getSubdirs();
221  // set # of bins of the histogram
222  if (htype == "mean" || htype == "Mean" ) {
223  nBins = subdirs.size();
224  me = dqm_store->book1D(sum_name,sum_name,nBins,0.5,nBins+0.5);
225  int ibin = 0;
226  for (std::vector<std::string>::const_iterator it = subdirs.begin();
227  it != subdirs.end(); it++) {
228  std::string subdir_name = (*it).substr((*it).find_last_of("/")+1);
229  ibin++;
230  tags.insert(std::pair<int,std::string>(ibin, (subdir_name)));
231  }
232  } else if (htype == "bin-by-bin" || htype == "Bin-by-Bin") {
233  for (std::vector<std::string>::const_iterator it = subdirs.begin();
234  it != subdirs.end(); it++) {
235  dqm_store->cd(*it);
236  std::string subdir_name = (*it).substr((*it).find_last_of("/")+1);
237  std::vector<MonitorElement*> s_contents = dqm_store->getContents(dqm_store->pwd());
238  for (std::vector<MonitorElement *>::const_iterator iv = s_contents.begin();
239  iv != s_contents.end(); iv++) {
240  MonitorElement* s_me = (*iv);
241  if (!s_me) continue;
242  std::string s_me_name = s_me->getName();
243  if (s_me_name.find(name) == 0 || s_me_name.find(tag_name) == 0) {
244  int ibin = s_me->getNbinsX();
245  nBins += ibin;
246  tags.insert(std::pair<int,std::string>(nBins-ibin/2, (subdir_name)));
247  break;
248  }
249  }
250  dqm_store->goUp();
251  }
252  me = dqm_store->book1D(sum_name,sum_name,nBins,0.5,nBins+0.5);
253  } else if (htype == "sum" || htype == "Sum") {
254  for (std::vector<std::string>::const_iterator it = subdirs.begin();
255  it != subdirs.end(); it++) {
256  dqm_store->cd(*it);
257  std::vector<MonitorElement*> s_contents = dqm_store->getContents(dqm_store->pwd());
258  dqm_store->goUp();
259  for (std::vector<MonitorElement *>::const_iterator iv = s_contents.begin();
260  iv != s_contents.end(); iv++) {
261  MonitorElement* s_me = (*iv);
262  if (!s_me) continue;
263  std::string s_me_name = s_me->getName();
264  if (s_me_name.find(name) == std::string::npos) continue;
265  if (s_me->kind() == MonitorElement::DQM_KIND_TH1F) {
266  TH1F* hist1 = s_me->getTH1F();
267  if (hist1) {
268  nBins = s_me->getNbinsX();
269  me = dqm_store->book1D(sum_name,sum_name,nBins,
270  hist1->GetXaxis()->GetXmin(),hist1->GetXaxis()->GetXmax());
271  break;
272  }
273  }
274  }
275  }
276  }
277  }
278  // Set the axis title
279  if (me && me->kind() == MonitorElement::DQM_KIND_TH1F
280  && (htype != "sum" || htype != "Sum")) {
281  TH1F* hist = me->getTH1F();
282  if (hist) {
283  if (name.find("NoisyStrips") != std::string::npos) hist->GetYaxis()->SetTitle("Noisy Strips (%)");
284  else hist->GetYaxis()->SetTitle(name.c_str());
285 
286  for (std::map<int,std::string>::const_iterator ic = tags.begin();
287  ic != tags.end(); ic++) {
288  hist->GetXaxis()->SetBinLabel(ic->first, (ic->second).c_str());
289  }
290  hist->LabelsOption("uv");
291  }
292  }
293  return me;
294 }
295 //
296 //
297 //
298 void SiStripSummaryCreator::fillHistos(int ival, int istep, std::string htype,
299  MonitorElement* me_src, MonitorElement* me) {
300 
301  if (me->getTH1()) {
302  // TProfile* prof = 0;
303  TH1F* hist1 = 0;
304  TH2F* hist2 = 0;
305  if (me->kind() == MonitorElement::DQM_KIND_TH1F) hist1 = me->getTH1F();
306  if (me->kind() == MonitorElement::DQM_KIND_TH2F) hist2 = me->getTH2F();
307  // if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) prof = me->getTProfile();
308 
309  int nbins = me_src->getNbinsX();
310  std::string name = me_src->getName();
311  if (htype == "mean" || htype == "Mean" ) {
312  if (hist2 && name.find("NoisyStrips") != std::string::npos) {
313  float bad = 0.0;
314  float entries = me_src->getEntries();
315  if (entries > 0.0) {
316  float binEntry = entries/nbins;
317  for (int k=1; k<nbins+1; k++) {
318  float noisy = me_src->getBinContent(k,3)+me_src->getBinContent(k,5);
319  float dead = me_src->getBinContent(k,2)+me_src->getBinContent(k,4);
320 // float good = me_src->getBinContent(k,1);
321  if (noisy >= binEntry*0.5 || dead >= binEntry*0.5) bad++;
322  }
323  bad = bad*100.0/nbins;
324  me->Fill(ival, bad);
325  }
326  } else me->Fill(ival, me_src->getMean());
327  } else if (htype == "bin-by-bin" || htype == "Bin-by-Bin") {
328  for (int k=1; k<nbins+1; k++) {
329  me->setBinContent(istep+k,me_src->getBinContent(k));
330  }
331  } else if (htype == "sum" || htype == "Sum") {
332  if ( hist1) {
333  for (int k=1; k<nbins+1; k++) {
334  float val = me_src->getBinContent(k) + me->getBinContent(k) ;
335  me->setBinContent(k,val);
336  }
337  }
338  }
339  }
340 }
bool getFrequencyForSummary(int &u_freq)
const std::string & getName(void) const
get name of ME
void setBinContent(int binx, double content)
set content of bin (1-D)
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1726
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:1021
void getDocument(std::string configFile, bool UseDB=false)
Methor that parses the xml file configFile.
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:704
void setSummaryMENames(std::map< std::string, std::string > &me_names)
double isum
double getEntries(void) const
get # of entries
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
void Fill(long long x)
bool readConfiguration(std::string &file_path)
TH1 * getTH1(void) const
void createSummary(DQMStore *dqm_store)
Kind kind(void) const
Get the type of the monitor element.
std::map< std::string, std::string > summaryMEMap
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1804
tuple tags
Definition: o2o.py:248
MonitorElement * getSummaryME(DQMStore *dqm_store, std::string &name, std::string htype)
void fillHistos(int ival, int istep, std::string htype, MonitorElement *me_src, MonitorElement *me)
TH1F * getTH1F(void) const
double getBinContent(int binx) const
get content of bin (1-D)
bool getMENamesForSummary(std::map< std::string, std::string > &me_names)
int getNbinsX(void) const
get # of bins in X-axis
void goUp(void)
equivalent to &quot;cd ..&quot;
Definition: DQMStore.cc:738
tuple cout
Definition: gather_cfg.py:145
void fillSummaryHistos(DQMStore *dqm_store)
TH2F * getTH2F(void) const
void fillGrandSummaryHistos(DQMStore *dqm_store)
const std::string & pwd(void) const
Definition: DQMStore.cc:699