CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
DQMGenericClient Class Reference

#include <DQMGenericClient.h>

Inheritance diagram for DQMGenericClient:
edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  CDOption
 
struct  EfficOption
 
struct  NormOption
 
struct  ResolOption
 

Public Member Functions

void analyze (const edm::Event &event, const edm::EventSetup &eventSetup)
 
void computeEfficiency (const std::string &startDir, const std::string &efficMEName, const std::string &efficMETitle, const std::string &recoMEName, const std::string &simMEName, const int type=1, const bool makeProfile=false)
 
void computeResolution (const std::string &startDir, const std::string &fitMEPrefix, const std::string &fitMETitlePrefix, const std::string &srcMEName)
 
 DQMGenericClient (const edm::ParameterSet &pset)
 
void endJob ()
 
void endRun (const edm::Run &r, const edm::EventSetup &c)
 EndRun. More...
 
void limitedFit (MonitorElement *srcME, MonitorElement *meanME, MonitorElement *sigmaME)
 
void makeCumulativeDist (const std::string &startDir, const std::string &cdName)
 
void normalizeToEntries (const std::string &startDir, const std::string &histName, const std::string &normHistName)
 
 ~DQMGenericClient ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

void findAllSubdirectories (std::string dir, std::set< std::string > *myList, const TString &pattern)
 
void generic_eff (TH1 *denom, TH1 *numer, MonitorElement *efficiencyHist, const int type=1)
 

Private Attributes

std::vector< CDOptioncdOptions_
 
std::vector< EfficOptionefficOptions_
 
bool isWildcardUsed_
 
std::vector< NormOptionnormOptions_
 
std::string outputFileName_
 
bool resLimitedFit_
 
std::vector< ResolOptionresolOptions_
 
std::vector< std::string > subDirs_
 
DQMStoretheDQM
 
unsigned int verbose_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- 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::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 29 of file DQMGenericClient.h.

Constructor & Destructor Documentation

DQMGenericClient::DQMGenericClient ( const edm::ParameterSet pset)

Definition at line 35 of file DQMGenericClient.cc.

References harvestRelVal::args, DQMGenericClient::EfficOption::denominator, genericClientPSetHelper_cff::efficSet(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), DQMGenericClient::EfficOption::isProfile, DQMGenericClient::EfficOption::name, DQMGenericClient::NormOption::name, DQMGenericClient::CDOption::name, DQMGenericClient::ResolOption::namePrefix, DQMGenericClient::NormOption::normHistName, DQMGenericClient::EfficOption::numerator, or, DQMGenericClient::ResolOption::srcName, DQMGenericClient::EfficOption::title, DQMGenericClient::ResolOption::titlePrefix, and DQMGenericClient::EfficOption::type.

36 {
37  typedef std::vector<edm::ParameterSet> VPSet;
38  typedef std::vector<std::string> vstring;
39  typedef boost::escaped_list_separator<char> elsc;
40 
41  elsc commonEscapes("\\", " \t", "\'");
42 
43  verbose_ = pset.getUntrackedParameter<unsigned int>("verbose", 0);
44 
45  // Parse efficiency commands
46  vstring effCmds = pset.getParameter<vstring>("efficiency");
47  for ( vstring::const_iterator effCmd = effCmds.begin();
48  effCmd != effCmds.end(); ++effCmd )
49  {
50  if ( effCmd->empty() ) continue;
51 
52  boost::tokenizer<elsc> tokens(*effCmd, commonEscapes);
53 
54  vector<string> args;
55  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
56  iToken != tokens.end(); ++iToken) {
57  if ( iToken->empty() ) continue;
58  args.push_back(*iToken);
59  }
60 
61  if ( args.size() < 4 ) {
62  LogInfo("DQMGenericClient") << "Wrong input to effCmds\n";
63  continue;
64  }
65 
66  EfficOption opt;
67  opt.name = args[0];
68  opt.title = args[1];
69  opt.numerator = args[2];
70  opt.denominator = args[3];
71  opt.isProfile = false;
72 
73  const string typeName = args.size() == 4 ? "eff" : args[4];
74  if ( typeName == "eff" ) opt.type = 1;
75  else if ( typeName == "fake" ) opt.type = 2;
76  else opt.type = 0;
77 
78  efficOptions_.push_back(opt);
79  }
80 
81  VPSet efficSets = pset.getUntrackedParameter<VPSet>("efficiencySets", VPSet());
82  for ( VPSet::const_iterator efficSet = efficSets.begin();
83  efficSet != efficSets.end(); ++efficSet )
84  {
85  EfficOption opt;
86  opt.name = efficSet->getUntrackedParameter<string>("name");
87  opt.title = efficSet->getUntrackedParameter<string>("title");
88  opt.numerator = efficSet->getUntrackedParameter<string>("numerator");
89  opt.denominator = efficSet->getUntrackedParameter<string>("denominator");
90  opt.isProfile = false;
91 
92  const string typeName = efficSet->getUntrackedParameter<string>("typeName", "eff");
93  if ( typeName == "eff" ) opt.type = 1;
94  else if ( typeName == "fake" ) opt.type = 2;
95  else opt.type = 0;
96 
97  efficOptions_.push_back(opt);
98  }
99 
100  // Parse profiles
101  vstring profileCmds = pset.getUntrackedParameter<vstring>("efficiencyProfile", vstring());
102  for ( vstring::const_iterator profileCmd = profileCmds.begin();
103  profileCmd != profileCmds.end(); ++profileCmd )
104  {
105  if ( profileCmd->empty() ) continue;
106 
107  boost::tokenizer<elsc> tokens(*profileCmd, commonEscapes);
108 
109  vector<string> args;
110  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
111  iToken != tokens.end(); ++iToken) {
112  if ( iToken->empty() ) continue;
113  args.push_back(*iToken);
114  }
115 
116  if ( args.size() < 4 ) {
117  LogInfo("DQMGenericClient") << "Wrong input to profileCmds\n";
118  continue;
119  }
120 
121  EfficOption opt;
122  opt.name = args[0];
123  opt.title = args[1];
124  opt.numerator = args[2];
125  opt.denominator = args[3];
126  opt.isProfile = true;
127 
128  const string typeName = args.size() == 4 ? "eff" : args[4];
129  if ( typeName == "eff" ) opt.type = 1;
130  else if ( typeName == "fake" ) opt.type = 2;
131  else opt.type = 0;
132 
133  efficOptions_.push_back(opt);
134  }
135 
136  VPSet profileSets = pset.getUntrackedParameter<VPSet>("efficiencyProfileSets", VPSet());
137  for ( VPSet::const_iterator profileSet = profileSets.begin();
138  profileSet != profileSets.end(); ++profileSet )
139  {
140  EfficOption opt;
141  opt.name = profileSet->getUntrackedParameter<string>("name");
142  opt.title = profileSet->getUntrackedParameter<string>("title");
143  opt.numerator = profileSet->getUntrackedParameter<string>("numerator");
144  opt.denominator = profileSet->getUntrackedParameter<string>("denominator");
145  opt.isProfile = true;
146 
147  const string typeName = profileSet->getUntrackedParameter<string>("typeName", "eff");
148  if ( typeName == "eff" ) opt.type = 1;
149  else if ( typeName == "fake" ) opt.type = 2;
150  else opt.type = 0;
151 
152  efficOptions_.push_back(opt);
153  }
154 
155  // Parse resolution commands
156  vstring resCmds = pset.getParameter<vstring>("resolution");
157  for ( vstring::const_iterator resCmd = resCmds.begin();
158  resCmd != resCmds.end(); ++resCmd )
159  {
160  if ( resCmd->empty() ) continue;
161  boost::tokenizer<elsc> tokens(*resCmd, commonEscapes);
162 
163  vector<string> args;
164  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
165  iToken != tokens.end(); ++iToken) {
166  if ( iToken->empty() ) continue;
167  args.push_back(*iToken);
168  }
169 
170  if ( args.size() != 3 ) {
171  LogInfo("DQMGenericClient") << "Wrong input to resCmds\n";
172  continue;
173  }
174 
175  ResolOption opt;
176  opt.namePrefix = args[0];
177  opt.titlePrefix = args[1];
178  opt.srcName = args[2];
179 
180  resolOptions_.push_back(opt);
181  }
182 
183  VPSet resolSets = pset.getUntrackedParameter<VPSet>("resolutionSets", VPSet());
184  for ( VPSet::const_iterator resolSet = resolSets.begin();
185  resolSet != resolSets.end(); ++resolSet )
186  {
187  ResolOption opt;
188  opt.namePrefix = resolSet->getUntrackedParameter<string>("namePrefix");
189  opt.titlePrefix = resolSet->getUntrackedParameter<string>("titlePrefix");
190  opt.srcName = resolSet->getUntrackedParameter<string>("srcName");
191 
192  resolOptions_.push_back(opt);
193  }
194 
195  // Parse Normalization commands
196  vstring normCmds = pset.getUntrackedParameter<vstring>("normalization", vstring());
197  for ( vstring::const_iterator normCmd = normCmds.begin();
198  normCmd != normCmds.end(); ++normCmd )
199  {
200  if ( normCmd->empty() ) continue;
201  boost::tokenizer<elsc> tokens(*normCmd, commonEscapes);
202 
203  vector<string> args;
204  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
205  iToken != tokens.end(); ++iToken) {
206  if ( iToken->empty() ) continue;
207  args.push_back(*iToken);
208  }
209 
210  if ( args.empty() or args.size() > 2 ) {
211  LogInfo("DQMGenericClient") << "Wrong input to normCmds\n";
212  continue;
213  }
214 
215  NormOption opt;
216  opt.name = args[0];
217  opt.normHistName = args.size() == 2 ? args[1] : args[0];
218 
219  normOptions_.push_back(opt);
220  }
221 
222  VPSet normSets = pset.getUntrackedParameter<VPSet>("normalizationSets", VPSet());
223  for ( VPSet::const_iterator normSet = normSets.begin();
224  normSet != normSets.end(); ++normSet )
225  {
226  NormOption opt;
227  opt.name = normSet->getUntrackedParameter<string>("name");
228  opt.normHistName = normSet->getUntrackedParameter<string>("normalizedTo", opt.name);
229 
230  normOptions_.push_back(opt);
231  }
232 
233  // Cumulative distributions
234  vstring cdCmds = pset.getUntrackedParameter<vstring>("cumulativeDists", vstring());
235  for ( vstring::const_iterator cdCmd = cdCmds.begin();
236  cdCmd != cdCmds.end(); ++cdCmd )
237  {
238  if ( cdCmd->empty() ) continue;
239  boost::tokenizer<elsc> tokens(*cdCmd, commonEscapes);
240 
241  vector<string> args;
242  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
243  iToken != tokens.end(); ++iToken) {
244  if ( iToken->empty() ) continue;
245  args.push_back(*iToken);
246  }
247 
248  if ( args.size() != 1 ) {
249  LogInfo("DQMGenericClient") << "Wrong input to cdCmds\n";
250  continue;
251  }
252 
253  CDOption opt;
254  opt.name = args[0];
255 
256  cdOptions_.push_back(opt);
257  }
258 
259  VPSet cdSets = pset.getUntrackedParameter<VPSet>("cumulativeDistSets", VPSet());
260  for ( VPSet::const_iterator cdSet = cdSets.begin();
261  cdSet != cdSets.end(); ++cdSet )
262  {
263  CDOption opt;
264  opt.name = cdSet->getUntrackedParameter<string>("name");
265 
266  cdOptions_.push_back(opt);
267  }
268 
269  outputFileName_ = pset.getUntrackedParameter<string>("outputFileName", "");
270  subDirs_ = pset.getUntrackedParameter<vstring>("subDirs");
271 
272  resLimitedFit_ = pset.getUntrackedParameter<bool>("resolutionLimitedFit",false);
273  isWildcardUsed_ = false;
274 }
std::vector< EfficOption > efficOptions_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
vector< string > vstring
Definition: ExoticaDQM.cc:75
std::vector< ResolOption > resolOptions_
std::vector< std::string > subDirs_
std::string outputFileName_
unsigned int verbose_
std::vector< CDOption > cdOptions_
dictionary args
std::vector< NormOption > normOptions_
DQMGenericClient::~DQMGenericClient ( )
inline

Definition at line 33 of file DQMGenericClient.h.

33 {};

Member Function Documentation

void DQMGenericClient::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
inlinevirtual

Implements edm::EDAnalyzer.

Definition at line 35 of file DQMGenericClient.h.

35 {};
void DQMGenericClient::computeEfficiency ( const std::string &  startDir,
const std::string &  efficMEName,
const std::string &  efficMETitle,
const std::string &  recoMEName,
const std::string &  simMEName,
const int  type = 1,
const bool  makeProfile = false 
)

Definition at line 371 of file DQMGenericClient.cc.

References i, and mathSSE::sqrt().

373 {
374  if ( ! theDQM->dirExists(startDir) ) {
375  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
376  LogInfo("DQMGenericClient") << "computeEfficiency() : "
377  << "Cannot find sub-directory " << startDir << endl;
378  }
379  return;
380  }
381 
382  theDQM->cd();
383 
384  ME* simME = theDQM->get(startDir+"/"+simMEName);
385  ME* recoME = theDQM->get(startDir+"/"+recoMEName);
386 
387  if ( !simME ) {
388  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
389  LogInfo("DQMGenericClient") << "computeEfficiency() : "
390  << "No sim-ME '" << simMEName << "' found\n";
391  }
392  return;
393  }
394 
395  if ( !recoME ) {
396  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
397  LogInfo("DQMGenericClient") << "computeEfficiency() : "
398  << "No reco-ME '" << recoMEName << "' found\n";
399  }
400  return;
401  }
402 
403  // Treat everything as the base class, TH1
404 
405  TH1* hSim = simME ->getTH1();
406  TH1* hReco = recoME->getTH1();
407 
408  if ( !hSim || !hReco ) {
409  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
410  LogInfo("DQMGenericClient") << "computeEfficiency() : "
411  << "Cannot create TH1 from ME\n";
412  }
413  return;
414  }
415 
416  string efficDir = startDir;
417  string newEfficMEName = efficMEName;
418  string::size_type shiftPos;
419  if ( string::npos != (shiftPos = efficMEName.rfind('/')) ) {
420  efficDir += "/"+efficMEName.substr(0, shiftPos);
421  newEfficMEName.erase(0, shiftPos+1);
422  }
423  theDQM->setCurrentFolder(efficDir);
424 
425  if (makeProfile) {
426  TProfile * efficHist = (hReco->GetXaxis()->GetXbins()->GetSize()==0) ?
427  new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
428  hReco->GetXaxis()->GetNbins(),
429  hReco->GetXaxis()->GetXmin(),
430  hReco->GetXaxis()->GetXmax()) :
431  new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
432  hReco->GetXaxis()->GetNbins(),
433  hReco->GetXaxis()->GetXbins()->GetArray());
434 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,0)
435  for (int i=1; i <= hReco->GetNbinsX(); i++) {
436 
437  const double nReco = hReco->GetBinContent(i);
438  const double nSim = hSim->GetBinContent(i);
439  if(nSim > INT_MAX || nSim < INT_MIN || nReco > INT_MAX || nReco < INT_MIN)
440  {
441  LogError("DQMGenericClient") << "computeEfficiency() : "
442  << "Overflow: bin content either too large or too small to be casted to int";
443  return;
444  }
445 
446  if ( nSim == 0 || nReco > nSim ) continue;
447  const double effVal = nReco/nSim;
448 
449  const double errLo = TEfficiency::ClopperPearson((int)nSim,
450  (int)nReco,
451  0.683,false);
452  const double errUp = TEfficiency::ClopperPearson((int)nSim,
453  (int)nReco,
454  0.683,true);
455  const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
456  efficHist->SetBinContent(i, effVal);
457  efficHist->SetBinEntries(i, 1);
458  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
459  }
460 #else
461  for (int i=1; i <= hReco->GetNbinsX(); i++) {
462 
463  const double nReco = hReco->GetBinContent(i);
464  const double nSim = hSim->GetBinContent(i);
465  if(nSim > INT_MAX || nSim < INT_MIN || nReco > INT_MAX || nReco < INT_MIN)
466  {
467  LogError("DQMGenericClient") << "computeEfficiency() : "
468  << "Overflow: bin content either too large or too small to be casted to int";
469  return;
470  }
471 
472  TGraphAsymmErrorsWrapper asymm;
473  std::pair<double, double> efficiencyWithError;
474  efficiencyWithError = asymm.efficiency((int)nReco,
475  (int)nSim);
476  double effVal = efficiencyWithError.first;
477  double errVal = efficiencyWithError.second;
478  if ((int)nSim > 0) {
479  efficHist->SetBinContent(i, effVal);
480  efficHist->SetBinEntries(i, 1);
481  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
482  }
483  }
484 #endif
485  theDQM->bookProfile(newEfficMEName.c_str(),efficHist);
486  delete efficHist;
487  }
488 
489  else {
490 
491  TH1* efficHist = (TH1*)hSim->Clone(newEfficMEName.c_str());
492  efficHist->SetTitle(efficMETitle.c_str());
493 
494  // Here is where you have trouble --- you need
495  // to understand what type of hist you have.
496 
497  ME* efficME = 0;
498 
499  // Parse the class name
500  // This works, but there might be a better way
501  TClass * myHistClass = efficHist->IsA();
502  TString histClassName = myHistClass->GetName();
503 
504  if (histClassName == "TH1F"){
505  efficME = theDQM->book1D(newEfficMEName, (TH1F*)efficHist);
506  } else if (histClassName == "TH2F"){
507  efficME = theDQM->book2D(newEfficMEName, (TH2F*)efficHist);
508  } else if (histClassName == "TH3F"){
509  efficME = theDQM->book3D(newEfficMEName, (TH3F*)efficHist);
510  }
511 
512 
513  if ( !efficME ) {
514  LogInfo("DQMGenericClient") << "computeEfficiency() : "
515  << "Cannot book effic-ME from the DQM\n";
516  return;
517  }
518 
519  // Update: 2009-9-16 slaunwhj
520  // call the most generic efficiency function
521  // works up to 3-d histograms
522 
523  generic_eff (hSim, hReco, efficME, type);
524 
525  // const int nBin = efficME->getNbinsX();
526  // for(int bin = 0; bin <= nBin; ++bin) {
527  // const float nSim = simME ->getBinContent(bin);
528  // const float nReco = recoME->getBinContent(bin);
529  // float eff =0;
530  // if (type=="fake")eff = nSim ? 1-nReco/nSim : 0.;
531  // else eff= nSim ? nReco/nSim : 0.;
532  // const float err = nSim && eff <= 1 ? sqrt(eff*(1-eff)/nSim) : 0.;
533  // efficME->setBinContent(bin, eff);
534  // efficME->setBinError(bin, err);
535  // }
536  efficME->setEntries(simME->getEntries());
537 
538  }
539 
540  // Global efficiency
541  ME* globalEfficME = theDQM->get(efficDir+"/globalEfficiencies");
542  if ( !globalEfficME ) globalEfficME = theDQM->book1D("globalEfficiencies", "Global efficiencies", 1, 0, 1);
543  if ( !globalEfficME ) {
544  LogInfo("DQMGenericClient") << "computeEfficiency() : "
545  << "Cannot book globalEffic-ME from the DQM\n";
546  return;
547  }
548  TH1F* hGlobalEffic = globalEfficME->getTH1F();
549  if ( !hGlobalEffic ) {
550  LogInfo("DQMGenericClient") << "computeEfficiency() : "
551  << "Cannot create TH1F from ME, globalEfficME\n";
552  return;
553  }
554 
555  const float nSimAll = hSim->GetEntries();
556  const float nRecoAll = hReco->GetEntries();
557  float efficAll=0;
558  if ( type == 1 ) efficAll = nSimAll ? nRecoAll/nSimAll : 0;
559  else if ( type == 2 ) efficAll = nSimAll ? 1-nRecoAll/nSimAll : 0;
560  const float errorAll = nSimAll && efficAll < 1 ? sqrt(efficAll*(1-efficAll)/nSimAll) : 0;
561 
562  const int iBin = hGlobalEffic->Fill(newEfficMEName.c_str(), 0);
563  hGlobalEffic->SetBinContent(iBin, efficAll);
564  hGlobalEffic->SetBinError(iBin, errorAll);
565 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
MonitorElement * book3D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ)
Book 3D histogram.
Definition: DQMStore.cc:1134
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
uint16_t size_type
Definition: ME.h:11
T sqrt(T t)
Definition: SSEVec.h:48
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1186
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:648
unsigned int verbose_
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1000
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
void generic_eff(TH1 *denom, TH1 *numer, MonitorElement *efficiencyHist, const int type=1)
void DQMGenericClient::computeResolution ( const std::string &  startDir,
const std::string &  fitMEPrefix,
const std::string &  fitMETitlePrefix,
const std::string &  srcMEName 
)

Definition at line 567 of file DQMGenericClient.cc.

References FitSlicesYTool::getFittedMeanWithError(), FitSlicesYTool::getFittedSigmaWithError(), and j.

569 {
570  if ( ! theDQM->dirExists(startDir) ) {
571  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
572  LogInfo("DQMGenericClient") << "computeResolution() : "
573  << "Cannot find sub-directory " << startDir << endl;
574  }
575  return;
576  }
577 
578  theDQM->cd();
579 
580  ME* srcME = theDQM->get(startDir+"/"+srcName);
581  if ( !srcME ) {
582  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
583  LogInfo("DQMGenericClient") << "computeResolution() : "
584  << "No source ME '" << srcName << "' found\n";
585  }
586  return;
587  }
588 
589  TH2F* hSrc = srcME->getTH2F();
590  if ( !hSrc ) {
591  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
592  LogInfo("DQMGenericClient") << "computeResolution() : "
593  << "Cannot create TH2F from source-ME\n";
594  }
595  return;
596  }
597 
598  const int nBin = hSrc->GetNbinsX();
599 
600  string newDir = startDir;
601  string newPrefix = namePrefix;
602  string::size_type shiftPos;
603  if ( string::npos != (shiftPos = namePrefix.rfind('/')) ) {
604  newDir += "/"+namePrefix.substr(0, shiftPos);
605  newPrefix.erase(0, shiftPos+1);
606  }
607 
608  theDQM->setCurrentFolder(newDir);
609 
610  float * lowedgesfloats = new float[nBin+1];
611  ME* meanME;
612  ME* sigmaME;
613  if (hSrc->GetXaxis()->GetXbins()->GetSize())
614  {
615  for (int j=0; j<nBin+1; ++j)
616  lowedgesfloats[j] = (float)hSrc->GetXaxis()->GetXbins()->GetAt(j);
617  meanME = theDQM->book1D(newPrefix+"_Mean", titlePrefix+" Mean", nBin, lowedgesfloats);
618  sigmaME = theDQM->book1D(newPrefix+"_Sigma", titlePrefix+" Sigma", nBin, lowedgesfloats);
619  }
620  else
621  {
622  meanME = theDQM->book1D(newPrefix+"_Mean", titlePrefix+" Mean", nBin,
623  hSrc->GetXaxis()->GetXmin(),
624  hSrc->GetXaxis()->GetXmax());
625  sigmaME = theDQM->book1D(newPrefix+"_Sigma", titlePrefix+" Sigma", nBin,
626  hSrc->GetXaxis()->GetXmin(),
627  hSrc->GetXaxis()->GetXmax());
628  }
629 
630  if (meanME && sigmaME)
631  {
632  meanME->setEfficiencyFlag();
633  sigmaME->setEfficiencyFlag();
634 
635  if (! resLimitedFit_ ) {
636  FitSlicesYTool fitTool(srcME);
637  fitTool.getFittedMeanWithError(meanME);
638  fitTool.getFittedSigmaWithError(sigmaME);
640  } else {
641  limitedFit(srcME,meanME,sigmaME);
642  }
643  }
644  delete[] lowedgesfloats;
645 }
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
uint16_t size_type
Definition: ME.h:11
int j
Definition: DBlmapReader.cc:9
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:648
unsigned int verbose_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
void limitedFit(MonitorElement *srcME, MonitorElement *meanME, MonitorElement *sigmaME)
void DQMGenericClient::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 360 of file DQMGenericClient.cc.

References LogTrace.

361 {
362 
363  // Update 2009-09-23
364  // Migrated all code from here to endRun
365 
366  LogTrace ("DQMGenericClient") << "inside of DQMGenericClient::endJob()"
367  << endl;
368 
369 }
#define LogTrace(id)
void DQMGenericClient::endRun ( const edm::Run r,
const edm::EventSetup c 
)
virtual

EndRun.

Reimplemented from edm::EDAnalyzer.

Definition at line 276 of file DQMGenericClient.cc.

References TrackerOfflineValidation_Dqm_cff::dirName, metacharacters(), cppFunctionSkipper::operator, and listBenchmarks::pattern.

276  {
277 
278  typedef vector<string> vstring;
279 
280  // Update 2009-09-23
281  // Migrated all code from endJob to this function
282  // endJob is not necessarily called in the proper sequence
283  // and does not necessarily book histograms produced in
284  // that step.
285  // It more robust to do the histogram manipulation in
286  // this endRun function
287 
288 
289 
290  theDQM = 0;
292 
293  if ( ! theDQM ) {
294  LogInfo("DQMGenericClient") << "Cannot create DQMStore instance\n";
295  return;
296  }
297 
298  // Process wildcard in the sub-directory
299  set<string> subDirSet;
300 
301  for(vstring::const_iterator iSubDir = subDirs_.begin();
302  iSubDir != subDirs_.end(); ++iSubDir) {
303  string subDir = *iSubDir;
304 
305  if ( subDir[subDir.size()-1] == '/' ) subDir.erase(subDir.size()-1);
306 
307  if ( TString(subDir).Contains(metacharacters) ) {
308  isWildcardUsed_ = true;
309 
310  const string::size_type shiftPos = subDir.rfind('/');
311  const string searchPath = subDir.substr(0, shiftPos);
312  const string pattern = subDir.substr(shiftPos + 1, subDir.length());
313  //std::cout << "\n\n\n\nLooking for all subdirs of " << subDir << std::endl;
314 
315  findAllSubdirectories (searchPath, &subDirSet, pattern);
316 
317  }
318  else {
319  subDirSet.insert(subDir);
320  }
321  }
322 
323  for(set<string>::const_iterator iSubDir = subDirSet.begin();
324  iSubDir != subDirSet.end(); ++iSubDir) {
325  const string& dirName = *iSubDir;
326 
327  for ( vector<EfficOption>::const_iterator efficOption = efficOptions_.begin();
328  efficOption != efficOptions_.end(); ++efficOption )
329  {
330  computeEfficiency(dirName, efficOption->name, efficOption->title,
331  efficOption->numerator, efficOption->denominator,
332  efficOption->type, efficOption->isProfile);
333  }
334 
335  for ( vector<ResolOption>::const_iterator resolOption = resolOptions_.begin();
336  resolOption != resolOptions_.end(); ++resolOption )
337  {
338  computeResolution(dirName, resolOption->namePrefix, resolOption->titlePrefix, resolOption->srcName);
339  }
340 
341  for ( vector<NormOption>::const_iterator normOption = normOptions_.begin();
342  normOption != normOptions_.end(); ++normOption )
343  {
344  normalizeToEntries(dirName, normOption->name, normOption->normHistName);
345  }
346 
347  for ( vector<CDOption>::const_iterator cdOption = cdOptions_.begin();
348  cdOption != cdOptions_.end(); ++cdOption )
349  {
350  makeCumulativeDist(dirName, cdOption->name);
351  }
352  }
353 
354  //if ( verbose_ > 0 ) theDQM->showDirStructure();
355 
356  if ( ! outputFileName_.empty() ) theDQM->save(outputFileName_);
357 
358 }
std::vector< EfficOption > efficOptions_
vector< string > vstring
Definition: ExoticaDQM.cc:75
TPRegexp metacharacters("[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]")
void makeCumulativeDist(const std::string &startDir, const std::string &cdName)
uint16_t size_type
std::vector< ResolOption > resolOptions_
std::vector< std::string > subDirs_
void computeResolution(const std::string &startDir, const std::string &fitMEPrefix, const std::string &fitMETitlePrefix, const std::string &srcMEName)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
std::string outputFileName_
void findAllSubdirectories(std::string dir, std::set< std::string > *myList, const TString &pattern)
std::vector< CDOption > cdOptions_
void computeEfficiency(const std::string &startDir, const std::string &efficMEName, const std::string &efficMETitle, const std::string &recoMEName, const std::string &simMEName, const int type=1, const bool makeProfile=false)
void normalizeToEntries(const std::string &startDir, const std::string &histName, const std::string &normHistName)
std::vector< NormOption > normOptions_
void DQMGenericClient::findAllSubdirectories ( std::string  dir,
std::set< std::string > *  myList,
const TString &  pattern = TString("") 
)
private

Definition at line 801 of file DQMGenericClient.cc.

References TrackerOfflineValidation_Dqm_cff::dirName, nonPerlWildcard(), and listBenchmarks::pattern.

801  {
802  TString pattern = _pattern;
803  if (!theDQM->dirExists(dir)) {
804  LogError("DQMGenericClient") << " DQMGenericClient::findAllSubdirectories ==> Missing folder " << dir << " !!!";
805  return;
806  }
807  if (pattern != "") {
808  if (pattern.Contains(nonPerlWildcard)) pattern.ReplaceAll("*",".*");
809  TPRegexp regexp(pattern);
810  theDQM->cd(dir);
811  vector <string> foundDirs = theDQM->getSubdirs();
812  for(vector<string>::const_iterator iDir = foundDirs.begin();
813  iDir != foundDirs.end(); ++iDir) {
814  TString dirName = iDir->substr(iDir->rfind('/') + 1, iDir->length());
815  if (dirName.Contains(regexp))
816  findAllSubdirectories ( *iDir, myList);
817  }
818  }
819  //std::cout << "Looking for directory " << dir ;
820  else if (theDQM->dirExists(dir)){
821  //std::cout << "... it exists! Inserting it into the list ";
822  myList->insert(dir);
823  //std::cout << "... now list has size " << myList->size() << std::endl;
824  theDQM->cd(dir);
826  } else {
827  //std::cout << "... DOES NOT EXIST!!! Skip bogus dir" << std::endl;
828 
829  LogInfo ("DQMGenericClient") << "Trying to find sub-directories of " << dir
830  << " failed because " << dir << " does not exist";
831 
832  }
833  return;
834 }
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1574
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:648
void findAllSubdirectories(std::string dir, std::set< std::string > *myList, const TString &pattern)
TPRegexp nonPerlWildcard("\\w\\*|^\\*")
dbl *** dir
Definition: mlp_gen.cc:35
void DQMGenericClient::generic_eff ( TH1 *  denom,
TH1 *  numer,
MonitorElement efficiencyHist,
const int  type = 1 
)
private

Definition at line 837 of file DQMGenericClient.cc.

References LogDebug, MonitorElement::setBinContent(), MonitorElement::setBinError(), MonitorElement::setEfficiencyFlag(), and mathSSE::sqrt().

837  {
838  for (int iBinX = 1; iBinX < denom->GetNbinsX()+1; iBinX++){
839  for (int iBinY = 1; iBinY < denom->GetNbinsY()+1; iBinY++){
840  for (int iBinZ = 1; iBinZ < denom->GetNbinsZ()+1; iBinZ++){
841 
842  int globalBinNum = denom->GetBin(iBinX, iBinY, iBinZ);
843 
844  float numerVal = numer->GetBinContent(globalBinNum);
845  float denomVal = denom->GetBinContent(globalBinNum);
846 
847  float effVal = 0;
848 
849  // fake eff is in use
850  if (type == 2 ) {
851  effVal = denomVal ? (1 - numerVal / denomVal) : 0;
852  } else {
853  effVal = denomVal ? numerVal / denomVal : 0;
854  }
855 
856  float errVal = (denomVal && (effVal <=1)) ? sqrt(effVal*(1-effVal)/denomVal) : 0;
857 
858  LogDebug ("DQMGenericClient") << "(iBinX, iBinY, iBinZ) = "
859  << iBinX << ", "
860  << iBinY << ", "
861  << iBinZ << "), global bin = " << globalBinNum
862  << "eff = " << numerVal << " / " << denomVal
863  << " = " << effVal
864  << " ... setting the error for that bin ... " << endl
865  << endl;
866 
867 
868  efficiencyHist->setBinContent(globalBinNum, effVal);
869  efficiencyHist->setBinError(globalBinNum, errVal);
870  efficiencyHist->setEfficiencyFlag();
871  }
872  }
873  }
874 
875  //efficiencyHist->setMinimum(0.0);
876  //efficiencyHist->setMaximum(1.0);
877 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
void setBinContent(int binx, double content)
set content of bin (1-D)
T sqrt(T t)
Definition: SSEVec.h:48
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
void setEfficiencyFlag(void)
void DQMGenericClient::limitedFit ( MonitorElement srcME,
MonitorElement meanME,
MonitorElement sigmaME 
)

Definition at line 749 of file DQMGenericClient.cc.

References cont, MonitorElement::getTH2F(), timingPdfMaker::histo, i, MonitorElement::setBinContent(), and MonitorElement::setBinError().

750 {
751  TH2F * histo = srcME->getTH2F();
752 
753  static int i = 0;
754  i++;
755 
756  // Fit slices projected along Y from bins in X
757  double cont_min = 100; //Minimum number of entries
758  Int_t binx = histo->GetXaxis()->GetNbins();
759 
760  for (int i = 1; i <= binx ; i++) {
761  TString iString(i);
762  TH1 *histoY = histo->ProjectionY(" ", i, i);
763  double cont = histoY->GetEntries();
764 
765  if (cont >= cont_min) {
766  float minfit = histoY->GetMean() - histoY->GetRMS();
767  float maxfit = histoY->GetMean() + histoY->GetRMS();
768 
769  TF1 *fitFcn = new TF1(TString("g")+histo->GetName()+iString,"gaus",minfit,maxfit);
770  double x1,x2;
771  fitFcn->GetRange(x1,x2);
772 
773  histoY->Fit(fitFcn,"QR0","",x1,x2);
774 
775 // histoY->Fit(fitFcn->GetName(),"RME");
776  double *par = fitFcn->GetParameters();
777  double *err = fitFcn->GetParErrors();
778 
779  meanME->setBinContent(i, par[1]);
780  meanME->setBinError(i, err[1]);
781 // meanME->setBinEntries(i, 1.);
782 // meanME->setBinError(i,sqrt(err[1]*err[1]+par[1]*par[1]));
783 
784  sigmaME->setBinContent(i, par[2]);
785  sigmaME->setBinError(i, err[2]);
786 // sigmaME->setBinEntries(i, 1.);
787 // sigmaME->setBinError(i,sqrt(err[2]*err[2]+par[2]*par[2]));
788 
789  if(fitFcn) delete fitFcn;
790  if(histoY) delete histoY;
791  }
792  else {
793  if(histoY) delete histoY;
794  continue;
795  }
796  }
797 }
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
int cont
TH2F * getTH2F(void) const
void DQMGenericClient::makeCumulativeDist ( const std::string &  startDir,
const std::string &  cdName 
)

Definition at line 708 of file DQMGenericClient.cc.

References i.

709 {
710  if ( ! theDQM->dirExists(startDir) ) {
711  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
712  LogInfo("DQMGenericClient") << "makeCumulativeDist() : "
713  << "Cannot find sub-directory " << startDir << endl;
714  }
715  return;
716  }
717 
718  theDQM->cd();
719 
720  ME* element_cd = theDQM->get(startDir+"/"+cdName);
721 
722  if ( !element_cd ) {
723  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
724  LogInfo("DQMGenericClient") << "makeCumulativeDist() : "
725  << "No such element '" << cdName << "' found\n";
726  }
727  return;
728  }
729 
730  TH1F* cd = element_cd->getTH1F();
731 
732  if ( !cd ) {
733  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
734  LogInfo("DQMGenericClient") << "makeCumulativeDist() : "
735  << "Cannot create TH1F from ME\n";
736  }
737  return;
738  }
739 
740  int n_bins = cd->GetNbinsX() + 1;
741 
742  for (int i = 1; i <= n_bins; i++) {
743  cd->SetBinContent(i,cd->GetBinContent(i) + cd->GetBinContent(i-1));
744  }
745 
746  return;
747 }
int i
Definition: DBlmapReader.cc:9
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
Definition: ME.h:11
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:648
unsigned int verbose_
void DQMGenericClient::normalizeToEntries ( const std::string &  startDir,
const std::string &  histName,
const std::string &  normHistName 
)

Definition at line 647 of file DQMGenericClient.cc.

References python.tagInventory::entries, and estimatePileup::hist.

648 {
649  if ( ! theDQM->dirExists(startDir) ) {
650  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
651  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
652  << "Cannot find sub-directory " << startDir << endl;
653  }
654  return;
655  }
656 
657  theDQM->cd();
658 
659  ME* element = theDQM->get(startDir+"/"+histName);
660  ME* normME = theDQM->get(startDir+"/"+normHistName);
661 
662  if ( !element ) {
663  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
664  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
665  << "No such element '" << histName << "' found\n";
666  }
667  return;
668  }
669 
670  if ( !normME ) {
671  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
672  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
673  << "No such element '" << normHistName << "' found\n";
674  }
675  return;
676  }
677 
678  TH1F* hist = element->getTH1F();
679  if ( !hist) {
680  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
681  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
682  << "Cannot create TH1F from ME\n";
683  }
684  return;
685  }
686 
687  TH1F* normHist = normME->getTH1F();
688  if ( !normHist ) {
689  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
690  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
691  << "Cannot create TH1F from ME\n";
692  }
693  return;
694  }
695 
696  const double entries = normHist->GetEntries();
697  if ( entries != 0 ) {
698  hist->Scale(1./entries);
699  }
700  else {
701  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
702  << "Zero entries in histogram\n";
703  }
704 
705  return;
706 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
Definition: ME.h:11
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:648
unsigned int verbose_

Member Data Documentation

std::vector<CDOption> DQMGenericClient::cdOptions_
private

Definition at line 93 of file DQMGenericClient.h.

std::vector<EfficOption> DQMGenericClient::efficOptions_
private

Definition at line 90 of file DQMGenericClient.h.

bool DQMGenericClient::isWildcardUsed_
private

Definition at line 83 of file DQMGenericClient.h.

std::vector<NormOption> DQMGenericClient::normOptions_
private

Definition at line 92 of file DQMGenericClient.h.

std::string DQMGenericClient::outputFileName_
private

Definition at line 88 of file DQMGenericClient.h.

bool DQMGenericClient::resLimitedFit_
private

Definition at line 84 of file DQMGenericClient.h.

std::vector<ResolOption> DQMGenericClient::resolOptions_
private

Definition at line 91 of file DQMGenericClient.h.

std::vector<std::string> DQMGenericClient::subDirs_
private

Definition at line 87 of file DQMGenericClient.h.

DQMStore* DQMGenericClient::theDQM
private

Definition at line 86 of file DQMGenericClient.h.

unsigned int DQMGenericClient::verbose_
private

Definition at line 82 of file DQMGenericClient.h.