Problem with TMVA package. Factory methods are not known

I am trying to use TMVA algorithms for classification problem. Here is my program:

#ifndef TMVACLASSIFICATION_C                                                        
#define TMVACLASSIFICATION_C
 
#include "TMVA/Types.h"
 
void TMVAClassification()
{
    TFile* outFile = new TFile("../Data/TMVA/kNN/kNN_Classification.root", "RECREATE");
    
    TFile* sigSrc = new TFile("../Data/tr_ph_selected.root");
    TFile* bkgSrc = new TFile("../Data/tr_ph_selected_mhg.root");
    //Get trees from files
    TTree* sigTree = (TTree*)sigSrc->Get("selected");
    TTree* bkgTree = (TTree*)bkgSrc->Get("selected");
    //Weights of trees
    Double_t sigWeight = 1.0;
    Double_t bkgWeight = 1.0;
    //Create Factory objects
    TMVA::Factory* factory =
        new TMVA::Factory( "EtotPtotClf", outFile,
        "AnalysisType=Classification:VarTransform=N,G,D" );
    //Add trees to the analysis
    factory->AddSignalTree( sigTree, sigWeight );
    factory->AddBackgroundTree( bkgTreeTrain, bkgWeight );
    //Add varibles of interest
    factory->AddVariable( "eTotal", "Total Energy of Photons", "MeV", 'F' );
    factory->AddVariable( "pTotal", "Total Momentum of Photons", "MeV/c", 'F' );
    //Preparing trees for processing
    TMVA::Factory::PrepareTrainingAndTestTree();
    //Book method!!! Let's use k Nearest Neighbors method! What's up? =)
    factory->BookMethod( TMVA::Types::kNN, "kNN", "nkKK=40")
    //Train methods
    factory->TrainAllMethods();
    //Test methods
    factory->TestAllMethods();
    //Evaluate methods
    factory->EvaluateAllMethods();
}
#endif              

When I try to compile the above macro I get

error:
no member named ‘AddSignalTree’ in 'TMVA::Factory’
factory->AddSignalTree( sigTree, sigWeight );

There are similar errors there? What should I do?


I am using

   ------------------------------------------------------------
  | Welcome to ROOT 6.08/02                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-08-02, 2 December 2016                         |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

I have found that I should use DataLoader object because of the recent ROOT version. Everything is OK now.
Should I delete this question or provide working code?

You solved your problem, so I marked it as solved :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.