1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.5 2007-05-14 09:53: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)
|
---|
108 | {
|
---|
109 | *fLog << inf << "Pedestals given by pointer will be subtracted." << endl;
|
---|
110 | return kTRUE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | if (fNamePedestalCam.IsNull())
|
---|
114 | {
|
---|
115 | *fLog << inf << "No name for MPedestalCam given, pedestal subtraction will be skipped." << endl;
|
---|
116 | return kTRUE;
|
---|
117 | }
|
---|
118 |
|
---|
119 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
|
---|
120 | if (!fPedestals)
|
---|
121 | {
|
---|
122 | *fLog << err << AddSerialNumber(fNamePedestalCam) << " [MPedestalCam] not found... aborting" << endl;
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | *fLog << inf << "Pedestals " << fNamePedestalCam << " will be subtracted." << endl;
|
---|
127 |
|
---|
128 | return kTRUE;
|
---|
129 | }
|
---|
130 |
|
---|
131 | // --------------------------------------------------------------------------
|
---|
132 | //
|
---|
133 | //
|
---|
134 | Int_t MPedestalSubtract::Process()
|
---|
135 | {
|
---|
136 | // Total number of samples
|
---|
137 | const Int_t numh = fRawEvt->GetNumHiGainSamples();
|
---|
138 | const Int_t numl = fRawEvt->GetNumLoGainSamples();
|
---|
139 |
|
---|
140 | // initialize fSignal
|
---|
141 | fSignal->InitSamples(numh+numl);//, fRawEvt->GetNumPixels(), numh+numl);
|
---|
142 |
|
---|
143 | // iterate over all pixels
|
---|
144 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
145 | while (pixel.Next())
|
---|
146 | {
|
---|
147 | // Get index ofthis pixel
|
---|
148 | const Int_t pixidx = pixel.GetPixelId();
|
---|
149 |
|
---|
150 | if (pixidx>=fSignal->GetNumPixels())
|
---|
151 | {
|
---|
152 | *fLog << err << "ERROR - Pixel index " << pixidx << " out of bounds... abort." << endl;
|
---|
153 | return kERROR;
|
---|
154 | }
|
---|
155 | // Get pointer were to store merged raw data
|
---|
156 | Byte_t *sample = fSignal->GetSamplesRaw(pixidx);
|
---|
157 |
|
---|
158 | // copy hi- and lo-gains samples together
|
---|
159 | memcpy(sample, pixel.GetHiGainSamples(), numh);
|
---|
160 | memcpy(sample+numh, pixel.GetLoGainSamples(), numl);
|
---|
161 |
|
---|
162 | // start of destination array, end of hi-gain destination array
|
---|
163 | // and start of hi-gain samples
|
---|
164 | Float_t *beg = fSignal->GetSamples(pixidx);
|
---|
165 | Float_t *end = beg + fSignal->GetNumSamples();
|
---|
166 |
|
---|
167 | const Byte_t *src = sample;
|
---|
168 |
|
---|
169 | // if no pedestals are given just convert the data into
|
---|
170 | // floats and we are finished
|
---|
171 | if (!fPedestals)
|
---|
172 | {
|
---|
173 | while (beg<end)
|
---|
174 | *beg++ = *src++;
|
---|
175 | continue;
|
---|
176 | }
|
---|
177 |
|
---|
178 | // get pedestal information for this pixel
|
---|
179 | const MPedestalPix &pedpix = (*fPedestals)[pixidx];
|
---|
180 |
|
---|
181 | // pedestal information
|
---|
182 | const Int_t ab = pixel.HasABFlag() ? 1 : 0;
|
---|
183 | const Float_t ped = pedpix.GetPedestal();
|
---|
184 |
|
---|
185 | // determine with which pedestal (+/- AB offset) to start
|
---|
186 | const Bool_t swap = (ab&1)==1;
|
---|
187 | const Float_t offh = swap ? -pedpix.GetPedestalABoffset() : pedpix.GetPedestalABoffset();
|
---|
188 | const Float_t mean[2] = { ped + offh, ped - offh };
|
---|
189 |
|
---|
190 | // Copy hi-gains into array and substract pedestal
|
---|
191 | // FIXME: Shell we really subtract the pedestal from saturating slices???
|
---|
192 | for (Float_t *ptr=beg; ptr<end; ptr++)
|
---|
193 | *ptr = (Float_t)*src++ - mean[(ptr-beg)&1];
|
---|
194 | }
|
---|
195 |
|
---|
196 | return kTRUE;
|
---|
197 | }
|
---|