Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/LICENSE) *
26 **********************************************************************************/
27
28/*! \class TMVA::TSpline1
29\ingroup TMVA
30Linear 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 pointer (not owned by TSpline1)
42/// TSpline is a TNamed object
43
44TMVA::TSpline1::TSpline1( const TString& title, const TGraph *theGraph )
45: fX(theGraph->GetX(), theGraph->GetX() + theGraph->GetN()),
46 fY(theGraph->GetY(), theGraph->GetY() + theGraph->GetN())
47{
48 SetNameTitle( title, title );
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// destructor
53
55
56////////////////////////////////////////////////////////////////////////////////
57/// returns linearly interpolated TGraph entry around x
58
60{
61 Int_t N = fX.size();
62 Int_t ibin = std::distance(fX.begin(), TMath::BinarySearch(fX.begin(), fX.end(), x));
63 // sanity checks
64 if (ibin < 0 ) ibin = 0;
65 if (ibin >= N) ibin = N - 1;
66
67 Int_t nextbin = ibin;
68 if ((x > fX[ibin] && ibin != N-1) || ibin == 0)
69 nextbin++;
70 else
71 nextbin--;
72
73 // linear interpolation
74 Double_t dx = fX[ibin] - fX[nextbin];
75 Double_t dy = fY[ibin] - fY[nextbin];
76 return fY[ibin] + (x - fX[ibin]) * dy/dx;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// no coefficients to precompute
81
83{
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// no knots
88
89void TMVA::TSpline1::GetKnot( Int_t /* i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
90{
91}
#define ClassImp(name)
Definition Rtypes.h:377
#define N
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
Linear interpolation of TGraph.
Definition TSpline1.h:43
TSpline1(const TString &title, const TGraph *theGraph)
constructor from TGraph pointer (not owned by TSpline1) TSpline is a TNamed object
Definition TSpline1.cxx:44
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const
no knots
Definition TSpline1.cxx:89
virtual ~TSpline1(void)
destructor
Definition TSpline1.cxx:54
virtual void BuildCoeff(void)
no coefficients to precompute
Definition TSpline1.cxx:82
virtual Double_t Eval(Double_t x) const
returns linearly interpolated TGraph entry around x
Definition TSpline1.cxx:59
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition TNamed.cxx:154
Basic string class.
Definition TString.h:139
Double_t x[n]
Definition legend1.C:17
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition TMathBase.h:347