Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:50

0001 // @(#)root/tmva $Id$
0002 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Class  : DataInputHandler                                                      *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Contains all the data information                                         *
0012  *                                                                                *
0013  * Authors (alphabetical):                                                        *
0014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
0015  *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
0016  *      Peter Speckmayer <Peter.Speckmayer@cern.ch>  - CERN, Switzerland          *
0017  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
0018  *                                                                                *
0019  * Copyright (c) 2006:                                                            *
0020  *      CERN, Switzerland                                                         *
0021  *      MPI-K Heidelberg, Germany                                                 *
0022  *                                                                                *
0023  * Redistribution and use in source and binary forms, with or without             *
0024  * modification, are permitted according to the terms listed in LICENSE           *
0025  * (see tmva/doc/LICENSE)                                          *
0026  **********************************************************************************/
0027 
0028 #ifndef ROOT_TMVA_DataInputHandler
0029 #define ROOT_TMVA_DataInputHandler
0030 
0031 //////////////////////////////////////////////////////////////////////////
0032 //                                                                      //
0033 // DataInputHandler                                                     //
0034 //                                                                      //
0035 // Class that contains all the data information                         //
0036 //                                                                      //
0037 //////////////////////////////////////////////////////////////////////////
0038 
0039 #include <vector>
0040 #include <map>
0041 #include <string>
0042 
0043 #include "TTree.h"
0044 #include "TCut.h"
0045 
0046 #include "TMVA/Types.h"
0047 
0048 namespace TMVA {
0049 
0050    class MsgLogger;
0051 
0052    class TreeInfo:public TObject {
0053 
0054    public:
0055 
0056       TreeInfo( TTree* tr, const TString& className, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType, Bool_t own=kFALSE )
0057       : fTree(tr), fClassName(className), fWeight(weight), fTreeType(tt), fOwner(own) {}
0058       TreeInfo():fTree(nullptr),fClassName(""),fWeight(1.0), fTreeType(Types::kMaxTreeType), fOwner(kFALSE) {}
0059       ~TreeInfo() { if (fOwner) delete fTree; }
0060 
0061       TTree*           GetTree()      const { return fTree; }
0062       Double_t         GetWeight()    const { return fWeight; }
0063       UInt_t           GetEntries()   const { if( !fTree ) return 0; else return fTree->GetEntries(); }
0064       Types::ETreeType GetTreeType()  const { return fTreeType; }
0065       const TString&   GetClassName() const { return fClassName; }
0066 
0067    private:
0068 
0069       TTree*           fTree;      ///< pointer to the tree
0070       TString          fClassName; ///< name of the class the tree belongs to
0071       Double_t         fWeight;    ///< weight for the tree
0072       Types::ETreeType fTreeType;  ///< tree is for training/testing/both
0073       Bool_t           fOwner;     ///< true if created from file
0074    protected:
0075        ClassDef(TreeInfo,1);
0076    };
0077 
0078    class DataInputHandler :public TObject {
0079 
0080    public:
0081 
0082       DataInputHandler();
0083       ~DataInputHandler();
0084 
0085       // setters
0086       void     AddSignalTree    ( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
0087       void     AddBackgroundTree( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
0088       void     AddSignalTree    ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
0089       void     AddBackgroundTree( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
0090       void     AddInputTrees    ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
0091 
0092       void     AddTree          ( TTree* tree, const TString& className, Double_t weight=1.0,
0093                                   const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
0094       void     AddTree          ( const TString& tr, const TString& className, Double_t weight=1.0,
0095                                   const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
0096 
0097       // accessors
0098       std::vector< TString >* GetClassList() const;
0099 
0100       UInt_t           GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
0101       UInt_t           GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
0102 
0103       UInt_t           GetNSignalTrees()           const { return fInputTrees["Signal"].size(); }
0104       UInt_t           GetNBackgroundTrees()       const { return fInputTrees["Background"].size(); }
0105       UInt_t           GetSignalEntries()          const { return GetEntries(fInputTrees["Signal"]); }
0106       UInt_t           GetBackgroundEntries()      const { return GetEntries(fInputTrees["Background"]); }
0107       UInt_t           GetEntries()                const;
0108       const TreeInfo&  SignalTreeInfo(Int_t i)     const { return fInputTrees["Signal"][i]; }
0109       const TreeInfo&  BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
0110 
0111       std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
0112       std::vector<TreeInfo>::const_iterator end( const TString& className )   const { return fInputTrees[className].end(); }
0113       std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
0114       std::vector<TreeInfo>::const_iterator Send()   const { return end  ("Signal"); }
0115       std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
0116       std::vector<TreeInfo>::const_iterator Bend()   const { return end  ("Background"); }
0117 
0118       // reset the list of trees
0119       void     ClearSignalTreeList()     { ClearTreeList("Signal"); }
0120       void     ClearBackgroundTreeList() { ClearTreeList("Background"); }
0121       void     ClearTreeList( const TString& className );
0122 
0123    private:
0124 
0125       UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
0126 
0127       TTree * ReadInputTree( const TString& dataFile );
0128 
0129       mutable std::map< TString, std::vector<TreeInfo> > fInputTrees;        ///< list of input trees per class (classname is given as first parameter in the map)
0130       std::map< std::string, Bool_t   >                  fExplicitTrainTest; ///< if set to true the user has specified training and testing data explicitly
0131       mutable MsgLogger*                                 fLogger;            ///<! message logger
0132       MsgLogger& Log() const { return *fLogger; }
0133    protected:
0134        ClassDef(DataInputHandler,1);
0135    };
0136 }
0137 
0138 #endif