Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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
48namespace 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(nullptr),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(); }
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:
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,
93 const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
94 void AddTree ( const TString& tr, const TString& className, Double_t weight=1.0,
95 const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
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
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
#define ClassDef(name, id)
Definition Rtypes.h:337
char name[80]
Definition TGX11.cxx:110
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
MsgLogger * fLogger
! message logger
UInt_t GetEntries(const TString &name) const
MsgLogger & Log() const
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
if set to true the user has specified training and testing data explicitly
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
list of input trees per class (classname is given as first parameter in the map)
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:57
TString fClassName
name of the class the tree belongs to
Double_t fWeight
weight for the tree
Types::ETreeType GetTreeType() const
const TString & GetClassName() const
Double_t GetWeight() const
Types::ETreeType fTreeType
tree is for training/testing/both
TTree * GetTree() const
Bool_t fOwner
true if created from file
TreeInfo(TTree *tr, const TString &className, Double_t weight=1.0, Types::ETreeType tt=Types::kMaxTreeType, Bool_t own=kFALSE)
TTree * fTree
pointer to the tree
UInt_t GetEntries() const
Singleton class for Global types used by TMVA.
Definition Types.h:71
@ kMaxTreeType
also used as temporary storage for trees not yet assigned for testing;training...
Definition Types.h:145
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual Long64_t GetEntries() const
Definition TTree.h:463
create variable transformations
auto * tt
Definition textangle.C:16