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): Markus Gaug, 02/2004 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MExtractBlindPixel
|
---|
28 | //
|
---|
29 | // Extracts the signal from a fixed window in a given range.
|
---|
30 | //
|
---|
31 | // Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
|
---|
32 | // to modify the ranges. The "low-gain" ranges are used for the NSB rejection
|
---|
33 | // whereas the high-gain ranges for blind pixel signal extraction. "High-gain"
|
---|
34 | // ranges can extend to the slices stored as "low-gain" in MRawEvtPixelIter
|
---|
35 | //
|
---|
36 | // Defaults are:
|
---|
37 | //
|
---|
38 | // fHiGainFirst = fgHiGainFirst = 10
|
---|
39 | // fHiGainLast = fgHiGainLast = 29
|
---|
40 | // fLoGainFirst = fgLoGainFirst = 0
|
---|
41 | // fLoGainLast = fgLoGainLast = 7
|
---|
42 | //
|
---|
43 | // The switches:
|
---|
44 | // - SetExtractionType ( kAmplitude ) and SetExtractionType ( kIntegral )
|
---|
45 | // can be used to choose between amplitude extraction (using a spline) and
|
---|
46 | // summed integral.
|
---|
47 | // - SetExtractionType ( kFilter )
|
---|
48 | // can be used to apply a filter discarding events passing over a threshold
|
---|
49 | // defined in fNSBFilterLimit
|
---|
50 | //
|
---|
51 | //////////////////////////////////////////////////////////////////////////////
|
---|
52 | #include "MExtractBlindPixel.h"
|
---|
53 |
|
---|
54 | #include "MLog.h"
|
---|
55 | #include "MLogManip.h"
|
---|
56 |
|
---|
57 | #include "MParList.h"
|
---|
58 |
|
---|
59 | #include "MRawEvtData.h"
|
---|
60 | #include "MRawRunHeader.h"
|
---|
61 | #include "MRawEvtPixelIter.h"
|
---|
62 |
|
---|
63 | #include "MExtractedSignalBlindPixel.h"
|
---|
64 |
|
---|
65 | #include "MPedestalCam.h"
|
---|
66 | #include "MPedestalPix.h"
|
---|
67 |
|
---|
68 | ClassImp(MExtractBlindPixel);
|
---|
69 |
|
---|
70 | using namespace std;
|
---|
71 |
|
---|
72 | const UInt_t MExtractBlindPixel::fgBlindPixelIdx = 559;
|
---|
73 | const Byte_t MExtractBlindPixel::fgHiGainFirst = 10;
|
---|
74 | const Byte_t MExtractBlindPixel::fgHiGainLast = 19;
|
---|
75 | const Byte_t MExtractBlindPixel::fgLoGainFirst = 0;
|
---|
76 | const Byte_t MExtractBlindPixel::fgLoGainLast = 7;
|
---|
77 | const Int_t MExtractBlindPixel::fgNSBFilterLimit = 70;
|
---|
78 | const Float_t MExtractBlindPixel::fgResolution = 0.003;
|
---|
79 | const Float_t MExtractBlindPixel::gkOverflow = 300.;
|
---|
80 | // --------------------------------------------------------------------------
|
---|
81 | //
|
---|
82 | // Default constructor.
|
---|
83 | //
|
---|
84 | // Initializes:
|
---|
85 | // - fBlindPixelIdx to fgBlindPixelIdx
|
---|
86 | // - fNSBFilterLimit to fgNSBFilterLimit
|
---|
87 | // - fResolution to fgResolution
|
---|
88 | // - fExtractionType to 0.
|
---|
89 | //
|
---|
90 | // Calls:
|
---|
91 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
92 | //
|
---|
93 | MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title)
|
---|
94 | : fHiGainSignal(NULL),
|
---|
95 | fHiGainFirstDeriv(NULL),
|
---|
96 | fHiGainSecondDeriv(NULL),
|
---|
97 | fDataType(0)
|
---|
98 | {
|
---|
99 |
|
---|
100 | fName = name ? name : "MExtractBlindPixel";
|
---|
101 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
102 |
|
---|
103 | // AddToBranchList("MRawEvtData.*");
|
---|
104 | // AddToBranchList("MRawEvtData2.*");
|
---|
105 |
|
---|
106 | SetResolution();
|
---|
107 | SetNSBFilterLimit();
|
---|
108 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
109 |
|
---|
110 | SetNumBlindPixels();
|
---|
111 |
|
---|
112 | Clear();
|
---|
113 |
|
---|
114 | }
|
---|
115 |
|
---|
116 | // --------------------------------------------------------------------------
|
---|
117 | //
|
---|
118 | // Destructor:
|
---|
119 | //
|
---|
120 | // - Deletes, (if not NULL):
|
---|
121 | // fHiGainSignal;
|
---|
122 | // fHiGainFirstDeriv;
|
---|
123 | // fHiGainSecondDeriv;
|
---|
124 | //
|
---|
125 | MExtractBlindPixel::~MExtractBlindPixel()
|
---|
126 | {
|
---|
127 |
|
---|
128 | if (fHiGainSignal)
|
---|
129 | delete [] fHiGainSignal;
|
---|
130 | if (fHiGainFirstDeriv)
|
---|
131 | delete [] fHiGainFirstDeriv;
|
---|
132 | if (fHiGainSecondDeriv)
|
---|
133 | delete [] fHiGainSecondDeriv;
|
---|
134 |
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Clear
|
---|
140 | //
|
---|
141 | // Initializes:
|
---|
142 | // - fBlindPixelIdx to 0
|
---|
143 | // - fExtractionType to 0
|
---|
144 | //
|
---|
145 | // Calls:
|
---|
146 | // - SetBlindPixelIdx()
|
---|
147 | //
|
---|
148 | // Deletes and sets to NULL (if exists):
|
---|
149 | // - fHiGainSignal
|
---|
150 | // - fHiGainFirstDeriv
|
---|
151 | // - fHiGainSecondDeriv
|
---|
152 | //
|
---|
153 | void MExtractBlindPixel::Clear( const Option_t *o)
|
---|
154 | {
|
---|
155 |
|
---|
156 | fExtractionType = 0;
|
---|
157 |
|
---|
158 | fBlindPixelIdx.Set(0);
|
---|
159 | SetBlindPixelIdx();
|
---|
160 |
|
---|
161 | if (fHiGainSignal)
|
---|
162 | {
|
---|
163 | delete [] fHiGainSignal;
|
---|
164 | fHiGainSignal = NULL;
|
---|
165 | }
|
---|
166 | if (fHiGainFirstDeriv)
|
---|
167 | {
|
---|
168 | delete [] fHiGainFirstDeriv;
|
---|
169 | fHiGainFirstDeriv = NULL;
|
---|
170 | }
|
---|
171 | if (fHiGainSecondDeriv)
|
---|
172 | {
|
---|
173 | delete [] fHiGainSecondDeriv;
|
---|
174 | fHiGainSecondDeriv = NULL;
|
---|
175 | }
|
---|
176 |
|
---|
177 | }
|
---|
178 |
|
---|
179 | void MExtractBlindPixel::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
180 | {
|
---|
181 |
|
---|
182 | MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
183 |
|
---|
184 | fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
|
---|
185 | if (lolast)
|
---|
186 | fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1);
|
---|
187 | else
|
---|
188 | fNumLoGainSamples = 0.;
|
---|
189 |
|
---|
190 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
191 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
192 |
|
---|
193 | fHiLoFirst = 0;
|
---|
194 | fHiLoLast = 0;
|
---|
195 | }
|
---|
196 |
|
---|
197 | // --------------------------------------------------------------------------
|
---|
198 | //
|
---|
199 | // Calls:
|
---|
200 | // - MExtractor::PreProcess(pList)
|
---|
201 | //
|
---|
202 | // The following output containers are also searched and created if
|
---|
203 | // they were not found:
|
---|
204 | //
|
---|
205 | // - MExtractedBlindPixel
|
---|
206 | //
|
---|
207 | Int_t MExtractBlindPixel::PreProcess(MParList *pList)
|
---|
208 | {
|
---|
209 |
|
---|
210 | if (!MExtractor::PreProcess(pList))
|
---|
211 | return kFALSE;
|
---|
212 |
|
---|
213 | fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel"));
|
---|
214 | if (!fBlindPixel)
|
---|
215 | return kFALSE;
|
---|
216 |
|
---|
217 | if (IsDataType(kRawEvt2))
|
---|
218 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData2"));
|
---|
219 | else
|
---|
220 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
221 |
|
---|
222 | if (!fRawEvt)
|
---|
223 | {
|
---|
224 | *fLog << err << GetDescriptor()
|
---|
225 | << Form("%s%s",IsDataType(kRawEvt2) ? "MRawEvtData2" : "MRawEvtData",
|
---|
226 | " not found... aborting.") << endl;
|
---|
227 | return kFALSE;
|
---|
228 | }
|
---|
229 | return kTRUE;
|
---|
230 | }
|
---|
231 |
|
---|
232 | // -------------------------------------------------------------------------- //
|
---|
233 | //
|
---|
234 | // The ReInit searches for:
|
---|
235 | // - MRawRunHeader::GetNumSamplesHiGain()
|
---|
236 | // - MRawRunHeader::GetNumSamplesLoGain()
|
---|
237 | //
|
---|
238 | // In case that the variables fHiGainLast and fLoGainLast are smaller than
|
---|
239 | // the even part of the number of samples obtained from the run header, a
|
---|
240 | // warning is given an the range is set back accordingly. A call to:
|
---|
241 | // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or
|
---|
242 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
---|
243 | // is performed in that case. The variable diff means here the difference
|
---|
244 | // between the requested range (fHiGainLast) and the available one. Note that
|
---|
245 | // the functions SetRange() are mostly overloaded and perform more checks,
|
---|
246 | // modifying the ranges again, if necessary.
|
---|
247 | //
|
---|
248 | Bool_t MExtractBlindPixel::ReInit(MParList *pList)
|
---|
249 | {
|
---|
250 |
|
---|
251 | if (fHiGainSignal)
|
---|
252 | delete [] fHiGainSignal;
|
---|
253 | if (fHiGainFirstDeriv)
|
---|
254 | delete [] fHiGainFirstDeriv;
|
---|
255 | if (fHiGainSecondDeriv)
|
---|
256 | delete [] fHiGainSecondDeriv;
|
---|
257 |
|
---|
258 | for (Int_t i=0;i<fNumBlindPixels;i++)
|
---|
259 | fBlindPixel->SetBlindPixelIdx(fBlindPixelIdx.At(i),i);
|
---|
260 |
|
---|
261 | fBlindPixel->SetExtractionType(fExtractionType);
|
---|
262 |
|
---|
263 | for (Int_t i=0;i<fBlindPixelIdx.GetSize();i++)
|
---|
264 | {
|
---|
265 |
|
---|
266 | MPedestalPix &pedpix = (*fPedestals)[fBlindPixelIdx.At(i)];
|
---|
267 |
|
---|
268 | if (&pedpix)
|
---|
269 | {
|
---|
270 | fBlindPixel->SetPed ( pedpix.GetPedestal() * fNumLoGainSamples, i );
|
---|
271 | fBlindPixel->SetPedErr ( pedpix.GetPedestalRms()* fNumLoGainSamples
|
---|
272 | / TMath::Sqrt((Float_t)fPedestals->GetTotalEntries()), i );
|
---|
273 | fBlindPixel->SetPedRms ( pedpix.GetPedestalRms()* TMath::Sqrt((Float_t)fNumLoGainSamples), i );
|
---|
274 | fBlindPixel->SetPedRmsErr( fBlindPixel->GetPedErr()/2., i );
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | const Int_t higainsamples = fRunHeader->GetNumSamplesHiGain();
|
---|
279 | const Int_t logainsamples = fRunHeader->GetNumSamplesLoGain();
|
---|
280 | Int_t lastavailable = higainsamples-1;
|
---|
281 |
|
---|
282 | if (logainsamples)
|
---|
283 | {
|
---|
284 | //
|
---|
285 | // If the signal is searched entirely in the low-gain range, have
|
---|
286 | // to skip the higain completely. This is steered by the variable fHiLoFirst
|
---|
287 | //
|
---|
288 | const Int_t firstdesired = (Int_t)fHiGainFirst;
|
---|
289 |
|
---|
290 | if (firstdesired > lastavailable)
|
---|
291 | {
|
---|
292 | const Int_t diff = firstdesired - lastavailable;
|
---|
293 | *fLog << endl;
|
---|
294 | *fLog << warn << "First Hi Gain slice " << (int)fHiGainFirst << " out of range [0,";
|
---|
295 | *fLog << lastavailable << "]... start at slice " << diff << " of the Lo Gain " << endl;
|
---|
296 |
|
---|
297 | fHiLoFirst = diff;
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | const Int_t lastdesired = (Int_t)fHiGainLast;
|
---|
302 |
|
---|
303 | if (lastdesired > lastavailable)
|
---|
304 | {
|
---|
305 | Int_t diff = lastdesired - lastavailable;
|
---|
306 | lastavailable += logainsamples ? logainsamples-1 : 0;
|
---|
307 |
|
---|
308 | if (lastdesired > lastavailable)
|
---|
309 | {
|
---|
310 | *fLog << endl;
|
---|
311 | *fLog << "Last Hi Gain slice " << (int)fHiGainLast << " out of range [0,";
|
---|
312 | *fLog << lastavailable << "]... reduce upper limit by " << diff << endl;
|
---|
313 | diff = logainsamples;
|
---|
314 | }
|
---|
315 |
|
---|
316 | fHiGainLast = higainsamples - 1;
|
---|
317 | fHiLoLast = logainsamples ? diff : 0;
|
---|
318 | }
|
---|
319 |
|
---|
320 | const Int_t range = fHiLoFirst ? fHiLoLast - fHiLoFirst + 1 : fHiGainLast - fHiGainFirst + fHiLoLast + 1;
|
---|
321 |
|
---|
322 | fHiGainSignal = new Float_t[range];
|
---|
323 | memset(fHiGainSignal,0,range*sizeof(Float_t));
|
---|
324 | fHiGainFirstDeriv = new Float_t[range];
|
---|
325 | memset(fHiGainFirstDeriv,0,range*sizeof(Float_t));
|
---|
326 | fHiGainSecondDeriv = new Float_t[range];
|
---|
327 | memset(fHiGainSecondDeriv,0,range*sizeof(Float_t));
|
---|
328 |
|
---|
329 | *fLog << endl;
|
---|
330 | *fLog << inf << "Extracting "
|
---|
331 | << (IsExtractionType(kAmplitude) ? "Amplitude" : " Integral")
|
---|
332 | << " using " << range << " FADC samples from "
|
---|
333 | << (fHiLoFirst ? "Low Gain slice" : " High Gain slice")
|
---|
334 | << (fHiLoFirst ? (Int_t)fHiLoFirst : (Int_t)fHiGainFirst)
|
---|
335 | << " to (including) "
|
---|
336 | << (fHiLoLast ? "Low Gain slice" : "High Gain slice")
|
---|
337 | << (fHiLoLast ? (Int_t)fHiLoLast-1 : (Int_t)fHiGainLast)
|
---|
338 | << endl;
|
---|
339 |
|
---|
340 | if (IsExtractionType(kFilter))
|
---|
341 | *fLog << inf << "Will use Filter using "
|
---|
342 | << (Int_t)(fLoGainLast-fLoGainFirst+1) << " FADC slices"
|
---|
343 | << " from High Gain slice " << (Int_t)fLoGainFirst
|
---|
344 | << " to High Gain slice " << (Int_t)fLoGainLast << endl;
|
---|
345 |
|
---|
346 | fBlindPixel->SetUsedFADCSlices(fHiGainFirst, range);
|
---|
347 |
|
---|
348 | return kTRUE;
|
---|
349 |
|
---|
350 | }
|
---|
351 |
|
---|
352 | // --------------------------------------------------------------------------
|
---|
353 | //
|
---|
354 | // FindSignalHiGain:
|
---|
355 | //
|
---|
356 | // - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
|
---|
357 | // - Sum up contents of *ptr
|
---|
358 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
359 | // - If fHiLoLast is set, loop from logain to (logain+fHiLoLast)
|
---|
360 | // - Add contents of *logain to sum
|
---|
361 | //
|
---|
362 | void MExtractBlindPixel::FindIntegral(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat)
|
---|
363 | {
|
---|
364 |
|
---|
365 | Int_t summ = 0;
|
---|
366 | Byte_t *p = ptr;
|
---|
367 | Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
|
---|
368 |
|
---|
369 | if (fHiLoFirst == 0)
|
---|
370 | {
|
---|
371 |
|
---|
372 | while (p<end)
|
---|
373 | {
|
---|
374 | summ += *ptr;
|
---|
375 |
|
---|
376 | if (*p++ >= fSaturationLimit)
|
---|
377 | sat++;
|
---|
378 | }
|
---|
379 |
|
---|
380 | }
|
---|
381 |
|
---|
382 | p = logain + fHiLoFirst;
|
---|
383 | end = logain + fHiLoLast;
|
---|
384 | while (p<end)
|
---|
385 | {
|
---|
386 | summ += *p;
|
---|
387 |
|
---|
388 | if (*p++ >= fSaturationLimit)
|
---|
389 | sat++;
|
---|
390 | }
|
---|
391 |
|
---|
392 | sum = (Float_t)summ;
|
---|
393 | }
|
---|
394 |
|
---|
395 | // --------------------------------------------------------------------------
|
---|
396 | //
|
---|
397 | // FindSignalPhe:
|
---|
398 | //
|
---|
399 | // - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
|
---|
400 | // - Sum up contents of *ptr
|
---|
401 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
402 | // - If fHiLoLast is set, loop from logain to (logain+fHiLoLast)
|
---|
403 | // - Add contents of *logain to sum
|
---|
404 | //
|
---|
405 | void MExtractBlindPixel::FindAmplitude(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat)
|
---|
406 | {
|
---|
407 |
|
---|
408 | Int_t range = 0;
|
---|
409 | Int_t count = 0;
|
---|
410 | Float_t abmaxpos = 0.;
|
---|
411 | Byte_t *p = ptr;
|
---|
412 | Byte_t *end;
|
---|
413 | Byte_t max = 0;
|
---|
414 | Byte_t maxpos = 0;
|
---|
415 | Int_t summ = 0;
|
---|
416 |
|
---|
417 | if (fHiLoFirst == 0)
|
---|
418 | {
|
---|
419 |
|
---|
420 | range = fHiGainLast - fHiGainFirst + 1;
|
---|
421 |
|
---|
422 | end = ptr + range;
|
---|
423 | //
|
---|
424 | // Check for saturation in all other slices
|
---|
425 | //
|
---|
426 | while (p++<end)
|
---|
427 | {
|
---|
428 |
|
---|
429 | fHiGainSignal[count] = (Float_t)*p;
|
---|
430 | summ += *p;
|
---|
431 |
|
---|
432 | if (*p > max)
|
---|
433 | {
|
---|
434 | max = *p;
|
---|
435 | maxpos = count;
|
---|
436 | }
|
---|
437 |
|
---|
438 | count++;
|
---|
439 |
|
---|
440 | if (*p >= fSaturationLimit)
|
---|
441 | sat++;
|
---|
442 | }
|
---|
443 | }
|
---|
444 |
|
---|
445 | if (fHiLoLast != 0)
|
---|
446 | {
|
---|
447 |
|
---|
448 | p = logain + fHiLoFirst;
|
---|
449 | end = logain + fHiLoLast;
|
---|
450 |
|
---|
451 | while (p<end)
|
---|
452 | {
|
---|
453 |
|
---|
454 | fHiGainSignal[count] = (Float_t)*p;
|
---|
455 | summ += *p;
|
---|
456 |
|
---|
457 | if (*p > max)
|
---|
458 | {
|
---|
459 | max = *p;
|
---|
460 | maxpos = count;
|
---|
461 | }
|
---|
462 |
|
---|
463 | range++;
|
---|
464 | count++;
|
---|
465 |
|
---|
466 | if (*p++ >= fSaturationLimit)
|
---|
467 | sat++;
|
---|
468 | }
|
---|
469 | }
|
---|
470 |
|
---|
471 | //
|
---|
472 | // allow one saturated slice
|
---|
473 | //
|
---|
474 | if (sat > 1)
|
---|
475 | {
|
---|
476 | sum = gkOverflow;
|
---|
477 | return;
|
---|
478 | }
|
---|
479 |
|
---|
480 | //
|
---|
481 | // Don't start if the maxpos is too close to the left limit.
|
---|
482 | //
|
---|
483 | if (maxpos < 2)
|
---|
484 | {
|
---|
485 | sum = (Float_t)max;
|
---|
486 | return;
|
---|
487 | }
|
---|
488 |
|
---|
489 | Float_t pp;
|
---|
490 |
|
---|
491 | for (Int_t i=1;i<range-1;i++)
|
---|
492 | {
|
---|
493 | pp = fHiGainSecondDeriv[i-1] + 4.;
|
---|
494 | fHiGainSecondDeriv[i] = -1.0/pp;
|
---|
495 | fHiGainFirstDeriv [i] = fHiGainSignal[i+1] - fHiGainSignal[i] - fHiGainSignal[i] + fHiGainSignal[i-1];
|
---|
496 | fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
|
---|
497 | p++;
|
---|
498 | }
|
---|
499 |
|
---|
500 | fHiGainSecondDeriv[range-1] = 0.;
|
---|
501 | for (Int_t k=range-2;k>=0;k--)
|
---|
502 | fHiGainSecondDeriv[k] = (fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k])/6.;
|
---|
503 |
|
---|
504 | //
|
---|
505 | // Now find the maximum
|
---|
506 | //
|
---|
507 | Float_t step = 0.2; // start with step size of 1ns and loop again with the smaller one
|
---|
508 | Float_t lower = (Float_t)maxpos-1.;
|
---|
509 | Float_t upper = (Float_t)maxpos;
|
---|
510 | Float_t x = lower;
|
---|
511 | Float_t y = 0.;
|
---|
512 | Float_t a = 1.;
|
---|
513 | Float_t b = 0.;
|
---|
514 | Int_t klo = maxpos-1;
|
---|
515 | Int_t khi = maxpos;
|
---|
516 | Float_t klocont = fHiGainSignal[klo];
|
---|
517 | Float_t khicont = fHiGainSignal[khi];
|
---|
518 | sum = (Float_t)khicont;
|
---|
519 | abmaxpos = lower;
|
---|
520 |
|
---|
521 | //
|
---|
522 | // Search for the maximum, starting in interval maxpos-1. If no maximum is found, go to
|
---|
523 | // interval maxpos+1.
|
---|
524 | //
|
---|
525 | while (x<upper-0.3)
|
---|
526 | {
|
---|
527 |
|
---|
528 | x += step;
|
---|
529 | a -= step;
|
---|
530 | b += step;
|
---|
531 |
|
---|
532 | y = a*klocont
|
---|
533 | + b*khicont
|
---|
534 | + (a*a*a-a)*fHiGainSecondDeriv[klo]
|
---|
535 | + (b*b*b-b)*fHiGainSecondDeriv[khi];
|
---|
536 |
|
---|
537 | if (y > sum)
|
---|
538 | {
|
---|
539 | sum = y;
|
---|
540 | abmaxpos = x;
|
---|
541 | }
|
---|
542 | }
|
---|
543 |
|
---|
544 | if (abmaxpos > upper-0.1)
|
---|
545 | {
|
---|
546 |
|
---|
547 | upper = (Float_t)maxpos+1;
|
---|
548 | lower = (Float_t)maxpos;
|
---|
549 | x = lower;
|
---|
550 | a = 1.;
|
---|
551 | b = 0.;
|
---|
552 | khi = maxpos+1;
|
---|
553 | klo = maxpos;
|
---|
554 | klocont = fHiGainSignal[klo];
|
---|
555 | khicont = fHiGainSignal[khi];
|
---|
556 |
|
---|
557 | while (x<upper-0.3)
|
---|
558 | {
|
---|
559 |
|
---|
560 | x += step;
|
---|
561 | a -= step;
|
---|
562 | b += step;
|
---|
563 |
|
---|
564 | y = a* klocont
|
---|
565 | + b* khicont
|
---|
566 | + (a*a*a-a)*fHiGainSecondDeriv[klo]
|
---|
567 | + (b*b*b-b)*fHiGainSecondDeriv[khi];
|
---|
568 |
|
---|
569 | if (y > sum)
|
---|
570 | {
|
---|
571 | sum = y;
|
---|
572 | abmaxpos = x;
|
---|
573 | }
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 | const Float_t up = abmaxpos+step-0.055;
|
---|
578 | const Float_t lo = abmaxpos-step+0.055;
|
---|
579 | const Float_t maxpossave = abmaxpos;
|
---|
580 |
|
---|
581 | x = abmaxpos;
|
---|
582 | a = upper - x;
|
---|
583 | b = x - lower;
|
---|
584 |
|
---|
585 | step = 0.04; // step size of 83 ps
|
---|
586 |
|
---|
587 | while (x<up)
|
---|
588 | {
|
---|
589 |
|
---|
590 | x += step;
|
---|
591 | a -= step;
|
---|
592 | b += step;
|
---|
593 |
|
---|
594 | y = a* klocont
|
---|
595 | + b* khicont
|
---|
596 | + (a*a*a-a)*fHiGainSecondDeriv[klo]
|
---|
597 | + (b*b*b-b)*fHiGainSecondDeriv[khi];
|
---|
598 |
|
---|
599 | if (y > sum)
|
---|
600 | {
|
---|
601 | sum = y;
|
---|
602 | abmaxpos = x;
|
---|
603 | }
|
---|
604 | }
|
---|
605 |
|
---|
606 | if (abmaxpos < klo + 0.02)
|
---|
607 | {
|
---|
608 | klo--;
|
---|
609 | khi--;
|
---|
610 | klocont = fHiGainSignal[klo];
|
---|
611 | khicont = fHiGainSignal[khi];
|
---|
612 | upper--;
|
---|
613 | lower--;
|
---|
614 | }
|
---|
615 |
|
---|
616 | x = maxpossave;
|
---|
617 | a = upper - x;
|
---|
618 | b = x - lower;
|
---|
619 |
|
---|
620 | while (x>lo)
|
---|
621 | {
|
---|
622 |
|
---|
623 | x -= step;
|
---|
624 | a += step;
|
---|
625 | b -= step;
|
---|
626 |
|
---|
627 | y = a* klocont
|
---|
628 | + b* khicont
|
---|
629 | + (a*a*a-a)*fHiGainSecondDeriv[klo]
|
---|
630 | + (b*b*b-b)*fHiGainSecondDeriv[khi];
|
---|
631 |
|
---|
632 | if (y > sum)
|
---|
633 | {
|
---|
634 | sum = y;
|
---|
635 | abmaxpos = x;
|
---|
636 | }
|
---|
637 | }
|
---|
638 |
|
---|
639 | }
|
---|
640 |
|
---|
641 | // --------------------------------------------------------------------------
|
---|
642 | //
|
---|
643 | // FindSignalFilter:
|
---|
644 | //
|
---|
645 | // - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
|
---|
646 | // - Sum up contents of *ptr
|
---|
647 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
648 | //
|
---|
649 | void MExtractBlindPixel::FindSignalFilter(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
|
---|
650 | {
|
---|
651 |
|
---|
652 | Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
|
---|
653 |
|
---|
654 | while (ptr<end)
|
---|
655 | {
|
---|
656 | sum += *ptr;
|
---|
657 |
|
---|
658 | if (*ptr++ >= fSaturationLimit)
|
---|
659 | sat++;
|
---|
660 | }
|
---|
661 | }
|
---|
662 |
|
---|
663 | // --------------------------------------------------------------------------
|
---|
664 | //
|
---|
665 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
666 | // pixel in the MExtractedBlindPixel container.
|
---|
667 | //
|
---|
668 | Int_t MExtractBlindPixel::Process()
|
---|
669 | {
|
---|
670 |
|
---|
671 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
672 |
|
---|
673 | fBlindPixel->Clear();
|
---|
674 |
|
---|
675 | for (Int_t id=0;id<fBlindPixelIdx.GetSize();id++)
|
---|
676 | {
|
---|
677 |
|
---|
678 | pixel.Jump(fBlindPixelIdx[id]);
|
---|
679 |
|
---|
680 | Int_t sum = 0;
|
---|
681 | Byte_t sat = 0;
|
---|
682 |
|
---|
683 | if (IsExtractionType(kFilter))
|
---|
684 | {
|
---|
685 |
|
---|
686 | FindSignalFilter(pixel.GetHiGainSamples()+fLoGainFirst, sum, sat);
|
---|
687 |
|
---|
688 | if (sum > fNSBFilterLimit)
|
---|
689 | {
|
---|
690 | fBlindPixel->SetExtractedSignal(-1.,id);
|
---|
691 | fBlindPixel->SetNumSaturated(sat,id);
|
---|
692 | fBlindPixel->SetReadyToSave();
|
---|
693 | continue;
|
---|
694 | }
|
---|
695 |
|
---|
696 | sum = 0;
|
---|
697 | if (pixel.HasLoGain())
|
---|
698 | FindSignalFilter(pixel.GetLoGainSamples(), sum, sat);
|
---|
699 |
|
---|
700 | /*
|
---|
701 | if (fModified)
|
---|
702 | {
|
---|
703 | if (sum > fNSBFilterLimit)
|
---|
704 | {
|
---|
705 | fBlindPixel->SetExtractedSignal(-1.,id);
|
---|
706 | fBlindPixel->SetNumSaturated(sat,id);
|
---|
707 | fBlindPixel->SetReadyToSave();
|
---|
708 | continue;
|
---|
709 | }
|
---|
710 | }
|
---|
711 | */
|
---|
712 | }
|
---|
713 |
|
---|
714 | Float_t newsum = 0.;
|
---|
715 | sat = 0;
|
---|
716 |
|
---|
717 | if (IsExtractionType(kAmplitude))
|
---|
718 | FindAmplitude (pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), newsum, sat);
|
---|
719 | else
|
---|
720 | FindIntegral (pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), newsum, sat);
|
---|
721 |
|
---|
722 |
|
---|
723 | fBlindPixel->SetExtractedSignal(newsum,id);
|
---|
724 | fBlindPixel->SetNumSaturated(sat,id);
|
---|
725 | }
|
---|
726 |
|
---|
727 | fBlindPixel->SetReadyToSave();
|
---|
728 | return kTRUE;
|
---|
729 | }
|
---|
730 |
|
---|
731 | // ------------------------------------------------------------------------------------
|
---|
732 | //
|
---|
733 | // Returns true if the Data type. Available are: kAmplitude, kIntegral and kFilter
|
---|
734 | // The flags kIntegral and kFilter may be set both.
|
---|
735 | //
|
---|
736 | Bool_t MExtractBlindPixel::IsDataType( const DataType_t typ )
|
---|
737 | {
|
---|
738 |
|
---|
739 | return TESTBIT( fDataType, typ );
|
---|
740 |
|
---|
741 | }
|
---|
742 |
|
---|
743 | // ------------------------------------------------------------------------------------
|
---|
744 | //
|
---|
745 | // Returns true if the extraction type. Available are: kAmplitude, kIntegral and kFilter
|
---|
746 | // The flags kIntegral and kFilter may be set both.
|
---|
747 | //
|
---|
748 | Bool_t MExtractBlindPixel::IsExtractionType( const ExtractionType_t typ )
|
---|
749 | {
|
---|
750 |
|
---|
751 | return TESTBIT( fExtractionType, typ );
|
---|
752 |
|
---|
753 | }
|
---|
754 |
|
---|
755 | // --------------------------------------------------------------------------
|
---|
756 | //
|
---|
757 | // Sets the Data type. Available are: kAmplitude and kIntegral
|
---|
758 | //
|
---|
759 | void MExtractBlindPixel::SetDataType( const DataType_t typ )
|
---|
760 | {
|
---|
761 | SETBIT( fDataType, typ );
|
---|
762 | }
|
---|
763 |
|
---|
764 | // --------------------------------------------------------------------------
|
---|
765 | //
|
---|
766 | // Sets the extraction type. Available are: kAmplitude and kIntegral
|
---|
767 | //
|
---|
768 | void MExtractBlindPixel::SetExtractionType( const ExtractionType_t typ )
|
---|
769 | {
|
---|
770 | SETBIT( fExtractionType, typ );
|
---|
771 | }
|
---|