00001 // @(#)root/tmva $Id: TSpline1.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 : TSpline1 * 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 // Linear interpolation of TGraph 00031 //_______________________________________________________________________ 00032 00033 #include "TMath.h" 00034 00035 #include "TMVA/TSpline1.h" 00036 00037 ClassImp(TMVA::TSpline1) 00038 00039 //_______________________________________________________________________ 00040 TMVA::TSpline1::TSpline1( const TString& title, TGraph* theGraph ) 00041 : fGraph( theGraph ) 00042 { 00043 // constructor from TGraph 00044 // TSpline is a TNamed object 00045 SetNameTitle( title, title ); 00046 } 00047 00048 //_______________________________________________________________________ 00049 TMVA::TSpline1::~TSpline1( void ) 00050 { 00051 // destructor 00052 if (fGraph) delete fGraph; // ROOT's spline classes also own the TGraph 00053 } 00054 00055 //_______________________________________________________________________ 00056 Double_t TMVA::TSpline1::Eval( Double_t x ) const 00057 { 00058 // returns linearly interpolated TGraph entry around x 00059 Int_t ibin = TMath::BinarySearch( fGraph->GetN(), 00060 fGraph->GetX(), 00061 x ); 00062 Int_t nbin = fGraph->GetN(); 00063 00064 // sanity checks 00065 if (ibin < 0 ) ibin = 0; 00066 if (ibin >= nbin) ibin = nbin - 1; 00067 00068 Int_t nextbin = ibin; 00069 if ((x > fGraph->GetX()[ibin] && ibin != nbin-1) || ibin == 0) 00070 nextbin++; 00071 else 00072 nextbin--; 00073 00074 // linear interpolation 00075 Double_t dx = fGraph->GetX()[ibin] - fGraph->GetX()[nextbin]; 00076 Double_t dy = fGraph->GetY()[ibin] - fGraph->GetY()[nextbin]; 00077 return fGraph->GetY()[ibin] + (x - fGraph->GetX()[ibin]) * dy/dx; 00078 } 00079 00080 //_______________________________________________________________________ 00081 void TMVA::TSpline1::BuildCoeff( void ) 00082 { 00083 // no coefficients to precompute 00084 } 00085 00086 //_______________________________________________________________________ 00087 void TMVA::TSpline1::GetKnot( Int_t /* i*/, Double_t& /*x*/, Double_t& /*y*/ ) const 00088 { 00089 // no knots 00090 } 00091