Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vtxRS.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file vtxRS.C
1 #include <TFile.h>
2 #include <TTree.h>
3 #include <TString.h>
4 #include <TChain.h>
5 
6 
7 #if not defined(__CINT__) || defined(__MAKECINT__)
8 // needs to be included when makecint runs (ACLIC)
9 #include "TMVA/Factory.h"
10 #include "TMVA/Tools.h"
11 #endif
12 
13 
14 
15 TChain* handleFile(string name, string extension, string treename, int filecount){
16  TChain *all = new TChain(treename.c_str());
17  string temp;
18  for (int i = 0; i < filecount; ++i)
19  {
20 
21  ostringstream s;
22  s<<i;
23  temp = name+string(s.str())+extension;
24  all->Add(temp.c_str());
25  }
26  return all;
27 }
28 
29 
30 void makeFactory(TTree* signalTree,std::string outfile,std::string factoryname)
31 {
32  using namespace TMVA;
33  TString jobname(factoryname.c_str());
34  TFile *targetFile = new TFile(outfile.c_str(),"RECREATE");
35  Factory *factory = new Factory(jobname,targetFile,"AnalysisType=Regression");
36  factory->AddRegressionTree(signalTree,1.0);
37  factory->AddVariable("track1_pt",'F');
38  factory->AddVariable("track2_pt",'F');
39  factory->AddVariable("track1_phi",'F');
40  factory->AddVariable("track1_phi-track2_phi","d#phi","rad");
41  factory->AddVariable("track1_eta",'F');
42  factory->AddVariable("track1_eta-track2_eta","d#eta","rad");
43  factory->AddVariable("(vtx_radius)/(track_layer+1)",'F');
44  factory->AddVariable("vtx_radius","radius","cm");
45  factory->AddTarget("tvtx_radius","radius","cm");
46 
47  string track_pT_cut = "track1_pt>.6&&track2_pt>.6";
48 
49  //string vtx_radius_cut = "vtx_radius>0"; //can I cut based on label?
50  string tCutInitializer = track_pT_cut;
51  TCut preTraingCuts(tCutInitializer.c_str());
52  factory->PrepareTrainingAndTestTree(preTraingCuts,"nTrain_Regression=0:nTest_Regression=0");
53  factory->BookMethod(Types::kKNN,"kNN14L","VarTransform=G:nkNN=16");
54  factory->BookMethod(Types::kKNN,"kNN12L","VarTransform=G:nkNN=8");
55  //factory->BookMethod( Types::kPDERS, "PDERS", "KernelEstimator=Teepee:NEventsMin=120:NEventsMax=210:VarTransform=G(_V0_,_V1_,_V3_,_V5_)");
56  //factory->BookMethod(Types::kMLP,"MLP_ANN2","HiddenLayers=500,6");
57  //factory->BookMethod(Types::kMLP,"MLP_ANN","HiddenLayers=5");
58 
59 
60  factory->TrainAllMethods();
61  factory->TestAllMethods();
62  factory->EvaluateAllMethods();
63  targetFile->Write();
64  targetFile->Close();
65 }
66 
67 
68 int vtxRS(){
69  using namespace std;
70  string treePath = "/sphenix/user/vassalli/gammasample/conversionembededonlineanalysis";
71  string treeExtension = ".root";
72  string outname = "/direct/phenix+u/vassalli/sphenix/single/Training/condorout/vtxTrainRS.root";
73  unsigned int nFiles=200;
74 
75  TChain *signalTree = handleFile(treePath,treeExtension,"vtxingTree",nFiles);
76  makeFactory(signalTree,outname,"vtxFactory");
77  /* outname="cutTrainE.root";
78  makeFactory(signalTree,backETree,outname,"eback");*/
79 }