CMS 3D CMS Logo

HLTMuonRefMethod.cc
Go to the documentation of this file.
5 
8 
10 
13 
14 #include <set>
15 #include <string>
16 #include <vector>
17 #include <TPRegexp.h>
18 #include <cmath>
19 #include <climits>
20 #include <boost/tokenizer.hpp>
21 #include <boost/regex.hpp>
22 
23 #include <TH1.h>
24 #include <TEfficiency.h>
25 
26 using namespace edm;
27 using namespace std;
28 
30 public:
31  explicit HLTMuonRefMethod(const edm::ParameterSet& set);
32  ~HLTMuonRefMethod() override = default;
33  ;
34 
35  void beginJob() override;
36  void beginRun(const edm::Run&, const edm::EventSetup&) override;
37  void dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter&) override;
38 
39 private:
40  // DQMStore* theDQM;
41 
42  std::vector<std::string> subDirs_;
43  std::vector<std::string> hltTriggers_;
44  std::vector<std::string> efficiency_;
45  std::vector<std::string> refEff_;
47 
49 
50  void findAllSubdirectories(DQMStore::IBooker& ibooker,
51  DQMStore::IGetter& igetter,
52  const std::string& dir,
53  std::set<std::string>* myList,
54  const TString& pattern);
55 };
56 
58  using VPSet = std::vector<edm::ParameterSet>;
59  using vstring = std::vector<std::string>;
60  using elsc = boost::escaped_list_separator<char>;
61 
62  subDirs_ = pset.getUntrackedParameter<vstring>("subDirs");
63  hltTriggers_ = pset.getUntrackedParameter<vstring>("hltTriggers");
64  refTriggers_ = pset.getUntrackedParameter<string>("refTriggers");
65  efficiency_ = pset.getUntrackedParameter<vstring>("efficiency");
66  refEff_ = pset.getUntrackedParameter<vstring>("refEff");
67 }
68 
70 
72  using vstring = std::vector<std::string>;
73  boost::regex metacharacters{"[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]"};
74  boost::smatch what;
75 
76  // theDQM = 0;
77  // theDQM = Service<DQMStore>().operator->();
78 
79  ibooker.cd();
80  set<string> subDirSet;
81 
82  for (auto iSubDir = subDirs_.begin(); iSubDir != subDirs_.end(); ++iSubDir) {
83  string subDir = *iSubDir;
84 
85  if (subDir[subDir.size() - 1] == '/')
86  subDir.erase(subDir.size() - 1);
87 
88  if (boost::regex_search(subDir, what, metacharacters)) {
89  const string::size_type shiftPos = subDir.rfind('/');
90  const string searchPath = subDir.substr(0, shiftPos);
91  const string pattern = subDir.substr(shiftPos + 1, subDir.length());
92  //std::cout << "\n\n\n\nLooking for all subdirs of " << subDir << std::endl;
93 
94  findAllSubdirectories(ibooker, igetter, searchPath, &subDirSet, pattern);
95 
96  } else {
97  subDirSet.insert(subDir);
98  }
99  }
100 
101  for (auto const& subDir : subDirSet) {
102  for (unsigned int iEff = 0; iEff != efficiency_.size(); ++iEff) {
103  string eff = efficiency_[iEff];
104 
105  // Getting reference trigger efficiency
106  MonitorElement* refEff = igetter.get(subDir + "/" + refTriggers_ + "/" + refEff_[iEff]);
107 
108  if (!refEff)
109  continue;
110 
111  // looping over all reference triggers
112  for (auto iTrigger = hltTriggers_.begin(); iTrigger != hltTriggers_.end(); ++iTrigger) {
113  string trig = *iTrigger;
114  MonitorElement* trigEff = igetter.get(subDir + "/" + trig + "/" + eff);
115  if (!trigEff)
116  continue;
117  TH1* hRef = refEff->getTH1();
118  TH1* hTrig = trigEff->getTH1();
119  TH1* hEff = (TH1*)hTrig->Clone(("eff_" + eff + "_ref").c_str());
120  hEff->SetTitle("Efficiency obtained with reference method");
121  TClass* myHistClass = hTrig->IsA();
122  TString histClassName = myHistClass->GetName();
123 
124  if (histClassName == "TH1F") {
125  for (int bin = 0; bin < hEff->GetNbinsX(); ++bin) {
126  hEff->SetBinContent(bin + 1, hEff->GetBinContent(bin + 1) * hRef->GetBinContent(bin + 1));
127  hEff->SetBinError(bin + 1,
128  hEff->GetBinContent(bin + 1) * hRef->GetBinError(bin + 1) +
129  hEff->GetBinError(bin + 1) * hRef->GetBinContent(bin + 1));
130  }
131  ibooker.cd(subDir + "/" + trig);
132  ibooker.book1D(hEff->GetName(), (TH1F*)hEff);
133 
134  } else if (histClassName == "TH2F") {
135  for (int i = 0; i < hRef->GetXaxis()->GetNbins(); ++i) {
136  for (int j = 0; j < hRef->GetYaxis()->GetNbins(); ++j) {
137  int bin = hEff->GetBin(i + 1, j + 1);
138  hEff->SetBinContent(bin, hRef->GetBinContent(i + 1, j + 1) * hTrig->GetBinContent(i + 1));
139  }
140  }
141  ibooker.cd(subDir + "/" + trig);
142  ibooker.book2D(hEff->GetName(), (TH2F*)hEff);
143  } else {
144  LogInfo("HLTMuonRefMethod") << "Histo class type << " << histClassName << " not implemented";
145  }
146 
147  delete hEff;
148  }
149  }
150  }
151 }
152 
154 
156  DQMStore::IGetter& igetter,
157  const std::string& dir,
158  std::set<std::string>* myList,
159  const TString& _pattern = TString("")) {
160  TString pattern = _pattern;
161  TPRegexp nonPerlWildcard("\\w\\*|^\\*");
162 
163  if (!igetter.dirExists(dir)) {
164  LogError("DQMGenericClient") << " DQMGenericClient::findAllSubdirectories ==> Missing folder " << dir << " !!!";
165  return;
166  }
167  if (pattern != "") {
168  if (pattern.Contains(nonPerlWildcard))
169  pattern.ReplaceAll("*", ".*");
170  TPRegexp regexp(pattern);
171  ibooker.cd(dir);
172  vector<string> foundDirs = igetter.getSubdirs();
173  for (auto iDir = foundDirs.begin(); iDir != foundDirs.end(); ++iDir) {
174  TString dirName = iDir->substr(iDir->rfind('/') + 1, iDir->length());
175  if (dirName.Contains(regexp))
176  findAllSubdirectories(ibooker, igetter, *iDir, myList);
177  }
178  }
179  //std::cout << "Looking for directory " << dir ;
180  else if (igetter.dirExists(dir)) {
181  //std::cout << "... it exists! Inserting it into the list ";
182  myList->insert(dir);
183  //std::cout << "... now list has size " << myList->size() << std::endl;
184  ibooker.cd(dir);
185  findAllSubdirectories(ibooker, igetter, dir, myList, "*");
186  } else {
187  //std::cout << "... DOES NOT EXIST!!! Skip bogus dir" << std::endl;
188 
189  LogInfo("DQMGenericClient") << "Trying to find sub-directories of " << dir << " failed because " << dir
190  << " does not exist";
191  }
192  return;
193 }
194 
DQMEDHarvester.h
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
HLTMuonRefMethod::beginJob
void beginJob() override
Definition: HLTMuonRefMethod.cc:69
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
DQMStore.h
dqm::implementation::IGetter::getSubdirs
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:678
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
fetchall_from_DQM_v2.regexp
regexp
Definition: fetchall_from_DQM_v2.py:93
MakerMacros.h
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
PostProcessorHcalIsoTrack_cfi.subDir
subDir
Definition: PostProcessorHcalIsoTrack_cfi.py:5
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
dqm::legacy::MonitorElement::getTH1
virtual TH1 * getTH1() const
Definition: MonitorElement.h:474
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLTMuonRefMethod::HLTMuonRefMethod
HLTMuonRefMethod(const edm::ParameterSet &set)
Definition: HLTMuonRefMethod.cc:57
edm::ParameterSet
Definition: ParameterSet.h:47
HLTMuonRefMethod::subDirs_
std::vector< std::string > subDirs_
Definition: HLTMuonRefMethod.cc:42
Event.h
PatBasicFWLiteJetAnalyzer_Selector_cfg.myList
myList
Definition: PatBasicFWLiteJetAnalyzer_Selector_cfg.py:14
HLTMuonRefMethod
Definition: HLTMuonRefMethod.cc:29
HLTMuonRefMethod::hltTriggers_
std::vector< std::string > hltTriggers_
Definition: HLTMuonRefMethod.cc:43
MuonPostProcessor_cff.refEff
refEff
Definition: MuonPostProcessor_cff.py:101
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
HLTMuonRefMethod::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: HLTMuonRefMethod.cc:153
edm::EventSetup
Definition: EventSetup.h:57
HLTMuonRefMethod::dqmEndJob
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: HLTMuonRefMethod.cc:71
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
ClusterTask_cfi.trig
trig
Definition: ClusterTask_cfi.py:398
HLTMuonRefMethod::refTriggers_
std::string refTriggers_
Definition: HLTMuonRefMethod.cc:46
HLTMuonRefMethod::refEff_
std::vector< std::string > refEff_
Definition: HLTMuonRefMethod.cc:45
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
DQMEDHarvester
Definition: DQMEDHarvester.py:1
HistogramManager_cfi.VPSet
def VPSet(*args)
Definition: HistogramManager_cfi.py:401
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Frameworkfwd.h
dqm::implementation::IGetter
Definition: DQMStore.h:484
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
vstring
vector< string > vstring
Definition: ExoticaDQM.cc:8
dqm::implementation::IBooker
Definition: DQMStore.h:43
ParameterSet.h
HLTMuonRefMethod::findAllSubdirectories
void findAllSubdirectories(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &dir, std::set< std::string > *myList, const TString &pattern)
Definition: HLTMuonRefMethod.cc:155
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HLTMuonRefMethod::outputFileName_
std::string outputFileName_
Definition: HLTMuonRefMethod.cc:48
HLTMuonRefMethod::efficiency_
std::vector< std::string > efficiency_
Definition: HLTMuonRefMethod.cc:44
dqm::implementation::IGetter::dirExists
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:708
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23