CMS 3D CMS Logo

SiStripSummaryCreator.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 
10  edm::LogInfo("SiStripSummaryCreator") << " Creating SiStripSummaryCreator "
11  << "\n";
12 }
13 
15  edm::LogInfo("SiStripSummaryCreator") << " Deleting SiStripSummaryCreator "
16  << "\n";
17 }
18 
20  summaryMEs_.clear();
21  SiStripConfigParser config_parser;
22  config_parser.getDocument(edm::FileInPath(file_path).fullPath());
23  if (!config_parser.getFrequencyForSummary(summaryFrequency_)) {
24  std::cout << "SiStripSummaryCreator::readConfiguration: Failed to read Summary configuration parameters!! ";
25  summaryFrequency_ = -1;
26  return false;
27  }
28  if (!config_parser.getMENamesForSummary(summaryMEs_)) {
29  std::cout << "SiStripSummaryCreator::readConfiguration: Failed to read Summary configuration parameters!! ";
30  return false;
31  }
32  return true;
33 }
34 
35 void SiStripSummaryCreator::setSummaryMENames(std::map<std::string, std::string>& me_names) {
36  summaryMEs_.clear();
37  for (std::map<std::string, std::string>::const_iterator isum = me_names.begin(); isum != me_names.end(); isum++) {
38  summaryMEs_.insert(std::pair<std::string, std::string>(isum->first, isum->second));
39  }
40 }
41 
42 //
43 // -- Browse through the Folder Structure
44 //
46  if (summaryMEs_.empty())
47  return;
48  std::string currDir = dqm_store.pwd();
49  std::vector<std::string> subdirs = dqm_store.getSubdirs();
50  int nmod = 0;
51  for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
52  if ((*it).find("module_") == std::string::npos)
53  continue;
54  nmod++;
55  }
56  if (nmod > 0) {
57  fillSummaryHistos(dqm_store);
58  } else {
59  for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
60  dqm_store.cd(*it);
61  createSummary(dqm_store);
62  dqm_store.goUp();
63  }
64  fillGrandSummaryHistos(dqm_store);
65  }
66 }
67 //
68 // -- Create and Fill Summary Histograms at the lowest level of the structure
69 //
71  std::string currDir = dqm_store.pwd();
72  std::map<std::string, MonitorElement*> MEMap;
73  std::vector<std::string> subdirs = dqm_store.getSubdirs();
74  if (subdirs.empty())
75  return;
76 
77  for (std::map<std::string, std::string>::const_iterator isum = summaryMEs_.begin(); isum != summaryMEs_.end();
78  isum++) {
79  std::string name = isum->first;
80  int iBinStep = 0;
81  int ndet = 0;
82  std::string htype = isum->second;
83  for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
84  if ((*it).find("module_") == std::string::npos)
85  continue;
86  dqm_store.cd(*it);
87  ndet++;
88  std::vector<MonitorElement*> contents = dqm_store.getContents(dqm_store.pwd());
89  dqm_store.goUp();
90  for (std::vector<MonitorElement*>::const_iterator im = contents.begin(); im != contents.end(); im++) {
91  MonitorElement* me_i = (*im);
92  if (!me_i)
93  continue;
94  std::string name_i = me_i->getName();
95  if (name_i.find(name) == std::string::npos)
96  continue;
97  std::map<std::string, MonitorElement*>::iterator iPos = MEMap.find(name);
99  // Get the Summary ME
100  if (iPos == MEMap.end()) {
101  me = getSummaryME(dqm_store, name, htype);
102  MEMap.insert(std::pair<std::string, MonitorElement*>(name, me));
103  } else
104  me = iPos->second;
105  // Fill it now
106  fillHistos(ndet, iBinStep, htype, me_i, me);
107  iBinStep += me_i->getNbinsX();
108  break;
109  }
110  }
111  }
112 }
113 
114 //
115 // -- Fill Summary Histogram at higher level
116 //
118  std::map<std::string, MonitorElement*> MEMap;
119  std::string currDir = dqm_store.pwd();
120  std::string dir_name = currDir.substr(currDir.find_last_of('/') + 1);
121  if ((dir_name.find("SiStrip") == 0) || (dir_name.find("Collector") == 0) || (dir_name.find("MechanicalView") == 0) ||
122  (dir_name.find("FU") == 0))
123  return;
124  std::vector<std::string> subdirs = dqm_store.getSubdirs();
125  if (subdirs.empty())
126  return;
127  ;
128  for (std::map<std::string, std::string>::const_iterator isum = summaryMEs_.begin(); isum != summaryMEs_.end();
129  isum++) {
130  std::string name, summary_name;
131  name = isum->first;
132  if (isum->second == "sum" || isum->second == "sum")
133  summary_name = "Summary_" + isum->first;
134  else
135  summary_name = "Summary_Mean" + isum->first;
136  std::string htype = isum->second;
137  int ibinStep = 0;
138  for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
139  dqm_store.cd(*it);
140  std::vector<MonitorElement*> contents = dqm_store.getContents(dqm_store.pwd());
141  dqm_store.goUp();
142  for (std::vector<MonitorElement*>::const_iterator im = contents.begin(); im != contents.end(); im++) {
143  MonitorElement* me_i = (*im);
144  if (!me_i)
145  continue;
146  std::string name_i = me_i->getName();
147  if (name_i.find((summary_name)) != std::string::npos) {
148  std::map<std::string, MonitorElement*>::iterator iPos = MEMap.find(name);
150  if (iPos == MEMap.end()) {
151  if (htype == "sum" || htype == "Sum") {
152  me = getSummaryME(dqm_store, name, htype);
153  } else {
154  me = getSummaryME(dqm_store, name, "bin-by-bin");
155  }
156  MEMap.insert(std::pair<std::string, MonitorElement*>(name, me));
157  } else
158  me = iPos->second;
159  if (htype == "sum" || htype == "Sum") {
160  fillHistos(0, ibinStep, htype, me_i, me);
161  } else {
162  fillHistos(0, ibinStep, "bin-by-bin", me_i, me);
163  }
164  ibinStep += me_i->getNbinsX();
165  break;
166  }
167  }
168  }
169  }
170 }
171 
173  std::string& name,
174  std::string htype) {
175  MonitorElement* me = nullptr;
176  std::string currDir = dqm_store.pwd();
177  std::string sum_name, tag_name;
178 
179  std::string dname = currDir.substr(currDir.find_last_of('/') + 1);
180  if (dname.find('_') != std::string::npos)
181  dname.insert(dname.find('_'), "_");
182  if (htype == "sum" && htype == "Sum") {
183  sum_name = "Summary" + name + "__" + dname;
184  tag_name = "Summary" + name;
185  } else {
186  sum_name = "Summary_Mean" + name + "__" + dname;
187  tag_name = "Summary_Mean" + name;
188  }
189  // If already booked
190  std::vector<MonitorElement*> contents = dqm_store.getContents(currDir);
191  for (std::vector<MonitorElement*>::const_iterator im = contents.begin(); im != contents.end(); im++) {
192  MonitorElement* me = (*im);
193  if (!me)
194  continue;
195  std::string me_name = me->getName();
196  if (me_name.find(sum_name) == 0) {
197  if (me->kind() == MonitorElement::Kind::TH1F || me->kind() == MonitorElement::Kind::TH2F ||
198  me->kind() == MonitorElement::Kind::TPROFILE) {
199  TH1* hist1 = me->getTH1();
200  if (hist1) {
201  hist1->Reset();
202  return me;
203  }
204  }
205  }
206  }
207  std::map<int, std::string> tags;
208  if (!me) {
209  int nBins = 0;
210  std::vector<std::string> subdirs = dqm_store.getSubdirs();
211  // set # of bins of the histogram
212  if (htype == "mean" || htype == "Mean") {
213  nBins = subdirs.size();
214  me = dqm_store.book1D(sum_name, sum_name, nBins, 0.5, nBins + 0.5);
215  int ibin = 0;
216  for (auto const& subdir : subdirs) {
217  std::string subdir_name = subdir.substr(subdir.find_last_of('/') + 1);
218  ++ibin;
219  tags.emplace(ibin, subdir_name);
220  }
221  } else if (htype == "bin-by-bin" || htype == "Bin-by-Bin") {
222  for (auto const& subdir : subdirs) {
223  dqm_store.cd(subdir);
224  std::string subdir_name = subdir.substr(subdir.find_last_of('/') + 1);
225  auto const& s_contents = dqm_store.getContents(dqm_store.pwd());
226  for (auto const* s_me : s_contents) {
227  if (!s_me)
228  continue;
229  std::string s_me_name = s_me->getName();
230  if (s_me_name.find(name) == 0 || s_me_name.find(tag_name) == 0) {
231  int ibin = s_me->getNbinsX();
232  nBins += ibin;
233  tags.emplace(nBins - ibin / 2, subdir_name);
234  break;
235  }
236  }
237  dqm_store.goUp();
238  }
239  me = dqm_store.book1D(sum_name, sum_name, nBins, 0.5, nBins + 0.5);
240  } else if (htype == "sum" || htype == "Sum") {
241  for (auto const& subdir : subdirs) {
242  dqm_store.cd(subdir);
243  auto const& s_contents = dqm_store.getContents(dqm_store.pwd());
244  dqm_store.goUp();
245  for (auto* s_me : s_contents) {
246  if (!s_me)
247  continue;
248  std::string s_me_name = s_me->getName();
249  if (s_me_name.find(name) == std::string::npos)
250  continue;
251  if (s_me->kind() == MonitorElement::Kind::TH1F) {
252  TH1F* hist1 = s_me->getTH1F();
253  if (hist1) {
254  nBins = s_me->getNbinsX();
255  me = dqm_store.book1D(
256  sum_name, sum_name, nBins, hist1->GetXaxis()->GetXmin(), hist1->GetXaxis()->GetXmax());
257  break;
258  }
259  }
260  }
261  }
262  }
263  }
264  // Set the axis title
265  if (me && me->kind() == MonitorElement::Kind::TH1F && (htype != "sum" || htype != "Sum")) {
266  TH1F* hist = me->getTH1F();
267  if (hist) {
268  if (name.find("NoisyStrips") != std::string::npos)
269  hist->GetYaxis()->SetTitle("Noisy Strips (%)");
270  else
271  hist->GetYaxis()->SetTitle(name.c_str());
272 
273  for (auto const& [bin, label] : tags) {
274  hist->GetXaxis()->SetBinLabel(bin, label.c_str());
275  }
276  hist->LabelsOption("uv");
277  }
278  }
279  return me;
280 }
281 
283  int const ival, int const istep, std::string const htype, MonitorElement* me_src, MonitorElement* me) {
284  if (me->getTH1()) {
285  TH1F* hist1 = nullptr;
286  TH2F* hist2 = nullptr;
287  if (me->kind() == MonitorElement::Kind::TH1F)
288  hist1 = me->getTH1F();
289  if (me->kind() == MonitorElement::Kind::TH2F)
290  hist2 = me->getTH2F();
291 
292  int nbins = me_src->getNbinsX();
293  const std::string& name = me_src->getName();
294  if (htype == "mean" || htype == "Mean") {
295  if (hist2 && name.find("NoisyStrips") != std::string::npos) {
296  float bad = 0.0;
297  float entries = me_src->getEntries();
298  if (entries > 0.0) {
299  float binEntry = entries / nbins;
300  for (int k = 1; k < nbins + 1; k++) {
301  float noisy = me_src->getBinContent(k, 3) + me_src->getBinContent(k, 5);
302  float dead = me_src->getBinContent(k, 2) + me_src->getBinContent(k, 4);
303  if (noisy >= binEntry * 0.5 || dead >= binEntry * 0.5)
304  bad++;
305  }
306  bad = bad * 100.0 / nbins;
307  me->Fill(ival, bad);
308  }
309  } else
310  me->Fill(ival, me_src->getMean());
311  } else if (htype == "bin-by-bin" || htype == "Bin-by-Bin") {
312  for (int k = 1; k < nbins + 1; k++) {
313  me->setBinContent(istep + k, me_src->getBinContent(k));
314  }
315  } else if (htype == "sum" || htype == "Sum") {
316  if (hist1) {
317  for (int k = 1; k < nbins + 1; k++) {
318  float val = me_src->getBinContent(k) + me->getBinContent(k);
319  me->setBinContent(k, val);
320  }
321  }
322  }
323  }
324 }
dqm::implementation::IGetter::getContents
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:593
MessageLogger.h
SiStripSummaryCreator::fillSummaryHistos
void fillSummaryHistos(DQMStore &dqm_store)
Definition: SiStripSummaryCreator.cc:70
dqm::implementation::DQMStore::goUp
void goUp() override
Definition: DQMStore.h:566
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
MonitorElementData::Kind::TH1F
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SiStripSummaryCreator::~SiStripSummaryCreator
virtual ~SiStripSummaryCreator()
Definition: SiStripSummaryCreator.cc:14
SiStripSummaryCreator.h
SiStripSummaryCreator::SiStripSummaryCreator
SiStripSummaryCreator()
Definition: SiStripSummaryCreator.cc:9
DQMStore.h
dqm::implementation::IGetter::getSubdirs
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:700
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
SiStripSummaryCreator::summaryMEs_
std::map< std::string, std::string > summaryMEs_
Definition: SiStripSummaryCreator.h:34
MonitorElementData::Kind::TH2F
relmon_rootfiles_spy.contents
contents
Definition: relmon_rootfiles_spy.py:129
edm::FileInPath
Definition: FileInPath.h:61
dqm::legacy::DQMStore
Definition: DQMStore.h:728
SiStripConfigParser.h
SiStripSummaryCreator::readConfiguration
bool readConfiguration(std::string const &file_path)
Definition: SiStripSummaryCreator.cc:19
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
seedmultiplicitymonitor_newtracking_cfi.nBins
nBins
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
dqmdumpme.k
k
Definition: dqmdumpme.py:60
FileInPath.h
dqm::impl::MonitorElement::getEntries
virtual double getEntries() const
get # of entries
Definition: MonitorElement.cc:628
SiStripConfigParser::getFrequencyForSummary
bool getFrequencyForSummary(int &u_freq)
Definition: SiStripConfigParser.cc:46
dqm::implementation::DQMStore::pwd
std::string pwd() override
Definition: DQMStore.h:567
SiStripSummaryCreator::setSummaryMENames
void setSummaryMENames(std::map< std::string, std::string > &me_names)
Definition: SiStripSummaryCreator.cc:35
compare_using_db.dir_name
dir_name
Definition: compare_using_db.py:32
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
SiStripSummaryCreator::getSummaryME
MonitorElement * getSummaryME(DQMStore &dqm_store, std::string &name, std::string htype)
Definition: SiStripSummaryCreator.cc:172
SiStripConfigParser
Definition: SiStripConfigParser.h:19
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
SiStripSummaryCreator::summaryFrequency_
int summaryFrequency_
Definition: SiStripSummaryCreator.h:35
SiStripConfigParser::getDocument
void getDocument(std::string filepath)
Definition: SiStripConfigParser.cc:13
SiStripConfigParser::getMENamesForSummary
bool getMENamesForSummary(std::map< std::string, std::string > &me_names)
Definition: SiStripConfigParser.cc:27
heppy_batch.val
val
Definition: heppy_batch.py:351
isum
double isum
Definition: MuScleFitUtils.cc:77
SiStripSummaryCreator::fillHistos
void fillHistos(int ival, int istep, std::string htype, MonitorElement *me_src, MonitorElement *me)
Definition: SiStripSummaryCreator.cc:282
SiStripSummaryCreator::createSummary
void createSummary(DQMStore &dqm_store)
Definition: SiStripSummaryCreator.cc:45
dqm::impl::MonitorElement::getNbinsX
virtual int getNbinsX() const
get # of bins in X-axis
Definition: MonitorElement.cc:574
SiStripSummaryCreator::fillGrandSummaryHistos
void fillGrandSummaryHistos(DQMStore &dqm_store)
Definition: SiStripSummaryCreator.cc:117
dqm::impl::MonitorElement::getName
const std::string & getName() const
get name of ME
Definition: MonitorElement.h:250
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
dqm::impl::MonitorElement::getMean
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:549
RefreshWebPage.dname
dname
Definition: RefreshWebPage.py:56
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
MonitorElementData::Kind::TPROFILE
dqm::impl::MonitorElement::getBinContent
virtual double getBinContent(int binx) const
get content of bin (1-D)
Definition: MonitorElement.cc:592
label
const char * label
Definition: PFTauDecayModeTools.cc:11
dqm::implementation::DQMStore::cd
void cd() override
Definition: DQMStore.h:564
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98