Changeset 9424 for trunk


Ignore:
Timestamp:
04/16/09 11:47:17 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MSpline3.cc

    r9312 r9424  
    132132}
    133133
     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//
     158Double_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//
     172Double_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//
     185Double_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//
     204Double_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//
     220Double_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
    134239// FIXME: As soon as TSpline3 allows access to fPoly we can implement
    135240//        a much faster evaluation of the spline, especially in
  • trunk/MagicSoft/Mars/mbase/MSpline3.h

    r9367 r9424  
    1414    TGraph  *ConvertGraph(const TGraph &s, Float_t freq) const;
    1515    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;
    1619
    1720public:
     
    4952    MSpline3(const TF1 &f, Double_t freq, const char *opt=0,Double_t valbeg=0, Double_t valend=0);
    5053
    51    Double_t GetXmin() const { return fXmin; }     // Minimum value of abscissa
    52    Double_t GetXmax() const { return fXmax; }     // Maximum value of abscissa
     54    Double_t GetXmin() const { return fXmin; }     // Minimum value of abscissa
     55    Double_t GetXmax() const { return fXmax; }     // Maximum value of abscissa
    5356
    54    Int_t GetNp() const { return fNp; }
     57    Int_t GetNp() const { return fNp; }
    5558
    56    TH1 *GetHistogram() const { return (TH1*)fHistogram; }
     59    TH1 *GetHistogram() const { return (TH1*)fHistogram; }
    5760
    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
    5967};
    6068
Note: See TracChangeset for help on using the changeset viewer.