Changeset 2821


Ignore:
Timestamp:
01/15/04 16:44:47 (21 years ago)
Author:
rico
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2820 r2821  
    44
    55                                                 -*-*- END OF LINE -*-*-
     6 2004/01/15: Javier Rico
     7       
     8   * manalysis/MPedCalcPedRun.[h,cc]
     9     - optimize the running time
     10     - add (some) documentation
     11     - correct treatment for the case of several input files
     12
     13   * macros/pedvsevent.C
     14     - added
     15     - draw pedestal mean and rms vs event# for input pixel# and run
     16       file, and compares them to the global pedestal mean and rms
     17
    618
    719 2004/01/15: Raquel de los Reyes
  • trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc

    r2806 r2821  
    1818!   Author(s): Josep Flix 04/2001 <mailto:jflix@ifae.es>
    1919!   Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de>
     20!   Author(s): Sebastian Commichau 12/2003
     21!   Author(s): Javier Rico 01/2004
    2022!
    21 !   Copyright: MAGIC Software Development, 2000-2001
     23!   Copyright: MAGIC Software Development, 2000-2004
    2224!
    2325!
     
    2830//   MPedCalcPedRun                                                        //
    2931//                                                                         //
     32//  This task takes a pedestal run file and fills MPedestalCam during      //
     33//  the Process() with the pedestal and rms computed in an event basis.    //
     34//  In the PostProcess() MPedestalCam is finally filled with the pedestal  //
     35//  mean and rms computed in a run basis.                                  //
     36//  More than one run (file) can be merged                                 //
     37//                                                                         //
    3038//  Input Containers:                                                      //
    3139//   MRawEvtData                                                           //
     
    3341//  Output Containers:                                                     //
    3442//   MPedestalCam                                                          //
     43//                                                                         //
    3544//                                                                         //
    3645/////////////////////////////////////////////////////////////////////////////
     
    7079    if (!fRawEvt)
    7180    {
    72         *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
     81        *fLog << err << "MRawEvtData not found... aborting." << endl;
    7382        return kFALSE;
    7483    }
     
    7887        return kFALSE;
    7988
    80     MGeomCamMagic magiccam;
    81 
    82     fSumx.Set(magiccam.GetNumPixels());
    83     fSumx2.Set(magiccam.GetNumPixels());
    84    
    85     for(UInt_t i=0;i<magiccam.GetNumPixels();i++)
    86     {
    87         fSumx.AddAt(0,i);
    88         fSumx2.AddAt(0,i);
    89     }
     89    fNumSamplesTot=0;
    9090
    9191    return kTRUE;
    9292}
    9393
    94 Bool_t MPedCalcPedRun::ReInit(MParList *pList )   
     94Bool_t MPedCalcPedRun::ReInit(MParList *pList)
    9595{
     96    const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
     97    if (!runheader)
     98    {
     99        *fLog << warn << dbginf;
     100        *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl;
     101    }
     102    else
     103        if (runheader->GetRunType() == kRTMonteCarlo)
     104            return kTRUE;
    96105
    97     fRunheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
    98     if (!fRunheader)
    99         {
    100         *fLog << warn << dbginf <<
    101                 "Warning - cannot check file type, MRawRunHeader not found." << endl;
    102         }
    103     else
    104         if (fRunheader->GetRunType() == kRTMonteCarlo)
    105         {
    106             return kTRUE;
    107         }
     106    fNumPixels = fPedestals->GetSize();
    108107
    109     fNumHiGainSamples =  fRunheader->GetNumSamplesHiGain();
     108    if(fSumx.GetSize()==0)
     109      {
     110        fSumx.Set(fNumPixels);
     111        fSumx2.Set(fNumPixels);
    110112
    111     fPedestals->InitSize(fRunheader->GetNumPixel());
     113        memset(fSumx.GetArray(),  0, sizeof(Float_t)*fNumPixels);
     114        memset(fSumx2.GetArray(), 0, sizeof(Float_t)*fNumPixels);
     115      }
     116
     117    // Calculate an even number for the hi gain samples to avoid
     118    // biases due to the fluctuation in pedestal from one slice to
     119    // the other one
     120    fNumHiGainSamples = runheader->GetNumSamplesHiGain() & ~1;
    112121
    113122    return kTRUE;
    114 
    115123}
    116 
    117124
    118125Int_t MPedCalcPedRun::Process()
    119126{
    120 
    121127    MRawEvtPixelIter pixel(fRawEvt);
    122128
    123129    while (pixel.Next())
    124130    {
    125         Byte_t shift=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? 0:1;
    126131              Byte_t *ptr = pixel.GetHiGainSamples();
    127         const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples()-shift;
     132        const Byte_t *end = ptr + fNumHiGainSamples;
    128133
    129         const Float_t higainped = CalcHiGainMean(ptr, end);
    130         const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
    131 
    132         const UInt_t pixid = pixel.GetPixelId();
    133         MPedestalPix &pix = (*fPedestals)[pixid];
     134        UInt_t sum = 0;
     135        UInt_t sqr = 0;
    134136       
    135         // cumulate the sum of pedestals and of pedestal squares
    136         fSumx.AddAt(higainped+fSumx.At(pixid),pixid);
    137         fSumx2.AddAt(GetSumx2(ptr, end)+fSumx2.At(pixid),pixid);
    138 
    139         // set the value of the pedestal and rms computed from the processed event
    140         pix.Set(higainped, higainrms);
     137        do
     138          {
     139            sum += *ptr;
     140            sqr += *ptr * *ptr;
     141          }
     142        while (++ptr != end);
     143       
     144        const Float_t msum = (Float_t)sum;
     145        const Float_t msqr = (Float_t)sqr;
     146       
     147        const Float_t higainped = msum/fNumHiGainSamples;
     148        const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainSamples)/(fNumHiGainSamples-1.));
     149       
     150        const UInt_t idx = pixel.GetPixelId();
     151        (*fPedestals)[idx].Set(higainped, higainrms);
     152       
     153        fSumx[idx]  += msum;
     154        fSumx2[idx] += sqr;
    141155    }
    142 
     156   
    143157    fPedestals->SetReadyToSave();
    144 
     158    fNumSamplesTot+=fNumHiGainSamples;
     159   
    145160    return kTRUE;
    146161}
     
    148163Int_t MPedCalcPedRun::PostProcess()
    149164{
    150 // Compute pedestals and rms from the whole run
    151 
    152     MRawEvtPixelIter pixel(fRawEvt);
    153 
    154     while (pixel.Next())
     165  // Compute pedestals and rms from the whole run
     166  const Int_t n  = fNumSamplesTot;
     167 
     168  MRawEvtPixelIter pixel(fRawEvt);
     169 
     170  while (pixel.Next())
    155171    {
    156         const UInt_t pixid = pixel.GetPixelId();
    157         MPedestalPix &pix = (*fPedestals)[pixid];
    158 
    159         const Int_t N = GetNumExecutions();
    160         const Float_t sum = fSumx.At(pixid);
    161         const Float_t sum2 = fSumx2.At(pixid);
    162         const Float_t higainped = sum/N;
    163         const Float_t higainrms = sqrt(1./(N-1.)*(sum2-sum*sum/N));
    164         pix.Set(higainped,higainrms);
    165 
     172      const UInt_t pixid = pixel.GetPixelId();
     173     
     174      const Float_t sum  = fSumx.At(pixid);
     175      const Float_t sum2 = fSumx2.At(pixid);
     176     
     177      const Float_t higainped = sum/n;
     178      const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.));
     179     
     180      (*fPedestals)[pixid].Set(higainped, higainrms);
    166181    }
    167     return kTRUE;
    168 
     182 
     183  return kTRUE;
    169184}
    170185
    171186
    172 Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
    173 {
    174     Int_t sum=0;
    175     Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples)
    176                         ? fNumHiGainSamples : fNumHiGainSamples-1;
    177 
    178     do sum += *ptr;
    179     while (++ptr != end);
    180    
    181     return (Float_t)sum/EvenNumSamples;
    182 }
    183 
    184 
    185 
    186 Float_t MPedCalcPedRun::GetSumx2(Byte_t *ptr, const Byte_t *end) const
    187 {
    188     Float_t square = 0;
    189 
    190     // Take an even number of time slices to avoid biases due to A/B effect
    191     Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
    192 
    193     do
    194     {
    195         const Float_t val = (Float_t)(*ptr);
    196 
    197         square += val*val;
    198     } while (++ptr != end);
    199 
    200     return square/EvenNumSamples;
    201 }
    202 
    203 
    204 Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const
    205 {
    206     Float_t rms = 0;
    207     Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
    208 
    209     do
    210     {
    211         const Float_t diff = (Float_t)(*ptr)-higainped;
    212 
    213         rms += diff*diff;
    214     } while (++ptr != end);
    215 
    216     return sqrt(rms/(EvenNumSamples-1));
    217 }
    218 
    219 
    220 
    221 /*
    222 Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
    223 {
    224     return higainrms/sqrt((float)fNumHiGainSamples);
    225 }
    226 
    227 Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const
    228 {
    229     return higainrms/sqrt(2.*fNumHiGainSamples);
    230 }
    231 */
  • trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h

    r2747 r2821  
    1616#include <TArrayF.h>
    1717
    18 class MRawRunHeader;
    1918class MRawEvtData;
    2019class MPedestalCam;
     
    2221class MPedCalcPedRun : public MTask
    2322{
    24     Byte_t fNumHiGainSamples;
     23    Byte_t   fNumHiGainSamples;
     24    UShort_t fNumPixels;
     25    ULong_t   fNumSamplesTot;
    2526
    26     MRawRunHeader *fRunheader; // raw event run header
    2727    MRawEvtData  *fRawEvt;     // raw event data (time slices)
    2828    MPedestalCam *fPedestals;  // Pedestals of all pixels in the camera
     
    3030    TArrayF fSumx;   // sum of values
    3131    TArrayF fSumx2;  // sum of squared values
    32 
    33     Float_t CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const;
    34     Float_t CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const;
    35     Float_t GetSumx2(Byte_t* ptr, const Byte_t* end) const;
    36    //Float_t CalcHiGainMeanErr(Float_t higainrms) const;
    37     //Float_t CalcHiGainRmsErr(Float_t higainrms) const;
    3832
    3933    Bool_t ReInit(MParList *pList);
     
    4438
    4539public:
    46 
    4740    MPedCalcPedRun(const char *name=NULL, const char *title=NULL);
    4841
Note: See TracChangeset for help on using the changeset viewer.