ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/jbabb/ScriptsAndMacros/TMVAscript_Zprime.C
Revision: 1.1
Committed: Sat Sep 3 21:22:30 2011 UTC (13 years, 8 months ago) by jbabb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 //TMVA script for Z' nTuple
2 //John Babb 7-9-09 ---> mostly stolen from example in TMVA
3
4
5 #include <iostream>
6
7
8 #include "TFile.h"
9 #include "TSystem.h"
10 #include "TTree.h"
11 #include "TBranch.h"
12 #include "TLeaf.h"
13
14 #include "tmva/test/TMVAGui.C"
15 #include "TMVA/Tools.h"
16 #include "TMVA/Factory.h"
17 #include "TPluginManager.h"
18
19 void TMVAscript_Zprime() {
20
21
22 std::cout << "Start TMVAnalysis" << std::endl
23 << "=================" << std::endl
24 << std::endl;
25
26
27 // Create a new root output file.
28 TString outfileName( "Zprime_BDT.root" );
29 TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
30
31 TMVA::Factory *factory = new TMVA::Factory( "TMVAnalysis", outputFile, Form("!V:!Silent:%sColor", gROOT->IsBatch()?"!":"") );
32
33
34 //Add all the variables from the events
35 factory->AddVariable( "pt_smuon", 'F' );
36 factory->AddVariable( "p_smuon", 'F' );
37 factory->AddVariable( "eta_smuon", 'F' );
38 factory->AddVariable( "ptRel_smuon", 'F' );
39 factory->AddVariable( "drMinMuJ_smuon", 'F' );
40 factory->AddVariable( "drMaxMuJ_smuon", 'F' );
41 factory->AddVariable( "dPhiMuMET_smuon", 'F' );
42 factory->AddVariable( "d0_smuon", 'F' );
43 factory->AddVariable( "MtMuMET_smuon", 'F' );
44 factory->AddVariable( "MtMuJetMET_smuon",'F' );
45 factory->AddVariable( "MMuJet1_smuon", 'F' );
46 factory->AddVariable( "relIso_smuon", 'F' );
47
48 factory->AddVariable( "pt_jet1", 'F' );
49 factory->AddVariable( "p_jet1", 'F' );
50 factory->AddVariable( "eta_jet1", 'F' );
51
52 factory->AddVariable( "pt_jet2", 'F' );
53 factory->AddVariable( "p_jet2", 'F' );
54 factory->AddVariable( "eta_jet2", 'F' );
55
56 factory->AddVariable( "pt_jet3", 'F' );
57 factory->AddVariable( "p_jet3", 'F' );
58 factory->AddVariable( "eta_jet3", 'F' );
59
60 factory->AddVariable( "met", 'F' );
61 factory->AddVariable( "neutrinoPz", 'F' );
62
63 //factory->AddVariable( "drJ1J2", 'F' );
64 //factory->AddVariable( "drJ1J3", 'F' );
65 //factory->AddVariable( "drJ2J3", 'F' );
66 //factory->AddVariable( "drMinJ1", 'F' );
67 //factory->AddVariable( "drMinJ2", 'F' );
68 //factory->AddVariable( "drMinJ3", 'F' );
69 factory->AddVariable( "nHardJets", 'I' );
70 factory->AddVariable( "bJets", 'I' );
71 factory->AddVariable( "HtJets", 'F' );
72 factory->AddVariable( "HtJetsLepMET", 'F' );
73 factory->AddVariable( "HJets", 'F' );
74 factory->AddVariable( "HJetsLepMET", 'F' );
75 factory->AddVariable( "MJ1J2J3", 'F' );
76 factory->AddVariable( "etaJ1J2J3", 'F' );
77 factory->AddVariable( "MJ1J2", 'F' );
78 factory->AddVariable( "MJ1J3", 'F' );
79 factory->AddVariable( "MJ2J3", 'F' );
80 factory->AddVariable( "etaJ1J2", 'F' );
81 factory->AddVariable( "etaJ2J3", 'F' );
82 factory->AddVariable( "etaJ1J3", 'F' );
83 factory->AddVariable( "sphericity", 'F' );
84 factory->AddVariable( "aplanarity", 'F' );
85 factory->AddVariable( "centrality", 'F' );
86
87 //factory->AddVariable("unfittedHadWPx", 'F' );
88 //factory->AddVariable("unfittedHadWPy", 'F' );
89 //factory->AddVariable("unfittedHadWPz", 'F' );
90 factory->AddVariable("unfittedHadWPt", 'F' );
91 factory->AddVariable("unfittedHadWE", 'F' );
92 //factory->AddVariable("unfittedHadWTheta", 'F' );
93 //factory->AddVariable("unfittedHadWPhi", 'F' );
94 factory->AddVariable("unfittedHadWEta", 'F' );
95 factory->AddVariable("unfittedHadWMass", 'F' );
96 //factory->AddVariable("unfittedLepWPx", 'F' );
97 //factory->AddVariable("unfittedLepWPy", 'F' );
98 //factory->AddVariable("unfittedLepWPz", 'F' );
99 factory->AddVariable("unfittedLepWPt", 'F' );
100 factory->AddVariable("unfittedLepWE", 'F' );
101 //factory->AddVariable("unfittedLepWTheta", 'F' );
102 //factory->AddVariable("unfittedLepWPhi", 'F' );
103 factory->AddVariable("unfittedLepWEta", 'F' );
104 factory->AddVariable("unfittedLepWMass", 'F' );
105
106 //factory->AddVariable("unfittedHadTopPx", 'F' );
107 //factory->AddVariable("unfittedHadTopPy", 'F' );
108 //factory->AddVariable("unfittedHadTopPz", 'F' );
109 factory->AddVariable("unfittedHadTopPt", 'F' );
110 factory->AddVariable("unfittedHadTopE", 'F' );
111 //factory->AddVariable("unfittedHadTopTheta", 'F' );
112 //factory->AddVariable("unfittedHadTopPhi", 'F' );
113 factory->AddVariable("unfittedHadTopEta", 'F' );
114 factory->AddVariable("unfittedHadTopMass", 'F' );
115 //factory->AddVariable("unfittedLepTopPx", 'F' );
116 //factory->AddVariable("unfittedLepTopPy", 'F' );
117 //factory->AddVariable("unfittedLepTopPz", 'F' );
118 factory->AddVariable("unfittedLepTopPt", 'F' );
119 factory->AddVariable("unfittedLepTopE", 'F' );
120 //factory->AddVariable("unfittedLepTopTheta", 'F' );
121 //factory->AddVariable("unfittedLepTopPhi", 'F' );
122 factory->AddVariable("unfittedLepTopEta", 'F' );
123 factory->AddVariable("unfittedLepTopMass", 'F' );
124
125 factory->AddVariable("unfittedEvent_ttInvariantMass",'F' );
126
127 factory->AddVariable("tt_dTheta",'F' );
128 factory->AddVariable("tt_dPhi",'F' );
129 factory->AddVariable("tt_dR",'F' );
130
131
132
133
134
135
136 // load the signal and background event samples from ROOT trees
137
138 //TFile *input1 = TFile::Open("Preselection/Skynet_Preselection_Zprime500.root");
139 //std::cout << "--- TMVAnalysis : Accessing " << "ZPrime500.root" << std::endl;
140
141 TFile *input2 = TFile::Open("Preselection/Skynet_Preselection_Zprime750.root");
142 std::cout << "--- TMVAnalysis : Accessing " << "ZPrime750.root" << std::endl;
143
144 TFile *input3 = TFile::Open("Preselection/Skynet_Preselection_Zprime1000.root");
145 std::cout << "--- TMVAnalysis : Accessing " << "ZPrime1000.root" << std::endl;
146
147 TFile *input4 = TFile::Open("Preselection/Skynet_Preselection_Zprime1250.root");
148 std::cout << "--- TMVAnalysis : Accessing " << "ZPrime1250.root" << std::endl;
149
150 TFile *input5 = TFile::Open("Preselection/Skynet_Preselection_Zprime1500.root");
151 std::cout << "--- TMVAnalysis : Accessing " << "ZPrime1500.root" << std::endl;
152
153 TFile *input6 = TFile::Open("Preselection/Skynet_Preselection_Zprime2000.root");
154 std::cout << "--- TMVAnalysis : Accessing " << "ZPrime2000.root" << std::endl;
155
156 TFile *input7 = TFile::Open("Preselection/Skynet_Preselection_TTbar.root");
157 std::cout << "--- TMVAnalysis : Accessing " << "TTbar.root" << std::endl;
158
159 //TFile *input8 = TFile::Open("./files/Skynet_TTbar_cut0p5/Skynet_TTbar_M1TeV.root");
160 //std::cout << "--- TMVAnalysis : Accessing " << "TTbar_M1TeV.root" << std::endl;
161
162 TFile *input9 = TFile::Open("Preselection/Skynet_Preselection_ST-t-T.root");
163 std::cout << "--- TMVAnalysis : Accessing " << "SingleTop_tChannel.root" << std::endl;
164
165 TFile *input10 = TFile::Open("Preselection/Skynet_Preselection_ST-s-T.root");
166 std::cout << "--- TMVAnalysis : Accessing " << "SingleTop_sChannel.root" << std::endl;
167
168 TFile *input11 = TFile::Open("Preselection/Skynet_Preselection_ST-tW-T.root");
169 std::cout << "--- TMVAnalysis : Accessing " << "SingleTop_tWChannel.root" << std::endl;
170
171 TFile *input12 = TFile::Open("Preselection/Skynet_Preselection_WJets.root");
172 std::cout << "--- TMVAnalysis : Accessing " << "WJets.root" << std::endl;
173
174 TFile *input13 = TFile::Open("Preselection/Skynet_Preselection_ZJets.root");
175 std::cout << "--- TMVAnalysis : Accessing " << "ZJets.root" << std::endl;
176
177 //TFile *input14 = TFile::Open("./files/Skynet_TTbar_cut0p5/Skynet_ZZ.root");
178 //std::cout << "--- TMVAnalysis : Accessing " << "ZZ.root" << std::endl;
179
180 //TFile *input15 = TFile::Open("./files/Skynet_TTbar_cut0p5/Skynet_WZ.root");
181 //std::cout << "--- TMVAnalysis : Accessing " << "WZ.root" << std::endl;
182
183 //TFile *input16 = TFile::Open("./files/Skynet_TTbar_cut0p5/Skynet_WW.root");
184 //std::cout << "--- TMVAnalysis : Accessing " << "WW.root" << std::endl;
185
186 TFile *input17 = TFile::Open("Preselection/Skynet_Preselection_QCD.root");
187 std::cout << "--- TMVAnalysis : Accessing " << "InclusiveMu15.root" << std::endl;
188
189
190 //Signal
191 //TTree *M500 = (TTree*)input1->Get("PATuple");
192 TTree *M750 = (TTree*)input2->Get("PATuple");
193 TTree *M1000 = (TTree*)input3->Get("PATuple");
194 TTree *M1250 = (TTree*)input4->Get("PATuple");
195 TTree *M1500 = (TTree*)input5->Get("PATuple");
196 TTree *M2000 = (TTree*)input6->Get("PATuple");
197
198 //Background
199 TTree *ttbar = (TTree*)input7->Get("PATuple");
200 //TTree *ttcont = (TTree*)input8->Get("PATuple");
201 TTree *st_t = (TTree*)input9->Get("PATuple");
202 TTree *st_s = (TTree*)input10->Get("PATuple");
203 TTree *st_tW = (TTree*)input11->Get("PATuple");
204 TTree *wjets = (TTree*)input12->Get("PATuple");
205 TTree *zjets = (TTree*)input13->Get("PATuple");
206 //TTree *zz = (TTree*)input14->Get("PATuple");
207 //TTree *wz = (TTree*)input15->Get("PATuple");
208 //TTree *ww = (TTree*)input16->Get("PATuple");
209 TTree *qcd = (TTree*)input17->Get("PATuple");
210
211
212
213
214
215 // global event weights per tree (see below for setting event-wise weights)
216 Double_t signalWeight = 1.0;
217 Double_t backgroundWeight = 1.0;
218
219 // ====== register trees ====================================================
220 //
221 // the following method is the prefered one:
222 // you can add an arbitrary number of signal or background trees
223 //factory->AddSignalTree ( M500, signalWeight );
224 factory->AddSignalTree ( M750, signalWeight );
225 factory->AddSignalTree ( M1000, signalWeight );
226 factory->AddSignalTree ( M1250, signalWeight );
227 factory->AddSignalTree ( M1500, signalWeight );
228 factory->AddSignalTree ( M2000, signalWeight );
229 factory->AddBackgroundTree( qcd, backgroundWeight );
230 factory->AddBackgroundTree( ttbar, backgroundWeight );
231 //factory->AddBackgroundTree( ttcont, backgroundWeight );
232 factory->AddBackgroundTree( wjets, backgroundWeight );
233 factory->AddBackgroundTree( zjets, backgroundWeight );
234 factory->AddBackgroundTree( st_t, backgroundWeight );
235 factory->AddBackgroundTree( st_s, backgroundWeight );
236 factory->AddBackgroundTree( st_tW, backgroundWeight );
237 //factory->AddBackgroundTree( zz, backgroundWeight );
238 //factory->AddBackgroundTree( wz, backgroundWeight );
239 //factory->AddBackgroundTree( ww, backgroundWeight );
240
241
242 TCut mycuts = ""; // for example: TCut mycuts = "abs(var1)<0.5 && abs(var2-0.5)<1";
243 TCut mycutb = ""; // for example: TCut mycutb = "abs(var1)<0.5";
244
245 // tell the factory to use all remaining events in the trees after training for testing:
246 factory->PrepareTrainingAndTestTree( mycuts, mycutb, "SplitMode=Random:NormMode=NumEvents:!V" );
247
248 factory->BookMethod( TMVA::Types::kBDT, "BDT", "H:V:NTrees=200:nEventsMin=20:nCuts=20:PruneStrength=-1:NodePurityLimit=0.5" );
249
250
251 // Train MVAs using the set of training events
252 factory->TrainAllMethods();
253
254 // ---- Evaluate all MVAs using the set of test events
255 factory->TestAllMethods();
256
257 // ----- Evaluate and compare performance of all configured MVAs
258 factory->EvaluateAllMethods();
259
260 // --------------------------------------------------------------
261
262 // Save the output
263 outputFile->Close();
264
265 std::cout << "==> Wrote root file: " << outputFile->GetName() << std::endl;
266 std::cout << "==> TMVAnalysis is done!" << std::endl;
267
268 delete factory;
269
270 // Launch the GUI for the root macros
271 if (!gROOT->IsBatch()) TMVAGui( outfileName );
272
273 }
274
275
276
277
278
279
280
281
282
283
284
285