[root6] Easiest way to fill MVA response to TTree?

Hello,

What’s the easiest way to fill MVA response to TTree? With root5, I just make a Class file from the TTree, then add something like the following in the .C file:

   if (fChain == 0) return;

   TFile *outFile = TFile::Open("withBDT1.root", "recreate");
   TTree *newTree = fChain->CloneTree(-1);
   
   Double_t BDTGVal;
   TBranch *BDTG_Branch = newTree->Branch("BDTGVal", &BDTGVal, "BDTGVal/D");

   // the training input variables
   const char* inputVars[] = { ... };

   //...
   std::vector<std::string> inputVarVec;
  
   
   for (size_t ivar = 0; ivar < numVars ; ivar++) {
     inputVarVec.push_back( inputVars[ivar] );
   }

   gROOT->LoadMacro("TMVAClassification_BDTG.class.C+");

   IClassifierReader* BDTGResponse = new ReadBDTG( inputVarVec );

   std::vector<Double_t> inputVec( numVars );

   Long64_t nentries = fChain->GetEntriesFast();
   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
     Long64_t ientry = LoadTree(jentry);
     if (ientry < 0) break;
     nb = fChain->GetEntry(jentry);   nbytes += nb;
  
     //... 
     (inputVec)[0]=(Double_t) ...
     //... 
     BDTGVal  = (Double_t)BDTGResponse->GetMvaValue( inputVec );
     
     BDTG_Branch->Fill();   
   }
   
   newTree->Write();
   outFile->Write();
...

But root6 is more strict, and this doesn’t work anymore. A small example would be appreciated. Thanks!

Replace this by (at the starting of your file):

#include "TMVAClassification_BDTG.class.C+"

Cheers,
Philippe.

1 Like

Yes, this is working! Thanks a lot!
BTW: Are this kind of changes from root 5->6 summarised somewhere?