ROOT  6.06/09
Reference Guide
TSpline1.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TSpline1 *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
16  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
17  * *
18  * Copyright (c) 2005: *
19  * CERN, Switzerland *
20  * U. of Victoria, Canada *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 //_______________________________________________________________________
29 //
30 // Linear interpolation of TGraph
31 //_______________________________________________________________________
32 
33 #include "TMath.h"
34 
35 #include "TMVA/TSpline1.h"
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// constructor from TGraph
41 /// TSpline is a TNamed object
42 
43 TMVA::TSpline1::TSpline1( const TString& title, TGraph* theGraph )
44  : fGraph( theGraph )
45 {
46  SetNameTitle( title, title );
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// destructor
51 
53 {
54  if (fGraph) delete fGraph; // ROOT's spline classes also own the TGraph
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// returns linearly interpolated TGraph entry around x
59 
61 {
62  Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
63  fGraph->GetX(),
64  x );
65  Int_t nbin = fGraph->GetN();
66 
67  // sanity checks
68  if (ibin < 0 ) ibin = 0;
69  if (ibin >= nbin) ibin = nbin - 1;
70 
71  Int_t nextbin = ibin;
72  if ((x > fGraph->GetX()[ibin] && ibin != nbin-1) || ibin == 0)
73  nextbin++;
74  else
75  nextbin--;
76 
77  // linear interpolation
78  Double_t dx = fGraph->GetX()[ibin] - fGraph->GetX()[nextbin];
79  Double_t dy = fGraph->GetY()[ibin] - fGraph->GetY()[nextbin];
80  return fGraph->GetY()[ibin] + (x - fGraph->GetX()[ibin]) * dy/dx;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// no coefficients to precompute
85 
87 {
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// no knots
92 
93 void TMVA::TSpline1::GetKnot( Int_t /* i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
94 {
95 }
96 
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
Double_t x[n]
Definition: legend1.C:17
ClassImp(TMVA::TSpline1) TMVA
constructor from TGraph TSpline is a TNamed object
Definition: TSpline1.cxx:37
TGraph * fGraph
Definition: TSpline1.h:62
double Double_t
Definition: RtypesCore.h:55
virtual Double_t Eval(Double_t x) const
returns linearly interpolated TGraph entry around x
Definition: TSpline1.cxx:60
virtual void BuildCoeff(void)
no coefficients to precompute
Definition: TSpline1.cxx:86
Abstract ClassifierFactory template that handles arbitrary types.
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
virtual ~TSpline1(void)
destructor
Definition: TSpline1.cxx:52
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:944
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const
no knots
Definition: TSpline1.cxx:93