ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "TMVA/TSpline1.h"
34 
35 #include "TGraph.h"
36 #include "TMath.h"
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// constructor from TGraph
42 /// TSpline is a TNamed object
43 
44 TMVA::TSpline1::TSpline1( const TString& title, TGraph* theGraph )
45  : fGraph( theGraph )
46 {
47  SetNameTitle( title, title );
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// destructor
52 
54 {
55  if (fGraph) delete fGraph; // ROOT's spline classes also own the TGraph
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// returns linearly interpolated TGraph entry around x
60 
62 {
63  Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
64  fGraph->GetX(),
65  x );
66  Int_t nbin = fGraph->GetN();
67 
68  // sanity checks
69  if (ibin < 0 ) ibin = 0;
70  if (ibin >= nbin) ibin = nbin - 1;
71 
72  Int_t nextbin = ibin;
73  if ((x > fGraph->GetX()[ibin] && ibin != nbin-1) || ibin == 0)
74  nextbin++;
75  else
76  nextbin--;
77 
78  // linear interpolation
79  Double_t dx = fGraph->GetX()[ibin] - fGraph->GetX()[nextbin];
80  Double_t dy = fGraph->GetY()[ibin] - fGraph->GetY()[nextbin];
81  return fGraph->GetY()[ibin] + (x - fGraph->GetX()[ibin]) * dy/dx;
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// no coefficients to precompute
86 
88 {
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// no knots
93 
94 void TMVA::TSpline1::GetKnot( Int_t /* i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
95 {
96 }
97 
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
Double_t x[n]
Definition: legend1.C:17
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
ClassImp(TMVA::TSpline1) TMVA
constructor from TGraph TSpline is a TNamed object
Definition: TSpline1.cxx:38
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:61
virtual void BuildCoeff(void)
no coefficients to precompute
Definition: TSpline1.cxx:87
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:53
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:94