DataInputHandler.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: DataInputHandler.h 33928 2010-06-15 16:19:31Z stelzer $
00002 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : DataInputHandler                                                      *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Contains all the data information                                         *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00015  *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
00016  *      Peter Speckmayer <Peter.Speckmayer@cern.ch>  - CERN, Switzerland          *
00017  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00018  *                                                                                *
00019  * Copyright (c) 2006:                                                            *
00020  *      CERN, Switzerland                                                         *
00021  *      MPI-K Heidelberg, Germany                                                 *
00022  *                                                                                *
00023  * Redistribution and use in source and binary forms, with or without             *
00024  * modification, are permitted according to the terms listed in LICENSE           *
00025  * (http://tmva.sourceforge.net/LICENSE)                                          *
00026  **********************************************************************************/
00027 
00028 #ifndef ROOT_TMVA_DataInputHandler
00029 #define ROOT_TMVA_DataInputHandler
00030 
00031 //////////////////////////////////////////////////////////////////////////
00032 //                                                                      //
00033 // DataInputHandler                                                     //
00034 //                                                                      //
00035 // Class that contains all the data information                         //
00036 //                                                                      //
00037 //////////////////////////////////////////////////////////////////////////
00038 
00039 #include <vector>
00040 #include <map>
00041 #include <string>
00042 #include <fstream>
00043 
00044 #ifndef ROOT_TTree
00045 #include "TTree.h"
00046 #endif
00047 #ifndef ROOT_TCut
00048 #include "TCut.h"
00049 #endif
00050 
00051 #ifndef ROOT_TMVA_Types
00052 #include "TMVA/Types.h"
00053 #endif
00054 
00055 namespace TMVA {
00056 
00057    class MsgLogger;
00058    
00059    class TreeInfo {
00060 
00061    public:
00062 
00063       TreeInfo( TTree* tr, const TString& className, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType, Bool_t own=kFALSE ) 
00064          : fTree(tr), fClassName(className), fWeight(weight), fTreeType(tt), fOwner(own) {}
00065       ~TreeInfo() { if (fOwner) delete fTree; }
00066 
00067       TTree*           GetTree()      const { return fTree; }
00068       Double_t         GetWeight()    const { return fWeight; }
00069       UInt_t           GetEntries()   const { return fTree->GetEntries(); }
00070       Types::ETreeType GetTreeType()  const { return fTreeType; }
00071       const TString&   GetClassName() const { return fClassName; }
00072 
00073    private:
00074 
00075       TTree*           fTree;     //! pointer to the tree
00076       TString          fClassName;//! name of the class the tree belongs to
00077       Double_t         fWeight;   //! weight for the tree
00078       Types::ETreeType fTreeType; //! tree is for training/testing/both
00079       Bool_t           fOwner;    //! true if created from file
00080    };
00081 
00082    class DataInputHandler {
00083 
00084    public:
00085 
00086       DataInputHandler();
00087       ~DataInputHandler();
00088 
00089       // setters
00090       void     AddSignalTree    ( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00091       void     AddBackgroundTree( TTree* tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00092       void     AddSignalTree    ( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00093       void     AddBackgroundTree( const TString& tr, Double_t weight=1.0, Types::ETreeType tt = Types::kMaxTreeType );
00094       void     AddInputTrees    ( TTree* inputTree, const TCut& SigCut, const TCut& BgCut);
00095 
00096       void     AddTree          ( TTree* tree, const TString& className, Double_t weight=1.0, 
00097                                   const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
00098       void     AddTree          ( const TString& tr, const TString& className, Double_t weight=1.0, 
00099                                   const TCut& cut = "", Types::ETreeType tt = Types::kMaxTreeType );
00100 
00101       // accessors
00102       std::vector< TString >* GetClassList() const;
00103 
00104       UInt_t           GetEntries( const TString& name ) const { return GetEntries( fInputTrees[name] ); }
00105       UInt_t           GetNTrees ( const TString& name ) const { return fInputTrees[name].size(); }
00106 
00107       UInt_t           GetNSignalTrees()           const { return fInputTrees["Signal"].size(); }
00108       UInt_t           GetNBackgroundTrees()       const { return fInputTrees["Background"].size(); }
00109       UInt_t           GetSignalEntries()          const { return GetEntries(fInputTrees["Signal"]); }
00110       UInt_t           GetBackgroundEntries()      const { return GetEntries(fInputTrees["Background"]); }
00111       UInt_t           GetEntries()                const;
00112       const TreeInfo&  SignalTreeInfo(Int_t i)     const { return fInputTrees["Signal"][i]; }
00113       const TreeInfo&  BackgroundTreeInfo(Int_t i) const { return fInputTrees["Background"][i]; }
00114 
00115       std::vector<TreeInfo>::const_iterator begin( const TString& className ) const { return fInputTrees[className].begin(); }
00116       std::vector<TreeInfo>::const_iterator end( const TString& className )   const { return fInputTrees[className].end(); }
00117       std::vector<TreeInfo>::const_iterator Sbegin() const { return begin("Signal"); }
00118       std::vector<TreeInfo>::const_iterator Send()   const { return end  ("Signal"); }
00119       std::vector<TreeInfo>::const_iterator Bbegin() const { return begin("Background"); }
00120       std::vector<TreeInfo>::const_iterator Bend()   const { return end  ("Background"); }
00121 
00122       // reset the list of trees
00123       void     ClearSignalTreeList()     { ClearTreeList("Signal"); }
00124       void     ClearBackgroundTreeList() { ClearTreeList("Background"); }
00125       void     ClearTreeList( const TString& className );
00126 
00127    private:
00128 
00129       UInt_t GetEntries(const std::vector<TreeInfo>& tiV) const;
00130 
00131       TTree * ReadInputTree( const TString& dataFile );
00132       
00133       mutable std::map< TString, std::vector<TreeInfo> > fInputTrees;        //! list of input trees per class (classname is given as first parameter in the map)
00134       std::map< std::string, Bool_t   >                  fExplicitTrainTest; //! if set to true the user has specified training and testing data explicitly
00135       mutable MsgLogger*                                 fLogger;   // message logger
00136       MsgLogger& Log() const { return *fLogger; }
00137    };
00138 }
00139 
00140 #endif

Generated on Tue Jul 5 14:27:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1