ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.8
Committed: Fri Oct 14 11:20:25 2011 UTC (13 years, 7 months ago) by khahn
Content type: text/plain
Branch: MAIN
Changes since 1.7: +11 -1 lines
Log Message:
passing ctrl all the way through to bdt selection

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 khahn 1.8 #include "SiMVAElectronSelection.h"
41 khahn 1.1 #include "RunLumiRangeMap.h"
42    
43     //
44     // utility headers
45     //
46     #include "ParseArgs.h"
47 dkralph 1.2 #include "SampleWeight.h"
48 khahn 1.1 #include "Selection.h"
49     #include "HZZCiCElectronSelection.h"
50 dkralph 1.4 #include "HZZLikelihoodElectronSelection.h"
51 dkralph 1.5 #include "HZZBDTElectronSelection.h"
52 dkralph 1.2 #include "SampleWeight.h"
53 khahn 1.1
54 khahn 1.8 //#define BDTFAIL_THEIR_EVENTS
55 khahn 1.1 //#define THEIR_EVENTS
56    
57     //=== MAIN =================================================================================================
58     int main(int argc, char** argv)
59     {
60    
61     vector<vector<string> > inputFiles;
62     inputFiles.push_back(vector<string>());
63    
64     //
65     // args
66     //--------------------------------------------------------------------------------------------------------------
67     ControlFlags ctrl;
68     parse_args( argc, argv, ctrl );
69     if( ctrl.inputfile.empty() ||
70     ctrl.inputfile.empty() ) {
71     cerr << "usage: applySelection.exe <flags> " << endl;
72     cerr << "\tmandoatory flags : " << endl;
73     cerr << "\t--inputfile | file containing a list of ntuples to run over" << endl;
74     cerr << "\t--outputfile | file to store selected evet" << endl;
75     return 1;
76     }
77     ctrl.dump();
78    
79 dkralph 1.4 map<string,double> entrymap; // number of unskimmed entries in each file
80    
81 khahn 1.1 //
82     // File I/O
83     //--------------------------------------------------------------------------------------------------------------
84     TChain * chain = new TChain("Events");
85     ifstream f(ctrl.inputfile.c_str());
86     string fname;
87     while (f >> fname) {
88 dkralph 1.4 if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
89 khahn 1.1 cout << "adding inputfile : " << fname.c_str() << endl;
90 dkralph 1.4 entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
91 khahn 1.1 chain->AddFile(fname.c_str());
92     }
93    
94 dkralph 1.2 // table of cross section values
95     SimpleTable xstab("./data/xs.dat");
96    
97 khahn 1.1 //
98     // Setup
99     //--------------------------------------------------------------------------------------------------------------
100     TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 );
101 dkralph 1.4 TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 1024, 0, 1024 );
102 khahn 1.6 // TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" );
103     TTree * passtuple = new TTree("passtuple", "passtuple" );
104     unsigned run, evt, lumi, channel;
105 khahn 1.7 float mZ1, mZ2, m4l, pt4l;
106     double w;
107 khahn 1.6 passtuple->Branch("run", &run);
108     passtuple->Branch("evt", &evt);
109     passtuple->Branch("lumi", &lumi);
110     passtuple->Branch("mZ1", &mZ1);
111     passtuple->Branch("mZ2", &mZ2);
112     passtuple->Branch("m4l", &m4l);
113     passtuple->Branch("pt4l", &pt4l);
114     passtuple->Branch("w", &w);
115 khahn 1.1 initCiCSelection();
116 dkralph 1.5 if(ctrl.eleSele=="lik") initLikSelection();
117     if(ctrl.eleSele=="bdt") initBDTSelection();
118 khahn 1.8 if(ctrl.eleSele=="si" ) initSiMVAElectronSelection();
119 khahn 1.1 initRunLumiRangeMap();
120    
121     //
122     // Loop
123     //--------------------------------------------------------------------------------------------------------------
124    
125     //
126     // Access samples and fill histograms
127     TFile *inputFile=0;
128     TTree *eventTree=0;
129    
130     // Data structures to store info from TTrees
131     mithep::TEventInfo *info = new mithep::TEventInfo();
132     TClonesArray *electronArr = new TClonesArray("mithep::TElectron");
133     TClonesArray *muonArr = new TClonesArray("mithep::TMuon");
134    
135    
136     TBranch *infoBr;
137     TBranch *electronBr;
138     TBranch *muonBr;
139    
140     // chain->SetBranchStatus("*",0); //disable all branches
141     // chain->SetBranchStatus("Info", 1);
142     // chain->SetBranchStatus("Muon", 1);
143     // chain->SetBranchStatus("Electron", 1);
144    
145     chain->SetBranchAddress("Info", &info);
146     chain->SetBranchAddress("Electron", &electronArr);
147     chain->SetBranchAddress("Muon", &muonArr);
148    
149    
150    
151     cout << "nEntries: " << chain->GetEntries() << endl;
152 dkralph 1.5 for(UInt_t ientry=0; ientry<chain->GetEntries(); ientry++) {
153 dkralph 1.4
154 khahn 1.1 chain->GetEntry(ientry);
155 dkralph 1.4 if(!(ientry%100000)) cout << "entry: " << ientry << endl;
156 khahn 1.1
157 dkralph 1.2 // get event weight for this file
158 dkralph 1.4 double eventweight=1;
159     if(ctrl.mc) eventweight = getWeight(xstab,entrymap,chain);
160 dkralph 1.2
161 khahn 1.1 #ifdef THEIR_EVENTS
162     if( !( info->evtNum == 504867308 ||
163     info->evtNum == 368148849 ||
164     info->evtNum == 129514273 ||
165     info->evtNum == 286336207 ||
166     info->evtNum == 344708580 ||
167     info->evtNum == 30998576 ||
168     info->evtNum == 155679852 ||
169     info->evtNum == 394010457 ||
170     info->evtNum == 917379387 ||
171     info->evtNum == 78213037 ||
172     info->evtNum == 337493970 ||
173     info->evtNum == 1491724484 ||
174     info->evtNum == 480301165 ||
175     info->evtNum == 1038911933 ||
176     info->evtNum == 876658967 ||
177     info->evtNum == 966824024 ||
178     info->evtNum == 141954801 ||
179     info->evtNum == 160966858 ||
180     info->evtNum == 191231387 ||
181     info->evtNum == 66033190 ||
182     info->evtNum == 10347106 ||
183     info->evtNum == 107360878 ) ) continue;
184     #endif
185 khahn 1.8
186    
187     #ifdef BDTFAIL_THEIR_EVENTS
188     if( !( info->evtNum == 78213037 ||
189     info->evtNum == 876658967 ) ) continue;
190    
191     #endif
192 khahn 1.1
193 dkralph 1.4 unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, eventweight, passtuple);
194 khahn 1.1 h_evtfail->Fill( evtfail, eventweight );
195 khahn 1.8
196 khahn 1.1
197     } //end loop over data
198    
199    
200    
201     delete info;
202     delete electronArr;
203     delete muonArr;
204    
205    
206    
207     //--------------------------------------------------------------------------------------------------------------
208     // Save Histograms;
209     //==============================================================================================================
210     const char * ofname;
211     if( strcmp( ctrl.outputfile.c_str(), "") ) {
212     ofname = ctrl.outputfile.c_str();
213     } else {
214     ofname = "tmp.root";
215     }
216    
217     TFile *file = new TFile(ofname, "RECREATE");
218     h_evt->Write();
219     h_evtfail->Write();
220     passtuple->Write();
221     file->Close();
222     delete file;
223    
224 dkralph 1.5 // map<TString,TMVA::Reader*>::iterator it;
225     // for(it=readers.begin(); it!=readers.end(); it++) delete (*it).second;
226    
227 khahn 1.1 cerr << "done!" << endl;
228     }
229    
230    
231