CMS 3D CMS Logo

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