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

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
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

void findAllSubdirectories (std::string dir, std::set< std::string > *myList, 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
 
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

Definition at line 31 of file DQMGenericClient.h.

Constructor & Destructor Documentation

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

Definition at line 36 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.

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

Definition at line 35 of file DQMGenericClient.h.

35 {};

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 37 of file DQMGenericClient.h.

37 {};
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 372 of file DQMGenericClient.cc.

References i, and mathSSE::sqrt().

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

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

553 {
554  if ( ! theDQM->dirExists(startDir) ) {
555  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
556  LogInfo("DQMGenericClient") << "computeResolution() : "
557  << "Cannot find sub-directory " << startDir << endl;
558  }
559  return;
560  }
561 
562  theDQM->cd();
563 
564  ME* srcME = theDQM->get(startDir+"/"+srcName);
565  if ( !srcME ) {
566  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
567  LogInfo("DQMGenericClient") << "computeResolution() : "
568  << "No source ME '" << srcName << "' found\n";
569  }
570  return;
571  }
572 
573  TH2F* hSrc = srcME->getTH2F();
574  if ( !hSrc ) {
575  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
576  LogInfo("DQMGenericClient") << "computeResolution() : "
577  << "Cannot create TH2F from source-ME\n";
578  }
579  return;
580  }
581 
582  const int nBin = hSrc->GetNbinsX();
583 
584  string newDir = startDir;
585  string newPrefix = namePrefix;
586  string::size_type shiftPos;
587  if ( string::npos != (shiftPos = namePrefix.rfind('/')) ) {
588  newDir += "/"+namePrefix.substr(0, shiftPos);
589  newPrefix.erase(0, shiftPos+1);
590  }
591 
592  theDQM->setCurrentFolder(newDir);
593 
594  float * lowedgesfloats = new float[nBin+1];
595  ME* meanME;
596  ME* sigmaME;
597  if (hSrc->GetXaxis()->GetXbins()->GetSize())
598  {
599  for (int j=0; j<nBin+1; ++j)
600  lowedgesfloats[j] = (float)hSrc->GetXaxis()->GetXbins()->GetAt(j);
601  meanME = theDQM->book1D(newPrefix+"_Mean", titlePrefix+" Mean", nBin, lowedgesfloats);
602  sigmaME = theDQM->book1D(newPrefix+"_Sigma", titlePrefix+" Sigma", nBin, lowedgesfloats);
603  }
604  else
605  {
606  meanME = theDQM->book1D(newPrefix+"_Mean", titlePrefix+" Mean", nBin,
607  hSrc->GetXaxis()->GetXmin(),
608  hSrc->GetXaxis()->GetXmax());
609  sigmaME = theDQM->book1D(newPrefix+"_Sigma", titlePrefix+" Sigma", nBin,
610  hSrc->GetXaxis()->GetXmin(),
611  hSrc->GetXaxis()->GetXmax());
612  }
613 
614  if (meanME && sigmaME)
615  {
616  meanME->setEfficiencyFlag();
617  sigmaME->setEfficiencyFlag();
618 
619  if (! resLimitedFit_ ) {
620  FitSlicesYTool fitTool(srcME);
621  fitTool.getFittedMeanWithError(meanME);
622  fitTool.getFittedSigmaWithError(sigmaME);
624  } else {
625  limitedFit(srcME,meanME,sigmaME);
626  }
627  }
628  delete[] lowedgesfloats;
629 }
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
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:1468
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:493
unsigned int verbose_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void limitedFit(MonitorElement *srcME, MonitorElement *meanME, MonitorElement *sigmaME)
void DQMGenericClient::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 361 of file DQMGenericClient.cc.

References LogTrace.

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

EndRun.

Reimplemented from edm::EDAnalyzer.

Definition at line 277 of file DQMGenericClient.cc.

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

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

Definition at line 785 of file DQMGenericClient.cc.

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

785  {
786  if (!theDQM->dirExists(dir)) {
787  LogError("DQMGenericClient") << " DQMGenericClient::findAllSubdirectories ==> Missing folder " << dir << " !!!";
788  return;
789  }
790  if (pattern != "") {
791  if (pattern.Contains(nonPerlWildcard)) pattern.ReplaceAll("*",".*");
792  TPRegexp regexp(pattern);
793  theDQM->cd(dir);
794  vector <string> foundDirs = theDQM->getSubdirs();
795  for(vector<string>::const_iterator iDir = foundDirs.begin();
796  iDir != foundDirs.end(); ++iDir) {
797  TString dirName = iDir->substr(iDir->rfind('/') + 1, iDir->length());
798  if (dirName.Contains(regexp))
799  findAllSubdirectories ( *iDir, myList);
800  }
801  }
802  //std::cout << "Looking for directory " << dir ;
803  else if (theDQM->dirExists(dir)){
804  //std::cout << "... it exists! Inserting it into the list ";
805  myList->insert(dir);
806  //std::cout << "... now list has size " << myList->size() << std::endl;
807  theDQM->cd(dir);
808  findAllSubdirectories (dir, myList, "*");
809  } else {
810  //std::cout << "... DOES NOT EXIST!!! Skip bogus dir" << std::endl;
811 
812  LogInfo ("DQMGenericClient") << "Trying to find sub-directories of " << dir
813  << " failed because " << dir << " does not exist";
814 
815  }
816  return;
817 }
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1419
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
void findAllSubdirectories(std::string dir, std::set< std::string > *myList, TString pattern)
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:493
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 820 of file DQMGenericClient.cc.

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

820  {
821  for (int iBinX = 1; iBinX < denom->GetNbinsX()+1; iBinX++){
822  for (int iBinY = 1; iBinY < denom->GetNbinsY()+1; iBinY++){
823  for (int iBinZ = 1; iBinZ < denom->GetNbinsZ()+1; iBinZ++){
824 
825  int globalBinNum = denom->GetBin(iBinX, iBinY, iBinZ);
826 
827  float numerVal = numer->GetBinContent(globalBinNum);
828  float denomVal = denom->GetBinContent(globalBinNum);
829 
830  float effVal = 0;
831 
832  // fake eff is in use
833  if (type == 2 ) {
834  effVal = denomVal ? (1 - numerVal / denomVal) : 0;
835  } else {
836  effVal = denomVal ? numerVal / denomVal : 0;
837  }
838 
839  float errVal = (denomVal && (effVal <=1)) ? sqrt(effVal*(1-effVal)/denomVal) : 0;
840 
841  LogDebug ("DQMGenericClient") << "(iBinX, iBinY, iBinZ) = "
842  << iBinX << ", "
843  << iBinY << ", "
844  << iBinZ << "), global bin = " << globalBinNum
845  << "eff = " << numerVal << " / " << denomVal
846  << " = " << effVal
847  << " ... setting the error for that bin ... " << endl
848  << endl;
849 
850 
851  efficiencyHist->setBinContent(globalBinNum, effVal);
852  efficiencyHist->setBinError(globalBinNum, errVal);
853  }
854  }
855  }
856 
857  //efficiencyHist->setMinimum(0.0);
858  //efficiencyHist->setMaximum(1.0);
859 }
#define LogDebug(id)
type
Definition: HCALResponse.h:22
void setBinContent(int binx, double content)
set content of bin (1-D)
T sqrt(T t)
Definition: SSEVec.h:46
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
void DQMGenericClient::limitedFit ( MonitorElement srcME,
MonitorElement meanME,
MonitorElement sigmaME 
)

Definition at line 733 of file DQMGenericClient.cc.

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

734 {
735  TH2F * histo = srcME->getTH2F();
736 
737  static int i = 0;
738  i++;
739 
740  // Fit slices projected along Y from bins in X
741  double cont_min = 100; //Minimum number of entries
742  Int_t binx = histo->GetXaxis()->GetNbins();
743 
744  for (int i = 1; i <= binx ; i++) {
745  TString iString(i);
746  TH1 *histoY = histo->ProjectionY(" ", i, i);
747  double cont = histoY->GetEntries();
748 
749  if (cont >= cont_min) {
750  float minfit = histoY->GetMean() - histoY->GetRMS();
751  float maxfit = histoY->GetMean() + histoY->GetRMS();
752 
753  TF1 *fitFcn = new TF1(TString("g")+histo->GetName()+iString,"gaus",minfit,maxfit);
754  double x1,x2;
755  fitFcn->GetRange(x1,x2);
756 
757  histoY->Fit(fitFcn,"QR0","",x1,x2);
758 
759 // histoY->Fit(fitFcn->GetName(),"RME");
760  double *par = fitFcn->GetParameters();
761  double *err = fitFcn->GetParErrors();
762 
763  meanME->setBinContent(i, par[1]);
764  meanME->setBinError(i, err[1]);
765 // meanME->setBinEntries(i, 1.);
766 // meanME->setBinError(i,sqrt(err[1]*err[1]+par[1]*par[1]));
767 
768  sigmaME->setBinContent(i, par[2]);
769  sigmaME->setBinError(i, err[2]);
770 // sigmaME->setBinEntries(i, 1.);
771 // sigmaME->setBinError(i,sqrt(err[2]*err[2]+par[2]*par[2]));
772 
773  if(fitFcn) delete fitFcn;
774  if(histoY) delete histoY;
775  }
776  else {
777  if(histoY) delete histoY;
778  continue;
779  }
780  }
781 }
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 692 of file DQMGenericClient.cc.

References i.

693 {
694  if ( ! theDQM->dirExists(startDir) ) {
695  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
696  LogInfo("DQMGenericClient") << "makeCumulativeDist() : "
697  << "Cannot find sub-directory " << startDir << endl;
698  }
699  return;
700  }
701 
702  theDQM->cd();
703 
704  ME* element_cd = theDQM->get(startDir+"/"+cdName);
705 
706  if ( !element_cd ) {
707  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
708  LogInfo("DQMGenericClient") << "makeCumulativeDist() : "
709  << "No such element '" << cdName << "' found\n";
710  }
711  return;
712  }
713 
714  TH1F* cd = element_cd->getTH1F();
715 
716  if ( !cd ) {
717  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
718  LogInfo("DQMGenericClient") << "makeCumulativeDist() : "
719  << "Cannot create TH1F from ME\n";
720  }
721  return;
722  }
723 
724  int n_bins = cd->GetNbinsX() + 1;
725 
726  for (int i = 1; i <= n_bins; i++) {
727  cd->SetBinContent(i,cd->GetBinContent(i) + cd->GetBinContent(i-1));
728  }
729 
730  return;
731 }
int i
Definition: DBlmapReader.cc:9
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
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:1468
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:493
unsigned int verbose_
void DQMGenericClient::normalizeToEntries ( const std::string &  startDir,
const std::string &  histName,
const std::string &  normHistName 
)

Definition at line 631 of file DQMGenericClient.cc.

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

632 {
633  if ( ! theDQM->dirExists(startDir) ) {
634  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
635  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
636  << "Cannot find sub-directory " << startDir << endl;
637  }
638  return;
639  }
640 
641  theDQM->cd();
642 
643  ME* element = theDQM->get(startDir+"/"+histName);
644  ME* normME = theDQM->get(startDir+"/"+normHistName);
645 
646  if ( !element ) {
647  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
648  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
649  << "No such element '" << histName << "' found\n";
650  }
651  return;
652  }
653 
654  if ( !normME ) {
655  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
656  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
657  << "No such element '" << normHistName << "' found\n";
658  }
659  return;
660  }
661 
662  TH1F* hist = element->getTH1F();
663  if ( !hist) {
664  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
665  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
666  << "Cannot create TH1F from ME\n";
667  }
668  return;
669  }
670 
671  TH1F* normHist = normME->getTH1F();
672  if ( !normHist ) {
673  if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
674  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
675  << "Cannot create TH1F from ME\n";
676  }
677  return;
678  }
679 
680  const double entries = normHist->GetEntries();
681  if ( entries != 0 ) {
682  hist->Scale(1./entries);
683  }
684  else {
685  LogInfo("DQMGenericClient") << "normalizeToEntries() : "
686  << "Zero entries in histogram\n";
687  }
688 
689  return;
690 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
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:1468
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:493
unsigned int verbose_

Member Data Documentation

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

Definition at line 95 of file DQMGenericClient.h.

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

Definition at line 92 of file DQMGenericClient.h.

bool DQMGenericClient::isWildcardUsed_
private

Definition at line 85 of file DQMGenericClient.h.

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

Definition at line 94 of file DQMGenericClient.h.

std::string DQMGenericClient::outputFileName_
private

Definition at line 90 of file DQMGenericClient.h.

bool DQMGenericClient::resLimitedFit_
private

Definition at line 86 of file DQMGenericClient.h.

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

Definition at line 93 of file DQMGenericClient.h.

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

Definition at line 89 of file DQMGenericClient.h.

DQMStore* DQMGenericClient::theDQM
private

Definition at line 88 of file DQMGenericClient.h.

unsigned int DQMGenericClient::verbose_
private

Definition at line 84 of file DQMGenericClient.h.