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): Abelardo Moralejo, 4/2004 <mailto:moralejo@pd.infn.it>
|
---|
19 | ! Markus Gaug , 4/2004 <mailto:markus@ifae.es>
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MExtractFixedWindowPeakSearch
|
---|
28 | //
|
---|
29 | // Calculate the signal integrating fWindowSize time slices, the same for
|
---|
30 | // all pixels. The integrated slices change from event to event, since the
|
---|
31 | // pulse positions in the FADC jump between events, but apparently in a
|
---|
32 | // "coherent" fashion. We first loop over all pixels and find the one
|
---|
33 | // which has the highest sum of fPeakSearchWindowSize (default: 4) consecutive
|
---|
34 | // non-saturated high gain slices. The position of the peak in this pixel
|
---|
35 | // determines the integration window position for all pixels of this event.
|
---|
36 | // For the moment we neglect time delays between pixels (which are in most
|
---|
37 | // cases small). The class is based on MExtractSignal2.
|
---|
38 | //
|
---|
39 | //////////////////////////////////////////////////////////////////////////////
|
---|
40 | #include "MExtractFixedWindowPeakSearch.h"
|
---|
41 | #include "MExtractor.h"
|
---|
42 |
|
---|
43 | #include "MLog.h"
|
---|
44 | #include "MLogManip.h"
|
---|
45 |
|
---|
46 | #include "MRawEvtPixelIter.h"
|
---|
47 |
|
---|
48 | #include "MExtractedSignalCam.h"
|
---|
49 | #include "MExtractedSignalPix.h"
|
---|
50 |
|
---|
51 | #include "MPedestalCam.h"
|
---|
52 | #include "MPedestalPix.h"
|
---|
53 |
|
---|
54 | ClassImp(MExtractFixedWindowPeakSearch);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | const Byte_t MExtractFixedWindowPeakSearch::fgHiGainWindowSize = 6;
|
---|
59 | const Byte_t MExtractFixedWindowPeakSearch::fgLoGainWindowSize = 6;
|
---|
60 | const Byte_t MExtractFixedWindowPeakSearch::fgPeakSearchWindowSize = 4;
|
---|
61 | const Byte_t MExtractFixedWindowPeakSearch::fgHiGainFirst = 0;
|
---|
62 | const Byte_t MExtractFixedWindowPeakSearch::fgHiGainLast = 14;
|
---|
63 | const Byte_t MExtractFixedWindowPeakSearch::fgLoGainFirst = 0;
|
---|
64 | const Byte_t MExtractFixedWindowPeakSearch::fgLoGainLast = 14;
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | // Default constructor.
|
---|
68 | //
|
---|
69 | MExtractFixedWindowPeakSearch::MExtractFixedWindowPeakSearch(const char *name, const char *title)
|
---|
70 | {
|
---|
71 |
|
---|
72 | fName = name ? name : "MExtractFixedWindowPeakSearch";
|
---|
73 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
74 |
|
---|
75 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
76 | SetWindows();
|
---|
77 | }
|
---|
78 |
|
---|
79 | void MExtractFixedWindowPeakSearch::SetWindows(Byte_t windowh, Byte_t windowl, Byte_t peaksearchwindow)
|
---|
80 | {
|
---|
81 | //
|
---|
82 | // Set windows to even number of slices due to clock noise (odd/even slice effect).
|
---|
83 | //
|
---|
84 | fWindowSizeHiGain = windowh & ~1;
|
---|
85 | fWindowSizeLoGain = windowl & ~1;
|
---|
86 | fPeakSearchWindowSize = peaksearchwindow & ~1;
|
---|
87 |
|
---|
88 |
|
---|
89 | if (fWindowSizeHiGain != windowh)
|
---|
90 | *fLog << endl << warn <<
|
---|
91 | "MExtractFixedWindowPeakSearch::SetWindows - Hi Gain window size has to be even, set to: "
|
---|
92 | << int(fWindowSizeHiGain) << " samples " << endl;
|
---|
93 |
|
---|
94 | if (fWindowSizeLoGain != windowl)
|
---|
95 | *fLog << endl << warn <<
|
---|
96 | "MExtractFixedWindowPeakSearch::SetWindows - Lo Gain window size has to be even, set to: "
|
---|
97 | << int(fWindowSizeLoGain) << " samples " << endl;
|
---|
98 |
|
---|
99 | if (fPeakSearchWindowSize != peaksearchwindow)
|
---|
100 | *fLog << endl << warn <<
|
---|
101 | "MExtractFixedWindowPeakSearch::SetWindows - Peak Search window size has to be even, set to: "
|
---|
102 | << int(fPeakSearchWindowSize) << " samples " << endl;
|
---|
103 |
|
---|
104 |
|
---|
105 | if (fWindowSizeHiGain<2)
|
---|
106 | {
|
---|
107 | fWindowSizeHiGain = 2;
|
---|
108 | *fLog << warn
|
---|
109 | << "MExtractFixedWindowPeakSearch::SetWindows - Hi Gain window size set to two samples" << endl;
|
---|
110 | }
|
---|
111 |
|
---|
112 | if (fWindowSizeLoGain<2)
|
---|
113 | {
|
---|
114 | fWindowSizeLoGain = 2;
|
---|
115 | *fLog << warn
|
---|
116 | << "MExtractFixedWindowPeakSearch::SetWindows - Lo Gain window size set to two samples" << endl;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (fPeakSearchWindowSize<2)
|
---|
120 | {
|
---|
121 | fPeakSearchWindowSize = 2;
|
---|
122 | *fLog << warn
|
---|
123 | << "MExtractFixedWindowPeakSearch::SetWindows - Peak Search window size set to two samples" << endl;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
|
---|
128 | fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
|
---|
129 |
|
---|
130 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
131 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
132 | }
|
---|
133 |
|
---|
134 | // --------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | // FindPeak
|
---|
137 | // Finds highest sum of "window" consecutive FADC slices in a pixel, and store
|
---|
138 | // in "startslice" the first slice of the group which yields the maximum sum.
|
---|
139 | // In "max" the value of the maximum sum is stored, in "sat" the number of
|
---|
140 | // saturated slices.
|
---|
141 | //
|
---|
142 | void MExtractFixedWindowPeakSearch::FindPeak(Byte_t *ptr, Byte_t window, Byte_t &startslice,
|
---|
143 | Int_t &max, Int_t &sat) const
|
---|
144 | {
|
---|
145 | const Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
|
---|
146 |
|
---|
147 | Int_t sum=0;
|
---|
148 |
|
---|
149 | //
|
---|
150 | // Calculate the sum of the first "window" slices
|
---|
151 | //
|
---|
152 | sat = 0;
|
---|
153 | Byte_t *p = ptr;
|
---|
154 |
|
---|
155 | while (p<ptr+window)
|
---|
156 | {
|
---|
157 | sum += *p;
|
---|
158 | if (*p++ >= fSaturationLimit)
|
---|
159 | sat++;
|
---|
160 | }
|
---|
161 |
|
---|
162 | //
|
---|
163 | // Check for saturation in all other slices
|
---|
164 | //
|
---|
165 | while (p<end)
|
---|
166 | if (*p++ >= fSaturationLimit)
|
---|
167 | sat++;
|
---|
168 |
|
---|
169 | //
|
---|
170 | // Calculate the i-th sum of n as
|
---|
171 | // sum_i+1 = sum_i + slice[i+window] - slice[i]
|
---|
172 | // This is fast and accurate (because we are using int's)
|
---|
173 | //
|
---|
174 | max=sum;
|
---|
175 | for (p=ptr; p+window<end; p++)
|
---|
176 | {
|
---|
177 | sum += *(p+window) - *p;
|
---|
178 | if (sum > max)
|
---|
179 | {
|
---|
180 | max = sum;
|
---|
181 | startslice = p-ptr;
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | return;
|
---|
186 | }
|
---|
187 |
|
---|
188 | // --------------------------------------------------------------------------
|
---|
189 | //
|
---|
190 | // FindSignal
|
---|
191 | // Adds up "window" slices starting in slice to which "ptr" points. The result
|
---|
192 | // is stored in "sum", and the number of saturated slices in "sat".
|
---|
193 | //
|
---|
194 | void MExtractFixedWindowPeakSearch::FindSignalHiGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
|
---|
195 | {
|
---|
196 | //
|
---|
197 | // Calculate the sum of the "window" slices starting in ptr
|
---|
198 | //
|
---|
199 | sum = 0;
|
---|
200 | sat = 0;
|
---|
201 | Byte_t *p = ptr;
|
---|
202 |
|
---|
203 | while (p<ptr+fWindowSizeHiGain)
|
---|
204 | {
|
---|
205 | sum += *p;
|
---|
206 | if (*p++ >= fSaturationLimit)
|
---|
207 | sat++;
|
---|
208 | }
|
---|
209 |
|
---|
210 | return;
|
---|
211 | }
|
---|
212 |
|
---|
213 | // --------------------------------------------------------------------------
|
---|
214 | //
|
---|
215 | // FindSignal
|
---|
216 | // Adds up "window" slices starting in slice to which "ptr" points. The result
|
---|
217 | // is stored in "sum", and the number of saturated slices in "sat".
|
---|
218 | //
|
---|
219 | void MExtractFixedWindowPeakSearch::FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
|
---|
220 | {
|
---|
221 | //
|
---|
222 | // Calculate the sum of the "window" slices starting in ptr
|
---|
223 | //
|
---|
224 | sum = 0;
|
---|
225 | sat = 0;
|
---|
226 | Byte_t *p = ptr;
|
---|
227 |
|
---|
228 | while (p<ptr+fWindowSizeLoGain)
|
---|
229 | {
|
---|
230 | sum += *p;
|
---|
231 | if (*p++ >= fSaturationLimit)
|
---|
232 | sat++;
|
---|
233 | }
|
---|
234 |
|
---|
235 | return;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // --------------------------------------------------------------------------
|
---|
239 | //
|
---|
240 | // Process
|
---|
241 | // First find the pixel with highest sum of fPeakSearchWindowSize slices (default:4)
|
---|
242 | // "startslice" will mark the slice at which the highest sum begins for that pixel.
|
---|
243 | // Then define the beginning of the integration window for ALL pixels as the slice
|
---|
244 | // before that: startslice-1 (this is somehow arbitrary), unless of course startslice=0,
|
---|
245 | // in which case we start at 0. We will also check that the integration window does not
|
---|
246 | // go beyond the FADC limits.
|
---|
247 | //
|
---|
248 | Int_t MExtractFixedWindowPeakSearch::Process()
|
---|
249 | {
|
---|
250 |
|
---|
251 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
252 |
|
---|
253 | Int_t sat;
|
---|
254 | Int_t maxsumhi = 0;
|
---|
255 | Byte_t startslice;
|
---|
256 | Byte_t hiGainFirst = 0;
|
---|
257 | Byte_t loGainFirst = 0;
|
---|
258 |
|
---|
259 | while (pixel.Next())
|
---|
260 | {
|
---|
261 | Int_t sumhi;
|
---|
262 | sat = 0;
|
---|
263 |
|
---|
264 | FindPeak(pixel.GetHiGainSamples(), fPeakSearchWindowSize, startslice, sumhi, sat);
|
---|
265 | if (sumhi > maxsumhi && sat == 0 )
|
---|
266 | {
|
---|
267 | maxsumhi = sumhi;
|
---|
268 | if (startslice > 0)
|
---|
269 | hiGainFirst = startslice-1;
|
---|
270 | else
|
---|
271 | hiGainFirst = 0;
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|
276 | loGainFirst = hiGainFirst;
|
---|
277 |
|
---|
278 | // Make sure we will not integrate beyond the hi gain limit:
|
---|
279 | if (hiGainFirst+fWindowSizeHiGain > pixel.GetNumHiGainSamples())
|
---|
280 | hiGainFirst = pixel.GetNumHiGainSamples()-fWindowSizeHiGain;
|
---|
281 |
|
---|
282 | // Make sure we will not integrate beyond the lo gain limit:
|
---|
283 | if (loGainFirst+fWindowSizeLoGain > pixel.GetNumLoGainSamples())
|
---|
284 | loGainFirst = pixel.GetNumLoGainSamples()-fWindowSizeLoGain;
|
---|
285 |
|
---|
286 | pixel.Reset();
|
---|
287 | fSignals->Clear();
|
---|
288 |
|
---|
289 | sat = 0;
|
---|
290 | while (pixel.Next())
|
---|
291 | {
|
---|
292 | //
|
---|
293 | // Find signal in hi- and lo-gain
|
---|
294 | //
|
---|
295 | Int_t sumhi;
|
---|
296 | Byte_t sathi;
|
---|
297 |
|
---|
298 | FindSignalHiGain(pixel.GetHiGainSamples()+hiGainFirst, sumhi, sathi);
|
---|
299 |
|
---|
300 | Int_t sumlo=0;
|
---|
301 | Byte_t satlo=0;
|
---|
302 | if (pixel.HasLoGain())
|
---|
303 | {
|
---|
304 | FindSignalLoGain(pixel.GetLoGainSamples()+loGainFirst, sumlo, satlo);
|
---|
305 | if (satlo)
|
---|
306 | sat++;
|
---|
307 | }
|
---|
308 |
|
---|
309 | //
|
---|
310 | // Take corresponding pedestal
|
---|
311 | //
|
---|
312 | const Int_t pixid = pixel.GetPixelId();
|
---|
313 |
|
---|
314 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
315 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
316 |
|
---|
317 | const Float_t pedes = ped.GetPedestal();
|
---|
318 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
319 |
|
---|
320 | //
|
---|
321 | // Set extracted signal with pedestal substracted
|
---|
322 | //
|
---|
323 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
---|
324 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
---|
325 |
|
---|
326 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
327 | } /* while (pixel.Next()) */
|
---|
328 |
|
---|
329 | fSignals->SetReadyToSave();
|
---|
330 |
|
---|
331 | return kTRUE;
|
---|
332 | }
|
---|