1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.62 2007-02-03 20:05:35 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): Markus Gaug, 05/2004 <mailto:markus@ifae.es>
|
---|
21 | ! Author(s): Thomas Bretz, 05/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
22 | !
|
---|
23 | ! Copyright: MAGIC Software Development, 2000-2006
|
---|
24 | !
|
---|
25 | !
|
---|
26 | \* ======================================================================== */
|
---|
27 |
|
---|
28 | //////////////////////////////////////////////////////////////////////////////
|
---|
29 | //
|
---|
30 | // MExtractTimeAndCharge
|
---|
31 | //
|
---|
32 | // Base class for the signal extractors which extract the arrival time
|
---|
33 | // and the signal at the same time. Uses the functions
|
---|
34 | // FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() to extract
|
---|
35 | // the signal.
|
---|
36 | //
|
---|
37 | // The following figure gives and example of possible inheritance trees.
|
---|
38 | // An extractor class can inherit from each of the following base classes:
|
---|
39 | // - MExtractor
|
---|
40 | // - MExtractTime
|
---|
41 | // - MExtractTimeAndCharge
|
---|
42 | //
|
---|
43 | //Begin_Html
|
---|
44 | /*
|
---|
45 | <img src="images/ExtractorClasses.gif">
|
---|
46 | */
|
---|
47 | //End_Html
|
---|
48 | //
|
---|
49 | // The following variables have to be set by the derived class and
|
---|
50 | // do not have defaults:
|
---|
51 | // - fNumHiGainSamples
|
---|
52 | // - fNumLoGainSamples
|
---|
53 | // - fSqrtHiGainSamples
|
---|
54 | // - fSqrtLoGainSamples
|
---|
55 | //
|
---|
56 | //
|
---|
57 | // Class Version 3:
|
---|
58 | // ----------------
|
---|
59 | // - Byte_t fMaxBinContent;
|
---|
60 | //
|
---|
61 | //
|
---|
62 | // Input Containers:
|
---|
63 | // MRawEvtData
|
---|
64 | // MRawRunHeader
|
---|
65 | // MPedestalCam
|
---|
66 | //
|
---|
67 | // Output Containers:
|
---|
68 | // MArrivalTimeCam
|
---|
69 | // MExtractedSignalCam
|
---|
70 | //
|
---|
71 | // For weired events check: Run 94127 Event 672, 1028
|
---|
72 | //
|
---|
73 | //////////////////////////////////////////////////////////////////////////////
|
---|
74 | #include "MExtractTimeAndCharge.h"
|
---|
75 |
|
---|
76 | #include <TRandom.h>
|
---|
77 | #include <TVector3.h>
|
---|
78 |
|
---|
79 | #include "MMath.h"
|
---|
80 |
|
---|
81 | #include "MLog.h"
|
---|
82 | #include "MLogManip.h"
|
---|
83 |
|
---|
84 | #include "MParList.h"
|
---|
85 |
|
---|
86 | #include "MRawEvtPixelIter.h"
|
---|
87 | #include "MRawRunHeader.h"
|
---|
88 |
|
---|
89 | #include "MArrivalTimeCam.h"
|
---|
90 | #include "MArrivalTimePix.h"
|
---|
91 |
|
---|
92 | #include "MExtractedSignalCam.h"
|
---|
93 | #include "MExtractedSignalPix.h"
|
---|
94 |
|
---|
95 | #include "MPedestalSubtractedEvt.h"
|
---|
96 |
|
---|
97 | ClassImp(MExtractTimeAndCharge);
|
---|
98 |
|
---|
99 | using namespace std;
|
---|
100 |
|
---|
101 | const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -2.5;
|
---|
102 | const Byte_t MExtractTimeAndCharge::fgLoGainSwitch = 120;
|
---|
103 |
|
---|
104 | // --------------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // Default constructor.
|
---|
107 | //
|
---|
108 | // Sets:
|
---|
109 | // - fWindowSizeHiGain and fWindowSizeLoGain to 0
|
---|
110 | // - fLoGainStartShift to fgLoGainStartShift
|
---|
111 | // - fLoGainSwitch to fgLoGainSwitch
|
---|
112 | //
|
---|
113 | MExtractTimeAndCharge::MExtractTimeAndCharge(const char *name, const char *title)
|
---|
114 | : fWindowSizeHiGain(0), fWindowSizeLoGain(0)
|
---|
115 | {
|
---|
116 | fName = name ? name : "MExtractTimeAndCharge";
|
---|
117 | fTitle = title ? title : "Base class for signal and time extractors";
|
---|
118 |
|
---|
119 | SetLoGainStartShift();
|
---|
120 | SetLoGainSwitch();
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // The PreProcess searches for the following input containers:
|
---|
126 | // - MRawEvtData
|
---|
127 | // - MRawRunHeader
|
---|
128 | // - MPedestalCam
|
---|
129 | //
|
---|
130 | // The following output containers are also searched and created if
|
---|
131 | // they were not found:
|
---|
132 | //
|
---|
133 | // - MExtractedSignalCam
|
---|
134 | // - MArrivalTimeCam
|
---|
135 | //
|
---|
136 | Int_t MExtractTimeAndCharge::PreProcess(MParList *pList)
|
---|
137 | {
|
---|
138 | if (!MExtractTime::PreProcess(pList))
|
---|
139 | return kFALSE;
|
---|
140 |
|
---|
141 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
|
---|
142 | if (!fSignals)
|
---|
143 | return kFALSE;
|
---|
144 |
|
---|
145 | *fLog << flush << inf;
|
---|
146 | return kTRUE;
|
---|
147 | }
|
---|
148 |
|
---|
149 | // --------------------------------------------------------------------------
|
---|
150 | //
|
---|
151 | // The ReInit calls:
|
---|
152 | // - MExtractor::ReInit()
|
---|
153 | //
|
---|
154 | // Call:
|
---|
155 | // - MArrivalTimeCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
---|
156 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
157 | // - InitArrays();
|
---|
158 | //
|
---|
159 | Bool_t MExtractTimeAndCharge::ReInit(MParList *pList)
|
---|
160 | {
|
---|
161 | if (!MExtractTime::ReInit(pList))
|
---|
162 | return kFALSE;
|
---|
163 |
|
---|
164 | if (!InitArrays(fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain()))
|
---|
165 | return kFALSE;
|
---|
166 |
|
---|
167 | if (fSignals)
|
---|
168 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
---|
169 | fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
170 | return kTRUE;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // --------------------------------------------------------------------------
|
---|
174 | //
|
---|
175 | // Return the x-value lower than sat0 at which the signal has been
|
---|
176 | // fallen bwlow maxcont/2. This time is determined using a simple second
|
---|
177 | // order polynomial interpolation.
|
---|
178 | //
|
---|
179 | Double_t MExtractTimeAndCharge::GetSaturationTime(Int_t sat0, const Float_t *sig, Int_t maxcont) const
|
---|
180 | {
|
---|
181 | const Int_t p = sat0>1 ? sat0-2 : sat0-1;
|
---|
182 | if (sat0<=0)
|
---|
183 | return 0;
|
---|
184 | if (sat0==1)
|
---|
185 | return sig[0]>maxcont/2 ? 0 : 0.5;
|
---|
186 |
|
---|
187 | if (sig[p]>sig[p+1] || sig[p+1]>sig[p+2])
|
---|
188 | return sig[p+1]>maxcont/2 ? sat0-1 : sat0-0.5;
|
---|
189 |
|
---|
190 | // Find the place at which the signal is maxcont/2
|
---|
191 | const TVector3 vx(sig[p], sig[p+1], sig[p+2]);
|
---|
192 | const TVector3 vy(p, p+1, p+2);
|
---|
193 |
|
---|
194 | return MMath::InterpolParabLin(vx, vy, maxcont/2);
|
---|
195 | }
|
---|
196 |
|
---|
197 | // --------------------------------------------------------------------------
|
---|
198 | //
|
---|
199 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
200 | // pixel in the MArrivalTimeCam container.
|
---|
201 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
202 | // pixel in the MExtractedSignalCam container.
|
---|
203 | // The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() are
|
---|
204 | // supposed to extract the signal themselves.
|
---|
205 | //
|
---|
206 | Int_t MExtractTimeAndCharge::Process()
|
---|
207 | {
|
---|
208 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
209 |
|
---|
210 | while (pixel.Next())
|
---|
211 | {
|
---|
212 | const Int_t pixidx = pixel.GetPixelId();
|
---|
213 |
|
---|
214 | const Float_t *sig = fSignal->GetSamples(pixidx);
|
---|
215 |
|
---|
216 | const Int_t numh = pixel.GetNumHiGainSamples();
|
---|
217 |
|
---|
218 | Int_t sathi0 = fHiGainFirst; // First slice to extract and first saturating slice
|
---|
219 | Int_t sathi1 = fHiGainLast; // Last slice to extract and last saturating slice
|
---|
220 |
|
---|
221 | Int_t maxcont;
|
---|
222 | Int_t maxposhi = fSignal->GetMax(pixidx, sathi0, sathi1, maxcont);
|
---|
223 | // Would it be better to take lastsat-firstsat?
|
---|
224 | Int_t numsathi = fSignal->GetSaturation(pixidx, fSaturationLimit, sathi0, sathi1);
|
---|
225 |
|
---|
226 | Float_t sumhi =0., deltasumhi =-1; // Set hi-gain of MExtractedSignalPix valid
|
---|
227 | Float_t timehi=0., deltatimehi=-1; // Set hi-gain of MArrivalTimePix valid
|
---|
228 |
|
---|
229 | // Do not even try to extract the hi-gain if we have
|
---|
230 | // more than one saturating slice
|
---|
231 | const Int_t rangehi = fHiGainLast - fHiGainFirst + 1;
|
---|
232 |
|
---|
233 | if (numsathi<2)
|
---|
234 | FindTimeAndChargeHiGain2(sig+fHiGainFirst, rangehi,
|
---|
235 | sumhi, deltasumhi, timehi, deltatimehi,
|
---|
236 | numsathi, maxposhi);
|
---|
237 |
|
---|
238 | // If we have saturating slices try to get a better estimate
|
---|
239 | // of the arrival time than timehi or sathi0. This is
|
---|
240 | // usefull to know where to start lo-gain extraction.
|
---|
241 | if (numsathi>1)
|
---|
242 | {
|
---|
243 | timehi = GetSaturationTime(sathi0, sig, maxcont)-fHiGainFirst;
|
---|
244 | deltatimehi = 0;
|
---|
245 | }
|
---|
246 |
|
---|
247 | // Make sure that in cases the time couldn't be correctly determined
|
---|
248 | // more meaningfull default values are assigned.
|
---|
249 | // For extractors like the digital filter and the spline
|
---|
250 | // we allow extracpolation by one slice.
|
---|
251 | // FIXME: Defined Out-Of-Range better so that the extractors
|
---|
252 | // know what to return!
|
---|
253 | if (deltatimehi>-0.5 && (timehi<-1 || timehi>=rangehi))
|
---|
254 | {
|
---|
255 | // Flag this as unreliable!
|
---|
256 | timehi = gRandom->Uniform(rangehi+1)-1;
|
---|
257 | // deltatimehi=-1; // Set PIXEL to UNRELIABLE?
|
---|
258 | }
|
---|
259 |
|
---|
260 | timehi += fHiGainFirst;
|
---|
261 |
|
---|
262 | Float_t sumlo =0, deltasumlo =-1; // invalidate logain of MExtractedSignalPix
|
---|
263 | Float_t timelo=0, deltatimelo=-1; // invalidate logain of MArrivalTimePix
|
---|
264 | Int_t numsatlo=0;
|
---|
265 |
|
---|
266 | //
|
---|
267 | // Adapt the low-gain extraction range from the obtained high-gain time
|
---|
268 | //
|
---|
269 |
|
---|
270 | // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
|
---|
271 | // MEANS: Hi gain has saturated, but the signal is to dim
|
---|
272 | // to extract the lo-gain properly
|
---|
273 | // This could happen because the maxcont was not extracted from
|
---|
274 | // all slices!
|
---|
275 | // THIS produces pulse positions ~= -1
|
---|
276 | // The signal might be handled in MCalibrateData, but hwat's about
|
---|
277 | // the arrival times in MCalibrateRelTime
|
---|
278 | if (numsathi>0 && maxcont<=fLoGainSwitch)
|
---|
279 | deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
|
---|
280 |
|
---|
281 | // If more than 8 hi-gain slices have saturated this is
|
---|
282 | // no physical event. We just assume that something with
|
---|
283 | // the extraction is wrong
|
---|
284 | if (numsathi>8) // FIXME: Should be something like 2?
|
---|
285 | deltasumhi=deltatimehi=-1;
|
---|
286 |
|
---|
287 | // FIXME: What to do with the pixel if it saturates too early???
|
---|
288 | if (pixel.HasLoGain() && maxcont>fLoGainSwitch)
|
---|
289 | {
|
---|
290 | Int_t first = numh+fLoGainFirst;
|
---|
291 | Int_t last = numh+fLoGainLast;
|
---|
292 |
|
---|
293 | // To determin the window in which the lo-gain is extracted
|
---|
294 | // clearly more information about the relation between the
|
---|
295 | // extraction window and the reslting time is necessary.
|
---|
296 | //
|
---|
297 | // numh + fLoGainStartShift == 14 / fLoGainStartShift=-1
|
---|
298 | //
|
---|
299 | // The lo-gain is expected to have its raising edge
|
---|
300 | // at timehi+numh+fOffsetLoGain. We start to search for the
|
---|
301 | // lo-gain fLoGainStartShift slices earlier.
|
---|
302 | //
|
---|
303 | // Instead of fLoGainStartShift the extractor should now how many
|
---|
304 | // slices before the expected raising edge the start of the
|
---|
305 | // search must be placed and from there we can step 1.5 slices
|
---|
306 | // back to be on the safe side.
|
---|
307 | //
|
---|
308 | // The jitter in the hi-/lo-gain offset ssems to be around +/-0.5
|
---|
309 | const Float_t tm = deltatimehi<0 ? -1.+fHiGainFirst : timehi;
|
---|
310 | first = TMath::FloorNint(tm+numh+fOffsetLoGain+fLoGainStartShift);
|
---|
311 |
|
---|
312 | if (first<0)
|
---|
313 | first = 0;
|
---|
314 | if (first>last)
|
---|
315 | first=last;
|
---|
316 |
|
---|
317 | /*
|
---|
318 | // Currently we have to stick to this check because at least
|
---|
319 | // the spline has arrays of this size...
|
---|
320 | if (first>last)
|
---|
321 | first = last;
|
---|
322 | if (first<numh+fLoGainFirst)
|
---|
323 | first = numh+fLoGainFirst;
|
---|
324 | */
|
---|
325 | Int_t satlo0 = first; // First slice to extract and first saturating slice
|
---|
326 | Int_t satlo1 = last; // Last slice to extract and last saturating slice
|
---|
327 |
|
---|
328 | // Would it be better to take lastsat-firstsat?
|
---|
329 | Int_t maxlo;
|
---|
330 | Int_t maxposlo = fSignal->GetMax(pixidx, satlo0, satlo1, maxlo);
|
---|
331 | numsatlo = fSignal->GetSaturation(pixidx, fSaturationLimit, satlo0, satlo1);
|
---|
332 |
|
---|
333 | //if (satlo0>first && satlo1<last && numsatlo>2)
|
---|
334 | //{
|
---|
335 | // fSignal->InterpolateSaturation(pixidx, fSaturationLimit, satlo0, satlo1);
|
---|
336 | // numsatlo = 0;
|
---|
337 | //}
|
---|
338 |
|
---|
339 | const Int_t rangelo = last-first+1;
|
---|
340 | FindTimeAndChargeLoGain2(sig+first, rangelo,
|
---|
341 | sumlo, deltasumlo, timelo, deltatimelo,
|
---|
342 | numsatlo, maxposlo);
|
---|
343 |
|
---|
344 | // If we have saturating slices try to get a better estimate
|
---|
345 | // of the arrival time than timehi or sathi0. This is
|
---|
346 | // usefull to know where to start lo-gain extraction.
|
---|
347 | if (numsatlo>1)
|
---|
348 | {
|
---|
349 | timelo = GetSaturationTime(satlo0, sig, maxlo)-numh-first;
|
---|
350 | deltatimelo = 0;
|
---|
351 | }
|
---|
352 |
|
---|
353 | // Make sure that in cases the time couldn't be correctly determined
|
---|
354 | // more meaningfull default values are assigned
|
---|
355 | // For extractors like the digital filter and the spline
|
---|
356 | // we allow extracpolation by one slice.
|
---|
357 | if (deltatimelo>-0.5 && (timelo<-1 || timelo>=rangelo))
|
---|
358 | {
|
---|
359 | // Flag this as unreliable!
|
---|
360 | timelo = gRandom->Uniform(rangelo+1)-1;
|
---|
361 | //deltatimelo=-1; // Set PIXEL to UNRELIABLE?
|
---|
362 | }
|
---|
363 |
|
---|
364 | timelo += first-numh;
|
---|
365 |
|
---|
366 | // If more than 6 lo-gain slices have saturated this is
|
---|
367 | // no physical event. We just assume that something with
|
---|
368 | // the extraction is wrong
|
---|
369 | if (numsatlo>6)
|
---|
370 | deltasumlo=deltatimelo=-1;
|
---|
371 |
|
---|
372 | // The extracted lo-gain signal cannot be zero or
|
---|
373 | // negative at all, so it must be wrong
|
---|
374 | if (sumlo<=0)
|
---|
375 | deltasumlo=-1;
|
---|
376 |
|
---|
377 | //if (TMath::Abs(timelo-fOffsetLoGain - timehi)>1.0)
|
---|
378 | // deltatimelo = -1;
|
---|
379 | }
|
---|
380 |
|
---|
381 | // Now store the result in the corresponding containers
|
---|
382 | MExtractedSignalPix &pix = (*fSignals)[pixidx];
|
---|
383 | MArrivalTimePix &tix = (*fArrTime)[pixidx];
|
---|
384 | pix.SetExtractedSignal(sumhi, deltasumhi, sumlo, deltasumlo);
|
---|
385 | pix.SetGainSaturation(numsathi, numsatlo);
|
---|
386 |
|
---|
387 | tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
|
---|
388 | tix.SetGainSaturation(numsathi, numsatlo);
|
---|
389 | } /* while (pixel.Next()) */
|
---|
390 |
|
---|
391 | fArrTime->SetReadyToSave();
|
---|
392 | fSignals->SetReadyToSave();
|
---|
393 |
|
---|
394 | return kTRUE;
|
---|
395 | }
|
---|
396 |
|
---|
397 | // --------------------------------------------------------------------------
|
---|
398 | //
|
---|
399 | // In addition to the resources of the base-class MExtractor:
|
---|
400 | // MJPedestal.MExtractor.LoGainStartShift: -2.8
|
---|
401 | //
|
---|
402 | Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
403 | {
|
---|
404 | Bool_t rc = MExtractTime::ReadEnv(env, prefix, print);
|
---|
405 |
|
---|
406 | if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
|
---|
407 | {
|
---|
408 | fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fgLoGainStartShift);
|
---|
409 | SetLoGainStartShift(fLoGainStartShift);
|
---|
410 | rc = kTRUE;
|
---|
411 | }
|
---|
412 |
|
---|
413 | if (IsEnvDefined(env, prefix, "LoGainSwitch", print))
|
---|
414 | {
|
---|
415 | fLoGainSwitch = GetEnvValue(env, prefix, "LoGainSwitch", fLoGainSwitch);
|
---|
416 | rc = kTRUE;
|
---|
417 | }
|
---|
418 |
|
---|
419 | return rc;
|
---|
420 | }
|
---|
421 |
|
---|
422 | void MExtractTimeAndCharge::Print(Option_t *o) const
|
---|
423 | {
|
---|
424 | MExtractTime::Print(o);
|
---|
425 |
|
---|
426 | *fLog << dec;
|
---|
427 | *fLog << " LoGainStartShift: " << fLoGainStartShift << endl;
|
---|
428 | *fLog << " LoGainSwitch: " << (Int_t)fLoGainSwitch << endl;
|
---|
429 | }
|
---|