26 #include <TDirectory.h> 27 #include <TEfficiency.h> 34 #include <boost/tokenizer.hpp> 83 std::set<std::string>*
myList,
90 : metacharacters_(
"[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]"), nonPerlWildcard_(
"\\w\\*|^\\*") {
91 boost::escaped_list_separator<char> commonEscapes(
"\\",
" \t",
"\'");
93 verbose_ =
pset.getUntrackedParameter<
unsigned int>(
"verbose", 0);
99 subDirs_ =
pset.getUntrackedParameter<std::vector<std::string>>(
"subDirs");
142 std::set<std::string> subDirSet;
164 for (std::set<std::string>::const_iterator iSubDir = subDirSet.begin(); iSubDir != subDirSet.end(); ++iSubDir) {
172 std::vector<std::string> seglist;
177 seglist.push_back(
token);
180 seglist.push_back(
name);
182 if (seglist.size() == 4 ||
185 if (seglist.at(2) ==
"GEN")
190 if (seglist.size() == 5)
194 if (seglist.at(3).rfind(
"2D", 0) == 0) {
199 opt.title = seglist.at(0) +
" " + seglist.at(1) +
" " + seglist.at(2) +
" " + seglist.at(3) +
212 opt.title = seglist.at(0) +
" " + seglist.at(1) +
" " + seglist.at(2) +
" " + seglist.at(3) +
237 efficOption.numerator,
238 efficOption.denominator);
255 <<
"Cannot find sub-directory " <<
dirName << std::endl;
267 if (!denominatorME) {
270 <<
"No denominator-ME '" << denominatorMEName <<
"' found\n";
277 <<
"No numerator-ME '" << numeratorMEName <<
"' found\n";
283 TH1* hDenominator = denominatorME->
getTH1();
284 TH1* hNumerator = numeratorME->
getTH1();
287 if (!hDenominator || !hNumerator) {
290 <<
"Cannot create TH1 from ME\n";
299 if (std::string::npos != (shiftPos = efficMEName.rfind(
'/'))) {
300 efficDir +=
"/" + efficMEName.substr(0, shiftPos);
301 newEfficMEName.erase(0, shiftPos + 1);
311 TH1* efficHist =
static_cast<TH1*
>(hDenominator->Clone(newEfficMEName.c_str()));
312 efficHist->SetDirectory(
nullptr);
313 efficHist->SetTitle(efficMETitle.c_str());
314 TClass* myHistClass = efficHist->IsA();
315 std::string histClassName = myHistClass->GetName();
316 if (histClassName ==
"TH1F") {
317 efficME = ibooker.
book1D(newEfficMEName, (TH1F*)efficHist);
318 }
else if (histClassName ==
"TH2F") {
319 efficME = ibooker.
book2D(newEfficMEName, (TH2F*)efficHist);
320 }
else if (histClassName ==
"TH3F") {
321 efficME = ibooker.
book3D(newEfficMEName, (TH3F*)efficHist);
328 <<
"Cannot book effic-ME from the DQM\n";
333 genericEff(hDenominator, hNumerator, efficME);
341 globalEfficME = ibooker.
book1D(
"globalEfficiencies",
"Global efficiencies", 1, 0, 1);
342 if (!globalEfficME) {
344 <<
"Cannot book globalEffic-ME from the DQM\n";
350 TH1F* hGlobalEffic = globalEfficME->
getTH1F();
353 <<
"Cannot create TH1F from ME, globalEfficME\n";
358 const float nDenominatorAll = hDenominator->GetEntries();
359 const float nNumeratorAll = hNumerator->GetEntries();
364 efficAll = nDenominatorAll ? nNumeratorAll / nDenominatorAll : 0;
365 errorAll = nDenominatorAll && efficAll < 1 ?
sqrt(efficAll * (1 - efficAll) / nDenominatorAll) : 0;
368 const int iBin = hGlobalEffic->Fill(newEfficMEName.c_str(), 0);
369 hGlobalEffic->SetBinContent(iBin, efficAll);
370 hGlobalEffic->SetBinError(iBin, errorAll);
379 std::set<std::string>*
myList,
380 const TString& _pattern = TString(
"")) {
381 TString patternTmp = _pattern;
385 edm::LogError(
"HLTGenValClient") <<
" HLTGenValClient::findAllSubdirectories ==> Missing folder " <<
dir <<
" !!!";
390 if (patternTmp !=
"") {
392 patternTmp.ReplaceAll(
"*",
".*");
393 TPRegexp
regexp(patternTmp);
395 std::vector<std::string> foundDirs = igetter.
getSubdirs();
396 for (
const auto& iDir : foundDirs) {
397 TString
dirName = iDir.substr(iDir.rfind(
'/') + 1, iDir.length());
411 edm::LogError(
"HLTGenValClient") <<
"Trying to find sub-directories of " <<
dir <<
" failed because " <<
dir 412 <<
" does not exist";
421 for (
int iBinX = 1; iBinX <
denom->GetNbinsX() + 1; iBinX++) {
422 for (
int iBinY = 1; iBinY <
denom->GetNbinsY() + 1; iBinY++) {
423 for (
int iBinZ = 1; iBinZ <
denom->GetNbinsZ() + 1; iBinZ++) {
424 int globalBinNum =
denom->GetBin(iBinX, iBinY, iBinZ);
427 float numerVal = numer->GetBinContent(globalBinNum);
428 float denomVal =
denom->GetBinContent(globalBinNum);
432 effVal = denomVal ? numerVal / denomVal : 0;
436 errVal = (denomVal && (effVal <= 1)) ?
sqrt(effVal * (1 - effVal) / denomVal) : 0;
std::vector< std::string > subDirs_
HLTGenValClient(const edm::ParameterSet &pset)
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
std::vector< EfficOption > efficOptions_
void computeEfficiency(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &dirName, const std::string &efficMEName, const std::string &efficMETitle, const std::string &numeratorMEName, const std::string &denominatorMEName)
const std::string separator_
void genericEff(TH1 *denom, TH1 *numer, MonitorElement *efficiencyHist)
virtual void setCurrentFolder(std::string const &fullpath)
virtual void setEntries(double nentries)
set # of entries
TPRegexp nonPerlWildcard_
virtual bool dirExists(std::string const &path) const
Log< level::Error, false > LogError
~HLTGenValClient() override
std::string outputFileName_
void makeAllPlots(DQMStore::IBooker &, DQMStore::IGetter &)
void findAllSubdirectories(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, std::string dir, std::set< std::string > *myList, const TString &pattern)
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
void dqmEndRun(DQMStore::IBooker &, DQMStore::IGetter &, edm::Run const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
virtual double getEntries() const
get # of entries
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
virtual TH1F * getTH1F() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
virtual MonitorElement * get(std::string const &fullpath) const
virtual TH1 * getTH1() const
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
MonitorElement * book3D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, FUNC onbooking=NOOP())
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const