// @(#)root/tmva $Id$
// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Eckhard v. Toerne

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : VariableGaussTransform                                                *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Decorrelation of input variables                                          *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
 *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
 *      Eckhard v. Toerne     <evt@uni-bonn.de>  - Uni Bonn, Germany              *
 *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         *
 *      U. of Victoria, Canada                                                    *
 *      MPI-K Heidelberg, Germany                                                 *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_VariableGaussTransform
#define ROOT_TMVA_VariableGaussTransform

#ifndef ROOT_TMVA_PDF
#include "TMVA/PDF.h"
#endif

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// VariableGaussTransform                                               //
//                                                                      //
// Gaussian transformation of input variables.                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <vector>

#ifndef ROOT_TH1
#include "TH1.h"
#endif
#ifndef ROOT_TGraph
#include "TGraph.h"
#endif
#ifndef ROOT_TSpline
#include "TSpline.h"
#endif
#ifndef ROOT_TDirectory
#include "TDirectory.h"
#endif
#ifndef ROOT_Event
#include "Event.h"
#endif

#ifndef ROOT_TMVA_VariableTransformBase
#include "TMVA/VariableTransformBase.h"
#endif

namespace TMVA {

   class TMVAGaussPair {

   public:

      TMVAGaussPair( Float_t f, Float_t w ): fF(f), fW(w) {}
      Bool_t  operator >  ( const TMVAGaussPair &p ) const { return fF >  p.fF; }
      Bool_t  operator <  ( const TMVAGaussPair &p ) const { return fF <  p.fF; }
      Bool_t  operator == ( const TMVAGaussPair &p ) const { return fF == p.fF; }
      Float_t GetValue() const { return fF; }
      Float_t GetWeight() const { return fW; }

   private:

      Float_t fF; // the float
      Float_t fW; // the event weight
   };


   class VariableGaussTransform : public VariableTransformBase {

   public:
  
      VariableGaussTransform( DataSetInfo& dsi, TString strcor=""  );
      virtual ~VariableGaussTransform( void );

      void   Initialize();
      Bool_t PrepareTransformation (const std::vector<Event*>&);

      virtual const Event* Transform(const Event* const, Int_t cls ) const;
      virtual const Event* InverseTransform(const Event* const, Int_t cls ) const;

      void WriteTransformationToStream ( std::ostream& ) const;
      void ReadTransformationFromStream( std::istream&, const TString& );
     
      virtual void AttachXMLTo(void* parent);
      virtual void ReadFromXML( void* trfnode );

      virtual void PrintTransformation( std::ostream & o );

      // writer of function code
      virtual void MakeFunction( std::ostream& fout, const TString& fncName, Int_t part, UInt_t trCounter, Int_t cls );
    
   private:

      Bool_t           fFlatNotGauss;
      Int_t            fPdfMinSmooth;
      Int_t            fPdfMaxSmooth;
      //      mutable Event*   fTransformedEvent;

      std::vector< std::vector< TH1F* > >      fCumulativeDist;   //! The Cummulative distributions 
      //std::vector< std::vector< TGraph* > >    fCumulativeGraph;  //! The Cummulative distributions 
      //std::vector< std::vector< TSpline3* > >  fCumulativeSpline; //! The Cummulative distributions 
      std::vector< std::vector< PDF*> >         fCumulativePDF;    //  The cumulative PDF

      void GetCumulativeDist( const std::vector<Event*>& );
      void CleanUpCumulativeArrays(TString opt = "ALL");

      // needed for backward compatibility
      UInt_t fElementsperbin;  // av number of events stored per bin in cum dist
      Double_t OldCumulant(Float_t x, TH1* h ) const;

      ClassDef(VariableGaussTransform,0) // Variable transformation: Gauss transformation
   };

} // namespace TMVA

#endif 
 VariableGaussTransform.h:1
 VariableGaussTransform.h:2
 VariableGaussTransform.h:3
 VariableGaussTransform.h:4
 VariableGaussTransform.h:5
 VariableGaussTransform.h:6
 VariableGaussTransform.h:7
 VariableGaussTransform.h:8
 VariableGaussTransform.h:9
 VariableGaussTransform.h:10
 VariableGaussTransform.h:11
 VariableGaussTransform.h:12
 VariableGaussTransform.h:13
 VariableGaussTransform.h:14
 VariableGaussTransform.h:15
 VariableGaussTransform.h:16
 VariableGaussTransform.h:17
 VariableGaussTransform.h:18
 VariableGaussTransform.h:19
 VariableGaussTransform.h:20
 VariableGaussTransform.h:21
 VariableGaussTransform.h:22
 VariableGaussTransform.h:23
 VariableGaussTransform.h:24
 VariableGaussTransform.h:25
 VariableGaussTransform.h:26
 VariableGaussTransform.h:27
 VariableGaussTransform.h:28
 VariableGaussTransform.h:29
 VariableGaussTransform.h:30
 VariableGaussTransform.h:31
 VariableGaussTransform.h:32
 VariableGaussTransform.h:33
 VariableGaussTransform.h:34
 VariableGaussTransform.h:35
 VariableGaussTransform.h:36
 VariableGaussTransform.h:37
 VariableGaussTransform.h:38
 VariableGaussTransform.h:39
 VariableGaussTransform.h:40
 VariableGaussTransform.h:41
 VariableGaussTransform.h:42
 VariableGaussTransform.h:43
 VariableGaussTransform.h:44
 VariableGaussTransform.h:45
 VariableGaussTransform.h:46
 VariableGaussTransform.h:47
 VariableGaussTransform.h:48
 VariableGaussTransform.h:49
 VariableGaussTransform.h:50
 VariableGaussTransform.h:51
 VariableGaussTransform.h:52
 VariableGaussTransform.h:53
 VariableGaussTransform.h:54
 VariableGaussTransform.h:55
 VariableGaussTransform.h:56
 VariableGaussTransform.h:57
 VariableGaussTransform.h:58
 VariableGaussTransform.h:59
 VariableGaussTransform.h:60
 VariableGaussTransform.h:61
 VariableGaussTransform.h:62
 VariableGaussTransform.h:63
 VariableGaussTransform.h:64
 VariableGaussTransform.h:65
 VariableGaussTransform.h:66
 VariableGaussTransform.h:67
 VariableGaussTransform.h:68
 VariableGaussTransform.h:69
 VariableGaussTransform.h:70
 VariableGaussTransform.h:71
 VariableGaussTransform.h:72
 VariableGaussTransform.h:73
 VariableGaussTransform.h:74
 VariableGaussTransform.h:75
 VariableGaussTransform.h:76
 VariableGaussTransform.h:77
 VariableGaussTransform.h:78
 VariableGaussTransform.h:79
 VariableGaussTransform.h:80
 VariableGaussTransform.h:81
 VariableGaussTransform.h:82
 VariableGaussTransform.h:83
 VariableGaussTransform.h:84
 VariableGaussTransform.h:85
 VariableGaussTransform.h:86
 VariableGaussTransform.h:87
 VariableGaussTransform.h:88
 VariableGaussTransform.h:89
 VariableGaussTransform.h:90
 VariableGaussTransform.h:91
 VariableGaussTransform.h:92
 VariableGaussTransform.h:93
 VariableGaussTransform.h:94
 VariableGaussTransform.h:95
 VariableGaussTransform.h:96
 VariableGaussTransform.h:97
 VariableGaussTransform.h:98
 VariableGaussTransform.h:99
 VariableGaussTransform.h:100
 VariableGaussTransform.h:101
 VariableGaussTransform.h:102
 VariableGaussTransform.h:103
 VariableGaussTransform.h:104
 VariableGaussTransform.h:105
 VariableGaussTransform.h:106
 VariableGaussTransform.h:107
 VariableGaussTransform.h:108
 VariableGaussTransform.h:109
 VariableGaussTransform.h:110
 VariableGaussTransform.h:111
 VariableGaussTransform.h:112
 VariableGaussTransform.h:113
 VariableGaussTransform.h:114
 VariableGaussTransform.h:115
 VariableGaussTransform.h:116
 VariableGaussTransform.h:117
 VariableGaussTransform.h:118
 VariableGaussTransform.h:119
 VariableGaussTransform.h:120
 VariableGaussTransform.h:121
 VariableGaussTransform.h:122
 VariableGaussTransform.h:123
 VariableGaussTransform.h:124
 VariableGaussTransform.h:125
 VariableGaussTransform.h:126
 VariableGaussTransform.h:127
 VariableGaussTransform.h:128
 VariableGaussTransform.h:129
 VariableGaussTransform.h:130
 VariableGaussTransform.h:131
 VariableGaussTransform.h:132
 VariableGaussTransform.h:133
 VariableGaussTransform.h:134