ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include <fstream>
43 
44 #ifndef ROOT_TTree
45 #include "TTree.h"
46 #endif
47 #ifndef ROOT_TCut
48 #include "TCut.h"
49 #endif
50 
51 #ifndef ROOT_TMVA_Types
52 #include "TMVA/Types.h"
53 #endif
54 
55 namespace TMVA {
56 
57  class MsgLogger;
58 
59  class TreeInfo {
60 
61  public:
62 
63  TreeInfo( TTree* tr, const TString& className, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType, Bool_t own=kFALSE )
64  : fTree(tr), fClassName(className), fWeight(weight), fTreeType(tt), fOwner(own) {}
65  ~TreeInfo() { if (fOwner) delete fTree; }
66 
67  TTree* GetTree() const { return fTree; }
68  Double_t GetWeight() const { return fWeight; }
69  UInt_t GetEntries() const { if( !fTree ) return 0; else return fTree->GetEntries(); }
71  const TString& GetClassName() const { return fClassName; }
72 
73  private:
74 
75  TTree* fTree; //! pointer to the tree
76  TString fClassName;//! name of the class the tree belongs to
77  Double_t fWeight; //! weight for the tree
78  Types::ETreeType fTreeType; //! tree is for training/testing/both
79  Bool_t fOwner; //! true if created from file
80  };
81 
83 
84  public:
85 
88 
89  // setters
92  void AddSignalTree ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
94  void AddInputTrees ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
95 
96  void AddTree ( TTree* tree, const TString& className, Double_t weight=1.0,
97  const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
98  void AddTree ( const TString& tr, const TString& className, Double_t weight=1.0,
99  const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
100 
101  // accessors
102  std::vector< TString >* GetClassList() const;
103 
104  UInt_t GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
105  UInt_t GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
106 
107  UInt_t GetNSignalTrees() const { return fInputTrees["Signal"].size(); }
108  UInt_t GetNBackgroundTrees() const { return fInputTrees["Background"].size(); }
109  UInt_t GetSignalEntries() const { return GetEntries(fInputTrees["Signal"]); }
110  UInt_t GetBackgroundEntries() const { return GetEntries(fInputTrees["Background"]); }
111  UInt_t GetEntries() const;
112  const TreeInfo& SignalTreeInfo(Int_t i) const { return fInputTrees["Signal"][i]; }
113  const TreeInfo& BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
114 
115  std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
116  std::vector<TreeInfo>::const_iterator end( const TString& className ) const { return fInputTrees[className].end(); }
117  std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
118  std::vector<TreeInfo>::const_iterator Send() const { return end ("Signal"); }
119  std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
120  std::vector<TreeInfo>::const_iterator Bend() const { return end ("Background"); }
121 
122  // reset the list of trees
123  void ClearSignalTreeList() { ClearTreeList("Signal"); }
124  void ClearBackgroundTreeList() { ClearTreeList("Background"); }
125  void ClearTreeList( const TString& className );
126 
127  private:
128 
129  UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
130 
131  TTree * ReadInputTree( const TString& dataFile );
132 
133  mutable std::map< TString, std::vector<TreeInfo> > fInputTrees; //! list of input trees per class (classname is given as first parameter in the map)
134  std::map< std::string, Bool_t > fExplicitTrainTest; //! if set to true the user has specified training and testing data explicitly
135  mutable MsgLogger* fLogger; // message logger
136  MsgLogger& Log() const { return *fLogger; }
137  };
138 }
139 
140 #endif
std::vector< TString > * GetClassList() const
Types::ETreeType GetTreeType() const
UInt_t GetSignalEntries() const
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TTree * GetTree() const
Types::ETreeType fTreeType
weight for the tree
UInt_t GetNTrees(const TString &name) const
UInt_t GetEntries(const TString &name) const
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
const TString & GetClassName() const
DataInputHandler()
constructor
std::vector< TreeInfo >::const_iterator Bbegin() const
TText * tt
Definition: textangle.C:16
std::map< TString, std::vector< TreeInfo > > fInputTrees
TTree * ReadInputTree(const TString &dataFile)
create trees from these ascii files
UInt_t GetNSignalTrees() const
Double_t GetWeight() const
A specialized string object used for TTree selections.
Definition: TCut.h:27
MsgLogger & Log() const
const TreeInfo & BackgroundTreeInfo(Int_t i) const
std::map< std::string, Bool_t > fExplicitTrainTest
list of input trees per class (classname is given as first parameter in the map)
void ClearTreeList(const TString &className)
std::vector< TreeInfo >::const_iterator Send() const
MsgLogger * fLogger
if set to true the user has specified training and testing data explicitly
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 ..
unsigned int UInt_t
Definition: RtypesCore.h:42
TString fClassName
pointer to the tree
Bool_t fOwner
tree is for training/testing/both
tuple tree
Definition: tree.py:24
TreeInfo(TTree *tr, const TString &className, Double_t weight=1.0, Types::ETreeType tt=Types::kMaxTreeType, Bool_t own=kFALSE)
double Double_t
Definition: RtypesCore.h:55
std::vector< TreeInfo >::const_iterator end(const TString &className) const
std::vector< TreeInfo >::const_iterator Bend() const
UInt_t GetEntries() const
#define name(a, b)
Definition: linkTestLib0.cpp:5
UInt_t GetNBackgroundTrees() const
UInt_t GetBackgroundEntries() const
std::vector< TreeInfo >::const_iterator Sbegin() const
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...
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
virtual Long64_t GetEntries() const
Definition: TTree.h:386
A TTree object has a header with a name and a title.
Definition: TTree.h:98
Double_t fWeight
name of the class the tree belongs to
std::vector< TreeInfo >::const_iterator begin(const TString &className) const
UInt_t GetEntries() const
return number of entries in tree
const TreeInfo & SignalTreeInfo(Int_t i) const