Changeset 8151 for trunk/MagicSoft


Ignore:
Timestamp:
10/24/06 08:58:13 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mpedestal
Files:
8 edited

Legend:

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

    r7188 r8151  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.23 2006-10-24 07:58:13 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    1719!
    1820!   Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
     21!   Author(s): Thomas Bretz 01/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1922!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     23!   Copyright: MAGIC Software Development, 2000-2006
    2124!
    2225!
     
    159162#include "MRawEvtHeader.h" 
    160163#include "MRawEvtPixelIter.h"
    161 #include "MRawEvtData.h"
    162164
    163165#include "MPedestalPix.h"
     
    167169#include "MGeomCam.h"
    168170
    169 #include "MTaskEnv.h"
    170171#include "MExtractTimeAndCharge.h"
     172#include "MPedestalSubtractedEvt.h"
    171173
    172174ClassImp(MExtractPedestal);
     
    174176using namespace std;
    175177
    176 const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
    177 const TString MExtractPedestal::fgNameRawEvtData  = "MRawEvtData";
    178 const UInt_t  MExtractPedestal::fgNumDump = 500;
     178const TString  MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
     179const TString  MExtractPedestal::fgNameRawEvtData  = "MRawEvtData";
     180
     181const UShort_t MExtractPedestal::fgCheckWinFirst   =  0;
     182const UShort_t MExtractPedestal::fgCheckWinLast    = 29;
     183const UShort_t MExtractPedestal::fgMaxSignalVar    = 40;
    179184
    180185// --------------------------------------------------------------------------
     
    186191//
    187192// Calls:
    188 // - AddToBranchList("fHiGainPixId");
    189 // - AddToBranchList("fHiGainFadcSamples");
    190193// - Clear()
    191194//
    192195MExtractPedestal::MExtractPedestal(const char *name, const char *title)
    193     : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), fPedestalsOut(NULL),
    194       fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE)
     196    : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL),
     197    fPedestalsOut(NULL), fExtractor(NULL), fSignal(0),
     198    fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE)
    195199{
    196200    fName  = name  ? name  : "MExtractPedestal";
    197201    fTitle = title ? title : "Base class to calculate pedestals";
    198202
    199     AddToBranchList("fHiGainPixId");
    200     AddToBranchList("fLoGainPixId");
    201     AddToBranchList("fHiGainFadcSamples");
    202     AddToBranchList("fLoGainFadcSamples");
    203  
    204203    SetIntermediateStorage( kFALSE );
    205     SetPedestalUpdate     ( kTRUE  );
    206204    SetRandomCalculation  ( kTRUE  );
    207205
     
    210208    SetNamePedestalCamInter();
    211209    SetNameRawEvtData();
    212     SetNumDump();
     210
     211    SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
     212    SetMaxSignalVar(fgMaxSignalVar);
    213213
    214214    Clear();
    215215}
    216216
     217// --------------------------------------------------------------------------
     218//
     219// Call reset() of all Arays
     220//
    217221void MExtractPedestal::ResetArrays()
    218222{
     
    244248// - fRawEvt to NULL
    245249// - fRunHeader to NULL
    246 // - fEvtHeader to NULL
    247250//
    248251void MExtractPedestal::Clear(const Option_t *o)
     
    251254  fRawEvt       = NULL;
    252255  fRunHeader    = NULL;
    253   fEvtHeader    = NULL;
    254256
    255257  // If the size is yet set, set the size
     
    269271  Bool_t rc = kTRUE;
    270272
    271   const Int_t odd  = windows & 0x1;
     273  const Int_t odd  = TMath::Odd(windows);
    272274 
    273275  if (odd && !fExtractor)
     
    275277      *fLog << warn << GetDescriptor();
    276278      *fLog << " - WARNING: Window size in SetExtractWindow has to be even... ";
    277       *fLog << " raising from " << windows << " to ";
    278       windows += 1;
     279      *fLog << " lowering from " << windows << " to ";
     280      windows -= 1;
    279281      *fLog << windows << "!" << endl;
    280282      rc = kFALSE;
     
    292294  fExtractWinFirst = windowf;
    293295  fExtractWinLast  = fExtractWinFirst+fExtractWinSize-1;
     296
     297  return rc;
     298}
     299
     300// --------------------------------------------------------------------------
     301//
     302// SetCheckRange:
     303//
     304// Exits, if the first argument is smaller than 0
     305// Exits, if the the last argument is smaller than the first
     306//
     307Bool_t MExtractPedestal::SetCheckRange(UShort_t chfirst, UShort_t chlast)
     308{
     309
     310  Bool_t rc = kTRUE;
    294311 
     312  if (chlast<=chfirst)
     313    {
     314      *fLog << warn << GetDescriptor();
     315      *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl;
     316      chlast = chfirst+1;
     317      rc = kFALSE;
     318    }
     319
     320  fCheckWinFirst = chfirst;
     321  fCheckWinLast  = chlast;
     322
    295323  return rc;
     324}
     325
     326
     327// --------------------------------------------------------------------------
     328//
     329// Check (and if neccesary: correct) the extraction and check ranges.
     330//
     331void MExtractPedestal::CheckExtractionWindow()
     332{
     333    // fSignal->GetNumSamples() not yet initialized!!!
     334    const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain();
     335
     336    if (fCheckWinLast >= num)
     337    {
     338        *fLog << warn << endl;
     339        *fLog << "Selected CheckWindow [" << fCheckWinFirst << "," << fCheckWinLast;
     340        *fLog << "] ranges out of range [0," << num-1 << "]." << endl;
     341        *fLog << "Resetting upper edge." << endl;
     342
     343        fCheckWinLast = num;
     344    }
     345
     346    if (fExtractWinLast >= num)
     347    {
     348        *fLog << warn << endl;
     349        *fLog << "Selected ExtractWindow [" << fExtractWinFirst << "," << fExtractWinLast;
     350        *fLog << "] ranges out of range [0," << num-1 << "]." << endl;
     351        *fLog << "Resetting upper edge." << endl;
     352
     353        fExtractWinLast = num;
     354    }
     355
     356    fExtractWinSize = fExtractWinLast-fExtractWinFirst+1;
     357
     358    if (fExtractor || TMath::Even(fExtractWinSize))
     359        return;
     360
     361    fExtractWinLast += fExtractWinLast==num-1 ? -1 : +1;
     362
     363    *fLog << warn << endl;
     364    *fLog << "ExtractionWindow odd...";
     365    *fLog << "New extraction window [" << fExtractWinFirst << "," << fExtractWinLast << "]" << endl;
     366
     367    fExtractWinSize = fExtractWinLast-fExtractWinFirst+1;
    296368}
    297369
     
    338410  }
    339411 
    340   fEvtHeader = (MRawEvtHeader*)pList->FindObject(AddSerialNumber("MRawEvtHeader"));
    341   if (!fEvtHeader)
    342   {
    343       *fLog << err << AddSerialNumber("MRawEvtHeader") << " not found... aborting." << endl;
    344       return kFALSE;
    345   }
    346  
    347412  fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
    348413  if (!fGeom)
    349414  {
    350415      *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
     416      return kFALSE;
     417  }
     418
     419  fSignal = (MPedestalSubtractedEvt*)pList->FindObject(AddSerialNumber("MPedestalSubtractedEvt"));
     420  if (!fSignal)
     421  {
     422      *fLog << err << AddSerialNumber("MPedestalSubtractedEvt") << " not found... aborting." << endl;
    351423      return kFALSE;
    352424  }
     
    376448  }
    377449
    378   *fLog << inf;
    379   Print();
    380 
    381450  return fExtractor ? fExtractor->CallPreProcess(pList) : kTRUE;
    382451}
    383452
     453//-----------------------------------------------------------------------
     454//
     455// Call Calc(). If fExtractor!=NULL enclose the call in setting the
     456// NoiseCalculation to fRandomCalculation
     457//
    384458Int_t MExtractPedestal::Process()
    385459{
     
    491565    if (fExtractor)
    492566    {
    493         if (!((MTask*)fExtractor)->ReInit(pList))
     567        if (!fExtractor->ReInit(pList))
    494568            return kFALSE;
    495569
    496         SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
    497     }
     570        // If an extractor is set determin the window size automatically!
     571        fExtractWinFirst = fExtractor->GetHiGainFirst();
     572        fExtractWinLast  = fExtractor->GetHiGainLast();
     573
     574        // fSignal->GetNumSamples() not yet initialized!!!
     575        const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain();
     576        if (fExtractWinLast >= num)
     577        {
     578            *fLog << err << GetDescriptor();
     579            *fLog << " - ERROR: Selected fExtractWinLast out of range." << endl;
     580            return kFALSE;
     581        }
     582    }
     583
     584    CheckExtractionWindow();
    498585
    499586    return kTRUE;
    500587}
    501588
     589// ---------------------------------------------------------------------------------
     590//
     591// PostProcess the extractor if available
     592//
    502593Int_t MExtractPedestal::PostProcess()
    503594{
     
    506597}
    507598
     599// ---------------------------------------------------------------------------------
     600//
     601// Check whether the signal variation between fCheckWinFirst and fCheckWinLast
     602// exceeds fMaxSignalVar or the signal is greater than 250
     603//
     604Bool_t MExtractPedestal::CheckVariation(UInt_t idx) const
     605{
     606    // This is the fast workaround to put hi- and lo-gains together
     607    Byte_t *slices = fSignal->GetSamplesRaw(idx);//pixel.GetSamples();
     608
     609    // Start 'real' work
     610    UShort_t max = 0;
     611    UShort_t min = (UShort_t)-1;
     612
     613    // Find the maximum and minimum signal per slice in the high gain window
     614    for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)
     615    {
     616        if (*slice > max)
     617            max = *slice;
     618        if (*slice < min)
     619            min = *slice;
     620    }
     621
     622    // If the maximum in the high gain window is smaller than
     623    return max-min<fMaxSignalVar && max<250;
     624}
     625
     626// ---------------------------------------------------------------------------------
     627//
     628// Invoke the hi-gain extraction starting at fExtractWinFirst+offset
     629// for fExtractWinLast-fExtractWinFirst+1 slices. If Noise calculation
     630// is set it is up to the signal extractor to do the right thing.
     631//
     632// Returns the extracted signal.
     633//
     634Float_t MExtractPedestal::CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const
     635{
     636    // Use the same extraction window as for signal extraction
     637    const Int_t first = fExtractWinFirst;
     638    const Int_t last  = fExtractWinLast;
     639
     640    const Int_t start = first+offset;
     641
     642    const Int_t range = last-first+1;
     643
     644    // This check is already done in CheckExtractionWindow
     645    //    if (range>pixel.GetNumSamples()-start)
     646    //        range = pixel.GetNumSamples()-start;
     647
     648    const Int_t idx = pixel.GetPixelId();
     649
     650    // Do some handling if maxpos is last slice?
     651    const Int_t maxposhi = fSignal->GetMax(idx, start, start+range-1);
     652
     653    const Float_t *sig = fSignal->GetSamples(idx);
     654
     655    // The pedestal is extracted with the hi-gain extractor (eg. digital
     656    // filter weights) but from the lo-gains
     657    Float_t dummy[3];
     658    Float_t sum = 0;
     659    fExtractor->FindTimeAndChargeHiGain2(sig+start, range, sum,
     660                                         dummy[0], dummy[1], dummy[2],
     661                                         0, maxposhi);
     662    return sum;
     663}
     664
     665// ---------------------------------------------------------------------------------
     666//
     667// Sum slices from fExtractWinFirst to fExtractWinLast. The total sum is
     668// returned. ab0 and ab1 will contain the total sum splitted by the
     669// AB-flag. If the AB-flag is invalid ab0=ab1=0 is returned.
     670//
     671UInt_t MExtractPedestal::CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const
     672{
     673    const Int_t first = fExtractWinFirst+offset;
     674
     675    Byte_t *ptr = fSignal->GetSamplesRaw(pixel.GetPixelId())+first;
     676    Byte_t *end = ptr + fExtractWinSize;
     677
     678    Int_t abflag = pixel.HasABFlag() + first;
     679
     680    UInt_t ab[2] = { 0, 0 };
     681    while (ptr<end)
     682        ab[abflag++ & 0x1] += *ptr++;
     683
     684    // This check if for old data without AB-Flag in the data
     685    const Bool_t valid = pixel.IsABFlagValid();
     686
     687    ab0 = valid ? ab[0] : 0;
     688    ab1 = valid ? ab[1] : 0;
     689
     690    return ab0+ab1;
     691}
    508692
    509693// --------------------------------------------------------------------------
     
    512696//    ExtractWindowFirst:    15
    513697//    ExtractWindowSize:      6
    514 //    NumEventsDump:        500
    515698//    PedestalUpdate:       yes
    516699//    RandomCalculation:    yes
     
    520703    Bool_t rc=kFALSE;
    521704
    522     // find resource for numdump
    523     if (IsEnvDefined(env, prefix, "NumDump", print))
    524     {
    525         const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);
    526         if (num<=0)
    527         {
    528             *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;
    529             return kERROR;
    530         }
    531 
    532         SetNumDump(num);
    533         rc = kTRUE;
    534     }
    535 
    536705    // find resource for fUseSpecialPixels
    537706    if (IsEnvDefined(env, prefix, "UseSpecialPixels", print))
    538707    {
    539708        SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels));
    540         rc = kTRUE;
    541     }
    542 
    543     // find resource for numeventsdump
    544     if (IsEnvDefined(env, prefix, "NumEventsDump", print))
    545     {
    546         SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
    547         rc = kTRUE;
    548     }
    549 
    550     // find resource for numeventsdump
    551     if (IsEnvDefined(env, prefix, "NumAreasDump", print))
    552     {
    553         SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
    554         rc = kTRUE;
    555     }
    556 
    557     // find resource for numeventsdump
    558     if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
    559     {
    560         SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
    561         rc = kTRUE;
    562     }
    563 
    564     // find resource for pedestal update
    565     if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
    566     {
    567         SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
    568709        rc = kTRUE;
    569710    }
     
    598739    SetExtractWindow(ef,es);
    599740
     741    // Find resources for CheckWindow
     742    Int_t cfs = fCheckWinFirst;
     743    Int_t cls = fCheckWinLast;
     744    if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
     745    {
     746        cfs = GetEnvValue(env, prefix, "CheckWinFirst", cfs);
     747        rc = kTRUE;
     748    }
     749    if (IsEnvDefined(env, prefix, "CheckWinLast", print))
     750    {
     751        cls = GetEnvValue(env, prefix, "CheckWinLast", cls);
     752        rc = kTRUE;
     753    }
     754
     755    SetCheckRange(cfs,cls);
     756
     757    // find resource for maximum signal variation
     758    if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
     759    {
     760        SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
     761        rc = kTRUE;
     762    }
     763
    600764    // find resource for MPedestalCam
    601765    if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
     
    648812    var    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
    649813    abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
     814    // The pedestal extracted with the extractor is divided by
     815    // the number of hi-gain samples because the calibration
     816    // multiplies by this number
    650817
    651818    // 5. Calculate the RMS from the Variance:
    652819    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
    653820
     821    // abOffs contains only half of the signal as ped.
     822    // Therefor abOffs is not the full, but the half amplitude
    654823    (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
    655824}
     
    683852    var    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
    684853    abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
     854    // The pedestal extracted with the extractor is divided by
     855    // the number of hi-gain samples because the calibration
     856    // multiplies by this number
    685857
    686858    // 5. Scale the mean, variance and AB-noise to the number of pixels:
     
    692864    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
    693865
     866    // abOffs contains only half of the signal as ped.
     867    // Therefor abOffs is not the full, but the half amplitude
    694868    fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
    695869}
     
    723897    var    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
    724898    abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
     899    // The pedestal extracted with the extractor is divided by
     900    // the number of hi-gain samples because the calibration
     901    // multiplies by this number
    725902
    726903    // 5. Scale the mean, variance and AB-noise to the number of pixels:
     
    732909    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
    733910
     911    // abOffs contains only half of the signal as ped.
     912    // Therefor abOffs is not the full, but the half amplitude
    734913    fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
    735914}
    736915
     916//-----------------------------------------------------------------------
     917//
    737918void MExtractPedestal::Print(Option_t *o) const
    738919{
     
    742923    *fLog << "Name of output MPedestalCam:  " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
    743924    *fLog << "Intermediate Storage is       " << (fIntermediateStorage?"on":"off") << endl;
    744     *fLog << "Pedestal Update is            " << (fPedestalUpdate?"on":"off") << endl;
    745925    *fLog << "Special pixel mode            " << (fUseSpecialPixels?"on":"off") << endl;
    746     if (fPedestalUpdate)
    747     {
    748         *fLog << "Num evts for pedestal   calc: " << fNumEventsDump << endl;
    749         *fLog << "Num evts for avg.areas  calc: " << fNumAreasDump << endl;
    750         *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
    751     }
    752926    if (fExtractor)
    753927    {
     
    755929        *fLog << (fRandomCalculation?"":"non-") << "random)" << endl;
    756930    }
    757 }
     931    *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << fExtractWinLast << " incl." << endl;
     932    *fLog << "CheckWindow from slice " << fCheckWinFirst   << " to " << fCheckWinLast << " incl." << endl;
     933    *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl;
     934}
  • trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h

    r7188 r8151  
    2020class MRawEvtHeader;
    2121class MExtractTimeAndCharge;
     22class MPedestalSubtractedEvt;
     23class MRawEvtPixelIter;
    2224
    2325class MExtractPedestal : public MTask
     
    2628  static const TString  fgNamePedestalCam;  //! "MPedestalCam"
    2729  static const TString  fgNameRawEvtData;   //! "MRawEvtData"
    28   static const UInt_t   fgNumDump;          //!
     30
     31  static const UShort_t fgCheckWinFirst;    //! First FADC slice to check for signal (currently set to: 0)
     32  static const UShort_t fgCheckWinLast;     //! Last FADC slice to check for signal  (currently set to: 29)
     33  static const UShort_t fgMaxSignalVar;     //! The maximum difference between the highest and lowest slice
    2934
    3035  TString fNamePedestalCamIn;        // Name of the incoming 'MPedestalCam' container
     
    4550  MRawEvtData   *fRawEvt;            //! Raw event data (time slices)
    4651  MRawRunHeader *fRunHeader;         //! RunHeader information
    47   MRawEvtHeader *fEvtHeader;         //! EvtHeader information
    4852  MExtractTimeAndCharge *fExtractor; //  Possible Extractor
     53  MPedestalSubtractedEvt *fSignal;   //!
    4954 
    5055  UShort_t fExtractWinFirst;         // First FADC slice to extract pedestal from
    5156  UShort_t fExtractWinSize;          // Number of slices to calculate the pedestal from
    5257  UShort_t fExtractWinLast;          // Last FADC slice to extract pedestal from
    53                                      
    54   UInt_t  fNumEventsDump;            // Number of event after which MPedestalCam gets updated
    55   UInt_t  fNumAreasDump;             // Number of events after which averaged areas gets updated
    56   UInt_t  fNumSectorsDump;           // Number of events after which averaged sectors gets updated
    57  
    58   Bool_t  fPedestalUpdate;           // Flag if the pedestal shall be updated after every fNumEventsDump
     58
     59  UShort_t fCheckWinFirst;
     60  UShort_t fCheckWinLast;
     61
     62  UShort_t fMaxSignalVar;
     63
    5964  Bool_t  fUseSpecialPixels;         // Flag if the special pixels shall be treated
    6065
     
    9297  void CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector);
    9398
     99  Float_t CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const;
     100  UInt_t  CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const;
     101  Bool_t  CheckVariation(UInt_t idx) const;
     102
     103  void CheckExtractionWindow();
     104
    94105public:
    95106  MExtractPedestal(const char *name=NULL, const char *title=NULL);
     
    98109  void Print(const Option_t *o="") const;
    99110
     111  // Setters
    100112  Bool_t SetExtractWindow(UShort_t first, UShort_t size);
     113  Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast);
    101114
    102   void SetNumEventsDump (UInt_t dumpevents=fgNumDump)  { fNumEventsDump  = dumpevents; }
    103   void SetNumAreasDump  (UInt_t dumpevents=fgNumDump)  { fNumAreasDump   = dumpevents; }
    104   void SetNumSectorsDump(UInt_t dumpevents=fgNumDump)  { fNumSectorsDump = dumpevents; }
    105   void SetNumDump       (UInt_t n=fgNumDump) { fNumEventsDump=n; fNumAreasDump=n; fNumSectorsDump=n; }
     115  void SetMaxSignalVar(UShort_t maxvar=40)  { fMaxSignalVar = maxvar;    }
    106116
    107117  // names
     
    120130  void SetIntermediateStorage (Bool_t b=kTRUE) { fIntermediateStorage = b; }
    121131  void SetUseSpecialPixels    (Bool_t b=kTRUE) { fUseSpecialPixels    = b; }
    122   void SetPedestalUpdate      (Bool_t b=kTRUE) { fPedestalUpdate      = b; }
    123132  void SetRandomCalculation   (Bool_t b=kTRUE) { fRandomCalculation   = b; }
    124133
  • 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}
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h

    r5715 r8151  
    1414#endif
    1515
    16 class MRawEvtPixelIter;
     16//class MRawEvtPixelIter;
    1717class MPedestalPix;
    1818
     
    2020{
    2121private:
    22     static const UShort_t fgCheckWinFirst;    // First FADC slice to check for signal (currently set to: 0)
    23     static const UShort_t fgCheckWinLast;     // Last FADC slice to check for signal  (currently set to: 29)
    24     static const UShort_t fgMaxSignalVar;     // The maximum difference between the highest and lowest slice
    2522    static const UShort_t fgExtractWinFirst;  // First FADC slice to use for pedestal calculation (currently set to: 15)
    2623    static const UShort_t fgExtractWinSize;   // number of successive slices used to calculate pedestal (currently set to: 6)
     24    static const UInt_t   fgNumDump;          //!
    2725
    28     UShort_t fMaxSignalVar;
    29     UShort_t fCheckWinFirst;
    30     UShort_t fCheckWinLast;
     26    UInt_t  fNumEventsDump;            // Number of event after which MPedestalCam gets updated
     27    UInt_t  fNumAreasDump;             // Number of events after which averaged areas gets updated
     28    UInt_t  fNumSectorsDump;           // Number of events after which averaged sectors gets updated
    3129
    3230    TArrayI fNumEventsUsed;      //! Number of events used for pedestal calc for each pixel
    3331    TArrayI fTotalCounter;       //! Counter for dumping values to Pedestal Container
    3432
    35     MArrayB fSlices;             //! workaround to put hi- and lo-gain slices together
     33    Bool_t  fPedestalUpdate;           // Flag if the pedestal shall be updated after every fNumEventsDump
    3634
    37     Bool_t fRandomCalculation;
     35    // MParContainer
     36    Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    3837
     38    // MTask
    3939    Bool_t ReInit(MParList *pList);
    40     Int_t  Calc();
    4140    Int_t  PostProcess();
    4241
    43     Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
     42    // MExtractPedestal
     43    Int_t  Calc();
    4444
    4545    //Helper function to extract slice values by slice number
    46     void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);
     46    //void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);
    4747    void ResetArrays();
    4848
     
    5353    MPedCalcFromLoGain(const char *name=NULL, const char *title=NULL);
    5454
    55     void Print(Option_t *o="") const;
    56 
    57     // Setters
    58     Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast);
    59     void SetMaxSignalVar(UShort_t maxvar=40)  { fMaxSignalVar = maxvar;    }
    60 
    6155    // Getters
    6256    TArrayI *GetNumEventsUsed() { return &fNumEventsUsed; }
     57
     58    void SetNumEventsDump (UInt_t dumpevents=fgNumDump)  { fNumEventsDump  = dumpevents; }
     59    void SetNumAreasDump  (UInt_t dumpevents=fgNumDump)  { fNumAreasDump   = dumpevents; }
     60    void SetNumSectorsDump(UInt_t dumpevents=fgNumDump)  { fNumSectorsDump = dumpevents; }
     61    void SetNumDump       (UInt_t n=fgNumDump) { fNumEventsDump=n; fNumAreasDump=n; fNumSectorsDump=n; }
     62
     63    void SetPedestalUpdate(Bool_t b=kTRUE) { fPedestalUpdate      = b; }
     64
     65    void Print(Option_t *o="") const;
    6366
    6467    ClassDef(MPedCalcFromLoGain, 1)   // Task to calculate pedestals from data runs
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc

    r7188 r8151  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MPedCalcPedRun.cc,v 1.49 2006-10-24 07:58:13 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    2224!   Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
    2325!
    24 !   Copyright: MAGIC Software Development, 2000-2004
     26!   Copyright: MAGIC Software Development, 2000-2006
    2527!
    2628!
     
    137139
    138140#include "MExtractPedestal.h"
    139 #include "MExtractTimeAndCharge.h"
     141#include "MPedestalSubtractedEvt.h"
    140142
    141143#include "MTriggerPattern.h"
     
    147149const UShort_t MPedCalcPedRun::fgExtractWinFirst       = 0;
    148150const UShort_t MPedCalcPedRun::fgExtractWinSize        = 6;
     151
    149152const UInt_t   MPedCalcPedRun::gkFirstRunWithFinalBits = 45605;
     153
    150154// --------------------------------------------------------------------------
    151155//
    152156// Default constructor:
    153157//
    154 // Sets:
    155 // - all pointers to NULL
    156 // - fWindowSizeHiGain to fgHiGainWindowSize
    157 // - fWindowSizeLoGain to fgLoGainWindowSize
    158 //
    159158// Calls:
    160 // - AddToBranchList("fHiGainPixId");
    161 // - AddToBranchList("fHiGainFadcSamples");
    162 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
     159// - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize)
    163160//
    164161MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
    165     : fOverlap(0), fIsFirstPedRun(kFALSE), fUsedEvents(0), fTrigPattern(NULL)
    166 {
    167   fName  = name  ? name  : "MPedCalcPedRun";
    168   fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
    169  
    170   SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
    171  
    172   //  SetNumEventsDump(1001);
    173   //  SetNumAreasDump(1001);
    174   //  SetNumSectorsDump(1001);
    175 }
    176 
    177 // --------------------------------------------------------------------------
    178 //
    179 // In case that the variables fExtractLast is greater than the number of
    180 // High-Gain FADC samples obtained from the run header, the flag
    181 // fOverlap is set to the difference and fExtractLast is set back by the
    182 // same number of slices.
    183 //
    184 void MPedCalcPedRun::CheckExtractionWindow()
    185 {
    186   const UShort_t lastavailable = fRunHeader->GetNumSamplesHiGain()-1;
    187  
    188   if (fExtractWinLast <= lastavailable)
    189     return;
    190  
    191   const UShort_t diff = fExtractWinLast - lastavailable;
    192  
    193   *fLog << warn << endl;
    194   *fLog << "Selected ExtractWindow [" << fExtractWinFirst << "," << fExtractWinLast;
    195   *fLog << "] ranges out of range [0," << lastavailable << "]." << endl;
    196   *fLog << "Using " << diff << " samples from the 'Lo-Gain' slices for the pedestal extraction" << endl;
    197  
    198   fExtractWinLast -= diff;
    199   fOverlap         = diff;
    200 }
    201 
     162    : fIsFirstPedRun(kFALSE), fUsedEvents(0), fTrigPattern(NULL)
     163{
     164    fName  = name  ? name  : "MPedCalcPedRun";
     165    fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
     166
     167    SetExtractWindow(fgExtractWinFirst, fgExtractWinSize);
     168}
     169
     170// --------------------------------------------------------------------------
     171//
     172// Call MExtractPedestal::reset and set fUsedEvents to 0.
     173//
    202174void MPedCalcPedRun::Reset()
    203175{
    204 
    205   MExtractPedestal::ResetArrays();
    206   fUsedEvents    = 0;
     176    MExtractPedestal::ResetArrays();
     177    fUsedEvents = 0;
    207178}
    208179
     
    213184Int_t MPedCalcPedRun::PreProcess(MParList *pList)
    214185{
    215 
    216   fUsedEvents    = 0;
    217   fIsFirstPedRun = kTRUE;
    218   fIsNotPedRun   = kFALSE;
    219  
    220   fTrigPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern");
    221   if (!fTrigPattern)
    222     *fLog << inf << "MTriggerPattern not found... Cannot use interlaced pedestal events." << endl;
    223 
    224   return MExtractPedestal::PreProcess(pList);
     186    fUsedEvents    = 0;
     187    fIsFirstPedRun = kTRUE;
     188    fIsNotPedRun   = kFALSE;
     189
     190    fTrigPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern");
     191    if (!fTrigPattern)
     192        *fLog << inf << "MTriggerPattern not found... Cannot use interlaced pedestal events." << endl;
     193
     194    return MExtractPedestal::PreProcess(pList);
    225195}
    226196
     
    232202Bool_t MPedCalcPedRun::ReInit(MParList *pList)
    233203{
    234 
    235   if (!MExtractPedestal::ReInit(pList))
    236     return kFALSE;
    237 
    238   CheckExtractionWindow();
    239 
    240   //
    241   // If this is the first ped run, the next run (call to ReInit)
    242   // is not the first anymore
    243   //
    244   switch (fRunHeader->GetRunType())
    245   {
    246   case MRawRunHeader::kRTPedestal:
    247   case MRawRunHeader::kRTMonteCarlo:
    248       fIsFirstPedRun = kFALSE;
    249       fIsNotPedRun   = kFALSE;
    250       return kTRUE;
    251  
    252   case MRawRunHeader::kRTCalibration:
    253       {
    254           TString proj(fRunHeader->GetProjectName());
    255           proj.ToLower();
    256 
    257           // test if a continuous light run has been declared as calibration...
    258           if (proj.Contains("cl"))
    259           {
    260               fIsFirstPedRun = kFALSE;
    261               fIsNotPedRun   = kFALSE;
    262               return kTRUE;
    263           }
    264       }
    265   }
    266 
    267   fIsNotPedRun = kTRUE;
    268 
    269   //
    270   // If this is the first call to ReInit (before reading the first file)
    271   // nothing should be done. It occurs for the case that the first treated
    272   // file is not of pedestal type.
    273   //
    274   if (fIsFirstPedRun)
     204    if (!MExtractPedestal::ReInit(pList))
     205        return kFALSE;
     206
     207    //
     208    // If this is the first ped run, the next run (call to ReInit)
     209    // is not the first anymore
     210    //
     211    switch (fRunHeader->GetRunType())
     212    {
     213    case MRawRunHeader::kRTPedestal:
     214    case MRawRunHeader::kRTMonteCarlo:
     215        fIsFirstPedRun = kFALSE;
     216        fIsNotPedRun   = kFALSE;
     217        return kTRUE;
     218
     219    case MRawRunHeader::kRTCalibration:
     220        {
     221            TString proj(fRunHeader->GetProjectName());
     222            proj.ToLower();
     223
     224            // test if a continuous light run has been declared as calibration...
     225            if (proj.Contains("cl"))
     226            {
     227                fIsFirstPedRun = kFALSE;
     228                fIsNotPedRun   = kFALSE;
     229                return kTRUE;
     230            }
     231        }
     232    }
     233
     234    fIsNotPedRun = kTRUE;
     235
     236    //
     237    // If this is the first call to ReInit (before reading the first file)
     238    // nothing should be done. It occurs for the case that the first treated
     239    // file is not of pedestal type.
     240    //
     241    if (fIsFirstPedRun)
     242        return kTRUE;
     243
     244    //
     245    // In the other case, produce the MPedestalCam to be use the subsequent
     246    // (non-pedestal) events
     247    //
     248    *fLog << inf << "Finalizing pedestal calculations..." << flush;
     249
     250    if (!Finalize())
     251        return kFALSE;
     252
     253    Reset();
     254
    275255    return kTRUE;
    276  
    277   //
    278   // In the other case, produce the MPedestalCam to be use the subsequent
    279   // (non-pedestal) events
    280   //
    281   *fLog << inf << "Finalizing pedestal calculations..." << flush;
    282  
    283   if (!Finalize())
    284     return kFALSE;
    285  
    286   Reset();
    287 
    288   return kTRUE;
    289256}
    290257
     
    300267Int_t MPedCalcPedRun::Calc()
    301268{
    302   if (fIsNotPedRun && !IsPedBitSet())
     269    if (fIsNotPedRun && !IsPedBitSet())
     270        return kTRUE;
     271
     272    fUsedEvents++;
     273
     274    MRawEvtPixelIter pixel(fRawEvt);
     275    while (pixel.Next())
     276    {
     277        const UInt_t idx = pixel.GetPixelId();
     278
     279        if (!CheckVariation(idx))
     280            continue;
     281
     282        //extract pedestal
     283        UInt_t ab[2];
     284        const Float_t sum = fExtractor ?
     285            CalcExtractor(pixel, 0) :
     286            CalcSums(pixel, 0, ab[0], ab[1]);
     287
     288        if (fIntermediateStorage)
     289            (*fPedestalsInter)[idx].Set(sum, 0, 0, fUsedEvents);
     290
     291        const Float_t sqrsum = sum*sum;
     292
     293        fSumx[idx]   += sum;
     294        fSumx2[idx]  += sqrsum;
     295
     296        fSumAB0[idx] += ab[0];
     297        fSumAB1[idx] += ab[1];
     298
     299        if (fUseSpecialPixels)
     300            continue;
     301
     302        const UInt_t aidx   = (*fGeom)[idx].GetAidx();
     303        const UInt_t sector = (*fGeom)[idx].GetSector();
     304
     305        fAreaSumx[aidx]      += sum;
     306        fAreaSumx2[aidx]     += sqrsum;
     307        fSectorSumx[sector]  += sum;
     308        fSectorSumx2[sector] += sqrsum;
     309
     310        fAreaSumAB0[aidx]    += ab[0];
     311        fAreaSumAB1[aidx]    += ab[1];
     312        fSectorSumAB0[aidx]  += ab[0];
     313        fSectorSumAB1[aidx]  += ab[1];
     314    }
     315
     316    fPedestalsOut->SetReadyToSave();
     317
    303318    return kTRUE;
    304  
    305   //  if (fUsedEvents == fNumEventsDump)
    306   //    {
    307   //      *fLog << endl;
    308   //      *fLog << inf << GetDescriptor() << " : Finalize pedestal calculations..." << flush;
    309   //      Finalize();
    310   //      Reset();
    311   //    }
    312  
    313   fUsedEvents++;
    314 
    315   MRawEvtPixelIter pixel(fRawEvt);
    316  
    317   while (pixel.Next())
    318   {
    319       const UInt_t idx = pixel.GetPixelId();
    320 
    321       Float_t sum = 0.;
    322       UInt_t  ab0 = 0;
    323       UInt_t  ab1 = 0;
    324      
    325       if (fExtractor)
    326         CalcExtractor(pixel, sum, (*fPedestalsIn)[idx]);
    327       else
    328         CalcSums(pixel, sum, ab0, ab1);
    329 
    330       fSumx[idx] += sum;
    331 
    332       if (fIntermediateStorage)
    333         (*fPedestalsInter)[idx].Set(sum,0.,0.,fUsedEvents);
    334 
    335       const Float_t sqrsum = sum*sum;
    336 
    337       fSumx2[idx]  += sqrsum;
    338       fSumAB0[idx] += ab0;
    339       fSumAB1[idx] += ab1;
    340 
    341       if (fUseSpecialPixels)
    342         continue;
    343 
    344       const UInt_t aidx   = (*fGeom)[idx].GetAidx();
    345       const UInt_t sector = (*fGeom)[idx].GetSector();     
    346 
    347       fAreaSumx[aidx]      += sum;
    348       fSectorSumx[sector]  += sum;
    349 
    350       fAreaSumx2[aidx]     += sqrsum;
    351       fSectorSumx2[sector] += sqrsum;
    352 
    353       fAreaSumAB0[aidx]    += ab0;
    354       fAreaSumAB1[aidx]    += ab1;
    355      
    356       fSectorSumAB0[aidx]  += ab0;
    357       fSectorSumAB1[aidx]  += ab1;
    358   }
    359  
    360   fPedestalsOut->SetReadyToSave();
    361 
    362   return kTRUE;
    363 }
    364 
    365 
    366 void MPedCalcPedRun::CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped)
    367 {
    368     const Bool_t abflag = pixel.HasABFlag();
    369 
    370     Byte_t *first  = pixel.GetHiGainSamples() + fExtractWinFirst;
    371     Byte_t *logain = pixel.GetLoGainSamples();
    372 
    373     Byte_t  sat = 0;
    374 
    375     Float_t dummy;
    376     fExtractor->FindTimeAndChargeHiGain(first,logain,sum,dummy,dummy,dummy,sat,ped,abflag);
    377 }
    378 
    379 void MPedCalcPedRun::CalcSums(const MRawEvtPixelIter &pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1)
    380 {
    381 
    382   Byte_t *higain = pixel.GetHiGainSamples() + fExtractWinFirst;
    383   Byte_t *ptr = higain;
    384   Byte_t *end = ptr + fExtractWinSize;
    385 
    386   const Bool_t abflag = pixel.HasABFlag();
    387 
    388   Int_t sumi = 0;
    389      
    390   Int_t  cnt = 0;
    391   do
    392   {
    393       sumi += *ptr;
    394       if (!pixel.IsABFlagValid())
    395           continue;
    396 
    397       const Int_t abFlag = (fExtractWinFirst + abflag + cnt) & 0x1;
    398       if (abFlag)
    399           ab1 += *ptr;
    400       else
    401           ab0 += *ptr;
    402 
    403       cnt++;
    404   } while (++ptr != end);
    405 
    406   if (fOverlap != 0)
    407   {
    408       ptr = pixel.GetLoGainSamples();
    409       end = ptr + fOverlap;
    410 
    411       do
    412       {
    413           sumi += *ptr;
    414           if (!pixel.IsABFlagValid())
    415               continue;
    416 
    417           const Int_t abFlag = (fExtractWinFirst + abflag + cnt) & 0x1;
    418           if (abFlag)
    419               ab1 += *ptr;
    420           else
    421               ab0 += *ptr;
    422 
    423           cnt++;
    424       } while (++ptr != end);
    425   }
    426 
    427   sum = (Float_t)sumi;
    428319}
    429320
     
    472363}
    473364
     365//-----------------------------------------------------------------------
     366//
     367// PostProcess MExtractPedestal and call Finalize
     368//
    474369Int_t MPedCalcPedRun::PostProcess()
    475370{
     
    501396}
    502397
     398//-----------------------------------------------------------------------
     399//
    503400void MPedCalcPedRun::Print(Option_t *o) const
    504401{
    505402    MExtractPedestal::Print(o);
    506403
    507     const Int_t last = fExtractor
    508       ? fExtractWinFirst + fExtractor->GetWindowSizeHiGain() -1
    509       : fExtractWinLast;
    510 
    511     *fLog << "ExtractWindow from slice      " << fExtractWinFirst << " to " << last << " incl." << endl;
    512     *fLog << "Num overlap lo-gain slices:   " << fOverlap << endl;
    513404    *fLog << "First pedrun out of sequence: " << (fIsFirstPedRun?"yes":"no") << endl;
    514405    *fLog << "Number of used events so far: " << fUsedEvents << endl;
  • trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h

    r5887 r8151  
    77
    88class MTriggerPattern;
    9 class MRawEvtPixelIter;
    109class MPedestalPix;
    1110
     
    1615    static const UShort_t fgExtractWinSize;   // Extraction Size Hi-Gain (currently set to: 14)
    1716    static const UInt_t   gkFirstRunWithFinalBits; // First Run with pedestal trigger bit at place 3
    18 
    19     UShort_t fOverlap;         // Number of overlapping slices from High-Gain to Low-Gain
    2017
    2118    Bool_t  fIsFirstPedRun;    //! Flag to tell if the first run out of many is used
     
    3229    Int_t  PostProcess();
    3330
    34     void CheckExtractionWindow();
    35     void CalcSums(const MRawEvtPixelIter &pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1);
    36     void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);
     31    //void CheckExtractionWindow();
     32    //UInt_t CalcSums(const MRawEvtPixelIter &pixel, UInt_t &ab0, UInt_t &ab1);
     33    //void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);
    3734
    3835public:
  • trunk/MagicSoft/Mars/mpedestal/Makefile

    r5847 r8151  
    4040           MPedestalCam.cc \
    4141           MPedestalPix.cc \
     42           MHPedestalCor.cc \
     43           MPedestalSubtract.cc \
     44           MPedestalSubtractedEvt.cc \
    4245           MPedCalcFromData.cc
    4346
  • trunk/MagicSoft/Mars/mpedestal/PedestalLinkDef.h

    r5477 r8151  
    1717#pragma link C++ class MPedestalCam+;
    1818#pragma link C++ class MPedestalPix+;
     19#pragma link C++ class MPedestalSubtract+;
     20#pragma link C++ class MPedestalSubtractedEvt+;
    1921#pragma link C++ class MPedCalcFromData+;
    2022
     23#pragma link C++ class MHPedestalCor+;
     24
    2125#endif
Note: See TracChangeset for help on using the changeset viewer.