2 #include "TMVA/Factory.h" 12 void BuildTree(std::string inFile, std::string outFile)
14 TFile* fIn =
new TFile(inFile.c_str());
15 TTree* tr = (TTree*)fIn->Get(
"pid/MVAPID");
16 std::vector<anab::MVAPIDResult>* mvares = 0;
17 tr->SetBranchAddress(
"MVAResult", &mvares);
18 TFile* fOut =
new TFile(outFile.c_str(),
"RECREATE");
19 TTree* mvaTree =
new TTree(
"mvaTree",
"mvaTree");
21 float evalRatio, concentration, coreHaloRatio, conicalness;
22 float dEdxStart, dEdxEnd, dEdxEndRatio;
24 int isTrack, isStoppingReco;
26 mvaTree->Branch(
"evalRatio", &evalRatio,
"evalRatio/F");
27 mvaTree->Branch(
"concentration", &concentration,
"concentration/F");
28 mvaTree->Branch(
"coreHaloRatio", &coreHaloRatio,
"coreHaloRatio/F");
29 mvaTree->Branch(
"conicalness", &conicalness,
"conicalness/F");
30 mvaTree->Branch(
"dEdxStart", &dEdxStart,
"dEdxStart/F");
31 mvaTree->Branch(
"dEdxEnd", &dEdxEnd,
"dEdxEnd/F");
32 mvaTree->Branch(
"dEdxEndRatio", &dEdxEndRatio,
"dEdxEndRatio/F");
33 mvaTree->Branch(
"length", &length,
"length/F");
34 mvaTree->Branch(
"isTrack", &isTrack,
"isTrack/I");
35 mvaTree->Branch(
"isStoppingReco", &isStoppingReco,
"isStoppingReco/I");
37 for (
int iEntry = 0; iEntry < tr->GetEntries(); ++iEntry) {
39 if (!mvares->size())
continue;
42 for (
unsigned int iRes = 0; iRes != mvares->size(); ++iRes) {
43 if ((((*mvares)[iRes]).nSpacePoints) > (biggestTrack->
nSpacePoints)) {
44 biggestTrack = &((*mvares)[iRes]);
53 dEdxEnd = biggestTrack->
dEdxEnd;
55 length = biggestTrack->
length;
56 isTrack = biggestTrack->
isTrack;
67 void TrainMVA(std::vector<std::string> signalFiles,
68 std::vector<std::string> backgroundFiles,
69 std::string outputFile,
73 TFile* fOut =
new TFile(outputFile.c_str(),
"RECREATE");
74 TMVA::Factory* factory =
new TMVA::Factory(jobName.c_str(), fOut,
"");
76 std::vector<TTree*> sigTrees;
80 TFile* fIn =
new TFile(fIter->c_str());
81 factory->AddSignalTree((TTree*)fIn->Get(
"mvaTree"));
85 fIter != backgroundFiles.end();
87 TFile* fIn =
new TFile(fIter->c_str());
88 factory->AddBackgroundTree((TTree*)fIn->Get(
"mvaTree"));
91 factory->AddVariable(
"evalRatio",
'F');
92 factory->AddVariable(
"concentration",
'F');
93 factory->AddVariable(
"coreHaloRatio",
'F');
94 factory->AddVariable(
"conicalness",
'F');
95 factory->AddVariable(
"dEdxStart",
'F');
96 factory->AddVariable(
"dEdxEnd",
'F');
97 factory->AddVariable(
"dEdxEndRatio",
'F');
99 factory->BookMethod(TMVA::Types::kTMlpANN,
"ANN",
"");
100 factory->BookMethod(TMVA::Types::kBDT,
"BDT",
"");
101 factory->TrainAllMethods();
102 factory->TestAllMethods();
103 factory->EvaluateAllMethods();
111 TFile* fIn =
new TFile(inFile.c_str());
112 TTree* tr = (TTree*)fIn->Get(
"pid/ANAB");
113 std::vector<anab::MVAPIDResult>* mvares = 0;
114 tr->SetBranchAddress(
"MVAResult", &mvares);
116 for (
int iEntry = 0; iEntry < tr->GetEntries(); ++iEntry) {
117 tr->GetEntry(iEntry);
118 if (!mvares->size())
continue;
121 for (
unsigned int iRes = 0; iRes != mvares->size(); ++iRes) {
122 if ((((*mvares)[iRes]).nSpacePoints) > (biggestTrack->
nSpacePoints)) {
123 biggestTrack = &((*mvares)[iRes]);
127 std::cout << biggestTrack->
mvaOutput.at(
string(
"ANN")) << std::endl;
std::map< std::string, double > mvaOutput
void BuildTree(std::string inFile, std::string outFile)
void PrintRes(std::string inFile)
void TrainMVA(std::vector< std::string > signalFiles, std::vector< std::string > backgroundFiles, std::string outputFile, std::string jobName)