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