| 1 | /* ======================================================================== *\
|
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.4 2007-01-15 12:06:15 tbretz Exp $
|
|---|
| 3 | ! --------------------------------------------------------------------------
|
|---|
| 4 | !
|
|---|
| 5 | ! *
|
|---|
| 6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 10 | ! *
|
|---|
| 11 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 12 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 13 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 14 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 15 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 16 | ! * or implied warranty.
|
|---|
| 17 | ! *
|
|---|
| 18 | !
|
|---|
| 19 | !
|
|---|
| 20 | ! Author(s): Thomas Bretz, 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 21 | !
|
|---|
| 22 | ! Copyright: MAGIC Software Development, 2000-2006
|
|---|
| 23 | !
|
|---|
| 24 | !
|
|---|
| 25 | \* ======================================================================== */
|
|---|
| 26 |
|
|---|
| 27 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 28 | //
|
|---|
| 29 | // MPedestalSubtract
|
|---|
| 30 | //
|
|---|
| 31 | // This class merges hi- and lo-gain samples into one array and
|
|---|
| 32 | // subtracts the pedestal (including the AB-offset) from the
|
|---|
| 33 | // data and stores the result in MPedestalSubtractedEvt.
|
|---|
| 34 | //
|
|---|
| 35 | // Input Containers:
|
|---|
| 36 | // MRawEvtData
|
|---|
| 37 | // MRawRunHeader
|
|---|
| 38 | // MPedestalCam
|
|---|
| 39 | //
|
|---|
| 40 | // Output Containers:
|
|---|
| 41 | // MPedestalSubtractedEvt
|
|---|
| 42 | //
|
|---|
| 43 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 44 | #include "MPedestalSubtract.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MParList.h"
|
|---|
| 50 |
|
|---|
| 51 | #include "MArrayB.h"
|
|---|
| 52 |
|
|---|
| 53 | #include "MRawEvtData.h"
|
|---|
| 54 | #include "MRawEvtPixelIter.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MPedestalCam.h"
|
|---|
| 57 | #include "MPedestalPix.h"
|
|---|
| 58 |
|
|---|
| 59 | #include "MPedestalSubtractedEvt.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MExtractedSignalCam.h"
|
|---|
| 62 | #include "MExtractedSignalPix.h"
|
|---|
| 63 |
|
|---|
| 64 | ClassImp(MPedestalSubtract);
|
|---|
| 65 |
|
|---|
| 66 | using namespace std;
|
|---|
| 67 |
|
|---|
| 68 | const TString MPedestalSubtract::fgNamePedestalCam = "MPedestalCam";
|
|---|
| 69 | const TString MPedestalSubtract::fgNamePedestalSubtractedEvt = "MPedestalSubtractedEvt";
|
|---|
| 70 |
|
|---|
| 71 | // --------------------------------------------------------------------------
|
|---|
| 72 | //
|
|---|
| 73 | // Default constructor.
|
|---|
| 74 | //
|
|---|
| 75 | MPedestalSubtract::MPedestalSubtract(const char *name, const char *title)
|
|---|
| 76 | : fRawEvt(NULL), fPedestals(NULL), fSignal(NULL)
|
|---|
| 77 | {
|
|---|
| 78 | fName = name ? name : "MPedestalSubtract";
|
|---|
| 79 | fTitle = title ? title : "Class to subtract pedestal";
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | // --------------------------------------------------------------------------
|
|---|
| 83 | //
|
|---|
| 84 | // The PreProcess searches for the following input containers:
|
|---|
| 85 | // - MRawEvtData
|
|---|
| 86 | // - MRawRunHeader
|
|---|
| 87 | // - MPedestalCam
|
|---|
| 88 | //
|
|---|
| 89 | // The following output containers are also searched and created if
|
|---|
| 90 | // they were not found:
|
|---|
| 91 | //
|
|---|
| 92 | // - MPedestalSubtractedEvt
|
|---|
| 93 | //
|
|---|
| 94 | Int_t MPedestalSubtract::PreProcess(MParList *pList)
|
|---|
| 95 | {
|
|---|
| 96 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 97 | if (!fRawEvt)
|
|---|
| 98 | {
|
|---|
| 99 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 100 | return kFALSE;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | fSignal = (MPedestalSubtractedEvt*)pList->FindCreateObj("MPedestalSubtractedEvt");//, AddSerialNumber(fNamePedestalSubtractedEvt));
|
|---|
| 104 | if (!fSignal)
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 |
|
|---|
| 107 | if (fPedestals || fNamePedestalCam.IsNull())
|
|---|
| 108 | return kTRUE;
|
|---|
| 109 |
|
|---|
| 110 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
|
|---|
| 111 | if (!fPedestals)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << err << AddSerialNumber(fNamePedestalCam) << " [MPedestalCam] not found... aborting" << endl;
|
|---|
| 114 | return kFALSE;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | return kTRUE;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // --------------------------------------------------------------------------
|
|---|
| 121 | //
|
|---|
| 122 | //
|
|---|
| 123 | Int_t MPedestalSubtract::Process()
|
|---|
| 124 | {
|
|---|
| 125 | // Total number of samples
|
|---|
| 126 | const Int_t numh = fRawEvt->GetNumHiGainSamples();
|
|---|
| 127 | const Int_t numl = fRawEvt->GetNumLoGainSamples();
|
|---|
| 128 |
|
|---|
| 129 | // initialize fSignal
|
|---|
| 130 | fSignal->InitSamples(numh+numl);//, fRawEvt->GetNumPixels(), numh+numl);
|
|---|
| 131 |
|
|---|
| 132 | // iterate over all pixels
|
|---|
| 133 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 134 | while (pixel.Next())
|
|---|
| 135 | {
|
|---|
| 136 | // Get index ofthis pixel
|
|---|
| 137 | const Int_t pixidx = pixel.GetPixelId();
|
|---|
| 138 |
|
|---|
| 139 | if (pixidx>=fSignal->GetNumPixels())
|
|---|
| 140 | {
|
|---|
| 141 | *fLog << err << "ERROR - Pixel index " << pixidx << " out of bounds... abort." << endl;
|
|---|
| 142 | return kERROR;
|
|---|
| 143 | }
|
|---|
| 144 | // Get pointer were to store merged raw data
|
|---|
| 145 | Byte_t *sample = fSignal->GetSamplesRaw(pixidx);
|
|---|
| 146 |
|
|---|
| 147 | // copy hi- and lo-gains samples together
|
|---|
| 148 | memcpy(sample, pixel.GetHiGainSamples(), numh);
|
|---|
| 149 | memcpy(sample+numh, pixel.GetLoGainSamples(), numl);
|
|---|
| 150 |
|
|---|
| 151 | // start of destination array, end of hi-gain destination array
|
|---|
| 152 | // and start of hi-gain samples
|
|---|
| 153 | Float_t *beg = fSignal->GetSamples(pixidx);
|
|---|
| 154 | Float_t *end = beg + fSignal->GetNumSamples();
|
|---|
| 155 |
|
|---|
| 156 | const Byte_t *src = sample;
|
|---|
| 157 |
|
|---|
| 158 | // if no pedestals are given just convert the data into
|
|---|
| 159 | // floats and we are finished
|
|---|
| 160 | if (!fPedestals)
|
|---|
| 161 | {
|
|---|
| 162 | while (beg<end)
|
|---|
| 163 | *beg++ = *src++;
|
|---|
| 164 | continue;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | // get pedestal information for this pixel
|
|---|
| 168 | const MPedestalPix &pedpix = (*fPedestals)[pixidx];
|
|---|
| 169 |
|
|---|
| 170 | // pedestal information
|
|---|
| 171 | const Int_t ab = pixel.HasABFlag() ? 1 : 0;
|
|---|
| 172 | const Float_t ped = pedpix.GetPedestal();
|
|---|
| 173 |
|
|---|
| 174 | // determine with which pedestal (+/- AB offset) to start
|
|---|
| 175 | const Bool_t swap = (ab&1)==1;
|
|---|
| 176 | const Float_t offh = swap ? -pedpix.GetPedestalABoffset() : pedpix.GetPedestalABoffset();
|
|---|
| 177 | const Float_t mean[2] = { ped + offh, ped - offh };
|
|---|
| 178 |
|
|---|
| 179 | // Copy hi-gains into array and substract pedestal
|
|---|
| 180 | // FIXME: Shell we really subtract the pedestal from saturating slices???
|
|---|
| 181 | for (Float_t *ptr=beg; ptr<end; ptr++)
|
|---|
| 182 | *ptr = (Float_t)*src++ - mean[(ptr-beg)&1];
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | return kTRUE;
|
|---|
| 186 | }
|
|---|