CMS 3D CMS Logo

HLTMuonRefMethod.cc
Go to the documentation of this file.
5 
9 
10 
12 
15 
16 #include <set>
17 #include <string>
18 #include <vector>
19 #include <TPRegexp.h>
20 #include <cmath>
21 #include <climits>
22 #include <boost/tokenizer.hpp>
23 #include <boost/regex.hpp>
24 
25 
26 #include <TH1.h>
27 #include <TEfficiency.h>
28 
29 
30 
31 
32 using namespace edm;
33 using namespace std;
34 
35 
36 
38 
39 public:
40  explicit HLTMuonRefMethod(const edm::ParameterSet& set);
41  ~HLTMuonRefMethod() override = default;;
42 
43  void beginJob() override;
44  void beginRun(const edm::Run&, const edm::EventSetup&) override ;
45  void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override ;
46 
47 
48 private:
49  // DQMStore* theDQM;
50 
51  std::vector<std::string> subDirs_;
52  std::vector<std::string> hltTriggers_;
53  std::vector<std::string> efficiency_;
54  std::vector<std::string> refEff_;
56 
58 
59  void findAllSubdirectories (DQMStore::IBooker& ibooker,
60  DQMStore::IGetter& igetter,
61  const std::string& dir,
62  std::set<std::string> * myList,
63  const TString& pattern);
64 
65 
66 };
67 
68 
70 {
71  using VPSet = std::vector<edm::ParameterSet>;
72  using vstring = std::vector<std::string>;
73  using elsc = boost::escaped_list_separator<char>;
74 
75  subDirs_ = pset.getUntrackedParameter<vstring>("subDirs");
76  hltTriggers_ = pset.getUntrackedParameter<vstring>("hltTriggers");
77  refTriggers_ = pset.getUntrackedParameter<string> ("refTriggers");
78  efficiency_ = pset.getUntrackedParameter<vstring>("efficiency" );
79  refEff_ = pset.getUntrackedParameter<vstring>("refEff");
80 }
81 
82 void
84 {
85 
86 }
87 
88 
90 {
91  using vstring = std::vector<std::string>;
92  boost::regex metacharacters{"[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]"};
93  boost::smatch what;
94 
95  // theDQM = 0;
96  // theDQM = Service<DQMStore>().operator->();
97 
98  ibooker.cd();
99  set<string> subDirSet;
100 
101  for(auto iSubDir = subDirs_.begin();
102  iSubDir != subDirs_.end(); ++iSubDir) {
103  string subDir = *iSubDir;
104 
105  if ( subDir[subDir.size()-1] == '/' ) subDir.erase(subDir.size()-1);
106 
107  if ( boost::regex_search(subDir, what, metacharacters)) {
108  const string::size_type shiftPos = subDir.rfind('/');
109  const string searchPath = subDir.substr(0, shiftPos);
110  const string pattern = subDir.substr(shiftPos + 1, subDir.length());
111  //std::cout << "\n\n\n\nLooking for all subdirs of " << subDir << std::endl;
112 
113  findAllSubdirectories (ibooker, igetter, searchPath, &subDirSet, pattern);
114 
115  }
116  else {
117  subDirSet.insert(subDir);
118  }
119  }
120 
121  for(auto const & subDir : subDirSet) {
122  for (unsigned int iEff = 0; iEff != efficiency_.size(); ++iEff){
123  string eff = efficiency_[iEff];
124 
125  // Getting reference trigger efficiency
126  MonitorElement* refEff = igetter.get(subDir + "/" + refTriggers_ + "/" + refEff_[iEff]);
127 
128  if (!refEff) continue;
129 
130 
131  // looping over all reference triggers
132  for (auto iTrigger = hltTriggers_.begin();
133  iTrigger != hltTriggers_.end(); ++iTrigger){
134  string trig = *iTrigger;
135  MonitorElement* trigEff = igetter.get(subDir + "/" + trig + "/" + eff );
136  if (!trigEff) continue;
137  TH1* hRef = refEff -> getTH1();
138  TH1* hTrig = trigEff -> getTH1();
139  TH1* hEff = (TH1*) hTrig->Clone( ("eff_" + eff + "_ref").c_str() );
140  hEff->SetTitle("Efficiency obtained with reference method");
141  TClass* myHistClass = hTrig->IsA();
142  TString histClassName = myHistClass->GetName();
143 
144  if (histClassName == "TH1F"){
145  for (int bin = 0; bin < hEff->GetNbinsX(); ++bin){
146  hEff->SetBinContent(bin+1, hEff->GetBinContent(bin+1)*hRef->GetBinContent(bin+1));
147  hEff->SetBinError (bin+1, hEff->GetBinContent(bin+1)*hRef->GetBinError(bin+1)+hEff->GetBinError(bin+1)*hRef->GetBinContent(bin+1));
148  }
149  ibooker.cd(subDir + "/" + trig);
150  ibooker.book1D( hEff->GetName(), (TH1F*) hEff);
151 
152  }
153  else if (histClassName == "TH2F"){
154  for (int i = 0; i < hRef->GetXaxis()->GetNbins(); ++i){
155  for (int j = 0; j < hRef->GetYaxis()->GetNbins(); ++j){
156  int bin = hEff->GetBin(i+1,j+1);
157  hEff -> SetBinContent( bin, hRef->GetBinContent(i+1,j+1) * hTrig->GetBinContent(i+1) );
158  }
159  }
160  ibooker.cd(subDir + "/" + trig);
161  ibooker.book2D( hEff->GetName(), (TH2F*) hEff);
162  }
163  else{
164  LogInfo ("HLTMuonRefMethod") << "Histo class type << " << histClassName << " not implemented";
165  }
166 
167  delete hEff;
168 
169  }
170  }
171  }
172 }
173 
174 
175 void
177 {
178 
179 
180 }
181 
182 
183 
184 void
186  const TString& _pattern = TString("")) {
187  TString pattern = _pattern;
188  TPRegexp nonPerlWildcard("\\w\\*|^\\*");
189 
190  if (!igetter.dirExists(dir)) {
191  LogError("DQMGenericClient") << " DQMGenericClient::findAllSubdirectories ==> Missing folder " << dir << " !!!";
192  return;
193  }
194  if (pattern != "") {
195  if (pattern.Contains(nonPerlWildcard)) pattern.ReplaceAll("*",".*");
196  TPRegexp regexp(pattern);
197  ibooker.cd(dir);
198  vector <string> foundDirs = igetter.getSubdirs();
199  for(auto iDir = foundDirs.begin();
200  iDir != foundDirs.end(); ++iDir) {
201  TString dirName = iDir->substr(iDir->rfind('/') + 1, iDir->length());
202  if (dirName.Contains(regexp))
203  findAllSubdirectories (ibooker, igetter, *iDir, myList);
204  }
205  }
206  //std::cout << "Looking for directory " << dir ;
207  else if (igetter.dirExists(dir)){
208  //std::cout << "... it exists! Inserting it into the list ";
209  myList->insert(dir);
210  //std::cout << "... now list has size " << myList->size() << std::endl;
211  ibooker.cd(dir);
212  findAllSubdirectories (ibooker, igetter, dir, myList, "*");
213  } else {
214  //std::cout << "... DOES NOT EXIST!!! Skip bogus dir" << std::endl;
215 
216  LogInfo ("DQMGenericClient") << "Trying to find sub-directories of " << dir
217  << " failed because " << dir << " does not exist";
218 
219  }
220  return;
221 }
222 
223 
std::vector< std::string > efficiency_
T getUntrackedParameter(std::string const &, T const &) const
void beginJob() override
vector< string > vstring
Definition: ExoticaDQM.cc:8
TPRegexp metacharacters("[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]")
uint16_t size_type
void beginJob()
Definition: Breakpoints.cc:14
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLTMuonRefMethod(const edm::ParameterSet &set)
std::vector< std::string > subDirs_
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::string refTriggers_
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
bin
set the eta bin as selection string.
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
bool dirExists(std::string const &path)
Definition: DQMStore.cc:343
std::vector< std::string > refEff_
std::vector< std::string > hltTriggers_
TPRegexp nonPerlWildcard("\\w\\*|^\\*")
HLT enums.
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
std::string outputFileName_
dbl *** dir
Definition: mlp_gen.cc:35
Definition: Run.h:45
void findAllSubdirectories(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &dir, std::set< std::string > *myList, const TString &pattern)