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