Changeset 8154


Ignore:
Timestamp:
10/24/06 09:26:10 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
3 added
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Makefile

    r8032 r8154  
    4545          mhist \
    4646          manalysis \
     47          mextralgo \
    4748          msignal \
    4849          mbadpixels \
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.cc

    r8072 r8154  
    3838}
    3939
     40// -----------------------------------------------------------------------------
     41//
     42// Calculates the chi2 of the fit, once the weights have been iterated.
     43// Argument: time, obtained after a call to EvalDigitalFilterHiGain
     44//
     45Float_t MExtralgoDigitalFilter::GetChisq(const Int_t maxp, const Int_t frac, const Float_t sum) const
     46{
     47    /*
     48    TMatrix g (windowh,1);
     49    TMatrix gt(windowh,1);
     50    TMatrix y (windowh,1);
     51
     52    const Float_t etau   = fFineAdjustHi*sumhi;
     53    const Float_t t_fine = TMath::Abs(fFineAdjustHi)< 1./fBinningResolutionHiGain ? -fFineAdjustHi : 0.;
     54
     55    //   if (t_fine==0.)
     56    //     return -1.;
     57
     58    if (fDebug)
     59        gLog << all << " fMaxPHi: " << fMaxPHi << " fIterPHi " << fIterPHi << " t_fine: " << t_fine << endl;
     60
     61    //
     62    // Slide with a window of size windowh over the sample
     63    // and calculate the arrays by interpolating the pulse shape using the
     64    // fine-tuned time information.
     65    //
     66    for (Int_t sample=0; sample &lt; windowh; sample++)
     67    {
     68        const Int_t idx = fArrBinningResHalfHiGain[sample] + fIterPHi;
     69        const Int_t ids = fMaxPHi + sample;
     70
     71        y [sample][0]     = fHiGainSignalDF[ids];
     72        g [sample][0]     = t_fine >= 0
     73            ? (fPulseShapeHiGain[idx]    + t_fine*(fPulseShapeHiGain[idx+1]   -fPulseShapeHiGain[idx])  )*sumhi
     74            : (fPulseShapeHiGain[idx]    + t_fine*(fPulseShapeHiGain[idx]     -fPulseShapeHiGain[idx-1]))*sumhi;
     75        gt[sample][0]     = t_fine >= 0
     76            ? (fPulseShapeDotHiGain[idx] + t_fine*(fPulseShapeDotHiGain[idx+1]-fPulseShapeDotHiGain[idx])   )*etau
     77            : (fPulseShapeDotHiGain[idx] + t_fine*(fPulseShapeDotHiGain[idx]  -fPulseShapeDotHiGain[idx-1]) )*etau;
     78    }
     79
     80    TMatrix second = y - g - gt;
     81    TMatrix first(TMatrix::kTransposed,second);
     82    TMatrix chisq = first * ((*fBHiInv)*second);
     83
     84    return chisq[0][0]/(windowh-2);
     85    */
     86/*
     87
     88    TMatrix S(fWindowSize, 1); // Signal (start==start of window)
     89    for (int i=0; i<fWindowSize; i++)
     90        S[i][0] = fVal[i+maxp];
     91
     92    TMatrix g(fWindowSize, 1);
     93    //TMatrix gT(fWindowSize, 1);
     94
     95    for (int i=0; i<fWindowSize; i++)
     96    {
     97        Int_t idx = fWeightsPerBin*i + frac;
     98
     99        // FIXME: Maybe we could do an interpolation on time-fineadj?
     100        //Float_t slope  = fPulseShapeHiGain[idx+1]   -fPulseShapeHiGain[idx];
     101        //Float_t slopet = fPulseShapeDotHiGain[idx+1]-fPulseShapeDotHiGain[idx];
     102
     103        g[i][0] = fPulseShapeHiGain[idx]   *sumhi;
     104        //gT[i][0] = fPulseShapeHiGainDot[idx]*tau;
     105    }
     106
     107    TMatrix Ainv; // Autocorrelation Matrix (inverted)
     108
     109    TMatrix m = S - g;// - gT;
     110    TMatrix mT(TMatrix::kTransposed, m);
     111
     112    TMatrix chisq = mT * (Ainv*m);
     113
     114    return chisq[0][0]/(fWindowSize-2);
     115  */
     116
     117    Double_t sumc = 0;
     118
     119    TMatrix d(fWindowSize, 1); // Signal (start==start of window)
     120    for (int i=0; i<fWindowSize; i++)
     121    {
     122        d[i][0] = fVal[i+maxp]/sum - fPulseShape[fWeightsPerBin*i + frac];
     123        sumc += d[i][0]*d[i][0];
     124    }
     125
     126/*
     127    TMatrix Ainv; // Autocorrelation Matrix (inverted)
     128
     129    TMatrix dT(TMatrix::kTransposed, d);
     130
     131    TMatrix chisq = dT * (*fAinv*d);
     132  */
     133    return sumc;//chisq[0][0]/(fWindowSize-2);
     134}
     135
    40136#include <iostream>
    41 void MExtralgoDigitalFilter::Extract()
     137void MExtralgoDigitalFilter::Extract(Int_t maxpos)
    42138{
    43139    fSignal    =  0; // default is: no pulse found
     
    54150    // Calculate the sum of the first fWindowSize slices
    55151    //
    56 
    57     // For the case of an even numberof weights/bin there is
     152    // For the case of an even number of weights/bin there is
    58153    // no central bin.So we create an artificial central bin.
    59154    for (Int_t i=0; i<fNum-fWindowSize+1; i++)
     
    66161        }
    67162    }
     163
     164    /*
     165     // This could be for a fast but less accurate extraction....
     166     maxamp = Eval(fWeightsAmp, maxpos-fWindowSize/2);
     167     maxp   = maxpos-fWindowSize/2;
     168     */
     169
    68170    // The number of available slices were smaller than the
    69171    // extraction window size of the extractor
     
    136238        fTime -= timefineadjust;
    137239}
     240
    138241
    139242#include <TH1.h>
     
    145248#include <TProfile.h>
    146249
    147 Bool_t MExtralgoDigitalFilter::CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb)
     250Int_t MExtralgoDigitalFilter::CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb)
    148251{
    149252    const Int_t weightsperbin = wpb<=0?shape.GetNbinsX()/autocorr.GetNbinsX():wpb;
     
    154257        cout << "        Shape: " << shape.GetNbinsX() << endl;
    155258        cout << "        ACorr: " << autocorr.GetNbinsX() << endl;
    156         return kFALSE;
     259        return -1;
    157260    }
    158261
     
    180283    // FIXME: DELETE!!!
    181284    TH1 &derivative = *static_cast<TH1*>(shape.Clone());
     285    derivative.SetDirectory(0);
    182286    derivative.Reset();
    183287
     
    233337        {
    234338            cout << "ERROR - Division by zero: denom[0][0]==0 for i=" << i << "." << endl;
    235             return kFALSE;
     339            return -1;
    236340        }
    237341
     
    248352    }
    249353
    250     return kTRUE;
     354    return first*weightsperbin;
    251355}
    252356
    253 void MExtralgoDigitalFilter::CalculateWeights2(TH1F &shape, const TH2F &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb)
     357Int_t MExtralgoDigitalFilter::CalculateWeights2(TH1 &shape, const TH2 &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb)
    254358{
    255359    const Int_t weightsperbin = wpb<=0?shape.GetNbinsX()/autocorr.GetNbinsX():wpb;
     
    260364        cout << "        Shape: " << shape.GetNbinsX() << endl;
    261365        cout << "        ACorr: " << autocorr.GetNbinsX() << endl;
    262         return;
     366        return -1;
    263367    }
    264368
     
    282386    TSpline5 val("Signal", &gr);
    283387
    284     TH1F derivative(shape);
     388    // FIXME: DELETE!!!
     389    TH1 &derivative = *static_cast<TH1*>(shape.Clone());
     390    derivative.SetDirectory(0);
    285391    derivative.Reset();
    286392
     
    331437        const TMatrixD denom  = (gT*(B*g))*(dT*(B*d)) - (dT*(B*g))*(dT*(B*g));
    332438
     439        if (denom[0][0]==0)
     440        {
     441            cout << "ERROR - Division by zero: denom[0][0]==0 for i=" << i << "." << endl;
     442            return -1;
     443        }
     444
    333445        const TMatrixD w_amp  = (dT*(B*d))*(gT*B) - (gT*(B*d))*(dT*B);
    334446        const TMatrixD w_time = (gT*(B*g))*(dT*B) - (gT*(B*d))*(gT*B);
     
    342454        }
    343455    }
     456    return first*weightsperbin;
    344457}
    345 /*
    346 Int_t start = fBinningResolutionHiGain*(fSignalStartBinHiGain + 1);
    347 for (Int_t i = -fBinningResolutionHiGain/2+1; i<=fBinningResolutionHiGain/2; i++)
    348 {
    349     // i = -4...5
    350     for (Int_t count=0; count < fWindowSizeHiGain; count++)
    351     {
    352         // count=0: pos=10*(start+0) + 10 + i
    353         // count=1: pos=10*(start+1) + 10 + i
    354         // count=2: pos=10*(start+2) + 10 + i
    355         // count=3: pos=10*(start+3) + 10 + i
    356     }
    357 
    358     for (Int_t count=0; count < fWindowSizeHiGain; count++)
    359     {
    360         // count=0: pos = 10*0 + 5 +i-1
    361         // count=1: pos = 10*1 + 5 +i-1
    362         // count=2: pos = 10*2 + 5 +i-1
    363         // count=3: pos = 10*3 + 5 +i-1
    364     }
    365 }
    366 
    367 Int_t start = fBinningResolutionLoGain*fSignalStartBinLoGain + fBinningResolutionLoGain/2;
    368 for (Int_t i = -fBinningResolutionLoGain/2+1; i<=fBinningResolutionLoGain/2; i++)
    369 {
    370     // i=-4..5
    371     for (Int_t count=0; count < fWindowSizeLoGain; count++)
    372     {
    373         // count=0: pos = 10*(start+0) + 5 + i
    374         // count=1: pos = 10*(start+1) + 5 + i
    375         // count=2: pos = 10*(start+2) + 5 + i
    376         // count=3: pos = 10*(start+3) + 5 + i
    377     }
    378 
    379     for (Int_t count=0; count < fWindowSizeLoGain; count++)
    380     {
    381         // count=0: pos = 10*0 + 5 +i-1
    382         // count=1: pos = 10*1 + 5 +i-1
    383         // count=2: pos = 10*2 + 5 +i-1
    384         // count=3: pos = 10*3 + 5 +i-1
    385     }
    386 }
    387 */
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.h

    r8072 r8154  
    22#define MARS_MExtralgoDigitalFilter
    33
    4 #ifndef ROOT_TROOT
    5 #include <TROOT.h>
     4#ifndef ROOT_TMatrix
     5#include <TMatrix.h>
    66#endif
    77
     
    1212class TArrayF;
    1313
     14//#include <TMatrix.h>
     15
    1416class MExtralgoDigitalFilter
    1517{
    1618private:
    1719    // Input
    18     Float_t *fVal;
    19     Int_t    fNum;
     20    const Float_t *fVal;
     21    Int_t fNum;
    2022
    2123    Float_t const *fWeightsAmp;
    2224    Float_t const *fWeightsTime;
     25    Float_t const *fPulseShape;
     26
     27    const TMatrix *fAinv;
    2328
    2429    const Int_t fWeightsPerBin; // Number of weights per data bin
     
    3035    Float_t fSignal;
    3136    Float_t fSignalDev;
     37
     38    Float_t GetChisq(const Int_t maxp, const Int_t frac, const Float_t sum) const;
     39
     40    inline Double_t ChiSq(const Double_t sum, const Int_t startv, const Int_t startw=0) const
     41    {
     42        //
     43        // Slide with a window of size windowsize over the sample
     44        // and multiply the entries with the corresponding weights
     45        //
     46        Double_t chisq = 0;
     47
     48        // Shift the start of the weight to the center of sample 0
     49        Float_t const *w = fPulseShape + startw;
     50
     51        const Float_t *beg = fVal+startv;
     52        for (Float_t const *pex=beg; pex<beg+fWindowSize; pex++)
     53        {
     54            const Double_t c = *w - *pex/sum;
     55            chisq += c*c;
     56            w += fWeightsPerBin;
     57        }
     58        return chisq;
     59    }
    3260
    3361    // Weights: Weights to evaluate
     
    4573        Float_t const *w = weights + startw;
    4674
    47         Float_t *const beg = fVal+startv;
     75        const Float_t *beg = fVal+startv;
    4876        for (Float_t const *pex=beg; pex<beg+fWindowSize; pex++)
    4977        {
     
    115143
    116144public:
    117     MExtralgoDigitalFilter(Int_t res, Int_t windowsize, Float_t *wa, Float_t *wt)
     145    MExtralgoDigitalFilter(Int_t res, Int_t windowsize, Float_t *wa, Float_t *wt, Float_t *ps=0, TMatrix *ainv=0)
    118146        : fVal(0), fNum(0), fWeightsAmp(wa+res/2), fWeightsTime(wt+res/2),
    119         fWeightsPerBin(res), fWindowSize(windowsize),
     147        fPulseShape(ps), fAinv(ainv), fWeightsPerBin(res), fWindowSize(windowsize),
    120148        fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1)
    121149    {
    122150    }
    123151
    124     void SetData(Int_t n, Float_t *val) { fNum=n; fVal=val; }
     152    void SetData(Int_t n, Float_t const *val) { fNum=n; fVal=val; }
    125153
    126154    Float_t GetTime() const          { return fTime; }
     
    134162
    135163    Float_t ExtractNoise(Int_t iter) const;
    136     void Extract();
     164    void Extract(Int_t maxpos=-1);
    137165
    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);
     166    static Int_t CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1);
     167    static Int_t CalculateWeights2(TH1 &shape, const TH2 &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1);
    140168};
    141169
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc

    r7999 r8154  
    207207}
    208208
     209#include <TRandom.h>
    209210Float_t MExtralgoSpline::ExtractNoise(Int_t iter)
    210211{
    211     const Float_t nsx = iter * fResolution;
     212    const Float_t nsx = gRandom->Uniform(); //iter * fResolution;
    212213
    213214    if (fExtractionType == kAmplitude)
     
    223224    fSignalDev = -1;
    224225    fTimeDev   = -1;
    225 
     226/*
    226227    //
    227228    // Allow no saturated slice and
     
    229230    //
    230231
    231     /*
    232232    const Bool_t limlo = maxbin <      TMath::Ceil(fRiseTime);
    233233    const Bool_t limup = maxbin > fNum-TMath::Ceil(fFallTime)-1;
     
    248248        return;
    249249    }
    250     */
    251 
    252     fTimeDev = fResolution;
    253250
    254251    //
     
    256253    //
    257254
    258 
    259     /*
    260255    Float_t step = 0.2; // start with step size of 1ns and loop again with the smaller one
    261256
     
    346341        }
    347342    }
    348   */
    349 
     343
     344    fTime      = maxpos;
     345    fTimeDev   = fResolution;
     346    fSignal    = CalcIntegral(maxpos);
     347    fSignalDev = 0;  // means: is valid
     348
     349    return;
     350*/
    350351    // --- Start NEW ---
    351352
     
    369370
    370371    Float_t maxpos, maxval;
     372    // FIXME: Check the dfeault if no maximum found!!!
    371373    GetMaxAroundI(maxbin, maxpos, maxval);
    372374
     
    376378    {
    377379        fTime      = maxpos;
     380        fTimeDev   = fResolution;
    378381        fSignal    = maxval;
    379382        fSignalDev = 0;  // means: is valid
     
    381384    }
    382385
    383     //
    384     // Loop from the beginning of the slice upwards to reach the maxhalf:
    385     // With means of bisection:
    386     //
    387     /*
    388     static const Float_t sqrt2 = TMath::Sqrt(2.);
    389 
    390     step = sqrt2*3*0.061;//fRiseTime;
    391     Float_t x = maxpos-0.86-3*0.061;//fRiseTime*1.25;
    392 
    393 //    step = sqrt2*0.5;//fRiseTime;
    394 //    Float_t x = maxpos-1.25;//fRiseTime*1.25;
    395 
    396     Int_t  cnt  =0;
    397     while (cnt++<30)
    398     {
    399         const Float_t y=EvalAt(x);
    400 
    401         if (TMath::Abs(y-maxval/2)<fResolution)
    402             break;
    403 
    404         step /= sqrt2; // /2
    405         x += y>maxval/2 ? -step : +step;
    406     }
    407     */
    408 
    409386    // Search downwards for maxval/2
    410387    // By doing also a search upwards we could extract the pulse width
     
    412389
    413390    fTime      = x1;
     391    fTimeDev   = fResolution;
    414392    fSignal    = CalcIntegral(maxpos);
    415393    fSignalDev = 0;  // means: is valid
    416394
    417     //if (fSignal>100)
    418     //    cout << "V=" << maxpos-x1 << endl;
     395    //
     396    // Loop from the beginning of the slice upwards to reach the maxhalf:
     397    // With means of bisection:
     398    //
     399    /*
     400    static const Float_t sqrt2 = TMath::Sqrt(2.);
     401
     402    step = sqrt2*3*0.061;//fRiseTime;
     403    Float_t x = maxpos-0.86-3*0.061;//fRiseTime*1.25;
     404
     405//    step = sqrt2*0.5;//fRiseTime;
     406//    Float_t x = maxpos-1.25;//fRiseTime*1.25;
     407
     408    Int_t  cnt  =0;
     409    while (cnt++<30)
     410    {
     411        const Float_t y=EvalAt(x);
     412
     413        if (TMath::Abs(y-maxval/2)<fResolution)
     414            break;
     415
     416        step /= sqrt2; // /2
     417        x += y>maxval/2 ? -step : +step;
     418    }
     419    */
    419420
    420421    //
     
    422423    //
    423424    //   fTime      = cnt==31 ? -1 : x;
     425    //   fTimeDev   = fResolution;
    424426    //   fSignal    = cnt==31 ? CalcIntegral(x) : CalcIntegral(maxpos);
    425427    //   fSignalDev = 0;  // means: is valid
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h

    r7999 r8154  
    2121
    2222    // Input
    23     Float_t *fVal;
    24     Int_t    fNum;
     23    Float_t const *fVal;
     24    const Int_t    fNum;
    2525
    2626    Float_t *fDer1;
     
    238238
    239239        // Take a default in case no maximum is found
     240        // FIXME: Check THIS!!!
    240241        xmax=i;
    241242        ymax=fVal[i];
     
    438439
    439440public:
    440     MExtralgoSpline(Float_t *val, Int_t n, Float_t *der1, Float_t *der2)
     441    MExtralgoSpline(const Float_t *val, Int_t n, Float_t *der1, Float_t *der2)
    441442        : fExtractionType(kIntegral), fVal(val), fNum(n), fDer1(der1), fDer2(der2), fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1)
    442443    {
  • trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc

    r8141 r8154  
    9494#include "MFTriggerPattern.h"
    9595#include "MGeomApply.h"
     96#include "MPedestalSubtract.h"
    9697//#include "MMcPedestalCopy.h"
    9798#include "MPointingPosCalc.h"
     
    450451    MContinue conttp(&ftp, "ContTrigPattern");
    451452
     453    // Create the pedestal subtracted raw-data
     454    MPedestalSubtract pedsub;
     455    pedsub.SetPedestalCam(&pedcamab);
     456
    452457    // Do signal and pedestal calculation
    453458    MPedCalcFromLoGain     pedlo1("MPedCalcFundamental");
     
    471476        extractor1->SetPedestals(&pedcamab);
    472477
     478        // Setup to use the hi-gain extraction window in the lo-gain
     479        // range (the start of the lo-gain range is added automatically
     480        // by MPedCalcFromLoGain)
     481        //
     482        // The window size of the extractor is not yet initialized,
     483        // so we have to stick to the extraction range
     484        const Int_t f = extractor1->GetHiGainFirst();
     485        const Int_t l = extractor1->GetHiGainLast();
     486        const Int_t w = (l-f+1)&~1;
     487
     488        pedlo1.SetExtractWindow(f, w);
     489
    473490        if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
    474491        {
    475492            pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
    476493            pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
     494            /*
    477495            const Int_t win = ((MExtractTimeAndCharge*)extractor1)->GetWindowSizeHiGain();
    478496            pedlo1.SetExtractWindow(15, win);
    479             pedlo2.SetExtractWindow(15, win/*obsolete*/);
    480             pedlo3.SetExtractWindow(15, win/*obsolete*/);
     497            pedlo2.SetExtractWindow(15, win//obsolete//);
     498            pedlo3.SetExtractWindow(15, win//obsolete//);
     499            */
    481500        }
    482501        else
    483502        {
     503            /*
    484504            // FIXME: How to get the fixed value 15 automatically?
    485505            const Int_t f = (Int_t)(15.5+extractor1->GetHiGainFirst());
     
    488508            pedlo2.SetExtractWindow(f, n);
    489509            pedlo3.SetExtractWindow(f, n);
     510            */
     511            pedlo2.SetExtractWindow(f, w);
     512            pedlo3.SetExtractWindow(f, w);
     513
    490514        }
    491515    }
     
    657681    tlist2.AddToList(&apply);
    658682    tlist2.AddToList(&merge);
     683    tlist2.AddToList(&pedsub);
    659684    tlist2.AddToList(&pedlo1);
    660685    tlist2.AddToList(&pedlo2);
  • trunk/MagicSoft/Mars/mjobs/MJCalibration.cc

    r8141 r8154  
    154154#include "MRawFileRead.h"
    155155#include "MGeomApply.h"
     156#include "MPedestalSubtract.h"
    156157#include "MTaskEnv.h"
    157158#include "MBadPixelsMerge.h"
     
    19071908    tlist.AddToList(&apply);
    19081909
    1909     MPedCalcPedRun           pedcalc;
    1910     pedcalc.SetExtractWindow(fExtractor->GetHiGainFirst(),TMath::Nint(fExtractor->GetNumHiGainSamples()));
     1910    // Produce pedestal subtracted raw-data
     1911    MPedestalSubtract pedsub;
     1912    pedsub.SetPedestalCam(fExtractor->GetPedestals());
     1913    tlist.AddToList(&pedsub);
     1914
     1915    // Setup to use the hi-gain extraction window in the lo-gain
     1916    // range (the start of the lo-gain range is added automatically
     1917    // by MPedCalcFromLoGain)
     1918    //
     1919    // The window size of the extractor is not yet initialized,
     1920    // so we have to stick to the extraction range
     1921    const Int_t f = fExtractor->GetHiGainFirst();
     1922    const Int_t l = fExtractor->GetHiGainLast();
     1923    const Int_t w = (l-f+1)&~1;
     1924
     1925    MPedCalcPedRun pedcalc;
     1926    pedcalc.SetExtractWindow(f, w);
    19111927
    19121928    if (IsIntensity())
  • trunk/MagicSoft/Mars/mjobs/MJPedestal.cc

    r7739 r8154  
    8282#include "MRawEvtData.h"
    8383#include "MGeomApply.h"
     84#include "MPedestalSubtract.h"
    8485#include "MTriggerPatternDecode.h"
    8586#include "MBadPixelsMerge.h"
     
    10641065    //
    10651066    if (!fBadPixelsFile.IsNull())
    1066       {
     1067    {
    10671068        *fLog << inf << "Excluding: " << fBadPixelsFile << endl;
    1068         ifstream fin(fBadPixelsFile.Data());
    1069         fBadPixels.AsciiRead((istream&)fin);
    1070       }
     1069        ifstream fin(fBadPixelsFile);
     1070        fBadPixels.AsciiRead(fin);
     1071    }
    10711072
    10721073    MGeomApply geomapl;
     
    10741075
    10751076    MPedCalcPedRun pedcalc;
    1076     pedcalc.SetPedestalUpdate(kFALSE);
     1077    //pedcalc.SetPedestalUpdate(kFALSE);
    10771078
    10781079    MPedCalcFromLoGain pedlogain;
     
    11321133        tlist.AddToList(&fillpul);
    11331134    }
     1135
     1136    // produce pedestal subtracted raw-data
     1137    MPedestalSubtract pedsub;
     1138    if (fExtractor && fExtractionType!=kFundamental)
     1139        pedsub.SetPedestalCam(&fPedestalCamIn);
     1140    else
     1141        pedsub.SetNamePedestalCam(""); // Only copy hi- and lo-gain together!
     1142    tlist.AddToList(&pedsub);
    11341143
    11351144    // ----------------------------------------------------------------------
     
    11861195    if (fExtractor)
    11871196    {
    1188       fExtractor->SetPedestals(&fPedestalCamIn);
    1189 
    1190       if (fExtractionType!=kFundamental)
     1197        fExtractor->SetPedestals(&fPedestalCamIn);
     1198
     1199        if (fExtractionType!=kFundamental)
    11911200        {
    1192           pedcalc.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
    1193           pedlogain.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
    1194          
    1195           pedcalc.SetExtractor((MExtractTimeAndCharge*)fExtractor);
    1196           pedlogain.SetExtractor((MExtractTimeAndCharge*)fExtractor);
     1201            pedcalc.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
     1202            pedlogain.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
     1203
     1204            pedcalc.SetExtractor((MExtractTimeAndCharge*)fExtractor);
     1205            pedlogain.SetExtractor((MExtractTimeAndCharge*)fExtractor);
    11971206        }
    1198      
    1199       if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
     1207        else
    12001208        {
    1201 
    1202           const Float_t f = 0.1+fExtractor->GetHiGainFirst();
    1203           const Int_t win = ((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeHiGain();
    1204           pedcalc.SetExtractWindow((Int_t)f, win);
    1205           pedlogain.SetExtractWindow((Int_t)(15+f), win);
    1206 
     1209            // The window size of the extractor is not yet initialized,
     1210            // so we have to stick to the extraction range
     1211            const Int_t f = fExtractor->GetHiGainFirst();
     1212            const Int_t l = fExtractor->GetHiGainLast();
     1213            const Int_t w = (l-f+1)&~1;
     1214
     1215            // Setup to use the hi-gain extraction window in the lo-gain
     1216            // range (the start of the lo-gain range is added automatically
     1217            // by MPedCalcFromLoGain)
     1218            pedcalc.SetExtractWindow(f, w);
     1219            pedlogain.SetExtractWindow(f, w);
    12071220        }
    1208       else
     1221
     1222        if (!fExtractor->InheritsFrom("MExtractTimeAndCharge") && fExtractionType!=kFundamental)
    12091223        {
    1210           const Float_t f = 0.1+fExtractor->GetHiGainFirst();
    1211           const Float_t n = 0.1+fExtractor->GetNumHiGainSamples();
    1212           pedcalc.SetExtractWindow((Int_t)f, (Int_t)n);
    1213           pedlogain.SetExtractWindow((Int_t)(15+f), (Int_t)n);
    1214 
    1215           if (fExtractionType!=kFundamental)
    1216             {
    1217               *fLog << inf;
    1218               *fLog << "Signal extractor doesn't inherit from MExtractTimeAndCharge..." << endl;
    1219               *fLog << " --> falling back to fundamental pedestal extraction." << endl;
    1220               fExtractionType=kFundamental;
    1221             }
     1224            *fLog << inf;
     1225            *fLog << "Signal extractor doesn't inherit from MExtractTimeAndCharge..." << endl;
     1226            *fLog << " --> falling back to fundamental pedestal extraction." << endl;
     1227            fExtractionType=kFundamental;
    12221228        }
    12231229    }
  • trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc

    r8153 r8154  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.2 2006-10-24 08:18:07 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
  • trunk/MagicSoft/Mars/mpedestal/Makefile

    r8151 r8154  
    4242           MHPedestalCor.cc \
    4343           MPedestalSubtract.cc \
    44            MPedestalSubtractedEvt.cc \
    45            MPedCalcFromData.cc
     44           MPedestalSubtractedEvt.cc
    4645
    4746############################################################
  • trunk/MagicSoft/Mars/mpedestal/PedestalLinkDef.h

    r8151 r8154  
    1919#pragma link C++ class MPedestalSubtract+;
    2020#pragma link C++ class MPedestalSubtractedEvt+;
    21 #pragma link C++ class MPedCalcFromData+;
    2221
    2322#pragma link C++ class MHPedestalCor+;
  • trunk/MagicSoft/Mars/msignal/MExtractTime.cc

    r8144 r8154  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MExtractTime.cc,v 1.22 2006-10-24 08:24:52 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    1719!
    1820!   Author(s): Markus Gaug, 04/2004 <mailto:markus@ifae.es>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2004
     21!   Author(s): Thomas Bretz, 04/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
     22!
     23!   Copyright: MAGIC Software Development, 2000-2006
    2124!
    2225!
     
    137140// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
    138141//                                      fLoGainFirst, fLoGainLast, fNumLoGainSamples);
    139 //
     142/*
    140143Bool_t MExtractTime::ReInit(MParList *pList)
    141144{
     
    148151    return kTRUE;
    149152}
    150 
     153*/
    151154// --------------------------------------------------------------------------
    152155//
    153156// Calculate the integral of the FADC time slices and store them as a new
    154157// pixel in the MArrivalTimeCam container.
    155 //
     158/*
    156159Int_t MExtractTime::Process()
    157160{
     
    183186      pix.SetGainSaturation(sathi, satlo);
    184187 
    185     } /* while (pixel.Next()) */
     188    }
    186189
    187190    fArrTime->SetReadyToSave();
    188191
    189192    return kTRUE;
    190 }
     193}*/
    191194
    192195void MExtractTime::Print(Option_t *o) const
    193196{
    194     if (IsA()==MExtractTime::Class())
    195         *fLog << GetDescriptor() << ":" << endl;
     197//    if (IsA()==MExtractTime::Class())
     198//        *fLog << GetDescriptor() << ":" << endl;
     199    MExtractor::Print(o);
    196200    *fLog << " Offset Lo-Gain:     " << fOffsetLoGain << endl;
    197     MExtractor::Print(o);
    198 }
     201}
  • trunk/MagicSoft/Mars/msignal/MExtractTime.h

    r7091 r8154  
    1717 
    1818  MArrivalTimeCam *fArrTime;          //! Container with the photons arrival times
    19  
     19/*
    2020  virtual void FindTimeHiGain(Byte_t *firstused, Float_t &time, Float_t &dtime,
    2121                              Byte_t &sat, const MPedestalPix &ped) const {}
    2222  virtual void FindTimeLoGain(Byte_t *firstused, Float_t &time, Float_t &dtime,
    2323                              Byte_t &sat, const MPedestalPix &ped) const {}
    24 
     24  */
    2525  Int_t  PreProcess( MParList *pList );
    26   Bool_t ReInit    ( MParList *pList );
    27   Int_t  Process   ();
     26//  Bool_t ReInit    ( MParList *pList );
     27//  Int_t  Process   ();
    2828
    2929public:
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc

    r7900 r8154  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.55 2006-10-24 08:24:52 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    1719!
    1820!   Author(s): Markus Gaug, 05/2004 <mailto:markus@ifae.es>
     21!   Author(s): Thomas Bretz, 05/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1922!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     23!   Copyright: MAGIC Software Development, 2000-2006
    2124!
    2225!
     
    6063//   MExtractedSignalCam
    6164//
     65// For weired events check: Run 94127 Event 672, 1028
     66//
    6267//////////////////////////////////////////////////////////////////////////////
    6368#include "MExtractTimeAndCharge.h"
     
    7075#include "MParList.h"
    7176
    72 #include "MRawEvtData.h"
     77//#include "MArrayB.h"
     78//#include "MArrayF.h"
     79
     80//#include "MRawEvtData.h"
    7381#include "MRawEvtPixelIter.h"
    74 #include "MRawRunHeader.h"
    75 
    76 #include "MPedestalCam.h"
    77 #include "MPedestalPix.h"
     82//#include "MRawRunHeader.h"
     83
     84//#include "MPedestalCam.h"
     85//#include "MPedestalPix.h"
     86#include "MPedestalSubtractedEvt.h"
    7887
    7988#include "MArrivalTimeCam.h"
     
    8796using namespace std;
    8897
    89 const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -3.5;
    90 const Byte_t  MExtractTimeAndCharge::fgLoGainSwitch = 120;
     98const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -6.0;
     99const Byte_t  MExtractTimeAndCharge::fgLoGainSwitch     =  120;
    91100
    92101// --------------------------------------------------------------------------
     
    95104//
    96105// Sets:
    97 // - fLoGainFirstSave to 0
    98106// - fWindowSizeHiGain and fWindowSizeLoGain to 0
    99107// - fLoGainStartShift to fgLoGainStartShift+fgOffsetLoGain
     
    101109//
    102110MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
    103     : fLoGainFirstSave(0), fWindowSizeHiGain(0), fWindowSizeLoGain(0)
     111    : /*fLoGainFirstSave(0),*/ fWindowSizeHiGain(0), fWindowSizeLoGain(0)
    104112{
    105113    fName  = name  ? name  : "MExtractTimeAndCharge";
     
    157165 
    158166  if (fSignals)
    159     fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
     167    fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast/*+fHiLoLast*/, fNumHiGainSamples,
    160168                                fLoGainFirst, fLoGainLast, fNumLoGainSamples);
    161 
    162169
    163170  return kTRUE;
     
    175182Int_t MExtractTimeAndCharge::Process()
    176183{
    177 
    178   MRawEvtPixelIter pixel(fRawEvt);
    179 
    180   while (pixel.Next())
    181   {
    182       // COPY HERE PRODUCING ARRAY WITH SAMPLES
    183 
    184       /*
    185        const MPedestalPix  &ped = (*fPedestals)[pixidx];
    186 
    187        const Float_t pedes  = ped.GetPedestal();
    188        const Float_t ABoffs = ped.GetPedestalABoffset();
    189 
    190        const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
    191 
    192        const Int_t num = pixel.GetNumHiGainSamples()+pixel.GetNumLoGainSamples();
    193 
    194        MArrayF sample(num);
    195 
    196        const Int_t abflag = pixel.HasABFlag() ? 1 : 0;
    197        const Int_t ids0 = fHiGainFirst + abflag;
    198 
    199        Int_t ids  = ids0;
    200 
    201        Float_t  null   = 0;      // Starting value for maxpos
    202        Float_t *maxpos = &null;  // Position of maximum
    203        Float_t *sat1   = 0;      // First saturating slice
    204        Float_t *sat2   = 0;      // Last saturating slice
    205 
    206        const Float_t *beg = sample.GetArray();
    207        const Float_t *end = beg + num;
    208 
    209        Float_t *ptr = beg;
    210        while (ptr<end)
    211        {
    212           *sample++ = (Float_t)*ptr - pedmean[ids++&0x1];
    213 
    214           // This extraction must be done independant for lo- and hi-gain
    215           // if (*ptr > *maxpos)
    216           //     maxpos = ptr;
    217           //
    218           // if (*ptr >= fSaturationLimit)
    219           // {
    220           //    sat2 = ptr;
    221           //    if (!sat1)
    222           //       sat1 = ptr;
    223           // }
    224           //
    225           // ptr++;
     184    MRawEvtPixelIter pixel(fRawEvt);
     185
     186    while (pixel.Next())
     187    {
     188        const Int_t pixidx = pixel.GetPixelId();
     189
     190        //
     191        // Preparations for the pedestal subtraction (with AB-noise correction)
     192        //
     193        Float_t *sig = fSignal->GetSamples(pixidx);
     194
     195        // ====================================================================
     196        //    MOVE THIS TO MExtractTimeAndCharge
     197        // ====================================================================
     198        // number of hi- and lo-gains
     199        const Int_t numh = pixel.GetNumHiGainSamples();
     200        const Int_t numl = pixel.GetNumLoGainSamples();
     201/*
     202        // COPY HERE PRODUCING ARRAY WITH SAMPLES
     203        static MArrayB sample;
     204        sample.Set(numh+numl);
     205
     206        if (numl>0)
     207        {
     208            memcpy(sample.GetArray(),      pixel.GetHiGainSamples(), numh);
     209            memcpy(sample.GetArray()+numh, pixel.GetLoGainSamples(), numl);
    226210        }
    227        */
    228 
    229       //
    230       // Find signal in hi- and lo-gain
    231       //
    232       Float_t sumhi =0., deltasumhi =0; // Set hi-gain of MExtractedSignalPix valid
    233       Float_t timehi=0., deltatimehi=0; // Set hi-gain of MArrivalTimePix valid
    234       Byte_t sathi=0;
    235 
    236       // Initialize fMaxBinContent for the case, it gets not set by the derived class
    237       fMaxBinContent = fLoGainSwitch + 1;
    238 
    239       const Int_t pixidx = pixel.GetPixelId();
    240       const MPedestalPix  &ped = (*fPedestals)[pixidx];
    241       const Bool_t higainabflag = pixel.HasABFlag();
    242 
    243       FindTimeAndChargeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(),
    244                               sumhi, deltasumhi, timehi, deltatimehi,
    245                               sathi, ped, higainabflag);
    246 
    247       // Make sure that in cases the time couldn't be correctly determined
    248       // more meaningfull default values are assigned
    249       if (timehi<=0 || timehi>pixel.GetNumHiGainSamples())
    250           timehi = gRandom->Uniform(pixel.GetNumHiGainSamples());
    251      
    252       Float_t sumlo =0., deltasumlo =-1.; // invalidate logain of MExtractedSignalPix
    253       Float_t timelo=0., deltatimelo=-1;  // invalidate logain of MArrivalTimePix
    254       Byte_t satlo=0;
    255      
    256       //
    257       // Adapt the low-gain extraction range from the obtained high-gain time
    258       //
    259 
    260       // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
    261       // MEANS: Hi gain has saturated, but it is too early to extract
    262       // the lo-gain properly
    263       // THIS produces pulse positions ~= -1
    264       // The signal might be handled in MCalibrateData, but hwat's about
    265       // the arrival times in MCalibrateRelTime
    266       if (sathi && fMaxBinContent<=fLoGainSwitch)
    267           deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
    268 
    269       // FIXME: What to do with the pixel if it saturates too early???
    270       if (pixel.HasLoGain() && (fMaxBinContent > fLoGainSwitch /*|| sathi>0*/) )
    271       {
    272           fLoGainFirstSave = fLoGainFirst;
    273 
    274           // sathi is the number (not index!) of the first saturating slice
    275           // 0 indicates that no saturation was found
    276           // FIMXME: Is 3 an accurate value?
    277 
    278           const Float_t pos = sathi==0 ? timehi : (int)(sathi)-3;
    279 
    280           if (pos+fLoGainStartShift>0)
    281               fLoGainFirst = (Byte_t)(pos + fLoGainStartShift);
    282 
    283           if (fLoGainFirst<fLoGainFirstSave)
    284               fLoGainFirst = fLoGainFirstSave;
    285 
    286           if (fLoGainLast-fLoGainFirst >= fWindowSizeLoGain)
    287           {
    288               deltasumlo  = 0; // make logain of MExtractedSignalPix valid
    289               deltatimelo = 0; // make logain of MArrivalTimePix valid
    290 
    291               const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
    292               FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
    293                                       sumlo, deltasumlo, timelo, deltatimelo,
    294                                       satlo, ped, logainabflag);
    295 
    296               if (satlo>6)
    297                   deltasumlo=deltatimelo=-1;
    298           }
    299           fLoGainFirst = fLoGainFirstSave;
    300 
    301           // Make sure that in cases the time couldn't be correctly determined
    302           // more meaningfull default values are assigned
    303           if (timelo<=0 || timelo>pixel.GetNumLoGainSamples())
    304               timelo = gRandom->Uniform(pixel.GetNumLoGainSamples());
    305       }
    306 
    307       MExtractedSignalPix &pix = (*fSignals)[pixidx];
    308       MArrivalTimePix     &tix = (*fArrTime)[pixidx];
    309       pix.SetExtractedSignal(sumhi, deltasumhi, sumlo, deltasumlo);
    310       pix.SetGainSaturation(sathi, satlo);
    311 
    312       tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
    313       tix.SetGainSaturation(sathi, satlo);
    314  
     211
     212        // get pedestal information
     213        const MPedestalPix &pedpix = (*fPedestals)[pixidx];
     214
     215        // pedestal information
     216        const Int_t   ab  = pixel.HasABFlag() ? 1 : 0;
     217        const Float_t ped = pedpix.GetPedestal();
     218
     219        // destination array
     220        static MArrayF sig;
     221        sig.Set(numh+numl);
     222
     223        // start of destination array, end of hi-gain destination array
     224        // and start of hi-gain samples
     225        Float_t *beg = sig.GetArray();
     226        Float_t *end = beg + sig.GetSize();
     227
     228        // determine with which pedestal (+/- AB offset) to start
     229        const Bool_t  noswap  = (ab&1)==((beg-beg)&1);
     230        const Float_t offh    = noswap ? pedpix.GetPedestalABoffset() : -pedpix.GetPedestalABoffset();
     231        const Float_t mean[2] = { ped + offh, ped - offh };
     232
     233        //const Int_t rangeh = fHiGainLast - fHiGainFirst + 1  + fHiLoLast;
     234        //const Int_t rangel = fLoGainLast - fLoGainFirst + 1;
     235
     236        const Byte_t *src = numl>0 ? sample.GetArray() : pixel.GetHiGainSamples();
     237        //const Byte_t *src = sample.GetArray();
     238
     239        // Copy hi-gains into array and substract pedestal
     240        // FIXME: Shell we really subtract the pedestal from saturating slices???
     241        for (Float_t *ptr=beg; ptr<end; ptr++)
     242            *ptr = (Float_t)*src++ - mean[(ptr-beg)&1];
     243
     244        // Determin saturation of hi-gains
     245        Byte_t *p0 = fSignal->GetSamplesRaw(pixidx); //numl>0 ? sample.GetArray() : pixel.GetHiGainSamples();
     246//        Byte_t *p0 = sample.GetArray();
     247
     248        Byte_t maxcont  =  0;
     249        Int_t  maxposhi = -1;
     250
     251        Byte_t *sathi0 = 0; // first saturating hi-gain slice
     252        Byte_t *sathi1 = 0; // last saturating hi-gain slice
     253        for (Byte_t *ptr=p0+fHiGainFirst; ptr<p0+fHiGainLast+fHiLoLast+1; ptr++)
     254        {
     255            // Get hi-gain maxbincontent
     256            // Put this into its own function and loop?
     257            if (*ptr>maxcont)
     258            {
     259                // ORGINAL:
     260                //Int_t range = (fHiGainLast - fHiGainFirst + 1 + fHiLoLast) - fWindowSizeHiGain + 1;
     261                // maxpos>1 && maxpos<=range
     262
     263                // This is a strange workaround to fit the previous
     264                // Spline setup: TO BE CHECKED!
     265                const Int_t pos = ptr-p0;
     266                if (pos<fHiGainLast+1)
     267                {
     268                    maxposhi = pos-fHiGainFirst;
     269
     270                    if (maxposhi>1 && maxposhi<fHiGainLast-fHiGainFirst*//*+1 -fWindowSizeHiGain+1*//*+fHiLoLast*//*)
     271                        maxcont = *ptr;
     272                }
     273            }
     274
     275            // FIXME: Do we also have to really COUNT the number
     276            // of saturating slices, eg. for crosschecks?
     277            if (*ptr>=fSaturationLimit)
     278            {
     279                sathi1 = ptr;
     280                if (!sathi0)
     281                    sathi0 = ptr;
     282            }
     283        }
     284*/
     285        Int_t sathi0 = fHiGainFirst;          // First slice to extract and first saturating slice
     286        Int_t sathi1 = fHiGainLast/*+fHiLoLast*/; // Last  slice to extract and last saturating slice
     287
     288        Int_t maxcont;
     289        Int_t maxposhi = fSignal->GetMax(pixidx, sathi0, sathi1, maxcont);
     290        // Would it be better to take lastsat-firstsat?
     291        Int_t numsathi = fSignal->GetSaturation(pixidx, fSaturationLimit, sathi0, sathi1);
     292/*
     293        // sathi2 is the number (not the index) of first saturating slice
     294//        const Byte_t sathi2   = sathi0<0 ? 0 : sathi0+1;
     295
     296        // Number (not index) of first saturating slice
     297 //       const Byte_t sathi2 = sathi0==0 ? 0 : sathi0-p0+1;
     298//        const Byte_t numsathi = sathi0==0 ? 0 : sathi1-sathi0+1;
     299
     300//        Int_t maxb = maxcont;
     301
     302        // ====================================================================
     303        // FIXME: Move range out of the extractors...
     304
     305        // Initialize maxcont for the case, it gets not set by the derived class
     306        Float_t sumhi2 =0., deltasumhi2 =-1; // Set hi-gain of MExtractedSignalPix valid
     307        Float_t timehi2=0., deltatimehi2=-1; // Set hi-gain of MArrivalTimePix valid
     308*/
     309        Float_t sumhi =0., deltasumhi =-1; // Set hi-gain of MExtractedSignalPix valid
     310        Float_t timehi=0., deltatimehi=-1; // Set hi-gain of MArrivalTimePix valid
     311        if (numsathi<1)
     312        {
     313
     314        const Int_t rangehi = fHiGainLast - fHiGainFirst + 1/* + fHiLoLast*/;
     315        FindTimeAndChargeHiGain2(sig/*.GetArray()*/+fHiGainFirst, rangehi,
     316                                 sumhi, deltasumhi, timehi, deltatimehi,
     317                                 numsathi, maxposhi);
     318
     319        timehi += fHiGainFirst;
     320        }
     321/*
     322        Float_t sumhi = sumhi2;
     323        Float_t deltasumhi = deltasumhi2;
     324        Float_t timehi = timehi2;
     325        Float_t deltatimehi=deltatimehi2;
     326//        Byte_t sathi = sathi2;
     327
     328
     329        //
     330        // Find signal in hi- and lo-gain
     331        //
     332        Float_t sumhi =0., deltasumhi =-1; // Set hi-gain of MExtractedSignalPix valid
     333        Float_t timehi=0., deltatimehi=-1; // Set hi-gain of MArrivalTimePix valid
     334        Byte_t sathi=0;
     335
     336        // Initialize maxcont for the case, it gets not set by the derived class
     337        maxcont = fLoGainSwitch + 1;
     338
     339        //const Int_t pixidx = pixel.GetPixelId();
     340        //const MPedestalPix  &ped = (*fPedestals)[pixidx];
     341        const Bool_t higainabflag = pixel.HasABFlag();
     342        FindTimeAndChargeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(),
     343                                sumhi, deltasumhi, timehi, deltatimehi,
     344                                sathi, pedpix, higainabflag);
     345        timehi += fHiGainFirst;
     346
     347  */
     348        // Make sure that in cases the time couldn't be correctly determined
     349        // more meaningfull default values are assigned
     350        if (timehi<=fHiGainFirst || timehi>=fHiGainLast)
     351            timehi = gRandom->Uniform(fHiGainLast-fHiGainFirst)+fHiGainFirst;
     352
     353        Float_t sumlo =0., deltasumlo =-1.; // invalidate logain of MExtractedSignalPix
     354        Float_t timelo=0., deltatimelo=-1;  // invalidate logain of MArrivalTimePix
     355        Byte_t satlo=0;
     356        Int_t numsatlo=0;
     357
     358        //
     359        // Adapt the low-gain extraction range from the obtained high-gain time
     360        //
     361
     362        // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
     363        // MEANS: Hi gain has saturated, but the signal is to dim
     364        // to extract the lo-gain properly
     365        // THIS produces pulse positions ~= -1
     366        // The signal might be handled in MCalibrateData, but hwat's about
     367        // the arrival times in MCalibrateRelTime
     368        if (numsathi>0 && maxcont<=fLoGainSwitch)
     369            deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
     370
     371        // If more than 8 hi-gain slices have saturated this is
     372        // no physical event. We just assume that something with
     373        // the extraction is wrong
     374        if (numsathi>8) // FIXME: Should be something like 2?
     375            deltasumhi=deltatimehi=-1;
     376
     377        // FIXME: What to do with the pixel if it saturates too early???
     378        if (pixel.HasLoGain() && (maxcont > fLoGainSwitch /*|| sathi>0*/) )
     379        {
     380            // To determin the window in which the lo-gain is extracted
     381            // clearly more information about the relation between the
     382            // extraction window and the reslting time is necessary.
     383            //fLoGainStartShift = -6.0;
     384
     385            const Byte_t fLoGainFirstSave = fLoGainFirst;
     386
     387            // sathi is the number (not index!) of the first saturating slice
     388            // 0 indicates that no saturation was found
     389            // FIXME: Is 0.5 should be expressed by the rise time of
     390            //        the hi-gain signal!
     391            const Float_t pos = numsathi==0 ? timehi : sathi0-0.5;
     392
     393            const Int_t lostart = TMath::FloorNint(pos+6);
     394
     395            const Int_t newfirst = TMath::FloorNint(pos+fLoGainStartShift);
     396            fLoGainFirst = newfirst>fLoGainFirstSave ? newfirst : fLoGainFirstSave;
     397
     398//            if (fLoGainLast-fLoGainFirst >= fWindowSizeLoGain)
     399            {
     400/*
     401                Float_t sumlo2 =0., deltasumlo2 =-1.; // invalidate logain of MExtractedSignalPix
     402                Float_t timelo2=0., deltatimelo2=-1.;  // invalidate logain of MArrivalTimePix
     403
     404                // Determin saturation in lo-gains
     405                Byte_t *satlo0 = 0; // first saturating hi-gain slice
     406                Byte_t *satlo1 = 0; // last saturating hi-gain slice
     407                Int_t maxposlo = -1;
     408                Byte_t maxlo = 0;
     409
     410                Byte_t *p0 = fSignal->GetSamplesRaw(pixidx);
     411                for (Byte_t *ptr=p0+numh+fLoGainFirst; ptr<p0+numh+fLoGainLast+1; ptr++)
     412                {
     413                    if (*ptr>maxlo)
     414                    {
     415                        // This is a strange workaround to fit the previous
     416                        // Spline setup: TO BE CHECKED!
     417                        const Int_t ipos = ptr-p0-numh;
     418                        if (ipos>=fLoGainFirst && ipos<=fLoGainLast)
     419                        {
     420                            maxposlo = ipos-fLoGainFirst;
     421                            maxlo = *ptr;
     422                        }
     423                    }
     424                    if (*ptr>=fSaturationLimit)
     425                    {
     426                        satlo1 = ptr;
     427                        if (!satlo0)
     428                            satlo0 = ptr;
     429                    }
     430                    // FIXME: Do we also have to really COUNT the number
     431                    // of saturating slices, eg. for crosschecks?
     432                }
     433
     434                // Number of saturating lo-gain slices (this is not necessary
     435                // identical to a counter counting the number of saturating
     436                // slices!)
     437                const Byte_t numsatlo = satlo0==0 ? 0 : satlo1-satlo0+1;
     438*/
     439
     440                Int_t satlo0 = numh+fLoGainFirst;   // First slice to extract and first saturating slice
     441                Int_t satlo1 = numh+fLoGainLast;    // Last  slice to extract and last saturating slice
     442
     443                // Would it be better to take lastsat-firstsat?
     444                Int_t maxlo;
     445                Int_t maxposlo = fSignal->GetMax(pixidx, satlo0, satlo1, maxlo);
     446                numsatlo = fSignal->GetSaturation(pixidx, fSaturationLimit, satlo0, satlo1);
     447
     448                //                const Byte_t satlo2 = numsatlo;
     449
     450                const Int_t rangelo = fLoGainLast - fLoGainFirst + 1;
     451                FindTimeAndChargeLoGain2(sig/*.GetArray()*/+numh+fLoGainFirst, rangelo,
     452                                         sumlo, deltasumlo, timelo, deltatimelo,
     453                                         numsatlo, maxposlo);
     454                timelo += fLoGainFirst;
     455
     456//                sumlo =sumlo2, deltasumlo=deltasumlo2; // invalidate logain of MExtractedSignalPix
     457//                timelo=timelo2, deltatimelo=deltatimelo2;  // invalidate logain of MArrivalTimePix
     458//                satlo = satlo2;
     459
     460                /*
     461                // THIS IS NOW THE JOB OF THE EXTRACTOR!
     462                //deltasumlo  = 0; // make logain of MExtractedSignalPix valid
     463                //deltatimelo = 0; // make logain of MArrivalTimePix valid
     464
     465                const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
     466                FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
     467                                        sumlo, deltasumlo, timelo, deltatimelo,
     468                                        satlo, pedpix, logainabflag);
     469                timelo += fLoGainFirst;
     470                */
     471
     472
     473                // If more than 6 lo-gain slices have saturated this is
     474                // no physical event. We just assume that something with
     475                // the extraction is wrong
     476                if (numsatlo>6)
     477                    deltasumlo=deltatimelo=-1;
     478            }
     479            fLoGainFirst = fLoGainFirstSave;
     480
     481            // Make sure that in cases the time couldn't be correctly determined
     482            // more meaningfull default values are assigned
     483            if (timelo<=fLoGainFirst || timelo>=fLoGainLast)
     484                timelo = gRandom->Uniform(fLoGainLast-fLoGainFirst)+fLoGainFirst;
     485       }
     486
     487        MExtractedSignalPix &pix = (*fSignals)[pixidx];
     488        MArrivalTimePix     &tix = (*fArrTime)[pixidx];
     489        pix.SetExtractedSignal(sumhi, deltasumhi, sumlo, deltasumlo);
     490        pix.SetGainSaturation(numsathi, numsatlo);
     491//        pix.SetGainSaturation(sathi, satlo);
     492
     493        tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
     494        tix.SetGainSaturation(numsathi, numsatlo);
     495//        tix.SetGainSaturation(sathi, satlo);
    315496    } /* while (pixel.Next()) */
    316497
    317   fArrTime->SetReadyToSave();
    318   fSignals->SetReadyToSave();
    319 
    320   return kTRUE;
     498    fArrTime->SetReadyToSave();
     499    fSignals->SetReadyToSave();
     500
     501    return kTRUE;
    321502}
    322503
     
    352533void MExtractTimeAndCharge::Print(Option_t *o) const
    353534{
    354   if (IsA()==Class())
    355     *fLog << GetDescriptor() << ":" << endl;
     535  MExtractTime::Print(o);
     536//  if (IsA()==Class())
     537//    *fLog << GetDescriptor() << ":" << endl;
    356538
    357539  *fLog << dec;
    358   *fLog << " Taking " << fWindowSizeHiGain
    359         << " HiGain samples from slice " << (Int_t)fHiGainFirst
    360         << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
    361   *fLog << " Taking " << fWindowSizeLoGain
    362         << " LoGain samples from slice " << (Int_t)fLoGainFirst
    363         << " to " << (Int_t)fLoGainLast << " incl" << endl;
    364  
     540  //*fLog << " Taking " << fWindowSizeHiGain
     541  //      << " HiGain samples from slice " << (Int_t)fHiGainFirst
     542  //      << " to " << (Int_t)(fHiGainLast/*+fHiLoLast*/) << " incl" << endl;
     543  //*fLog << " Taking " << fWindowSizeLoGain
     544  //      << " LoGain samples from slice " << (Int_t)fLoGainFirst
     545  //      << " to " << (Int_t)fLoGainLast << " incl" << endl;
     546  //
    365547  *fLog << " LoGainStartShift:   " << fLoGainStartShift << endl;
    366548  *fLog << " LoGainSwitch:       " << (Int_t)fLoGainSwitch << endl;
    367   MExtractTime::Print(o);
    368549}
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.h

    r7091 r8154  
    1414  static const Byte_t  fgLoGainSwitch;     //! Default for fLoGainSwitch     (now set to: 100)
    1515 
    16 protected:
     16private:
    1717
    18   Byte_t  fLoGainFirstSave;       //! Temporary variable to store the original position of low-gain start slice
     18//  Byte_t  fLoGainFirstSave;       //! Temporary variable to store the original position of low-gain start slice
    1919  Float_t fLoGainStartShift;      // Shift to start searching the low-gain signal obtained from the high-gain times.
    2020
    2121  Byte_t  fLoGainSwitch;          // Limit for max. bin content before the low-gain gets extracted
    2222
     23protected:
     24
    2325  Int_t  fWindowSizeHiGain;       //  Window Size High-Gain
    2426  Int_t  fWindowSizeLoGain;       //  Window Size Low-Gain
    2527
    26   Byte_t fMaxBinContent;          //  Maximum bin content
    27 
    2828  Int_t  PreProcess(MParList *pList);
    2929  Int_t  Process();
    30   Bool_t ReInit(MParList *pList);
    31 
    3230  Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    3331
     
    4745  virtual void SetWindowSize(Int_t windowh, Int_t windowl) { fWindowSizeHiGain = windowh;
    4846                                                           fWindowSizeLoGain = windowl;  }
     47
     48  Bool_t ReInit(MParList *pList);
    4949 
    5050  virtual Bool_t InitArrays() { return kTRUE; }
    51 
     51/*
    5252  virtual void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
    5353                                       Float_t &time, Float_t &dtime,
     
    5757                                       Float_t &time, Float_t &dtime,
    5858                                       Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag) { }
     59  */
     60  virtual void FindTimeAndChargeHiGain2(const Float_t *firstused, Int_t num, Float_t &sum, Float_t &dsum,
     61                                       Float_t &time, Float_t &dtime,
     62                                       Byte_t sat, Int_t maxpos) { }
     63 
     64  virtual void FindTimeAndChargeLoGain2(const Float_t *firstused, Int_t num, Float_t &sum,  Float_t &dsum,
     65                                       Float_t &time, Float_t &dtime,
     66                                       Byte_t sat, Int_t maxpos) { }
     67
     68  // For MExtractPedestal
    5969
    6070  ClassDef(MExtractTimeAndCharge, 2)   // Time And Charge Extractor Base Class
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc

    r8129 r8154  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndChargeDigitalFilter.cc,v 1.73 2006-10-24 08:24:52 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    7274#include "MCalibrationPattern.h"
    7375#include "MExtractedSignalCam.h"
     76#include "MExtralgoDigitalFilter.h"
    7477
    7578#include "MPedestalPix.h"
     
    8386const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainFirst             =  1;
    8487const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainLast              = 14;
    85 const Int_t  MExtractTimeAndChargeDigitalFilter::fgWindowSizeHiGain        =  4;
    86 const Int_t  MExtractTimeAndChargeDigitalFilter::fgWindowSizeLoGain        =  6;
     88//const Int_t  MExtractTimeAndChargeDigitalFilter::fgWindowSizeHiGain        =  4;
     89//const Int_t  MExtractTimeAndChargeDigitalFilter::fgWindowSizeLoGain        =  6;
    8790const Int_t  MExtractTimeAndChargeDigitalFilter::fgBinningResolutionHiGain = 10;
    8891const Int_t  MExtractTimeAndChargeDigitalFilter::fgBinningResolutionLoGain = 10;
     
    9093const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain    =  4;
    9194const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain           =  0.95;
    92 const Float_t MExtractTimeAndChargeDigitalFilter::fgLoGainStartShift       = -1.8;
     95//const Float_t MExtractTimeAndChargeDigitalFilter::fgLoGainStartShift       = -1.8;
    9396
    9497// --------------------------------------------------------------------------
     
    104107//
    105108MExtractTimeAndChargeDigitalFilter::MExtractTimeAndChargeDigitalFilter(const char *name, const char *title)
    106     : fTimeShiftHiGain(0.), fTimeShiftLoGain(0.), fAutomaticWeights(kTRUE), fRandomIter(0)
     109    : fBinningResolutionHiGain(fgBinningResolutionHiGain),
     110    fBinningResolutionLoGain(fgBinningResolutionLoGain),
     111    fAutomaticWeights(kTRUE), fRandomIter(0)
    107112{
    108113    fName  = name  ? name  : "MExtractTimeAndChargeDigitalFilter";
     
    110115
    111116    SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
    112     SetWindowSize();
    113     SetBinningResolution();
    114     SetSignalStartBin();
     117    SetWindowSize(3, 5);
     118//    SetBinningResolution();
     119//    SetSignalStartBin();
    115120
    116121    SetOffsetLoGain(fgOffsetLoGain);          // Order between both
    117     SetLoGainStartShift(fgLoGainStartShift);  // is important
     122//    SetLoGainStartShift(fgLoGainStartShift);  // is important
    118123}
    119124
     
    121126//
    122127// Checks:
    123 // - if a window is bigger than the one defined by the ranges, set it to the available range
     128// - if a window is bigger than the one defined by the ranges, set it
     129// to the available range
    124130//
    125131// Sets:
    126132// - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain
    127133// - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain
    128 // 
     134//
     135// This function might be used to turn the digital filter into a
     136// sliding window extractor by setting the filename to NULL
     137//
    129138void MExtractTimeAndChargeDigitalFilter::SetWindowSize(Int_t windowh, Int_t windowl)
    130139{
    131 
    132   if (windowh != fgWindowSizeHiGain)
    133     *fLog << warn << GetDescriptor()
    134           << ": ATTENTION!!! If you are not Hendrik Bartko, do NOT use a different window size than the default." << endl;
    135   if (windowl != fgWindowSizeLoGain)
    136     *fLog << warn << GetDescriptor()
    137           << ": ATTENTION!!! If you are not Hendrik Bartko, do NOT use a different window size than the default" << endl;
    138 
    139140  fWindowSizeHiGain = windowh;
    140141  fWindowSizeLoGain = windowl;
     
    184185  // size of 6. The exact numbers have to be found still.
    185186  //
    186   fNumHiGainSamples = fAmpWeightsHiGain.GetSum()/fBinningResolutionHiGain;
    187   fNumLoGainSamples = fAmpWeightsLoGain.GetSum()/fBinningResolutionLoGain;
     187  fNumHiGainSamples  = fWindowSizeHiGain;
     188  fNumLoGainSamples  = fWindowSizeLoGain;
    188189  fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
    189190  fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
     
    191192}
    192193
     194
    193195// --------------------------------------------------------------------------
    194196//
     
    213215//
    214216// If new weights are set
    215 //  fTimeShiftHiGain
    216 //  fTimeShiftLoGain
    217217//  fNumHiGainSamples
    218218//  fNumLoGainSamples
     
    234234
    235235    //
    236     // shift the times back to the right reference (start counting from 0)
     236    // We need here the effective number of samples. In pricipal the number
     237    // is different depending on the weights used and must be set
     238    // event by event.
    237239    //
    238     // The high-gain has the extraction offset (fHiGainFirst) already included
    239     // here for speed reason. The low-gain has a changing extraction offset,
    240     // so it will be added at every event (in FindTimeAndChargeLoGain)
    241     fTimeShiftHiGain = 0.5 + 1./fBinningResolutionHiGain;
    242     fTimeShiftLoGain = 0.5 + 1./fBinningResolutionLoGain;
    243 
    244     //
    245     // We need here the effective number of samples which is about 2.5 in the case of a window
    246     // size of 6. The exact numbers have to be found still.
    247     //
    248     fNumHiGainSamples = (Float_t)fWindowSizeHiGain/2.4;
    249     fNumLoGainSamples = (Float_t)fWindowSizeLoGain/2.4;
     240    fNumHiGainSamples  = fAmpWeightsHiGain.GetSum()/fBinningResolutionHiGain;
     241    fNumLoGainSamples  = fAmpWeightsLoGain.GetSum()/fBinningResolutionLoGain;
    250242    fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
    251243    fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
     
    253245    // From MExtractTimeAndCharge::ReInit
    254246    if (fSignals)
    255         fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
     247        fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast/*+fHiLoLast*/, fNumHiGainSamples,
    256248                                    fLoGainFirst, fLoGainLast, fNumLoGainSamples);
    257249    return kTRUE;
     
    269261        return kFALSE;
    270262
    271     const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
    272     const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1);
    273 
    274     fHiGainSignal.Set(rangehi);
    275     fLoGainSignal.Set(rangelo);
     263    //const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
     264    //const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1);
     265
     266    //cout << "ARRAYS INITIALIZED TO : " << rangehi << " " << rangelo << endl;
     267
     268    //fHiGainSignal.Set(rangehi);
     269    //fLoGainSignal.Set(rangelo);
    276270
    277271    return GetWeights();
     
    295289}
    296290
    297 void MExtractTimeAndChargeDigitalFilter::CalcBinningResArrays()
    298 {
    299 
    300   fArrBinningResHiGain.Set(fWindowSizeHiGain);
    301   fArrBinningResHalfHiGain.Set(fWindowSizeHiGain);
    302 
    303   for (int i=0; i<fWindowSizeHiGain; i++)
    304     {
    305       fArrBinningResHiGain[i] = fBinningResolutionHiGain*i;
    306       fArrBinningResHalfHiGain[i] = fArrBinningResHiGain[i] + fBinningResolutionHalfHiGain;
    307     }
    308 
    309   fArrBinningResLoGain.Set(fWindowSizeLoGain);
    310   fArrBinningResHalfLoGain.Set(fWindowSizeLoGain);
    311  
    312   for (int i=0; i<fWindowSizeLoGain; i++)
    313     {
    314       fArrBinningResLoGain[i] = fBinningResolutionLoGain*i;
    315       fArrBinningResHalfLoGain[i] = fArrBinningResLoGain[i] + fBinningResolutionHalfLoGain;
    316     }
    317 }
    318 
    319291// --------------------------------------------------------------------------
    320292//
    321293// Apply the digital filter algorithm to the high-gain slices.
    322294//
    323 void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Float_t &dsum,
     295void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain2(const Float_t *ptr, Int_t num,
     296                                                                  Float_t &sum, Float_t &dsum,
     297                                                                  Float_t &time, Float_t &dtime,
     298                                                                  Byte_t sat, Int_t maxpos)
     299{
     300    // Do some handling if maxpos is last slice!
     301
     302    MExtralgoDigitalFilter df(fBinningResolutionHiGain, fWindowSizeHiGain,
     303                              fAmpWeightsHiGain.GetArray(),
     304                              fTimeWeightsHiGain.GetArray(),
     305                              fPulseHiGain.GetArray());
     306    df.SetData(num, ptr);
     307
     308    if (IsNoiseCalculation())
     309    {
     310        if (fRandomIter == fBinningResolutionHiGain)
     311            fRandomIter = 0;
     312
     313        sum = df.ExtractNoise(fRandomIter);
     314        fRandomIter++;
     315        return;
     316    }
     317
     318    df.Extract(/*maxpos*/);
     319    df.GetSignal(sum, dsum);
     320    df.GetTime(time, dtime);
     321}
     322
     323void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeLoGain2(const Float_t *ptr, Int_t num,
     324                                                                  Float_t &sum, Float_t &dsum,
     325                                                                  Float_t &time, Float_t &dtime,
     326                                                                  Byte_t sat, Int_t maxpos)
     327{
     328    MExtralgoDigitalFilter df(fBinningResolutionLoGain, fWindowSizeLoGain,
     329                              fAmpWeightsLoGain.GetArray(),
     330                              fTimeWeightsLoGain.GetArray(),
     331                              fPulseLoGain.GetArray());
     332
     333    df.SetData(num, ptr);
     334
     335    if (IsNoiseCalculation())
     336    {
     337        if (fRandomIter == fBinningResolutionLoGain)
     338            fRandomIter = 0;
     339
     340        sum = df.ExtractNoise(fRandomIter);
     341        return;
     342    }
     343
     344    df.Extract(/*maxpos*/);
     345    df.GetSignal(sum, dsum);
     346    df.GetTime(time, dtime);
     347}
     348
     349/*
     350// --------------------------------------------------------------------------
     351//
     352// Apply the digital filter algorithm to the high-gain slices.
     353//
     354void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain(Byte_t *first, Byte_t *logain, Float_t &sum, Float_t &dsum,
    324355                                                                 Float_t &time, Float_t &dtime,
    325356                                                                 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag)
    326357{
    327 
    328   Int_t range = fHiGainLast - fHiGainFirst + 1;
    329  
    330   const Byte_t *end = ptr + range;
    331   Byte_t *p     = ptr;
    332 
    333   //
    334   // Preparations for the pedestal subtraction (with AB-noise correction)
    335   //
    336   const Float_t pedes  = ped.GetPedestal();
    337   const Float_t ABoffs = ped.GetPedestalABoffset();
    338 
    339   const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
    340 
    341   range += fHiLoLast;
    342   fMaxBinContent = 0;
    343   //
    344   // Check for saturation in all other slices
    345   //
    346   Int_t ids = fHiGainFirst;
    347   Float_t *sample = fHiGainSignal.GetArray();
    348   while (p<end)
    349     {
    350       *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
    351 
    352       if (*p > fMaxBinContent)
    353         {
    354           Byte_t maxpos = p-ptr;
    355 
    356           // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
    357           if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
    358             fMaxBinContent = *p;
    359         }
    360 
    361       if (*p++ >= fSaturationLimit)
    362         if (!sat)
    363           sat = ids-fHiGainFirst;
    364     }
    365 
    366   //
    367   // Slide with a window of size fWindowSizeHiGain over the sample
    368   // and multiply the entries with the corresponding weights
    369   //
    370   if (IsNoiseCalculation())
    371     {
    372       if (fRandomIter == fBinningResolutionHiGain)
    373         fRandomIter = 0;
    374       for (Int_t ids=0; ids < fWindowSizeHiGain; ids++)
     358    Int_t range = fHiGainLast - fHiGainFirst + 1;
     359    const Byte_t *end = first + range;
     360    Byte_t       *p  = first;
     361
     362    const Float_t pedes  = ped.GetPedestal();
     363    const Float_t ABoffs = ped.GetPedestalABoffset();
     364
     365    const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
     366
     367    Byte_t maxcont = 0;
     368    Int_t  maxpos  = 0;  // obsolete for Digital Filter (used in spline!)
     369    sat = 0;
     370
     371    //
     372    // Check for saturation in all other slices
     373    //
     374    Int_t ids = fHiGainFirst;
     375    Float_t *sample = fHiGainSignal.GetArray();
     376
     377    while (p<end)
     378    {
     379        *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
     380
     381        if (*p > maxcont)
    375382        {
    376           const Int_t   idx = fArrBinningResHiGain[ids] + fRandomIter;
    377           sum              += fAmpWeightsHiGain [idx]*fHiGainSignal[ids];
     383            maxpos = ids-fHiGainFirst-1;
     384            // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
     385            //if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
     386            if (maxpos > 1 && maxpos < (range-1*//* - fWindowSizeHiGain + 1*//*))
     387                maxcont = *p;
    378388        }
    379       fRandomIter++;
    380       return;
    381     }
    382  
    383   if (fHiLoLast != 0)
    384     {
    385 
    386       end = logain + fHiLoLast;
    387 
    388       while (logain<end)
     389
     390        if (*p++ >= fSaturationLimit)
     391            if (!sat)
     392                sat = ids-fHiGainFirst;
     393    }
     394
     395    if (fHiLoLast != 0)
     396    {
     397        end = logain + fHiLoLast;
     398
     399        while (logain<end)
    389400        {
    390 
    391           *sample++ = (Float_t)*logain - pedmean[(ids++ + abflag) & 0x1];
    392 
    393           if (*logain++ >= fSaturationLimit)
    394             if (!sat)
    395               sat = ids-fHiGainFirst;
     401            *sample++ = (Float_t)*logain - pedmean[(ids++ + abflag) & 0x1];
     402
     403            if (*logain > maxcont)
     404            {
     405                maxpos = ids-fHiGainFirst-1;
     406
     407                // FIXME!!! MUST BE THERE!
     408                // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
     409                //if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
     410                //    maxcont = *logain;
     411            }
     412
     413            if (*logain++ >= fSaturationLimit)
     414                if (!sat)
     415                    sat = ids-fHiGainFirst;
     416
     417            range++;
    396418        }
    397419    }
    398420
    399   //
    400   // allow no saturated slice
    401   //
    402   //  if (sat > 0)
    403   //    return;
    404  
    405   Float_t time_sum  = 0.;
    406   Float_t fmax      = -FLT_MAX;
    407   Float_t ftime_max = 0.;
    408   Int_t   max_p     = -1;
    409  
    410   //
    411   // Calculate the sum of the first fWindowSize slices
    412   //
    413   for (Int_t i=0;i<range-fWindowSizeHiGain+1;i++)
    414     {
    415       sum      = 0.;
    416       time_sum = 0.;
    417 
    418       //
    419       // Slide with a window of size fWindowSizeHiGain over the sample
    420       // and multiply the entries with the corresponding weights
    421       //
    422       for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
    423       {
    424         const Int_t   idx = fBinningResolutionHiGain*sample+fBinningResolutionHalfHiGain;
    425         const Float_t pex = fHiGainSignal[sample+i];
    426         sum              += fAmpWeightsHiGain [idx]*pex;
    427         time_sum         += fTimeWeightsHiGain[idx]*pex;
    428       }
    429 
    430       if (sum>fmax)
    431       {
    432         fmax      = sum;
    433         ftime_max = time_sum;
    434         max_p     = i;
    435       }
    436     } /*   for (Int_t i=0;i<range-fWindowSizeHiGain+1;i++) */
    437 
    438   if (max_p<0)
    439   {
    440       sum = 0;
    441       time = -1;
    442       dsum = -1;
    443       dtime = -1;
    444       return;
    445   }
    446 
    447   if (fmax==0)
    448   {
    449       sum = 0;
    450       time = -1;
    451       dsum = 0;
    452       dtime = 0;
    453       return;
    454   }
    455 
    456   ftime_max        /= fmax;
    457   Int_t t_iter      = Int_t(ftime_max*fBinningResolutionHiGain);
    458   Int_t sample_iter = 0;
    459 
    460   while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain )
    461     {
    462       if (t_iter > fBinningResolutionHalfHiGain-1)
    463         {
    464           t_iter -= fBinningResolutionHiGain;
    465           max_p--;
    466           sample_iter--;
    467         }
    468       if (t_iter < -fBinningResolutionHalfHiGain)
    469         {
    470           t_iter += fBinningResolutionHiGain;
    471           max_p++;
    472           sample_iter++;
    473         }
    474     }
    475 
    476   sum = 0.;
    477   time_sum = 0.;
    478   if (max_p < 0)
    479     max_p = 0;
    480   if (max_p+fWindowSizeHiGain > range)
    481     max_p = range-fWindowSizeHiGain;
    482   //
    483   // Slide with a window of size fWindowSizeHiGain over the sample
    484   // and multiply the entries with the corresponding weights
    485   //
    486   for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
    487   {
    488     const Int_t   idx = fArrBinningResHalfHiGain[sample] + t_iter;
    489     const Int_t   ids = max_p + sample;
    490     const Float_t pex = fHiGainSignal[ids];
    491     sum              += fAmpWeightsHiGain [idx]*pex;
    492     time_sum         += fTimeWeightsHiGain[idx]*pex;
    493   }
    494 
    495   if (sum == 0)
    496   {
    497       time = -1;
    498       dsum = 0;
    499       dtime = 0;
    500       return;
    501   }
    502 
    503   // here, the first high-gain slice is already included in the fTimeShiftHiGain
    504 //  time = fTimeShiftHiGain + max_p - Float_t(t_iter)/fBinningResolutionHiGain;
    505   time = max_p + fTimeShiftHiGain + (Float_t)fHiGainFirst /* this shifts the time to the start of the rising edge */
    506       - ((Float_t)t_iter)/fBinningResolutionHiGain;
    507 
    508   const Float_t timefineadjust = time_sum/sum;
    509  
    510   if (TMath::Abs(timefineadjust) < 4./fBinningResolutionHiGain)
    511     time -= timefineadjust;
    512 
     421    FindTimeAndChargeHiGain2(fHiGainSignal.GetArray(), range,
     422                             sum, dsum, time, dtime,
     423                             sat, 0);
    513424}
    514425
     
    521432                                                                 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag)
    522433{
    523 
    524   const Int_t range = fLoGainLast - fLoGainFirst + 1;
    525 
    526   const Byte_t *end = ptr + range;
    527   Byte_t *p     = ptr;
    528   //
    529   // Prepare the low-gain pedestal
    530   //
    531   const Float_t pedes  = ped.GetPedestal();
    532   const Float_t ABoffs = ped.GetPedestalABoffset();
    533        
    534   const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
    535 
    536   //
    537   // Check for saturation in all other slices
    538   //
    539   Float_t *sample = fLoGainSignal.GetArray();
    540   Int_t    ids    = fLoGainFirst;
    541   while (p<end)
    542     {
    543       *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
    544 
    545       if (*p++ >= fSaturationLimit)
    546         sat++;
    547     }
    548 
    549   //
    550   // Slide with a window of size fWindowSizeLoGain over the sample
    551   // and multiply the entries with the corresponding weights
    552   //
    553   if (IsNoiseCalculation())
    554     {
    555       if (fRandomIter == fBinningResolutionLoGain)
    556         fRandomIter = 0;
    557       for (Int_t ids=0; ids < fWindowSizeLoGain; ids++)
    558         {
    559           const Int_t   idx = fArrBinningResLoGain[ids] + fRandomIter;
    560           sum              += fAmpWeightsLoGain [idx]*fLoGainSignal[ids];
    561         }
    562       return;
    563     }
    564 
    565   Float_t time_sum  = 0.;
    566   Float_t fmax      = -FLT_MAX;
    567   Float_t ftime_max = 0.;
    568   Int_t   max_p     = -1;
    569  
    570   //
    571   // Calculate the sum of the first fWindowSize slices
    572   //
    573   for (Int_t i=0;i<range-fWindowSizeLoGain+1;i++)
    574     {
    575       sum      = 0.;
    576       time_sum = 0.;
    577      
    578       //
    579       // Slide with a window of size fWindowSizeLoGain over the sample
    580       // and multiply the entries with the corresponding weights
    581       //
    582       for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
    583       {
    584         const Int_t   idx = fArrBinningResHalfLoGain[sample];
    585         const Float_t pex = fLoGainSignal[sample+i];
    586         sum              += fAmpWeightsLoGain [idx]*pex;
    587         time_sum         += fTimeWeightsLoGain[idx]*pex;
    588       }
    589 
    590       if (sum>fmax)
    591       {
    592         fmax      = sum;
    593         ftime_max = time_sum;
    594         max_p     = i;
    595       }
    596     } /*   for (Int_t i=0;i<range-fWindowSizeLoGain+1;i++) */
    597 
    598   if (max_p<0)
    599   {
    600       sum = 0;
    601       time = -1;
    602       dsum = -1;
    603       dtime = -1;
    604       return;
    605   }
    606 
    607   if (fmax==0)
    608   {
    609       sum = 0;
    610       time = -1;
    611       dsum = 0;
    612       dtime = 0;
    613       return;
    614   }
    615 
    616   ftime_max        /= fmax;
    617   Int_t t_iter      = Int_t(ftime_max*fBinningResolutionLoGain);
    618   Int_t sample_iter = 0;
    619 
    620   while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain )
    621     {
    622       if (t_iter > fBinningResolutionHalfLoGain-1)
    623         {
    624           t_iter -= fBinningResolutionLoGain;
    625           max_p--;
    626           sample_iter--;
    627         }
    628       if (t_iter < -fBinningResolutionHalfLoGain)
    629         {
    630           t_iter += fBinningResolutionLoGain;
    631           max_p++;
    632           sample_iter++;
    633         }
    634     }
    635  
    636   sum = 0.;
    637   time_sum = 0.;
    638 
    639   //
    640   // Slide with a window of size fWindowSizeLoGain over the sample
    641   // and multiply the entries with the corresponding weights
    642   //
    643   for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
    644   {
    645     const Int_t   idx = fArrBinningResHalfLoGain[sample] + t_iter;
    646     const Int_t   ids = max_p + sample;
    647     const Float_t pex = ids < 0 ? 0. : ( ids >= range ? 0. : fLoGainSignal[ids]);
    648     sum              += fAmpWeightsLoGain [idx]*pex;
    649     time_sum         += fTimeWeightsLoGain[idx]*pex;
    650   }
    651 
    652   if (sum == 0)
    653   {
    654       time = -1;
    655       dsum = 0;
    656       dtime = 0;
    657       return;
    658   }
    659 
    660   time = max_p + fTimeShiftLoGain + (Float_t)fLoGainFirst /* this shifts the time to the start of the rising edge */
    661       - ((Float_t)t_iter)/fBinningResolutionLoGain;
    662 
    663   const Float_t timefineadjust = time_sum/sum;
    664  
    665   if (TMath::Abs(timefineadjust) < 4./fBinningResolutionLoGain)
    666     time -= timefineadjust;
    667 
    668 }
    669 
     434    const Int_t range = fLoGainLast - fLoGainFirst + 1;
     435
     436    const Byte_t *end = ptr + range;
     437    Byte_t *p     = ptr;
     438
     439    //
     440    // Prepare the low-gain pedestal
     441    //
     442    const Float_t pedes  = ped.GetPedestal();
     443    const Float_t ABoffs = ped.GetPedestalABoffset();
     444
     445    const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
     446
     447    //
     448    // Check for saturation in all other slices
     449    //
     450    Float_t *sample = fLoGainSignal.GetArray();
     451    Int_t    ids    = fLoGainFirst;
     452
     453    while (p<end)
     454    {
     455        *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
     456
     457        if (*p++ >= fSaturationLimit)
     458            sat++;
     459    }
     460
     461    FindTimeAndChargeLoGain2(fLoGainSignal.GetArray(), range,
     462                             sum, dsum, time, dtime,
     463                             sat, 0);
     464
     465}
     466*/
    670467// --------------------------------------------------------------------------
    671468//
     
    681478{
    682479
    683   Byte_t hw = fWindowSizeHiGain;
    684   Byte_t lw = fWindowSizeLoGain;
    685480  Bool_t rc = kFALSE;
    686481
     
    690485      rc = kTRUE;
    691486  }
     487   /*
     488  Byte_t hw = fWindowSizeHiGain;
     489  Byte_t lw = fWindowSizeLoGain;
    692490
    693491  if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
     
    704502  if (rc)
    705503    SetWindowSize(hw, lw);
    706  
     504
    707505  Bool_t rc2 = kFALSE;
    708506  Int_t brh = fBinningResolutionHiGain;
     
    725523      rc = kTRUE;
    726524    }
    727  
     525   */
    728526  if (IsEnvDefined(env, prefix, "WeightsFile", print))
    729527    {
     
    823621            }
    824622
    825             if (2!=sscanf(str.Data(), "# High Gain Weights:%2i %2i", &fWindowSizeHiGain, &fBinningResolutionHiGain))
     623            if (2!=sscanf(str.Data(), "# High Gain Weights: %2i %2i", &fWindowSizeHiGain, &fBinningResolutionHiGain))
    826624            {
    827625                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
     
    833631            fAmpWeightsHiGain .Set(len);
    834632            fTimeWeightsHiGain.Set(len);
     633            fPulseHiGain.Set(len);
    835634            hi = kTRUE;
    836635            continue;
     
    845644            }
    846645
    847             if (2!=sscanf(str.Data(),"# Low Gain Weights:%2i %2i", &fWindowSizeLoGain, &fBinningResolutionLoGain))
     646            if (2!=sscanf(str.Data(),"# Low Gain Weights: %2i %2i", &fWindowSizeLoGain, &fBinningResolutionLoGain))
    848647            {
    849648                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
     
    855654            fAmpWeightsLoGain .Set(len);
    856655            fTimeWeightsLoGain.Set(len);
     656            fPulseLoGain.Set(len);
    857657            lo = kTRUE;
    858658            continue;
     
    867667            continue;
    868668
    869         if (2!=sscanf(str.Data(), "%f %f",
     669        if (3!=sscanf(str.Data(), "%f %f %f",
    870670                      lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt],
    871                       lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt]))
     671                      lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt],
     672                      lo ? &fPulseLoGain[cnt] : &fPulseHiGain[cnt]))
    872673        {
    873674            *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
     
    903704    *fLog << "with a resolution of " << fBinningResolutionLoGain << endl;
    904705
    905     CalcBinningResArrays();
     706    //CalcBinningResArrays();
    906707
    907708    switch (fWindowSizeHiGain)
     
    1058859    return ReadWeightsFile(name, path);
    1059860}
    1060 
     861/*
    1061862//----------------------------------------------------------------------------
    1062863//
     
    1125926  Int_t start = fBinningResolutionHiGain*(fSignalStartBinHiGain + 1);
    1126927
    1127   for (Int_t i = -fBinningResolutionHalfHiGain+1; i<=fBinningResolutionHalfHiGain; i++)
     928  for (Int_t i = -fBinningResolutionHiGain/2+1; i<=fBinningResolutionHiGain/2; i++)
    1128929    {
    1129930 
     
    1178979      for (Int_t count=0; count < fWindowSizeHiGain; count++)
    1179980        {
    1180           const Int_t idx = i+fBinningResolutionHalfHiGain+fBinningResolutionHiGain*count-1;
     981          const Int_t idx = i+fBinningResolutionHiGain/2+fBinningResolutionHiGain*count-1;
    1181982          fAmpWeightsHiGain [idx] = w_amp [0][count];
    1182983          fTimeWeightsHiGain[idx] = w_time[0][count];
     
    12461047      // Loop over relative time in one BinningResolution interval
    12471048      //
    1248       Int_t start = fBinningResolutionLoGain*fSignalStartBinLoGain + fBinningResolutionHalfLoGain;
    1249      
    1250       for (Int_t i = -fBinningResolutionHalfLoGain+1; i<=fBinningResolutionHalfLoGain; i++)
     1049      Int_t start = fBinningResolutionLoGain*fSignalStartBinLoGain + fBinningResolutionLoGain/2;
     1050     
     1051      for (Int_t i = -fBinningResolutionLoGain/2+1; i<=fBinningResolutionLoGain/2; i++)
    12511052        {
    12521053         
     
    13011102          for (Int_t count=0; count < fWindowSizeLoGain; count++)
    13021103            {
    1303               const Int_t idx = i+fBinningResolutionHalfLoGain+fBinningResolutionLoGain*count-1;
     1104              const Int_t idx = i+fBinningResolutionLoGain/2+fBinningResolutionLoGain*count-1;
    13041105              fAmpWeightsLoGain [idx] = w_amp [0][count];
    13051106              fTimeWeightsLoGain[idx] = w_time[0][count];
     
    13291130  return kTRUE;
    13301131}
    1331 
     1132*/
    13321133void MExtractTimeAndChargeDigitalFilter::Print(Option_t *o) const
    13331134{
     
    13361137
    13371138    MExtractTimeAndCharge::Print(o);
    1338     *fLog << " Time Shift  HiGain: " << fTimeShiftHiGain         << "  LoGain: " << fTimeShiftLoGain << endl;
    13391139    *fLog << " Window Size HiGain: " << fWindowSizeHiGain        << "  LoGain: " << fWindowSizeLoGain << endl;
    13401140    *fLog << " Binning Res HiGain: " << fBinningResolutionHiGain << "  LoGain: " << fBinningResolutionHiGain << endl;
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h

    r7194 r8154  
    2222{
    2323private:
    24   static const Byte_t fgHiGainFirst;             //! Default for fHiGainFirst       (now set to: 0)
    25   static const Byte_t fgHiGainLast;              //! Default for fHiGainLast        (now set to:14)
    26   static const Byte_t fgLoGainFirst;             //! Default for fLoGainFirst       (now set to: 3)
    27   static const Byte_t fgLoGainLast;              //! Default for fLoGainLast        (now set to:14)
    28   static const Int_t  fgWindowSizeHiGain;        //! Default for fWindowSizeHiGain  (now set to: 6)
    29   static const Int_t  fgWindowSizeLoGain;        //! Default for fWindowSizeLoGain  (now set to: 6)
    30   static const Int_t  fgBinningResolutionHiGain; //! Default for fBinningResolutionHiGain (now set to: 10)
    31   static const Int_t  fgBinningResolutionLoGain; //! Default for fBinningResolutionLoGain (now set to: 10)
    32   static const Int_t  fgSignalStartBinHiGain;    //! Default for fSignalStartBinHiGain (now set to: 4)
    33   static const Int_t  fgSignalStartBinLoGain;    //! Default for fSignalStartBinLoGain (now set to: 4)
    34   static const TString fgNameWeightsFile;        //! "cosmics_weights.dat"
    35   static const Float_t fgOffsetLoGain;           //! Default for fOffsetLoGain (now set to 1.7)
    36   static const Float_t fgLoGainStartShift;       //! Default for fLoGainStartShift (now set to -1.8)
     24    static const Byte_t fgHiGainFirst;             //! Default for fHiGainFirst       (now set to: 0)
     25    static const Byte_t fgHiGainLast;              //! Default for fHiGainLast        (now set to:14)
     26    static const Byte_t fgLoGainFirst;             //! Default for fLoGainFirst       (now set to: 3)
     27    static const Byte_t fgLoGainLast;              //! Default for fLoGainLast        (now set to:14)
     28//    static const Int_t  fgWindowSizeHiGain;        //! Default for fWindowSizeHiGain  (now set to: 6)
     29//    static const Int_t  fgWindowSizeLoGain;        //! Default for fWindowSizeLoGain  (now set to: 6)
     30    static const Int_t  fgBinningResolutionHiGain; //! Default for fBinningResolutionHiGain (now set to: 10)
     31    static const Int_t  fgBinningResolutionLoGain; //! Default for fBinningResolutionLoGain (now set to: 10)
     32    static const Int_t  fgSignalStartBinHiGain;    //! Default for fSignalStartBinHiGain (now set to: 4)
     33    static const Int_t  fgSignalStartBinLoGain;    //! Default for fSignalStartBinLoGain (now set to: 4)
     34    static const TString fgNameWeightsFile;        //! "cosmics_weights.dat"
     35    static const Float_t fgOffsetLoGain;           //! Default for fOffsetLoGain (now set to 1.7)
     36//    static const Float_t fgLoGainStartShift;       //! Default for fLoGainStartShift (now set to -1.8)
    3737
    38   MCalibrationPattern  *fCalibPattern;          //! Calibration DM pattern
    39  
    40   MArrayF fHiGainSignal;                        //! Need fast access to the signals in a float way
    41   MArrayF fLoGainSignal;                        //! Store them in separate arrays
     38    MCalibrationPattern  *fCalibPattern;          //! Calibration DM pattern
    4239
    43   MArrayI fArrBinningResHiGain;                 //! helping arrays to hold binningres * i
    44   MArrayI fArrBinningResLoGain;                 //! helping arrays to hold binningres * i
    45   MArrayI fArrBinningResHalfHiGain;             //! helping arrays to hold binningres * i + binningreshalf
    46   MArrayI fArrBinningResHalfLoGain;             //! helping arrays to hold binningres * i + binningreshalf
    47  
    48   Float_t fTimeShiftHiGain;                     //  Time shift from when on to apply the filter
    49   Float_t fTimeShiftLoGain;                     //  Time shift from when on to apply the filter
    50  
    51   Int_t   fSignalStartBinHiGain;                //! Start bin from when on to apply weights
    52   Int_t   fSignalStartBinLoGain;                //! Start bin from when on to apply weights
     40//    MArrayF fHiGainSignal;                        //! Need fast access to the signals in a float way
     41//    MArrayF fLoGainSignal;                        //! Store them in separate arrays
    5342
    54   Int_t   fBinningResolutionHiGain;             //  Number of weights per bin High-Gain
    55   Int_t   fBinningResolutionHalfHiGain;         //  Half Number of weights per bin High-Gain
    56   Int_t   fBinningResolutionLoGain;             //  Number of weights per bin Low-Gain
    57   Int_t   fBinningResolutionHalfLoGain;         //  Half Number of weights per bin Low-Gain
    58  
    59   MArrayF fAmpWeightsHiGain;                    //! Amplitude weights High-Gain (from weights file)
    60   MArrayF fTimeWeightsHiGain;                   //! Time weights High-Gain (from weights file)
    61   MArrayF fAmpWeightsLoGain;                    //! Amplitude weights Low-Gain (from weights file)
    62   MArrayF fTimeWeightsLoGain;                   //! Time weights Low-Gain (from weights file)
     43//    Int_t   fSignalStartBinHiGain;                //! Start bin from when on to apply weights
     44//    Int_t   fSignalStartBinLoGain;                //! Start bin from when on to apply weights
    6345
    64   TString fNameWeightsFile;                     // Name of the weights file
    65   Bool_t  fAutomaticWeights;                    // Flag whether weight should be determined automatically
    66   TString fNameWeightsFileSet;                  //! Flag if weights have alreayd been set
    67   Int_t   fRandomIter;                          //! Counter used to randomize weights for noise calculation
     46    Int_t   fBinningResolutionHiGain;             //  Number of weights per bin High-Gain
     47    Int_t   fBinningResolutionLoGain;             //  Number of weights per bin Low-Gain
    6848
    69   // MExtractTimeAndChargeDigitalFilter
    70   void    CalcBinningResArrays();
    71   Int_t   GetAutomaticWeights();
    72   Bool_t  GetWeights();
    73   Int_t   ReadWeightsFile(TString filename, TString path="");
    74   TString CompileWeightFileName(TString path, const TString &name) const;
     49    MArrayF fAmpWeightsHiGain;                    //! Amplitude weights High-Gain (from weights file)
     50    MArrayF fTimeWeightsHiGain;                   //! Time weights High-Gain (from weights file)
     51    MArrayF fAmpWeightsLoGain;                    //! Amplitude weights Low-Gain (from weights file)
     52    MArrayF fTimeWeightsLoGain;                   //! Time weights Low-Gain (from weights file)
    7553
    76   // MExtractTimeAndCharge
    77   Bool_t InitArrays();
     54    MArrayF fPulseHiGain;                    //!
     55    MArrayF fPulseLoGain;                    //!
    7856
    79   // MTask
    80   Int_t PreProcess(MParList *pList);
    81   Int_t Process();
     57    TString fNameWeightsFile;                     // Name of the weights file
     58    Bool_t  fAutomaticWeights;                    // Flag whether weight should be determined automatically
     59    TString fNameWeightsFileSet;                  //! Flag if weights have alreayd been set
     60    Int_t   fRandomIter;                          //! Counter used to randomize weights for noise calculation
     61
     62    // MExtractTimeAndChargeDigitalFilter
     63    void    CalcBinningResArrays();
     64    Int_t   GetAutomaticWeights();
     65    Bool_t  GetWeights();
     66    Int_t   ReadWeightsFile(TString filename, TString path="");
     67    TString CompileWeightFileName(TString path, const TString &name) const;
     68
     69
     70    // MExtractTimeAndCharge
     71    Bool_t InitArrays();
     72
     73    // MTask
     74    Int_t PreProcess(MParList *pList);
     75    Int_t Process();
    8276
    8377protected:
    84   // MParContainer
    85   Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
     78    // MParContainer
     79    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    8680
    8781public:
    88   MExtractTimeAndChargeDigitalFilter(const char *name=NULL, const char *title=NULL);
    89   ~MExtractTimeAndChargeDigitalFilter() { }
     82    MExtractTimeAndChargeDigitalFilter(const char *name=NULL, const char *title=NULL);
     83    ~MExtractTimeAndChargeDigitalFilter() { }
     84/*
     85    Bool_t WriteWeightsFile(TString filename,
     86                            TH1F *shapehi, TH2F *autocorrhi,
     87                            TH1F *shapelo=NULL, TH2F *autocorrlo=NULL );
    9088
    91   Bool_t WriteWeightsFile(TString filename,
    92                           TH1F *shapehi, TH2F *autocorrhi,
    93                           TH1F *shapelo=NULL, TH2F *autocorrlo=NULL );
     89  */
     90    void SetNameWeightsFile(TString s="")
     91    {
     92        s.ReplaceAll("\015", ""); // This is a fix for TEnv files edited with windows editors
     93        fNameWeightsFile = s;
     94        fNameWeightsFileSet="";
     95    }
    9496
     97    void EnableAutomaticWeights(Bool_t b=kTRUE) { fAutomaticWeights = b; }
    9598
    96   void SetNameWeightsFile(TString s="") { s.ReplaceAll("\015", ""); // This is a fix for TEnv files edited with windows editors
    97       fNameWeightsFile = s; fNameWeightsFileSet=""; }
    98   void EnableAutomaticWeights(Bool_t b=kTRUE) { fAutomaticWeights = b; }
     99    void SetBinningResolution(const Int_t rh=fgBinningResolutionHiGain, const Int_t rl=fgBinningResolutionLoGain)
     100    {
     101        fBinningResolutionHiGain = rh & ~1;
     102        fBinningResolutionLoGain = rl & ~1;
     103    }
     104/*
     105    void SetSignalStartBin( const Int_t sh=fgSignalStartBinHiGain, const Int_t sl=fgSignalStartBinLoGain)
     106    {
     107        fSignalStartBinHiGain = sh;
     108        fSignalStartBinLoGain = sl;
     109    }
    99110
    100   void SetBinningResolution(const Int_t rh=fgBinningResolutionHiGain, const Int_t rl=fgBinningResolutionLoGain)  {
    101     fBinningResolutionHiGain     = rh & ~1;
    102     fBinningResolutionHalfHiGain = fBinningResolutionHiGain/2;
    103     fBinningResolutionLoGain     = rl & ~1;
    104     fBinningResolutionHalfLoGain = fBinningResolutionLoGain/2;
    105   }
    106  
    107   void SetSignalStartBin( const Int_t sh=fgSignalStartBinHiGain, const Int_t sl=fgSignalStartBinLoGain) {
    108     fSignalStartBinHiGain = sh;
    109     fSignalStartBinLoGain = sl;
    110   }
     111 */
     112    void SetWindowSize( Int_t windowh, Int_t windowl);
     113    const char* GetNameWeightsFile() const  { return fNameWeightsFile.Data(); }
    111114
    112   void SetWindowSize( Int_t windowh=fgWindowSizeHiGain, Int_t windowl=fgWindowSizeLoGain);
     115    void Print(Option_t *o="") const; //*MENU*
     116/*
     117    void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
     118                                 Float_t &time, Float_t &dtime,
     119                                 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
     120    void FindTimeAndChargeLoGain(Byte_t *firstused, Float_t &sum,  Float_t &dsum,
     121                                 Float_t &time, Float_t &dtime,
     122                                 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
     123 */
     124    void FindTimeAndChargeHiGain2(const Float_t *firstused, Int_t num, Float_t &sum, Float_t &dsum,
     125                                  Float_t &time, Float_t &dtime,
     126                                  Byte_t sat, Int_t maxpos);
    113127
    114   const char* GetNameWeightsFile() const  { return fNameWeightsFile.Data(); }
     128    void FindTimeAndChargeLoGain2(const Float_t *firstused, Int_t num, Float_t &sum,  Float_t &dsum,
     129                                  Float_t &time, Float_t &dtime,
     130                                  Byte_t sat, Int_t maxpos);
    115131
    116   void Print(Option_t *o="") const; //*MENU*
    117 
    118   void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
    119                                Float_t &time, Float_t &dtime,
    120                                Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
    121   void FindTimeAndChargeLoGain(Byte_t *firstused, Float_t &sum,  Float_t &dsum,
    122                                Float_t &time, Float_t &dtime,
    123                                Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
    124  
    125   ClassDef(MExtractTimeAndChargeDigitalFilter, 2)   // Hendrik's digital filter
     132    ClassDef(MExtractTimeAndChargeDigitalFilter, 2)   // Hendrik's digital filter
    126133};
    127134
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc

    r7930 r8154  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndChargeSpline.cc,v 1.61 2006-10-24 08:24:52 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    1517! *
    1618!
    17 !   Author(s): Markus Gaug       09/2004 <mailto:markus@ifae.es>
     19!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzbrug.de>
     20!   Author(s): Markus Gaug 09/2004 <mailto:markus@ifae.es>
    1821!
    19 !   Copyright: MAGIC Software Development, 2002-2004
     22!   Copyright: MAGIC Software Development, 2002-2006
    2023!
    2124!
     
    142145#include "MExtractTimeAndChargeSpline.h"
    143146
     147#include "MExtralgoSpline.h"
     148
    144149#include "MPedestalPix.h"
    145150
     
    156161const Byte_t  MExtractTimeAndChargeSpline::fgLoGainLast       = 14;
    157162const Float_t MExtractTimeAndChargeSpline::fgResolution       = 0.05;
    158 const Float_t MExtractTimeAndChargeSpline::fgRiseTimeHiGain   = 0.5;
    159 const Float_t MExtractTimeAndChargeSpline::fgFallTimeHiGain   = 0.5;
     163const Float_t MExtractTimeAndChargeSpline::fgRiseTimeHiGain   = 0.7;
     164const Float_t MExtractTimeAndChargeSpline::fgFallTimeHiGain   = 1.0;
    160165const Float_t MExtractTimeAndChargeSpline::fgLoGainStretch    = 1.5;
    161166const Float_t MExtractTimeAndChargeSpline::fgOffsetLoGain     = 1.3;
    162 const Float_t MExtractTimeAndChargeSpline::fgLoGainStartShift = -2.4;
     167//const Float_t MExtractTimeAndChargeSpline::fgLoGainStartShift = -2.4;
    163168
    164169// --------------------------------------------------------------------------
     
    177182//
    178183MExtractTimeAndChargeSpline::MExtractTimeAndChargeSpline(const char *name, const char *title)
    179     : fAbMax(0.), fAbMaxPos(0.), fHalfMax(0.),
    180       fRandomIter(0), fExtractionType(kIntegral)
     184    : fRandomIter(0), fExtractionType(kIntegral)
    181185{
    182186
     
    187191  SetLoGainStretch();
    188192  SetOffsetLoGain(fgOffsetLoGain);
    189   SetLoGainStartShift(fgLoGainStartShift);
     193//  SetLoGainStartShift(fgLoGainStartShift);
    190194
    191195  SetRiseTimeHiGain();
     
    310314{
    311315
    312   Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
    313 
    314   fHiGainSignal     .Set(range);
     316  Int_t range = fHiGainLast - fHiGainFirst + 1;// + fHiLoLast;
     317
     318//  fHiGainSignal     .Set(range);
    315319  fHiGainFirstDeriv .Set(range);
    316320  fHiGainSecondDeriv.Set(range);
     
    318322  range = fLoGainLast - fLoGainFirst + 1;
    319323
    320   fLoGainSignal     .Set(range);
     324//  fLoGainSignal     .Set(range);
    321325  fLoGainFirstDeriv .Set(range);
    322326  fLoGainSecondDeriv.Set(range);
    323327
    324   fHiGainSignal     .Reset();
     328//  fHiGainSignal     .Reset();
    325329  fHiGainFirstDeriv .Reset();
    326330  fHiGainSecondDeriv.Reset();
    327331
    328   fLoGainSignal     .Reset();
     332//  fLoGainSignal     .Reset();
    329333  fLoGainFirstDeriv .Reset();
    330334  fLoGainSecondDeriv.Reset();
     
    361365}
    362366
     367void MExtractTimeAndChargeSpline::FindTimeAndChargeHiGain2(const Float_t *ptr, Int_t num,
     368                                                           Float_t &sum, Float_t &dsum,
     369                                                           Float_t &time, Float_t &dtime,
     370                                                           Byte_t sat, Int_t maxpos)
     371{
     372    //    const Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
     373
     374    // Do some handling if maxpos is last slice!
     375
     376    MExtralgoSpline s(ptr, num, fHiGainFirstDeriv.GetArray(), fHiGainSecondDeriv.GetArray());
     377
     378    s.SetRiseFallTime(fRiseTimeHiGain, fFallTimeHiGain);
     379    s.SetResolution(fResolution);
     380
     381    if (IsNoiseCalculation())
     382    {
     383        if (fRandomIter == int(1./fResolution))
     384            fRandomIter = 0;
     385
     386        sum = s.ExtractNoise(fRandomIter);
     387        fRandomIter++;
     388        return;
     389    }
     390
     391    s.Extract(sat, maxpos);
     392    s.GetTime(time, dtime);
     393    s.GetSignal(sum, dsum);
     394}
     395
     396void MExtractTimeAndChargeSpline::FindTimeAndChargeLoGain2(const Float_t *ptr, Int_t num,
     397                                                           Float_t &sum,  Float_t &dsum,
     398                                                           Float_t &time, Float_t &dtime,
     399                                                           Byte_t sat, Int_t maxpos)
     400{
     401    MExtralgoSpline s(ptr, num, fLoGainFirstDeriv.GetArray(), fLoGainSecondDeriv.GetArray());
     402
     403    s.SetRiseFallTime(fRiseTimeLoGain, fFallTimeLoGain);
     404    s.SetResolution(fResolution);
     405
     406    if (IsNoiseCalculation())
     407    {
     408        if (fRandomIter == int(1./fResolution))
     409            fRandomIter = 0;
     410
     411        sum = s.ExtractNoise(fRandomIter);
     412        return;
     413    }
     414
     415    s.Extract(sat, maxpos);
     416    s.GetTime(time, dtime);
     417    s.GetSignal(sum, dsum);
     418}
     419
    363420// --------------------------------------------------------------------------
    364421//
    365 // Calculates the arrival time and charge for each pixel
    366 //
    367 void MExtractTimeAndChargeSpline::FindTimeAndChargeHiGain(Byte_t *first, Byte_t *logain, Float_t &sum, Float_t &dsum,
     422// Calculates the arrival time and charge for each pixel
     423//
     424/*
     425void MExtractTimeAndChargeSpline::FindTimeAndChargeHiGain(Byte_t *first, Byte_t *logain, Float_t &sum, Float_t &dsum,
    368426                                                          Float_t &time, Float_t &dtime,
    369427                                                          Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag)
    370428{
    371   Int_t range = fHiGainLast - fHiGainFirst + 1;
    372   const Byte_t *end = first + range;
    373   Byte_t       *p  = first;
    374 
    375   sat = 0;
    376   dsum = 0; // In all cases the extracted signal is valid
    377 
    378   const Float_t pedes  = ped.GetPedestal();
    379   const Float_t ABoffs = ped.GetPedestalABoffset();
    380 
    381   const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
    382 
    383   fAbMax         = 0.;
    384   fAbMaxPos      = 0.;
    385   fHalfMax       = 0.;
    386   fMaxBinContent = 0;
    387   Int_t  maxpos  = 0;
    388 
    389   //
    390   // Check for saturation in all other slices
    391   //
    392   Int_t ids = fHiGainFirst;
    393   Float_t *sample = fHiGainSignal.GetArray();
    394   while (p<end)
    395     {
    396 
    397       *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
    398 
    399       if (*p > fMaxBinContent)
     429    Int_t range = fHiGainLast - fHiGainFirst + 1;
     430    const Byte_t *end = first + range;
     431    Byte_t       *p  = first;
     432
     433    const Float_t pedes  = ped.GetPedestal();
     434    const Float_t ABoffs = ped.GetPedestalABoffset();
     435
     436    const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
     437
     438    Byte_t maxcont = 0;
     439    Int_t  maxpos  = 0;
     440    sat = 0;
     441
     442    //
     443    // Check for saturation in all other slices
     444    //
     445    Int_t ids = fHiGainFirst;
     446    Float_t *sample = fHiGainSignal.GetArray();
     447    while (p<end)
     448    {
     449        *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
     450
     451        if (*p > maxcont)
    400452        {
    401           maxpos = ids-fHiGainFirst-1;
    402           // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
    403           if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
    404               fMaxBinContent = *p;
     453            maxpos = ids-fHiGainFirst-1;
     454            // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
     455            //if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
     456            if (maxpos > 1 && maxpos < (range-1*//* - fWindowSizeHiGain + 1*//*))
     457                maxcont = *p;
    405458        }
    406459
    407       if (*p++ >= fSaturationLimit)
    408         if (!sat)
    409           sat = ids-fHiGainFirst;
    410      
    411     }
    412  
    413   if (fHiLoLast != 0)
    414     {
    415 
    416       end = logain + fHiLoLast;
    417 
    418       while (logain<end)
     460        if (*p++ >= fSaturationLimit)
     461            if (!sat)
     462                sat = ids-fHiGainFirst;
     463    }
     464
     465    if (fHiLoLast != 0)
     466    {
     467        end = logain + fHiLoLast;
     468
     469        while (logain<end)
    419470        {
    420 
    421           *sample++ = (Float_t)*logain - pedmean[(ids++ + abflag) & 0x1];
    422 
    423           if (*logain > fMaxBinContent)
    424             {
     471            *sample++ = (Float_t)*logain - pedmean[(ids++ + abflag) & 0x1];
     472
     473            if (*logain > maxcont)
     474            {
    425475                maxpos = ids-fHiGainFirst-1;
     476
     477                // FIXME!!! MUST BE THERE!
    426478                // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
    427479                //if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
    428                 //    fMaxBinContent = *logain;
     480                //    maxcont = *logain;
    429481            }
    430          
    431           if (*logain++ >= fSaturationLimit)
    432             if (!sat)
    433               sat = ids-fHiGainFirst;
    434 
    435           range++;
     482
     483            if (*logain++ >= fSaturationLimit)
     484                if (!sat)
     485                    sat = ids-fHiGainFirst;
     486
     487            range++;
    436488        }
    437489    }
    438490
    439   fAbMax = fHiGainSignal[maxpos];
    440 
    441   fHiGainSecondDeriv[0] = 0.;
    442   fHiGainFirstDeriv[0]  = 0.;
    443 
    444   for (Int_t i=1;i<range-1;i++)
    445     {
    446       const Float_t pp = fHiGainSecondDeriv[i-1] + 4.;
    447       fHiGainSecondDeriv[i] = -1.0/pp;
    448       fHiGainFirstDeriv [i] = fHiGainSignal[i+1] - 2*fHiGainSignal[i] + fHiGainSignal[i-1];
    449       fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
    450     }
    451 
    452   fHiGainSecondDeriv[range-1] = 0.;
    453 
    454   for (Int_t k=range-2;k>=0;k--)
    455     fHiGainSecondDeriv[k] = fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k];
    456   for (Int_t k=range-2;k>=0;k--)
    457     fHiGainSecondDeriv[k] /= 6.;
    458  
    459   if (IsNoiseCalculation())
    460     {
    461 
    462       if (fRandomIter == int(1./fResolution))
    463         fRandomIter = 0;
    464      
    465       const Float_t nsx = fRandomIter * fResolution;
    466 
    467       if (fExtractionType == kAmplitude)
    468         {
    469           const Float_t b = nsx;
    470           const Float_t a = 1. - nsx;
    471          
    472           sum = a*fHiGainSignal[1]
    473             + b*fHiGainSignal[2]
    474             + (a*a*a-a)*fHiGainSecondDeriv[1]
    475             + (b*b*b-b)*fHiGainSecondDeriv[2];
    476         }
    477       else
    478           sum = CalcIntegralHiGain(2. + nsx, range);
    479 
    480       fRandomIter++;
    481       return;
    482     }
    483 
    484   //
    485   // Allow no saturated slice and
    486   // Don't start if the maxpos is too close to the limits.
    487   //
    488   const Bool_t limlo = maxpos <       TMath::Ceil(fRiseTimeHiGain);
    489   const Bool_t limup = maxpos > range-TMath::Ceil(fFallTimeHiGain)-1;
    490   if (sat || limlo || limup)
    491     {
    492       dtime = 1.0;
    493       if (fExtractionType == kAmplitude)
    494         {
    495           sum  = fAbMax;
    496           time = (Float_t)(fHiGainFirst + maxpos);
    497           return;
    498         }
    499 
    500       sum  = CalcIntegralHiGain(limlo ? 0 : range, range);
    501       time = (Float_t)(fHiGainFirst + maxpos - 1);
    502       return;
    503     }
    504      
    505   dtime = fResolution;
    506 
    507   //
    508   // Now find the maximum 
    509   //
    510   Float_t step    = 0.2; // start with step size of 1ns and loop again with the smaller one
    511   Float_t lower   = -1. + maxpos;
    512   Float_t upper   = (Float_t)maxpos;
    513   fAbMaxPos       = upper;
    514   Float_t x       = lower;
    515   Float_t y       = 0.;
    516   Float_t a       = 1.;
    517   Float_t b       = 0.;
    518   Int_t   klo     = maxpos-1;
    519   Int_t   khi     = maxpos;
    520 
    521   //
    522   // Search for the maximum, starting in interval maxpos-1 in steps of 0.2 till maxpos-0.2.
    523   // If no maximum is found, go to interval maxpos+1.
    524   //
    525   while ( x < upper - 0.3 )
    526     {
    527 
    528       x += step;
    529       a -= step;
    530       b += step;
    531 
    532       y = a*fHiGainSignal[klo]
    533         + b*fHiGainSignal[khi]
    534         + (a*a*a-a)*fHiGainSecondDeriv[klo]
    535         + (b*b*b-b)*fHiGainSecondDeriv[khi];
    536 
    537       if (y > fAbMax)
    538         {
    539           fAbMax    = y;
    540           fAbMaxPos = x;
    541         }
    542 
    543     }
    544 
    545   //
    546   // Search for the absolute maximum from maxpos to maxpos+1 in steps of 0.2
    547   //
    548   if (fAbMaxPos > upper-0.1)
    549     {
    550       upper   = 1. + maxpos;
    551       lower   = (Float_t)maxpos;
    552       x       = lower;
    553       a       = 1.;
    554       b       = 0.;
    555       khi     = maxpos+1;
    556       klo     = maxpos;
    557 
    558       while (x<upper-0.3)
    559         {
    560 
    561           x += step;
    562           a -= step;
    563           b += step;
    564          
    565           y = a*fHiGainSignal[klo]
    566             + b*fHiGainSignal[khi]
    567             + (a*a*a-a)*fHiGainSecondDeriv[klo]
    568             + (b*b*b-b)*fHiGainSecondDeriv[khi];
    569 
    570           if (y > fAbMax)
    571             {
    572               fAbMax    = y;
    573               fAbMaxPos = x;
    574             }
    575         }
    576   }
    577   //
    578   // Now, the time, abmax and khicont and klocont are set correctly within the previous precision.
    579   // Try a better precision.
    580   //
    581   const Float_t up = fAbMaxPos+step - 3.0*fResolution;
    582   const Float_t lo = fAbMaxPos-step + 3.0*fResolution;
    583   const Float_t maxpossave = fAbMaxPos;
    584  
    585   x     = fAbMaxPos;
    586   a     = upper - x;
    587   b     = x - lower;
    588  
    589   step  = 2.*fResolution; // step size of 0.1 FADC slices
    590  
    591   while (x<up)
    592     {
    593 
    594       x += step;
    595       a -= step;
    596       b += step;
    597      
    598       y = a*fHiGainSignal[klo]
    599         + b*fHiGainSignal[khi]
    600         + (a*a*a-a)*fHiGainSecondDeriv[klo]
    601         + (b*b*b-b)*fHiGainSecondDeriv[khi];
    602      
    603       if (y > fAbMax)
    604         {
    605           fAbMax    = y;
    606           fAbMaxPos = x;
    607         }
    608     }
    609 
    610   //
    611   // Second, try from time down to time-0.2 in steps of fResolution.
    612   //
    613   x     = maxpossave;
    614 
    615   //
    616   // Test the possibility that the absolute maximum has not been found between
    617   // maxpos and maxpos+0.05, then we have to look between maxpos-0.05 and maxpos
    618   // which requires new setting of klocont and khicont
    619   //
    620   if (x < lower + fResolution)
    621     {
    622       klo--;
    623       khi--;
    624       upper -= 1.;
    625       lower -= 1.;
    626     }
    627 
    628   a     = upper - x;
    629   b     = x - lower;
    630  
    631   while (x>lo)
    632     {
    633 
    634       x -= step;
    635       a += step;
    636       b -= step;
    637      
    638       y = a*fHiGainSignal[klo]
    639         + b*fHiGainSignal[khi]
    640         + (a*a*a-a)*fHiGainSecondDeriv[klo]
    641         + (b*b*b-b)*fHiGainSecondDeriv[khi];
    642      
    643       if (y > fAbMax)
    644         {
    645           fAbMax    = y;
    646           fAbMaxPos = x;
    647         }
    648     }
    649 
    650   if (fExtractionType == kAmplitude)
    651     {
    652       time  = fAbMaxPos + (Int_t)fHiGainFirst;
    653       sum   = fAbMax;
    654       return;
    655     }
    656 
    657   fHalfMax = fAbMax/2.;
    658  
    659   //
    660   // Now, loop from the maximum bin leftward down in order to find the position of the half maximum.
    661   // First, find the right FADC slice:
    662   //
    663   klo  = maxpos;
    664   while (klo > 0)
    665     {
    666       if (fHiGainSignal[--klo] < fHalfMax)
    667         break;
    668     }
    669  
    670   khi = klo+1;
    671   //
    672   // Loop from the beginning of the slice upwards to reach the fHalfMax:
    673   // With means of bisection:
    674   //
    675   x     = (Float_t)klo;
    676   a     = 1.;
    677   b     = 0.;
    678  
    679   step = 0.5;
    680   Bool_t back = kFALSE;
    681  
    682   Int_t maxcnt = 20;
    683   Int_t cnt    = 0;
    684  
    685   while (TMath::Abs(y-fHalfMax) > fResolution)
    686     {
    687      
    688       if (back)
    689         {
    690           x -= step;
    691           a += step;
    692           b -= step;
    693         }
    694       else
    695         {
    696           x += step;
    697           a -= step;
    698           b += step;
    699         }
    700      
    701       y = a*fHiGainSignal[klo]
    702         + b*fHiGainSignal[khi]
    703         + (a*a*a-a)*fHiGainSecondDeriv[klo]
    704         + (b*b*b-b)*fHiGainSecondDeriv[khi];
    705      
    706       back = y > fHalfMax;
    707      
    708       if (++cnt > maxcnt)
    709         break;
    710      
    711       step /= 2.;
    712     }
    713  
    714   //
    715   // Now integrate the whole thing!
    716   //
    717   time = (Float_t)fHiGainFirst + x;
    718   sum  = CalcIntegralHiGain(fAbMaxPos - fRiseTimeHiGain, range);
    719 }
    720 
     491    FindTimeAndChargeHiGain2(fHiGainSignal.GetArray(), range,
     492                             sum, dsum, time, dtime,
     493                             sat, maxpos);
     494}
    721495
    722496// --------------------------------------------------------------------------
     
    728502                                                          Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag)
    729503{
    730   Int_t range = fLoGainLast - fLoGainFirst + 1;
    731   const Byte_t *end = first + range;
    732   Byte_t       *p  = first;
    733 
    734   const Float_t pedes  = ped.GetPedestal();
    735   const Float_t ABoffs = ped.GetPedestalABoffset();
    736 
    737   const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
    738 
    739   fAbMax        = 0.;
    740   fAbMaxPos     = 0.;
    741   Int_t  maxpos = 0;
    742   Int_t  max    = -9999;
    743 
    744   dsum = 0; // In all cases the extracted signal is valid
    745 
    746   //
    747   // Check for saturation in all other slices
    748   //
    749   Int_t    ids    = fLoGainFirst;
    750   Float_t *sample = fLoGainSignal.GetArray();
    751   while (p<end)
    752     {
    753 
    754       *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
    755 
    756       if (*p > max)
     504    Int_t range = fLoGainLast - fLoGainFirst + 1;
     505    const Byte_t *end = first + range;
     506    Byte_t       *p  = first;
     507
     508    const Float_t pedes  = ped.GetPedestal();
     509    const Float_t ABoffs = ped.GetPedestalABoffset();
     510
     511    const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
     512
     513    Int_t  maxpos = 0;
     514    Int_t  max    = -9999;
     515
     516    //
     517    // Check for saturation in all other slices
     518    //
     519    Int_t    ids    = fLoGainFirst;
     520    Float_t *sample = fLoGainSignal.GetArray();
     521    while (p<end)
     522    {
     523        *sample++ = (Float_t)*p - pedmean[(ids++ + abflag) & 0x1];
     524
     525        if (*p > max)
    757526        {
    758           maxpos = ids-fLoGainFirst-1;
    759           max    = *p;
     527            maxpos = ids-fLoGainFirst-1;
     528            max    = *p;
    760529        }
    761530
    762       if (*p++ >= fSaturationLimit)
    763         sat++;
    764     }
    765  
    766   fAbMax = fLoGainSignal[maxpos];
    767  
    768   fLoGainSecondDeriv[0] = 0.;
    769   fLoGainFirstDeriv[0]  = 0.;
    770 
    771   for (Int_t i=1;i<range-1;i++)
    772     {
    773       const Float_t pp = fLoGainSecondDeriv[i-1] + 4.;
    774       fLoGainSecondDeriv[i] = -1.0/pp;
    775       fLoGainFirstDeriv [i] = fLoGainSignal[i+1] - 2*fLoGainSignal[i] + fLoGainSignal[i-1];
    776       fLoGainFirstDeriv [i] = (6.0*fLoGainFirstDeriv[i]-fLoGainFirstDeriv[i-1])/pp;
    777     }
    778 
    779   fLoGainSecondDeriv[range-1] = 0.;
    780 
    781   for (Int_t k=range-2;k>=0;k--)
    782     fLoGainSecondDeriv[k] = fLoGainSecondDeriv[k]*fLoGainSecondDeriv[k+1] + fLoGainFirstDeriv[k];
    783   for (Int_t k=range-2;k>=0;k--)
    784     fLoGainSecondDeriv[k] /= 6.;
    785  
    786   if (IsNoiseCalculation())
    787     {
    788       if (fRandomIter == int(1./fResolution))
    789         fRandomIter = 0;
    790      
    791       const Float_t nsx = fRandomIter * fResolution;
    792 
    793       if (fExtractionType == kAmplitude)
    794         {
    795           const Float_t b = nsx;
    796           const Float_t a = 1. - nsx;
    797          
    798           sum = a*fLoGainSignal[1]
    799             + b*fLoGainSignal[2]
    800             + (a*a*a-a)*fLoGainSecondDeriv[1]
    801             + (b*b*b-b)*fLoGainSecondDeriv[2];
    802         }
    803       else
    804           sum = CalcIntegralLoGain(2. + nsx, range);
    805 
    806       fRandomIter++;
    807       return;
    808     }
    809   //
    810   // Allow no saturated slice and
    811   // Don't start if the maxpos is too close to the limits.
    812   //
    813   const Bool_t limlo = maxpos <       TMath::Ceil(fRiseTimeLoGain);
    814   const Bool_t limup = maxpos > range-TMath::Ceil(fFallTimeLoGain)-1;
    815   if (sat || limlo || limup)
    816     {
    817       dtime = 1.0;
    818       if (fExtractionType == kAmplitude)
    819         {
    820           time = (Float_t)(fLoGainFirst + maxpos);
    821           sum = fAbMax;
    822           return;
    823         }
    824 
    825       sum  = CalcIntegralLoGain(limlo ? 0 : range, range);
    826       time = (Float_t)(fLoGainFirst + maxpos - 1);
    827       return;
    828     }
    829 
    830   dtime = fResolution;
    831 
    832   //
    833   // Now find the maximum 
    834   //
    835   Float_t step    = 0.2; // start with step size of 1ns and loop again with the smaller one
    836   Float_t lower   = -1. + maxpos;
    837   Float_t upper   = (Float_t)maxpos;
    838   fAbMaxPos       = upper;
    839   Float_t x       = lower;
    840   Float_t y       = 0.;
    841   Float_t a       = 1.;
    842   Float_t b       = 0.;
    843   Int_t   klo     = maxpos-1;
    844   Int_t   khi     = maxpos;
    845 
    846   //
    847   // Search for the maximum, starting in interval maxpos-1 in steps of 0.2 till maxpos-0.2.
    848   // If no maximum is found, go to interval maxpos+1.
    849   //
    850   while ( x < upper - 0.3 )
    851     {
    852 
    853       x += step;
    854       a -= step;
    855       b += step;
    856 
    857       y = a*fLoGainSignal[klo]
    858         + b*fLoGainSignal[khi]
    859         + (a*a*a-a)*fLoGainSecondDeriv[klo]
    860         + (b*b*b-b)*fLoGainSecondDeriv[khi];
    861 
    862       if (y > fAbMax)
    863         {
    864           fAbMax    = y;
    865           fAbMaxPos = x;
    866         }
    867 
    868     }
    869 
    870   //
    871   // Test the possibility that the absolute maximum has not been found before the
    872   // maxpos and search from maxpos to maxpos+1 in steps of 0.2
    873   //
    874   if (fAbMaxPos > upper-0.1)
    875     {
    876 
    877       upper   = 1. + maxpos;
    878       lower   = (Float_t)maxpos;
    879       x       = lower;
    880       a       = 1.;
    881       b       = 0.;
    882       khi     = maxpos+1;
    883       klo     = maxpos;
    884 
    885       while (x<upper-0.3)
    886         {
    887 
    888           x += step;
    889           a -= step;
    890           b += step;
    891          
    892           y = a*fLoGainSignal[klo]
    893             + b*fLoGainSignal[khi]
    894             + (a*a*a-a)*fLoGainSecondDeriv[klo]
    895             + (b*b*b-b)*fLoGainSecondDeriv[khi];
    896 
    897           if (y > fAbMax)
    898             {
    899               fAbMax    = y;
    900               fAbMaxPos = x;
    901             }
    902         }
    903   }
    904 
    905 
    906   //
    907   // Now, the time, abmax and khicont and klocont are set correctly within the previous precision.
    908   // Try a better precision.
    909   //
    910   const Float_t up = fAbMaxPos+step - 3.0*fResolution;
    911   const Float_t lo = fAbMaxPos-step + 3.0*fResolution;
    912   const Float_t maxpossave = fAbMaxPos;
    913  
    914   x     = fAbMaxPos;
    915   a     = upper - x;
    916   b     = x - lower;
    917  
    918   step  = 2.*fResolution; // step size of 0.1 FADC slice
    919  
    920   while (x<up)
    921     {
    922 
    923       x += step;
    924       a -= step;
    925       b += step;
    926      
    927       y = a*fLoGainSignal[klo]
    928         + b*fLoGainSignal[khi]
    929         + (a*a*a-a)*fLoGainSecondDeriv[klo]
    930         + (b*b*b-b)*fLoGainSecondDeriv[khi];
    931      
    932       if (y > fAbMax)
    933         {
    934           fAbMax    = y;
    935           fAbMaxPos = x;
    936         }
    937     }
    938 
    939   //
    940   // Second, try from time down to time-0.2 in steps of 0.025.
    941   //
    942   x     = maxpossave;
    943 
    944   //
    945   // Test the possibility that the absolute maximum has not been found between
    946   // maxpos and maxpos+0.05, then we have to look between maxpos-0.05 and maxpos
    947   // which requires new setting of klocont and khicont
    948   //
    949   if (x < lower + fResolution)
    950     {
    951       klo--;
    952       khi--;
    953       upper -= 1.;
    954       lower -= 1.;
    955     }
    956 
    957   a     = upper - x;
    958   b     = x - lower;
    959  
    960   while (x>lo)
    961     {
    962 
    963       x -= step;
    964       a += step;
    965       b -= step;
    966      
    967       y = a*fLoGainSignal[klo]
    968         + b*fLoGainSignal[khi]
    969         + (a*a*a-a)*fLoGainSecondDeriv[klo]
    970         + (b*b*b-b)*fLoGainSecondDeriv[khi];
    971      
    972       if (y > fAbMax)
    973         {
    974           fAbMax    = y;
    975           fAbMaxPos = x;
    976         }
    977     }
    978 
    979   if (fExtractionType == kAmplitude)
    980     {
    981       time = fAbMaxPos + (Int_t)fLoGainFirst;
    982       sum  = fAbMax;
    983       return;
    984     }
    985  
    986   fHalfMax = fAbMax/2.;
    987  
    988   //
    989   // Now, loop from the maximum bin leftward down in order to find the position of the half maximum.
    990   // First, find the right FADC slice:
    991   //
    992   klo  = maxpos;
    993   while (klo > 0)
    994     {
    995       klo--;
    996       if (fLoGainSignal[klo] < fHalfMax)
    997         break;
    998     }
    999  
    1000   khi = klo+1;
    1001   //
    1002   // Loop from the beginning of the slice upwards to reach the fHalfMax:
    1003   // With means of bisection:
    1004   //
    1005   x     = (Float_t)klo;
    1006   a     = 1.;
    1007   b     = 0.;
    1008  
    1009   step = 0.5;
    1010   Bool_t back = kFALSE;
    1011  
    1012   Int_t maxcnt = 20;
    1013   Int_t cnt    = 0;
    1014  
    1015   while (TMath::Abs(y-fHalfMax) > fResolution)
    1016     {
    1017      
    1018       if (back)
    1019         {
    1020           x -= step;
    1021           a += step;
    1022           b -= step;
    1023         }
    1024       else
    1025         {
    1026           x += step;
    1027           a -= step;
    1028           b += step;
    1029         }
    1030      
    1031       y = a*fLoGainSignal[klo]
    1032         + b*fLoGainSignal[khi]
    1033         + (a*a*a-a)*fLoGainSecondDeriv[klo]
    1034         + (b*b*b-b)*fLoGainSecondDeriv[khi];
    1035      
    1036       back = y > fHalfMax;
    1037      
    1038       if (++cnt > maxcnt)
    1039         break;
    1040      
    1041       step /= 2.;
    1042     }
    1043  
    1044   //
    1045   // Now integrate the whole thing!
    1046   //
    1047   time = x + (Int_t)fLoGainFirst;
    1048   sum  = CalcIntegralLoGain(fAbMaxPos - fRiseTimeLoGain, range);
    1049 }
    1050 
    1051 Float_t MExtractTimeAndChargeSpline::CalcIntegralHiGain(Float_t start, Float_t range) const
    1052 {
    1053     // The number of steps is calculated directly from the integration
    1054     // window. This is the only way to ensure we are not dealing with
    1055     // numerical rounding uncertanties, because we always get the same
    1056     // value under the same conditions -- it might still be different on
    1057     // other machines!
    1058     const Float_t step  = 0.2;
    1059     const Float_t width = fRiseTimeHiGain+fFallTimeHiGain;
    1060     const Float_t max   = range-1 - (width+step);
    1061     const Int_t   num   = TMath::Nint(width/step);
    1062 
    1063     // The order is important. In some cases (limlo-/limup-check) it can
    1064     // happen than max<0. In this case we start at 0
    1065     if (start > max)
    1066         start = max;
    1067     if (start < 0)
    1068         start = 0;
    1069 
    1070     start += step/2;
    1071 
    1072     Double_t sum = 0.;
    1073     for (Int_t i=0; i<num; i++)
    1074     {
    1075         const Float_t x = start+i*step;
    1076         const Int_t klo = (Int_t)TMath::Floor(x);
    1077         const Int_t khi = klo + 1;
    1078         // Note: if x is close to one integer number (= a FADC sample)
    1079         // we get the same result by using that sample as klo, and the
    1080         // next one as khi, or using the sample as khi and the previous
    1081         // one as klo (the spline is of course continuous). So we do not
    1082         // expect problems from rounding issues in the argument of
    1083         // Floor() above (we have noticed differences in roundings
    1084         // depending on the compilation options).
    1085 
    1086         const Float_t a = khi - x; // Distance from x to next FADC sample
    1087         const Float_t b = x - klo; // Distance from x to previous FADC sample
    1088 
    1089         sum += a*fHiGainSignal[klo]
    1090             +  b*fHiGainSignal[khi]
    1091             + (a*a*a-a)*fHiGainSecondDeriv[klo]
    1092             + (b*b*b-b)*fHiGainSecondDeriv[khi];
    1093 
    1094         // FIXME? Perhaps the integral should be done analitically
    1095         // between every two FADC slices, instead of numerically
    1096     }
    1097 
    1098     sum *= step; // Transform sum in integral
    1099     return sum;
    1100 }
    1101 
    1102 Float_t MExtractTimeAndChargeSpline::CalcIntegralLoGain(Float_t start, Float_t range) const
    1103 {
    1104     // The number of steps is calculated directly from the integration
    1105     // window. This is the only way to ensure we are not dealing with
    1106     // numerical rounding uncertanties, because we always get the same
    1107     // value under the same conditions -- it might still be different on
    1108     // other machines!
    1109     const Float_t step  = 0.2;
    1110     const Float_t width = fRiseTimeLoGain+fFallTimeLoGain;
    1111     const Float_t max   = range-1 - (width+step);
    1112     const Int_t   num   = TMath::Nint(width/step);
    1113 
    1114     // The order is important. In some cases (limlo-/limup-check) it can
    1115     // happen that max<0. In this case we start at 0
    1116     if (start > max)
    1117         start = max;
    1118     if (start < 0)
    1119         start = 0;
    1120 
    1121     start += step/2;
    1122 
    1123     Double_t sum = 0.;
    1124     for (Int_t i=0; i<num; i++)
    1125     {
    1126         const Float_t x = start+i*step;
    1127         const Int_t klo = (Int_t)TMath::Floor(x);
    1128         const Int_t khi = klo + 1;
    1129         // Note: if x is close to one integer number (= a FADC sample)
    1130         // we get the same result by using that sample as klo, and the
    1131         // next one as khi, or using the sample as khi and the previous
    1132         // one as klo (the spline is of course continuous). So we do not
    1133         // expect problems from rounding issues in the argument of
    1134         // Floor() above (we have noticed differences in roundings
    1135         // depending on the compilation options).
    1136 
    1137         const Float_t a = khi - x; // Distance from x to next FADC sample
    1138         const Float_t b = x - klo; // Distance from x to previous FADC sample
    1139 
    1140         sum += a*fLoGainSignal[klo]
    1141             +  b*fLoGainSignal[khi]
    1142             + (a*a*a-a)*fLoGainSecondDeriv[klo]
    1143             + (b*b*b-b)*fLoGainSecondDeriv[khi];
    1144 
    1145         // FIXME? Perhaps the integral should be done analitically
    1146         // between every two FADC slices, instead of numerically
    1147     }
    1148     sum *= step; // Transform sum in integral
    1149     return sum;
    1150 }
     531        if (*p++ >= fSaturationLimit)
     532            sat++;
     533    }
     534
     535    FindTimeAndChargeLoGain2(fLoGainSignal.GetArray(), range,
     536                             sum, dsum, time, dtime,
     537                             sat, maxpos);
     538}
     539*/
    1151540
    1152541// --------------------------------------------------------------------------
     
    1198587
    1199588  return MExtractTimeAndCharge::ReadEnv(env, prefix, print) ? kTRUE : rc;
    1200 
    1201 }
    1202 
    1203 
     589}
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h

    r7491 r8154  
    1111
    1212class MPedestalPix;
     13
    1314class MExtractTimeAndChargeSpline : public MExtractTimeAndCharge
    1415{
     16private:
     17    static const Byte_t  fgHiGainFirst;      //! Default for fHiGainFirst  (now set to: 2)
     18    static const Byte_t  fgHiGainLast;       //! Default for fHiGainLast   (now set to: 14)
     19    static const Byte_t  fgLoGainFirst;      //! Default for fLoGainFirst  (now set to: 2)
     20    static const Byte_t  fgLoGainLast;       //! Default for fLoGainLast   (now set to: 14)
     21    static const Float_t fgResolution;       //! Default for fResolution   (now set to: 0.003)
     22    static const Float_t fgRiseTimeHiGain;   //! Default for fRiseTime     (now set to: 1.5)
     23    static const Float_t fgFallTimeHiGain;   //! Default for fFallTime     (now set to: 4.5)
     24    static const Float_t fgLoGainStretch;    //! Default for fLoGainStretch    (now set to: 1.5)
     25    static const Float_t fgOffsetLoGain;     //! Default for fOffsetLoGain     (now set to 1.7)
     26//    static const Float_t fgLoGainStartShift; //! Default for fLoGainStartShift (now set to -1.6)
     27
     28//    MArrayF fHiGainSignal;                   //! Need fast access to the signals in a float way
     29//    MArrayF fLoGainSignal;                   //! Store them in separate arrays
     30    MArrayF fHiGainFirstDeriv;               //! High-gain discretized first derivatives
     31    MArrayF fLoGainFirstDeriv;               //! Low-gain discretized first derivatives
     32    MArrayF fHiGainSecondDeriv;              //! High-gain discretized second derivatives
     33    MArrayF fLoGainSecondDeriv;              //! Low-gain discretized second derivatives
     34
     35    Float_t fResolution;                     // The time resolution in FADC units
     36
     37    Float_t fRiseTimeHiGain;                 // The usual rise time of the pulse in the high-gain
     38    Float_t fFallTimeHiGain;                 // The usual fall time of the pulse in the high-gain
     39    Float_t fRiseTimeLoGain;                 // The usual rise time of the pulse in the low-gain
     40    Float_t fFallTimeLoGain;                 // The usual fall time of the pulse in the low-gain
     41
     42    Float_t fLoGainStretch;                  // The stretch of the low-gain w.r.t. the high-gain pulse
     43
     44    Int_t   fRandomIter;                     //! Counter used to randomize weights for noise calculation
     45
     46    Int_t   ReadEnv(const TEnv &env, TString prefix, Bool_t print);
     47    Bool_t  InitArrays();
     48
     49public:
     50    enum ExtractionType_t { kAmplitude, kIntegral };    //! Possible time and charge extraction types
    1551
    1652private:
    17  
    18   static const Byte_t  fgHiGainFirst;      //! Default for fHiGainFirst  (now set to: 2)
    19   static const Byte_t  fgHiGainLast;       //! Default for fHiGainLast   (now set to: 14)
    20   static const Byte_t  fgLoGainFirst;      //! Default for fLoGainFirst  (now set to: 2)
    21   static const Byte_t  fgLoGainLast;       //! Default for fLoGainLast   (now set to: 14)
    22   static const Float_t fgResolution;       //! Default for fResolution   (now set to: 0.003)
    23   static const Float_t fgRiseTimeHiGain;   //! Default for fRiseTime     (now set to: 1.5)
    24   static const Float_t fgFallTimeHiGain;   //! Default for fFallTime     (now set to: 4.5)
    25   static const Float_t fgLoGainStretch;    //! Default for fLoGainStretch    (now set to: 1.5)
    26   static const Float_t fgOffsetLoGain;     //! Default for fOffsetLoGain     (now set to 1.7)
    27   static const Float_t fgLoGainStartShift; //! Default for fLoGainStartShift (now set to -1.6)
    28  
    29   MArrayF fHiGainSignal;                //! Need fast access to the signals in a float way
    30   MArrayF fLoGainSignal;                //! Store them in separate arrays
    31   MArrayF fHiGainFirstDeriv;            //! High-gain discretized first derivatives
    32   MArrayF fLoGainFirstDeriv;            //! Low-gain discretized first derivatives
    33   MArrayF fHiGainSecondDeriv;           //! High-gain discretized second derivatives
    34   MArrayF fLoGainSecondDeriv;           //! Low-gain discretized second derivatives
    35 
    36   Float_t fAbMax;                       //! Current maximum of the spline
    37   Float_t fAbMaxPos;                    //! Current position of the maximum of the spline
    38   Float_t fHalfMax;                     //! Current half maximum of the spline
    39 
    40   Float_t fResolution;                  // The time resolution in FADC units
    41 
    42   Float_t fRiseTimeHiGain;              // The usual rise time of the pulse in the high-gain
    43   Float_t fFallTimeHiGain;              // The usual fall time of the pulse in the high-gain
    44   Float_t fRiseTimeLoGain;              // The usual rise time of the pulse in the low-gain
    45   Float_t fFallTimeLoGain;              // The usual fall time of the pulse in the low-gain
    46 
    47   Float_t fLoGainStretch;               // The stretch of the low-gain w.r.t. the high-gain pulse
    48 
    49   Int_t   fRandomIter;                  //! Counter used to randomize weights for noise calculation
    50  
    51   Int_t   ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    52 
    53   Bool_t  InitArrays();
    54  
    55   Float_t CalcIntegralHiGain(Float_t start, Float_t range) const;
    56   Float_t CalcIntegralLoGain(Float_t start, Float_t range) const;
    57 
    58 public: 
    59   enum ExtractionType_t { kAmplitude, kIntegral };    //! Possible time and charge extraction types
    60 
    61 private:
    62  
    63   ExtractionType_t fExtractionType;
     53    ExtractionType_t fExtractionType;
    6454
    6555public:
     56    MExtractTimeAndChargeSpline(const char *name=NULL, const char *title=NULL);
     57    ~MExtractTimeAndChargeSpline() {}
    6658
    67   MExtractTimeAndChargeSpline(const char *name=NULL, const char *title=NULL);
    68   ~MExtractTimeAndChargeSpline() {}
     59    Float_t GetRiseTimeHiGain() const { return fRiseTimeHiGain; }
     60    Float_t GetFallTimeHiGain() const { return fFallTimeHiGain; }
    6961
    70   Float_t GetRiseTimeHiGain() const { return fRiseTimeHiGain; }
    71   Float_t GetFallTimeHiGain() const { return fFallTimeHiGain; }
     62    void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0 );
    7263
    73   void SetRange      ( Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0 ); 
    74   void SetResolution ( const Float_t f=fgResolution  )  { fResolution  = f;  }
    75   void SetRiseTimeHiGain( const Float_t f=fgRiseTimeHiGain    )
     64    void SetResolution(const Float_t f=fgResolution)  { fResolution  = f;  }
     65
     66    void SetRiseTimeHiGain(const Float_t f=fgRiseTimeHiGain)
    7667    {
    77       fRiseTimeHiGain    = f;
    78       fRiseTimeLoGain    = f*fLoGainStretch;
    79       fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
    80       fWindowSizeHiGain  = TMath::Nint(fRiseTimeHiGain + fFallTimeHiGain);
     68        fRiseTimeHiGain    = f;
     69        fRiseTimeLoGain    = f*fLoGainStretch;
     70        fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
     71        fWindowSizeHiGain  = TMath::Nint(fRiseTimeHiGain + fFallTimeHiGain);
    8172    }
    82   void SetFallTimeHiGain( const Float_t f=fgFallTimeHiGain    )
     73    void SetFallTimeHiGain(const Float_t f=fgFallTimeHiGain)
    8374    {
    84       fFallTimeHiGain    = f;
    85       fFallTimeLoGain    = f*fLoGainStretch;
    86       fNumHiGainSamples  = fRiseTimeHiGain + fFallTimeHiGain;
    87       fNumLoGainSamples  = fLoGainLast ? fRiseTimeLoGain + fFallTimeLoGain : 0.;
    88       fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
    89       fWindowSizeLoGain  = TMath::Nint(fRiseTimeLoGain + fFallTimeLoGain);
     75        fFallTimeHiGain    = f;
     76        fFallTimeLoGain    = f*fLoGainStretch;
     77        fNumHiGainSamples  = fRiseTimeHiGain + fFallTimeHiGain;
     78        fNumLoGainSamples  = fLoGainLast ? fRiseTimeLoGain + fFallTimeLoGain : 0.;
     79        fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
     80        fWindowSizeLoGain  = TMath::Nint(fRiseTimeLoGain + fFallTimeLoGain);
    9081    }
    9182
    92   void SetLoGainStretch ( const Float_t f=fgLoGainStretch    )  { fLoGainStretch = f;   }
    93  
    94   void SetChargeType ( const ExtractionType_t typ=kIntegral);
    95  
    96   void FindTimeAndChargeHiGain(Byte_t *first, Byte_t *logain, Float_t &sum, Float_t &dsum,
    97                                Float_t &time, Float_t &dtime,
    98                                Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
    99   void FindTimeAndChargeLoGain(Byte_t *first, Float_t &sum,  Float_t &dsum,
    100                                Float_t &time, Float_t &dtime,
    101                                Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
     83    void SetLoGainStretch(const Float_t f=fgLoGainStretch) { fLoGainStretch = f;   }
    10284
    103   ClassDef(MExtractTimeAndChargeSpline, 4)   // Task to Extract Arrival Times and Charges using a Cubic Spline
     85    void SetChargeType(const ExtractionType_t typ=kIntegral);
     86/*
     87    void FindTimeAndChargeHiGain(Byte_t *first, Byte_t *logain, Float_t &sum, Float_t &dsum,
     88                                 Float_t &time, Float_t &dtime,
     89                                 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
     90    void FindTimeAndChargeLoGain(Byte_t *first, Float_t &sum,  Float_t &dsum,
     91                                 Float_t &time, Float_t &dtime,
     92                                 Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
     93*/
     94    void FindTimeAndChargeHiGain2(const Float_t *firstused, Int_t num, Float_t &sum, Float_t &dsum,
     95                                  Float_t &time, Float_t &dtime,
     96                                  Byte_t sat, Int_t maxpos);
     97
     98    void FindTimeAndChargeLoGain2(const Float_t *firstused, Int_t num, Float_t &sum,  Float_t &dsum,
     99                                  Float_t &time, Float_t &dtime,
     100                                  Byte_t sat, Int_t maxpos);
     101
     102    ClassDef(MExtractTimeAndChargeSpline, 4)   // Task to Extract Arrival Times and Charges using a Cubic Spline
    104103};
    105104
    106105#endif
    107 
    108 
    109 
  • trunk/MagicSoft/Mars/msignal/MExtractedSignalPix.h

    r7876 r8154  
    1515  Float_t fExtractedSignalLoGainError; // error of the mean value of the extracted signal
    1616
    17   Byte_t fNumHiGainSaturated;          // Number of first hi-gain slice which has saturated (could be negative if already the first slice saturates)
    18   Byte_t fNumLoGainSaturated;          // Number of first lo-gain slices which have saturated
     17  Byte_t fNumHiGainSaturated;          // Number of how many hi-gain slices saturated
     18  Byte_t fNumLoGainSaturated;          // Number of how many lo-gain slices saturated
     19
     20  Byte_t GetNumHiGainSaturated() const { return fNumHiGainSaturated; }
     21  Byte_t GetNumLoGainSaturated() const { return fNumLoGainSaturated; }
    1922
    2023public:
     
    3639  Float_t GetExtractedSignalLoGainError() const { return fExtractedSignalLoGainError;  }
    3740
    38   Byte_t GetNumHiGainSaturated()          const { return fNumHiGainSaturated;          }
    39   Byte_t GetNumLoGainSaturated()          const { return fNumLoGainSaturated;          }
    40 
    4141  Bool_t IsHiGainSaturated()              const { return fNumHiGainSaturated>0;        }
    4242  Bool_t IsLoGainSaturated()              const { return fNumLoGainSaturated>0;        }
  • trunk/MagicSoft/Mars/msignal/MExtractor.cc

    r7881 r8154  
    9393#include "MPedestalCam.h"
    9494#include "MPedestalPix.h"
     95//#include "MPedestalSubtractEvt.h"
    9596
    9697#include "MExtractedSignalCam.h"
     
    101102using namespace std;
    102103
    103 const Byte_t  MExtractor::fgSaturationLimit = 250;
     104const Byte_t  MExtractor::fgSaturationLimit = 245;
    104105const TString MExtractor::fgNamePedestalCam = "MPedestalCam";
    105106const TString MExtractor::fgNameSignalCam   = "MExtractedSignalCam";
     
    123124MExtractor::MExtractor(const char *name, const char *title)
    124125    : fResolutionPerPheHiGain(0), fResolutionPerPheLoGain(0),
    125       fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
    126       fHiLoLast(0), fNumHiGainSamples(0), fNumLoGainSamples(0)
     126    fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
     127    fSignal(NULL),
     128      /*fHiLoLast(0),*/ fNumHiGainSamples(0), fNumLoGainSamples(0)
    127129{
    128130    fName  = name  ? name  : "MExtractor";
     
    172174    {
    173175        *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
     176        return kFALSE;
     177    }
     178
     179    fSignal = (MPedestalSubtractedEvt*)pList->FindObject(AddSerialNumber("MPedestalSubtractedEvt"));
     180    if (!fSignal)
     181    {
     182        *fLog << err << AddSerialNumber("MPedestalSubtractedEvt") << " not found... aborting." << endl;
    174183        return kFALSE;
    175184    }
     
    231240Bool_t MExtractor::ReInit(MParList *pList)
    232241{
    233 
     242    const Int_t numl = fRunHeader->GetNumSamplesLoGain();
     243    const Int_t numh = fRunHeader->GetNumSamplesHiGain();
     244    const Int_t num  = numh+numl;
     245
     246    if (fHiGainLast>=num)
     247    {
     248        *fLog << err << "ERROR - Last hi-gain slice must not exceed " << num-1 << endl;
     249        return kFALSE;
     250    }
     251    if (fLoGainLast>=num)
     252    {
     253        *fLog << err << "ERROR - Last lo-gain slice must not exceed " << num-1 << endl;
     254        return kFALSE;
     255    }
     256
     257/*
    234258  const Int_t logainsamples = fRunHeader->GetNumSamplesLoGain();
    235259
     
    289313    }
    290314 
    291   return kTRUE;
     315  */
     316    return kTRUE;
    292317}
    293318
     
    431456    *fLog << " Hi Gain Range:      " << Form("%2d %2d", fHiGainFirst, fHiGainLast) << endl;
    432457    *fLog << " Lo Gain Range:      " << Form("%2d %2d", fLoGainFirst, fLoGainLast) << endl;
    433     *fLog << " Gain Overlap to Lo: " << Form("%2d", fHiLoLast)        << endl;
     458//    *fLog << " Gain Overlap to Lo: " << Form("%2d", fHiLoLast)        << endl;
    434459    *fLog << " Saturation Lim:     " << Form("%3d", fSaturationLimit) << endl;
    435460    *fLog << " Num Samples Hi/Lo:  " << Form("%2.1f %2.1f", fNumHiGainSamples, fNumLoGainSamples) << endl;
  • trunk/MagicSoft/Mars/msignal/MExtractor.h

    r7804 r8154  
    1818
    1919class MPedestalCam;
     20class MPedestalSubtractedEvt;
    2021class MExtractedSignalCam;
    2122
     
    4243  MRawEvtData         *fRawEvt;            //! Raw event data (time slices)
    4344  MRawRunHeader       *fRunHeader;         //! RunHeader information
     45
     46  MPedestalSubtractedEvt *fSignal;         //!
    4447                                       
    4548  Byte_t   fHiGainFirst;                   // First FADC slice nr. to extract the High Gain signal
     
    4851  Byte_t   fLoGainLast;                    // Last FADC slice nr. to extract the Low Gain signal
    4952                                           
    50   Byte_t   fHiLoLast;                      // Number of slices in fLoGainSamples counted for the High-Gain signal
     53//  Byte_t   fHiLoLast;                      // Number of slices in fLoGainSamples counted for the High-Gain signal
    5154                                           
    5255  Float_t  fNumHiGainSamples;              // Number High Gain FADC slices used to extract the signal
     
    9194  Float_t GetResolutionPerPheHiGain() const { return fResolutionPerPheHiGain; }
    9295  Float_t GetResolutionPerPheLoGain() const { return fResolutionPerPheLoGain; }
     96  Byte_t  GetSaturationLimit() const { return fSaturationLimit; }
    9397
    9498  Bool_t  IsNoiseCalculation () const { return fNoiseCalculation; }
     
    107111
    108112  void SetPedestals (MPedestalCam *pedcam)   { fPedestals = pedcam; }
     113  MPedestalCam *GetPedestals()   { return fPedestals; }
    109114
    110115  // TObject
    111116  void Clear(Option_t *o="")
    112117    {
    113       fHiGainFirst = fHiGainLast = fLoGainFirst = fLoGainLast = fHiLoLast = 0;
     118      fHiGainFirst = fHiGainLast = fLoGainFirst = fLoGainLast = /*fHiLoLast =*/ 0;
    114119    }
    115120
  • trunk/MagicSoft/Mars/msignal/Makefile

    r7897 r8154  
    2121INCLUDES =  -I. -I../mbase -I../mgui -I../mraw -I../manalysis \
    2222            -I../mgeom -I../mtools -I../mpedestal -I../mbadpixels \
    23             -I../mcalib
     23            -I../mcalib -I../mextralgo
    2424
    2525# mgui (MCamEvent):         MExtractSignalCam
  • trunk/MagicSoft/Mars/msignal/calibration_weights_UV46.dat

    r6870 r8154  
    11# High Gain Weights: 4 10
    22# (Amplitude)  (Time)
    3 -0.735581 -0.673266
    4 -0.800386 -0.47606
    5 -0.902801 -0.192719
    6 -0.945945 0.237423
    7 -0.851618 0.770424
    8 -0.598107 1.28444
    9 -0.290663 1.69546
    10 0.0967702 1.89144
    11 0.362204 1.98161
    12 0.610111 2.06506
    13 0.919902 2.20752
    14 1.12282 1.94486
    15 1.46305 1.70309
    16 1.85728 1.58904
    17 2.19155 1.21011
    18 2.37154 0.603168
    19 2.37187 0.000360131
    20 2.25639 -0.535921
    21 2.12495 -0.948388
    22 1.97328 -1.286
    23 1.72155 -1.70358
    24 1.55218 -1.75991
    25 1.21489 -1.86382
    26 0.759117 -2.09403
    27 0.266577 -2.03167
    28 -0.102906 -1.60487
    29 -0.284545 -1.16641
    30 -0.367327 -0.679947
    31 -0.376403 -0.3943
    32 -0.379568 -0.229929
    33 -0.218954 0.0443019
    34 -0.22659 0.163101
    35 -0.195144 0.249649
    36 -0.136182 0.328464
    37 -0.0541723 0.334035
    38 -0.00249719 0.207255
    39 0.00794832 0.102902
    40 0.00785676 0.0396167
    41 0.00459524 0.0111356
    42 0.00887564 0.0405
     3-0.735581 -0.673266      0
     4-0.800386 -0.47606       0
     5-0.902801 -0.192719      0
     6-0.945945 0.237423       0
     7-0.851618 0.770424       0
     8-0.598107 1.28444        0
     9-0.290663 1.69546        0
     100.0967702 1.89144        0
     110.362204 1.98161         0
     120.610111 2.06506         0
     130.919902 2.20752         0
     141.12282 1.94486          0
     151.46305 1.70309          0
     161.85728 1.58904          0
     172.19155 1.21011          0
     182.37154 0.603168         0
     192.37187 0.000360131      0
     202.25639 -0.535921        0
     212.12495 -0.948388        0
     221.97328 -1.286           0
     231.72155 -1.70358         0
     241.55218 -1.75991         0
     251.21489 -1.86382         0
     260.759117 -2.09403        0
     270.266577 -2.03167        0
     28-0.102906 -1.60487       0
     29-0.284545 -1.16641       0
     30-0.367327 -0.679947      0
     31-0.376403 -0.3943        0
     32-0.379568 -0.229929      0
     33-0.218954 0.0443019      0
     34-0.22659 0.163101        0
     35-0.195144 0.249649       0
     36-0.136182 0.328464       0
     37-0.0541723 0.334035      0
     38-0.00249719 0.207255     0
     390.00794832 0.102902      0
     400.00785676 0.0396167     0
     410.00459524 0.0111356     0
     420.00887564 0.0405        0
    4343# Low Gain Weights: 6 10
    4444# (Amplitude)  (Time)
    45 0.0446612 -0.385273
    46 0.038191 -0.00418687
    47 0.0386966 0.0212324
    48 0.0402881 0.0744799
    49 0.0415794 0.229615
    50 0.0598731 0.44332
    51 0.0758477 0.661518
    52 0.101509 1.10641
    53 0.159323 1.64997
    54 0.497256 2.83685
    55 0.245087 3.27499
    56 0.140546 2.46177
    57 0.58086 2.2849
    58 0.632721 2.45587
    59 0.72819 2.52835
    60 0.889583 2.48099
    61 0.980812 2.50031
    62 1.09885 2.55892
    63 1.21374 2.78769
    64 1.61928 3.08069
    65 1.38544 1.95583
    66 1.31998 1.1792
    67 1.50633 0.591226
    68 1.50916 0.0793899
    69 1.5008 -0.33188
    70 1.47339 -0.575386
    71 1.45362 -0.915309
    72 1.40214 -1.31593
    73 1.34175 -1.77904
    74 1.0661 -2.05471
    75 1.31087 -1.49798
    76 1.33793 -1.34758
    77 1.10172 -1.21719
    78 1.08133 -1.09356
    79 1.04007 -0.981455
    80 0.976745 -1.08299
    81 0.930979 -1.14774
    82 0.874203 -1.18348
    83 0.816708 -1.20126
    84 0.587354 -1.92869
    85 0.783078 -1.89621
    86 0.792771 -1.03439
    87 0.622278 -0.781807
    88 0.61184 -0.745831
    89 0.578792 -0.683741
    90 0.537336 -0.596328
    91 0.51443 -0.592858
    92 0.482294 -0.560586
    93 0.462351 -0.827587
    94 0.317989 -1.05649
    95 0.459672 -0.775035
    96 0.468287 -0.619961
    97 0.374182 -0.31635
    98 0.376946 -0.225242
    99 0.367075 -0.347444
    100 0.340737 -0.393231
    101 0.321054 -0.187384
    102 0.320654 -0.225558
    103 0.302148 -0.399499
    104 0.232954 -0.607578
     450.0446612 -0.385273      0
     460.038191 -0.00418687     0
     470.0386966 0.0212324      0
     480.0402881 0.0744799      0
     490.0415794 0.229615       0
     500.0598731 0.44332        0
     510.0758477 0.661518       0
     520.101509 1.10641         0
     530.159323 1.64997         0
     540.497256 2.83685         0
     550.245087 3.27499         0
     560.140546 2.46177         0
     570.58086 2.2849           0
     580.632721 2.45587         0
     590.72819 2.52835          0
     600.889583 2.48099         0
     610.980812 2.50031         0
     621.09885 2.55892          0
     631.21374 2.78769          0
     641.61928 3.08069          0
     651.38544 1.95583          0
     661.31998 1.1792           0
     671.50633 0.591226         0
     681.50916 0.0793899        0
     691.5008 -0.33188          0
     701.47339 -0.575386        0
     711.45362 -0.915309        0
     721.40214 -1.31593         0
     731.34175 -1.77904         0
     741.0661 -2.05471          0
     751.31087 -1.49798         0
     761.33793 -1.34758         0
     771.10172 -1.21719         0
     781.08133 -1.09356         0
     791.04007 -0.981455        0
     800.976745 -1.08299        0
     810.930979 -1.14774        0
     820.874203 -1.18348        0
     830.816708 -1.20126        0
     840.587354 -1.92869        0
     850.783078 -1.89621        0
     860.792771 -1.03439        0
     870.622278 -0.781807       0
     880.61184 -0.745831        0
     890.578792 -0.683741       0
     900.537336 -0.596328       0
     910.51443 -0.592858        0
     920.482294 -0.560586       0
     930.462351 -0.827587       0
     940.317989 -1.05649        0
     950.459672 -0.775035       0
     960.468287 -0.619961       0
     970.374182 -0.31635        0
     980.376946 -0.225242       0
     990.367075 -0.347444       0
     1000.340737 -0.393231       0
     1010.321054 -0.187384       0
     1020.320654 -0.225558       0
     1030.302148 -0.399499       0
     1040.232954 -0.607578       0
  • trunk/MagicSoft/Mars/msignal/cosmics_weights46.dat

    r6870 r8154  
    11# High Gain Weights: 4 10
    22# (Amplitude)  (Time)
    3 -0.637443 -0.648763
    4 -0.707555 -0.610204
    5 -0.772465 -0.469694
    6 -0.896081 -0.305143
    7 -1.02783 0.00696361
    8 -1.03684 0.731979
    9 -0.73698 1.49428
    10 -0.23419 1.57509
    11 0.12767 1.83675
    12 0.441087 1.70526
    13 0.639658 1.50546
    14 0.806192 1.58667
    15 0.966865 1.41151
    16 1.24058 1.34506
    17 1.58293 1.39453
    18 2.02092 1.46038
    19 2.31508 0.8539
    20 2.31705 0.051831
    21 2.18497 -0.493294
    22 2.01129 -0.749924
    23 1.8675 -0.959329
    24 1.75322 -1.25026
    25 1.60962 -1.37231
    26 1.3216 -1.58832
    27 0.880364 -1.9924
    28 0.219661 -2.50675
    29 -0.35077 -1.96955
    30 -0.553454 -0.855454
    31 -0.491715 -0.387673
    32 -0.38701 -0.0297507
    33 -0.293549 0.092153
    34 -0.278646 0.194742
    35 -0.263716 0.25195
    36 -0.221238 0.323789
    37 -0.121941 0.381038
    38 0.00379863 0.393009
    39 0.0805122 0.201843
    40 0.0443888 -0.0531952
    41 -0.0199606 -0.175625
    42 -0.0809393 -0.21419
     3-0.637443 -0.648763     0
     4-0.707555 -0.610204     0
     5-0.772465 -0.469694     0
     6-0.896081 -0.305143     0
     7-1.02783 0.00696361     0
     8-1.03684 0.731979       0
     9-0.73698 1.49428        0
     10-0.23419 1.57509        0
     110.12767 1.83675         0
     120.441087 1.70526        0
     130.639658 1.50546        0
     140.806192 1.58667        0
     150.966865 1.41151        0
     161.24058 1.34506         0
     171.58293 1.39453         0
     182.02092 1.46038         0
     192.31508 0.8539          0
     202.31705 0.051831        0
     212.18497 -0.493294       0
     222.01129 -0.749924       0
     231.8675 -0.959329        0
     241.75322 -1.25026        0
     251.60962 -1.37231        0
     261.3216 -1.58832         0
     270.880364 -1.9924        0
     280.219661 -2.50675       0
     29-0.35077 -1.96955       0
     30-0.553454 -0.855454     0
     31-0.491715 -0.387673     0
     32-0.38701 -0.0297507     0
     33-0.293549 0.092153      0
     34-0.278646 0.194742      0
     35-0.263716 0.25195       0
     36-0.221238 0.323789      0
     37-0.121941 0.381038      0
     380.00379863 0.393009     0
     390.0805122 0.201843      0
     400.0443888 -0.0531952    0
     41-0.0199606 -0.175625    0
     42-0.0809393 -0.21419     0
    4343# Low Gain Weights: 6 10
    4444# (Amplitude)  (Time)
    45 0.0446612 -0.385273
    46 0.038191 -0.00418687
    47 0.0386966 0.0212324
    48 0.0402881 0.0744799
    49 0.0415794 0.229615
    50 0.0598731 0.44332
    51 0.0758477 0.661518
    52 0.101509 1.10641
    53 0.159323 1.64997
    54 0.497256 2.83685
    55 0.245087 3.27499
    56 0.140546 2.46177
    57 0.58086 2.2849
    58 0.632721 2.45587
    59 0.72819 2.52835
    60 0.889583 2.48099
    61 0.980812 2.50031
    62 1.09885 2.55892
    63 1.21374 2.78769
    64 1.61928 3.08069
    65 1.38544 1.95583
    66 1.31998 1.1792
    67 1.50633 0.591226
    68 1.50916 0.0793899
    69 1.5008 -0.33188
    70 1.47339 -0.575386
    71 1.45362 -0.915309
    72 1.40214 -1.31593
    73 1.34175 -1.77904
    74 1.0661 -2.05471
    75 1.31087 -1.49798
    76 1.33793 -1.34758
    77 1.10172 -1.21719
    78 1.08133 -1.09356
    79 1.04007 -0.981455
    80 0.976745 -1.08299
    81 0.930979 -1.14774
    82 0.874203 -1.18348
    83 0.816708 -1.20126
    84 0.587354 -1.92869
    85 0.783078 -1.89621
    86 0.792771 -1.03439
    87 0.622278 -0.781807
    88 0.61184 -0.745831
    89 0.578792 -0.683741
    90 0.537336 -0.596328
    91 0.51443 -0.592858
    92 0.482294 -0.560586
    93 0.462351 -0.827587
    94 0.317989 -1.05649
    95 0.459672 -0.775035
    96 0.468287 -0.619961
    97 0.374182 -0.31635
    98 0.376946 -0.225242
    99 0.367075 -0.347444
    100 0.340737 -0.393231
    101 0.321054 -0.187384
    102 0.320654 -0.225558
    103 0.302148 -0.399499
    104 0.232954 -0.607578
     450.0446612 -0.385273     0
     460.038191 -0.00418687    0
     470.0386966 0.0212324     0
     480.0402881 0.0744799     0
     490.0415794 0.229615      0
     500.0598731 0.44332       0
     510.0758477 0.661518      0
     520.101509 1.10641        0
     530.159323 1.64997        0
     540.497256 2.83685        0
     550.245087 3.27499        0
     560.140546 2.46177        0
     570.58086 2.2849          0
     580.632721 2.45587        0
     590.72819 2.52835         0
     600.889583 2.48099        0
     610.980812 2.50031        0
     621.09885 2.55892         0
     631.21374 2.78769         0
     641.61928 3.08069         0
     651.38544 1.95583         0
     661.31998 1.1792          0
     671.50633 0.591226        0
     681.50916 0.0793899       0
     691.5008 -0.33188         0
     701.47339 -0.575386       0
     711.45362 -0.915309       0
     721.40214 -1.31593        0
     731.34175 -1.77904        0
     741.0661 -2.05471         0
     751.31087 -1.49798        0
     761.33793 -1.34758        0
     771.10172 -1.21719        0
     781.08133 -1.09356        0
     791.04007 -0.981455       0
     800.976745 -1.08299       0
     810.930979 -1.14774       0
     820.874203 -1.18348       0
     830.816708 -1.20126       0
     840.587354 -1.92869       0
     850.783078 -1.89621       0
     860.792771 -1.03439       0
     870.622278 -0.781807      0
     880.61184 -0.745831       0
     890.578792 -0.683741      0
     900.537336 -0.596328      0
     910.51443 -0.592858       0
     920.482294 -0.560586      0
     930.462351 -0.827587      0
     940.317989 -1.05649       0
     950.459672 -0.775035      0
     960.468287 -0.619961      0
     970.374182 -0.31635       0
     980.376946 -0.225242      0
     990.367075 -0.347444      0
     1000.340737 -0.393231      0
     1010.321054 -0.187384      0
     1020.320654 -0.225558      0
     1030.302148 -0.399499      0
     1040.232954 -0.607578      0
Note: See TracChangeset for help on using the changeset viewer.