Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TransformationHandler.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Jan Therhaag, Eckhard von Toerne
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TransformationHandler *
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  * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
16  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
18  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
19  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
20  * *
21  * Copyright (c) 2005-2011: *
22  * CERN, Switzerland *
23  * MPI-K Heidelberg, Germany *
24  * U. of Bonn, Germany *
25  * *
26  * Redistribution and use in source and binary forms, with or without *
27  * modification, are permitted according to the terms listed in LICENSE *
28  * (http://tmva.sourceforge.net/LICENSE) *
29  **********************************************************************************/
30 
31 #ifndef ROOT_TMVA_TransformationHandler
32 #define ROOT_TMVA_TransformationHandler
33 
34 //////////////////////////////////////////////////////////////////////////
35 // //
36 // TransformationHandler //
37 // //
38 // Class that contains all the data information //
39 // //
40 //////////////////////////////////////////////////////////////////////////
41 
42 #include "TList.h"
43 #include "TString.h"
44 
45 #include "TMVA/DataSetInfo.h"
46 
47 namespace TMVA {
48 
49  class Event;
50  class DataSet;
51  class Ranking;
52  class VariableTransformBase;
53  class MsgLogger;
54 
55  class TransformationHandler {
56  public:
57 
58  struct VariableStat {
59  Double_t fMean;
60  Double_t fRMS;
61  Double_t fMin;
62  Double_t fMax;
63  };
64 
65  TransformationHandler( DataSetInfo&, const TString& callerName );
66  ~TransformationHandler();
67 
68  TString GetName() const;
69  TString GetVariableAxisTitle( const VariableInfo& info ) const;
70 
71  const Event* Transform(const Event*) const;
72  const Event* InverseTransform(const Event*, Bool_t suppressIfNoTargets=true ) const;
73 
74  // overrides the reference classes of all added transformations. Handle with care!!!
75  void SetTransformationReferenceClass( Int_t cls );
76 
77  VariableTransformBase* AddTransformation(VariableTransformBase*, Int_t cls );
78  const TList& GetTransformationList() const { return fTransformations; }
79  Int_t GetNumOfTransformations() const { return fTransformations.GetSize(); }
80  const std::vector<Event*>* CalcTransformations( const std::vector<Event*>&, Bool_t createNewVector = kFALSE );
81 
82  void CalcStats( const std::vector<Event*>& events );
83  void AddStats ( Int_t k, UInt_t ivar, Double_t mean, Double_t rms, Double_t min, Double_t max );
84  Double_t GetMean ( Int_t ivar, Int_t cls = -1 ) const;
85  Double_t GetRMS ( Int_t ivar, Int_t cls = -1 ) const;
86  Double_t GetMin ( Int_t ivar, Int_t cls = -1 ) const;
87  Double_t GetMax ( Int_t ivar, Int_t cls = -1 ) const;
88 
89  void WriteToStream ( std::ostream& o ) const;
90  void AddXMLTo ( void* parent=0 ) const;
91  void ReadFromStream( std::istream& istr );
92  void ReadFromXML ( void* trfsnode );
93 
94  // writer of function code
95  void MakeFunction(std::ostream& fout, const TString& fncName, Int_t part) const;
96 
97  // variable ranking
98  void PrintVariableRanking() const;
99 
100  // provides string vector giving explicit transformation (only last transform at present -> later show full chain)
101  std::vector<TString>* GetTransformationStringsOfLastTransform() const;
102  const char* GetNameOfLastTransform() const;
103 
104  // modify caller name for output
105  void SetCallerName( const TString& name );
106  const TString& GetCallerName() const { return fCallerName; }
107 
108  // setting file dir for histograms
109  TDirectory* GetRootDir() const { return fRootBaseDir; }
110  void SetRootDir( TDirectory *d ) { fRootBaseDir = d; }
111 
112  void PlotVariables( const std::vector<Event*>& events, TDirectory* theDirectory = 0 );
113 
114  private:
115 
116  // std::vector<TMVA::Event*>* TransformCollection( VariableTransformBase* trf,
117  // Int_t cls,
118  // std::vector<TMVA::Event*>* events,
119  // Bool_t replace ) const;
120 
121  const TMVA::VariableInfo& Variable(UInt_t ivar) const { return fDataSetInfo.GetVariableInfos().at(ivar); }
122  const TMVA::VariableInfo& Target (UInt_t itgt) const { return fDataSetInfo.GetTargetInfos()[itgt]; }
123 
124  DataSet* Data() { return fDataSetInfo.GetDataSet(); }
125 
126  DataSetInfo& fDataSetInfo; // pointer to the datasetinfo
127  TList fTransformations; //! list of transformations
128  std::vector< Int_t > fTransformationsReferenceClasses; //! reference classes for the transformations
129  std::vector<std::vector<TMVA::TransformationHandler::VariableStat> > fVariableStats; // first the variables, then the targets
130 
131  Int_t fNumC; // number of categories (#classes +1)
132 
133  std::vector<Ranking*> fRanking; //! ranking object
134  TDirectory* fRootBaseDir; //! if set put input var hists
135  TString fCallerName; //! name of the caller for output
136  mutable MsgLogger* fLogger; //! message logger
137  MsgLogger& Log() const { return *fLogger; }
138  };
139 }
140 
141 #endif