I am trying to use TMVA for the first time, hoping to train a BDT discriminator. At the moment I was trying to train a simple discriminator using 2 variables, and to add signal and background training and test events “by hand”. The relevant parts of my code could be summarized as:
TString outfileName("TMVA.root");
TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile, "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification" );
TMVA::DataLoader *dataloader=new TMVA::DataLoader("dataset");
dataloader->AddVariable( "a", 'F' );
dataloader->AddVariable( "b", 'F' );
for(Long64_t it = 0; it < treeSignal->GetEntries();; ++it){
treeSignal->GetEntry(it);
std::vector<Double_t> vars(2);
vars[0] = a;
vars[1] = b;
dataloader->AddSignalTrainingEvent( vars, 1. );
}
for(Long64_t it = 0; it < treeBkg->GetEntries();; ++it){
treeBkg->GetEntry(it);
std::vector<Double_t> vars(2);
vars[0] = a;
vars[1] = b;
dataloader->AddBackgroundTrainingEvent( vars, 1. );
}
factory->BookMethod( dataloader, TMVA::Types::kBDT, "BDT", "!H:!V:NTrees=850:MinNodeSize=2.5%:MaxDepth=3:BoostType=AdaBoost:AdaBoostBeta=0.5:UseBaggedBoost:BaggedSampleFraction=0.5:SeparationType=GiniIndex:nCuts=20");
factory->TrainAllMethods();
However, the moment I try “factory->BookMethod(…)” the code crashes with the error message “terminate called after throwing an instance of ‘std::bad_alloc’ what(): std::bad_alloc Aborted (core dumped)”, and I can not seem to figure out what the problem is. What am I missing here that makes the code crash? (extra note : For the moment my code and trees are organized in such a way that I can only add training events by hand, and can not use “->AddSignalTree” etc.) Thanks in advance for the help!