CMS 3D CMS Logo

DQMHistNormalizer.cc
Go to the documentation of this file.
1 
8 // framework & common header files
15 
16 //DQM services
19 
20 //Regexp handling
21 #include "classlib/utils/RegexpMatch.h"
22 #include "classlib/utils/Regexp.h"
23 
24 #include <string>
25 #include <vector>
26 #include <map>
27 
28 using namespace std;
29 
31 public:
34 
35  explicit DQMHistNormalizer(const edm::ParameterSet&);
36  ~DQMHistNormalizer() override;
37  void analyze(const edm::Event&, const edm::EventSetup&) override;
38  void endJob() override {}
39  void endRun(const edm::Run& r, const edm::EventSetup& c) override;
40 
41 private:
42  lat::Regexp* buildRegex(const string& expr);
43  vector<string> plotNamesToNormalize_; //root name used by all the plots that must be normalized
44  string reference_;
45 };
46 
48  : plotNamesToNormalize_(cfg.getParameter<std::vector<string> >("plotNamesToNormalize")),
49  reference_(cfg.getParameter<string>("reference")) {
50  //std::cout << "<DQMHistNormalizer::DQMHistNormalizer>:" << std::endl;
51 }
52 
54  //--- nothing to be done yet
55 }
56 
58  //--- nothing to be done yet
59 }
60 
61 lat::Regexp* DQMHistNormalizer::buildRegex(const string& expr) {
62  lat::Regexp* rx = nullptr;
63  try {
64  rx = new lat::Regexp(expr, 0, lat::Regexp::Wildcard);
65  rx->study();
66  } catch (lat::Error& e) {
67  throw cms::Exception("DQMHistNormalizer")
68  << "Invalid regular expression '" << expr.c_str() << "':" << e.explain().c_str();
69  }
70  return rx;
71 }
72 
74  //std::cout << "<DQMHistNormalizer::endJob>:" << std::endl;
75 
76  //--- check that DQMStore service is available
77  if (!edm::Service<DQMStore>().isAvailable()) {
78  edm::LogError("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
79  return;
80  }
81 
83 
84  vector<MonitorElement*> allOurMEs = dqmStore.getAllContents("RecoTauV/");
85  lat::Regexp* refregex = buildRegex("*RecoTauV/*/" + reference_);
86  vector<lat::Regexp*> toNormRegex;
87  for (std::vector<string>::const_iterator toNorm = plotNamesToNormalize_.begin();
88  toNorm != plotNamesToNormalize_.end();
89  ++toNorm)
90  toNormRegex.push_back(buildRegex("*RecoTauV/*/" + *toNorm));
91 
92  map<string, MonitorElement*> refsMap;
93  vector<MonitorElement*> toNormElements;
94 
95  for (vector<MonitorElement*>::const_iterator element = allOurMEs.begin(); element != allOurMEs.end(); ++element) {
96  string pathname = (*element)->getFullname();
97  //cout << pathname << endl;
98  //Matches reference
99  if (refregex->match(pathname)) {
100  //cout << "Matched to ref" << endl;
101  string dir = pathname.substr(0, pathname.rfind("/"));
102  if (refsMap.find(dir) != refsMap.end()) {
103  edm::LogInfo("DQMHistNormalizer")
104  << "DQMHistNormalizer::endRun: Warning! found multiple normalizing references for dir: " << dir << "!";
105  edm::LogInfo("DQMHistNormalizer") << " " << (refsMap[dir])->getFullname();
106  edm::LogInfo("DQMHistNormalizer") << " " << pathname;
107  } else {
108  refsMap[dir] = *element;
109  }
110  }
111 
112  //Matches targets
113  for (vector<lat::Regexp*>::const_iterator reg = toNormRegex.begin(); reg != toNormRegex.end(); ++reg) {
114  if ((*reg)->match(pathname)) {
115  //cout << "Matched to target" << endl;
116  toNormElements.push_back(*element);
117  //cout << "Filled the collection" << endl;
118  }
119  }
120  }
121 
122  delete refregex;
123  for (vector<lat::Regexp*>::const_iterator reg = toNormRegex.begin(); reg != toNormRegex.end(); ++reg)
124  delete *reg;
125 
126  for (vector<MonitorElement*>::const_iterator matchingElement = toNormElements.begin();
127  matchingElement != toNormElements.end();
128  ++matchingElement) {
129  string meName = (*matchingElement)->getFullname();
130  string dir = meName.substr(0, meName.rfind("/"));
131 
132  if (refsMap.find(dir) == refsMap.end()) {
133  edm::LogInfo("DQMHistNormalizer") << "DQMHistNormalizer::endRun: Error! normalizing references for " << meName
134  << " not found! Skipping...";
135  continue;
136  }
137 
138  float norm = refsMap[dir]->getTH1()->GetEntries();
139  TH1* hist = (*matchingElement)->getTH1();
140  if (norm != 0.) {
141  if (!hist->GetSumw2N())
142  hist->Sumw2();
143  hist->Scale(1 / norm); //use option "width" to divide the bin contents and errors by the bin width?
144  } else {
145  edm::LogInfo("DQMHistNormalizer") << "DQMHistNormalizer::endRun: Error! Normalization failed in "
146  << hist->GetTitle() << "!";
147  }
148 
149  } // for(vector<MonitorElement *>::const_iterator matchingElement = matchingElemts.begin(); matchingElement = matchingElemts.end(); ++matchingElement)
150 }
151 
Ecal2004TBTDCRanges_v1_cff.endRun
endRun
Definition: Ecal2004TBTDCRanges_v1_cff.py:4
DQMHistNormalizer::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: DQMHistNormalizer.cc:32
MessageLogger.h
DQMHistNormalizer::endRun
void endRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: DQMHistNormalizer.cc:73
BTVHLTOfflineSource_cfi.pathname
pathname
Definition: BTVHLTOfflineSource_cfi.py:28
edm::Run
Definition: Run.h:45
edm::LogInfo
Definition: MessageLogger.h:254
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
DQMHistNormalizer::~DQMHistNormalizer
~DQMHistNormalizer() override
Definition: DQMHistNormalizer.cc:53
EDAnalyzer.h
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
MakerMacros.h
DQMHistNormalizer::plotNamesToNormalize_
vector< string > plotNamesToNormalize_
Definition: DQMHistNormalizer.cc:43
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:727
compare.hist
hist
Definition: compare.py:376
Service.h
DQMHistNormalizer::reference_
string reference_
Definition: DQMHistNormalizer.cc:44
DQMHistNormalizer::buildRegex
lat::Regexp * buildRegex(const string &expr)
Definition: DQMHistNormalizer.cc:61
DQMHistNormalizer::endJob
void endJob() override
Definition: DQMHistNormalizer.cc:38
L1TBPTX_cfi.dqmStore
dqmStore
Definition: L1TBPTX_cfi.py:6
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DQMHistNormalizer::DQMHistNormalizer
DQMHistNormalizer(const edm::ParameterSet &)
Definition: DQMHistNormalizer.cc:47
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
leef::Error
edm::ErrorSummaryEntry Error
Definition: LogErrorEventFilter.cc:29
edm::Service
Definition: Service.h:30
DQMHistNormalizer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DQMHistNormalizer.cc:57
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
corrVsCorr.rx
rx
Definition: corrVsCorr.py:103
edm::EventSetup
Definition: EventSetup.h:57
DQMHistNormalizer::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: DQMHistNormalizer.cc:33
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
looper.cfg
cfg
Definition: looper.py:297
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DQMHistNormalizer
Definition: DQMHistNormalizer.cc:30
std
Definition: JetResolutionObject.h:76
jets_cff.expr
expr
Definition: jets_cff.py:449
Exception
Definition: hltDiff.cc:246
EventSetup.h
ParameterSet.h
edm::Event
Definition: Event.h:73
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37