ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "TMVA/TSpline2.h"
34 
35 #include "TGraph.h"
36 #include "TMath.h"
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// constructor from TGraph
42 /// TSpline is a TNamed object
43 
44 TMVA::TSpline2::TSpline2( const TString& title, TGraph* theGraph )
45  : fGraph( theGraph ) // not owned by TSpline2
46 {
47  SetNameTitle( title, title );
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// destructor
52 
54 {
55  if (fGraph) delete fGraph; // ROOT's spline classes also own the TGraph
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// returns quadratically interpolated TGraph entry around x
60 
62 {
63  Double_t retval=0;
64 
65  Int_t ibin = TMath::BinarySearch( fGraph->GetN(),
66  fGraph->GetX(),
67  x );
68 
69  // sanity checks
70  if (ibin < 0 ) ibin = 0;
71  if (ibin >= fGraph->GetN()) ibin = fGraph->GetN() - 1;
72 
73  Float_t dx = 0; // should be zero
74 
75  if (ibin == 0 ) {
76 
77  retval = Quadrax( x,
78  fGraph->GetX()[ibin] + dx,
79  fGraph->GetX()[ibin+1] + dx,
80  fGraph->GetX()[ibin+2] + dx,
81  fGraph->GetY()[ibin],
82  fGraph->GetY()[ibin+1],
83  fGraph->GetY()[ibin+2]);
84 
85  }
86  else if (ibin >= (fGraph->GetN()-2)) {
87  ibin = fGraph->GetN() - 1; // always fixed to last bin
88 
89  retval = Quadrax( x,
90  fGraph->GetX()[ibin-2] + dx,
91  fGraph->GetX()[ibin-1] + dx,
92  fGraph->GetX()[ibin] + dx,
93  fGraph->GetY()[ibin-2],
94  fGraph->GetY()[ibin-1],
95  fGraph->GetY()[ibin]);
96  }
97  else {
98 
99  retval = ( Quadrax( x,
100  fGraph->GetX()[ibin-1] + dx,
101  fGraph->GetX()[ibin] + dx,
102  fGraph->GetX()[ibin+1] + dx,
103  fGraph->GetY()[ibin-1],
104  fGraph->GetY()[ibin],
105  fGraph->GetY()[ibin+1])
106  +
107  Quadrax( x, fGraph->GetX()[ibin] + dx,
108  fGraph->GetX()[ibin+1] + dx,
109  fGraph->GetX()[ibin+2] + dx,
110  fGraph->GetY()[ibin],
111  fGraph->GetY()[ibin+1],
112  fGraph->GetY()[ibin+2]) )*0.5;
113  }
114 
115  return retval;
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// no coefficients to precompute
120 
122 {
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// no knots
127 
128 void TMVA::TSpline2::GetKnot( Int_t /*i*/, Double_t& /*x*/, Double_t& /*y*/ ) const
129 {
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// quadratic interpolation
134 /// Revised and checked by Francois Nov, 16th, 2000
135 /// Note the beautiful non-spontaneous symmetry breaking ...
136 /// It was checked that the old routine gave exactly the same answers.
137 ///
138 
139 Double_t TMVA::TSpline2::Quadrax( const Float_t dm,const Float_t dm1,const Float_t dm2,const Float_t dm3,
140  const Float_t cos1, const Float_t cos2, const Float_t cos3 ) const
141 {
142  Float_t a = cos1*(dm2-dm3) + cos2*(dm3-dm1) + cos3*(dm1-dm2);
143  Float_t b = cos1*(dm2*dm2-dm3*dm3) + cos2*(dm3*dm3-dm1*dm1) + cos3*(dm1*dm1-dm2*dm2);
144  Float_t c = cos1*(dm2-dm3)*dm2*dm3 + cos2*(dm3-dm1)*dm3*dm1 + cos3*(dm1-dm2)*dm1*dm2;
145 
146  Float_t denom = (dm2-dm3)*(dm3-dm1)*(dm1-dm2);
147 
148  return (denom != 0.0) ? (-a*dm*dm+b*dm-c)/denom : 0.0;
149 }
150 
151 
float Float_t
Definition: RtypesCore.h:53
return c
virtual void BuildCoeff(void)
no coefficients to precompute
Definition: TSpline2.cxx:121
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:128
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual Double_t Eval(Double_t x) const
returns quadratically interpolated TGraph entry around x
Definition: TSpline2.cxx:61
double Double_t
Definition: RtypesCore.h:55
virtual ~TSpline2(void)
destructor
Definition: TSpline2.cxx:53
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:139
ClassImp(TMVA::TSpline2) TMVA
constructor from TGraph TSpline is a TNamed object
Definition: TSpline2.cxx:38
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