Ignore:
Timestamp:
02/10/09 20:00:10 (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

    r9229 r9312  
    3838#include <TF1.h>
    3939
     40#include "MArrayD.h"
     41
    4042ClassImp(MSpline3);
    4143
     
    4850MSpline3::MSpline3(const TF1 &f, const char *opt, Double_t valbeg, Double_t valend)
    4951    : TSpline3("MSpline3", f.GetXmin(), f.GetXmax(), &f, f.GetNpx(), opt, valbeg, valend)
     52{
     53}
     54
     55MSpline3::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)
    5057{
    5158}
     
    105112// a discrete binning is done similar to the constructor of TSpline
    106113//
    107 TGraph *MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const
     114MArrayD &MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const
    108115{
    109116    const UInt_t npx = f.GetNpx();
     
    111118    // WARNING: This is a stupid workaround because the TSpline3-
    112119    // constructor takes a pointer as input! It is not thread-safe!
    113     static TGraph g;
     120    static MArrayD g;
    114121    g.Set(npx);
    115122
     
    119126    {
    120127        const Double_t x = f.GetXmin() + i*step;
    121         g.SetPoint(i, x*freq, f.Eval(x));
     128        g[i] = f.Eval(x);
    122129    }
    123130
    124     return &g;
     131    return g;
    125132}
     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/*
     140Double_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
     147Int_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  
    66#endif
    77
     8class MArrayD;
     9
    810class MSpline3 : public TSpline3
    911{
    1012private:
    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;
    1416
    1517public:
    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() { }
    2119
    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    }
    2726
    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    }
    4132
    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    }
    4738
    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);
    5350
    5451   Double_t GetXmin() const { return fXmin; }     // Minimum value of abscissa
     
    5754   Int_t GetNp() const { return fNp; }
    5855
     56   TH1 *GetHistogram() const { return fHistogram; }
     57
    5958   ClassDef(MSpline3, 1) // An extension of the TSpline3
    6059};
Note: See TracChangeset for help on using the changeset viewer.