#include <DQMGenericClient.h>
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. | |
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 () | |
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< CDOption > | cdOptions_ |
std::vector< EfficOption > | efficOptions_ |
bool | isWildcardUsed_ |
std::vector< NormOption > | normOptions_ |
std::string | outputFileName_ |
bool | resLimitedFit_ |
std::vector< ResolOption > | resolOptions_ |
std::vector< std::string > | subDirs_ |
DQMStore * | theDQM |
unsigned int | verbose_ |
Definition at line 31 of file DQMGenericClient.h.
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, DQMGenericClient::ResolOption::srcName, DQMGenericClient::EfficOption::title, DQMGenericClient::ResolOption::titlePrefix, EcalElecEmulTccFlatFileProducerFromTPG_cfg::tokens, and DQMGenericClient::EfficOption::type.
{ typedef std::vector<edm::ParameterSet> VPSet; typedef std::vector<std::string> vstring; typedef boost::escaped_list_separator<char> elsc; elsc commonEscapes("\\", " \t", "\'"); verbose_ = pset.getUntrackedParameter<unsigned int>("verbose", 0); // Parse efficiency commands vstring effCmds = pset.getParameter<vstring>("efficiency"); for ( vstring::const_iterator effCmd = effCmds.begin(); effCmd != effCmds.end(); ++effCmd ) { if ( effCmd->empty() ) continue; boost::tokenizer<elsc> tokens(*effCmd, commonEscapes); vector<string> args; for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin(); iToken != tokens.end(); ++iToken) { if ( iToken->empty() ) continue; args.push_back(*iToken); } if ( args.size() < 4 ) { LogInfo("DQMGenericClient") << "Wrong input to effCmds\n"; continue; } EfficOption opt; opt.name = args[0]; opt.title = args[1]; opt.numerator = args[2]; opt.denominator = args[3]; opt.isProfile = false; const string typeName = args.size() == 4 ? "eff" : args[4]; if ( typeName == "eff" ) opt.type = 1; else if ( typeName == "fake" ) opt.type = 2; else opt.type = 0; efficOptions_.push_back(opt); } VPSet efficSets = pset.getUntrackedParameter<VPSet>("efficiencySets", VPSet()); for ( VPSet::const_iterator efficSet = efficSets.begin(); efficSet != efficSets.end(); ++efficSet ) { EfficOption opt; opt.name = efficSet->getUntrackedParameter<string>("name"); opt.title = efficSet->getUntrackedParameter<string>("title"); opt.numerator = efficSet->getUntrackedParameter<string>("numerator"); opt.denominator = efficSet->getUntrackedParameter<string>("denominator"); opt.isProfile = false; const string typeName = efficSet->getUntrackedParameter<string>("typeName", "eff"); if ( typeName == "eff" ) opt.type = 1; else if ( typeName == "fake" ) opt.type = 2; else opt.type = 0; efficOptions_.push_back(opt); } // Parse profiles vstring profileCmds = pset.getUntrackedParameter<vstring>("efficiencyProfile", vstring()); for ( vstring::const_iterator profileCmd = profileCmds.begin(); profileCmd != profileCmds.end(); ++profileCmd ) { if ( profileCmd->empty() ) continue; boost::tokenizer<elsc> tokens(*profileCmd, commonEscapes); vector<string> args; for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin(); iToken != tokens.end(); ++iToken) { if ( iToken->empty() ) continue; args.push_back(*iToken); } if ( args.size() < 4 ) { LogInfo("DQMGenericClient") << "Wrong input to profileCmds\n"; continue; } EfficOption opt; opt.name = args[0]; opt.title = args[1]; opt.numerator = args[2]; opt.denominator = args[3]; opt.isProfile = true; const string typeName = args.size() == 4 ? "eff" : args[4]; if ( typeName == "eff" ) opt.type = 1; else if ( typeName == "fake" ) opt.type = 2; else opt.type = 0; efficOptions_.push_back(opt); } VPSet profileSets = pset.getUntrackedParameter<VPSet>("efficiencyProfileSets", VPSet()); for ( VPSet::const_iterator profileSet = profileSets.begin(); profileSet != profileSets.end(); ++profileSet ) { EfficOption opt; opt.name = profileSet->getUntrackedParameter<string>("name"); opt.title = profileSet->getUntrackedParameter<string>("title"); opt.numerator = profileSet->getUntrackedParameter<string>("numerator"); opt.denominator = profileSet->getUntrackedParameter<string>("denominator"); opt.isProfile = true; const string typeName = profileSet->getUntrackedParameter<string>("typeName", "eff"); if ( typeName == "eff" ) opt.type = 1; else if ( typeName == "fake" ) opt.type = 2; else opt.type = 0; efficOptions_.push_back(opt); } // Parse resolution commands vstring resCmds = pset.getParameter<vstring>("resolution"); for ( vstring::const_iterator resCmd = resCmds.begin(); resCmd != resCmds.end(); ++resCmd ) { if ( resCmd->empty() ) continue; boost::tokenizer<elsc> tokens(*resCmd, commonEscapes); vector<string> args; for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin(); iToken != tokens.end(); ++iToken) { if ( iToken->empty() ) continue; args.push_back(*iToken); } if ( args.size() != 3 ) { LogInfo("DQMGenericClient") << "Wrong input to resCmds\n"; continue; } ResolOption opt; opt.namePrefix = args[0]; opt.titlePrefix = args[1]; opt.srcName = args[2]; resolOptions_.push_back(opt); } VPSet resolSets = pset.getUntrackedParameter<VPSet>("resolutionSets", VPSet()); for ( VPSet::const_iterator resolSet = resolSets.begin(); resolSet != resolSets.end(); ++resolSet ) { ResolOption opt; opt.namePrefix = resolSet->getUntrackedParameter<string>("namePrefix"); opt.titlePrefix = resolSet->getUntrackedParameter<string>("titlePrefix"); opt.srcName = resolSet->getUntrackedParameter<string>("srcName"); resolOptions_.push_back(opt); } // Parse Normalization commands vstring normCmds = pset.getUntrackedParameter<vstring>("normalization", vstring()); for ( vstring::const_iterator normCmd = normCmds.begin(); normCmd != normCmds.end(); ++normCmd ) { if ( normCmd->empty() ) continue; boost::tokenizer<elsc> tokens(*normCmd, commonEscapes); vector<string> args; for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin(); iToken != tokens.end(); ++iToken) { if ( iToken->empty() ) continue; args.push_back(*iToken); } if ( args.empty() or args.size() > 2 ) { LogInfo("DQMGenericClient") << "Wrong input to normCmds\n"; continue; } NormOption opt; opt.name = args[0]; opt.normHistName = args.size() == 2 ? args[1] : args[0]; normOptions_.push_back(opt); } VPSet normSets = pset.getUntrackedParameter<VPSet>("normalizationSets", VPSet()); for ( VPSet::const_iterator normSet = normSets.begin(); normSet != normSets.end(); ++normSet ) { NormOption opt; opt.name = normSet->getUntrackedParameter<string>("name"); opt.normHistName = normSet->getUntrackedParameter<string>("normalizedTo", opt.name); normOptions_.push_back(opt); } // Cumulative distributions vstring cdCmds = pset.getUntrackedParameter<vstring>("cumulativeDists", vstring()); for ( vstring::const_iterator cdCmd = cdCmds.begin(); cdCmd != cdCmds.end(); ++cdCmd ) { if ( cdCmd->empty() ) continue; boost::tokenizer<elsc> tokens(*cdCmd, commonEscapes); vector<string> args; for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin(); iToken != tokens.end(); ++iToken) { if ( iToken->empty() ) continue; args.push_back(*iToken); } if ( args.size() != 1 ) { LogInfo("DQMGenericClient") << "Wrong input to cdCmds\n"; continue; } CDOption opt; opt.name = args[0]; cdOptions_.push_back(opt); } VPSet cdSets = pset.getUntrackedParameter<VPSet>("cumulativeDistSets", VPSet()); for ( VPSet::const_iterator cdSet = cdSets.begin(); cdSet != cdSets.end(); ++cdSet ) { CDOption opt; opt.name = cdSet->getUntrackedParameter<string>("name"); cdOptions_.push_back(opt); } outputFileName_ = pset.getUntrackedParameter<string>("outputFileName", ""); subDirs_ = pset.getUntrackedParameter<vstring>("subDirs"); resLimitedFit_ = pset.getUntrackedParameter<bool>("resolutionLimitedFit",false); isWildcardUsed_ = false; }
DQMGenericClient::~DQMGenericClient | ( | ) | [inline] |
Definition at line 35 of file DQMGenericClient.h.
{};
void DQMGenericClient::analyze | ( | const edm::Event & | event, |
const edm::EventSetup & | eventSetup | ||
) | [inline, virtual] |
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 |
||
) |
void DQMGenericClient::computeResolution | ( | const std::string & | startDir, |
const std::string & | fitMEPrefix, | ||
const std::string & | fitMETitlePrefix, | ||
const std::string & | srcMEName | ||
) |
void DQMGenericClient::endJob | ( | void | ) | [virtual] |
Reimplemented from edm::EDAnalyzer.
Definition at line 361 of file DQMGenericClient.cc.
References LogTrace.
{ // Update 2009-09-23 // Migrated all code from here to endRun LogTrace ("DQMGenericClient") << "inside of DQMGenericClient::endJob()" << endl; }
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(), cmsCodeRules::cppFunctionSkipper::operator, and listBenchmarks::pattern.
{ typedef vector<string> vstring; // Update 2009-09-23 // Migrated all code from endJob to this function // endJob is not necessarily called in the proper sequence // and does not necessarily book histograms produced in // that step. // It more robust to do the histogram manipulation in // this endRun function theDQM = 0; theDQM = Service<DQMStore>().operator->(); if ( ! theDQM ) { LogInfo("DQMGenericClient") << "Cannot create DQMStore instance\n"; return; } // Process wildcard in the sub-directory set<string> subDirSet; for(vstring::const_iterator iSubDir = subDirs_.begin(); iSubDir != subDirs_.end(); ++iSubDir) { string subDir = *iSubDir; if ( subDir[subDir.size()-1] == '/' ) subDir.erase(subDir.size()-1); if ( TString(subDir).Contains(metacharacters) ) { isWildcardUsed_ = true; const string::size_type shiftPos = subDir.rfind('/'); const string searchPath = subDir.substr(0, shiftPos); const string pattern = subDir.substr(shiftPos + 1, subDir.length()); //std::cout << "\n\n\n\nLooking for all subdirs of " << subDir << std::endl; findAllSubdirectories (searchPath, &subDirSet, pattern); } else { subDirSet.insert(subDir); } } for(set<string>::const_iterator iSubDir = subDirSet.begin(); iSubDir != subDirSet.end(); ++iSubDir) { const string& dirName = *iSubDir; for ( vector<EfficOption>::const_iterator efficOption = efficOptions_.begin(); efficOption != efficOptions_.end(); ++efficOption ) { computeEfficiency(dirName, efficOption->name, efficOption->title, efficOption->numerator, efficOption->denominator, efficOption->type, efficOption->isProfile); } for ( vector<ResolOption>::const_iterator resolOption = resolOptions_.begin(); resolOption != resolOptions_.end(); ++resolOption ) { computeResolution(dirName, resolOption->namePrefix, resolOption->titlePrefix, resolOption->srcName); } for ( vector<NormOption>::const_iterator normOption = normOptions_.begin(); normOption != normOptions_.end(); ++normOption ) { normalizeToEntries(dirName, normOption->name, normOption->normHistName); } for ( vector<CDOption>::const_iterator cdOption = cdOptions_.begin(); cdOption != cdOptions_.end(); ++cdOption ) { makeCumulativeDist(dirName, cdOption->name); } } //if ( verbose_ > 0 ) theDQM->showDirStructure(); if ( ! outputFileName_.empty() ) theDQM->save(outputFileName_); }
void DQMGenericClient::findAllSubdirectories | ( | std::string | dir, |
std::set< std::string > * | myList, | ||
TString | pattern = "" |
||
) | [private] |
Definition at line 759 of file DQMGenericClient.cc.
References TrackerOfflineValidation_Dqm_cff::dirName, nonPerlWildcard(), and listBenchmarks::pattern.
{ if (pattern != "") { if (pattern.Contains(nonPerlWildcard)) pattern.ReplaceAll("*",".*"); TPRegexp regexp(pattern); theDQM->cd(dir); vector <string> foundDirs = theDQM->getSubdirs(); for(vector<string>::const_iterator iDir = foundDirs.begin(); iDir != foundDirs.end(); ++iDir) { TString dirName = iDir->substr(iDir->rfind('/') + 1, iDir->length()); if (dirName.Contains(regexp)) findAllSubdirectories ( *iDir, myList); } } //std::cout << "Looking for directory " << dir ; else if (theDQM->dirExists(dir)){ //std::cout << "... it exists! Inserting it into the list "; myList->insert(dir); //std::cout << "... now list has size " << myList->size() << std::endl; theDQM->cd(dir); findAllSubdirectories (dir, myList, "*"); } else { //std::cout << "... DOES NOT EXIST!!! Skip bogus dir" << std::endl; LogInfo ("DQMGenericClient") << "Trying to find sub-directories of " << dir << " failed because " << dir << " does not exist"; } return; }
void DQMGenericClient::generic_eff | ( | TH1 * | denom, |
TH1 * | numer, | ||
MonitorElement * | efficiencyHist, | ||
const int | type = 1 |
||
) | [private] |
Definition at line 791 of file DQMGenericClient.cc.
References LogDebug, MonitorElement::setBinContent(), MonitorElement::setBinError(), and mathSSE::sqrt().
{ for (int iBinX = 1; iBinX < denom->GetNbinsX()+1; iBinX++){ for (int iBinY = 1; iBinY < denom->GetNbinsY()+1; iBinY++){ for (int iBinZ = 1; iBinZ < denom->GetNbinsZ()+1; iBinZ++){ int globalBinNum = denom->GetBin(iBinX, iBinY, iBinZ); float numerVal = numer->GetBinContent(globalBinNum); float denomVal = denom->GetBinContent(globalBinNum); float effVal = 0; // fake eff is in use if (type == 2 ) { effVal = denomVal ? (1 - numerVal / denomVal) : 0; } else { effVal = denomVal ? numerVal / denomVal : 0; } float errVal = (denomVal && (effVal <=1)) ? sqrt(effVal*(1-effVal)/denomVal) : 0; LogDebug ("DQMGenericClient") << "(iBinX, iBinY, iBinZ) = " << iBinX << ", " << iBinY << ", " << iBinZ << "), global bin = " << globalBinNum << "eff = " << numerVal << " / " << denomVal << " = " << effVal << " ... setting the error for that bin ... " << endl << endl; efficiencyHist->setBinContent(globalBinNum, effVal); efficiencyHist->setBinError(globalBinNum, errVal); } } } //efficiencyHist->setMinimum(0.0); //efficiencyHist->setMaximum(1.0); }
void DQMGenericClient::limitedFit | ( | MonitorElement * | srcME, |
MonitorElement * | meanME, | ||
MonitorElement * | sigmaME | ||
) |
Definition at line 712 of file DQMGenericClient.cc.
References cont, MonitorElement::getTH2F(), trackerHits::histo, i, Gflash::par, MonitorElement::setBinContent(), and MonitorElement::setBinError().
{ TH2F * histo = srcME->getTH2F(); static int i = 0; i++; // Fit slices projected along Y from bins in X double cont_min = 100; //Minimum number of entries Int_t binx = histo->GetXaxis()->GetNbins(); for (int i = 1; i <= binx ; i++) { TString iString(i); TH1 *histoY = histo->ProjectionY(" ", i, i); double cont = histoY->GetEntries(); if (cont >= cont_min) { float minfit = histoY->GetMean() - histoY->GetRMS(); float maxfit = histoY->GetMean() + histoY->GetRMS(); TF1 *fitFcn = new TF1(TString("g")+histo->GetName()+iString,"gaus",minfit,maxfit); double x1,x2; fitFcn->GetRange(x1,x2); histoY->Fit(fitFcn,"QR0","",x1,x2); // histoY->Fit(fitFcn->GetName(),"RME"); double *par = fitFcn->GetParameters(); double *err = fitFcn->GetParErrors(); meanME->setBinContent(i,par[1]); meanME->setBinError(i,err[1]); sigmaME->setBinContent(i,par[2]); sigmaME->setBinError(i,err[2]); if(fitFcn) delete fitFcn; if(histoY) delete histoY; } else { if(histoY) delete histoY; continue; } } }
void DQMGenericClient::makeCumulativeDist | ( | const std::string & | startDir, |
const std::string & | cdName | ||
) |
Definition at line 671 of file DQMGenericClient.cc.
References i.
{ if ( ! theDQM->dirExists(startDir) ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "makeCumulativeDist() : " << "Cannot find sub-directory " << startDir << endl; } return; } theDQM->cd(); ME* element_cd = theDQM->get(startDir+"/"+cdName); if ( !element_cd ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "makeCumulativeDist() : " << "No such element '" << cdName << "' found\n"; } return; } TH1F* cd = element_cd->getTH1F(); if ( !cd ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "makeCumulativeDist() : " << "Cannot create TH1F from ME\n"; } return; } int n_bins = cd->GetNbinsX() + 1; for (int i = 1; i <= n_bins; i++) { cd->SetBinContent(i,cd->GetBinContent(i) + cd->GetBinContent(i-1)); } return; }
void DQMGenericClient::normalizeToEntries | ( | const std::string & | startDir, |
const std::string & | histName, | ||
const std::string & | normHistName | ||
) |
Definition at line 610 of file DQMGenericClient.cc.
References python::tagInventory::entries, and estimatePileup::hist.
{ if ( ! theDQM->dirExists(startDir) ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "normalizeToEntries() : " << "Cannot find sub-directory " << startDir << endl; } return; } theDQM->cd(); ME* element = theDQM->get(startDir+"/"+histName); ME* normME = theDQM->get(startDir+"/"+normHistName); if ( !element ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "normalizeToEntries() : " << "No such element '" << histName << "' found\n"; } return; } if ( !normME ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "normalizeToEntries() : " << "No such element '" << normHistName << "' found\n"; } return; } TH1F* hist = element->getTH1F(); if ( !hist) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "normalizeToEntries() : " << "Cannot create TH1F from ME\n"; } return; } TH1F* normHist = normME->getTH1F(); if ( !normHist ) { if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) { LogInfo("DQMGenericClient") << "normalizeToEntries() : " << "Cannot create TH1F from ME\n"; } return; } const double entries = normHist->GetEntries(); if ( entries != 0 ) { hist->Scale(1./entries); } else { LogInfo("DQMGenericClient") << "normalizeToEntries() : " << "Zero entries in histogram\n"; } return; }
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.