#include "TFile.h"
#include "TTree.h"
#include "TMVA/Factory.h"
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include "MVAPIDResult.h"
Go to the source code of this file.
|
void | BuildTree (std::string inFile, std::string outFile) |
|
void | TrainMVA (std::vector< std::string > signalFiles, std::vector< std::string > backgroundFiles, std::string outputFile, std::string jobName) |
|
void | PrintRes (std::string inFile) |
|
void BuildTree |
( |
std::string |
inFile, |
|
|
std::string |
outFile |
|
) |
| |
Definition at line 12 of file TrainMVA.C.
References anab::MVAPIDResult::concentration, anab::MVAPIDResult::conicalness, anab::MVAPIDResult::coreHaloRatio, anab::MVAPIDResult::dEdxEnd, anab::MVAPIDResult::dEdxEndRatio, anab::MVAPIDResult::dEdxStart, anab::MVAPIDResult::evalRatio, anab::MVAPIDResult::isStoppingReco, anab::MVAPIDResult::isTrack, anab::MVAPIDResult::length, and anab::MVAPIDResult::nSpacePoints.
13 TFile* fIn=
new TFile(inFile.c_str());
14 TTree* tr=(TTree*)fIn->Get(
"pid/MVAPID");
15 std::vector<anab::MVAPIDResult>* mvares=0;
16 tr->SetBranchAddress(
"MVAResult",&mvares);
17 TFile* fOut=
new TFile(outFile.c_str(),
"RECREATE");
18 TTree* mvaTree =
new TTree(
"mvaTree",
"mvaTree");
20 float evalRatio, concentration, coreHaloRatio, conicalness;
21 float dEdxStart, dEdxEnd, dEdxEndRatio;
23 int isTrack, isStoppingReco;
25 mvaTree->Branch(
"evalRatio",&evalRatio,
"evalRatio/F");
26 mvaTree->Branch(
"concentration",&concentration,
"concentration/F");
27 mvaTree->Branch(
"coreHaloRatio",&coreHaloRatio,
"coreHaloRatio/F");
28 mvaTree->Branch(
"conicalness",&conicalness,
"conicalness/F");
29 mvaTree->Branch(
"dEdxStart",&dEdxStart,
"dEdxStart/F");
30 mvaTree->Branch(
"dEdxEnd",&dEdxEnd,
"dEdxEnd/F");
31 mvaTree->Branch(
"dEdxEndRatio",&dEdxEndRatio,
"dEdxEndRatio/F");
32 mvaTree->Branch(
"length",&length,
"length/F");
33 mvaTree->Branch(
"isTrack",&isTrack,
"isTrack/I");
34 mvaTree->Branch(
"isStoppingReco",&isStoppingReco,
"isStoppingReco/I");
36 for(
int iEntry=0;iEntry<tr->GetEntries();++iEntry){
38 if(!mvares->size())
continue;
41 for(
unsigned int iRes=0;iRes!=mvares->size();++iRes){
42 if((((*mvares)[iRes]).nSpacePoints)>(biggestTrack->
nSpacePoints)){
43 biggestTrack=&((*mvares)[iRes]);
54 length=biggestTrack->
length;
void PrintRes |
( |
std::string |
inFile | ) |
|
Definition at line 101 of file TrainMVA.C.
References anab::MVAPIDResult::mvaOutput, and anab::MVAPIDResult::nSpacePoints.
103 TFile* fIn=
new TFile(inFile.c_str());
104 TTree* tr=(TTree*)fIn->Get(
"pid/ANAB");
105 std::vector<anab::MVAPIDResult>* mvares=0;
106 tr->SetBranchAddress(
"MVAResult",&mvares);
108 for(
int iEntry=0;iEntry<tr->GetEntries();++iEntry){
109 tr->GetEntry(iEntry);
110 if(!mvares->size())
continue;
113 for(
unsigned int iRes=0;iRes!=mvares->size();++iRes){
114 if((((*mvares)[iRes]).nSpacePoints)>(biggestTrack->
nSpacePoints)){
115 biggestTrack=&((*mvares)[iRes]);
119 std::cout<<biggestTrack->
mvaOutput.at(
string(
"ANN"))<<std::endl;
std::map< std::string, double > mvaOutput
void TrainMVA |
( |
std::vector< std::string > |
signalFiles, |
|
|
std::vector< std::string > |
backgroundFiles, |
|
|
std::string |
outputFile, |
|
|
std::string |
jobName |
|
) |
| |
Definition at line 66 of file TrainMVA.C.
68 TFile* fOut =
new TFile(outputFile.c_str(),
"RECREATE");
69 TMVA::Factory* factory =
new TMVA::Factory( jobName.c_str(), fOut,
"" );
71 std::vector<TTree*> sigTrees;
74 TFile* fIn=
new TFile(fIter->c_str());
75 factory->AddSignalTree((TTree*)fIn->Get(
"mvaTree"));
79 TFile* fIn=
new TFile(fIter->c_str());
80 factory->AddBackgroundTree((TTree*)fIn->Get(
"mvaTree"));
83 factory->AddVariable(
"evalRatio",
'F');
84 factory->AddVariable(
"concentration",
'F');
85 factory->AddVariable(
"coreHaloRatio",
'F');
86 factory->AddVariable(
"conicalness",
'F');
87 factory->AddVariable(
"dEdxStart",
'F');
88 factory->AddVariable(
"dEdxEnd",
'F');
89 factory->AddVariable(
"dEdxEndRatio",
'F');
91 factory->BookMethod( TMVA::Types::kTMlpANN,
"ANN",
"" );
92 factory->BookMethod( TMVA::Types::kBDT,
"BDT",
"" );
93 factory->TrainAllMethods();
94 factory->TestAllMethods();
95 factory->EvaluateAllMethods();