00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROOT_TMVA_DataInputHandler
00029 #define ROOT_TMVA_DataInputHandler
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <vector>
00040 #include <map>
00041 #include <string>
00042 #include <fstream>
00043
00044 #ifndef ROOT_TTree
00045 #include "TTree.h"
00046 #endif
00047 #ifndef ROOT_TCut
00048 #include "TCut.h"
00049 #endif
00050
00051 #ifndef ROOT_TMVA_Types
00052 #include "TMVA/Types.h"
00053 #endif
00054
00055 namespace TMVA {
00056
00057 class MsgLogger;
00058
00059 class TreeInfo {
00060
00061 public:
00062
00063 TreeInfo( TTree* tr, const TString& className, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType, Bool_t own=kFALSE )
00064 : fTree(tr), fClassName(className), fWeight(weight), fTreeType(tt), fOwner(own) {}
00065 ~TreeInfo() { if (fOwner) delete fTree; }
00066
00067 TTree* GetTree() const { return fTree; }
00068 Double_t GetWeight() const { return fWeight; }
00069 UInt_t GetEntries() const { return fTree->GetEntries(); }
00070 Types::ETreeType GetTreeType() const { return fTreeType; }
00071 const TString& GetClassName() const { return fClassName; }
00072
00073 private:
00074
00075 TTree* fTree;
00076 TString fClassName;
00077 Double_t fWeight;
00078 Types::ETreeType fTreeType;
00079 Bool_t fOwner;
00080 };
00081
00082 class DataInputHandler {
00083
00084 public:
00085
00086 DataInputHandler();
00087 ~DataInputHandler();
00088
00089
00090 void AddSignalTree ( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00091 void AddBackgroundTree( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00092 void AddSignalTree ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00093 void AddBackgroundTree( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00094 void AddInputTrees ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
00095
00096 void AddTree ( TTree* tree, const TString& className, Double_t weight=1.0,
00097 const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
00098 void AddTree ( const TString& tr, const TString& className, Double_t weight=1.0,
00099 const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
00100
00101
00102 std::vector< TString >* GetClassList() const;
00103
00104 UInt_t GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
00105 UInt_t GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
00106
00107 UInt_t GetNSignalTrees() const { return fInputTrees["Signal"].size(); }
00108 UInt_t GetNBackgroundTrees() const { return fInputTrees["Background"].size(); }
00109 UInt_t GetSignalEntries() const { return GetEntries(fInputTrees["Signal"]); }
00110 UInt_t GetBackgroundEntries() const { return GetEntries(fInputTrees["Background"]); }
00111 UInt_t GetEntries() const;
00112 const TreeInfo& SignalTreeInfo(Int_t i) const { return fInputTrees["Signal"][i]; }
00113 const TreeInfo& BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
00114
00115 std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
00116 std::vector<TreeInfo>::const_iterator end( const TString& className ) const { return fInputTrees[className].end(); }
00117 std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
00118 std::vector<TreeInfo>::const_iterator Send() const { return end ("Signal"); }
00119 std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
00120 std::vector<TreeInfo>::const_iterator Bend() const { return end ("Background"); }
00121
00122
00123 void ClearSignalTreeList() { ClearTreeList("Signal"); }
00124 void ClearBackgroundTreeList() { ClearTreeList("Background"); }
00125 void ClearTreeList( const TString& className );
00126
00127 private:
00128
00129 UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
00130
00131 TTree * ReadInputTree( const TString& dataFile );
00132
00133 mutable std::map< TString, std::vector<TreeInfo> > fInputTrees;
00134 std::map< std::string, Bool_t > fExplicitTrainTest;
00135 mutable MsgLogger* fLogger;
00136 MsgLogger& Log() const { return *fLogger; }
00137 };
00138 }
00139
00140 #endif