CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTTauPostProcessor.cc
Go to the documentation of this file.
4 
5 #include "TEfficiency.h"
6 #include "TProfile.h"
7 
8 #include<tuple>
9 
10 namespace {
11  std::tuple<float, float> calcEfficiency(float num, float denom) {
12  if(denom == 0.0f)
13  return std::make_tuple(0.0f, 0.0f);
14 
15  //float eff = num/denom;
16  constexpr double cl = 0.683f; // "1-sigma"
17  const float eff = num/denom;
18  const float errDown = TEfficiency::ClopperPearson(denom, num, cl, false);
19  const float errUp = TEfficiency::ClopperPearson(denom, num, cl, true);
20 
21  // Because of limitation of TProfile, just take max
22  return std::make_tuple(eff, std::max(eff-errDown, errUp-eff));
23  }
24 }
25 
27  dqmBaseFolder_(ps.getUntrackedParameter<std::string>("DQMBaseFolder"))
28 {}
29 
31 {}
32 
34 {
35  if(!iGetter.dirExists(dqmBaseFolder_)) {
36  LogDebug("HLTTauDQMOffline") << "Folder " << dqmBaseFolder_ << " does not exist";
37  return;
38  }
40  for(const std::string& subfolder: iGetter.getSubdirs()) {
41  std::size_t pos = subfolder.rfind("/");
42  if(pos == std::string::npos)
43  continue;
44  ++pos; // position of first letter after /
45  if(subfolder.compare(pos, 4, "HLT_") == 0) { // start with HLT_
46  LogDebug("HLTTauDQMOffline") << "Processing path " << subfolder.substr(pos);
47  plotFilterEfficiencies(iBooker, iGetter, subfolder);
48  }
49  }
50 }
51 
53  // Get the source
54  const MonitorElement *eventsPerFilter = iGetter.get(folder+"/EventsPerFilter");
55  if(!eventsPerFilter) {
56  LogDebug("HLTTauDQMOffline") << "ME " << folder << "/EventsPerFilter not found";
57  return;
58  }
59 
60  // Book efficiency TProfile
61  iBooker.setCurrentFolder(folder);
62  MonitorElement *efficiency = iBooker.bookProfile("EfficiencyRefPrevious", "Efficiency to previous filter", eventsPerFilter->getNbinsX()-1,0,eventsPerFilter->getNbinsX()-1, 100,0,1);
63  efficiency->setAxisTitle("Efficiency", 2);
64  const TAxis *xaxis = eventsPerFilter->getTH1F()->GetXaxis();
65  for(int bin=1; bin < eventsPerFilter->getNbinsX(); ++bin) {
66  efficiency->setBinLabel(bin, xaxis->GetBinLabel(bin));
67  }
68 
69  // Fill efficiency TProfile
70  TProfile *prev = efficiency->getTProfile();
71  for(int i=2; i <= eventsPerFilter->getNbinsX(); ++i) {
72  if(eventsPerFilter->getBinContent(i-1) < eventsPerFilter->getBinContent(i)) {
73  LogDebug("HLTTauDQMOffline") << "HLTTauPostProcessor: Encountered denominator < numerator with efficiency plot EfficiencyRefPrevious in folder " << folder << ", bin " << i << " numerator " << eventsPerFilter->getBinContent(i) << " denominator " << eventsPerFilter->getBinContent(i-1);
74  continue;
75  }
76  const std::tuple<float, float> effErr = calcEfficiency(eventsPerFilter->getBinContent(i), eventsPerFilter->getBinContent(i-1));
77  const float efficiency = std::get<0>(effErr);
78  const float err = std::get<1>(effErr);
79 
80  prev->SetBinContent(i-1, efficiency);
81  prev->SetBinEntries(i-1, 1);
82  prev->SetBinError(i-1, std::sqrt(efficiency*efficiency + err*err));
83  }
84 }
85 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:155
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:291
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void dqmEndJob(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) override
HLTTauPostProcessor(const edm::ParameterSet &)
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:48
double f[11][100]
bool dirExists(const std::string &path)
Definition: DQMStore.cc:307
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
void plotFilterEfficiencies(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const std::string &folder) const
TH1F * getTH1F(void) const
std::vector< std::string > getSubdirs(void)
Definition: DQMStore.cc:295
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:319
double getBinContent(int binx) const
get content of bin (1-D)
TProfile * getTProfile(void) const
int getNbinsX(void) const
get # of bins in X-axis
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
#define constexpr
const std::string dqmBaseFolder_