00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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 )
00042 {
00043
00044
00045 SetNameTitle( title, title );
00046 }
00047
00048
00049 TMVA::TSpline2::~TSpline2( void )
00050 {
00051
00052 if (fGraph) delete fGraph;
00053 }
00054
00055
00056 Double_t TMVA::TSpline2::Eval( const Double_t x ) const
00057 {
00058
00059 Double_t retval=0;
00060
00061 Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
00062 fGraph->GetX(),
00063 x );
00064
00065
00066 if (ibin < 0 ) ibin = 0;
00067 if (ibin >= fGraph->GetN()) ibin = fGraph->GetN() - 1;
00068
00069 Float_t dx = 0;
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;
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
00118 }
00119
00120
00121 void TMVA::TSpline2::GetKnot( Int_t , Double_t& , Double_t& ) const
00122 {
00123
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
00131
00132
00133
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