Ignore:
Timestamp:
10/24/06 09:26:10 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.