/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : TMVA_TSpline2                                                         *
 *                                                                                *
 * Description:                                                                   *
 *      Implementation (see header for description)                               *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
 *      Xavier Prudent  <prudent@lapp.in2p3.fr>  - LAPP, France                   *
 *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-KP Heidelberg, Germany     *
 *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland,                                                        * 
 *      U. of Victoria, Canada,                                                   * 
 *      MPI-KP Heidelberg, Germany,                                               * 
 *      LAPP, Annecy, France                                                      *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://mva.sourceforge.net/license.txt)                                       *
 *                                                                                *
 **********************************************************************************/

#include "TMVA_TSpline2.h"
#include "Riostream.h"

ClassImp(TMVA_TSpline2)

//_______________________________________________________________________
 TMVA_TSpline2::TMVA_TSpline2( TString title, TGraph* theGraph )
  : fGraph( theGraph )
{
  // TSpline is a TNamed object
  SetNameTitle( title, title );  
}

//_______________________________________________________________________
 TMVA_TSpline2::~TMVA_TSpline2( void )
{
  if (NULL != fGraph) delete fGraph;
}

//_______________________________________________________________________
 Double_t TMVA_TSpline2::Eval( const Double_t x ) const
{  
  Double_t retval=0;
  
  Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
				    fGraph->GetX(),
				    x );

  // sanity checks
  if (ibin < 0               ) ibin = 0;
  if (ibin >= fGraph->GetN()) ibin =  fGraph->GetN() - 1;
  
  Float_t dx = 0; // should be zero
  
  if (ibin == 0 ) {
    
    retval = Quadrax(  x,
		       fGraph->GetX()[ibin]   + dx,
		       fGraph->GetX()[ibin+1] + dx,
		       fGraph->GetX()[ibin+2] + dx,
		       fGraph->GetY()[ibin],
		       fGraph->GetY()[ibin+1],
		       fGraph->GetY()[ibin+2]);
    
  }
  else if (ibin >= (fGraph->GetN()-1)) {
    
    retval = Quadrax( x, 
		      fGraph->GetX()[ibin-2] + dx,
 		      fGraph->GetX()[ibin-1] + dx,
 		      fGraph->GetX()[ibin]   + dx,
 		      fGraph->GetY()[ibin-2],
 		      fGraph->GetY()[ibin-1],
		      fGraph->GetY()[ibin]);
  }
  else {  
    
    retval = ( Quadrax( x, 
			fGraph->GetX()[ibin-1] + dx,
			fGraph->GetX()[ibin]   + dx,
			fGraph->GetX()[ibin+1] + dx,
			fGraph->GetY()[ibin-1],
			fGraph->GetY()[ibin],
			fGraph->GetY()[ibin+1])
	       + 
	       Quadrax( x, fGraph->GetX()[ibin] + dx,
			fGraph->GetX()[ibin+1]  + dx,
			fGraph->GetX()[ibin+2]  + dx,
			fGraph->GetY()[ibin],
			fGraph->GetY()[ibin+1],
			fGraph->GetY()[ibin+2]) )*0.5;
  }

  return retval;
}

//_______________________________________________________________________
 void TMVA_TSpline2::BuildCoeff( void )
{}

//_______________________________________________________________________
 void TMVA_TSpline2::GetKnot( Int_t  /*i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
{}

//_______________________________________________________________________
 Double_t TMVA_TSpline2::Quadrax(const Float_t dm,const Float_t dm1,const Float_t dm2,const Float_t dm3,
			       const Float_t cos1, const Float_t cos2, const Float_t cos3 ) const
{  
// 
// Revised and checked by Francois Nov, 16th, 2000
// Note the beautiful non-spontaneous symmetry breaking ...
// It was checked that the old routine gave exactly the same answers.
//   
  Float_t a = cos1*(dm2-dm3) + cos2*(dm3-dm1) + cos3*(dm1-dm2);
  Float_t b = cos1*(dm2*dm2-dm3*dm3) + cos2*(dm3*dm3-dm1*dm1) + cos3*(dm1*dm1-dm2*dm2);
  Float_t c = cos1*(dm2-dm3)*dm2*dm3 + cos2*(dm3-dm1)*dm3*dm1 + cos3*(dm1-dm2)*dm1*dm2;

  Float_t denom = (dm2-dm3)*(dm3-dm1)*(dm1-dm2);
  
  return (denom != 0.0) ? (-a*dm*dm+b*dm-c)/denom : 0.0;
}




ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.