Ignore:
Timestamp:
10/16/06 18:02:31 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.h

    r7942 r8072  
    55#include <TROOT.h>
    66#endif
     7
     8class TH1;
     9class TH2;
     10class TH1F;
     11class TH2F;
     12class TArrayF;
    713
    814class MExtralgoDigitalFilter
     
    1319    Int_t    fNum;
    1420
    15     Float_t *fWeightsAmp;
    16     Float_t *fWeightsTime;
     21    Float_t const *fWeightsAmp;
     22    Float_t const *fWeightsTime;
    1723
    18     Int_t   fWeightsPerBin; // Number of weights per data bin
     24    const Int_t fWeightsPerBin; // Number of weights per data bin
     25    const Int_t fWindowSize;
    1926
    2027    // Result
     
    2431    Float_t fSignalDev;
    2532
    26     inline void Eval(Double_t &sumamp, Double_t &sumtime, const Int_t windowsize, const Int_t startv, const Int_t startw=0) const
     33    // Weights: Weights to evaluate
     34    // Startv: Index of first bin of data
     35    // startw: Offset on the weights
     36    inline Double_t Eval(Float_t const *weights, const Int_t startv, const Int_t startw=0) const
    2737    {
    2838        //
     
    3040        // and multiply the entries with the corresponding weights
    3141        //
    32         sumamp = 0;
    33         sumtime = 0;
     42        Double_t sum = 0;
    3443
    3544        // Shift the start of the weight to the center of sample 0
    36         Float_t const *wa  = fWeightsAmp  + fWeightsPerBin/2 + startw;
    37         Float_t const *wt  = fWeightsTime + fWeightsPerBin/2 + startw;
     45        Float_t const *w = weights + startw;
     46
    3847        Float_t *const beg = fVal+startv;
     48        for (Float_t const *pex=beg; pex<beg+fWindowSize; pex++)
     49        {
     50            sum += *w * *pex;
     51            w += fWeightsPerBin;
     52        }
     53        return sum;
     54    }
    3955
    40         for (Float_t const *pex=beg; pex<beg+windowsize; pex++)
     56    inline void AlignIntoLimits(Int_t &maxp, Int_t &frac) const
     57    {
     58        // Align maxp into available range (TO BE CHECKED)
     59        if (maxp < 0)
    4160        {
    42             sumamp  += *wa * *pex;
    43             sumtime += *wt * *pex;
    44 
    45             // Step forward by one bin
    46             wa += fWeightsPerBin;
    47             wt += fWeightsPerBin;
     61            maxp = 0;
     62            frac = fWeightsPerBin/2-1; // Assume peak at the end of the last slice
     63        }
     64        if (maxp > fNum-fWindowSize)
     65        {
     66            maxp = fNum-fWindowSize;
     67            frac = -fWeightsPerBin/2; // Assume peak at the beginning of the first slice
    4868        }
    4969    }
    5070
     71    inline Int_t AlignExtractionWindow(Int_t &maxp, Int_t &frac, const Double_t ampsum)
     72    {
     73        // Align extraction window to signal position
     74
     75        const Double_t timesum = Eval(fWeightsTime, maxp, frac);
     76
     77        // Because fWeightsPerBin/2 doesn't correspond to the center
     78        // of a bin the time-values extracted are slightly positive.
     79        // They are roughly between -0.45 and 0.55
     80        const Double_t binoffset = TMath::Even(fWeightsPerBin) ? 0.5 : 0;
     81
     82        // This is the time offset from the extraction position
     83        Double_t tmoffset = (frac+binoffset)/fWeightsPerBin + timesum/ampsum;
     84
     85        // Convert the residual fraction of one slice into an
     86        // offset position in the extraction weights
     87        const Int_t integ = TMath::FloorNint(tmoffset+0.5);
     88
     89        /*
     90        if (integ>0)
     91            tmoffset=0.49-0.05;
     92        if (integ<0)
     93            tmoffset=-0.49-0.05;
     94        integ=0;
     95        */
     96
     97        // move the extractor by an offset number of slices
     98        // determined by the extracted time
     99        maxp -= integ;
     100
     101        frac  = TMath::FloorNint((tmoffset-integ)*fWeightsPerBin);
     102
     103        // Align maxp into available range (TO BE CHECKED)
     104        AlignIntoLimits(maxp, frac);
     105
     106        return integ;
     107    }
     108
     109    inline void AlignExtractionWindow(Int_t &maxp, Int_t &frac)
     110    {
     111        const Double_t amp = Eval(fWeightsAmp, maxp, frac);
     112        if (amp!=0)
     113            AlignExtractionWindow(maxp, frac, amp);
     114    }
     115
    51116public:
    52     MExtralgoDigitalFilter(Float_t *val, Int_t n, Float_t *wa, Float_t *wt)
    53         : fVal(val), fNum(n),
    54         fWeightsAmp(wa), fWeightsTime(wt), fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1)
     117    MExtralgoDigitalFilter(Int_t res, Int_t windowsize, Float_t *wa, Float_t *wt)
     118        : fVal(0), fNum(0), fWeightsAmp(wa+res/2), fWeightsTime(wt+res/2),
     119        fWeightsPerBin(res), fWindowSize(windowsize),
     120        fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1)
    55121    {
    56122    }
    57123
    58     void SetWeightsPerBin(Int_t res) { fWeightsPerBin=res; }
     124    void SetData(Int_t n, Float_t *val) { fNum=n; fVal=val; }
    59125
    60126    Float_t GetTime() const          { return fTime; }
     
    67133    void GetTime(Float_t &sig, Float_t &dsig) const   { sig=fTime; dsig=fTimeDev; }
    68134
    69     Float_t ExtractNoise(Int_t iter, Int_t windowsize) const;
    70     void Extract(Int_t windowsize, Float_t timeshift);
     135    Float_t ExtractNoise(Int_t iter) const;
     136    void Extract();
     137
     138    static Bool_t CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1);
     139    static void CalculateWeights2(TH1F &shape, const TH2F &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1);
    71140};
    72141
Note: See TracChangeset for help on using the changeset viewer.