Logo ROOT   6.16/01
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
49namespace 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:
77 };
78
79 class DataInputHandler :public TObject {
80
81 public:
82
85
86 // setters
89 void AddSignalTree ( 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
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassDef(name, id)
Definition: Rtypes.h:324
A specialized string object used for TTree selections.
Definition: TCut.h:25
Class that contains all the data information.
const TreeInfo & BackgroundTreeInfo(Int_t i) const
UInt_t GetEntries(const TString &name) const
MsgLogger & Log() const
message logger
void ClearTreeList(const TString &className)
std::vector< TreeInfo >::const_iterator Send() const
UInt_t GetNSignalTrees() const
const TreeInfo & SignalTreeInfo(Int_t i) const
std::vector< TreeInfo >::const_iterator end(const TString &className) const
UInt_t GetEntries() const
return number of entries in tree
UInt_t GetBackgroundEntries() const
TTree * ReadInputTree(const TString &dataFile)
create trees from these ascii files
std::vector< TreeInfo >::const_iterator Sbegin() const
std::map< std::string, Bool_t > fExplicitTrainTest
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
std::vector< TreeInfo >::const_iterator Bbegin() const
UInt_t GetNBackgroundTrees() const
std::vector< TString > * GetClassList() const
std::map< TString, std::vector< TreeInfo > > fInputTrees
std::vector< TreeInfo >::const_iterator Bend() 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...
UInt_t GetNTrees(const TString &name) const
UInt_t GetSignalEntries() const
std::vector< TreeInfo >::const_iterator begin(const TString &className) const
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 ..
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
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Types::ETreeType GetTreeType() const
const TString & GetClassName() const
Double_t GetWeight() const
Types::ETreeType fTreeType
TTree * GetTree() const
TreeInfo(TTree *tr, const TString &className, Double_t weight=1.0, Types::ETreeType tt=Types::kMaxTreeType, Bool_t own=kFALSE)
UInt_t GetEntries() const
Singleton class for Global types used by TMVA.
Definition: Types.h:73
@ kMaxTreeType
Definition: Types.h:146
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
A TTree object has a header with a name and a title.
Definition: TTree.h:71
virtual Long64_t GetEntries() const
Definition: TTree.h:402
Abstract ClassifierFactory template that handles arbitrary types.
Definition: tree.py:1
auto * tt
Definition: textangle.C:16