Logo ROOT  
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 /*! \class TMVA::TSpline1
29 \ingroup TMVA
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 }
TNamed::SetNameTitle
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:154
TMVA::TSpline1::Eval
virtual Double_t Eval(Double_t x) const
returns linearly interpolated TGraph entry around x
Definition: TSpline1.cxx:61
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGraph.h
x
Double_t x[n]
Definition: legend1.C:17
TString
Basic string class.
Definition: TString.h:136
TMVA::TSpline1::~TSpline1
virtual ~TSpline1(void)
destructor
Definition: TSpline1.cxx:53
TMVA::TSpline1
Linear interpolation of TGraph.
Definition: TSpline1.h:43
TMVA::TSpline1::GetKnot
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const
no knots
Definition: TSpline1.cxx:94
TSpline1.h
TMath::BinarySearch
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMathBase.h:278
Double_t
double Double_t
Definition: RtypesCore.h:59
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
TMVA::TSpline1::TSpline1
TSpline1(const TString &title, TGraph *theGraph)
constructor from TGraph TSpline is a TNamed object
Definition: TSpline1.cxx:44
TMVA::TSpline1::BuildCoeff
virtual void BuildCoeff(void)
no coefficients to precompute
Definition: TSpline1.cxx:87
TMath.h
int