ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/MultivariateAnalysis/macros/TMVApplication.C
(Generate patch)

Comparing UserCode/LJMet/MultivariateAnalysis/macros/TMVApplication.C (file contents):
Revision 1.1 by kukartse, Thu Nov 20 22:34:49 2008 UTC vs.
Revision 1.3 by kukartse, Thu Mar 5 17:30:20 2009 UTC

# Line 12 | Line 12
12   * ------------------------------------------------------------------------------ *
13   **********************************************************************************/
14  
15 + #include <iostream>
16 +
17 + #include "TCut.h"
18 + #include "TFile.h"
19 + #include "TSystem.h"
20 + #include "TTree.h"
21 + #include "TStopwatch.h"
22 + // requires links
23 + #include "TMVA/Factory.h"
24 + #include "TMVA/Tools.h"
25 + #include "TMVA/Config.h"
26 + #include "TMVA/Reader.h"
27 +
28   // ---------------------------------------------------------------
29   // choose MVA methods to be applied
30   Bool_t Use_Cuts            = 0;
# Line 92 | Line 105 | void TMVApplication( TString myMethodLis
105     // create a set of variables and declare them to the reader
106     // - the variable names must corresponds in name and type to
107     // those given in the weight file(s) that you use
108 <   Float_t var1, var2;
109 <   Float_t var3, var4;
110 <   reader->AddVariable( "var1+var2", &var1 );
111 <   reader->AddVariable( "var1-var2", &var2 );
112 <   reader->AddVariable( "var3", &var3 );
113 <   reader->AddVariable( "var4", &var4 );
108 >   Float_t _getHt3;
109 >   Float_t _aplanarity;
110 >   Float_t _dPhiLMet;
111 >   Float_t _sphericity;
112 >   Float_t _jet1Jet2DeltaR;
113 >   Float_t _leptonJetDeltaR;
114 >   //
115 >   // ORDER of variables is important here! Must be the same as in the weights file!!!
116 >   //
117 >   reader->AddVariable("getHt3", &_getHt3);
118 >   reader->AddVariable("aplanarity", &_aplanarity);
119 >   reader->AddVariable("dPhiLMet", &_dPhiLMet);
120 >   reader->AddVariable("sphericity", &_sphericity);
121 >   reader->AddVariable("jet1Jet2DeltaR", &_jet1Jet2DeltaR);
122 >   reader->AddVariable("leptonJetDeltaR", &_leptonJetDeltaR);
123  
124     //
125     // book the MVA methods
# Line 131 | Line 153 | void TMVApplication( TString myMethodLis
153    
154     // book output histograms
155     UInt_t nbin = 100;
156 +   TFile *target  = new TFile( "TMVApp.root","RECREATE" );
157     TH1F *histLk, *histLkD, *histLkPCA, *histPD, *histPDD, *histPDPCA, *histKNN, *histHm, *histFi;
158     TH1F *histNn, *histNnC, *histNnT, *histBdt, *histBdtD, *histRf;
159     TH1F *histSVMG, *histSVMP, *histSVML;
160     TH1F *histFDAMT, *histFDAGA;
161  
162     if (Use_Likelihood)    histLk    = new TH1F( "MVA_Likelihood",    "MVA_Likelihood",    nbin,  0, 1 );
163 +   TTree * _tree = new TTree("classifier","classifier");
164 +   Double_t _ll = -1.0;
165 +   TBranch * b_ll = _tree->Branch("MVA_Likelihood", &_ll, "classifier/D");
166     if (Use_LikelihoodD)   histLkD   = new TH1F( "MVA_LikelihoodD",   "MVA_LikelihoodD",   nbin,  0.000001, 0.9999 );
167     if (Use_LikelihoodPCA) histLkPCA = new TH1F( "MVA_LikelihoodPCA", "MVA_LikelihoodPCA", nbin,  0, 1 );
168     if (Use_PDERS)         histPD    = new TH1F( "MVA_PDERS",         "MVA_PDERS",         nbin,  0, 1 );
# Line 169 | Line 195 | void TMVApplication( TString myMethodLis
195     // we'll later on use only the "signal" events for the test in this example.
196     //  
197     TFile *input(0);
198 <   TString fname = "./tmva_example.root";  
198 >   //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/fake_data/tmva_fake_data_100pb-summer08-09jan2009.root";  
199 >   //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/fake_data/tmva_fake_data_20pb-summer08-25feb2009.root";  
200 >   //TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/training/tmva_training-summer08-25feb2009.root";
201 >   //TString fname = "./tmva_fake_data_200pb-summer08-25feb2009.root";  
202 >   TString fname = "/uscms_data/d1/lpcljm/MVA/Summer08/fake_data/tmva_fake_data_20pb-summer08-25feb2009.root";  
203 >
204     if (!gSystem->AccessPathName( fname )) {
205        // first we try to find tmva_example.root in the local directory
206        cout << "--- accessing data file: " << fname << endl;
# Line 194 | Line 225 | void TMVApplication( TString myMethodLis
225     // - you can use the same variables as above which is slightly faster,
226     //   but of course you can use different ones and copy the values inside the event loop
227     //
228 <   TTree* theTree = (TTree*)input->Get("TreeS");
228 >   TTree* theTree = (TTree*)input->Get("data");
229 >   //TTree* theTree = (TTree*)input->Get("ttbar");
230 >   //TTree* theTree = (TTree*)input->Get("wjets");
231 >   //TTree* theTree = (TTree*)input->Get("qcd");
232     cout << "--- select signal sample" << endl;
233 <   Float_t userVar1, userVar2;
234 <   theTree->SetBranchAddress( "var1", &userVar1 );
235 <   theTree->SetBranchAddress( "var2", &userVar2 );
236 <   theTree->SetBranchAddress( "var3", &var3 );
237 <   theTree->SetBranchAddress( "var4", &var4 );
233 >   //Float_t userVar1, userVar2;
234 >   Double_t aplanarity;
235 >   Double_t getHt3;
236 >   Double_t sphericity;
237 >   Double_t jet1Jet2DeltaR;
238 >   Double_t dPhiLMet;
239 >   Double_t leptonJetDeltaR;
240 >   theTree->SetBranchAddress( "aplanarity", &aplanarity );
241 >   theTree->SetBranchAddress( "getHt3", &getHt3 );
242 >   theTree->SetBranchAddress( "sphericity", &sphericity );
243 >   theTree->SetBranchAddress( "jet1Jet2DeltaR", &jet1Jet2DeltaR );
244 >   theTree->SetBranchAddress( "dPhiLMet", &dPhiLMet );
245 >   theTree->SetBranchAddress( "leptonJetDeltaR", &leptonJetDeltaR );
246  
247     // efficiency calculator for cut method
248     Int_t    nSelCuts = 0, nSelCutsD = 0, nSelCutsGA = 0;
# Line 216 | Line 258 | void TMVApplication( TString myMethodLis
258  
259        theTree->GetEntry(ievt);
260  
261 <      var1 = userVar1 + userVar2;
262 <      var2 = userVar1 - userVar2;
261 >      //var1 = userVar1 + userVar2;
262 >      //var2 = userVar1 - userVar2;
263 >      _aplanarity = (Float_t)aplanarity;
264 >      _getHt3 = (Float_t)getHt3;
265 >      _sphericity = (Float_t)sphericity;
266 >      _jet1Jet2DeltaR = (Float_t)jet1Jet2DeltaR;
267 >      _dPhiLMet = (Float_t)dPhiLMet;
268 >      _leptonJetDeltaR = (Float_t)leptonJetDeltaR;
269      
270        //
271        // return the MVAs and fill to histograms
# Line 238 | Line 286 | void TMVApplication( TString myMethodLis
286           if (passed) nSelCutsGA++;
287        }
288  
289 <      if (Use_Likelihood   )   histLk    ->Fill( reader->EvaluateMVA( "Likelihood method"    ) );
289 >      if (Use_Likelihood   ){
290 >        _ll = (Double_t)(reader->EvaluateMVA("Likelihood method") );
291 >        histLk    ->Fill( reader->EvaluateMVA( "Likelihood method"    ) );
292 >        _tree    ->Fill();
293 >      }
294        if (Use_LikelihoodD  )   histLkD   ->Fill( reader->EvaluateMVA( "LikelihoodD method"   ) );
295        if (Use_LikelihoodPCA)   histLkPCA ->Fill( reader->EvaluateMVA( "LikelihoodPCA method" ) );
296        if (Use_PDERS        )   histPD    ->Fill( reader->EvaluateMVA( "PDERS method"         ) );
# Line 275 | Line 327 | void TMVApplication( TString myMethodLis
327     if (Use_CutsGA) cout << "--- efficiency for CutsGA method: " << double(nSelCutsGA)/theTree->GetEntries()
328                          << " (for a required signal efficiency of " << effS << ")" << endl;
329  
330 +   /*************************
331     //
332     // write histograms
333     //
# Line 301 | Line 354 | void TMVApplication( TString myMethodLis
354     if (Use_FDA_GA       )   histFDAGA ->Write();
355  
356     if (Use_Fisher       ) { probHistFi->Write(); rarityHistFi->Write(); }
357 +
358     target->Close();
359 +   *******************************/
360 +
361 +   target->cd();
362 +   target->Write();
363 +   delete target;
364  
365     cout << "--- created root file: \"TMVApp.root\" containing the MVA output histograms" << endl;
366    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines