ROOT  6.06/09
Reference Guide
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  * 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 //_______________________________________________________________________
29 //
30 // Quadratic interpolation of TGraph
31 //_______________________________________________________________________
32 
33 #include "TMath.h"
34 
35 #include "TMVA/TSpline2.h"
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// constructor from TGraph
41 /// TSpline is a TNamed object
42 
43 TMVA::TSpline2::TSpline2( const TString& title, TGraph* theGraph )
44  : fGraph( theGraph ) // not owned by TSpline2
45 {
46  SetNameTitle( title, title );
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// destructor
51 
53 {
54  if (fGraph) delete fGraph; // ROOT's spline classes also own the TGraph
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// returns quadratically interpolated TGraph entry around x
59 
61 {
62  Double_t retval=0;
63 
64  Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
65  fGraph->GetX(),
66  x );
67 
68  // sanity checks
69  if (ibin < 0 ) ibin = 0;
70  if (ibin >= fGraph->GetN()) ibin = fGraph->GetN() - 1;
71 
72  Float_t dx = 0; // should be zero
73 
74  if (ibin == 0 ) {
75 
76  retval = Quadrax( x,
77  fGraph->GetX()[ibin] + dx,
78  fGraph->GetX()[ibin+1] + dx,
79  fGraph->GetX()[ibin+2] + dx,
80  fGraph->GetY()[ibin],
81  fGraph->GetY()[ibin+1],
82  fGraph->GetY()[ibin+2]);
83 
84  }
85  else if (ibin >= (fGraph->GetN()-2)) {
86  ibin = fGraph->GetN() - 1; // always fixed to last bin
87 
88  retval = Quadrax( x,
89  fGraph->GetX()[ibin-2] + dx,
90  fGraph->GetX()[ibin-1] + dx,
91  fGraph->GetX()[ibin] + dx,
92  fGraph->GetY()[ibin-2],
93  fGraph->GetY()[ibin-1],
94  fGraph->GetY()[ibin]);
95  }
96  else {
97 
98  retval = ( Quadrax( x,
99  fGraph->GetX()[ibin-1] + dx,
100  fGraph->GetX()[ibin] + dx,
101  fGraph->GetX()[ibin+1] + dx,
102  fGraph->GetY()[ibin-1],
103  fGraph->GetY()[ibin],
104  fGraph->GetY()[ibin+1])
105  +
106  Quadrax( x, fGraph->GetX()[ibin] + dx,
107  fGraph->GetX()[ibin+1] + dx,
108  fGraph->GetX()[ibin+2] + dx,
109  fGraph->GetY()[ibin],
110  fGraph->GetY()[ibin+1],
111  fGraph->GetY()[ibin+2]) )*0.5;
112  }
113 
114  return retval;
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// no coefficients to precompute
119 
121 {
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// no knots
126 
127 void TMVA::TSpline2::GetKnot( Int_t /*i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
128 {
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// quadratic interpolation
133 /// Revised and checked by Francois Nov, 16th, 2000
134 /// Note the beautiful non-spontaneous symmetry breaking ...
135 /// It was checked that the old routine gave exactly the same answers.
136 ///
137 
138 Double_t TMVA::TSpline2::Quadrax( const Float_t dm,const Float_t dm1,const Float_t dm2,const Float_t dm3,
139  const Float_t cos1, const Float_t cos2, const Float_t cos3 ) const
140 {
141  Float_t a = cos1*(dm2-dm3) + cos2*(dm3-dm1) + cos3*(dm1-dm2);
142  Float_t b = cos1*(dm2*dm2-dm3*dm3) + cos2*(dm3*dm3-dm1*dm1) + cos3*(dm1*dm1-dm2*dm2);
143  Float_t c = cos1*(dm2-dm3)*dm2*dm3 + cos2*(dm3-dm1)*dm3*dm1 + cos3*(dm1-dm2)*dm1*dm2;
144 
145  Float_t denom = (dm2-dm3)*(dm3-dm1)*(dm1-dm2);
146 
147  return (denom != 0.0) ? (-a*dm*dm+b*dm-c)/denom : 0.0;
148 }
149 
150 
float Float_t
Definition: RtypesCore.h:53
virtual void BuildCoeff(void)
no coefficients to precompute
Definition: TSpline2.cxx:120
Basic string class.
Definition: TString.h:137
TGraph * fGraph
Definition: TSpline2.h:60
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
Double_t x[n]
Definition: legend1.C:17
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const
no knots
Definition: TSpline2.cxx:127
virtual Double_t Eval(Double_t x) const
returns quadratically interpolated TGraph entry around x
Definition: TSpline2.cxx:60
double Double_t
Definition: RtypesCore.h:55
virtual ~TSpline2(void)
destructor
Definition: TSpline2.cxx:52
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:138
Abstract ClassifierFactory template that handles arbitrary types.
ClassImp(TMVA::TSpline2) TMVA
constructor from TGraph TSpline is a TNamed object
Definition: TSpline2.cxx:37
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:944