Ignore:
Timestamp:
12/10/03 08:24:42 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc

    r2599 r2629  
    5050#include "MPedestalCam.h"
    5151
     52#include "MGeomCamMagic.h"
     53
    5254ClassImp(MPedCalcPedRun);
    5355
     
    6163    AddToBranchList("fHiGainPixId");
    6264    AddToBranchList("fHiGainFadcSamples");
     65   
     66    fCounter=0;
    6367}
    6468
     
    7579    if (!fPedestals)
    7680        return kFALSE;
     81
     82    MGeomCamMagic magiccam;
     83
     84    fSumx.Set(magiccam.GetNumPixels());
     85    fSumx2.Set(magiccam.GetNumPixels());
     86   
     87    for(UInt_t i=0;i<magiccam.GetNumPixels();i++)
     88    {
     89        fSumx.AddAt(0,i);
     90        fSumx2.AddAt(0,i);
     91    }
    7792
    7893    return kTRUE;
     
    110125    while (pixel.Next())
    111126    {
    112              Byte_t *ptr = pixel.GetHiGainSamples();
    113         const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
     127        Byte_t shift=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? 0:1;
     128              Byte_t *ptr = pixel.GetHiGainSamples();
     129        const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples()-shift;
    114130
    115131        const Float_t higainped = CalcHiGainMean(ptr, end);
     
    118134        const UInt_t pixid = pixel.GetPixelId();
    119135        MPedestalPix &pix = (*fPedestals)[pixid];
    120 
     136       
     137        // cumulate the sum of pedestals and of pedestal squares
     138        fSumx.AddAt(higainped+fSumx.At(pixid),pixid);
     139        fSumx2.AddAt(GetSumx2(ptr, end)+fSumx2.At(pixid),pixid);
     140
     141        // set the value of the pedestal and rms computed from the processed event
    121142        pix.Set(higainped, higainrms);
    122 
    123     }
     143    }
     144
     145
     146    fCounter++;
    124147
    125148    fPedestals->SetReadyToSave();
     
    128151}
    129152
     153Int_t MPedCalcPedRun::PostProcess()
     154{
     155// Compute pedestals and rms from the whole run
     156
     157    MRawEvtPixelIter pixel(fRawEvt);
     158
     159    while (pixel.Next())
     160    {
     161        const UInt_t pixid = pixel.GetPixelId();
     162        MPedestalPix &pix = (*fPedestals)[pixid];
     163
     164        const Int_t N = fCounter;
     165        const Float_t sum = fSumx.At(pixid);
     166        const Float_t sum2 = fSumx2.At(pixid);
     167        const Float_t higainped = sum/N;
     168        const Float_t higainrms = sqrt(1./(N-1.)*(sum2-sum*sum/N));
     169        pix.Set(higainped,higainrms);
     170
     171    }
     172    return kTRUE;
     173
     174}
     175
     176
    130177Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
    131178{
    132179    Int_t sum=0;
     180    Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
    133181
    134182    do sum += *ptr;
    135183    while (++ptr != end);
    136 
    137     return (Float_t)sum/fNumHiGainSamples;
     184   
     185    return (Float_t)sum/EvenNumSamples;
     186}
     187
     188
     189
     190Float_t MPedCalcPedRun::GetSumx2(Byte_t *ptr, const Byte_t *end) const
     191{
     192    Float_t square = 0;
     193
     194    // Take an even number of time slices to avoid biases due to A/B effect
     195    Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
     196
     197    do
     198    {
     199        const Float_t val = (Float_t)(*ptr);
     200
     201        square += val*val;
     202    } while (++ptr != end);
     203
     204    return square/EvenNumSamples;
    138205}
    139206
     
    142209{
    143210    Float_t rms = 0;
     211    Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
    144212
    145213    do
     
    150218    } while (++ptr != end);
    151219
    152     return sqrt(rms/fNumHiGainSamples);
    153 }
     220    return sqrt(rms/EvenNumSamples);
     221}
     222
     223
     224
    154225/*
    155226Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
Note: See TracChangeset for help on using the changeset viewer.