Ignore:
Timestamp:
11/09/04 14:55:21 (20 years ago)
Author:
gaug
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mpedestal
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc

    r5353 r5356  
    107107//
    108108//  Call:
    109 //  SetCheckRange(fCheckWinFirst,fCheckWinLast);
     109//  SetCheckRange(fCheckWinFirst,fCheckWinLast); 
    110110//  to set the Window in which a signal is searched
    111111//
     
    179179    : fGeom(NULL), fPedContainerName("MPedestalCam")
    180180{
     181
    181182  fName  = name  ? name  : "MPedCalcFromLoGain";
    182183  fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
     
    191192  SetPedestalUpdate(kTRUE);
    192193  Clear();
     194
    193195}
    194196
     
    196198//
    197199// Sets:
    198 // - fNumSamplesTot to 0
    199200// - fRawEvt to NULL
    200201// - fRunHeader to NULL
    201202// - fPedestals to NULL
    202203//
     204// Resets:
     205// - fSumx
     206// - fSumx2
     207// - fSumAB0
     208// - fSumAB1
     209// - fNumEventsUsed
     210// - fTotalCounter
     211//
    203212void MPedCalcFromLoGain::Clear(const Option_t *o)
    204213{
     214
    205215  fRawEvt    = NULL;
    206216  fRunHeader = NULL;
     
    223233//
    224234// SetCheckRange:
    225 //
    226 // Calls:
    227 // - MExtractor::SetCheckRange(hifirst,hilast,lofirst,lolast);
    228 // - SetExtractWindow(fWindowSizeHiGain,fExtractWinSize);
     235//
     236// Exits, if the first argument is smaller than 0
     237// Exits, if the the last argument is smaller than the first
    229238//
    230239void MPedCalcFromLoGain::SetCheckRange(Int_t chfirst, Int_t chlast)
    231240{
    232241
    233 
    234   if(chfirst<0){
    235     *fLog << warn << GetDescriptor()
    236            << Form(": First slice in window to check for Signal <0, adjust:")<< endl;
    237     exit(-1);
    238     }
    239 
    240   if(chlast<=chfirst){
    241     *fLog << warn << GetDescriptor()
    242           << Form(": Last slice in Check window smaller than first slice in window, adjust:")<< endl;
    243     exit(-1);
    244     }
    245 
     242  if(chfirst<0)
     243    {
     244      *fLog << warn << GetDescriptor()
     245            << ": First slice in window to check for Signal <0, adjust:" << endl;
     246      exit(-1);
     247    }
     248
     249  if(chlast<=chfirst)
     250    {
     251      *fLog << warn << GetDescriptor()
     252            << ": Last slice in Check window smaller than first slice in window, adjust:" << endl;
     253      exit(-1);
     254    }
     255 
    246256  fCheckWinFirst = chfirst;
    247257  fCheckWinLast = chlast;
    248258
     259}
     260
     261// --------------------------------------------------------------------------
     262//
     263// Exits:
     264// - if a window is odd
     265//
     266void MPedCalcFromLoGain::SetExtractWindow(Int_t windowf, Int_t windows)
     267{
    249268 
    250 }
    251 
    252 // --------------------------------------------------------------------------
    253 //
    254 void MPedCalcFromLoGain::SetMaxSignalVar(Int_t maxvar)
    255 {
    256   fMaxSignalVar = maxvar;
    257 }
    258 
    259 // --------------------------------------------------------------------------
    260 //
    261 // Checks:
    262 // - if a window is odd
    263 //
    264 void MPedCalcFromLoGain::SetExtractWindow(Int_t windowf, Int_t windows)
    265 {
    266  
    267   if(windowf<0){
    268     *fLog << warn << GetDescriptor()
    269            << Form(": First slice in Extract window has to be >0, adjust:")<< endl;
    270     exit(-1);
     269  if(windowf<0)
     270    {
     271      *fLog << warn << GetDescriptor()
     272            << Form(": First slice in Extract window has to be >0, adjust:")<< endl;
     273      exit(-1);
    271274    }
    272275 
    273276  Int_t odd  = windows & 0x1;
    274277 
    275   if (odd||(windows==0)){
    276     *fLog << warn << GetDescriptor() << ": Extract window size has to be even and larger 0, adjust!"<< endl;
    277     exit(-1);
    278   }
    279 
    280   fExtractWinSize = windows;
     278  if (odd||(windows==0))
     279    {
     280      *fLog << warn << GetDescriptor() << ": Extract window size has to be even and larger 0, adjust!"<< endl;
     281      exit(-1);
     282    }
     283 
     284  fExtractWinSize  = windows;
    281285  fExtractWinFirst = windowf;
    282   fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
    283 
    284 //
    285 //  NO RANGE CHECK IMPLEMENTED, YET
    286 //
     286  fExtractWinLast  = fExtractWinFirst+fExtractWinSize-1;
     287 
    287288/*
    288289    const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
     
    322323// they were not found:
    323324//
    324 //  - MPedestalCam
     325//  - MPedestalCam with the name fPedContainerName
    325326//
    326327Int_t MPedCalcFromLoGain::PreProcess(MParList *pList)
    327328{
     329
    328330    Clear();
    329331
     
    362364}
    363365
    364 // --------------------------------------------------------------------------
    365 //
    366 // The ReInit searches for:
    367 // -  MRawRunHeader::GetNumSamplesHiGain()
    368 // -  MRawRunHeader::GetNumSamplesLoGain()
    369 //
    370 
     366// ---------------------------------------------------------------------------------
     367//
     368// Checks:
     369// - if the number of available slices
     370//   (fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1)
     371//   is smaller than the number of used slices
     372//   (fExtractWinSize+ fExtractWinFirst-1) or
     373//    fCheckWinLast
     374//
     375// Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
     376//  - fSumx
     377//  - fSumx2
     378//  - fSumAB0
     379//  - fSumAB1
     380//  - fNumEventsUsed
     381//  - fTotalCounter
     382//
    371383Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
    372384{
    373385
    374   Int_t lastavailableslice = (Int_t)fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1;
    375 
    376   Int_t lastextractslice =  fExtractWinSize+ fExtractWinFirst - 1;
    377 
    378    if ( lastextractslice  > lastavailableslice)//changed to override check
     386  Int_t lastavailableslice = (Int_t)fRunHeader->GetNumSamplesHiGain()
     387                            +(Int_t)fRunHeader->GetNumSamplesLoGain()-1;
     388  Int_t lastextractslice   =  fExtractWinSize+ fExtractWinFirst - 1;
     389
     390   if ( lastextractslice  > lastavailableslice ) //changed to override check
    379391    {
    380392      *fLog << endl;
     
    382394            << Form(": Selected Extract Window ranges out of the available limits adjust. Last available slice is %2i",
    383395                    lastavailableslice) << endl;
    384       exit(-1);
    385     }
    386 
    387   if (  fCheckWinLast  > lastavailableslice)//changed to override check
     396      return kFALSE;
     397    }
     398
     399  if ( fCheckWinLast  > lastavailableslice ) //changed to override check
    388400    {
    389401      *fLog << endl;
     
    391403            << Form(": Last Check Window slice is out of the available limits adjust. Last available slice is %2i",
    392404                    lastavailableslice) << endl;
    393       exit(-1);
     405      return kFALSE;
    394406    }
    395407
     
    420432}
    421433
     434// ---------------------------------------------------------------------------------
     435//
     436// Calculates for pixel "idx":
     437//
     438// Ped per slice      = sum / n / fExtractWinSize;
     439// RMS per slice      = sqrt { (sum2 -  sum*sum/n) / (n-1) / fExtractWinSize }
     440// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
     441//
     442// Sets fTotalCounter up by 1.
     443//
    422444void MPedCalcFromLoGain::Calc(ULong_t n, UInt_t idx)
    423445{
    424     const ULong_t nsamplestot = n*fExtractWinSize;
    425 
    426     const Float_t sum  = fSumx.At(idx);
    427     const Float_t sum2 = fSumx2.At(idx);
    428     const Float_t ped  = sum/nsamplestot;
    429 
    430     // 1. Calculate the Variance of the sums:
    431     Float_t var = (sum2-sum*sum/n)/(n-1.);
    432 
    433     // 2. Scale the variance to the number of slices:
    434     var /= (Float_t)(fExtractWinSize);
    435 
    436     // 3. Calculate the RMS from the Variance:
    437     const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
    438 
    439     // 4. Calculate the amplitude of the 150MHz "AB" noise
    440     const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
    441 
    442     (*fPedestals)[idx].Set(ped, rms, abOffs, n);
    443 
    444     fTotalCounter[idx]++;
    445 }
    446 
     446
     447  const ULong_t nsamplestot = n*fExtractWinSize;
     448 
     449  const Float_t sum  = fSumx.At(idx);
     450  const Float_t sum2 = fSumx2.At(idx);
     451  const Float_t ped  = sum/nsamplestot;
     452 
     453  // 1. Calculate the Variance of the sums:
     454  Float_t var = (sum2-sum*sum/n)/(n-1.);
     455
     456  // 2. Scale the variance to the number of slices:
     457  var /= (Float_t)(fExtractWinSize);
     458 
     459  // 3. Calculate the RMS from the Variance:
     460  const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
     461 
     462  // 4. Calculate the amplitude of the 150MHz "AB" noise
     463  const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
     464 
     465  (*fPedestals)[idx].Set(ped, rms, abOffs, n);
     466 
     467  fTotalCounter[idx]++;
     468}
     469
     470// ---------------------------------------------------------------------------------
     471//
     472// Returns the pointer to slice "slice".
     473//
    447474UInt_t MPedCalcFromLoGain::GetSlice(MRawEvtPixelIter *pixel, UInt_t slice)
    448475{
     
    459486 else
    460487   {
    461     ptr = pixel->GetHiGainSamples();
    462     ptr += slice;
     488     ptr = pixel->GetHiGainSamples();
     489     ptr += slice;
    463490   }
    464491
     
    535562
    536563        if (!fPedestalUpdate || fNumEventsUsed[idx]<fNumEventsDump)
    537             continue;
     564          continue;
    538565
    539566        Calc(fNumEventsDump, idx);
     
    547574
    548575    if (fPedestalUpdate)
    549         fPedestals->SetReadyToSave();
     576      fPedestals->SetReadyToSave();
    550577
    551578    return kTRUE;
     
    560587    // Compute pedestals and rms from the whole run
    561588    if (fPedestalUpdate)
    562         return kTRUE;
     589      return kTRUE;
    563590
    564591    *fLog << flush << inf << "Calculating Pedestals..." << flush;
     
    566593    const Int_t npix = fGeom->GetNumPixels();
    567594    for (Int_t idx=0; idx<npix; idx++)
    568     {
     595      {
    569596        const ULong_t n = fNumEventsUsed[idx];
    570597        if (n>1)
    571             Calc(n, idx);
    572     }
     598          Calc(n, idx);
     599      }
    573600
    574601    fPedestals->SetReadyToSave();
    575602    return kTRUE;
    576603}
     604
    577605
    578606Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h

    r5338 r5356  
    6969    void SetCheckRange(Int_t checkfirst=0, Int_t checklast=29);
    7070    void SetExtractWindow(Int_t extractfirst=15, Int_t windowsize=6);
    71     void SetMaxSignalVar(Int_t maxvar=0);
    72     void SetNumEventsDump(UInt_t dumpevents = 0) {fNumEventsDump = dumpevents;}
     71    void SetMaxSignalVar(Int_t maxvar=0)         { fMaxSignalVar = maxvar;    }
     72    void SetNumEventsDump(UInt_t dumpevents = 0) { fNumEventsDump = dumpevents;}
    7373    void SetPedestalUpdate(Bool_t pedupdate)  {fPedestalUpdate = pedupdate;}
    7474
Note: See TracChangeset for help on using the changeset viewer.