TSpline2.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: TSpline2.cxx 29122 2009-06-22 06:51:30Z brun $   
00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : TSpline2                                                              *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation (see header for description)                               *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00015  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00016  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00017  *                                                                                *
00018  * Copyright (c) 2005:                                                            *
00019  *      CERN, Switzerland                                                         * 
00020  *      U. of Victoria, Canada                                                    * 
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 //_______________________________________________________________________
00029 //                                                                      
00030 // Quadratic interpolation of TGraph
00031 //_______________________________________________________________________
00032 
00033 #include "TMath.h"
00034 
00035 #include "TMVA/TSpline2.h"
00036 
00037 ClassImp(TMVA::TSpline2)
00038 
00039 //_______________________________________________________________________
00040 TMVA::TSpline2::TSpline2( const TString& title, TGraph* theGraph )
00041    : fGraph( theGraph ) // not owned by TSpline2
00042 {
00043    // constructor from TGraph
00044    // TSpline is a TNamed object
00045    SetNameTitle( title, title );
00046 }
00047 
00048 //_______________________________________________________________________
00049 TMVA::TSpline2::~TSpline2( void )
00050 {
00051    // destructor
00052    if (fGraph) delete fGraph; // ROOT's spline classes also own the TGraph
00053 }
00054 
00055 //_______________________________________________________________________
00056 Double_t TMVA::TSpline2::Eval( const Double_t x ) const
00057 {  
00058    // returns quadratically interpolated TGraph entry around x
00059    Double_t retval=0;
00060   
00061    Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
00062                                      fGraph->GetX(),
00063                                      x );
00064 
00065    // sanity checks
00066    if (ibin < 0               ) ibin = 0;
00067    if (ibin >= fGraph->GetN()) ibin =  fGraph->GetN() - 1;
00068   
00069    Float_t dx = 0; // should be zero
00070   
00071    if (ibin == 0 ) {
00072     
00073       retval = Quadrax(  x,
00074                          fGraph->GetX()[ibin]   + dx,
00075                          fGraph->GetX()[ibin+1] + dx,
00076                          fGraph->GetX()[ibin+2] + dx,
00077                          fGraph->GetY()[ibin],
00078                          fGraph->GetY()[ibin+1],
00079                          fGraph->GetY()[ibin+2]);
00080     
00081    }
00082    else if (ibin >= (fGraph->GetN()-2)) {
00083       ibin = fGraph->GetN() - 1; // always fixed to last bin
00084 
00085       retval = Quadrax( x,
00086                         fGraph->GetX()[ibin-2] + dx,
00087                         fGraph->GetX()[ibin-1] + dx,
00088                         fGraph->GetX()[ibin]   + dx,
00089                         fGraph->GetY()[ibin-2],
00090                         fGraph->GetY()[ibin-1],
00091                         fGraph->GetY()[ibin]);
00092    } 
00093    else {  
00094     
00095       retval = ( Quadrax( x, 
00096                           fGraph->GetX()[ibin-1] + dx,
00097                           fGraph->GetX()[ibin]   + dx,
00098                           fGraph->GetX()[ibin+1] + dx,
00099                           fGraph->GetY()[ibin-1],
00100                           fGraph->GetY()[ibin],
00101                           fGraph->GetY()[ibin+1])
00102                  + 
00103                  Quadrax( x, fGraph->GetX()[ibin] + dx,
00104                           fGraph->GetX()[ibin+1]  + dx,
00105                           fGraph->GetX()[ibin+2]  + dx,
00106                           fGraph->GetY()[ibin],
00107                           fGraph->GetY()[ibin+1],
00108                           fGraph->GetY()[ibin+2]) )*0.5;
00109    }
00110 
00111    return retval;
00112 }
00113 
00114 //_______________________________________________________________________
00115 void TMVA::TSpline2::BuildCoeff( void )
00116 {
00117    // no coefficients to precompute
00118 }
00119 
00120 //_______________________________________________________________________
00121 void TMVA::TSpline2::GetKnot( Int_t  /*i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
00122 {
00123    // no knots
00124 }
00125 
00126 //_______________________________________________________________________
00127 Double_t TMVA::TSpline2::Quadrax( const Float_t dm,const Float_t dm1,const Float_t dm2,const Float_t dm3,
00128                                   const Float_t cos1, const Float_t cos2, const Float_t cos3 ) const
00129 {  
00130    // quadratic interpolation
00131    // Revised and checked by Francois Nov, 16th, 2000
00132    // Note the beautiful non-spontaneous symmetry breaking ...
00133    // It was checked that the old routine gave exactly the same answers.
00134    //   
00135    Float_t a = cos1*(dm2-dm3) + cos2*(dm3-dm1) + cos3*(dm1-dm2);
00136    Float_t b = cos1*(dm2*dm2-dm3*dm3) + cos2*(dm3*dm3-dm1*dm1) + cos3*(dm1*dm1-dm2*dm2);
00137    Float_t c = cos1*(dm2-dm3)*dm2*dm3 + cos2*(dm3-dm1)*dm3*dm1 + cos3*(dm1-dm2)*dm1*dm2;
00138 
00139    Float_t denom = (dm2-dm3)*(dm3-dm1)*(dm1-dm2);
00140   
00141    return (denom != 0.0) ? (-a*dm*dm+b*dm-c)/denom : 0.0;
00142 }
00143 
00144 

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