ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelectionZ4L.cc
Revision: 1.3
Committed: Wed Feb 29 09:42:09 2012 UTC (13 years, 2 months ago) by anlevin
Content type: text/plain
Branch: MAIN
CVS Tags: synced_FSR_2, synced_FSR, synched2, synched
Changes since 1.2: +6 -6 lines
Log Message:
changed Z4l selection code

File Contents

# Content
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 using namespace std;
8
9 //
10 // root headers
11 //
12 #include <TFile.h>
13 #include <TTree.h>
14 #include <TChain.h>
15 #include <TBranch.h>
16 #include <TClonesArray.h>
17
18
19 //
20 // TMVA
21 //
22 #include "TMVA/Reader.h"
23 #include "TMVA/Tools.h"
24 #include "TMVA/Config.h"
25 #include "TMVA/MethodBDT.h"
26
27 //
28 // ntuple format headers
29 //
30 #include "HiggsAnaDefs.hh"
31 #include "TEventInfo.hh"
32 #include "TElectron.hh"
33 #include "TMuon.hh"
34 #include "TJet.hh"
35 #include "TPhoton.hh"
36
37
38 //
39 // our headers
40 //
41 #include "ParseArgs.h"
42 #include "MuonSelection.h"
43 #include "HZZCiCElectronSelection.h"
44 #include "IsolationSelection.h"
45 #include "SelectionZ4L.h"
46
47 #include "Angles.h"
48 #include "KinematicsStruct.h"
49 #include "InfoStruct.h"
50 #include "GenInfoStruct.h"
51 #include "WeightStruct.h"
52 #include "GlobalDataAndFuncs.h"
53 #include "AngleTuple.h"
54
55 #include "SampleWeight.h"
56 #include "EfficiencyWeightsInterface.h"
57
58
59 //=== MAIN =================================================================================================
60 int main(int argc, char** argv)
61 {
62
63
64 vector<pair<unsigned,unsigned> > runevtvec;
65 vector<vector<string> > inputFiles;
66 inputFiles.push_back(vector<string>());
67
68 //
69 // args
70 //--------------------------------------------------------------------------------------------------------------
71 ControlFlags ctrl;
72 parse_args( argc, argv, ctrl );
73 if( ctrl.inputfile.empty() ||
74 ctrl.inputfile.empty() ) {
75 cerr << "usage: applySelection.exe <flags> " << endl;
76 cerr << "\tmandoatory flags : " << endl;
77 cerr << "\t--inputfile | file containing a list of ntuples to run over" << endl;
78 cerr << "\t--outputfile | file to store selected evet" << endl;
79 return 1;
80 }
81 ctrl.dump();
82 assert( ctrl.mH != 0 );
83
84 map<string,double> entrymap; // number of unskimmed entries in each file
85
86 //
87 // File I/O
88 //--------------------------------------------------------------------------------------------------------------
89 TChain * chain = new TChain("Events");
90 ifstream f(ctrl.inputfile.c_str());
91 string fname;
92 while (f >> fname) {
93 if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
94 cout << "adding inputfile : " << fname.c_str() << endl;
95 entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
96 chain->AddFile(fname.c_str());
97 }
98
99 // table of cross section values
100 SimpleTable xstab("./data/xs.dat");
101
102
103
104
105 //
106 // Setup
107 //--------------------------------------------------------------------------------------------------------------
108 const char * ofname;
109 if( strcmp( ctrl.outputfile.c_str(), "") ) {
110 ofname = ctrl.outputfile.c_str();
111 } else {
112 ofname = "tmp.root";
113 }
114
115 Angles angles;
116 KinematicsStruct kinematics;
117 InfoStruct evtinfo;
118 WeightStruct weights;
119 GenInfoStruct geninfo;
120
121 AngleTuple nt( (const char*)ofname, (const char*)"zznt");
122 nt.makeKinematicsBranch(kinematics);
123 nt.makeInfoBranch(evtinfo);
124
125 TH1F * h_w_hpt;
126 if(ctrl.mc) {
127 nt.makeWeightBranch(weights);
128 nt.makeGenInfoBranch(geninfo);
129 initEfficiencyWeights();
130 /*
131 // Higgs only, pt reweighting
132 if( ctrl.mH <= 140 ) {
133 char wptname[256];
134 sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
135 TFile * f_hpt = new TFile(wptname);
136 f_hpt->Print();
137 sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
138 h_w_hpt = (TH1F*)(f_hpt->FindObjectAny(wptname));
139 h_w_hpt->Print();
140 }
141 */
142 } else {
143 initRunLumiRangeMap();
144 }
145
146 // setup CiC cuts
147 initCiCSelection();
148 CICStruct cicTightCuts = getCiCCuts("tight");
149
150
151 //##########################################################################
152 // Setup tree I/O
153 //##########################################################################
154
155 // Data structures to store info from TTrees
156 mithep::TEventInfo *info = new mithep::TEventInfo();
157 mithep::TGenInfo *ginfo = new mithep::TGenInfo();
158 TClonesArray *electronArr = new TClonesArray("mithep::TElectron");
159 TClonesArray *muonArr = new TClonesArray("mithep::TMuon");
160 TClonesArray *photonArr = new TClonesArray("mithep::TPhoton");
161
162 chain->SetBranchAddress("Info", &info);
163 chain->SetBranchAddress("Electron", &electronArr);
164 chain->SetBranchAddress("Muon", &muonArr);
165 chain->SetBranchAddress("Photon", &photonArr);
166
167 ginfo = NULL;
168 if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);}
169
170 int count=0, pass=0;
171 UInt_t imax = chain->GetEntries();
172 cout << "nEntries: " << imax << endl;
173
174 //##########################################################################
175 // Loop !!!!!!!!!
176 //##########################################################################
177 for(UInt_t ientry=0; ientry<imax; ientry++)
178 {
179 chain->GetEntry(ientry);
180 if(!(ientry%100000)) cerr << "entry: " << ientry << endl;
181
182 // get event weight for this process
183 if(ctrl.mc) {
184 weights.w = getWeight(xstab,entrymap,chain);
185 } else {
186 // skip duplicates
187 std::pair<unsigned,unsigned> tmppair(info->runNum,info->evtNum);
188 if( find( runevtvec.begin(), runevtvec.end(), tmppair ) != runevtvec.end() )
189 continue;
190 }
191
192 //if(info->evtNum != 197434335 || info->runNum != 170826) continue;
193
194 EventData ret4l =
195 apply_Z4L_selection(ctrl, info,
196 electronArr,
197 cicTightCuts,
198 &electronPreSelectionCic,
199 &failsCicSelection,
200 muonArr,
201 &noPreSelection,
202 &passMuonSelectionBackDoor,
203 &pairwiseIsoSelection);
204 if( ctrl.debug ) cout << endl;
205
206 if( ret4l.status.pass() ) {
207
208 runevtvec.push_back(pair<unsigned,unsigned> (info->runNum,info->evtNum) );
209
210 fillKinematics(ret4l,kinematics);
211 fillEventInfo(info,evtinfo);
212 if(ctrl.mc) fillGenInfo(ginfo,geninfo);
213
214 nt.Fill();
215
216 cerr << "PASS:: "
217 << "\trun: " << evtinfo.run
218 << "\tevt: " << evtinfo.evt
219 << endl;
220 pass++;
221 // if( pass > 3 ) break;
222
223 }
224 }
225
226 nt.WriteClose();
227 }
228
229
230