Ignore:
Timestamp:
11/04/04 17:35:11 (20 years ago)
Author:
otte
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mpedestal
Files:
2 edited

Legend:

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

    r5204 r5338  
    1919!   Author(s): Thomas Bretz 05/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
    2020!   Author(s): Sebastian Commichau 12/2003
    21 !   Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
     21!   Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es> 
    2222!   Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
    2323!   Author(s): Florian Goebel 06/2004 <mailto:fgoebel@mppmu.mpg.de>
     24!   Author(s): Nepomuk Otte 10/2004 <mailto:otte@mppmu.mpg.de>
    2425!
    2526!   Copyright: MAGIC Software Development, 2000-2004
     
    2930
    3031/////////////////////////////////////////////////////////////////////////////
     32//
     33//
    3134//
    3235//   MPedCalcLoGain
    3336//
    3437//
    35 //  This task is derived form MPedCalcPedRun, described below. However, It
     38//  This task is devide form MPedCalcPedRun, described below. However, It
    3639//  calculates the pedstals using the low gain slices, whenever the difference
    3740//  between the highest and the lowest slice in the high gain
     
    9598//  Usage of this class:
    9699//  ====================
    97 //
    98 //  Call: SetRange(higainfirst, higainlast, logainfirst, logainlast)
    99 //  to modify the ranges in which the window is allowed to move.
    100 //  Defaults are:
    101 //
    102 //   fHiGainFirst =  fgHiGainFirst =  0
    103 //   fHiGainLast  =  fgHiGainLast  =  29
    104 //   fLoGainFirst =  fgLoGainFirst =  0
    105 //   fLoGainLast  =  fgLoGainLast  =  14
    106 //
    107 //  Call: SetWindowSize(windowhigain, windowlogain)
    108 //  to modify the sliding window widths. Windows have to be an even number.
    109 //  In case of odd numbers, the window will be modified.
    110 //
    111 //  Defaults are:
    112 //
    113 //   fHiGainWindowSize = fgHiGainWindowSize = 14
    114 //   fLoGainWindowSize = fgLoGainWindowSize = 0
    115 //
    116 //  Variables:
    117 //   fgHiGainFirst;      First FADC slice Hi-Gain (currently set to: 3)
    118 //   fgHiGainLast:       Last FADC slice Hi-Gain (currently set to: 14)
    119 //   fgLoGainFirst:      First FADC slice Lo-Gain (currently set to: 3)
    120 //   fgLoGainLast:       Last FADC slice Lo-Gain (currently set to: 14)
    121 //   fgHiGainWindowSize: The extraction window Hi-Gain
    122 //   fgLoGainWindowSize: The extraction window Lo-Gain
    123 //   fgMaxHiGainVar:     The maximum difference between the highest and lowest slice
    124 //                       in the high gain window allowed in order to use low gain
     100// 
     101//
     102//   fCheckWinFirst =  fgCheckWinFirst =  0
     103//   fHiGainLast  =  fgCheckWinLast  =  29
     104//   fExtractWinFirst =  fgExtractWinFirst =  0
     105//   fExtractWinSize  =  fgExtractWinSize  =  6
     106//   fMaxSignalVar   =   fgMaxSignalVar  = 40;
     107//
     108//  Call:
     109//  SetCheckRange(fCheckWinFirst,fCheckWinLast);
     110//  to set the Window in which a signal is searched
     111//
     112//  SetExtractWindow(fExtractWindFirst,fExtractWinSize);
     113//  to set the Window from which a signal is extracted
     114//
     115//  SetMaxSignalVar(fMaxSignalVar);
     116//  set the maximum allowed difference between maximum and minimal signal in CheckWindow 
     117//
     118//   Variables:
     119//   fgCheckWinFirst;      First FADC slice to check for signal (currently set to: 0)
     120//   fgCheckWinLast:       Last FADC slice to check for signal (currently set to: 29)
     121//   fgExtractWinFirst:    First FADC slice to be used for pedestal extraction (currently set to: 15)
     122//   fgExtractWinSize:     Window size in slices used for pedestal extraction (currently set to: 6)
     123//   fgMaxSignalVar:       The maximum difference between the highest and lowest slice
     124//                         in the check window allowed in order to use event
    125125//
    126126//  Input Containers:
     
    157157using namespace std;
    158158
    159 const Byte_t MPedCalcFromLoGain::fgHiGainFirst      = 0;
    160 const Byte_t MPedCalcFromLoGain::fgHiGainLast       = 11;
    161 const Byte_t MPedCalcFromLoGain::fgLoGainFirst      = 1;
    162 const Byte_t MPedCalcFromLoGain::fgLoGainLast       = 14;
    163 const Byte_t MPedCalcFromLoGain::fgHiGainWindowSize = 12;
    164 const Byte_t MPedCalcFromLoGain::fgLoGainWindowSize = 14;
    165 const Byte_t MPedCalcFromLoGain::fgMaxHiGainVar     = 40;
     159const Int_t MPedCalcFromLoGain::fgCheckWinFirst      = 0;
     160const Int_t MPedCalcFromLoGain::fgCheckWinLast       = 29;
     161const Int_t MPedCalcFromLoGain::fgExtractWinFirst    = 15;
     162const Int_t MPedCalcFromLoGain::fgExtractWinSize     = 6;
     163const Int_t MPedCalcFromLoGain::fgMaxSignalVar       = 40;
    166164
    167165// --------------------------------------------------------------------------
     
    171169// Sets:
    172170// - all pointers to NULL
    173 // - fWindowSizeHiGain to fgHiGainWindowSize
    174 // - fWindowSizeLoGain to fgLoGainWindowSize
    175171//
    176172// Calls:
    177173// - AddToBranchList("fHiGainPixId");
    178174// - AddToBranchList("fHiGainFadcSamples");
    179 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
     175// - SetCheckRange(fgCheckWinFirst, fgCheckWinLast, fgExtractWinFirst, fgExtractWinSize)
    180176// - Clear()
    181177//
    182178MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
    183     : fWindowSizeHiGain(fgHiGainWindowSize),
    184       fWindowSizeLoGain(fgLoGainWindowSize),
    185       fGeom(NULL), fPedContainerName("MPedestalCam")
    186 {
    187     fName  = name  ? name  : "MPedCalcFromLoGain";
    188     fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
    189 
    190     AddToBranchList("fHiGainPixId");
    191     AddToBranchList("fLoGainPixId");
    192     AddToBranchList("fHiGainFadcSamples");
    193     AddToBranchList("fLoGainFadcSamples");
    194 
    195     SetRange();
    196     SetMaxHiGainVar();
    197     SetPedestalUpdate(kTRUE);
    198     SetNumEventsDump(500);
    199 
    200     Clear();
     179    : fGeom(NULL), fPedContainerName("MPedestalCam")
     180{
     181  fName  = name  ? name  : "MPedCalcFromLoGain";
     182  fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
     183 
     184  AddToBranchList("fHiGainPixId");
     185  AddToBranchList("fHiGainFadcSamples");
     186 
     187  SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
     188  SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
     189
     190  SetMaxSignalVar(fgMaxSignalVar);
     191  SetPedestalUpdate(kTRUE);
     192  Clear();
    201193}
    202194
     
    211203void MPedCalcFromLoGain::Clear(const Option_t *o)
    212204{
    213     fRawEvt    = NULL;
    214     fRunHeader = NULL;
    215     fPedestals = NULL;
    216 
    217     // If the size is yet set, set the size
    218     if (fSumx.GetSize()>0)
    219     {
    220         // Reset contents of arrays.
    221         fSumx.Reset();
    222         fSumx2.Reset();
    223         fSumAB0.Reset();
    224         fSumAB1.Reset();
    225         fNumEventsUsed.Reset();
    226         fTotalCounter.Reset();
    227     }
    228 }
    229 
    230 // --------------------------------------------------------------------------
    231 //
    232 // SetRange:
     205  fRawEvt    = NULL;
     206  fRunHeader = NULL;
     207  fPedestals = NULL;
     208
     209  // If the size is yet set, set the size
     210  if (fSumx.GetSize()>0)
     211  {
     212      // Reset contents of arrays.
     213      fSumx.Reset();
     214      fSumx2.Reset();
     215      fSumAB0.Reset();
     216      fSumAB1.Reset();
     217      fNumEventsUsed.Reset();
     218      fTotalCounter.Reset();
     219  }
     220}
     221
     222// --------------------------------------------------------------------------
     223//
     224// SetCheckRange:
    233225//
    234226// Calls:
    235 // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
    236 // - SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
    237 //
    238 void MPedCalcFromLoGain::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
    239 {
    240     MExtractor::SetRange(hifirst, hilast, lofirst, lolast);
    241 
    242     //
    243     // Redo the checks if the window is still inside the ranges
    244     //
    245     SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
    246 }
    247 
    248 // --------------------------------------------------------------------------
    249 //
    250 void MPedCalcFromLoGain::SetMaxHiGainVar(Byte_t maxvar)
    251 {
    252     fMaxHiGainVar = maxvar;
     227// - MExtractor::SetCheckRange(hifirst,hilast,lofirst,lolast);
     228// - SetExtractWindow(fWindowSizeHiGain,fExtractWinSize);
     229//
     230void MPedCalcFromLoGain::SetCheckRange(Int_t chfirst, Int_t chlast)
     231{
     232
     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
     246  fCheckWinFirst = chfirst;
     247  fCheckWinLast = chlast;
     248
     249 
     250}
     251
     252// --------------------------------------------------------------------------
     253//
     254void MPedCalcFromLoGain::SetMaxSignalVar(Int_t maxvar)
     255{
     256  fMaxSignalVar = maxvar;
    253257}
    254258
     
    256260//
    257261// Checks:
    258 // - if a window is odd, subtract one
    259 // - if a window is bigger than the one defined by the ranges, set it to the available range
    260 // - if a window is smaller than 2, set it to 2
    261 //
    262 // Sets:
    263 // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain
    264 // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain
    265 // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
    266 // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples) 
    267 // 
    268 void MPedCalcFromLoGain::SetWindowSize(Byte_t windowh, Byte_t windowl)
    269 {
    270 
    271     fWindowSizeHiGain = windowh & ~1;
    272     fWindowSizeLoGain = windowl & ~1;
    273  
    274     if (fWindowSizeHiGain != windowh)
    275     {
    276         *fLog << warn;
    277         *fLog << GetDescriptor() << ": HiGain window has to be even, set to: ";
    278         *fLog << int(fWindowSizeHiGain) << " samples " << endl;
    279     }
    280    
    281     if (fWindowSizeLoGain != windowl)
    282     {
    283         *fLog << warn;
    284         *fLog << GetDescriptor() << ": Lo Gain window has to be even, set to: ";
    285         *fLog << int(fWindowSizeLoGain) << " samples " << endl;
    286     }
    287 
    288     if (fWindowSizeHiGain == 0)
    289     {
    290         *fLog << warn;
    291         *fLog << GetDescriptor() << ": HiGain window currently set to 0, will set it to 2 samples ";
    292         fWindowSizeHiGain = 2;
    293     }
    294    
    295     if (fWindowSizeLoGain == 0)
    296     {
    297         *fLog << warn;
    298         *fLog << GetDescriptor() << ": LoGain window currently set to 0, will set it to 2 samples ";
    299         fWindowSizeLoGain = 2;
    300     }
    301    
    302     const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
    303     const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
    304  
    305     if (fWindowSizeHiGain > availhirange)
    306     {
    307         *fLog << warn;
    308         *fLog << GetDescriptor() << ": HiGain window " << (int)fWindowSizeHiGain;
    309         *fLog << " out of range [" << (int)fHiGainFirst;
    310         *fLog << "," << (int)fHiGainLast << "]" << endl;
    311         *fLog << "Will set window size to " << (int)availhirange << endl;
    312         fWindowSizeHiGain = availhirange;
    313     }
    314    
    315     if (fWindowSizeLoGain > availlorange)
    316     {
    317         *fLog << warn;
    318         *fLog << GetDescriptor() << ": LoGain window " << (int)fWindowSizeLoGain;
    319         *fLog << " out of range [" << (int)fLoGainFirst;
    320         *fLog << "," << (int)fLoGainLast << "]" << endl;
    321         *fLog << "Will set window size to " << (int)availlorange << endl;
    322         fWindowSizeLoGain = availlorange;
    323     }
    324     /*
    325      fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
    326      fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
    327 
    328      fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
    329      fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
    330     */
     262// - if a window is odd
     263//
     264 
     265void MPedCalcFromLoGain::SetExtractWindow(Int_t windowf, Int_t windows)
     266{
     267 
     268  if(windowf<0){
     269    *fLog << warn << GetDescriptor()
     270           << Form(": First slice in Extract window has to be >0, adjust:")<< endl;
     271    exit(-1);
     272    }
     273 
     274  Int_t odd  = windows & 0x1;
     275 
     276
     277  if (odd||(windows==0)){
     278    *fLog << warn << GetDescriptor() << ": Extract window size has to be even and larger 0, adjust!"<< endl;
     279    exit(-1);
     280  }
     281
     282  fExtractWinSize = windows;
     283  fExtractWinFirst = windowf;
     284  fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
     285
     286 
    331287}
    332288
     
    369325    }
    370326
     327
    371328    fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fPedContainerName));
    372329    if (!fPedestals)
    373330        return kFALSE;
    374331
    375     if (fNumEventsDump<=0 && fPedestalUpdate)
    376     {
    377         *fLog << warn << "Pedestal Update switched on and Number of Events to dump <= 0... fNumEventsDump=1000" << endl;
    378         fNumEventsDump=1000;
    379     }
    380 
    381     *fLog << inf << "Continous update switched " << (fPedestalUpdate?"on":"off");
    382     if (fPedestalUpdate)
    383         *fLog << " (dump each " << fNumEventsDump << " events)" << endl;
    384     *fLog << endl;
    385 
    386332    return kTRUE;
    387333}
     
    393339// -  MRawRunHeader::GetNumSamplesLoGain()
    394340//
    395 // In case that the variables fHiGainLast and fLoGainLast are smaller than
    396 // the even part of the number of samples obtained from the run header, a
    397 // warning is given an the range is set back accordingly. A call to: 
    398 // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or
    399 // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
    400 // is performed in that case. The variable diff means here the difference
    401 // between the requested range (fHiGainLast) and the available one. Note that
    402 // the functions SetRange() are mostly overloaded and perform more checks,
    403 // modifying the ranges again, if necessary.
    404 //
     341
    405342Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
    406343{
    407     if (fRunHeader->GetNumSamplesHiGain()<1)
    408     {
    409         *fLog << err << "ERROR - Number of available HiGainSamples<1... abort." << endl;
    410         return kFALSE;
    411     }
    412     if (fRunHeader->GetNumSamplesLoGain()<1)
    413     {
    414         *fLog << err << "ERROR - Number of available LoGainSamples<1... abort." << endl;
    415         return kFALSE;
    416     }
    417 
    418     fHiGainFirst = TMath::Max(fHiGainFirst, 0);
    419     fHiGainLast  = TMath::Min(fHiGainLast,  fRunHeader->GetNumSamplesHiGain()-1);
    420 
    421     fLoGainFirst = TMath::Max(fLoGainFirst, 0);
    422     fLoGainLast  = TMath::Min(fLoGainLast,  fRunHeader->GetNumSamplesLoGain()-1);
    423 
    424     const Double_t wh = fWindowSizeHiGain;
    425     const Double_t wl = fWindowSizeLoGain;
    426     const Double_t fh = fHiGainFirst;
    427     const Double_t fl = fLoGainFirst;;
    428 
    429     fWindowSizeHiGain = TMath::Min(fWindowSizeHiGain, fHiGainLast-fHiGainFirst+1);
    430     fWindowSizeLoGain = TMath::Min(fWindowSizeLoGain, fLoGainLast-fLoGainFirst+1);
    431 
    432     SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast);
    433 
    434     if (wh!=fWindowSizeHiGain || fh!=fHiGainFirst || wl!=fWindowSizeLoGain || fl!=fLoGainFirst)
    435     {
    436         *fLog << inf << endl;
    437         *fLog << "Taking " << Form("%2d", (int)fWindowSizeHiGain) << " slices of Hi-Gain starting at slice " << (int)fHiGainFirst << endl;
    438         *fLog << "Taking " << Form("%2d", (int)fWindowSizeLoGain) << " slices of Lo-Gain starting at slice " << (int)fLoGainFirst << endl;
    439     }
    440 
    441     if (fWindowSizeHiGain==0)
    442     {
    443         *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl;
    444         return kFALSE;
    445     }
    446     if (fWindowSizeLoGain==0)
    447     {
    448         *fLog << err << "ERROR - LoGain windows size == 0... abort." << endl;
    449         return kFALSE;
    450     }
    451 
    452     // If the size is not yet set, set the size
    453     if (fSumx.GetSize()==0)
    454     {
    455         const Int_t npixels = fPedestals->GetSize();
    456 
    457         fSumx. Set(npixels);
    458         fSumx2.Set(npixels);
    459         fSumAB0.Set(npixels);
    460         fSumAB1.Set(npixels);
    461         fNumEventsUsed.Set(npixels);
    462         fTotalCounter.Set(npixels);
    463 
    464         // Reset contents of arrays.
    465         fSumx.Reset();
    466         fSumx2.Reset();
    467         fSumAB0.Reset();
    468         fSumAB1.Reset();
    469         fNumEventsUsed.Reset();
    470         fTotalCounter.Reset();
    471     }
    472 
    473     return kTRUE;
     344
     345  Int_t lastavailableslice = (Int_t)fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1;
     346
     347  Int_t lastextractslice =  fExtractWinSize+ fExtractWinFirst - 1;
     348
     349   if ( lastextractslice  > lastavailableslice)//changed to override check
     350    {
     351      *fLog << endl;
     352      *fLog << warn << GetDescriptor()
     353            << Form(": Selected Extract Window ranges out of the available limits adjust. Last available slice is %2i",
     354                    lastavailableslice) << endl;
     355      exit(-1);
     356    }
     357
     358  if (  fCheckWinLast  > lastavailableslice)//changed to override check
     359    {
     360      *fLog << endl;
     361      *fLog << warn << GetDescriptor()
     362            << Form(": Last Check Window slice is out of the available limits adjust. Last available slice is %2i",
     363                    lastavailableslice) << endl;
     364      exit(-1);
     365    }
     366
     367
     368 
     369  // If the size is not yet set, set the size
     370  if (fSumx.GetSize()==0)
     371  {
     372      const Int_t npixels = fPedestals->GetSize();
     373
     374      fSumx. Set(npixels);
     375      fSumx2.Set(npixels);
     376      fSumAB0.Set(npixels);
     377      fSumAB1.Set(npixels);
     378      fNumEventsUsed.Set(npixels);
     379      fTotalCounter.Set(npixels);
     380
     381      // Reset contents of arrays.
     382      fSumx.Reset();
     383      fSumx2.Reset();
     384      fSumAB0.Reset();
     385      fSumAB1.Reset();
     386      fNumEventsUsed.Reset();
     387      fTotalCounter.Reset();
     388  }
     389 
     390  return kTRUE;
    474391}
    475392
    476393void MPedCalcFromLoGain::Calc(ULong_t n, UInt_t idx)
    477394{
    478     const ULong_t nsamplestot = n*fWindowSizeLoGain;
     395    const ULong_t nsamplestot = n*fExtractWinSize;
    479396
    480397    const Float_t sum  = fSumx.At(idx);
     
    486403
    487404    // 2. Scale the variance to the number of slices:
    488     var /= (Float_t)(fWindowSizeLoGain);
     405    var /= (Float_t)(fExtractWinSize);
    489406
    490407    // 3. Calculate the RMS from the Variance:
     
    497414
    498415    fTotalCounter[idx]++;
     416}
     417
     418UInt_t MPedCalcFromLoGain::GetSlice(MRawEvtPixelIter *pixel, UInt_t slice)
     419{
     420
     421 const UInt_t nh = (Int_t)fRunHeader->GetNumSamplesHiGain();
     422
     423 Byte_t *ptr;
     424
     425 if(slice>=nh)
     426   {
     427     ptr = pixel->GetLoGainSamples();
     428     ptr += slice - nh;
     429   }
     430 else
     431   {
     432    ptr = pixel->GetHiGainSamples();
     433    ptr += slice;
     434   }
     435
     436   return *ptr;
    499437}
    500438
     
    511449    while (pixel.Next())
    512450    {
    513         const UInt_t idx = pixel.GetPixelId();
    514 
    515         Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst;
    516         Byte_t *end = ptr + fWindowSizeHiGain;
    517 
    518         UInt_t sum = 0;
    519         UInt_t sqr = 0;
    520 
    521         UInt_t max = 0;
    522         UInt_t min = 255;
     451
     452         const UInt_t idx = pixel.GetPixelId();
     453
     454        Int_t max = 0;
     455        Int_t min = 1025;
    523456   
    524457        // Find the maximum and minimum signal per slice in the high gain window
    525         do {
    526             if (*ptr > max)
    527                 max = *ptr;
    528             if (*ptr < min)
    529                 min = *ptr;
    530         } while (++ptr != end);
     458     
     459        for(Int_t slice=fCheckWinFirst; slice<=fCheckWinLast; slice++)
     460          {
     461   
     462          Int_t svalue = GetSlice(&pixel,slice);
     463            if (svalue > max) {
     464                max = svalue;
     465            }
     466            if (svalue < min) {
     467                min = svalue;
     468            }
     469        }
    531470
    532471        // If the maximum in the high gain window is smaller than
    533         if (max-min>=fMaxHiGainVar || max>=255)
     472        if (max-min>=fMaxSignalVar || max>=250)
    534473            continue;
    535474
    536         ptr = pixel.GetLoGainSamples() + fLoGainFirst;
    537         end = ptr + fWindowSizeLoGain;
    538 
    539         Byte_t *firstSlice = ptr;
    540 
    541         do {
    542             sum += *ptr;
    543             sqr += *ptr * *ptr;
    544         } while (++ptr != end);
     475        UInt_t sum = 0;
     476        UInt_t sqr = 0;
     477
     478        //extract pedestal
     479        for(Int_t slice=fExtractWinFirst; slice<=fExtractWinLast; slice++)
     480          {   
     481          UInt_t svalue = GetSlice(&pixel,slice);
     482          sum += svalue;
     483          sqr += svalue*svalue;
     484        }
    545485
    546486        const Float_t msum   = (Float_t)sum;
     
    553493        // Calculate the amplitude of the 150MHz "AB" noise
    554494
    555         if (pixel.IsABFlagValid())
     495        Int_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1;
     496
     497        //cout << " MPedCalcFromLoGain: idx: " << idx << " abFlag: " << abFlag << endl;
     498
     499        for (Int_t islice=fExtractWinFirst; islice<=fExtractWinLast; islice+=2)
    556500        {
    557             const Int_t abFlag = (fRunHeader->GetNumSamplesHiGain()
    558                                   + fLoGainFirst + pixel.HasABFlag()) & 0x1;
    559             for (Int_t islice=0; islice<fWindowSizeLoGain; islice+=2)
    560             {
    561                 const Int_t sliceAB0 = islice + abFlag;
    562                 const Int_t sliceAB1 = islice - abFlag + 1;
    563                 fSumAB0[idx] += firstSlice[sliceAB0];
    564                 fSumAB1[idx] += firstSlice[sliceAB1];
    565             }
     501            Int_t sliceAB0 = islice + abFlag;
     502            Int_t sliceAB1 = islice - abFlag + 1;
     503            fSumAB0[idx] += GetSlice(&pixel, sliceAB0);
     504            fSumAB1[idx] += GetSlice(&pixel, sliceAB1);
    566505        }
    567506
     
    579518
    580519    if (fPedestalUpdate)
    581       fPedestals->SetReadyToSave();
     520        fPedestals->SetReadyToSave();
    582521
    583522    return kTRUE;
     
    591530{
    592531    // Compute pedestals and rms from the whole run
    593     if (fPedestalUpdate || GetNumExecutions()<1)
     532    if (fPedestalUpdate)
    594533        return kTRUE;
    595534
    596     *fLog << flush << inf << "Calculating pedestals..." << flush;
    597 
    598     Double_t sum = 0;
     535    *fLog << flush << inf << "Calculating Pedestals..." << flush;
    599536
    600537    const Int_t npix = fGeom->GetNumPixels();
     
    604541        if (n>1)
    605542            Calc(n, idx);
    606         sum += n;
    607     }
    608 
    609     *fLog << flush << inf << "Calculating means..." << flush;
    610 
    611     fPedestals->SetTotalEntries((UInt_t)(sum/npix*(fWindowSizeLoGain+fWindowSizeHiGain)));
     543    }
     544
    612545    fPedestals->SetReadyToSave();
    613     fPedestals->ReCalc(*fGeom);
    614546    return kTRUE;
    615547}
     
    622554    Bool_t rc=kFALSE;
    623555
    624     Byte_t hw = fWindowSizeHiGain;
    625     Byte_t lw = fWindowSizeLoGain;
    626     if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
    627     {
    628         hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
     556    Int_t lw = fExtractWinSize;
     557    Int_t wf = fExtractWinFirst;
     558
     559    if (IsEnvDefined(env, prefix, "ExtractWindowSize", print))
     560    {
     561        lw = GetEnvValue(env, prefix, "ExtractWindowSize", lw);
     562        wf = GetEnvValue(env, prefix, "ExtractWindowFirst", wf);
    629563        rc = kTRUE;
    630     }
    631     if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
    632     {
    633         lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
     564
     565    }
     566    SetExtractWindow(wf,lw);
     567
     568    Int_t num = fNumEventsDump;
     569    if (IsEnvDefined(env, prefix, "NumEventsDump", print))
     570    {
     571        num = GetEnvValue(env, prefix, "NumEventsDump", num);
    634572        rc = kTRUE;
    635573    }
    636 
    637     if (rc)
    638         SetWindowSize(hw, lw);
    639 
    640     if (IsEnvDefined(env, prefix, "NumEventsDump", print))
    641     {
    642         SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", fNumEventsDump));
     574    SetNumEventsDump(num);
     575
     576    Byte_t max = fMaxSignalVar;
     577    if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
     578    {
     579        max = GetEnvValue(env, prefix, "MaxSignalVar", max);
    643580        rc = kTRUE;
    644581    }
    645 
    646     if (IsEnvDefined(env, prefix, "MaxHiGainVar", print))
    647     {
    648         SetMaxHiGainVar(GetEnvValue(env, prefix, "MaxHiGainVar", fMaxHiGainVar));
     582    SetMaxSignalVar(max);
     583
     584    Bool_t upd = fPedestalUpdate;
     585    if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
     586    {
     587        upd = GetEnvValue(env, prefix, "PedestalUpdate", upd);
    649588        rc = kTRUE;
    650589    }
    651 
    652     if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
    653     {
    654         SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
    655         rc = kTRUE;
    656     }
     590    SetPedestalUpdate(upd);
    657591
    658592    return rc;
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h

    r4648 r5338  
    1616class MGeomCam;
    1717class MBadPixelsCam;
     18class MRawEvtPixelIter;
    1819
    1920class MPedCalcFromLoGain : public MExtractor
    2021{
    21     static const Byte_t fgHiGainFirst;      // First FADC slice Hi-Gain (currently set to: 3)
    22     static const Byte_t fgHiGainLast;       // Last FADC slice Hi-Gain (currently set to: 14)
    23     static const Byte_t fgLoGainFirst;      // First FADC slice Lo-Gain (currently set to: 3)
    24     static const Byte_t fgLoGainLast;       // Last FADC slice Lo-Gain (currently set to: 14)
    25     static const Byte_t fgHiGainWindowSize; // The extraction window Hi-Gain
    26     static const Byte_t fgLoGainWindowSize; // The extraction window Lo-Gain
    27     static const Byte_t fgMaxHiGainVar;     // The maximum difference between the highest and lowest slice
     22    static const Int_t fgCheckWinFirst;      // First FADC slice to check for signal (currently set to: 0)
     23    static const Int_t fgCheckWinLast;       // Last FADC slice to check for signal  (currently set to: 29)
     24    static const Int_t fgExtractWinFirst;      // First FADC slice to use for pedestal calculation (currently set to: 15)
     25    static const Int_t fgExtractWinSize;       // number of successive slices used to calculate pedestal (currently set to: 6)
     26    static const Int_t fgMaxSignalVar;     // The maximum difference between the highest and lowest slice
    2827
    2928    Int_t   fNumEventsDump;      // Number of event after which MPedestalCam gets updated
    3029
    31     Byte_t  fMaxHiGainVar;
    32     Byte_t  fWindowSizeHiGain;   // Number of Hi Gain slices in window
    33     Byte_t  fWindowSizeLoGain;   // Number of Lo Gain slices in window
     30    Int_t  fMaxSignalVar;
     31    Int_t  fCheckWinFirst;
     32    Int_t  fCheckWinLast;
     33    Int_t  fExtractWinSize;              // Number of slices to calculate the pedestal from
     34    Int_t  fExtractWinFirst;
     35    Int_t  fExtractWinLast;
    3436
    3537    Bool_t  fPedestalUpdate;
     
    5557    void Calc(ULong_t n, UInt_t idx);
    5658
     59    //Helper function to extract slice values by slice number
     60    UInt_t GetSlice(MRawEvtPixelIter *pixel, UInt_t slice);
     61
    5762public:
    5863    MPedCalcFromLoGain(const char *name=NULL, const char *title=NULL);
     
    6267
    6368    // Setter
    64     void SetRange(Byte_t hifirst=fgHiGainFirst, Byte_t hilast=fgHiGainLast, Byte_t lofirst=fgLoGainFirst, Byte_t lolast=fgLoGainLast);
    65     void SetWindowSize(Byte_t windowh=fgHiGainWindowSize, Byte_t windowl=fgLoGainWindowSize);
    66     void SetMaxHiGainVar(Byte_t maxvar=fgMaxHiGainVar);
    67     void SetNumEventsDump(UInt_t dumpevents = 0) { fNumEventsDump = dumpevents; }
     69    void SetCheckRange(Int_t checkfirst=0, Int_t checklast=29);
     70    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;}
    6873    void SetPedestalUpdate(Bool_t pedupdate)  {fPedestalUpdate = pedupdate;}
    6974
Note: See TracChangeset for help on using the changeset viewer.