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
38
39////////////////////////////////////////////////////////////////////////////////
40/// constructor from TGraph pointer (not owned by TSpline1)
41/// TSpline is a TNamed object
42
44: fX(theGraph->GetX(), theGraph->GetX() + theGraph->GetN()),
45 fY(theGraph->GetY(), theGraph->GetY() + theGraph->GetN())
46{
47 SetNameTitle( title, title );
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// destructor
52
54
55////////////////////////////////////////////////////////////////////////////////
56/// returns linearly interpolated TGraph entry around x
57
59{
60 Int_t N = fX.size();
61 Int_t ibin = std::distance(std::lower_bound(fX.rbegin(), fX.rend(), x, std::greater{}), fX.rend()) - 1;
62 // sanity checks
63 if (ibin < 0 ) ibin = 0;
64 if (ibin >= N) ibin = N - 1;
65
67 if ((x > fX[ibin] && ibin != N-1) || ibin == 0)
68 nextbin++;
69 else
70 nextbin--;
71
72 // linear interpolation
73 Double_t dx = fX[ibin] - fX[nextbin];
74 Double_t dy = fY[ibin] - fY[nextbin];
75 return fY[ibin] + (x - fX[ibin]) * dy/dx;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// no coefficients to precompute
80
82{
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// no knots
87
88void TMVA::TSpline1::GetKnot( Int_t /* i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
89{
90}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define N
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
TSpline1(const TString &title, const TGraph *theGraph)
constructor from TGraph pointer (not owned by TSpline1) TSpline is a TNamed object
Definition TSpline1.cxx:43
void BuildCoeff(void) override
no coefficients to precompute
Definition TSpline1.cxx:81
Double_t Eval(Double_t x) const override
returns linearly interpolated TGraph entry around x
Definition TSpline1.cxx:58
virtual ~TSpline1(void)
destructor
Definition TSpline1.cxx:53
void GetKnot(Int_t i, Double_t &x, Double_t &y) const override
no knots
Definition TSpline1.cxx:88
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition TNamed.cxx:163
Basic string class.
Definition TString.h:138
Double_t x[n]
Definition legend1.C:17