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
40
41////////////////////////////////////////////////////////////////////////////////
42/// constructor from TGraph pointer (not owned by TSpline2)
43/// TSpline is a TNamed object
44
45TMVA::TSpline2::TSpline2(const TString &title, const TGraph *theGraph)
46: fX(theGraph->GetX(), theGraph->GetX() + theGraph->GetN()),
47 fY(theGraph->GetY(), theGraph->GetY() + theGraph->GetN())
48{
49 SetNameTitle( title, title );
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// destructor
54
56
57////////////////////////////////////////////////////////////////////////////////
58/// returns quadratically interpolated TGraph entry around x
59
61{
62 Double_t retval=0;
63 Int_t N = fX.size();
64 Int_t ibin = std::distance(fX.begin(), TMath::BinarySearch( fX.begin(), fX.end(), x ));
65
66 // sanity checks
67 if (ibin < 0 ) ibin = 0;
68 if (ibin >= N) ibin = N - 1;
69
70 Float_t dx = 0; // should be zero
71 if (N < 3) { // if the graph does not have enough points
72 Warning("Eval", "Graph has less than 3 points, returning value of the closest");
73 retval = fY[ibin];
74 } else if (ibin == 0) {
75
76 retval = Quadrax(x,
77 fX[ibin] + dx,
78 fX[ibin + 1] + dx,
79 fX[ibin + 2] + dx,
80 fY[ibin],
81 fY[ibin + 1],
82 fY[ibin + 2]);
83
84 } else if (ibin >= (N - 2)) {
85 ibin = N - 1; // always fixed to last bin
86
87 retval = Quadrax(x,
88 fX[ibin - 2] + dx,
89 fX[ibin - 1] + dx,
90 fX[ibin] + dx,
91 fY[ibin - 2],
92 fY[ibin - 1],
93 fY[ibin]);
94 } else {
95
96 retval = ( Quadrax( x,
97 fX[ibin-1] + dx,
98 fX[ibin] + dx,
99 fX[ibin+1] + dx,
100 fY[ibin-1],
101 fY[ibin],
102 fY[ibin+1])
103 +
104 Quadrax( x,
105 fX[ibin] + dx,
106 fX[ibin+1] + dx,
107 fX[ibin+2] + dx,
108 fY[ibin],
109 fY[ibin+1],
110 fY[ibin+2]) )*0.5;
111 }
112
113 return retval;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// no coefficients to precompute
118
120{
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// no knots
125
126void TMVA::TSpline2::GetKnot( Int_t /*i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
127{
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// quadratic interpolation
132/// Revised and checked by Francois Nov, 16th, 2000
133/// Note the beautiful non-spontaneous symmetry breaking ...
134/// It was checked that the old routine gave exactly the same answers.
135///
136
137Double_t TMVA::TSpline2::Quadrax( const Float_t dm,const Float_t dm1,const Float_t dm2,const Float_t dm3,
138 const Float_t cos1, const Float_t cos2, const Float_t cos3 ) const
139{
140 Float_t a = cos1*(dm2-dm3) + cos2*(dm3-dm1) + cos3*(dm1-dm2);
141 Float_t b = cos1*(dm2*dm2-dm3*dm3) + cos2*(dm3*dm3-dm1*dm1) + cos3*(dm1*dm1-dm2*dm2);
142 Float_t c = cos1*(dm2-dm3)*dm2*dm3 + cos2*(dm3-dm1)*dm3*dm1 + cos3*(dm1-dm2)*dm1*dm2;
143
144 Float_t denom = (dm2-dm3)*(dm3-dm1)*(dm1-dm2);
145
146 return (denom != 0.0) ? (-a*dm*dm+b*dm-c)/denom : 0.0;
147}
148
149
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
float Float_t
Definition RtypesCore.h:57
#define ClassImp(name)
Definition Rtypes.h:377
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
#define N
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
Quadratic interpolation of TGraph.
Definition TSpline2.h:43
virtual void BuildCoeff(void)
no coefficients to precompute
Definition TSpline2.cxx:119
TSpline2(const TString &title, const TGraph *theGraph)
constructor from TGraph pointer (not owned by TSpline2) TSpline is a TNamed object
Definition TSpline2.cxx:45
virtual ~TSpline2(void)
destructor
Definition TSpline2.cxx:55
virtual Double_t Eval(Double_t x) const
returns quadratically interpolated TGraph entry around x
Definition TSpline2.cxx:60
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const
no knots
Definition TSpline2.cxx:126
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:137
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