Classification Application problem

Hello, dear ROOT forum:

I made a modification in the ClassificationApplication macro, and it compiles well but at the time to execute it, sends me an error. Here is part of the modified code,

using namespace TMVA;
void BmesonClassificationApplication( TString myMethodList = "" )
   std::map<std::string,int> Use;

 TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );

   Float_t nB, nMu, B_px, B_py, B_pz, B_kaon_px, B_kaon_py, B_kaon_pz;

   reader->AddVariable( "nB", &nB );
   reader->AddVariable( "nMu", &nMu );
TString dir    = "Dataset_B_Decay/weights/";
   TString prefix = "BmesonClassification";

   // Book method(s)
   for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
      if (it->second) {
         TString methodName = TString(it->first) + TString(" method");
         TString weightfile = dir + prefix + TString("_") + TString(it->first) + TString(".weights.xml");
         reader->BookMVA( methodName, weightfile );

   // Book output histograms
   UInt_t nbin = 100;
  TH1F *histNn(0);
   TH1F *histNnbfgs(0);
   TH1F *histNnbnn(0);
 if (Use["MLP"])           histNn      = new TH1F( "MVA_MLP",           "MVA_MLP",           nbin, -1.25, 1.5 );
 TFile *input(0);
 TString fname = "/data.root";
TFile* signalfile = new TFile("signal.root");
TTree* signaltree = (TTree*)signalfile->Get("rootuple/ntuple");

signaltree->SetBranchAddress( "nB", &nB );
signaltree->SetBranchAddress( "nMu", &nMu );

std::vector<Float_t> vecVar(4); // vector for EvaluateMVA tests

   std::cout << "--- Processing: " << signaltree->GetEntries() << " events" << std::endl;
   TStopwatch sw;
   for (Long64_t ievt=0; ievt<signaltree->GetEntries();ievt++) {

      if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl;


   if (Use["MLP" ])   histNn     ->Fill( reader->EvaluateMVA( "MLP method" ) );
   std::cout << "--- End of event loop: "; sw.Print();
TFile *target  = new TFile( "BmesonClassificationApp.root","RECREATE" );

   if (Use["MLP" ])   histNn     ->Write();

 std::cout << "--- Created root file: \"TMVApp_BmesonClassification.root\" containing the MVA output histograms" << std::endl;

   delete reader;
   std::cout << "==> TMVA_BmesonClassificationApplication is done!" << std::endl << std::endl;

int main( int argc, char** argv )
   TString methodList;
   for (int i=1; i<argc; i++) {
      TString regMethod(argv[i]);
      if(regMethod=="-b" || regMethod=="--batch") continue;
      if (!methodList.IsNull()) methodList += TString(",");
      methodList += regMethod;
   return 0;

The error is:

==> Start BClassificationApplication
<FATAL>                          : <BookMVA> fatal error: unable to open input weight file: Dataset_B_Decay/weights/BmesonClassification_MLP.weights.xml
***> abort program execution
terminate called after throwing an instance of 'std::runtime_error'
  what():  FATAL error

BTW the macro of only BmesonClassification.C works and I obtain the weights files BmesonClassification_BDT.weights.xml, etc. Could you please give a clue that what’s going on?

Thanks a lot and have a nice day :slight_smile:

Hi Karen!

It’s hard to guess what is going wrong. My best guess would be that the relative path of Dataset_B_Decay/weights/BmesonClassification_MLP.weights.xml does not match.

Do you execute the script in the parent directory of Dataset_B_Decay? Is ls -la Dataset_B_Decay/weights/BmesonClassification_MLP.weights.xml valid in the directory you call root ClassificationApplication.C?


1 Like

Hi again Stefan :slight_smile:

I tried your suggestion but it doesn’t enough. But I observe the lines

using namespace TMVA;
if (myMethodList != "") {
      for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;

      std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' );
      for (UInt_t i=0; i<mlist.size(); i++) {
         std::string regMethod(mlist[i]);

Then, I changed the name of the macros of classification and application, as TMVAClassification_Bmeson.C, TMVAClassificationApplication_Bmeson.C, and works. I don’t know if my reasoning is correct, but thanks for your help :slight_smile: