source: trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.cc@ 4384

Last change on this file since 4384 was 4340, checked in by gaug, 21 years ago
*** empty log message ***
File size: 10.6 KB
Line 
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 analyzing 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! Author(s): Markus Gaug 05/2004 <mailto:markus@ifae.es>
18!
19! Copyright: MAGIC Software Development, 2002-2004
20!
21!
22\* ======================================================================== */
23
24//////////////////////////////////////////////////////////////////////////////
25//
26// MExtractTimeAndChargeSpline
27//
28// Fast Spline extractor using a cubic spline algorithm of Numerical Recipes.
29// It returns the integral below the interpolating spline.
30//
31// Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
32// to modify the ranges. Ranges have to be an even number. In case of odd
33// ranges, the last slice will be reduced by one.
34//
35// Defaults are:
36//
37// fHiGainFirst = fgHiGainFirst = 3
38// fHiGainLast = fgHiGainLast = 14
39// fLoGainFirst = fgLoGainFirst = 3
40// fLoGainLast = fgLoGainLast = 14
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MExtractFixedWindowSpline.h"
44
45#include "MExtractedSignalCam.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50ClassImp(MExtractFixedWindowSpline);
51
52using namespace std;
53
54const Byte_t MExtractFixedWindowSpline::fgHiGainFirst = 2;
55const Byte_t MExtractFixedWindowSpline::fgHiGainLast = 14;
56const Byte_t MExtractFixedWindowSpline::fgLoGainFirst = 3;
57const Byte_t MExtractFixedWindowSpline::fgLoGainLast = 14;
58// --------------------------------------------------------------------------
59//
60// Default constructor.
61//
62// Calls:
63// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
64//
65MExtractFixedWindowSpline::MExtractFixedWindowSpline(const char *name, const char *title)
66 : fHiGainFirstDeriv(NULL), fLoGainFirstDeriv(NULL),
67 fHiGainSecondDeriv(NULL), fLoGainSecondDeriv(NULL)
68{
69
70 fName = name ? name : "MExtractFixedWindowSpline";
71 fTitle = title ? title : "Signal Extractor for a fixed FADC window using a fast spline";
72
73 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
74}
75
76MExtractFixedWindowSpline::~MExtractFixedWindowSpline()
77{
78
79 if (fHiGainFirstDeriv)
80 delete fHiGainFirstDeriv;
81 if (fLoGainFirstDeriv)
82 delete fLoGainFirstDeriv;
83 if (fHiGainSecondDeriv)
84 delete fHiGainSecondDeriv;
85 if (fLoGainSecondDeriv)
86 delete fLoGainSecondDeriv;
87
88}
89
90// --------------------------------------------------------------------------
91//
92// SetRange:
93//
94// Checks:
95// - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
96// - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
97// - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
98// - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
99//
100// Calls:
101// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
102//
103// Sets:
104// - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
105// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
106// - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
107// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
108//
109void MExtractFixedWindowSpline::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
110{
111
112 const Byte_t windowhi = hilast-hifirst+1;
113 const Byte_t windowlo = lolast-lofirst+1;
114
115 const Byte_t whieven = windowhi & ~1;
116 const Byte_t wloeven = windowlo & ~1;
117
118 if (whieven != windowhi)
119 {
120 *fLog << warn << GetDescriptor()
121 << Form("%s%2i%s%2i",": Hi Gain window size has to be even, set last slice from "
122 ,(int)hilast," to ",(int)(hilast-1)) << endl;
123 hilast -= 1;
124 }
125
126 if (wloeven != windowlo)
127 {
128 *fLog << warn << GetDescriptor()
129 << Form("%s%2i%s%2i",": Lo Gain window size has to be even, set last slice from "
130 ,(int)lolast," to ",(int)(lolast-1)) << endl;
131 lolast -= 1;
132 }
133
134 if (whieven<2)
135 {
136 *fLog << warn << GetDescriptor()
137 << Form("%s%2i%s%2i",": Hi Gain window is smaller than 2 FADC sampes, set last slice from"
138 ,(int)hilast," to ",(int)(hifirst+1)) << endl;
139 hilast = hifirst+1;
140 }
141
142 if (wloeven<2)
143 {
144 *fLog << warn << GetDescriptor()
145 << Form("%s%2i%s%2i",": Lo Gain window is smaller than 2 FADC sampes, set last slice from"
146 ,(int)lolast," to ",(int)(lofirst+1)) << endl;
147 lolast = lofirst+1;
148 }
149
150
151 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
152
153 //
154 // Very important: Because the spline interpolates between the slice,
155 // the number of samples for the pedestal subtraction
156 // is now 1 less than with e.g. MExtractFixedWindow
157 //
158 fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst);
159 fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst);
160
161 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
162 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
163
164}
165
166// --------------------------------------------------------------------------
167//
168// ReInit
169//
170// Calls:
171// - MExtractor::ReInit(pList);
172// - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
173// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
174//
175// Deletes all arrays, if not NULL
176// Creates new arrays according to the extraction range
177//
178Bool_t MExtractFixedWindowSpline::ReInit(MParList *pList)
179{
180
181 if (!MExtractor::ReInit(pList))
182 return kFALSE;
183
184 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
185 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
186
187 if (fHiGainFirstDeriv)
188 delete fHiGainFirstDeriv;
189 if (fLoGainFirstDeriv)
190 delete fLoGainFirstDeriv;
191 if (fHiGainSecondDeriv)
192 delete fHiGainSecondDeriv;
193 if (fLoGainSecondDeriv)
194 delete fLoGainSecondDeriv;
195
196 Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
197
198 fHiGainFirstDeriv = new Float_t[range];
199 memset(fHiGainFirstDeriv,0,range*sizeof(Float_t));
200 fHiGainSecondDeriv = new Float_t[range];
201 memset(fHiGainSecondDeriv,0,range*sizeof(Float_t));
202
203 range = fLoGainLast - fLoGainFirst + 1;
204
205 fLoGainFirstDeriv = new Float_t[range];
206 memset(fLoGainFirstDeriv,0,range*sizeof(Float_t));
207 fLoGainSecondDeriv = new Float_t[range];
208 memset(fLoGainSecondDeriv,0,range*sizeof(Float_t));
209
210 return kTRUE;
211}
212
213
214// --------------------------------------------------------------------------
215//
216// FindSignalHiGain:
217//
218// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
219// - Sum up contents of *ptr
220// - If *ptr is greater than fSaturationLimit, raise sat by 1
221//
222// - If fHiLoLast is not 0, loop also from logain to (logain+fHiLoLast)
223// - Sum up contents of logain
224// - If *logain is greater than fSaturationLimit, raise sat by 1
225//
226void MExtractFixedWindowSpline::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
227{
228
229 const Byte_t *end = ptr + fHiGainLast - fHiGainFirst;
230 Int_t range = fHiGainLast - fHiGainFirst + fHiLoLast + 1;
231
232 Float_t pp;
233 Int_t i = 0;
234
235 fHiGainSecondDeriv[0] = 0.;
236 fHiGainFirstDeriv[0] = 0.;
237
238 Int_t summ = 0;
239 sum = (Float_t)*ptr++/2.;
240 //
241 // Check for saturation in all other slices
242 //
243 while (ptr<end)
244 {
245
246 summ += *ptr;
247 i++;
248
249 pp = fHiGainSecondDeriv[i-1] + 4.;
250 fHiGainSecondDeriv[i] = -1.0/pp;
251 fHiGainFirstDeriv [i] = *(ptr+1) - 2.* *(ptr) + *(ptr-1);
252 fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
253
254 if (*ptr++ >= fSaturationLimit)
255 sat++;
256 }
257
258 if (*ptr++ >= fSaturationLimit)
259 sat++;
260
261 if (fHiLoLast == 0)
262 {
263 sum += (Float_t)*ptr/2.;
264 fHiGainSecondDeriv[++i] = 0.;
265
266 }
267 else
268 {
269 summ += *ptr;
270 i++;
271
272 pp = fHiGainSecondDeriv[i-1] + 4.;
273 fHiGainSecondDeriv[i] = -1.0/pp;
274 fHiGainFirstDeriv [i] = *(logain) - 2.* *(ptr) + *(ptr-1);
275 fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
276
277 end = logain + fHiLoLast - 1;
278
279 while (logain<end)
280 {
281
282 summ += *logain;
283 i++;
284
285 pp = fHiGainSecondDeriv[i-1] + 4.;
286 fHiGainSecondDeriv[i] = -1.0/pp;
287 fHiGainFirstDeriv [i] = *(logain+1) - 2.* *(logain) + *(ptr-1);
288 fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
289
290 if (*logain++ >= fSaturationLimit)
291 sat++;
292
293 }
294 sum += (Float_t)*logain/2;
295 fHiGainSecondDeriv[++i] = 0.;
296 }
297
298 for (Int_t k=range-2;k>0;k--)
299 {
300 fHiGainSecondDeriv[k] = fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k];
301 sum += 0.25*fHiGainSecondDeriv[k];
302 }
303
304 sum += (Float_t)summ;
305}
306
307// --------------------------------------------------------------------------
308//
309// FindSignalLoGain:
310//
311// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
312// - Sum up contents of *ptr
313// - If *ptr is greater than fSaturationLimit, raise sat by 1
314//
315void MExtractFixedWindowSpline::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
316{
317
318 const Byte_t *end = ptr + fLoGainLast - fLoGainFirst;
319 Int_t range = fLoGainLast - fLoGainFirst + 1;
320
321 Float_t pp;
322 Int_t i = 0;
323
324 fLoGainSecondDeriv[0] = 0.;
325 fLoGainFirstDeriv[0] = 0.;
326
327 Int_t summ = 0;
328 sum = (Float_t)*ptr++/2.;
329 //
330 // Check for saturation in all other slices
331 //
332 while (ptr<end)
333 {
334
335 summ += *ptr;
336 i++;
337
338 pp = fLoGainSecondDeriv[i-1] + 4.;
339 fLoGainSecondDeriv[i] = -1.0/pp;
340 fLoGainFirstDeriv [i] = *(ptr+1) - 2.* *(ptr) + *(ptr-1);
341 fLoGainFirstDeriv [i] = (6.0*fLoGainFirstDeriv[i]-fLoGainFirstDeriv[i-1])/pp;
342
343 if (*ptr++ >= fSaturationLimit)
344 sat++;
345 }
346
347 if (*ptr++ >= fSaturationLimit)
348 sat++;
349
350 sum += (Float_t)*ptr/2.;
351 fLoGainSecondDeriv[++i] = 0.;
352
353 for (Int_t k=range-2;k>0;k--)
354 {
355 fLoGainSecondDeriv[k] = fLoGainSecondDeriv[k]*fLoGainSecondDeriv[k+1] + fLoGainFirstDeriv[k];
356 sum += 0.25*fLoGainSecondDeriv[k];
357 }
358
359 sum += (Float_t)summ;
360}
361
Note: See TracBrowser for help on using the repository browser.