ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.5
Committed: Wed Oct 12 17:25:15 2011 UTC (13 years, 7 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.4: +7 -2 lines
Log Message:
add bdt

File Contents

# User Rev Content
1 khahn 1.1 //
2     // System headers
3     //
4     #include <vector> // STL vector class
5     #include <iostream> // standard I/O
6     #include <iomanip> // functions to format standard I/O
7     #include <fstream> // functions for file I/O
8     #include <string> // C++ string class
9     #include <sstream> // class for parsing strings
10     #include <assert.h>
11     #include <stdlib.h>
12     #include <getopt.h>
13     using namespace std;
14    
15     //
16     // ROOT headers
17     //
18     #include <TROOT.h> // access to gROOT, entry point to ROOT system
19     #include <TSystem.h> // interface to OS
20     #include <TFile.h> // file handle class
21     #include <TNtuple.h>
22     #include <TTree.h> // class to access ntuples
23     #include <TChain.h> //
24     #include <TBranch.h> // class to access branches in TTree
25     #include <TClonesArray.h> // ROOT array class
26     #include <TCanvas.h> // class for drawing
27     #include <TH1F.h> // 1D histograms
28     #include <TBenchmark.h> // class to track macro running statistics
29     #include <TLorentzVector.h> // 4-vector class
30     #include <TVector3.h> // 3D vector class
31    
32     //
33     // ntuple format headers
34     //
35 dkralph 1.2 #include "HiggsAnaDefs.hh"
36 khahn 1.1 #include "TEventInfo.hh"
37     #include "TElectron.hh"
38     #include "TMuon.hh"
39     #include "TJet.hh"
40     #include "RunLumiRangeMap.h"
41    
42     //
43     // utility headers
44     //
45     #include "ParseArgs.h"
46 dkralph 1.2 #include "SampleWeight.h"
47 khahn 1.1 #include "Selection.h"
48     #include "HZZCiCElectronSelection.h"
49 dkralph 1.4 #include "HZZLikelihoodElectronSelection.h"
50 dkralph 1.5 #include "HZZBDTElectronSelection.h"
51 dkralph 1.2 #include "SampleWeight.h"
52 khahn 1.1
53     //#define THEIR_EVENTS
54    
55     //=== MAIN =================================================================================================
56     int main(int argc, char** argv)
57     {
58    
59     vector<vector<string> > inputFiles;
60     inputFiles.push_back(vector<string>());
61    
62     //
63     // args
64     //--------------------------------------------------------------------------------------------------------------
65     ControlFlags ctrl;
66     parse_args( argc, argv, ctrl );
67     if( ctrl.inputfile.empty() ||
68     ctrl.inputfile.empty() ) {
69     cerr << "usage: applySelection.exe <flags> " << endl;
70     cerr << "\tmandoatory flags : " << endl;
71     cerr << "\t--inputfile | file containing a list of ntuples to run over" << endl;
72     cerr << "\t--outputfile | file to store selected evet" << endl;
73     return 1;
74     }
75     ctrl.dump();
76    
77 dkralph 1.4 map<string,double> entrymap; // number of unskimmed entries in each file
78    
79 khahn 1.1 //
80     // File I/O
81     //--------------------------------------------------------------------------------------------------------------
82     TChain * chain = new TChain("Events");
83     ifstream f(ctrl.inputfile.c_str());
84     string fname;
85     while (f >> fname) {
86 dkralph 1.4 if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
87 khahn 1.1 cout << "adding inputfile : " << fname.c_str() << endl;
88 dkralph 1.4 entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
89 khahn 1.1 chain->AddFile(fname.c_str());
90     }
91    
92 dkralph 1.2 // table of cross section values
93     SimpleTable xstab("./data/xs.dat");
94    
95 khahn 1.1 //
96     // Setup
97     //--------------------------------------------------------------------------------------------------------------
98     TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 );
99 dkralph 1.4 TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 1024, 0, 1024 );
100 khahn 1.1 TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" );
101     initCiCSelection();
102 dkralph 1.5 if(ctrl.eleSele=="lik") initLikSelection();
103     if(ctrl.eleSele=="bdt") initBDTSelection();
104 khahn 1.1 initRunLumiRangeMap();
105    
106     //
107     // Loop
108     //--------------------------------------------------------------------------------------------------------------
109    
110     //
111     // Access samples and fill histograms
112     TFile *inputFile=0;
113     TTree *eventTree=0;
114    
115     // Data structures to store info from TTrees
116     mithep::TEventInfo *info = new mithep::TEventInfo();
117     TClonesArray *electronArr = new TClonesArray("mithep::TElectron");
118     TClonesArray *muonArr = new TClonesArray("mithep::TMuon");
119    
120    
121     TBranch *infoBr;
122     TBranch *electronBr;
123     TBranch *muonBr;
124    
125     // chain->SetBranchStatus("*",0); //disable all branches
126     // chain->SetBranchStatus("Info", 1);
127     // chain->SetBranchStatus("Muon", 1);
128     // chain->SetBranchStatus("Electron", 1);
129    
130     chain->SetBranchAddress("Info", &info);
131     chain->SetBranchAddress("Electron", &electronArr);
132     chain->SetBranchAddress("Muon", &muonArr);
133    
134    
135    
136     cout << "nEntries: " << chain->GetEntries() << endl;
137 dkralph 1.5 for(UInt_t ientry=0; ientry<chain->GetEntries(); ientry++) {
138 dkralph 1.4
139 khahn 1.1 chain->GetEntry(ientry);
140 dkralph 1.4 if(!(ientry%100000)) cout << "entry: " << ientry << endl;
141 khahn 1.1
142 dkralph 1.2 // get event weight for this file
143 dkralph 1.4 double eventweight=1;
144     if(ctrl.mc) eventweight = getWeight(xstab,entrymap,chain);
145 dkralph 1.2
146 khahn 1.1 #ifdef THEIR_EVENTS
147     if( !( info->evtNum == 504867308 ||
148     info->evtNum == 368148849 ||
149     info->evtNum == 129514273 ||
150     info->evtNum == 286336207 ||
151     info->evtNum == 344708580 ||
152     info->evtNum == 30998576 ||
153     info->evtNum == 155679852 ||
154     info->evtNum == 394010457 ||
155     info->evtNum == 917379387 ||
156     info->evtNum == 78213037 ||
157     info->evtNum == 337493970 ||
158     info->evtNum == 1491724484 ||
159     info->evtNum == 480301165 ||
160     info->evtNum == 1038911933 ||
161     info->evtNum == 876658967 ||
162     info->evtNum == 966824024 ||
163     info->evtNum == 141954801 ||
164     info->evtNum == 160966858 ||
165     info->evtNum == 191231387 ||
166     info->evtNum == 66033190 ||
167     info->evtNum == 10347106 ||
168     info->evtNum == 107360878 ) ) continue;
169     #endif
170    
171 dkralph 1.4 unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, eventweight, passtuple);
172 khahn 1.1 h_evtfail->Fill( evtfail, eventweight );
173 dkralph 1.4 if( ctrl.debug ) cout << endl << endl;
174 khahn 1.1
175     } //end loop over data
176    
177    
178    
179     delete info;
180     delete electronArr;
181     delete muonArr;
182    
183    
184    
185     //--------------------------------------------------------------------------------------------------------------
186     // Save Histograms;
187     //==============================================================================================================
188     const char * ofname;
189     if( strcmp( ctrl.outputfile.c_str(), "") ) {
190     ofname = ctrl.outputfile.c_str();
191     } else {
192     ofname = "tmp.root";
193     }
194    
195     TFile *file = new TFile(ofname, "RECREATE");
196     h_evt->Write();
197     h_evtfail->Write();
198     passtuple->Write();
199     file->Close();
200     delete file;
201    
202 dkralph 1.5 // map<TString,TMVA::Reader*>::iterator it;
203     // for(it=readers.begin(); it!=readers.end(); it++) delete (*it).second;
204    
205 khahn 1.1 cerr << "done!" << endl;
206     }
207    
208    
209