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): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MExtractSignal2
|
---|
29 | //
|
---|
30 | // Calculate the signal as the fWindowSize time slices which have the highest
|
---|
31 | // integral contents.
|
---|
32 | //
|
---|
33 | //
|
---|
34 | //
|
---|
35 | //////////////////////////////////////////////////////////////////////////////
|
---|
36 | #include "MExtractSignal2.h"
|
---|
37 |
|
---|
38 | #include "MLog.h"
|
---|
39 | #include "MLogManip.h"
|
---|
40 |
|
---|
41 | #include "MParList.h"
|
---|
42 |
|
---|
43 | #include "MRawEvtData.h"
|
---|
44 | #include "MRawEvtPixelIter.h"
|
---|
45 |
|
---|
46 | #include "MPedestalCam.h"
|
---|
47 | #include "MPedestalPix.h"
|
---|
48 |
|
---|
49 | #include "MExtractedSignalCam.h"
|
---|
50 | #include "MExtractedSignalPix.h"
|
---|
51 |
|
---|
52 | //#include "MArrivalTime.h"
|
---|
53 |
|
---|
54 | ClassImp(MExtractSignal2);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | const Byte_t MExtractSignal2::fgSaturationLimit = 254;
|
---|
59 | const Byte_t MExtractSignal2::fgFirst = 0;
|
---|
60 | const Byte_t MExtractSignal2::fgLast = 14;
|
---|
61 | const Byte_t MExtractSignal2::fgWindowSize = 6;
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Default constructor.
|
---|
66 | //
|
---|
67 | MExtractSignal2::MExtractSignal2(const char *name, const char *title)
|
---|
68 | : fSaturationLimit(fgSaturationLimit)
|
---|
69 | {
|
---|
70 |
|
---|
71 | fName = name ? name : "MExtractSignal2";
|
---|
72 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
73 |
|
---|
74 | AddToBranchList("MRawEvtData.*");
|
---|
75 |
|
---|
76 | SetRange();
|
---|
77 | }
|
---|
78 |
|
---|
79 | void MExtractSignal2::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t windowh, Byte_t lofirst, Byte_t lolast, Byte_t windowl)
|
---|
80 | {
|
---|
81 |
|
---|
82 | fNumHiGainSamples = hilast-hifirst+1;
|
---|
83 | fNumLoGainSamples = lolast-lofirst+1;
|
---|
84 |
|
---|
85 | fHiGainFirst = hifirst;
|
---|
86 | fLoGainFirst = lofirst;
|
---|
87 |
|
---|
88 | fWindowSizeHiGain = windowh & ~1;
|
---|
89 | fWindowSizeLoGain = windowl & ~1;
|
---|
90 |
|
---|
91 | if (fWindowSizeHiGain != windowh)
|
---|
92 | *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size has to be even, set to: "
|
---|
93 | << int(fWindowSizeHiGain) << " samples " << endl;
|
---|
94 |
|
---|
95 | if (fWindowSizeLoGain != windowl)
|
---|
96 | *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size has to be even, set to: "
|
---|
97 | << int(fWindowSizeLoGain) << " samples " << endl;
|
---|
98 |
|
---|
99 | if (fWindowSizeHiGain<2)
|
---|
100 | {
|
---|
101 | fWindowSizeHiGain = 2;
|
---|
102 | *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size set to two samples" << endl;
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (fWindowSizeLoGain<2)
|
---|
106 | {
|
---|
107 | fWindowSizeLoGain = 2;
|
---|
108 | *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size set to two samples" << endl;
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (fWindowSizeHiGain > fNumHiGainSamples)
|
---|
112 | {
|
---|
113 | fWindowSizeHiGain = fNumHiGainSamples & ~1;
|
---|
114 | *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size set to "
|
---|
115 | << int(fWindowSizeHiGain) << " samples " << endl;
|
---|
116 | }
|
---|
117 |
|
---|
118 | if (fWindowSizeLoGain > fNumLoGainSamples)
|
---|
119 | {
|
---|
120 | fWindowSizeLoGain = fNumLoGainSamples & ~1;
|
---|
121 | *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size set to "
|
---|
122 | << int(fWindowSizeLoGain) << " samples " << endl;
|
---|
123 | }
|
---|
124 |
|
---|
125 | fWindowSqrtHiGain = TMath::Sqrt((Float_t)fWindowSizeHiGain);
|
---|
126 | fWindowSqrtLoGain = TMath::Sqrt((Float_t)fWindowSizeLoGain);
|
---|
127 |
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 | // --------------------------------------------------------------------------
|
---|
133 | //
|
---|
134 | // The PreProcess searches for the following input containers:
|
---|
135 | // - MRawEvtData
|
---|
136 | // - MPedestalCam
|
---|
137 | //
|
---|
138 | // The following output containers are also searched and created if
|
---|
139 | // they were not found:
|
---|
140 | //
|
---|
141 | // - MExtractedSignalCam
|
---|
142 | //
|
---|
143 | Int_t MExtractSignal2::PreProcess(MParList *pList)
|
---|
144 | {
|
---|
145 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
146 | if (!fRawEvt)
|
---|
147 | {
|
---|
148 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
149 | return kFALSE;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
---|
154 | if (!fSignals)
|
---|
155 | return kFALSE;
|
---|
156 |
|
---|
157 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1, (Float_t)fWindowSizeHiGain,
|
---|
158 | fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1, (Float_t)fWindowSizeLoGain);
|
---|
159 |
|
---|
160 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
161 | if (!fPedestals)
|
---|
162 | {
|
---|
163 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
164 | return kFALSE;
|
---|
165 | }
|
---|
166 | /*
|
---|
167 | fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
|
---|
168 | if (!fArrivalTime)
|
---|
169 | return kFALSE;
|
---|
170 | */
|
---|
171 | return kTRUE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | void MExtractSignal2::FindSignal(Byte_t *ptr, Byte_t size, Byte_t window, Int_t &max, Int_t &sat) const
|
---|
175 | {
|
---|
176 | const Byte_t *end = ptr + size;
|
---|
177 |
|
---|
178 | Int_t sum=0;
|
---|
179 |
|
---|
180 | //
|
---|
181 | // Calculate the sum of the first fWindowSize slices
|
---|
182 | //
|
---|
183 | sat = 0;
|
---|
184 | Byte_t *p = ptr;
|
---|
185 | while (p<ptr+window)
|
---|
186 | {
|
---|
187 | sum += *p;
|
---|
188 | if (*p++ >= fSaturationLimit)
|
---|
189 | sat++;
|
---|
190 | }
|
---|
191 |
|
---|
192 | //
|
---|
193 | // Check for saturation in all other slices
|
---|
194 | //
|
---|
195 | while (p<end)
|
---|
196 | if (*p++ >= fSaturationLimit)
|
---|
197 | sat++;
|
---|
198 |
|
---|
199 | //
|
---|
200 | // Calculate the i-th sum as
|
---|
201 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
---|
202 | // This is fast and accurate (because we are using int's)
|
---|
203 | //
|
---|
204 | max=sum;
|
---|
205 | for (p=ptr; p+window<end; p++)
|
---|
206 | {
|
---|
207 | sum += *(p+window) - *p;
|
---|
208 | if (sum>max)
|
---|
209 | max = sum;
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | // --------------------------------------------------------------------------
|
---|
214 | //
|
---|
215 | // Calculate the integral of the FADC of fWindowSize time slices which have the
|
---|
216 | // highest signal
|
---|
217 | //
|
---|
218 | Int_t MExtractSignal2::Process()
|
---|
219 | {
|
---|
220 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
221 | fSignals->Clear();
|
---|
222 |
|
---|
223 | Int_t sat=0;
|
---|
224 | while (pixel.Next())
|
---|
225 | {
|
---|
226 | //
|
---|
227 | // Find signal in hi- and lo-gain
|
---|
228 | //
|
---|
229 | Int_t sumhi, sathi;
|
---|
230 | FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, fWindowSizeHiGain, sumhi, sathi);
|
---|
231 |
|
---|
232 | Int_t sumlo=0;
|
---|
233 | Int_t satlo=0;
|
---|
234 | if (pixel.HasLoGain())
|
---|
235 | {
|
---|
236 | FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, fWindowSizeLoGain, sumlo, satlo);
|
---|
237 | if (satlo)
|
---|
238 | sat++;
|
---|
239 | }
|
---|
240 |
|
---|
241 | //
|
---|
242 | // Take correspodning pedestal
|
---|
243 | //
|
---|
244 | const Int_t pixid = pixel.GetPixelId();
|
---|
245 |
|
---|
246 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
247 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
248 |
|
---|
249 | const Float_t pedes = ped.GetPedestal();
|
---|
250 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
251 |
|
---|
252 | //
|
---|
253 | // Set extracted signal with pedestal substracted
|
---|
254 | //
|
---|
255 | pix.SetExtractedSignal(sumhi - pedes*fWindowSizeHiGain, pedrms*fWindowSqrtHiGain,
|
---|
256 | sumlo - pedes*fWindowSizeLoGain, pedrms*fWindowSqrtLoGain);
|
---|
257 |
|
---|
258 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
259 | } /* while (pixel.Next()) */
|
---|
260 |
|
---|
261 | //
|
---|
262 | // Print a warning if evant has saturationg lo-gains
|
---|
263 | //
|
---|
264 | if (sat)
|
---|
265 | *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
|
---|
266 |
|
---|
267 | fSignals->SetReadyToSave();
|
---|
268 |
|
---|
269 | return kTRUE;
|
---|
270 | }
|
---|