- Timestamp:
- 04/16/09 11:47:17 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MSpline3.cc
r9312 r9424 132 132 } 133 133 134 // -------------------------------------------------------------------------- 135 // 136 // Return the integral in the splines bin i up to x. 137 // 138 // The TSpline3 in the Interval [fX[i], fX[i+1]] is defined as: 139 // 140 // dx = x-fX[i] 141 // y = fY + dx*fB + dx*dx*fC + dx*dx*dx*fD 142 // 143 // This yields the integral: 144 // 145 // int(y) = dx*fY + 1/2*dx*dx*fB + 1/3*dx*dx*dx*fC + 1/4*dx*dx*dx*dx*fD 146 // = dx*(fY + dx*(1/2*fB + dx*(1/3*fC + dx*(1/4*fD)))) 147 // 148 // Which gives for the integral range [fX[i], fX[i]+w]: 149 // int(fX[i]+w)-int(fX[i]) = w*(fY + w*(1/2*fB + w*(1/3*fC + w*(1/4*fD)))) 150 // 151 // and for the integral range [fX[i]+w, fX[i+1]]: 152 // int(fX[i+1])-int(fX[i]+w) = ` 153 // W*(fY + W*(1/2*fB + W*(1/3*fC + W*(1/4*fD)))) - 154 // w*(fY + w*(1/2*fB + w*(1/3*fC + w*(1/4*fD)))) 155 // with 156 // W := fX[i+1]-fX[i] 157 // 158 Double_t MSpline3::Integral(Int_t i, Double_t x) const 159 { 160 Double_t x0, y, b, c, d; 161 const_cast<MSpline3*>(this)->GetCoeff(i, x0, y, b, c, d); 162 163 const Double_t w = x-x0; 164 165 return w*(y + w*(b/2 + w*(c/3 + w*d/4))); 166 } 167 168 // -------------------------------------------------------------------------- 169 // 170 // Return the integral of the spline's bin i. 171 // 172 Double_t MSpline3::Integral(Int_t i) const 173 { 174 Double_t x, y; 175 176 GetKnot(i+1, x, y); 177 178 return Integral(i, x); 179 } 180 181 // -------------------------------------------------------------------------- 182 // 183 // Return the integral from a to b 184 // 185 Double_t MSpline3::Integral(Double_t a, Double_t b) const 186 { 187 const Int_t n = FindX(a); 188 const Int_t m = FindX(b); 189 190 Double_t sum = -Integral(n, a); 191 192 for (int i=n; i<=m-1; i++) 193 sum += Integral(i); 194 195 sum += Integral(m, b); 196 197 return sum; 198 } 199 200 // -------------------------------------------------------------------------- 201 // 202 // Return the integral between Xmin and Xmax 203 // 204 Double_t MSpline3::Integral() const 205 { 206 Double_t sum = 0; 207 208 for (int i=0; i<GetNp()-1; i++) 209 sum += Integral(i); 210 211 return sum; 212 } 213 214 // -------------------------------------------------------------------------- 215 // 216 // Return the integral between Xmin and Xmax of int( f(x)*sin(x) ) 217 // 218 // The x-axis is assumed to be in degrees 219 // 220 Double_t MSpline3::IntegralSolidAngle() const 221 { 222 const Int_t n = GetNp(); 223 224 MArrayD x(n); 225 MArrayD y(n); 226 227 for (int i=0; i<n; i++) 228 { 229 GetKnot(i, x[i], y[i]); 230 231 x[i] *= TMath::DegToRad(); 232 y[i] *= TMath::Sin(x[i]); 233 } 234 235 return TMath::TwoPi()*MSpline3(x.GetArray(), y.GetArray(), n).Integral(); 236 } 237 238 134 239 // FIXME: As soon as TSpline3 allows access to fPoly we can implement 135 240 // a much faster evaluation of the spline, especially in -
trunk/MagicSoft/Mars/mbase/MSpline3.h
r9367 r9424 14 14 TGraph *ConvertGraph(const TGraph &s, Float_t freq) const; 15 15 MArrayD &ConvertFunc(const TF1 &f, Float_t freq) const; 16 17 Double_t Integral(Int_t i, Double_t x) const; 18 Double_t Integral(Int_t i) const; 16 19 17 20 public: … … 49 52 MSpline3(const TF1 &f, Double_t freq, const char *opt=0,Double_t valbeg=0, Double_t valend=0); 50 53 51 Double_t GetXmin() const { return fXmin; } // Minimum value of abscissa52 Double_t GetXmax() const { return fXmax; } // Maximum value of abscissa54 Double_t GetXmin() const { return fXmin; } // Minimum value of abscissa 55 Double_t GetXmax() const { return fXmax; } // Maximum value of abscissa 53 56 54 Int_t GetNp() const { return fNp; }57 Int_t GetNp() const { return fNp; } 55 58 56 TH1 *GetHistogram() const { return (TH1*)fHistogram; }59 TH1 *GetHistogram() const { return (TH1*)fHistogram; } 57 60 58 ClassDef(MSpline3, 1) // An extension of the TSpline3 61 Double_t Integral(Double_t a, Double_t b) const; 62 Double_t Integral() const; 63 64 Double_t IntegralSolidAngle() const; 65 66 ClassDef(MSpline3, 1) // An extension of the TSpline3 59 67 }; 60 68
Note:
See TracChangeset
for help on using the changeset viewer.