ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.4
Committed: Thu Sep 22 18:01:19 2011 UTC (13 years, 7 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.3: +13 -8 lines
Log Message:
Added likelihood electron ID.

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