File indexing completed on 2025-01-30 10:22:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef ROOT_TMVA_DataInputHandler
0029 #define ROOT_TMVA_DataInputHandler
0030
0031
0032
0033
0034
0035
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;
0070 TString fClassName;
0071 Double_t fWeight;
0072 Types::ETreeType fTreeType;
0073 Bool_t fOwner;
0074 protected:
0075 ClassDef(TreeInfo,1);
0076 };
0077
0078 class DataInputHandler :public TObject {
0079
0080 public:
0081
0082 DataInputHandler();
0083 ~DataInputHandler();
0084
0085
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
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
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;
0130 std::map< std::string, Bool_t > fExplicitTrainTest;
0131 mutable MsgLogger* fLogger;
0132 MsgLogger& Log() const { return *fLogger; }
0133 protected:
0134 ClassDef(DataInputHandler,1);
0135 };
0136 }
0137
0138 #endif