Logo ROOT  
Reference Guide
DataInputHandler.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : DataInputHandler *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Contains all the data information *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18  * *
19  * Copyright (c) 2006: *
20  * CERN, Switzerland *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #ifndef ROOT_TMVA_DataInputHandler
29 #define ROOT_TMVA_DataInputHandler
30 
31 //////////////////////////////////////////////////////////////////////////
32 // //
33 // DataInputHandler //
34 // //
35 // Class that contains all the data information //
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #include <vector>
40 #include <map>
41 #include <string>
42 
43 #include "TTree.h"
44 #include "TCut.h"
45 
46 #include "TMVA/Types.h"
47 
48 namespace TMVA {
49 
50  class MsgLogger;
51 
52  class TreeInfo:public TObject {
53 
54  public:
55 
56  TreeInfo( TTree* tr, const TString& className, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType, Bool_t own=kFALSE )
57  : fTree(tr), fClassName(className), fWeight(weight), fTreeType(tt), fOwner(own) {}
58  TreeInfo():fTree(0),fClassName(""),fWeight(1.0), fTreeType(Types::kMaxTreeType), fOwner(kFALSE) {}
59  ~TreeInfo() { if (fOwner) delete fTree; }
60 
61  TTree* GetTree() const { return fTree; }
62  Double_t GetWeight() const { return fWeight; }
63  UInt_t GetEntries() const { if( !fTree ) return 0; else return fTree->GetEntries(); }
64  Types::ETreeType GetTreeType() const { return fTreeType; }
65  const TString& GetClassName() const { return fClassName; }
66 
67  private:
68 
69  TTree* fTree; // pointer to the tree
70  TString fClassName;// name of the class the tree belongs to
71  Double_t fWeight; // weight for the tree
72  Types::ETreeType fTreeType; // tree is for training/testing/both
73  Bool_t fOwner; // true if created from file
74  protected:
75  ClassDef(TreeInfo,1);
76  };
77 
78  class DataInputHandler :public TObject {
79 
80  public:
81 
84 
85  // setters
88  void AddSignalTree ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
90  void AddInputTrees ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
91 
92  void AddTree ( TTree* tree, const TString& className, Double_t weight=1.0,
94  void AddTree ( const TString& tr, const TString& className, Double_t weight=1.0,
96 
97  // accessors
98  std::vector< TString >* GetClassList() const;
99 
100  UInt_t GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
101  UInt_t GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
102 
103  UInt_t GetNSignalTrees() const { return fInputTrees["Signal"].size(); }
104  UInt_t GetNBackgroundTrees() const { return fInputTrees["Background"].size(); }
105  UInt_t GetSignalEntries() const { return GetEntries(fInputTrees["Signal"]); }
106  UInt_t GetBackgroundEntries() const { return GetEntries(fInputTrees["Background"]); }
107  UInt_t GetEntries() const;
108  const TreeInfo& SignalTreeInfo(Int_t i) const { return fInputTrees["Signal"][i]; }
109  const TreeInfo& BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
110 
111  std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
112  std::vector<TreeInfo>::const_iterator end( const TString& className ) const { return fInputTrees[className].end(); }
113  std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
114  std::vector<TreeInfo>::const_iterator Send() const { return end ("Signal"); }
115  std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
116  std::vector<TreeInfo>::const_iterator Bend() const { return end ("Background"); }
117 
118  // reset the list of trees
119  void ClearSignalTreeList() { ClearTreeList("Signal"); }
120  void ClearBackgroundTreeList() { ClearTreeList("Background"); }
121  void ClearTreeList( const TString& className );
122 
123  private:
124 
125  UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
126 
127  TTree * ReadInputTree( const TString& dataFile );
128 
129  mutable std::map< TString, std::vector<TreeInfo> > fInputTrees; // list of input trees per class (classname is given as first parameter in the map)
130  std::map< std::string, Bool_t > fExplicitTrainTest; // if set to true the user has specified training and testing data explicitly
131  mutable MsgLogger* fLogger; //! message logger
132  MsgLogger& Log() const { return *fLogger; }
133  protected:
135  };
136 }
137 
138 #endif
TCut
Definition: TCut.h:25
TMVA::DataInputHandler::Log
MsgLogger & Log() const
message logger
Definition: DataInputHandler.h:154
tt
auto * tt
Definition: textangle.C:16
TMVA::DataInputHandler::Sbegin
std::vector< TreeInfo >::const_iterator Sbegin() const
Definition: DataInputHandler.h:135
TMVA::DataInputHandler::AddSignalTree
void AddSignalTree(TTree *tr, Double_t weight=1.0, Types::ETreeType tt=Types::kMaxTreeType)
add a signal tree to the dataset to be used as input
Definition: DataInputHandler.cxx:116
TMVA::TreeInfo::fWeight
Double_t fWeight
Definition: DataInputHandler.h:93
TMVA::DataInputHandler::begin
std::vector< TreeInfo >::const_iterator begin(const TString &className) const
Definition: DataInputHandler.h:133
TMVA::DataInputHandler
Definition: DataInputHandler.h:100
tree
Definition: tree.py:1
TMVA::DataInputHandler::DataInputHandler
DataInputHandler()
constructor
Definition: DataInputHandler.cxx:51
TMVA::TreeInfo::TreeInfo
TreeInfo()
Definition: DataInputHandler.h:80
TMVA::DataInputHandler::BackgroundTreeInfo
const TreeInfo & BackgroundTreeInfo(Int_t i) const
Definition: DataInputHandler.h:131
TTree
Definition: TTree.h:79
Int_t
int Int_t
Definition: RtypesCore.h:45
TMVA::TreeInfo::fTree
TTree * fTree
Definition: DataInputHandler.h:91
TMVA::DataInputHandler::ClearBackgroundTreeList
void ClearBackgroundTreeList()
Definition: DataInputHandler.h:142
TMVA::DataInputHandler::Bend
std::vector< TreeInfo >::const_iterator Bend() const
Definition: DataInputHandler.h:138
TMVA::TreeInfo::~TreeInfo
~TreeInfo()
Definition: DataInputHandler.h:81
TMVA::DataInputHandler::GetClassList
std::vector< TString > * GetClassList() const
Definition: DataInputHandler.cxx:193
TMVA::DataInputHandler::GetNTrees
UInt_t GetNTrees(const TString &name) const
Definition: DataInputHandler.h:123
TTree.h
TString
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMVA::DataInputHandler::SignalTreeInfo
const TreeInfo & SignalTreeInfo(Int_t i) const
Definition: DataInputHandler.h:130
TMVA::TreeInfo::fTreeType
Types::ETreeType fTreeType
Definition: DataInputHandler.h:94
TMVA::DataInputHandler::~DataInputHandler
~DataInputHandler()
destructor
Definition: DataInputHandler.cxx:60
TMVA::TreeInfo::GetEntries
UInt_t GetEntries() const
Definition: DataInputHandler.h:85
TMVA::TreeInfo::fClassName
TString fClassName
Definition: DataInputHandler.h:92
TMVA::DataInputHandler::GetSignalEntries
UInt_t GetSignalEntries() const
Definition: DataInputHandler.h:127
TMVA::DataInputHandler::AddTree
void AddTree(TTree *tree, const TString &className, Double_t weight=1.0, const TCut &cut="", Types::ETreeType tt=Types::kMaxTreeType)
add tree of className events for tt (Training;Testing..) type as input ..
Definition: DataInputHandler.cxx:82
TMVA::TreeInfo::GetWeight
Double_t GetWeight() const
Definition: DataInputHandler.h:84
TMVA::TreeInfo
Definition: DataInputHandler.h:74
TMVA::DataInputHandler::GetNBackgroundTrees
UInt_t GetNBackgroundTrees() const
Definition: DataInputHandler.h:126
TMVA::DataInputHandler::ClearTreeList
void ClearTreeList(const TString &className)
Definition: DataInputHandler.cxx:181
TMVA::DataInputHandler::AddInputTrees
void AddInputTrees(TTree *inputTree, const TCut &SigCut, const TCut &BgCut)
define the input trees for signal and background from single input tree, containing both signal and b...
Definition: DataInputHandler.cxx:170
TMVA::Types::ETreeType
ETreeType
Definition: Types.h:166
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMVA::DataInputHandler::GetBackgroundEntries
UInt_t GetBackgroundEntries() const
Definition: DataInputHandler.h:128
TMVA::DataInputHandler::fExplicitTrainTest
std::map< std::string, Bool_t > fExplicitTrainTest
Definition: DataInputHandler.h:152
TCut.h
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
Types.h
TMVA::DataInputHandler::ReadInputTree
TTree * ReadInputTree(const TString &dataFile)
create trees from these ascii files
Definition: DataInputHandler.cxx:152
TMVA::TreeInfo::GetTreeType
Types::ETreeType GetTreeType() const
Definition: DataInputHandler.h:86
TMVA::Types::kMaxTreeType
@ kMaxTreeType
Definition: Types.h:169
unsigned int
TMVA::DataInputHandler::AddBackgroundTree
void AddBackgroundTree(TTree *tr, Double_t weight=1.0, Types::ETreeType tt=Types::kMaxTreeType)
add a background tree to the dataset to be used as input
Definition: DataInputHandler.cxx:124
TMVA::DataInputHandler::ClearSignalTreeList
void ClearSignalTreeList()
Definition: DataInputHandler.h:141
TMVA::TreeInfo::fOwner
Bool_t fOwner
Definition: DataInputHandler.h:95
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MsgLogger
Definition: MsgLogger.h:83
TMVA::TreeInfo::GetClassName
const TString & GetClassName() const
Definition: DataInputHandler.h:87
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
TMVA::TreeInfo::GetTree
TTree * GetTree() const
Definition: DataInputHandler.h:83
TMVA::DataInputHandler::GetEntries
UInt_t GetEntries() const
return number of entries in tree
Definition: DataInputHandler.cxx:216
TMVA::DataInputHandler::Send
std::vector< TreeInfo >::const_iterator Send() const
Definition: DataInputHandler.h:136
TMVA::DataInputHandler::Bbegin
std::vector< TreeInfo >::const_iterator Bbegin() const
Definition: DataInputHandler.h:137
TMVA::DataInputHandler::fLogger
MsgLogger * fLogger
Definition: DataInputHandler.h:153
TTree::GetEntries
virtual Long64_t GetEntries() const
Definition: TTree.h:458
TMVA::DataInputHandler::end
std::vector< TreeInfo >::const_iterator end(const TString &className) const
Definition: DataInputHandler.h:134
TMVA::DataInputHandler::fInputTrees
std::map< TString, std::vector< TreeInfo > > fInputTrees
Definition: DataInputHandler.h:151
TMVA::DataInputHandler::GetNSignalTrees
UInt_t GetNSignalTrees() const
Definition: DataInputHandler.h:125
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22