37 TTree *fillTree(TTree * tree, Int_t nPoints, Double_t offset, Double_t scale, UInt_t seed = 100)
44 tree->SetBranchAddress(
"x", &x);
45 tree->SetBranchAddress(
"y", &y);
46 tree->SetBranchAddress(
"eventID", &eventID);
48 for (Int_t n = 0; n < nPoints; ++n) {
49 x = rng.Gaus(offset, scale);
50 y = rng.Gaus(offset, scale);
60 tree->ResetBranchAddresses();
64 int TMVACrossValidationApplication()
67 TMVA::Tools::Instance();
70 TMVA::Reader *reader =
new TMVA::Reader(
"!Color:!Silent:!V");
76 reader->AddVariable(
"x", &x);
77 reader->AddVariable(
"y", &y);
78 reader->AddSpectator(
"eventID", &eventID);
81 TString jobname(
"TMVACrossEvaluation");
83 TString methodName =
"BDTG";
84 TString weightfile = TString(
"dataset/weights/") + jobname +
"_" + methodName + TString(
".weights.xml");
86 Bool_t weightfileExists = (gSystem->AccessPathName(weightfile) == kFALSE);
87 if (weightfileExists) {
88 reader->BookMVA(methodName, weightfile);
90 std::cout <<
"Weightfile for method " << methodName <<
" not found."
91 " Did you run TMVACrossValidation with a specified"
92 " splitExpr?" << std::endl;
98 TString methodName =
"Fisher";
99 TString weightfile = TString(
"dataset/weights/") + jobname +
"_" + methodName + TString(
".weights.xml");
101 Bool_t weightfileExists = (gSystem->AccessPathName(weightfile) == kFALSE);
102 if (weightfileExists) {
103 reader->BookMVA(methodName, weightfile);
105 std::cout <<
"Weightfile for method " << methodName <<
" not found."
106 " Did you run TMVACrossValidation with a specified"
107 " splitExpr?" << std::endl;
113 TTree *tree =
new TTree();
114 tree->Branch(
"x", &x,
"x/F");
115 tree->Branch(
"y", &y,
"y/F");
116 tree->Branch(
"eventID", &eventID,
"eventID/I");
118 fillTree(tree, 1000, 1.0, 1.0, 100);
119 fillTree(tree, 1000, -1.0, 1.0, 101);
120 tree->SetBranchAddress(
"x", &x);
121 tree->SetBranchAddress(
"y", &y);
122 tree->SetBranchAddress(
"eventID", &eventID);
126 TH1F histBDTG{
"BDTG",
"BDTG", nbin, -1, 1};
127 TH1F histFisher{
"Fisher",
"Fisher", nbin, -1, 1};
130 for (Long64_t ievt = 0; ievt < tree->GetEntries(); ievt++) {
131 tree->GetEntry(ievt);
133 Double_t valBDTG = reader->EvaluateMVA(
"BDTG");
134 Double_t valFisher = reader->EvaluateMVA(
"Fisher");
136 histBDTG.Fill(valBDTG);
137 histFisher.Fill(valFisher);
140 tree->ResetBranchAddresses();
144 TFile *target =
new TFile(
"TMVACrossEvaluationApp.root",
"RECREATE");
160 int main(
int argc,
char **argv)
162 TMVACrossValidationApplication();