CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
DQMHistNormalizer Class Reference
Inheritance diagram for DQMHistNormalizer:
edm::EDAnalyzer

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
 DQMHistNormalizer (const edm::ParameterSet &)
 
virtual void endJob ()
 
virtual void endRun (const edm::Run &r, const edm::EventSetup &c)
 
virtual ~DQMHistNormalizer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

lat::Regexp * buildRegex (const string &expr)
 

Private Attributes

vector< string > plotNamesToNormalize_
 
string reference_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Class to produce efficiency histograms by dividing nominator by denominator histograms

Date:
2012/06/18 12:31:04
Revision:
1.8
Author
Christian Veelken, UC Davis

Definition at line 38 of file DQMHistNormalizer.cc.

Constructor & Destructor Documentation

DQMHistNormalizer::DQMHistNormalizer ( const edm::ParameterSet cfg)
explicit

Definition at line 54 of file DQMHistNormalizer.cc.

54  :
55  plotNamesToNormalize_(cfg.getParameter< std::vector<string> >("plotNamesToNormalize")),
56  reference_(cfg.getParameter< string >("reference"))
57 {
58  //std::cout << "<DQMHistNormalizer::DQMHistNormalizer>:" << std::endl;
59 }
T getParameter(std::string const &) const
vector< string > plotNamesToNormalize_
DQMHistNormalizer::~DQMHistNormalizer ( )
virtual

Definition at line 61 of file DQMHistNormalizer.cc.

62 {
63 //--- nothing to be done yet
64 }

Member Function Documentation

void DQMHistNormalizer::analyze ( const edm::Event ,
const edm::EventSetup  
)
virtual

Implements edm::EDAnalyzer.

Definition at line 66 of file DQMHistNormalizer.cc.

67 {
68 //--- nothing to be done yet
69 }
lat::Regexp * DQMHistNormalizer::buildRegex ( const string &  expr)
private

Definition at line 71 of file DQMHistNormalizer.cc.

References alignCSCRings::e, raiseDQMError(), and corrVsCorr::rx.

Referenced by endRun().

72 {
73  lat::Regexp* rx = 0;
74  try
75  {
76  rx = new lat::Regexp(expr, 0, lat::Regexp::Wildcard);
77  rx->study();
78  }
79  catch (lat::Error &e)
80  {
81  raiseDQMError("DQMStore", "Invalid regular expression '%s': %s",
82  expr.c_str(), e.explain().c_str());
83  }
84  return rx;
85 }
void raiseDQMError(const char *context, const char *fmt,...)
Definition: DQMError.cc:11
virtual void DQMHistNormalizer::endJob ( void  )
inlinevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 45 of file DQMHistNormalizer.cc.

45 {}
void DQMHistNormalizer::endRun ( const edm::Run r,
const edm::EventSetup c 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 87 of file DQMHistNormalizer.cc.

References buildRegex(), dir, DQMStore::getAllContents(), estimatePileup::hist, timingPdfMaker::pathname, plotNamesToNormalize_, and reference_.

88 {
89  //std::cout << "<DQMHistNormalizer::endJob>:" << std::endl;
90 
91 //--- check that DQMStore service is available
92  if ( !edm::Service<DQMStore>().isAvailable() ) {
93  edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
94  return;
95  }
96 
97  DQMStore& dqmStore = (*edm::Service<DQMStore>());
98 
99  vector<MonitorElement *> allOurMEs = dqmStore.getAllContents("RecoTauV/");
100  lat::Regexp* refregex = buildRegex("*RecoTauV/*/" + reference_);
101  vector<lat::Regexp*> toNormRegex;
102  for ( std::vector<string>::const_iterator toNorm = plotNamesToNormalize_.begin(); toNorm != plotNamesToNormalize_.end(); ++toNorm )
103  toNormRegex.push_back( buildRegex("*RecoTauV/*/" + *toNorm) );
104 
105  map<string, MonitorElement *> refsMap;
106  vector<MonitorElement *> toNormElements;
107 
108  for(vector<MonitorElement *>::const_iterator element = allOurMEs.begin(); element != allOurMEs.end(); ++element){
109  string pathname = (*element)->getFullname();
110  //cout << pathname << endl;
111  //Matches reference
112  if(refregex->match(pathname)){
113  //cout << "Matched to ref" << endl;
114  string dir = pathname.substr(0, pathname.rfind("/"));
115  if(refsMap.find(dir) != refsMap.end()){
116  edm::LogInfo("DQMHistNormalizer")<<"DQMHistNormalizer::endRun: Warning! found multiple normalizing references for dir: "<<dir<<"!";
117  edm::LogInfo("DQMHistNormalizer")<<" " << (refsMap[dir])->getFullname();
118  edm::LogInfo("DQMHistNormalizer")<<" " << pathname;
119  }
120  else{
121  refsMap[dir] = *element;
122  }
123  }
124 
125  //Matches targets
126  for(vector<lat::Regexp*>::const_iterator reg = toNormRegex.begin(); reg != toNormRegex.end(); ++reg){
127  if((*reg)->match(pathname)){
128  //cout << "Matched to target" << endl;
129  toNormElements.push_back(*element);
130  //cout << "Filled the collection" << endl;
131  }
132  }
133  }
134 
135  delete refregex;
136  for(vector<lat::Regexp*>::const_iterator reg = toNormRegex.begin(); reg != toNormRegex.end(); ++reg)
137  delete *reg;
138 
139  for(vector<MonitorElement *>::const_iterator matchingElement = toNormElements.begin(); matchingElement != toNormElements.end(); ++matchingElement){
140  string meName = (*matchingElement)->getFullname();
141  string dir = meName.substr(0, meName.rfind("/"));
142 
143  if(refsMap.find(dir) == refsMap.end()){
144  edm::LogInfo("DQMHistNormalizer")<<"DQMHistNormalizer::endRun: Error! normalizing references for "<<meName<<" not found! Skipping...";
145  continue;
146  }
147 
148  float norm = refsMap[dir]->getTH1()->GetEntries();
149  TH1* hist = (*matchingElement)->getTH1();
150  if ( norm != 0. ) {
151  if( !hist->GetSumw2N() ) hist->Sumw2();
152  hist->Scale(1/norm);//use option "width" to divide the bin contents and errors by the bin width?
153  }else{
154  edm::LogInfo("DQMHistNormalizer")<<"DQMHistNormalizer::endRun: Error! Normalization failed in "<<hist->GetTitle()<<"!";
155  }
156 
157  }// for(vector<MonitorElement *>::const_iterator matchingElement = matchingElemts.begin(); matchingElement = matchingElemts.end(); ++matchingElement)
158 }
vector< string > plotNamesToNormalize_
std::vector< MonitorElement * > getAllContents(const std::string &path) const
Definition: DQMStore.cc:1672
lat::Regexp * buildRegex(const string &expr)
dbl *** dir
Definition: mlp_gen.cc:35

Member Data Documentation

vector<string> DQMHistNormalizer::plotNamesToNormalize_
private

Definition at line 50 of file DQMHistNormalizer.cc.

Referenced by endRun().

string DQMHistNormalizer::reference_
private

Definition at line 51 of file DQMHistNormalizer.cc.

Referenced by endRun().