forked from RemKamal/ElectronID
-
Notifications
You must be signed in to change notification settings - Fork 1
/
computeSingleCutEfficiency.C
98 lines (78 loc) · 3.03 KB
/
computeSingleCutEfficiency.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "TTree.h"
#include "TString.h"
#include "TFile.h"
#include "OptimizationConstants.hh"
#include "VarCut.hh"
// Files with signal and background trees (ideally the ntuples
// that were used for TMVA optimization
const TString fnameSignal = "../../ntuples/DYJetsToLL_50ns.root";
const TString signalTreeName = "ntupler/ElectronTree";
const TString fnameBackground = "../../ntuples/TTJets_50ns.root";
const TString backgroundTreeName = "ntupler/ElectronTree";
// Forward declarations
TTree *getTreeFromFile(TString fname, TString tname);
void findEfficiencies(TTree *signalTree, TTree *backgroundTree, bool doBarrel,
float &effSignal, float &effBackground,
VarCut *cutObject);
//
// Main function
//
void computeSingleCutEfficiency(TString var, float cutVal, bool doBarrel){
// Get trees
printf("\n Take true electrons from %s tree %s\n",
fnameSignal.Data(), signalTreeName.Data());
TTree *signalTree = getTreeFromFile( fnameSignal, signalTreeName);
// Input background tree
printf("\n Take background electrons from %s tree %s\n",
fnameBackground.Data(), backgroundTreeName.Data());
TTree *backgroundTree = getTreeFromFile( fnameBackground, backgroundTreeName);
VarCut *cutObject = new VarCut();
for(int ivar= 0; ivar<Vars::nVariables; ivar++){
if( var == Vars::variables[ivar]->name )
cutObject->setCutValue( Vars::variables[ivar]->name, cutVal);
else
cutObject->setCutValue( Vars::variables[ivar]->name, 1e30);
}
printf("Compute the efficiency of the following cut set:\n");
cutObject->print();
// Compute the efficiencies
float effSignal, effBackground;
findEfficiencies(signalTree, backgroundTree, doBarrel,
effSignal, effBackground,
cutObject);
printf("Computed eff: effS= %.3f effB= %.3f\n",
effSignal, effBackground);
}
// Get a given tree from a given file name.
TTree *getTreeFromFile(TString fname, TString tname){
TFile *file = new TFile( fname );
TTree *tree = (TTree*) file->Get(tname);
return tree;
}
// Compute signal and background efficiencies for given cuts
void findEfficiencies(TTree *signalTree, TTree *backgroundTree, bool doBarrel,
float &effSignal, float &effBackground, VarCut *cutObject){
TCut etaCut = "";
if( doBarrel ){
etaCut = Opt::etaCutBarrel;
}else{
etaCut = Opt::etaCutEndcap;
}
TCut kinematicCuts = Opt::ptCut && etaCut;
TCut preselectionCuts = kinematicCuts && Opt::otherPreselectionCuts;
TCut signalCuts = preselectionCuts && Opt::trueEleCut;
TCut backgroundCuts = preselectionCuts && Opt::fakeEleCut;
TCut selectionCuts = *(cutObject->getCut());
printf("\nSelecton cuts: %s\n",
selectionCuts.GetTitle());
printf("\nSignal cuts: %s\n",
signalCuts.GetTitle());
printf("\nBackground cuts: %s\n",
backgroundCuts.GetTitle());
effSignal = (1.0*signalTree->GetEntries(selectionCuts && signalCuts) )
/ signalTree->GetEntries(signalCuts);
effBackground = (1.0*backgroundTree->GetEntries(selectionCuts
&& backgroundCuts) )
/ backgroundTree->GetEntries(backgroundCuts);
return;
}