/*! * \file MSimMLManager.h * \brief Machine Learning methods interface * * <+DETAILED+> * * \author Chinmay Borwankar (), * * \internal * Created: 03/31/2017 * Revision: none * Compiler: gcc * Organization: Astrophysical Sciences Division, Bhabha Atomic Research Centre * Copyright: * * This source code is released for free distribution under the terms of the * GNU General Public License as published by the Free Software Foundation. */ #ifndef MSimTMVAInterface_hxx #define MSimTMVAInterface_hxx #include #include #include #include #include "TROOT.h" #include "TSystem.h" #include "TFile.h" #include "TChain.h" #include "TEntryList.h" #include "TList.h" #include "TStopwatch.h" #include "TString.h" #include "TCut.h" #include "TSelector.h" #include "TMVA/Factory.h" #include "TMVA/DataLoader.h" #include "TMVA/Tools.h" #include "TMVA/Reader.h" #include "TMVA/MethodPyRandomForest.h" #include "TMVA/MethodPyGTB.h" #include "TMVA/MethodPyAdaBoost.h" #include "TMVA/MethodCuts.h" #include "TMVA/TMVAGui.h" #include "TMVA/TMVARegGui.h" //#include "MSimIOCorsika.h" //#include "MSimRT.h" //#include "MSimCameraLayout.h" //#include "MSimPatternTrigger.h" //#include "MSimImageAnalyser.h" /* * ===================================================================================== * Class: MMLResponse * Description: class to evaluate ML response * ===================================================================================== */ class MMLResponse : public TNamed { public: /* ==================== LIFECYCLE ======================================= */ MMLResponse (); /* constructor */ ~MMLResponse (); /* destructor */ /* ==================== ACCESSORS ======================================= */ /* ==================== MUTATORS ======================================= */ /* ==================== OPERATORS ======================================= */ /* ==================== METHODS ======================================= */ // common methods to training and prediction void AddCategory(Int_t icat, TString categorycut) ; //methods for prediction phase void InitReader(const TString &theOpt, Int_t ncat = 1, Bool_t verbose = 0) ; Int_t LoadData(const char *pathtodata, const char *treename) ; Int_t LoadFriendData(const char *pathtodata, const char *treename) ; void CategorizeData(const char *precut) ; Long64_t GetEntries() const ; void AddReaderVariable(const TString &expression,const char *leafname) ; void AddReaderSpectator(const TString &expression,const char *leafname) ; void BookMVA(const TString &methodName, const TString &weightfile ) ; Int_t EvaluateMVA(const char *outfile, const char *outtree,const char *precut, Double_t *aux = 0) ; Int_t EvaluateRegression(const char *outfile, const char *outtree, Double_t *aux = 0) ; protected: /* ==================== METHODS ======================================= */ /* ==================== DATA MEMBERS ======================================= */ private: MMLResponse ( const MMLResponse &other ); /* copy constructor */ MMLResponse& operator = ( const MMLResponse &other ); /* assignment operator */ /* ==================== METHODS ======================================= */ /* ==================== DATA MEMBERS ======================================= */ TChain *fChainReader ; ///< Chain on which reader will be operated TList *fCategoryCuts ; ///< Cuts defining categories TList *fEntryLists ; ///< EntryLists corresponding to categories TList *fListReader ; ///< List of TMVA Reader objects to manage Readers predictions on categories vector fReaderVariableLeaves ; //! fReaderVariableExprs ; //! fReaderSpectatorLeaves ; //! fReaderSpectatorExprs ; //! fMethodsBookedReader ; //! /// class MMLTrainer : public TNamed { public: /* ==================== LIFECYCLE ======================================= */ MMLTrainer (); /* constructor */ ~MMLTrainer (); /* destructor */ /* ==================== ACCESSORS ======================================= */ /* ==================== MUTATORS ======================================= */ /* ==================== OPERATORS ======================================= */ /* ==================== METHODS ======================================= */ // common methods to training and prediction void AddCategory(Int_t icat, TString categorycut) ; // Methods for training phase Int_t InitFactory(const char* jobname, const char *outputfilename, const char *options, Int_t ncat = 1) ; void AddTrainingVariable(const TString &expression, const TString &title, const TString &unit, char type='F', Double_t min=0, Double_t max=0) ; void AddTrainingSpectator (const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0) ; void AddTarget (const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0) ; void AddSignalTree(TTree *sigtree, Double_t sigweight) ; void AddBackgroundTree(TTree *bkgtree, Double_t bkgweight) ; void AddRegressionTree(TTree *tree, Double_t weight, TMVA::Types::ETreeType treetype = TMVA::Types::kMaxTreeType) ; void PrepareTrainingAndTestTreeCls(TCut sigcut, TCut bkgcut, const TString &splitopt) ; void PrepareTrainingAndTestTreeReg(TCut sigcut, const TString &splitopt) ; void BookMethod(TMVA::Types::EMVA MLMethod, TString methodTitle, TString trainOptions) ; void TrainAllMethods() ; void TestAllMethods() ; void EvaluateAllMethods() ; protected: /* ==================== METHODS ======================================= */ /* ==================== DATA MEMBERS ======================================= */ private: MMLTrainer& operator = ( const MMLTrainer &other ) ; /* assignment operator */ MMLTrainer ( const MMLTrainer &other ); /* copy constructor */ /* ==================== METHODS ======================================= */ /* ==================== DATA MEMBERS ======================================= */ TMVA::Types::EAnalysisType fAnaType ; ///< Type of analysis (Classification or Regression) UInt_t fNumberOfCategories ; ///< Number of categories of data in training/prediction TFile **fFilesTMVA ; ///< TMVA output root file pointers TList *fCategoryCuts ; ///< Cuts defining categories TList *fListFactory ; ///< List of TMVA Factory objects to handle ML/MVA operations on categories TList *fListDataLoader ; ///< List of DataLoaders corresponding to each category vector fTrainVariables ; //! fSpecVariables ; //!