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

**URL:** <https://root-forum.cern.ch/t/root6-easiest-way-to-fill-mva-response-to-ttree/27251>\
**Category:** TMVA\
**Created:** [December 12, 2017, 2:18pm UTC](https://root-forum.cern.ch/t/root6-easiest-way-to-fill-mva-response-to-ttree/27251 "2017-12-12T14:18:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hejb](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@hejb](https://root-forum.cern.ch/u/hejb)\
**Post date:** [December 12, 2017, 2:18pm UTC](https://root-forum.cern.ch/t/root6-easiest-way-to-fill-mva-response-to-ttree/27251/1 "2017-12-12T14:18:10Z")

</div>

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:

```auto
   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!

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [December 12, 2017, 4:02pm UTC](https://root-forum.cern.ch/t/root6-easiest-way-to-fill-mva-response-to-ttree/27251/2 "2017-12-12T16:02:32Z")

</div>

> [@hejb](#):
>
> gROOT-\>LoadMacro(“TMVAClassification\_BDTG.class.C+”);

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

```auto
#include "TMVAClassification_BDTG.class.C+"

```

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![hejb](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/49beb7/32.png) [@hejb](https://root-forum.cern.ch/u/hejb)\
**Post date:** [December 12, 2017, 4:16pm UTC](https://root-forum.cern.ch/t/root6-easiest-way-to-fill-mva-response-to-ttree/27251/3 "2017-12-12T16:16:07Z")

</div>

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