Ignore:
Timestamp:
10/24/06 08:58:13 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r6325 r8151  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.34 2006-10-24 07:58:13 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    2426!   Author(s): Nepomuk Otte 10/2004 <mailto:otte@mppmu.mpg.de>
    2527!
    26 !   Copyright: MAGIC Software Development, 2000-2004
     28!   Copyright: MAGIC Software Development, 2000-2006
    2729!
    2830!
     
    142144#include "MRawRunHeader.h" 
    143145#include "MRawEvtPixelIter.h"
    144 #include "MRawEvtData.h"
    145146
    146147#include "MPedestalPix.h"
     
    151152
    152153#include "MExtractPedestal.h"
    153 #include "MExtractTimeAndCharge.h"
     154#include "MPedestalSubtractedEvt.h"
    154155
    155156ClassImp(MPedCalcFromLoGain);
     
    157158using namespace std;
    158159
    159 const UShort_t MPedCalcFromLoGain::fgCheckWinFirst   =  0;
    160 const UShort_t MPedCalcFromLoGain::fgCheckWinLast    = 29;
    161160const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 17;
    162161const UShort_t MPedCalcFromLoGain::fgExtractWinSize  =  6;
    163 const UShort_t MPedCalcFromLoGain::fgMaxSignalVar    = 40;
     162const UInt_t   MPedCalcFromLoGain::fgNumDump         = 500;
    164163
    165164// --------------------------------------------------------------------------
     
    167166// Default constructor:
    168167//
    169 // Sets:
    170 // - all pointers to NULL
    171 //
    172168// Calls:
    173 // - AddToBranchList("fHiGainPixId");
    174 // - AddToBranchList("fHiGainFadcSamples");
    175 // - SetCheckRange(fgCheckWinFirst, fgCheckWinLast, fgExtractWinFirst, fgExtractWinSize)
     169// - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
    176170//
    177171MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title)
     
    180174    fTitle = title ? title : "Task to calculate pedestals from lo-gains";
    181175
    182     SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
    183176    SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
    184 
    185     SetMaxSignalVar(fgMaxSignalVar);
    186 }
    187 
     177    SetPedestalUpdate(kTRUE);
     178    SetNumDump();
     179}
     180
     181// --------------------------------------------------------------------------
     182//
     183// Call MExtractPedestl::ResetArrays aand reset fNumAventsUsed and
     184// fTotalCounter
     185//
    188186void MPedCalcFromLoGain::ResetArrays()
    189187{
     
    192190    fNumEventsUsed.Reset();
    193191    fTotalCounter.Reset();
    194 }
    195 
    196 // --------------------------------------------------------------------------
    197 //
    198 // SetCheckRange:
    199 //
    200 // Exits, if the first argument is smaller than 0
    201 // Exits, if the the last argument is smaller than the first
    202 //
    203 Bool_t MPedCalcFromLoGain::SetCheckRange(UShort_t chfirst, UShort_t chlast)
    204 {
    205 
    206   Bool_t rc = kTRUE;
    207  
    208   if (chlast<=chfirst)
    209     {
    210       *fLog << warn << GetDescriptor();
    211       *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl;
    212       chlast = chfirst+1;
    213       rc = kFALSE;
    214     }
    215 
    216   fCheckWinFirst = chfirst;
    217   fCheckWinLast  = chlast;
    218 
    219   return rc;
    220192}
    221193
     
    231203Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
    232204{
    233 
    234   const UShort_t hisamples = fRunHeader->GetNumSamplesHiGain();
    235   const UShort_t losamples = fRunHeader->GetNumSamplesLoGain();
    236  
    237   fSlices.Set(hisamples+losamples);
    238  
    239   UShort_t lastavailable   = hisamples+losamples-1;
    240 
    241   if (fExtractor)
    242     fExtractWinLast = fExtractWinFirst + fExtractor->GetWindowSizeHiGain() - 1;
    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   if (fCheckWinLast > lastavailable) //changed to override check
    253     {
    254       *fLog << warn << GetDescriptor();
    255       *fLog << " - WARNING: Last Check Window slice out of range...adjusting to last available slice ";
    256       *fLog << lastavailable << endl;
    257      
    258       fCheckWinLast = lastavailable;
    259     }
    260  
    261   if (fExtractWinLast > lastavailable)
    262     {
    263       if (fExtractor)
    264         {
    265           *fLog << err << GetDescriptor();
    266           *fLog << " - ERROR: Selected Last Extraction Window: "
    267                 << fExtractWinFirst + fExtractor->GetWindowSizeHiGain()-1
    268                 << "ranges out of range: " << lastavailable-1 << endl;
    269           return kFALSE;
    270         }
    271       else
    272         {
    273           const UShort_t diff = fExtractWinLast - lastavailable;
    274           *fLog << warn << GetDescriptor();
    275           *fLog << " - WARNING: Selected Extract Window ranges out of range...adjusting to last available slice ";
    276           *fLog << lastavailable << endl;
    277          
    278           fExtractWinLast -= diff;
    279           fExtractWinSize -= diff;
    280         }
    281     }
    282  
    283   return MExtractPedestal::ReInit(pList);
     205    // If the size is not yet set, set the size
     206    if (fSumx.GetSize()==0)
     207    {
     208        const Int_t npixels = fPedestalsOut->GetSize();
     209        fNumEventsUsed.Set(npixels);
     210        fTotalCounter.Set(npixels);
     211    }
     212
     213    if (!MExtractPedestal::ReInit(pList))
     214        return kFALSE;
     215
     216    return kTRUE;
    284217}
    285218
     
    292225Int_t MPedCalcFromLoGain::Calc()
    293226{
    294     // This is the workaround to put hi- and lo-gains together
    295     const Int_t nhigain = fRunHeader->GetNumSamplesHiGain();
    296     const Int_t nlogain = fRunHeader->GetNumSamplesLoGain();
    297 
    298     Byte_t *slices = fSlices.GetArray();
    299 
    300227    // Real Process
    301228    MRawEvtPixelIter pixel(fRawEvt);
     
    303230    while (pixel.Next())
    304231    {
    305         // This is the fast workaround to put hi- and lo-gains together
    306         memcpy(slices,         pixel.GetHiGainSamples(), nhigain);
    307         memcpy(slices+nhigain, pixel.GetLoGainSamples(), nlogain);
    308 
    309         // Start 'real' work
    310232        const UInt_t idx = pixel.GetPixelId();
     233
     234        if (!CheckVariation(idx))
     235            continue;
     236
     237        //extract pedestal
     238        UInt_t ab[2];
     239        const Float_t sum = fExtractor ?
     240            CalcExtractor(pixel, pixel.GetNumHiGainSamples()) :
     241            CalcSums(pixel, pixel.GetNumHiGainSamples(), ab[0], ab[1]);
    311242
    312243        const UInt_t aidx   = (*fGeom)[idx].GetAidx();
    313244        const UInt_t sector = (*fGeom)[idx].GetSector();
    314 
    315         UShort_t max = 0;
    316         UShort_t min = (UShort_t)-1;
    317 
    318         // Find the maximum and minimum signal per slice in the high gain window
    319         for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)
    320         {
    321             if (*slice > max)
    322                 max = *slice;
    323             if (*slice < min)
    324                 min = *slice;
    325         }
    326      
    327         // If the maximum in the high gain window is smaller than
    328         if (max-min>=fMaxSignalVar || max>=250)
    329             continue;
    330 
    331         Float_t sum  = 0.;
    332 
    333         //extract pedestal
    334         if (fExtractor)
    335             CalcExtractor(pixel, sum, (*fPedestalsIn)[idx]);
    336         else
    337         {
    338             UInt_t  sumi = 0;
    339             for(Byte_t *slice=slices+fExtractWinFirst; slice<=slices+fExtractWinLast; slice++)
    340                 sumi += *slice;
    341             sum = (Float_t)sumi;
    342         }
    343245
    344246        const Float_t sqrsum = sum*sum;
     
    352254
    353255        if (fIntermediateStorage)
    354           (*fPedestalsInter)[idx].Set(sum,0.,0.,fNumEventsUsed[idx]);
     256            (*fPedestalsInter)[idx].Set(sum, 0, 0, fNumEventsUsed[idx]);
    355257
    356258        fNumEventsUsed[idx]   ++;
     
    358260        fSectorFilled [sector]++;
    359261
    360         if (!fExtractor)
     262        if (!fExtractor && pixel.IsABFlagValid())
    361263        {
    362             //
    363             // Calculate the amplitude of the 150MHz "AB" noise
    364             //
    365             const UShort_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1;
    366 
    367             for (Byte_t *slice=slices+fExtractWinFirst; slice<=slices+fExtractWinLast; slice+=2)
    368             {
    369                 const UShort_t ab0 = *(slice + abFlag);
    370                 const UShort_t ab1 = *(slice - abFlag + 1);
    371 
    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             }
     264            fSumAB0[idx]        += ab[0];
     265            fSumAB1[idx]        += ab[1];
     266            fAreaSumAB0[aidx]   += ab[0];
     267            fAreaSumAB1[aidx]   += ab[1];
     268            fSectorSumAB0[aidx] += ab[0];
     269            fSectorSumAB1[aidx] += ab[1];
    379270        }
    380271
     
    425316            CalcAreaResults(fAreaFilled[aidx], fAreaValid[aidx], aidx);
    426317
    427 }
    428 
    429 void MPedCalcFromLoGain::CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped)
    430 {
    431     Byte_t  sat  = 0;
    432     Byte_t *logain = pixel.GetLoGainSamples() + fExtractWinFirst;
    433 
    434     const Bool_t logainabflag = (pixel.HasABFlag() + pixel.GetNumHiGainSamples()) & 0x1;
    435 
    436     Float_t dummy;
    437     fExtractor->FindTimeAndChargeHiGain(logain,logain,sum,dummy,dummy,dummy,sat,ped,logainabflag);
    438318}
    439319
     
    469349}
    470350
    471 
    472351// --------------------------------------------------------------------------
    473352//
    474353//  The following resources are available:
    475 //    FirstCheckWindowSlice:  0
    476 //    LastCheckWindowSlice:  29
    477 //    MaxSignalVar:          40
    478354//
    479355Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     
    481357    Bool_t rc=kFALSE;
    482358
    483     // Find resources for CheckWindow
    484     Int_t fs = fCheckWinFirst;
    485     Int_t ls = fCheckWinLast;
    486     if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
    487     {
    488         fs = GetEnvValue(env, prefix, "CheckWinFirst", fs);
     359    // find resource for pedestal update
     360    if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
     361    {
     362        SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
    489363        rc = kTRUE;
    490364    }
    491     if (IsEnvDefined(env, prefix, "CheckWinLast", print))
    492     {
    493         ls = GetEnvValue(env, prefix, "CheckWinLast", ls);
     365
     366    // find resource for numdump
     367    if (IsEnvDefined(env, prefix, "NumDump", print))
     368    {
     369        const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
     370        if (num<=0)
     371        {
     372            *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
     373            return kERROR;
     374        }
     375
     376        SetNumDump(num);
    494377        rc = kTRUE;
    495378    }
    496379
    497     SetCheckRange(fs,ls);
    498 
    499     // find resource for maximum signal variation
    500     if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
    501     {
    502         SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
     380    // find resource for numeventsdump
     381    if (IsEnvDefined(env, prefix, "NumEventsDump", print))
     382    {
     383        SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
    503384        rc = kTRUE;
    504385    }
    505386
    506     return MExtractPedestal::ReadEnv(env,prefix,print) ? kTRUE : rc;
     387    // find resource for numeventsdump
     388    if (IsEnvDefined(env, prefix, "NumAreasDump", print))
     389    {
     390        SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
     391        rc = kTRUE;
     392    }
     393
     394    // find resource for numeventsdump
     395    if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
     396    {
     397        SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
     398        rc = kTRUE;
     399    }
     400
     401    return rc;
    507402}
    508403
    509404void MPedCalcFromLoGain::Print(Option_t *o) const
    510405{
    511 
    512406    MExtractPedestal::Print(o);
    513407
    514     const Int_t last = fExtractor
    515       ? fExtractWinFirst + fExtractor->GetWindowSizeHiGain() -1
    516       : fExtractWinLast;
    517 
    518     *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << last << " incl." << endl;
    519     *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl;
    520     *fLog << "CheckWindow from slice " << fCheckWinFirst   << " to " << fCheckWinLast << " incl." << endl;
    521 }
     408    *fLog << "Pedestal Update is            " << (fPedestalUpdate?"on":"off") << endl;
     409    if (fPedestalUpdate)
     410    {
     411        *fLog << "Num evts for pedestal   calc: " << fNumEventsDump << endl;
     412        *fLog << "Num evts for avg.areas  calc: " << fNumAreasDump << endl;
     413        *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
     414    }
     415}
Note: See TracChangeset for help on using the changeset viewer.