Home | News | Documentation | Download

TMVA Error TMVAClassification.C

Hello;
i modify TMVAClassification.C script for signal and bkgrd files.

int TMVAClassification( TString myMethodList = "" )
{
   // The explicit loading of the shared libTMVA is done in TMVAlogon.C, defined in .rootrc
   // if you use your private .rootrc, or run from a different directory, please copy the
   // corresponding lines from .rootrc

   // Methods to be processed can be given as an argument; use format:
   //
   //     mylinux~> root -l TMVAClassification.C\(\"myMethod1,myMethod2,myMethod3\"\)

   //---------------------------------------------------------------
   // This loads the library
   TMVA::Tools::Instance();

//______________________________________________________________________________________________
   // Default MVA methods to be trained + tested
   std::map<std::string,int> Use;
   // Boosted Decision Trees
   Use["BDT"]             = 1; // uses Adaptive Boost
   Use["BDTG"]            = 0; // uses Gradient Boost
   Use["BDTB"]            = 0; // uses Bagging
   Use["BDTD"]            = 0; // decorrelation + Adaptive Boost
   Use["BDTF"]            = 0; // allow usage of fisher discriminant for node splitting
//_________________________________________________________________________________________________

  //output file which will contain results from TMVA
   TString outfileName( "TMVA_out.root" );
   TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

   //TMVA factory, which carries analysis
   TMVA::Factory *factory = new TMVA::Factory("TMVAClassification",outputFile,"V:!Silent:Color:Transformations=I:DrawProgressBar:AnalysisType=Classification");

   TMVA::DataLoader *dataloader=new TMVA::DataLoader("dataset");
   
   Double_t signalWeight = 1.0;
   Double_t backgroundWeight=1.0;

   //Signal & Background Files

   TFile* signal = new TFile("/path/to/file/signal.root");
   TTree* sigTree = (TTree*)(signal->Get("Tree"));
   
   TFile* data = new TFile("/path/to/file/background.root");
   TTree* dataTree = (TTree*)(data->Get("Tree"));

   dataloader->AddSignalTree(sigTree,signalWeight);
   dataloader->AddBackgroundTree(dataTree,backgroundWeight);

   TCut mycuts="(Jet_size==511||Jet_size==-511)";
   TCut mycutb="MissingET_size>5400."; 

   //List of Variables
   dataloader->AddVariable("Jet_size",'F');
   dataloader->AddVariable("Electron_size",'F');
   dataloader->AddVariable("Photon_size",'F'); 
   dataloader->AddVariable("MissingET_size",'F');

   //Spliting the sample for training
   dataloader->PrepareTrainingAndTestTree(mycuts,mycutb,"random"); 

   //define the TMVA method, in this case a BDT
   factory->BookMethod( dataloader, TMVA::Types::kBDT, "BDT","NTrees=400:MaxDepth=2"); 

   //train and test the BDT.

   factory->TrainAllMethods();
   factory->TestAllMethods(); 
   factory->EvaluateAllMethods();

   // Launch the GUI for the root macros
   if (!gROOT->IsBatch()) TMVA::TMVAGui( outfileName );

   return 0;
}

int main( int argc, char** argv )
{
   // Select methods (don't look at this code - not of interest)
   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 TMVAClassification(methodList);
}

But when i run this script i got the following Error

Please help me how to fix this.

It appears that in the macro you perhaps forgot to replace the ROOT files “/path/to/file/signal.root” and “/path/to/file/background.root” by their real path names.

thanks for your response… the paths are corrected but still same issue

Hello,

From the error message and the log you can see that there are no events for training, Can you check that the selection cuts are correct and you are left with some events ?

Lorenzo