| 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 09/2003 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | // //
|
|---|
| 27 | // MExtractSignal //
|
|---|
| 28 | // //
|
|---|
| 29 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 |
|
|---|
| 31 | #include "MExtractSignal.h"
|
|---|
| 32 |
|
|---|
| 33 | #include "MExtractedSignalCam.h"
|
|---|
| 34 | #include "MExtractedSignalPix.h"
|
|---|
| 35 |
|
|---|
| 36 | #include "MPedestalCam.h"
|
|---|
| 37 | #include "MPedestalPix.h"
|
|---|
| 38 |
|
|---|
| 39 | #include "MGeomCam.h"
|
|---|
| 40 |
|
|---|
| 41 | #include "MLog.h"
|
|---|
| 42 | #include "MLogManip.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MParList.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MRawEvtData.h"
|
|---|
| 47 | #include "MRawEvtPixelIter.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "TMath.h"
|
|---|
| 50 |
|
|---|
| 51 | ClassImp(MExtractSignal);
|
|---|
| 52 |
|
|---|
| 53 | using namespace std;
|
|---|
| 54 | // --------------------------------------------------------------------------
|
|---|
| 55 | //
|
|---|
| 56 | // Default constructor.
|
|---|
| 57 | //
|
|---|
| 58 | MExtractSignal::MExtractSignal(/*const Byte_t first, const Byte_t last, const Byte_t logainshift,*/
|
|---|
| 59 | const char *name, const char *title)
|
|---|
| 60 | : /*fNumHiGainSamples(last-first+1), fNumLoGainSamples(last-first+1),*/
|
|---|
| 61 | fSaturationLimit(254)
|
|---|
| 62 | {
|
|---|
| 63 |
|
|---|
| 64 | fName = name ? name : "MExtractSignal";
|
|---|
| 65 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
|---|
| 66 |
|
|---|
| 67 | AddToBranchList("MRawEvtData.*");
|
|---|
| 68 |
|
|---|
| 69 | SetRange();
|
|---|
| 70 | /*
|
|---|
| 71 | fFirst = first;
|
|---|
| 72 | fLoGainFirst = first+logainshift;
|
|---|
| 73 |
|
|---|
| 74 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
|---|
| 75 | fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
|
|---|
| 76 | */
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void MExtractSignal::SetRange(Byte_t first, Byte_t last, Byte_t logainshift)
|
|---|
| 80 | {
|
|---|
| 81 | fNumHiGainSamples = last-first+1;
|
|---|
| 82 | fNumLoGainSamples = last-first+1;
|
|---|
| 83 |
|
|---|
| 84 | fFirst = first;
|
|---|
| 85 | fLoGainFirst = first+logainshift;
|
|---|
| 86 |
|
|---|
| 87 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
|---|
| 88 | fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // --------------------------------------------------------------------------
|
|---|
| 92 | //
|
|---|
| 93 | // The PreProcess searches for the following input containers:
|
|---|
| 94 | // - MRawEvtData
|
|---|
| 95 | // - MPedestalCam
|
|---|
| 96 | //
|
|---|
| 97 | // The following output containers are also searched and created if
|
|---|
| 98 | // they were not found:
|
|---|
| 99 | //
|
|---|
| 100 | // - MExtractedSignalCam
|
|---|
| 101 | //
|
|---|
| 102 | Int_t MExtractSignal::PreProcess(MParList *pList)
|
|---|
| 103 | {
|
|---|
| 104 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 105 | if (!fRawEvt)
|
|---|
| 106 | {
|
|---|
| 107 | *fLog << err << "MRawEvtData not found... aborting." << endl;
|
|---|
| 108 | return kFALSE;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam");
|
|---|
| 113 | if (!fSignals)
|
|---|
| 114 | return kFALSE;
|
|---|
| 115 |
|
|---|
| 116 | fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
|---|
| 117 | if (!fPedestals)
|
|---|
| 118 | {
|
|---|
| 119 | *fLog << err << "MPedestalCam not found... aborting" << endl;
|
|---|
| 120 | return kFALSE;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | return kTRUE;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | // --------------------------------------------------------------------------
|
|---|
| 128 | //
|
|---|
| 129 | // The ReInit searches for the following input containers:
|
|---|
| 130 | // - MRawRunHeader
|
|---|
| 131 | //
|
|---|
| 132 | Bool_t MExtractSignal::ReInit(MParList *pList )
|
|---|
| 133 | {
|
|---|
| 134 | MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 135 | if (!cam)
|
|---|
| 136 | {
|
|---|
| 137 | *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
|
|---|
| 138 | return kFALSE;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | // FIXME: This solution may change in the future, MExtractedSignal
|
|---|
| 142 | // must be similar to MCerPhotEvt not to MPedestalCam
|
|---|
| 143 | // (Have to think about the mean size of both solutions)
|
|---|
| 144 | fSignals->InitSize(cam->GetNumPixels());
|
|---|
| 145 |
|
|---|
| 146 | fSignals->SetNumUsedFADCSlices(fNumHiGainSamples, fFirst, fFirst+fNumHiGainSamples-1,
|
|---|
| 147 | fNumLoGainSamples, fFirst, fFirst+fNumLoGainSamples-1);
|
|---|
| 148 |
|
|---|
| 149 | return kTRUE;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | // --------------------------------------------------------------------------
|
|---|
| 154 | //
|
|---|
| 155 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 156 | // pixel in the MExtractedSignalCam container.
|
|---|
| 157 | //
|
|---|
| 158 | Int_t MExtractSignal::Process()
|
|---|
| 159 | {
|
|---|
| 160 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 161 | fSignals->Clear();
|
|---|
| 162 |
|
|---|
| 163 | while (pixel.Next())
|
|---|
| 164 | {
|
|---|
| 165 | UShort_t satHi = 0;
|
|---|
| 166 | UShort_t satLo = 0;
|
|---|
| 167 |
|
|---|
| 168 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 169 | Byte_t *first = ptr + fFirst;
|
|---|
| 170 | Byte_t *last = ptr + fFirst + fNumHiGainSamples;
|
|---|
| 171 |
|
|---|
| 172 | UInt_t sumHi = 0;
|
|---|
| 173 | UInt_t sumLo = 0;
|
|---|
| 174 |
|
|---|
| 175 | const Int_t pixid = pixel.GetPixelId();
|
|---|
| 176 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 177 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
|---|
| 178 |
|
|---|
| 179 | const Float_t pedes = ped.GetPedestal();
|
|---|
| 180 | const Float_t pedrms = ped.GetPedestalRms();
|
|---|
| 181 |
|
|---|
| 182 | Byte_t maxhi = 0;
|
|---|
| 183 | Byte_t midhi = 0;
|
|---|
| 184 |
|
|---|
| 185 | for (ptr=first;ptr<last;ptr++)
|
|---|
| 186 | {
|
|---|
| 187 |
|
|---|
| 188 | if (*ptr > maxhi)
|
|---|
| 189 | {
|
|---|
| 190 | maxhi = *ptr;
|
|---|
| 191 | midhi = ptr-first;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | sumHi += *ptr;
|
|---|
| 195 |
|
|---|
| 196 | if (*ptr >= fSaturationLimit)
|
|---|
| 197 | satHi++;
|
|---|
| 198 |
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | ptr = pixel.GetLoGainSamples();
|
|---|
| 202 | first = ptr + fLoGainFirst + 1;
|
|---|
| 203 | last = ptr + fLoGainFirst + fNumLoGainSamples +1;
|
|---|
| 204 | Byte_t maxlo = 0;
|
|---|
| 205 | Byte_t midlo = 0;
|
|---|
| 206 |
|
|---|
| 207 | for (ptr=first;ptr<last;ptr++)
|
|---|
| 208 | {
|
|---|
| 209 |
|
|---|
| 210 | if (*ptr > maxlo)
|
|---|
| 211 | {
|
|---|
| 212 | maxlo = *ptr;
|
|---|
| 213 | midlo = ptr-first;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | sumLo += *ptr;
|
|---|
| 217 |
|
|---|
| 218 | if (*ptr >= fSaturationLimit)
|
|---|
| 219 | {
|
|---|
| 220 | *fLog << err << dbginf
|
|---|
| 221 | << "Warning: Saturation of Lo Gain reached in pixel: "
|
|---|
| 222 | << pixid << " " << " sum = " << sumLo << endl;
|
|---|
| 223 | satLo++;
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
|
|---|
| 228 | pedrms*fSqrtHiGainSamples,
|
|---|
| 229 | ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples),
|
|---|
| 230 | pedrms*fSqrtLoGainSamples
|
|---|
| 231 | );
|
|---|
| 232 |
|
|---|
| 233 | pix.SetGainSaturation(satHi, satHi, satLo);
|
|---|
| 234 |
|
|---|
| 235 | // FIXME: Arrival time has to be stored in MArrivalTime!
|
|---|
| 236 | if (satHi)
|
|---|
| 237 | pix.SetArrivalTimes((Float_t)(midlo+fFirst),0.,0.);
|
|---|
| 238 | else
|
|---|
| 239 | pix.SetArrivalTimes((Float_t)(midhi+fLoGainFirst),0.,0.);
|
|---|
| 240 |
|
|---|
| 241 | } /* while (pixel.Next()) */
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 | fSignals->SetReadyToSave();
|
|---|
| 245 |
|
|---|
| 246 | return kTRUE;
|
|---|
| 247 | }
|
|---|