Changeset 9312 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 02/10/09 20:00:10 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MSpline3.cc
r9229 r9312 38 38 #include <TF1.h> 39 39 40 #include "MArrayD.h" 41 40 42 ClassImp(MSpline3); 41 43 … … 48 50 MSpline3::MSpline3(const TF1 &f, const char *opt, Double_t valbeg, Double_t valend) 49 51 : TSpline3("MSpline3", f.GetXmin(), f.GetXmax(), &f, f.GetNpx(), opt, valbeg, valend) 52 { 53 } 54 55 MSpline3::MSpline3(const TF1 &f, Double_t freq, const char *opt,Double_t valbeg, Double_t valend) 56 : TSpline3("MSpline3", f.GetXmin()*freq, f.GetXmax()*freq, ConvertFunc(f, freq).GetArray(), f.GetNpx(), opt, valbeg, valend) 50 57 { 51 58 } … … 105 112 // a discrete binning is done similar to the constructor of TSpline 106 113 // 107 TGraph *MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const114 MArrayD &MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const 108 115 { 109 116 const UInt_t npx = f.GetNpx(); … … 111 118 // WARNING: This is a stupid workaround because the TSpline3- 112 119 // constructor takes a pointer as input! It is not thread-safe! 113 static TGraphg;120 static MArrayD g; 114 121 g.Set(npx); 115 122 … … 119 126 { 120 127 const Double_t x = f.GetXmin() + i*step; 121 g .SetPoint(i, x*freq, f.Eval(x));128 g[i] = f.Eval(x); 122 129 } 123 130 124 return &g;131 return g; 125 132 } 133 134 // FIXME: As soon as TSpline3 allows access to fPoly we can implement 135 // a much faster evaluation of the spline, especially in 136 // special conditions like in MAnalogSignal::AddPulse 137 // This will be the case for root > 5.22/00 138 139 /* 140 Double_t MSpline3::EvalFast(Double_t x) const 141 { 142 // Eval this spline at x 143 const Int_t klow=FindFast(x); 144 return fPoly[klow].Eval(x); 145 } 146 147 Int_t MSpline3::FindFast(Double_t x) const 148 { 149 // 150 // If out of boundaries, extrapolate 151 // It may be badly wrong 152 153 // if (x<=fXmin) 154 // return 0; 155 // 156 // if (x>=fXmax) 157 // return fNp-1; 158 159 // 160 // Equidistant knots, use histogramming 161 if (fKstep) 162 return TMath::Min(Int_t((x-fXmin)/fDelta),fNp-1); 163 164 // 165 // Non equidistant knots, binary search 166 Int_t klow = 0; 167 Int_t khig = fNp-1; 168 169 Int_t khalf; 170 while (khig-klow>1) 171 if(x>fPoly[khalf=(klow+khig)/2].X()) 172 klow=khalf; 173 else 174 khig=khalf; 175 176 // This could be removed, sanity check 177 //if(!(fPoly[klow].X()<=x && x<=fPoly[klow+1].X())) 178 // Error("Eval", 179 // "Binary search failed x(%d) = %f < %f < x(%d) = %f\n", 180 // klow,fPoly[klow].X(),x,fPoly[klow+1].X()); 181 182 return klow; 183 } 184 */ -
trunk/MagicSoft/Mars/mbase/MSpline3.h
r9229 r9312 6 6 #endif 7 7 8 class MArrayD; 9 8 10 class MSpline3 : public TSpline3 9 11 { 10 12 private: 11 TGraph *ConvertSpline(const TSpline &s, Float_t freq) const;12 TGraph *ConvertGraph(const TGraph &s, Float_t freq) const;13 TGraph *ConvertFunc(const TF1 &f, Float_t freq) const;13 TGraph *ConvertSpline(const TSpline &s, Float_t freq) const; 14 TGraph *ConvertGraph(const TGraph &s, Float_t freq) const; 15 MArrayD &ConvertFunc(const TF1 &f, Float_t freq) const; 14 16 15 17 public: 16 MSpline3(const TGraph &g, 17 const char *opt=0, Double_t valbeg=0, Double_t valend=0) 18 : TSpline3("MSpline3", &g, opt, valbeg, valend) 19 { 20 } 18 MSpline3() { } 21 19 22 MSpline3(const TGraph &g, Double_t freq, 23 const char *opt=0, Double_t valbeg=0, Double_t valend=0) 24 : TSpline3("MSpline3", ConvertGraph(g, freq), opt, valbeg, valend) 25 { 26 } 20 // None equidistant binning (evaluation a bit slower in case of many bins) 21 MSpline3(const TGraph &g, 22 const char *opt=0, Double_t valbeg=0, Double_t valend=0) 23 : TSpline3("MSpline3", &g, opt, valbeg, valend) 24 { 25 } 27 26 28 MSpline3(const TSpline &s, Double_t freq, 29 const char *opt=0, Double_t valbeg=0, Double_t valend=0) 30 : TSpline3("MSpline3", ConvertSpline(s, freq), opt, valbeg, valend) 31 { 32 } 33 /* 34 MSpline3(Double_t xmin, Double_t xmax, 35 const TF1 *func, Int_t n, const char *opt=0, 36 Double_t valbeg=0, Double_t valend=0) 37 : TSpline3("MSpline3", xmin, xmax, func, n, opt, valbeg, valend) 38 { 39 }*/ 40 MSpline3(const TF1 &f, const char *opt=0,Double_t valbeg=0, Double_t valend=0); 27 MSpline3(const TGraph &g, Double_t freq, 28 const char *opt=0, Double_t valbeg=0, Double_t valend=0) 29 : TSpline3("MSpline3", ConvertGraph(g, freq), opt, valbeg, valend) 30 { 31 } 41 32 42 MSpline3(const TF1 &f, Double_t freq,43 const char *opt=0,Double_t valbeg=0, Double_t valend=0)44 : TSpline3("MSpline3", ConvertFunc(f, freq), opt, valbeg, valend)45 {46 }33 MSpline3(const TSpline &s, Double_t freq, 34 const char *opt=0, Double_t valbeg=0, Double_t valend=0) 35 : TSpline3("MSpline3", ConvertSpline(s, freq), opt, valbeg, valend) 36 { 37 } 47 38 48 MSpline3(const Double_t x[], const Double_t y[], Int_t n, const char *opt=0, 49 Double_t valbeg=0, Double_t valend=0) 50 : TSpline3("MSpline3", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n, opt, valbeg, valend) 51 { 52 } 39 MSpline3(const Double_t x[], const Double_t y[], Int_t n, const char *opt=0, 40 Double_t valbeg=0, Double_t valend=0) 41 : TSpline3("MSpline3", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n, opt, valbeg, valend) 42 { 43 } 44 45 // Equidistant binning (evaluation a bit faster in case of many bins) 46 47 // FIXME: In principle TF1 can be evaluated histogram like which should be faster 48 MSpline3(const TF1 &f, const char *opt=0,Double_t valbeg=0, Double_t valend=0); 49 MSpline3(const TF1 &f, Double_t freq, const char *opt=0,Double_t valbeg=0, Double_t valend=0); 53 50 54 51 Double_t GetXmin() const { return fXmin; } // Minimum value of abscissa … … 57 54 Int_t GetNp() const { return fNp; } 58 55 56 TH1 *GetHistogram() const { return fHistogram; } 57 59 58 ClassDef(MSpline3, 1) // An extension of the TSpline3 60 59 };
Note:
See TracChangeset
for help on using the changeset viewer.