Logo ROOT   6.07/09
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 #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:public TObject {
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():fTree(0),fClassName(""),fWeight(1.0), fTreeType(Types::kMaxTreeType), fOwner(kFALSE) {}
66  ~TreeInfo() { if (fOwner) delete fTree; }
67 
68  TTree* GetTree() const { return fTree; }
69  Double_t GetWeight() const { return fWeight; }
70  UInt_t GetEntries() const { if( !fTree ) return 0; else return fTree->GetEntries(); }
72  const TString& GetClassName() const { return fClassName; }
73 
74  private:
75 
76  TTree* fTree; // pointer to the tree
77  TString fClassName;// name of the class the tree belongs to
78  Double_t fWeight; // weight for the tree
79  Types::ETreeType fTreeType; // tree is for training/testing/both
80  Bool_t fOwner; // true if created from file
81  protected:
82  ClassDef(TreeInfo,1);
83  };
84 
85  class DataInputHandler :public TObject {
86 
87  public:
88 
91 
92  // setters
93  void AddSignalTree ( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
94  void AddBackgroundTree( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
95  void AddSignalTree ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
96  void AddBackgroundTree( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
97  void AddInputTrees ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
98 
99  void AddTree ( TTree* tree, const TString& className, Double_t weight=1.0,
100  const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
101  void AddTree ( const TString& tr, const TString& className, Double_t weight=1.0,
102  const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
103 
104  // accessors
105  std::vector< TString >* GetClassList() const;
106 
107  UInt_t GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
108  UInt_t GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
109 
110  UInt_t GetNSignalTrees() const { return fInputTrees["Signal"].size(); }
111  UInt_t GetNBackgroundTrees() const { return fInputTrees["Background"].size(); }
112  UInt_t GetSignalEntries() const { return GetEntries(fInputTrees["Signal"]); }
113  UInt_t GetBackgroundEntries() const { return GetEntries(fInputTrees["Background"]); }
114  UInt_t GetEntries() const;
115  const TreeInfo& SignalTreeInfo(Int_t i) const { return fInputTrees["Signal"][i]; }
116  const TreeInfo& BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
117 
118  std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
119  std::vector<TreeInfo>::const_iterator end( const TString& className ) const { return fInputTrees[className].end(); }
120  std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
121  std::vector<TreeInfo>::const_iterator Send() const { return end ("Signal"); }
122  std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
123  std::vector<TreeInfo>::const_iterator Bend() const { return end ("Background"); }
124 
125  // reset the list of trees
126  void ClearSignalTreeList() { ClearTreeList("Signal"); }
127  void ClearBackgroundTreeList() { ClearTreeList("Background"); }
128  void ClearTreeList( const TString& className );
129 
130  private:
131 
132  UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
133 
134  TTree * ReadInputTree( const TString& dataFile );
135 
136  mutable std::map< TString, std::vector<TreeInfo> > fInputTrees; // list of input trees per class (classname is given as first parameter in the map)
137  std::map< std::string, Bool_t > fExplicitTrainTest; // if set to true the user has specified training and testing data explicitly
138  mutable MsgLogger* fLogger; // message logger
139  MsgLogger& Log() const { return *fLogger; }
140  protected:
142  };
143 }
144 
145 #endif
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
UInt_t GetNTrees(const TString &name) const
UInt_t GetEntries(const TString &name) const
const TString & GetClassName() const
#define ClassDef(name, id)
Definition: Rtypes.h:254
std::vector< TreeInfo >::const_iterator Bbegin() const
TText * tt
Definition: textangle.C:16
std::map< TString, std::vector< TreeInfo > > fInputTrees
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
std::vector< TreeInfo >::const_iterator Send() const
unsigned int UInt_t
Definition: RtypesCore.h:42
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
Mother of all ROOT objects.
Definition: TObject.h:44
UInt_t GetNBackgroundTrees() const
UInt_t GetBackgroundEntries() const
Abstract ClassifierFactory template that handles arbitrary types.
std::vector< TreeInfo >::const_iterator Sbegin() const
Definition: tree.py:1
virtual Long64_t GetEntries() const
Definition: TTree.h:392
A TTree object has a header with a name and a title.
Definition: TTree.h:98
std::vector< TreeInfo >::const_iterator begin(const TString &className) const
char name[80]
Definition: TGX11.cxx:109
const TreeInfo & SignalTreeInfo(Int_t i) const