ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.2
Committed: Wed Sep 14 12:11:57 2011 UTC (13 years, 8 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.1: +11 -3 lines
Log Message:
Alter to run on dkralph ntuples, make runlumi code independent of bambu.

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