Ignore:
Timestamp:
11/28/04 20:06:04 (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

    r5395 r5498  
    3333//   MPedCalcLoGain
    3434//
    35 //  This task is devide form MPedCalcPedRun, described below. However, It
    36 //  calculates the pedstals using the low gain slices, whenever the difference
     35//  This task derives from MExtractPedestal.
     36//  It calculates the pedestals using the low gain slices, whenever the difference
    3737//  between the highest and the lowest slice in the high gain
    3838//  slices is below a given threshold (SetMaxHiGainVar). In this case the receiver
     
    7373<img src="images/PedestalStudyOuter.gif">
    7474*/
     75//End_Html
    7576//
    7677// The plots show the inner and outer pixels, respectivly and have the following meaning:
     
    9798// 
    9899//
    99 //   fCheckWinFirst =  fgCheckWinFirst =  0
    100 //   fHiGainLast  =  fgCheckWinLast  =  29
     100//   fCheckWinFirst   =  fgCheckWinFirst  =  0
     101//   fCheckWinLast    =  fgCheckWinLast    =  29
    101102//   fExtractWinFirst =  fgExtractWinFirst =  0
    102103//   fExtractWinSize  =  fgExtractWinSize  =  6
    103 //   fMaxSignalVar   =   fgMaxSignalVar  = 40;
     104//   fMaxSignalVar    =  fgMaxSignalVar    = 40;
    104105//
    105106//  Call:
     
    133134/////////////////////////////////////////////////////////////////////////////
    134135#include "MPedCalcFromLoGain.h"
    135 #include "MExtractor.h"
     136#include "MExtractPedestal.h"
     137
     138#include "MExtractTimeAndCharge.h"
    136139
    137140#include "MParList.h"
     
    159162const UShort_t MPedCalcFromLoGain::fgExtractWinSize  =  6;
    160163const UShort_t MPedCalcFromLoGain::fgMaxSignalVar    = 40;
    161 
    162164// --------------------------------------------------------------------------
    163165//
     
    174176//
    175177MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
    176     : fGeom(NULL), fNamePedestalCam("MPedestalCam")
    177 {
    178     fName  = name  ? name  : "MPedCalcFromLoGain";
    179     fTitle = title ? title : "Task to calculate pedestals from lo-gains";
    180 
    181     AddToBranchList("fHiGainPixId");
    182     AddToBranchList("fLoGainPixId");
    183     AddToBranchList("fHiGainFadcSamples");
    184     AddToBranchList("fLoGainFadcSamples");
    185 
    186     SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
    187     SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
    188 
    189     SetMaxSignalVar(fgMaxSignalVar);
    190     SetPedestalUpdate(kTRUE);
    191 
    192     Clear();
     178{
     179
     180  fName  = name  ? name  : "MPedCalcFromLoGain";
     181  fTitle = title ? title : "Task to calculate pedestals from lo-gains";
     182 
     183  SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
     184  SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
     185 
     186  SetMaxSignalVar(fgMaxSignalVar);
     187 
     188  Clear();
    193189}
    194190
    195191void MPedCalcFromLoGain::ResetArrays()
    196192{
    197     // Reset contents of arrays.
    198     fSumx.Reset();
    199     fSumx2.Reset();
    200     fSumAB0.Reset();
    201     fSumAB1.Reset();
    202     fNumEventsUsed.Reset();
    203     fTotalCounter.Reset();
    204 }
    205 
    206 // --------------------------------------------------------------------------
    207 //
    208 // Sets:
    209 // - fRawEvt to NULL
    210 // - fRunHeader to NULL
    211 // - fPedestals to NULL
    212 //
    213 // Resets:
    214 // - fSumx
    215 // - fSumx2
    216 // - fSumAB0
    217 // - fSumAB1
    218 // - fNumEventsUsed
    219 // - fTotalCounter
    220 //
    221 void MPedCalcFromLoGain::Clear(const Option_t *o)
    222 {
    223 
    224   fRawEvt    = NULL;
    225   fRunHeader = NULL;
    226   fPedestals = NULL;
    227 
    228   // If the size is yet set, set the size
    229   if (fSumx.GetSize()>0)
    230       ResetArrays();
     193
     194  MExtractPedestal::ResetArrays();
     195 
     196  fNumEventsUsed.Reset();
     197  fTotalCounter.Reset();
    231198}
    232199
     
    240207Bool_t MPedCalcFromLoGain::SetCheckRange(UShort_t chfirst, UShort_t chlast)
    241208{
    242     Bool_t rc = kTRUE;
    243 
    244     if (chlast<=chfirst)
    245     {
    246         *fLog << warn << GetDescriptor();
    247         *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl;
    248         chlast = chfirst+1;
    249         rc = kFALSE;
    250     }
    251 
    252     fCheckWinFirst = chfirst;
    253     fCheckWinLast  = chlast;
    254 
    255     return rc;
    256 }
    257 
    258 // --------------------------------------------------------------------------
    259 //
    260 // Checks:
    261 // - if a window is odd
    262 //
    263 Bool_t MPedCalcFromLoGain::SetExtractWindow(UShort_t windowf, UShort_t windows)
    264 {
    265     Bool_t rc = kTRUE;
    266 
    267     const Int_t odd  = windows & 0x1;
    268 
    269     if (odd || windows==0)
    270     {
    271         *fLog << warn << GetDescriptor();
    272         *fLog << " - WARNING: Window size in SetExtraxtWindow has to be even and > 0... adjusting!" << endl;
    273         windows += 1;
    274         rc = kFALSE;
    275     }
    276 
    277     fExtractWinSize  = windows;
    278     fExtractWinFirst = windowf;
    279     fExtractWinLast  = fExtractWinFirst+fExtractWinSize-1;
    280 
    281 //
    282 //  NO RANGE CHECK IMPLEMENTED, YET
    283 //
    284 /*
    285     const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
    286     const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
    287  
    288     if (fWindowSizeHiGain > availhirange)
    289     {
    290         *fLog << warn;
    291         *fLog << GetDescriptor() << ": HiGain window " << (int)fWindowSizeHiGain;
    292         *fLog << " out of range [" << (int)fHiGainFirst;
    293         *fLog << "," << (int)fHiGainLast << "]" << endl;
    294         *fLog << "Will set window size to " << (int)availhirange << endl;
    295         fWindowSizeHiGain = availhirange;
    296     }
    297    
    298     if (fWindowSizeLoGain > availlorange)
    299     {
    300         *fLog << warn;
    301         *fLog << GetDescriptor() << ": LoGain window " << (int)fWindowSizeLoGain;
    302         *fLog << " out of range [" << (int)fLoGainFirst;
    303         *fLog << "," << (int)fLoGainLast << "]" << endl;
    304         *fLog << "Will set window size to " << (int)availlorange << endl;
    305         fWindowSizeLoGain = availlorange;
    306     }
    307     */
     209
     210  Bool_t rc = kTRUE;
     211 
     212  if (chlast<=chfirst)
     213    {
     214      *fLog << warn << GetDescriptor();
     215      *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl;
     216      chlast = chfirst+1;
     217      rc = kFALSE;
     218    }
     219
     220  fCheckWinFirst = chfirst;
     221  fCheckWinLast  = chlast;
    308222
    309223  return rc;
    310 }
    311 
    312 // --------------------------------------------------------------------------
    313 //
    314 // Look for the following input containers:
    315 //
    316 //  - MRawEvtData
    317 //  - MRawRunHeader
    318 //  - MGeomCam
    319 //
    320 // The following output containers are also searched and created if
    321 // they were not found:
    322 //
    323 //  - MPedestalCam with the name fPedContainerName
    324 //
    325 Int_t MPedCalcFromLoGain::PreProcess(MParList *pList)
    326 {
    327     Clear();
    328 
    329     fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
    330     if (!fRawEvt)
    331     {
    332         *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
    333         return kFALSE;
    334     }
    335 
    336     fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
    337     if (!fRunHeader)
    338     {
    339         *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
    340         return kFALSE;
    341     }
    342 
    343     fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
    344     if (!fGeom)
    345     {
    346         *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
    347         return kFALSE;
    348     }
    349 
    350     fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCam));
    351     if (!fPedestals)
    352         return kFALSE;
    353 
    354     *fLog << inf;
    355     Print();
    356 
    357     return kTRUE;
    358224}
    359225
     
    367233//    fCheckWinLast
    368234//
    369 // Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
    370 //  - fSumx
    371 //  - fSumx2
    372 //  - fSumAB0
    373 //  - fSumAB1
    374 //  - fNumEventsUsed
    375 //  - fTotalCounter
    376 //
    377235Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
    378236{
    379   Int_t lastavailableslice = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain()-1;
    380   Int_t lastextractslice   = fExtractWinSize + fExtractWinFirst - 1;
    381 
    382    if (lastextractslice>lastavailableslice)//changed to override check
     237
     238  const UShort_t hisamples = fRunHeader->GetNumSamplesHiGain();
     239  const UShort_t losamples = fRunHeader->GetNumSamplesLoGain();
     240
     241  if (fExtractor)
     242    SetExtractWindow(hisamples+fExtractor->GetHiGainFirst(),hisamples+fExtractor->GetHiGainLast());
     243 
     244  // If the size is not yet set, set the size
     245  if (fSumx.GetSize()==0)
     246  {
     247    const Int_t npixels  = fPedestalsOut->GetSize();
     248    fNumEventsUsed.Set(npixels);
     249    fTotalCounter.Set(npixels);
     250  }
     251 
     252  MExtractPedestal::ReInit(pList);
     253 
     254  UShort_t lastavailable = hisamples+losamples-1;
     255
     256   if (fExtractWinLast > lastavailable) //changed to override check
    383257   {
    384        *fLog << warn << GetDescriptor();
    385        *fLog << " - WARNING: Selected Extract Window ranges out of range...adjusting to last available slice ";
    386        *fLog << lastavailableslice << endl;
    387 
    388        lastextractslice=lastavailableslice;
     258     const UShort_t diff = fExtractWinLast - lastavailable;
     259     *fLog << warn << GetDescriptor();
     260     *fLog << " - WARNING: Selected Extract Window ranges out of range...adjusting to last available slice ";
     261     *fLog << lastavailable << endl;
     262     
     263     fExtractWinLast -= diff;
     264     fExtractWinSize -= diff;
    389265   }
    390266
    391    if (fCheckWinLast>lastavailableslice)//changed to override check
     267   lastavailable = fRunHeader->GetNumSamplesHiGain()-1;
     268
     269   if (fCheckWinLast > lastavailable) //changed to override check
    392270   {
    393271       *fLog << warn << GetDescriptor();
    394272       *fLog << " - WARNING: Last Check Window slice out of range...adjusting to last available slice ";
    395        *fLog << lastavailableslice << endl;
    396 
    397        fCheckWinLast=lastavailableslice;
     273       *fLog << lastavailable << endl;
     274
     275       fCheckWinLast = lastavailable;
    398276   }
    399277
    400 
    401   // If the size is not yet set, set the size
    402   if (fSumx.GetSize()==0)
    403   {
    404       const Int_t npixels = fPedestals->GetSize();
    405 
    406       fSumx. Set(npixels);
    407       fSumx2.Set(npixels);
    408       fSumAB0.Set(npixels);
    409       fSumAB1.Set(npixels);
    410       fNumEventsUsed.Set(npixels);
    411       fTotalCounter.Set(npixels);
    412 
    413       ResetArrays();
    414   }
    415  
    416278  return kTRUE;
    417 }
    418 
    419 // ---------------------------------------------------------------------------------
    420 //
    421 // Calculates for pixel "idx":
    422 //
    423 // Ped per slice      = sum / n / fExtractWinSize;
    424 // RMS per slice      = sqrt { (sum2 -  sum*sum/n) / (n-1) / fExtractWinSize }
    425 // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
    426 //
    427 // Sets fTotalCounter up by 1.
    428 //
    429 void MPedCalcFromLoGain::Calc(ULong_t n, UInt_t idx)
    430 {
    431 
    432   const ULong_t nsamplestot = n*fExtractWinSize;
    433  
    434   const Float_t sum  = fSumx.At(idx);
    435   const Float_t sum2 = fSumx2.At(idx);
    436   const Float_t ped  = sum/nsamplestot;
    437  
    438   // 1. Calculate the Variance of the sums:
    439   Float_t var = (sum2-sum*sum/n)/(n-1.);
    440 
    441   // 2. Scale the variance to the number of slices:
    442   var /= fExtractWinSize;
    443  
    444   // 3. Calculate the RMS from the Variance:
    445   const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
    446  
    447   // 4. Calculate the amplitude of the 150MHz "AB" noise
    448   const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
    449  
    450   (*fPedestals)[idx].Set(ped, rms, abOffs, n);
    451  
    452   fTotalCounter[idx]++;
    453279}
    454280
     
    479305Int_t MPedCalcFromLoGain::Process()
    480306{
    481     MRawEvtPixelIter pixel(fRawEvt);
    482 
    483     while (pixel.Next())
    484     {
    485         const UInt_t idx = pixel.GetPixelId();
    486 
    487         UShort_t max = 0;
    488         UShort_t min = (UShort_t)-1;
    489 
    490         // Find the maximum and minimum signal per slice in the high gain window
    491         for (Int_t slice=fCheckWinFirst; slice<=fCheckWinLast; slice++)
     307
     308  MRawEvtPixelIter pixel(fRawEvt);
     309 
     310  while (pixel.Next())
     311    {
     312      const UInt_t idx = pixel.GetPixelId();
     313      const UInt_t aidx   = (*fGeom)[idx].GetAidx();
     314      const UInt_t sector = (*fGeom)[idx].GetSector();     
     315     
     316      UShort_t max = 0;
     317      UShort_t min = (UShort_t)-1;
     318     
     319      // Find the maximum and minimum signal per slice in the high gain window
     320      for (Int_t slice=fCheckWinFirst; slice<=fCheckWinLast; slice++)
    492321        {
    493             const UShort_t svalue = GetSlice(&pixel,slice);
    494             if (svalue > max)
    495                 max = svalue;
    496             if (svalue < min)
    497                 min = svalue;
     322          const UShort_t svalue = GetSlice(&pixel,slice);
     323          if (svalue > max)
     324            max = svalue;
     325          if (svalue < min)
     326            min = svalue;
    498327        }
    499 
    500         // If the maximum in the high gain window is smaller than
    501         if (max-min>=fMaxSignalVar || max>=250)
     328     
     329      // If the maximum in the high gain window is smaller than
     330      if (max-min>=fMaxSignalVar || max>=250)
     331        continue;
     332     
     333      Float_t sum  = 0.;
     334      UInt_t  sumi = 0;
     335     
     336      //extract pedestal
     337      if (fExtractor)
     338        CalcExtractor( &pixel, sum, (*fPedestalsIn)[idx] );
     339      else
     340        {
     341          for(Int_t slice=fExtractWinFirst; slice<=fExtractWinLast; slice++)
     342            sumi += GetSlice(&pixel,slice);
     343          sum = (Float_t)sumi;
     344        }
     345     
     346      const Float_t sqrsum = sum*sum;
     347     
     348      fSumx[idx]           += sum;
     349      fSumx2[idx]          += sqrsum;
     350      fAreaSumx[aidx]      += sum;
     351      fAreaSumx2[aidx]     += sqrsum;
     352      fSectorSumx[sector]  += sum;     
     353      fSectorSumx2[sector] += sqrsum;     
     354     
     355      fNumEventsUsed[idx]   ++;
     356      fAreaFilled   [aidx]  ++;
     357      fSectorFilled [sector]++;
     358     
     359      if (!fExtractor)
     360        {
     361          //
     362          // Calculate the amplitude of the 150MHz "AB" noise
     363          //
     364          const UShort_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1;
     365         
     366          for (UShort_t islice=fExtractWinFirst; islice<=fExtractWinLast; islice+=2)
     367            {
     368              const UShort_t sliceAB0 = islice + abFlag;
     369              const UShort_t sliceAB1 = islice - abFlag + 1;
     370              const UShort_t ab0 = GetSlice(&pixel, sliceAB0);
     371              const UShort_t ab1 = GetSlice(&pixel, sliceAB1);
     372              fSumAB0[idx]        += ab0;
     373              fSumAB1[idx]        += ab1;
     374              fAreaSumAB0[aidx]   += ab0;
     375              fAreaSumAB1[aidx]   += ab1;     
     376              fSectorSumAB0[aidx] += ab0;
     377              fSectorSumAB1[aidx] += ab1;     
     378            }
     379        }
     380     
     381      if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump)
     382        continue;
     383     
     384      CalcPixResults(fNumEventsDump, idx);
     385      fTotalCounter[idx]++;
     386     
     387      fNumEventsUsed[idx]=0;
     388      fSumx[idx]=0;
     389      fSumx2[idx]=0;
     390      fSumAB0[idx]=0;
     391      fSumAB1[idx]=0;
     392    }
     393 
     394  if (!(GetNumExecutions() % fNumAreasDump))
     395    {
     396      //
     397      // Loop over the (two) area indices to get the averaged pedestal per aidx
     398      //
     399      for (UInt_t aidx=0; aidx<fAreaValid.GetSize(); aidx++)
     400        {
     401          const Int_t   napix = fAreaValid.At(aidx);
     402          if (napix == 0)
    502403            continue;
    503 
    504         UInt_t sum = 0;
    505         UInt_t sqr = 0;
    506 
    507         //extract pedestal
    508         for(Int_t slice=fExtractWinFirst; slice<=fExtractWinLast; slice++)
     404         
     405          CalcAreaResults(fSectorFilled[aidx],napix,aidx);
     406        }
     407    }
     408 
     409  if (!(GetNumExecutions() % fNumSectorsDump))
     410    {
     411      //
     412      // Loop over the (two) sector indices to get the averaged pedestal per sector
     413      //
     414      for (UInt_t sector=0; sector<fSectorValid.GetSize(); sector++)
    509415        {
    510             const UInt_t svalue = GetSlice(&pixel,slice);
    511             sum += svalue;
    512             sqr += svalue*svalue;
     416          const Int_t   nspix = fSectorValid.At(sector);
     417          if (nspix == 0)
     418            continue;
     419         
     420          CalcSectorResults(fSectorFilled[sector],nspix,sector);
    513421        }
    514 
    515         fSumx[idx]  += sum;
    516         fSumx2[idx] += sum*sum;
    517 
    518         fNumEventsUsed[idx]++;
    519 
    520         // Calculate the amplitude of the 150MHz "AB" noise
    521         UShort_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1;
    522 
    523         for (UShort_t islice=fExtractWinFirst; islice<=fExtractWinLast; islice+=2)
     422    }
     423 
     424  if (fPedestalUpdate)
     425    fPedestalsOut->SetReadyToSave();
     426 
     427  return kTRUE;
     428}
     429
     430void MPedCalcFromLoGain::CalcExtractor( MRawEvtPixelIter *pixel, Float_t &sum, MPedestalPix &ped)
     431{
     432 
     433  Byte_t  sat  = 0;
     434  Byte_t *logain = pixel->GetLoGainSamples() + fExtractWinFirst;
     435  const Bool_t logainabflag = (pixel->HasABFlag() + pixel->GetNumHiGainSamples()) & 0x1;
     436  Float_t dummy;
     437  fExtractor->FindTimeAndChargeLoGain(logain,sum,dummy,dummy,dummy,sat,ped,logainabflag);
     438}
     439
     440
     441// --------------------------------------------------------------------------
     442//
     443// Compute signal mean and rms in the whole run and store it in MPedestalCam
     444//
     445Int_t MPedCalcFromLoGain::PostProcess()
     446{
     447
     448  // Compute pedestals and rms from the whole run
     449  if (fPedestalUpdate)
     450    return kTRUE;
     451 
     452  *fLog << flush << inf << "Calculating Pedestals..." << flush;
     453 
     454  const Int_t npix = fGeom->GetNumPixels();
     455  for (Int_t idx=0; idx<npix; idx++)
     456    {
     457      const ULong_t n = fNumEventsUsed[idx];
     458      if (n>1)
    524459        {
    525             const UShort_t sliceAB0 = islice + abFlag;
    526             const UShort_t sliceAB1 = islice - abFlag + 1;
    527             fSumAB0[idx] += GetSlice(&pixel, sliceAB0);
    528             fSumAB1[idx] += GetSlice(&pixel, sliceAB1);
     460          CalcPixResults(n, idx);
     461          fTotalCounter[idx]++;
    529462        }
    530 
    531         if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump)
    532           continue;
    533 
    534         Calc(fNumEventsDump, idx);
    535 
    536         fNumEventsUsed[idx]=0;
    537         fSumx[idx]=0;
    538         fSumx2[idx]=0;
    539         fSumAB0[idx]=0;
    540         fSumAB1[idx]=0;
    541     }
    542 
    543     if (fPedestalUpdate)
    544       fPedestals->SetReadyToSave();
    545 
    546     return kTRUE;
    547 }
    548 
    549 // --------------------------------------------------------------------------
    550 //
    551 // Compute signal mean and rms in the whole run and store it in MPedestalCam
    552 //
    553 Int_t MPedCalcFromLoGain::PostProcess()
    554 {
    555     // Compute pedestals and rms from the whole run
    556     if (fPedestalUpdate)
    557       return kTRUE;
    558 
    559     *fLog << flush << inf << "Calculating Pedestals..." << flush;
    560 
    561     const Int_t npix = fGeom->GetNumPixels();
    562     for (Int_t idx=0; idx<npix; idx++)
    563       {
    564         const ULong_t n = fNumEventsUsed[idx];
    565         if (n>1)
    566           Calc(n, idx);
    567       }
    568 
    569     fPedestals->SetReadyToSave();
    570     return kTRUE;
     463    }
     464
     465  //
     466  // Loop over the (two) area indices to get the averaged pedestal per aidx
     467  //
     468  for (UInt_t aidx=0; aidx<fAreaFilled.GetSize(); aidx++)
     469    {
     470      const Int_t   napix = fAreaValid.At(aidx);
     471      if (napix == 0)
     472        continue;
     473
     474      CalcAreaResults(fAreaFilled[aidx],napix,aidx);
     475    }
     476 
     477  //
     478  // Loop over the (six) sector indices to get the averaged pedestal per sector
     479  //
     480  for (UInt_t sector=0; sector<fSectorFilled.GetSize(); sector++)
     481    {
     482      const Int_t   nspix = fSectorValid.At(sector);
     483      if (nspix == 0)
     484        continue;
     485     
     486      CalcSectorResults(fSectorFilled[sector],nspix,sector);
     487    }
     488
     489  fPedestalsOut->SetReadyToSave();
     490  return kTRUE;
    571491}
    572492
     
    577497//    FirstCheckWindowSlice:  0
    578498//    LastCheckWindowSlice:  29
    579 //    ExtractWindowFirst:    15
    580 //    ExtractWindowSize:      6
    581 //    NumEventsDump:        500
    582499//    MaxSignalVar:          40
    583 //    PedestalUpdate:       yes
    584500//
    585501Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
    586502{
    587     Bool_t rc=kFALSE;
    588 
    589     // Find resources for CheckWindow
    590     Int_t fs = fCheckWinFirst;
    591     Int_t ls = fCheckWinLast;
    592     if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
    593     {
    594         fs = GetEnvValue(env, prefix, "CheckWinFirst", fs);
    595         rc = kTRUE;
    596     }
    597     if (IsEnvDefined(env, prefix, "CheckWinLast", print))
    598     {
    599         ls = GetEnvValue(env, prefix, "CheckWinLast", ls);
    600         rc = kTRUE;
    601     }
    602 
    603     SetCheckRange(fs,ls);
    604 
    605     // Find resources for ExtractWindow
    606     Int_t lw = fExtractWinSize;
    607     Int_t wf = fExtractWinFirst;
    608     if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
    609     {
    610         lw = GetEnvValue(env, prefix, "ExtractWinSize", lw);
    611         rc = kTRUE;
    612     }
    613 
    614     if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
    615     {
    616         wf = GetEnvValue(env, prefix, "ExtractWinFirst", wf);
    617         rc = kTRUE;
    618     }
    619     SetExtractWindow(wf,lw);
    620 
    621     // find resource for numeventsdump
    622     if (IsEnvDefined(env, prefix, "NumEventsDump", print))
    623     {
    624         SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
    625         rc = kTRUE;
    626     }
    627 
    628     // find resource for maximum signal variation
    629     if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
    630     {
    631         SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
    632         rc = kTRUE;
    633     }
    634 
    635     // find resource for pedestal update
    636     if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
    637     {
    638         SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
    639         rc = kTRUE;
    640     }
    641 
    642     return rc;
     503
     504  Bool_t rc=kFALSE;
     505 
     506  // Find resources for CheckWindow
     507  Int_t fs = fCheckWinFirst;
     508  Int_t ls = fCheckWinLast;
     509  if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
     510    {
     511      fs = GetEnvValue(env, prefix, "CheckWinFirst", fs);
     512      rc = kTRUE;
     513    }
     514  if (IsEnvDefined(env, prefix, "CheckWinLast", print))
     515    {
     516      ls = GetEnvValue(env, prefix, "CheckWinLast", ls);
     517      rc = kTRUE;
     518    }
     519 
     520  SetCheckRange(fs,ls);
     521 
     522  // find resource for maximum signal variation
     523  if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
     524    {
     525      SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
     526      rc = kTRUE;
     527    }
     528 
     529  return MExtractPedestal::ReadEnv(env,prefix,print) ? kTRUE : rc;
    643530}
    644531
    645532void MPedCalcFromLoGain::Print(Option_t *o) const
    646533{
    647     *fLog << GetDescriptor() << ":" << endl;
    648     *fLog << "Parameters used for pedestal calculation from " << fNamePedestalCam << ":"<<endl;
    649     *fLog << "CheckWindow from slice " << fCheckWinFirst   << " to " << fCheckWinLast << " included." << endl;
    650     *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << fExtractWinLast << " included." << endl;
    651     *fLog << "Max allowed signal variation: " << fMaxSignalVar << endl;
    652     *fLog << "Number of events to calculate pedestal from: " << fNumEventsDump << endl;
    653     *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
    654 }
     534
     535  MExtractPedestal::Print(o);
     536
     537  *fLog << "CheckWindow   from slice  " << fCheckWinFirst   << " to " << fCheckWinLast << " incl." << endl;
     538  *fLog << "Max. allowed signal variation:             " << fMaxSignalVar << endl;
     539  *fLog << endl;
     540}
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h

    r5381 r5498  
    22#define MARS_MPedCalcFromLoGain
    33
    4 #ifndef MARS_MTask
    5 #include "MTask.h"
     4#ifndef MARS_MExtractPedestal
     5#include "MExtractPedestal.h"
    66#endif
    77
     
    1414#endif
    1515
    16 class MGeomCam;
    17 class MPedestalCam;
    18 class MRawEvtData;
    1916class MRawEvtPixelIter;
    20 class MRawRunHeader;
     17class MPedestalPix;
     18class MPedCalcFromLoGain : public MExtractPedestal
     19{
    2120
    22 class MPedCalcFromLoGain : public MTask
    23 {
    24     static const UShort_t fgCheckWinFirst;    // First FADC slice to check for signal (currently set to: 0)
    25     static const UShort_t fgCheckWinLast;     // Last FADC slice to check for signal  (currently set to: 29)
    26     static const UShort_t fgExtractWinFirst;  // First FADC slice to use for pedestal calculation (currently set to: 15)
    27     static const UShort_t fgExtractWinSize;   // number of successive slices used to calculate pedestal (currently set to: 6)
    28     static const UShort_t fgMaxSignalVar;     // The maximum difference between the highest and lowest slice
     21  static const UShort_t fgCheckWinFirst;    // First FADC slice to check for signal (currently set to: 0)
     22  static const UShort_t fgCheckWinLast;     // Last FADC slice to check for signal  (currently set to: 29)
     23  static const UShort_t fgMaxSignalVar;     // The maximum difference between the highest and lowest slice
     24  static const UShort_t fgExtractWinFirst;  // First FADC slice to use for pedestal calculation (currently set to: 15)
     25  static const UShort_t fgExtractWinSize;   // number of successive slices used to calculate pedestal (currently set to: 6)
     26   
     27  UShort_t fMaxSignalVar;
     28  UShort_t fCheckWinFirst;
     29  UShort_t fCheckWinLast;
    2930
    30     MGeomCam      *fGeom;        //! Camera geometry
    31     MPedestalCam  *fPedestals;   //! Pedestals of all pixels in the camera
    32     MRawEvtData   *fRawEvt;      //! Raw event data (time slices)
    33     MRawRunHeader *fRunHeader;   //! RunHeader information
     31  TArrayI fNumEventsUsed;      // Number of events used for pedestal calc for each pixel
     32  TArrayI fTotalCounter;       // Counter for dumping values to Pedestal Container
    3433
    35     UInt_t   fNumEventsDump;     // Number of event after which MPedestalCam gets updated
    36 
    37     UShort_t fMaxSignalVar;
    38     UShort_t fCheckWinFirst;
    39     UShort_t fCheckWinLast;
    40     UShort_t fExtractWinSize;    // Number of slices to calculate the pedestal from
    41     UShort_t fExtractWinFirst;
    42     UShort_t fExtractWinLast;
    43 
    44     Bool_t  fPedestalUpdate;
    45 
    46     TString fNamePedestalCam;    // name of the 'MPedestalCam' container
    47 
    48     TArrayI fNumEventsUsed;      // Number of events used for pedestal calc for each pixel
    49     TArrayI fTotalCounter;       // Counter for dumping values to Pedestal Container
    50     TArrayD fSumx;               // sum of values
    51     TArrayD fSumx2;              // sum of squared values
    52     TArrayD fSumAB0;             // sum of ABFlag=0 slices
    53     TArrayD fSumAB1;             // sum of ABFlag=1 slices
    54 
    55     // MParContainer
    56     Int_t  PreProcess (MParList *pList);
    57     Bool_t ReInit     (MParList *pList);
    58     Int_t  Process    ();
    59     Int_t  PostProcess();
    60     Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    61 
    62     // Calculation
    63     void Calc(ULong_t n, UInt_t idx);
    64 
    65     //Helper function to extract slice values by slice number
    66     UShort_t GetSlice(MRawEvtPixelIter *pixel, UInt_t slice);
    67     void ResetArrays();
     34  Bool_t ReInit     (MParList *pList);
     35  Int_t  Process    ();
     36  Int_t  PostProcess();
     37 
     38  Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
     39 
     40  //Helper function to extract slice values by slice number
     41  UShort_t GetSlice(MRawEvtPixelIter *pixel, UInt_t slice);
     42  void CalcExtractor   ( MRawEvtPixelIter *pixel, Float_t &sum, MPedestalPix &ped);
     43  void ResetArrays();
    6844
    6945public:
    70     MPedCalcFromLoGain(const char *name=NULL, const char *title=NULL);
    7146
    72     // TObject
    73     void Clear(const Option_t *o="");
    74     void Print(Option_t *o="") const;
     47  MPedCalcFromLoGain(const char *name=NULL, const char *title=NULL);
     48 
     49  void Print(Option_t *o="") const;
     50 
     51  // Setters
     52  Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast);
     53  void SetMaxSignalVar(UShort_t maxvar=40)       { fMaxSignalVar = maxvar;    }
    7554
    76     // Setter
    77     Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast);
    78     Bool_t SetExtractWindow(UShort_t extractfirst=fgExtractWinFirst, UShort_t windowsize=fgExtractWinSize);
    79 
    80     void SetMaxSignalVar(UShort_t maxvar=40)       { fMaxSignalVar = maxvar;    }
    81     void SetNumEventsDump(UInt_t dumpevents = 500) { fNumEventsDump = dumpevents;}
    82     void SetPedestalUpdate(Bool_t pedupdate)  {fPedestalUpdate = pedupdate;}
    83 
    84     void SetNamePedestalCam(const char *name) { fNamePedestalCam = name; }
    85 
    86     // Getter
    87     TArrayI *GetNumEventsUsed() { return &fNumEventsUsed; }
    88 
    89     ClassDef(MPedCalcFromLoGain, 0)   // Task to calculate pedestals from pedestal runs raw data
     55  // Getters
     56  TArrayI *GetNumEventsUsed() { return &fNumEventsUsed; }
     57 
     58  ClassDef(MPedCalcFromLoGain, 1)   // Task to calculate pedestals from data runs
    9059};
    9160
Note: See TracChangeset for help on using the changeset viewer.