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 endRun(const edm::Run& r, const edm::EventSetup& c) override;
39 
40 private:
41  lat::Regexp* buildRegex(const string& expr);
42  vector<string> plotNamesToNormalize_; //root name used by all the plots that must be normalized
43  string reference_;
44 };
45 
47  : plotNamesToNormalize_(cfg.getParameter<std::vector<string> >("plotNamesToNormalize")),
48  reference_(cfg.getParameter<string>("reference")) {
49  //std::cout << "<DQMHistNormalizer::DQMHistNormalizer>:" << std::endl;
50 }
51 
53  //--- nothing to be done yet
54 }
55 
57  //--- nothing to be done yet
58 }
59 
60 lat::Regexp* DQMHistNormalizer::buildRegex(const string& expr) {
61  lat::Regexp* rx = nullptr;
62  try {
63  rx = new lat::Regexp(expr, 0, lat::Regexp::Wildcard);
64  rx->study();
65  } catch (lat::Error& e) {
66  throw cms::Exception("DQMHistNormalizer")
67  << "Invalid regular expression '" << expr.c_str() << "':" << e.explain().c_str();
68  }
69  return rx;
70 }
71 
73  //std::cout << "<DQMHistNormalizer::endJob>:" << std::endl;
74 
75  //--- check that DQMStore service is available
76  if (!edm::Service<DQMStore>().isAvailable()) {
77  edm::LogError("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
78  return;
79  }
80 
82 
83  vector<MonitorElement*> allOurMEs = dqmStore.getAllContents("RecoTauV/");
84  lat::Regexp* refregex = buildRegex("*RecoTauV/*/" + reference_);
85  vector<lat::Regexp*> toNormRegex;
86  for (std::vector<string>::const_iterator toNorm = plotNamesToNormalize_.begin();
87  toNorm != plotNamesToNormalize_.end();
88  ++toNorm)
89  toNormRegex.push_back(buildRegex("*RecoTauV/*/" + *toNorm));
90 
91  map<string, MonitorElement*> refsMap;
92  vector<MonitorElement*> toNormElements;
93 
94  for (vector<MonitorElement*>::const_iterator element = allOurMEs.begin(); element != allOurMEs.end(); ++element) {
95  string pathname = (*element)->getFullname();
96  //cout << pathname << endl;
97  //Matches reference
98  if (refregex->match(pathname)) {
99  //cout << "Matched to ref" << endl;
100  string dir = pathname.substr(0, pathname.rfind("/"));
101  if (refsMap.find(dir) != refsMap.end()) {
102  edm::LogInfo("DQMHistNormalizer")
103  << "DQMHistNormalizer::endRun: Warning! found multiple normalizing references for dir: " << dir << "!";
104  edm::LogInfo("DQMHistNormalizer") << " " << (refsMap[dir])->getFullname();
105  edm::LogInfo("DQMHistNormalizer") << " " << pathname;
106  } else {
107  refsMap[dir] = *element;
108  }
109  }
110 
111  //Matches targets
112  for (vector<lat::Regexp*>::const_iterator reg = toNormRegex.begin(); reg != toNormRegex.end(); ++reg) {
113  if ((*reg)->match(pathname)) {
114  //cout << "Matched to target" << endl;
115  toNormElements.push_back(*element);
116  //cout << "Filled the collection" << endl;
117  }
118  }
119  }
120 
121  delete refregex;
122  for (vector<lat::Regexp*>::const_iterator reg = toNormRegex.begin(); reg != toNormRegex.end(); ++reg)
123  delete *reg;
124 
125  for (vector<MonitorElement*>::const_iterator matchingElement = toNormElements.begin();
126  matchingElement != toNormElements.end();
127  ++matchingElement) {
128  string meName = (*matchingElement)->getFullname();
129  string dir = meName.substr(0, meName.rfind("/"));
130 
131  if (refsMap.find(dir) == refsMap.end()) {
132  edm::LogInfo("DQMHistNormalizer") << "DQMHistNormalizer::endRun: Error! normalizing references for " << meName
133  << " not found! Skipping...";
134  continue;
135  }
136 
137  float norm = refsMap[dir]->getTH1()->GetEntries();
138  TH1* hist = (*matchingElement)->getTH1();
139  if (norm != 0.) {
140  if (!hist->GetSumw2N())
141  hist->Sumw2();
142  hist->Scale(1 / norm); //use option "width" to divide the bin contents and errors by the bin width?
143  } else {
144  edm::LogInfo("DQMHistNormalizer") << "DQMHistNormalizer::endRun: Error! Normalization failed in "
145  << hist->GetTitle() << "!";
146  }
147 
148  } // for(vector<MonitorElement *>::const_iterator matchingElement = matchingElemts.begin(); matchingElement = matchingElemts.end(); ++matchingElement)
149 }
150 
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:72
BTVHLTOfflineSource_cfi.pathname
pathname
Definition: BTVHLTOfflineSource_cfi.py:35
edm::Run
Definition: Run.h:45
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
DQMHistNormalizer::~DQMHistNormalizer
~DQMHistNormalizer() override
Definition: DQMHistNormalizer.cc:52
EDAnalyzer.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
MakerMacros.h
DQMHistNormalizer::plotNamesToNormalize_
vector< string > plotNamesToNormalize_
Definition: DQMHistNormalizer.cc:42
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:43
DQMHistNormalizer::buildRegex
lat::Regexp * buildRegex(const string &expr)
Definition: DQMHistNormalizer.cc:60
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:46
edm::ParameterSet
Definition: ParameterSet.h:47
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:56
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
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
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
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:483
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