Ignore:
Timestamp:
04/30/04 15:47:11 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/msignal
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc

    r3322 r3911  
    2727//   MExtractPINDiode
    2828//
     29//  Extracts the signal from a fixed window in a given range.
     30//
     31//  Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
     32//  to modify the ranges. Ranges have to be an even number. In case of odd
     33//  ranges, the last slice will be reduced by one.
     34//  Defaults are:
     35//
     36//   fHiGainFirst =  fgHiGainFirst =  3
     37//   fHiGainLast  =  fgHiGainLast  =  14
     38//   fLoGainFirst =  fgLoGainFirst =  3
     39//   fLoGainLast  =  fgLoGainLast  =  14
     40//
    2941//////////////////////////////////////////////////////////////////////////////
    3042#include "MExtractPINDiode.h"
     43#include "MExtractor.h"
    3144
    3245#include <fstream>
     
    4962using namespace std;
    5063
    51 const UInt_t MExtractPINDiode::fgPINDiodeIdx     = 1;
    52 const Byte_t MExtractPINDiode::fgSaturationLimit = 254;
    53 const Byte_t MExtractPINDiode::fgFirst =  1;
    54 const Byte_t MExtractPINDiode::fgLast  = 30;
    55 
     64const UInt_t MExtractPINDiode::fgPINDiodeIdx     = 100;
     65const Byte_t MExtractPINDiode::fgHiGainFirst =  0;
     66const Byte_t MExtractPINDiode::fgHiGainLast  =  14;
     67const Byte_t MExtractPINDiode::fgLoGainFirst =  0;
     68const Byte_t MExtractPINDiode::fgLoGainLast  =  14;
    5669// --------------------------------------------------------------------------
    5770//
    5871// Default constructor.
    5972//
     73// Calls:
     74// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
     75// - SetPINDiodeIdx()
     76//
    6077MExtractPINDiode::MExtractPINDiode(const char *name, const char *title)
    61     : fSaturationLimit(fgSaturationLimit)
    6278{
    6379 
     
    6581  fTitle = title ? title : "Task to extract the signal from the FADC slices";
    6682 
    67   AddToBranchList("MRawEvtData.*");
    68  
     83  SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
    6984  SetPINDiodeIdx();
    70   SetSaturationLimit();
    71   SetRange();
    72 }
    73 
    74 void MExtractPINDiode::SetRange(Byte_t first, Byte_t last)
    75 {
    76 
    77     fNumSamples = last-first+1;
    78     fFirst      = first;
    79     fLast       = last;
    80 
    81     fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
    82 }
    83 
    84 // --------------------------------------------------------------------------
    85 //
    86 // The PreProcess searches for the following input containers:
    87 //  - MRawEvtData
    88 //  - MPedestalCam
     85}
     86
     87// --------------------------------------------------------------------------
     88//
     89// SetRange:
     90//
     91// Checks:
     92// - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
     93// - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
     94// - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
     95// - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
     96//
     97// Calls:
     98// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
     99//
     100// Sets:
     101// - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
     102// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
     103// - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
     104// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples) 
     105// 
     106void MExtractPINDiode::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
     107{
     108
     109  const Byte_t window = hilast-hifirst+1+lolast-lofirst+1;
     110  const Byte_t weven  = window & ~1;
     111
     112  if (weven != window)
     113    {
     114      *fLog << warn << GetDescriptor()
     115            << Form("%s%2i%s%2i",": Total window size has to be even, set last slice from "
     116                    ,(int)lolast," to ",(int)(lolast-1)) << endl;
     117      lolast -= 1;
     118    }
     119 
     120  if (window<2)
     121    {
     122      *fLog << warn << GetDescriptor()
     123            << Form("%s%2i%s%2i",": Total window is smaller than 2 FADC sampes, set last slice from"
     124                    ,(int)lolast," to ",(int)(lofirst+1)) << endl;
     125      hilast = hifirst+1;
     126    }
     127 
     128
     129  MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
     130
     131  fNumSamples = fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1;
     132  fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
     133 
     134}
     135
     136// --------------------------------------------------------------------------
     137//
     138// Calls:
     139// - MExtractor::PreProcess
    89140//
    90141// The following output containers are also searched and created if
     
    95146Int_t MExtractPINDiode::PreProcess(MParList *pList)
    96147{
    97     fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
    98     if (!fRawEvt)
    99     {
    100         *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
    101         return kFALSE;
    102     }
    103 
    104 
    105     fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
    106     if (!fPINDiode)
    107         return kFALSE;
    108 
    109     fPINDiode->SetUsedFADCSlices(fFirst, fLast);
    110 
    111     fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
    112 
    113     if (!fPedestals)
    114     {
    115         *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
    116         return kFALSE;
    117     }
    118 
    119     const MPedestalPix &ped   = (*fPedestals)[fPINDiodeIdx];
     148
     149  if (!MExtractor::PreProcess(pList))
     150    return kFALSE;
     151 
     152  fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
     153  if (!fPINDiode)
     154    return kFALSE;
     155
     156  fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
     157
     158  const MPedestalPix &ped   = (*fPedestals)[fPINDiodeIdx];
    120159
    121160    if (&ped)
     
    134173}
    135174
    136 void MExtractPINDiode::FindSignal(Byte_t *ptr, Int_t size, UInt_t &sum, UInt_t &sum2, UInt_t &sat, UInt_t &max) const
    137 {
    138 
    139   Byte_t *end = ptr + size;
    140  
     175void MExtractPINDiode::FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
     176{
     177
     178  Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
     179
    141180  while (ptr<end)
    142181    {
    143182      sum  += *ptr;
    144183      sum2 += *ptr * *ptr;
    145       if (*ptr > max)
    146         max = *ptr;
     184
     185      if (*ptr++ >= fSaturationLimit)
     186        sat++;
     187    }
     188}
     189
     190void MExtractPINDiode::FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
     191{
     192
     193  Byte_t *end = ptr +  fLoGainLast - fLoGainFirst  + 1;
     194
     195  while (ptr<end)
     196    {
     197      sum  += *ptr;
     198      sum2 += *ptr * *ptr;
    147199     
    148200      if (*ptr++ >= fSaturationLimit)
     
    151203}
    152204
     205
     206
    153207// --------------------------------------------------------------------------
    154208//
     
    159213{
    160214
    161     MRawEvtPixelIter pixel(fRawEvt);
    162 
    163     fPINDiode->Clear();
    164 
    165     pixel.Jump(fPINDiodeIdx);
    166  
    167     UInt_t sum  = 0;
    168     UInt_t sum2 = 0;
    169     UInt_t sat  = 0;
    170     UInt_t max  = 0;
    171 
    172     FindSignal(pixel.GetHiGainSamples()+fFirst-1,
    173                fRawEvt->GetNumHiGainSamples(),
    174                sum, sum2, sat, max);
    175     FindSignal(pixel.GetLoGainSamples(),
    176                fLast-fRawEvt->GetNumLoGainSamples(),
    177                sum, sum2, sat, max);
    178    
    179 
    180     const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
    181     const Float_t rms = TMath::Sqrt(var);
    182    
    183     //
    184     // FIXME: The following formulae have to be revised!!
    185     //
    186     fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
    187     fPINDiode->SetExtractedRms   (rms, rms/2./fSqrtSamples);
    188     fPINDiode->SetExtractedTime  (max, rms/fSqrtSamples);
    189     fPINDiode->SetSaturation(sat);
    190 
    191     if (sat)
    192       *fLog << warn << "WARNING - saturation occurred in the PIN Diode " << endl;
    193 
    194     fPINDiode->SetReadyToSave();
    195 
    196     return kTRUE;
     215
     216  MRawEvtPixelIter pixel(fRawEvt);
     217 
     218  fPINDiode->Clear();
     219 
     220  pixel.Jump(fPINDiodeIdx);
     221 
     222  Int_t sum   = 0;
     223  Int_t sum2  = 0;
     224  Byte_t sat  = 0;
     225  Int_t max   = 0;
     226 
     227  //
     228  // Calculate first the time:
     229  //
     230  const Int_t maxhi = pixel.GetIdxMaxHiGainSample();
     231  const Int_t maxlo = pixel.GetIdxMaxLoGainSample();
     232 
     233  if (maxhi > maxlo)
     234    max = maxhi;
     235  else
     236    max = maxlo + pixel.GetNumHiGainSamples();
     237 
     238  FindSignalandVarianceHiGain(pixel.GetHiGainSamples()+fHiGainFirst,sum,sum2,sat);
     239  FindSignalandVarianceLoGain(pixel.GetLoGainSamples()+fLoGainFirst,sum,sum2,sat);
     240
     241  const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
     242  const Float_t rms = TMath::Sqrt(var);
     243 
     244  //
     245  // FIXME: The following formulae have to be revised!!
     246  //
     247  fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
     248  fPINDiode->SetExtractedRms   (rms, rms/2./fSqrtSamples);
     249  fPINDiode->SetExtractedTime  (max, rms/fSqrtSamples);
     250  fPINDiode->SetSaturation(sat);
     251  fPINDiode->SetReadyToSave();
     252 
     253  return kTRUE;
    197254}
    198255
     
    214271    }
    215272
    216     const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
    217     const Bool_t arg1 = arg2 || fFirst != fgFirst;
     273    const Bool_t arg2 = fNumSamples+fHiGainFirst-1 != fgLoGainLast;
     274    const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
    218275
    219276    if (!arg1)
     
    221278
    222279    out << "   " << GetUniqueName() << ".SetRange(";
    223     out << (int)fFirst;
     280    out << (int)fHiGainFirst;
    224281    if (arg2)
    225       out << ", " << (int)(fNumSamples+fFirst-1);
     282      out << ", " << (int)(fNumSamples+fHiGainFirst-1);
    226283    out << ");" << endl;
    227284}
  • trunk/MagicSoft/Mars/msignal/MExtractPINDiode.h

    r3322 r3911  
    1111/////////////////////////////////////////////////////////////////////////////
    1212
    13 #ifndef MARS_MTask
    14 #include "MTask.h"
     13#ifndef MARS_MExtractor
     14#include "MExtractor.h"
    1515#endif
    1616
    17 class MRawEvtData;
    18 class MRawRunHeader;
    19 
    20 class MPedestalCam;
    2117class MExtractedSignalPINDiode;
    22 class MExtractPINDiode : public MTask
     18class MExtractPINDiode : public MExtractor
    2319{
    2420private:
    2521
    2622  static const UInt_t fgPINDiodeIdx; 
    27   static const Byte_t fgSaturationLimit;
    28   static const Byte_t fgFirst;
    29   static const Byte_t fgLast;
     23  static const Byte_t fgHiGainFirst;     // First FADC slice Hi-Gain (currently set to: 3)
     24  static const Byte_t fgHiGainLast;      // Last FADC slice Hi-Gain (currently set to: 14)
     25  static const Byte_t fgLoGainFirst;     // First FADC slice Lo-Gain (currently set to: 3)
     26  static const Byte_t fgLoGainLast;      // Last FADC slice Lo-Gain (currently set to: 14)
    3027
    31   MPedestalCam              *fPedestals;    // Pedestals of all pixels in the camera
    3228  MExtractedSignalPINDiode  *fPINDiode;     // Extracted signal of the PIN Diode
    3329
    34   MRawEvtData         *fRawEvt;       // raw event data (time slices)
    35   MRawRunHeader       *fRunHeader;    // RunHeader information
    36  
    37   Byte_t  fFirst;
    38   Byte_t  fLast;
    39   Byte_t  fNumSamples;
    40   Float_t fSqrtSamples;
    41   Byte_t  fSaturationLimit;
    4230  UInt_t  fPINDiodeIdx;
    43 
    4431  Float_t fPedestal;
    4532  Float_t fPedRms;
     33  Int_t   fNumSamples;
     34  Float_t fSqrtSamples;
    4635 
    47   void   FindSignal(Byte_t *ptr, Int_t size, UInt_t &sum, UInt_t &sum2, UInt_t &sat, UInt_t &max) const;
    48  
     36  void   FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const;
     37  void   FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const;
     38
    4939  Int_t  PreProcess(MParList *pList);
    5040  Int_t  Process();
     
    5646
    5747  // Setters
    58   void SetRange(const Byte_t hifirst=fgFirst,
    59                 const Byte_t hilast=fgLast);
    60   void SetSaturationLimit(const Byte_t lim=fgSaturationLimit) { fSaturationLimit = lim; }
     48  void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
    6149  void SetPINDiodeIdx(    const UInt_t idx=fgPINDiodeIdx    ) { fPINDiodeIdx     = idx; }   
    6250
    63   ClassDef(MExtractPINDiode, 0) // Task to fill the Extracted PINDiode Containers from raw data
     51  ClassDef(MExtractPINDiode, 0) // Signal Extractor for the PIN Diode
    6452};
    6553
Note: See TracChangeset for help on using the changeset viewer.