Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trainBDT.C
Go to the documentation of this file.
1 //
2 // May 12, 2016 D. Lawrence
3 //
4 // This macro is used to train a BDT to be used in
5 // the Level-3 trigger. It assumes there already
6 // exists a file l3bdt.root that was created using
7 // the l3bdt plugin like this:
8 //
9 // hd_root -o l3bdt.root -PPLUGINS=L3BDTtree file.evio
10 //
11 
12 #include <iostream>
13 
14 #include<TMVA/Factory.h>
15 
16 void trainBDT(void)
17 {
18  // Open input file and get tree
19  TFile *infile = new TFile("l3bdt.root");
20  TTree *l3tree = (TTree*)infile->Get("l3tree");
21  if(l3tree == NULL){
22  cout << "Couldn't open \"l3bdt.root\"!" << endl;
23  return;
24  }
25 
26  // Open output root file (for TMVA)
27  TFile *outfile = new TFile("l3BDT_out.root", "RECREATE");
28  TMVA::Factory *fac = new TMVA::Factory("L3",outfile,"");
29 
30  // Specify input tree that contains both signal and background
31  TCut signalCut("Evisible>=4.0 && ((Npshits+Npschits)<=1)");
32  TCut backgroundCut("Evisible<4.0 && ((Npshits+Npschits)<=1)");
33  fac->SetInputTrees(l3tree, signalCut, backgroundCut);
34 
35  // Add variables
36  fac->AddVariable("Nstart_counter", 'I');
37  fac->AddVariable("Ntof", 'I');
38  fac->AddVariable("Nbcal_points", 'I');
39  fac->AddVariable("Nbcal_clusters", 'I');
40  fac->AddVariable("Ebcal_points", 'F');
41  fac->AddVariable("Ebcal_clusters", 'F');
42  fac->AddVariable("Nfcal_clusters", 'I');
43  fac->AddVariable("Efcal_clusters", 'F');
44  fac->AddVariable("Ntrack_candidates", 'I');
45  fac->AddVariable("Ptot_candidates", 'F');
46 
47  TCut preSelectCut("");
48  fac->PrepareTrainingAndTestTree(preSelectCut,"");
49  fac->BookMethod(TMVA::Types::kBDT, "BDT", "");
50 
51  fac->TrainAllMethods();
52  fac->TestAllMethods();
53  fac->EvaluateAllMethods();
54 
55  delete fac;
56 
57  outfile->Close();
58  delete outfile;
59 }
60 
TFile * infile
Definition: tw_corr.C:45
void trainBDT(void)
Definition: trainBDT.C:16
TFile * outfile
Definition: tw_corr.C:46