Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSpline2.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 : TSpline2 *
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::TSpline2
29\ingroup TMVA
30Quadratic interpolation of TGraph
31*/
32
33#include "TMVA/TSpline2.h"
34
35#include "TGraph.h"
36#include "TMath.h"
37#include "TSpline.h"
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// constructor from TGraph pointer (not owned by TSpline2)
42/// TSpline is a TNamed object
43
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 quadratically interpolated TGraph entry around x
58
60{
62 Int_t N = fX.size();
63 Int_t ibin = std::distance(std::lower_bound(fX.rbegin(), fX.rend(), x, std::greater{}), fX.rend()) - 1;
64
65 // sanity checks
66 if (ibin < 0 ) ibin = 0;
67 if (ibin >= N) ibin = N - 1;
68
69 Float_t dx = 0; // should be zero
70 if (N < 3) { // if the graph does not have enough points
71 Warning("Eval", "Graph has less than 3 points, returning value of the closest");
72 retval = fY[ibin];
73 } else if (ibin == 0) {
74
75 retval = Quadrax(x,
76 fX[ibin] + dx,
77 fX[ibin + 1] + dx,
78 fX[ibin + 2] + dx,
79 fY[ibin],
80 fY[ibin + 1],
81 fY[ibin + 2]);
82
83 } else if (ibin >= (N - 2)) {
84 ibin = N - 1; // always fixed to last bin
85
86 retval = Quadrax(x,
87 fX[ibin - 2] + dx,
88 fX[ibin - 1] + dx,
89 fX[ibin] + dx,
90 fY[ibin - 2],
91 fY[ibin - 1],
92 fY[ibin]);
93 } else {
94
95 retval = ( Quadrax( x,
96 fX[ibin-1] + dx,
97 fX[ibin] + dx,
98 fX[ibin+1] + dx,
99 fY[ibin-1],
100 fY[ibin],
101 fY[ibin+1])
102 +
103 Quadrax( x,
104 fX[ibin] + dx,
105 fX[ibin+1] + dx,
106 fX[ibin+2] + dx,
107 fY[ibin],
108 fY[ibin+1],
109 fY[ibin+2]) )*0.5;
110 }
111
112 return retval;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// no coefficients to precompute
117
119{
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// no knots
124
125void TMVA::TSpline2::GetKnot( Int_t /*i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
126{
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// quadratic interpolation
131/// Revised and checked by Francois Nov, 16th, 2000
132/// Note the beautiful non-spontaneous symmetry breaking ...
133/// It was checked that the old routine gave exactly the same answers.
134///
135
137 const Float_t cos1, const Float_t cos2, const Float_t cos3 ) const
138{
139 Float_t a = cos1*(dm2-dm3) + cos2*(dm3-dm1) + cos3*(dm1-dm2);
142
143 Float_t denom = (dm2-dm3)*(dm3-dm1)*(dm1-dm2);
144
145 return (denom != 0.0) ? (-a*dm*dm+b*dm-c)/denom : 0.0;
146}
147
148
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
#define N
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void GetKnot(Int_t i, Double_t &x, Double_t &y) const override
no knots
Definition TSpline2.cxx:125
void BuildCoeff(void) override
no coefficients to precompute
Definition TSpline2.cxx:118
Double_t Eval(Double_t x) const override
returns quadratically interpolated TGraph entry around x
Definition TSpline2.cxx:59
TSpline2(const TString &title, const TGraph *theGraph)
constructor from TGraph pointer (not owned by TSpline2) TSpline is a TNamed object
Definition TSpline2.cxx:44
virtual ~TSpline2(void)
destructor
Definition TSpline2.cxx:54
Double_t Quadrax(Float_t dm, Float_t dm1, Float_t dm2, Float_t dm3, Float_t cos1, Float_t cos2, Float_t cos3) const
quadratic interpolation Revised and checked by Francois Nov, 16th, 2000 Note the beautiful non-sponta...
Definition TSpline2.cxx:136
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