#include "TFile.h"
#include "TMVA/Factory.h"
#include "TTree.h"
#include <iostream>
#include <map>
#include <string>
#include <vector>
#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.
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;
void PrintRes |
( |
std::string |
inFile | ) |
|
Definition at line 108 of file TrainMVA.C.
References anab::MVAPIDResult::mvaOutput, and anab::MVAPIDResult::nSpacePoints.
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 TrainMVA |
( |
std::vector< std::string > |
signalFiles, |
|
|
std::vector< std::string > |
backgroundFiles, |
|
|
std::string |
outputFile, |
|
|
std::string |
jobName |
|
) |
| |
Definition at line 67 of file TrainMVA.C.
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();