Changeset 3948 for trunk


Ignore:
Timestamp:
05/03/04 17:32:06 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r3942 r3948  
    1 #ifndef MARS_MExtractTime
    2 #define MARS_MExtractTime
    3 
    4 #ifndef MARS_MExtractor
    5 #include "MExtractor.h"
    6 #endif
    7 
    8 class MPedestalPix;
    9 class MArrivalTimeCam;
    10 class MExtractTime : public MExtractor
    11 {
    12  
    13   MArrivalTimeCam *fArrTime;   // Container with the photons arrival times
    14  
    15   virtual Int_t PreProcess(MParList *pList);
    16   virtual Bool_t ReInit(MParList *pList);
    17   virtual Int_t Process();
    18 
    19   virtual void FindTimeHiGain(Byte_t *firstused, Float_t &time, Float_t &dtime,
    20                               Byte_t &sat, const MPedestalPix &ped) const;
    21   virtual void FindTimeLoGain(Byte_t *firstused, Float_t &time, Float_t &dtime,
    22                               Byte_t &sat, const MPedestalPix &ped) const;
    23 
    24 public:
    25 
    26   MExtractTime(const char *name=NULL, const char *title=NULL);
     1/* ======================================================================== *\
     2!
     3! *
     4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     5! * Software. It is distributed to you in the hope that it can be a useful
     6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     7! * It is distributed WITHOUT ANY WARRANTY.
     8! *
     9! * Permission to use, copy, modify and distribute this software and its
     10! * documentation for any purpose is hereby granted without fee,
     11! * provided that the above copyright notice appear in all copies and
     12! * that both that copyright notice and this permission notice appear
     13! * in supporting documentation. It is provided "as is" without express
     14! * or implied warranty.
     15! *
     16!
     17!
     18!   Author(s): Markus Gaug, 04/2004 <mailto:markus@ifae.es>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2004
     21!
     22!
     23\* ======================================================================== */
     24
     25//////////////////////////////////////////////////////////////////////////////
     26//
     27//   MExtractTime
     28//
     29//   Base class for the signal extractors, used the functions
     30//   FindTimeHiGain() and FindTimeLoGain() to extract the signal and
     31//   substract the pedestal value   
     32//
     33//   The following variables have to be set by the derived class and
     34//   do not have defaults:
     35//   - fNumHiGainSamples
     36//   - fNumLoGainSamples
     37//   - fSqrtHiGainSamples
     38//   - fSqrtLoGainSamples
     39//
     40// Input Containers:
     41//   MRawEvtData
     42//   MRawRunHeader
     43//   MPedestalCam
     44//
     45// Output Containers:
     46//   MArrivalTimeCam
     47//
     48//////////////////////////////////////////////////////////////////////////////
     49#include "MExtractTime.h"
     50
     51#include <fstream>
     52
     53#include "MLog.h"
     54#include "MLogManip.h"
     55
     56#include "MParList.h"
     57
     58#include "MRawEvtData.h"
     59#include "MRawEvtPixelIter.h"
     60#include "MRawRunHeader.h"
     61
     62#include "MPedestalCam.h"
     63#include "MPedestalPix.h"
     64
     65#include "MArrivalTimeCam.h"
     66#include "MArrivalTimePix.h"
     67
     68ClassImp(MExtractTime);
     69
     70using namespace std;
     71
     72// --------------------------------------------------------------------------
     73//
     74// Default constructor.
     75//
     76// Set:
     77// - all pointers to NULL
     78// - all variables to 0
     79// - fSaturationLimit to fgSaturationLimit
     80//
     81// Call:
     82// -  AddToBranchList("MRawEvtData.*")
     83//
     84MExtractTime::MExtractTime(const char *name, const char *title)
     85    : fArrTime(NULL)
     86{
     87
     88    fName  = name  ? name  : "MExtractTime";
     89    fTitle = title ? title : "Base class for signal extractors";
     90
     91}
     92
     93
     94
     95// --------------------------------------------------------------------------
     96//
     97// The PreProcess searches for the following input containers:
     98//  - MRawEvtData
     99//  - MRawRunHeader
     100//  - MPedestalCam
     101//
     102// The following output containers are also searched and created if
     103// they were not found:
     104//
     105//  - MArrivalTimeCam
     106//
     107Int_t MExtractTime::PreProcess(MParList *pList)
     108{
     109
     110  fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
     111  if (!fRawEvt)
     112    {
     113        *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
     114        return kFALSE;
     115    }
     116 
     117  fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
     118  if (!fRunHeader)
     119    {
     120      *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
     121      return kFALSE;
     122    }
     123 
     124 
     125  fArrTime = (MArrivalTimeCam*)pList->FindCreateObj(AddSerialNumber("MArrivalTimeCam"));
     126  if (!fArrTime)
     127    return kFALSE;
     128 
     129
     130  fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
     131  if (!fPedestals)
     132    {
     133      *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
     134      return kFALSE;
     135    }
     136 
     137  return kTRUE;
     138}
     139
     140// --------------------------------------------------------------------------
     141//
     142// The ReInit searches for:
     143// -  MRawRunHeader::GetNumSamplesHiGain()
     144// -  MRawRunHeader::GetNumSamplesLoGain()
     145//
     146// In case that the variable fLoGainLast is smaller than
     147// the even part of the number of samples obtained from the run header, a
     148// warning is given an the range is set back accordingly. A call to: 
     149// - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
     150// is performed in that case. The variable diff means here the difference
     151// between the requested range (fLoGainLast) and the available one. Note that
     152// the functions SetRange() are mostly overloaded and perform more checks,
     153// modifying the ranges again, if necessary.
     154//
     155// In case that the variable fHiGainLast is smaller than the available range
     156// obtained from the run header, a warning is given that a part of the low-gain
     157// samples are used for the extraction of the high-gain signal.
     158//
     159// Call:
     160// - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
     161//                                          fLoGainFirst, fLoGainLast, fNumLoGainSamples);
     162//
     163Bool_t MExtractTime::ReInit(MParList *pList)
     164{
     165 
     166  Int_t lastdesired   = (Int_t)(fLoGainLast);
     167  Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
     168 
     169  if (lastdesired > lastavailable)
     170    {
     171      const Int_t diff = lastdesired - lastavailable;
     172      *fLog << endl;
     173      *fLog << warn << GetDescriptor()
     174            << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [",
     175                    (int)fLoGainFirst,",",lastdesired,
     176                    "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
     177      *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
     178      SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
     179    }
     180
     181  lastdesired   = (Int_t)fHiGainLast;
     182  lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
     183 
     184  if (lastdesired > lastavailable)
     185    {
     186      const Int_t diff = lastdesired - lastavailable;
     187      *fLog << endl;
     188      *fLog << warn << GetDescriptor()
     189            << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
     190                    (int)fHiGainFirst,",",lastdesired,
     191                    "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
     192      *fLog << warn << GetDescriptor()
     193            << Form("%s%2i%s",": Will use ",diff," samples from the Low-Gain for the High-Gain extraction")
     194            << endl;
     195      fHiGainLast -= diff;
     196      fHiLoLast    = diff;
     197    }
     198
     199
     200  fArrTime->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fLoGainFirst, fLoGainLast);
     201
     202  return kTRUE;
     203}
     204
     205
     206
     207void MExtractTime::FindTimeHiGain(Byte_t *firstused, Float_t &time, Float_t &dtime,
     208                                  Byte_t &sat, const MPedestalPix &ped) const
     209{
     210  return;
     211}
     212
     213void MExtractTime::FindTimeLoGain(Byte_t *firstused, Float_t &time, Float_t &dtime,
     214                                  Byte_t &sat, const MPedestalPix &ped) const
     215{
     216  return;
     217}
     218
     219// --------------------------------------------------------------------------
     220//
     221// Calculate the integral of the FADC time slices and store them as a new
     222// pixel in the MArrivalTimeCam container.
     223//
     224Int_t MExtractTime::Process()
     225{
     226
     227
     228  MRawEvtPixelIter pixel(fRawEvt);
     229  fArrTime->Clear();
     230
     231  while (pixel.Next())
     232    {
     233      //
     234      // Find signal in hi- and lo-gain
     235      //
     236      Float_t timehi=0., deltatimehi=0.;
     237      Byte_t sathi=0;
     238
     239      const Int_t pixid = pixel.GetPixelId();
     240      const MPedestalPix  &ped = (*fPedestals)[pixid];
     241      MArrivalTimePix &pix = (*fArrTime)[pixid];
     242
     243      FindTimeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, timehi, deltatimehi, sathi, ped);
     244
     245      Float_t timelo=0., deltatimelo=0.;
     246      Byte_t satlo=0;
     247
     248      if (pixel.HasLoGain())
     249        FindTimeLoGain(pixel.GetLoGainSamples()+fLoGainFirst, timelo, deltatimelo, satlo, ped);
     250     
     251      pix.SetArrivalTime(timehi, deltatimehi, timelo, deltatimelo);
     252      pix.SetGainSaturation(sathi, sathi, satlo);
    27253 
    28   ClassDef(MExtractTime, 0)   // Arrival Time Extractor Base Class
    29 };
    30 
    31 #endif
    32 
    33 
    34 
     254    } /* while (pixel.Next()) */
     255
     256    fArrTime->SetReadyToSave();
     257
     258    return kTRUE;
     259}
     260
Note: See TracChangeset for help on using the changeset viewer.