| 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 figure gives and example of possible inheritance trees. 
 | 
|---|
| 34 | //   An extractor class can inherit from each of the following base classes:
 | 
|---|
| 35 | //    - MExtractor
 | 
|---|
| 36 | //    - MExtractTime
 | 
|---|
| 37 | //    - MExtractTimeAndCharge
 | 
|---|
| 38 | //
 | 
|---|
| 39 | //Begin_Html
 | 
|---|
| 40 | /*
 | 
|---|
| 41 | <img src="images/ExtractorClasses.gif">
 | 
|---|
| 42 | */
 | 
|---|
| 43 | //End_Html
 | 
|---|
| 44 | //
 | 
|---|
| 45 | //   The following variables have to be set by the derived class and 
 | 
|---|
| 46 | //   do not have defaults:
 | 
|---|
| 47 | //   - fNumHiGainSamples
 | 
|---|
| 48 | //   - fNumLoGainSamples
 | 
|---|
| 49 | //   - fSqrtHiGainSamples
 | 
|---|
| 50 | //   - fSqrtLoGainSamples
 | 
|---|
| 51 | //
 | 
|---|
| 52 | // Input Containers:
 | 
|---|
| 53 | //   MRawEvtData
 | 
|---|
| 54 | //   MRawRunHeader
 | 
|---|
| 55 | //   MPedestalCam
 | 
|---|
| 56 | //
 | 
|---|
| 57 | // Output Containers:
 | 
|---|
| 58 | //   MArrivalTimeCam
 | 
|---|
| 59 | //
 | 
|---|
| 60 | //////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 61 | #include "MExtractTime.h"
 | 
|---|
| 62 | 
 | 
|---|
| 63 | #include <fstream>
 | 
|---|
| 64 | 
 | 
|---|
| 65 | #include "MLog.h"
 | 
|---|
| 66 | #include "MLogManip.h"
 | 
|---|
| 67 | 
 | 
|---|
| 68 | #include "MParList.h"
 | 
|---|
| 69 | 
 | 
|---|
| 70 | #include "MRawEvtData.h"
 | 
|---|
| 71 | #include "MRawEvtPixelIter.h"
 | 
|---|
| 72 | #include "MRawRunHeader.h"
 | 
|---|
| 73 | 
 | 
|---|
| 74 | #include "MPedestalCam.h"
 | 
|---|
| 75 | #include "MPedestalPix.h"
 | 
|---|
| 76 | 
 | 
|---|
| 77 | #include "MArrivalTimeCam.h"
 | 
|---|
| 78 | #include "MArrivalTimePix.h"
 | 
|---|
| 79 | 
 | 
|---|
| 80 | ClassImp(MExtractTime);
 | 
|---|
| 81 | 
 | 
|---|
| 82 | using namespace std;
 | 
|---|
| 83 | 
 | 
|---|
| 84 | const TString MExtractTime::fgNameTimeCam   = "MArrivalTimeCam";
 | 
|---|
| 85 | // --------------------------------------------------------------------------
 | 
|---|
| 86 | //
 | 
|---|
| 87 | // Default constructor. 
 | 
|---|
| 88 | //
 | 
|---|
| 89 | // Set: 
 | 
|---|
| 90 | // - all pointers to NULL
 | 
|---|
| 91 | // - all variables to 0
 | 
|---|
| 92 | // - fSaturationLimit to fgSaturationLimit
 | 
|---|
| 93 | // - fNameTimeCam to fgNameTimeCam
 | 
|---|
| 94 | //
 | 
|---|
| 95 | // Call:
 | 
|---|
| 96 | // -  AddToBranchList("MRawEvtData.*")
 | 
|---|
| 97 | //
 | 
|---|
| 98 | MExtractTime::MExtractTime(const char *name, const char *title)
 | 
|---|
| 99 |   : fArrTime(NULL)
 | 
|---|
| 100 | {
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   fName  = name  ? name  : "MExtractTime";
 | 
|---|
| 103 |   fTitle = title ? title : "Base class for signal extractors";
 | 
|---|
| 104 |   
 | 
|---|
| 105 |   SetNameTimeCam();
 | 
|---|
| 106 | }
 | 
|---|
| 107 | 
 | 
|---|
| 108 | 
 | 
|---|
| 109 | 
 | 
|---|
| 110 | // --------------------------------------------------------------------------
 | 
|---|
| 111 | //
 | 
|---|
| 112 | // The PreProcess searches for the following input containers:
 | 
|---|
| 113 | //  - MRawEvtData
 | 
|---|
| 114 | //  - MRawRunHeader
 | 
|---|
| 115 | //  - MPedestalCam
 | 
|---|
| 116 | //
 | 
|---|
| 117 | // The following output containers are also searched and created if
 | 
|---|
| 118 | // they were not found:
 | 
|---|
| 119 | //
 | 
|---|
| 120 | //  - MArrivalTimeCam
 | 
|---|
| 121 | //
 | 
|---|
| 122 | Int_t MExtractTime::PreProcess(MParList *pList)
 | 
|---|
| 123 | {
 | 
|---|
| 124 |   fArrTime = (MArrivalTimeCam*)pList->FindCreateObj("MArrivalTimeCam",AddSerialNumber(fNameTimeCam));
 | 
|---|
| 125 |   if (!fArrTime)
 | 
|---|
| 126 |       return kFALSE;
 | 
|---|
| 127 | 
 | 
|---|
| 128 |   return PreProcessStd(pList);
 | 
|---|
| 129 | }
 | 
|---|
| 130 | 
 | 
|---|
| 131 | // --------------------------------------------------------------------------
 | 
|---|
| 132 | //
 | 
|---|
| 133 | // The ReInit calls:
 | 
|---|
| 134 | // -  MExtractor::ReInit()
 | 
|---|
| 135 | //
 | 
|---|
| 136 | // Call: 
 | 
|---|
| 137 | // - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
 | 
|---|
| 138 | //                                      fLoGainFirst, fLoGainLast, fNumLoGainSamples);
 | 
|---|
| 139 | //
 | 
|---|
| 140 | Bool_t MExtractTime::ReInit(MParList *pList)
 | 
|---|
| 141 | {
 | 
|---|
| 142 |     if (!MExtractor::ReInit(pList))
 | 
|---|
| 143 |         return kFALSE;
 | 
|---|
| 144 | 
 | 
|---|
| 145 |     if (fArrTime)
 | 
|---|
| 146 |       fArrTime->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fLoGainFirst, fLoGainLast);
 | 
|---|
| 147 | 
 | 
|---|
| 148 |     return kTRUE;
 | 
|---|
| 149 | }
 | 
|---|
| 150 | 
 | 
|---|
| 151 | // --------------------------------------------------------------------------
 | 
|---|
| 152 | //
 | 
|---|
| 153 | // Calculate the integral of the FADC time slices and store them as a new
 | 
|---|
| 154 | // pixel in the MArrivalTimeCam container.
 | 
|---|
| 155 | //
 | 
|---|
| 156 | Int_t MExtractTime::Process()
 | 
|---|
| 157 | {
 | 
|---|
| 158 | 
 | 
|---|
| 159 | 
 | 
|---|
| 160 |   MRawEvtPixelIter pixel(fRawEvt);
 | 
|---|
| 161 | 
 | 
|---|
| 162 |   while (pixel.Next())
 | 
|---|
| 163 |     {
 | 
|---|
| 164 |       //
 | 
|---|
| 165 |       // Find signal in hi- and lo-gain
 | 
|---|
| 166 |       //
 | 
|---|
| 167 |       Float_t timehi=0., deltatimehi=0.;
 | 
|---|
| 168 |       Byte_t sathi=0;
 | 
|---|
| 169 | 
 | 
|---|
| 170 |       const Int_t pixid = pixel.GetPixelId();
 | 
|---|
| 171 |       const MPedestalPix  &ped = (*fPedestals)[pixid];
 | 
|---|
| 172 |       MArrivalTimePix &pix = (*fArrTime)[pixid];
 | 
|---|
| 173 | 
 | 
|---|
| 174 |       FindTimeHiGain(pixel.GetHiGainSamples()+fHiGainFirst, timehi, deltatimehi, sathi, ped);
 | 
|---|
| 175 | 
 | 
|---|
| 176 |       Float_t timelo=0., deltatimelo=0.;
 | 
|---|
| 177 |       Byte_t satlo=0;
 | 
|---|
| 178 | 
 | 
|---|
| 179 |       if ((sathi)&&pixel.HasLoGain())
 | 
|---|
| 180 |           FindTimeLoGain(pixel.GetLoGainSamples()+fLoGainFirst, timelo, deltatimelo, satlo, ped);
 | 
|---|
| 181 | 
 | 
|---|
| 182 |       pix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
 | 
|---|
| 183 |       pix.SetGainSaturation(sathi, sathi, satlo);
 | 
|---|
| 184 |  
 | 
|---|
| 185 |     } /* while (pixel.Next()) */
 | 
|---|
| 186 | 
 | 
|---|
| 187 |     fArrTime->SetReadyToSave();
 | 
|---|
| 188 | 
 | 
|---|
| 189 |     return kTRUE;
 | 
|---|
| 190 | }
 | 
|---|
| 191 | 
 | 
|---|
| 192 | void MExtractTime::Print(Option_t *o) const
 | 
|---|
| 193 | {
 | 
|---|
| 194 |     if (IsA()==MExtractTime::Class())
 | 
|---|
| 195 |         *fLog << GetDescriptor() << ":" << endl;
 | 
|---|
| 196 |     *fLog << " Offset Lo-Gain:     " << fOffsetLoGain << endl;
 | 
|---|
| 197 |     MExtractor::Print(o);
 | 
|---|
| 198 | }
 | 
|---|