Crombie Tools
PlotTriggerEfficiency.cc
Go to the documentation of this file.
1 #include <vector>
2 
3 #include "TMath.h"
4 #include "TH2D.h"
5 #include "TH1D.h"
6 #include "TGraphAsymmErrors.h"
8 
10 
11 //--------------------------------------------------------------------
12 void
13 PlotTriggerEfficiency::MakeCanvas(TString FileBase, Int_t NumXBins, Double_t *XBins,
14  TString XLabel, TString, Bool_t logY)
15 {
16  TH2D* result_holder = new TH2D("Trigger2DHist", "Trigger2DHist", NumXBins, XBins, 2, 0, 2);
17  std::vector<TGraphAsymmErrors*> mapped;
18 
19  TString drawing = TString::Format("%s:%s>>Trigger2DHist", fTrigger.Data(), fDefaultExpr.Data());
20  Message(eDebug, "Drawing with: %s", drawing.Data());
21 
22  fChain->Draw(drawing, fDefaultCut);
23  TH1D *allhist = result_holder->ProjectionX("all");
24  for (int iBin = 1; iBin < NumXBins + 1; iBin++) {
25  Message(eDebug, "Bin: %i, pass: %f, fail: %f", iBin,
26  result_holder->GetBinContent(iBin, 2), result_holder->GetBinContent(iBin, 1));
27 
28  // If no events at all, just pretend a buttload failed.
29  if (!allhist->GetBinContent(iBin))
30  allhist->SetBinContent(iBin, 1000000);
31  }
32 
33  TGraphAsymmErrors* plot = new TGraphAsymmErrors(NumXBins);
34  Message(eDebug, "Number of graph points: %i", plot->GetN());
35  plot->Divide(result_holder->ProjectionX("pass", 2, -1), allhist);
36  Message(eDebug, "Number of graph points: %i", plot->GetN());
37 
38  plot->GetYaxis()->SetRangeUser(0.0, 1.2);
39  mapped.push_back(plot);
40  SetDrawOpts("ape");
41  AddCutLine(1.0, false);
42 
43  BaseCanvas(FileBase, mapped, XLabel, "Efficiency", logY);
44 
45  mapped.clear();
46 
47  delete plot;
48  delete allhist;
49  delete result_holder;
50 }
51 
52 //--------------------------------------------------------------------
53 void
54 PlotTriggerEfficiency::MakeCanvas(TString FileBase, Int_t NumXBins, Double_t MinX, Double_t MaxX,
55  TString XLabel, TString, Bool_t logY)
56 {
57  Double_t XBins[NumXBins+1];
58  ConvertToArray(NumXBins, MinX, MaxX, XBins);
59  MakeCanvas(FileBase, NumXBins, XBins, XLabel, "", logY);
60 }