Logo ROOT   6.10/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 #include "TTree.h"
45 #include "TCut.h"
46 
47 #include "TMVA/Types.h"
48 
49 namespace TMVA {
50 
51  class MsgLogger;
52 
53  class TreeInfo:public TObject {
54 
55  public:
56 
57  TreeInfo( TTree* tr, const TString& className, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType, Bool_t own=kFALSE )
58  : fTree(tr), fClassName(className), fWeight(weight), fTreeType(tt), fOwner(own) {}
59  TreeInfo():fTree(0),fClassName(""),fWeight(1.0), fTreeType(Types::kMaxTreeType), fOwner(kFALSE) {}
60  ~TreeInfo() { if (fOwner) delete fTree; }
61 
62  TTree* GetTree() const { return fTree; }
63  Double_t GetWeight() const { return fWeight; }
64  UInt_t GetEntries() const { if( !fTree ) return 0; else return fTree->GetEntries(); }
66  const TString& GetClassName() const { return fClassName; }
67 
68  private:
69 
70  TTree* fTree; // pointer to the tree
71  TString fClassName;// name of the class the tree belongs to
72  Double_t fWeight; // weight for the tree
73  Types::ETreeType fTreeType; // tree is for training/testing/both
74  Bool_t fOwner; // true if created from file
75  protected:
76  ClassDef(TreeInfo,1);
77  };
78 
79  class DataInputHandler :public TObject {
80 
81  public:
82 
85 
86  // setters
87  void AddSignalTree ( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
88  void AddBackgroundTree( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
89  void AddSignalTree ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
90  void AddBackgroundTree( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
91  void AddInputTrees ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
92 
93  void AddTree ( TTree* tree, const TString& className, Double_t weight=1.0,
94  const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
95  void AddTree ( const TString& tr, const TString& className, Double_t weight=1.0,
96  const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
97 
98  // accessors
99  std::vector< TString >* GetClassList() const;
100 
101  UInt_t GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
102  UInt_t GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
103 
104  UInt_t GetNSignalTrees() const { return fInputTrees["Signal"].size(); }
105  UInt_t GetNBackgroundTrees() const { return fInputTrees["Background"].size(); }
106  UInt_t GetSignalEntries() const { return GetEntries(fInputTrees["Signal"]); }
107  UInt_t GetBackgroundEntries() const { return GetEntries(fInputTrees["Background"]); }
108  UInt_t GetEntries() const;
109  const TreeInfo& SignalTreeInfo(Int_t i) const { return fInputTrees["Signal"][i]; }
110  const TreeInfo& BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
111 
112  std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
113  std::vector<TreeInfo>::const_iterator end( const TString& className ) const { return fInputTrees[className].end(); }
114  std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
115  std::vector<TreeInfo>::const_iterator Send() const { return end ("Signal"); }
116  std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
117  std::vector<TreeInfo>::const_iterator Bend() const { return end ("Background"); }
118 
119  // reset the list of trees
120  void ClearSignalTreeList() { ClearTreeList("Signal"); }
121  void ClearBackgroundTreeList() { ClearTreeList("Background"); }
122  void ClearTreeList( const TString& className );
123 
124  private:
125 
126  UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
127 
128  TTree * ReadInputTree( const TString& dataFile );
129 
130  mutable std::map< TString, std::vector<TreeInfo> > fInputTrees; // list of input trees per class (classname is given as first parameter in the map)
131  std::map< std::string, Bool_t > fExplicitTrainTest; // if set to true the user has specified training and testing data explicitly
132  mutable MsgLogger* fLogger; //! message logger
133  MsgLogger& Log() const { return *fLogger; }
134  protected:
136  };
137 }
138 
139 #endif
TTree * GetTree() const
std::vector< TreeInfo >::const_iterator Bend() const
Singleton class for Global types used by TMVA.
Definition: Types.h:73
const TreeInfo & BackgroundTreeInfo(Int_t i) const
std::vector< TreeInfo >::const_iterator Bbegin() const
UInt_t GetNBackgroundTrees() const
UInt_t GetNSignalTrees() const
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
std::vector< TreeInfo >::const_iterator Send() const
std::vector< TreeInfo >::const_iterator end(const TString &className) const
Types::ETreeType fTreeType
std::vector< TreeInfo >::const_iterator Sbegin() const
#define ClassDef(name, id)
Definition: Rtypes.h:297
TText * tt
Definition: textangle.C:16
std::map< TString, std::vector< TreeInfo > > fInputTrees
UInt_t GetEntries() const
A specialized string object used for TTree selections.
Definition: TCut.h:25
Types::ETreeType GetTreeType() const
std::map< std::string, Bool_t > fExplicitTrainTest
Class that contains all the data information.
MsgLogger & Log() const
message logger
std::vector< TreeInfo >::const_iterator begin(const TString &className) const
unsigned int UInt_t
Definition: RtypesCore.h:42
UInt_t GetBackgroundEntries() const
const Bool_t kFALSE
Definition: RtypesCore.h:92
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
const TString & GetClassName() const
UInt_t GetSignalEntries() const
UInt_t GetEntries(const TString &name) const
virtual Long64_t GetEntries() const
Definition: TTree.h:381
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Mother of all ROOT objects.
Definition: TObject.h:37
Abstract ClassifierFactory template that handles arbitrary types.
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:78
const TreeInfo & SignalTreeInfo(Int_t i) const
Double_t GetWeight() const
UInt_t GetNTrees(const TString &name) const