1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.57 2006-10-27 13:49:42 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 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
170 | // pixel in the MArrivalTimeCam container.
|
---|
171 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
172 | // pixel in the MExtractedSignalCam container.
|
---|
173 | // The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() are
|
---|
174 | // supposed to extract the signal themselves.
|
---|
175 | //
|
---|
176 | Int_t MExtractTimeAndCharge::Process()
|
---|
177 | {
|
---|
178 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
179 |
|
---|
180 | while (pixel.Next())
|
---|
181 | {
|
---|
182 | const Int_t pixidx = pixel.GetPixelId();
|
---|
183 |
|
---|
184 | const Float_t *sig = fSignal->GetSamples(pixidx);
|
---|
185 |
|
---|
186 | const Int_t numh = pixel.GetNumHiGainSamples();
|
---|
187 |
|
---|
188 | Int_t sathi0 = fHiGainFirst; // First slice to extract and first saturating slice
|
---|
189 | Int_t sathi1 = fHiGainLast; // Last slice to extract and last saturating slice
|
---|
190 |
|
---|
191 | Int_t maxcont;
|
---|
192 | Int_t maxposhi = fSignal->GetMax(pixidx, sathi0, sathi1, maxcont);
|
---|
193 | // Would it be better to take lastsat-firstsat?
|
---|
194 | Int_t numsathi = fSignal->GetSaturation(pixidx, fSaturationLimit, sathi0, sathi1);
|
---|
195 |
|
---|
196 | Float_t sumhi =0., deltasumhi =-1; // Set hi-gain of MExtractedSignalPix valid
|
---|
197 | Float_t timehi=0., deltatimehi=-1; // Set hi-gain of MArrivalTimePix valid
|
---|
198 |
|
---|
199 | // Do not even try to extract the hi-gain if we have
|
---|
200 | // more than one saturating slice
|
---|
201 | if (numsathi<2)
|
---|
202 | {
|
---|
203 | const Int_t rangehi = fHiGainLast - fHiGainFirst + 1;
|
---|
204 | FindTimeAndChargeHiGain2(sig+fHiGainFirst, rangehi,
|
---|
205 | sumhi, deltasumhi, timehi, deltatimehi,
|
---|
206 | numsathi, maxposhi);
|
---|
207 |
|
---|
208 |
|
---|
209 | // Make sure that in cases the time couldn't be correctly determined
|
---|
210 | // more meaningfull default values are assigned
|
---|
211 | //if (timehi<fHiGainFirst || timehi>=fHiGainLast-1)
|
---|
212 | if (deltatimehi>-0.5 && (timehi<0 || timehi>=fHiGainLast-fHiGainFirst+1))
|
---|
213 | timehi = gRandom->Uniform(fHiGainLast-fHiGainFirst+1);
|
---|
214 |
|
---|
215 | timehi += fHiGainFirst;
|
---|
216 | }
|
---|
217 |
|
---|
218 | // If we have saturating slices try to get a better estimate
|
---|
219 | // of the arrival time than timehi or sathi0. This is
|
---|
220 | // usefull to know where to start lo-gain extraction.
|
---|
221 | if (numsathi>1)
|
---|
222 | {
|
---|
223 | const Int_t p = sathi0>1 ? sathi0-2 : sathi0-1;
|
---|
224 | if (sathi0>0)
|
---|
225 | {
|
---|
226 | // Find the place at which the signal is maxcont/2
|
---|
227 | const TVector3 vx(sig[p], sig[p+1], sig[p+2]);
|
---|
228 | const TVector3 vy(p, p+1, p+2);
|
---|
229 | timehi=MMath::InterpolParabLin(vx, vy, maxcont/2);
|
---|
230 | }
|
---|
231 | else
|
---|
232 | timehi=0;
|
---|
233 | }
|
---|
234 |
|
---|
235 | Float_t sumlo =0, deltasumlo =-1; // invalidate logain of MExtractedSignalPix
|
---|
236 | Float_t timelo=0, deltatimelo=-1; // invalidate logain of MArrivalTimePix
|
---|
237 | Int_t numsatlo=0;
|
---|
238 |
|
---|
239 | //
|
---|
240 | // Adapt the low-gain extraction range from the obtained high-gain time
|
---|
241 | //
|
---|
242 |
|
---|
243 | // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
|
---|
244 | // MEANS: Hi gain has saturated, but the signal is to dim
|
---|
245 | // to extract the lo-gain properly
|
---|
246 | // This could happen because the maxcont was not extracted from
|
---|
247 | // all slices!
|
---|
248 | // THIS produces pulse positions ~= -1
|
---|
249 | // The signal might be handled in MCalibrateData, but hwat's about
|
---|
250 | // the arrival times in MCalibrateRelTime
|
---|
251 | if (numsathi>0 && maxcont<=fLoGainSwitch)
|
---|
252 | deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
|
---|
253 |
|
---|
254 | // If more than 8 hi-gain slices have saturated this is
|
---|
255 | // no physical event. We just assume that something with
|
---|
256 | // the extraction is wrong
|
---|
257 | if (numsathi>8) // FIXME: Should be something like 2?
|
---|
258 | deltasumhi=deltatimehi=-1;
|
---|
259 |
|
---|
260 | // FIXME: What to do with the pixel if it saturates too early???
|
---|
261 | if (pixel.HasLoGain() && maxcont>fLoGainSwitch)
|
---|
262 | {
|
---|
263 | Int_t first = numh+fLoGainFirst;
|
---|
264 | Int_t last = numh+fLoGainLast;
|
---|
265 |
|
---|
266 | // To determin the window in which the lo-gain is extracted
|
---|
267 | // clearly more information about the relation between the
|
---|
268 | // extraction window and the reslting time is necessary.
|
---|
269 | //
|
---|
270 | // numh + fLoGainStartShift == 14 / fLoGainStartShift=-1
|
---|
271 | //
|
---|
272 | // The lo-gain is expected to have its raising edge
|
---|
273 | // at timehi+numh+fOffsetLoGain. We start to search for the
|
---|
274 | // lo-gain fLoGainStartShift slices earlier.
|
---|
275 | //
|
---|
276 | // Instead of fLoGainStartShift the extractor should now how many
|
---|
277 | // slices before the expected raising edge the start of the
|
---|
278 | // search must be placed and from there we can step 1.5 slices
|
---|
279 | // back to be on the safe side.
|
---|
280 | //
|
---|
281 | // The jitter in the hi-/lo-gain offset ssems to be around +/-0.5
|
---|
282 | first = TMath::FloorNint(timehi+numh+fOffsetLoGain+fLoGainStartShift);
|
---|
283 | if (first<0)
|
---|
284 | first = 0;
|
---|
285 | if (first>last)
|
---|
286 | first=last;
|
---|
287 |
|
---|
288 | /*
|
---|
289 | // Currently we have to stick to this check because at least
|
---|
290 | // the spline has arrays of this size...
|
---|
291 | if (first>last)
|
---|
292 | first = last;
|
---|
293 | if (first<numh+fLoGainFirst)
|
---|
294 | first = numh+fLoGainFirst;
|
---|
295 | */
|
---|
296 | Int_t satlo0 = first; // First slice to extract and first saturating slice
|
---|
297 | Int_t satlo1 = last; // Last slice to extract and last saturating slice
|
---|
298 |
|
---|
299 | // Would it be better to take lastsat-firstsat?
|
---|
300 | Int_t maxlo;
|
---|
301 | Int_t maxposlo = fSignal->GetMax(pixidx, satlo0, satlo1, maxlo);
|
---|
302 | numsatlo = fSignal->GetSaturation(pixidx, fSaturationLimit, satlo0, satlo1);
|
---|
303 |
|
---|
304 | FindTimeAndChargeLoGain2(sig+first, last-first+1,
|
---|
305 | sumlo, deltasumlo, timelo, deltatimelo,
|
---|
306 | numsatlo, maxposlo);
|
---|
307 |
|
---|
308 | // Make sure that in cases the time couldn't be correctly determined
|
---|
309 | // more meaningfull default values are assigned
|
---|
310 | //if (timehi<fHiGainFirst || timehi>=fHiGainLast-1)
|
---|
311 | if (deltatimelo>-0.5 && (timelo<0 || timelo>=last-first+1))
|
---|
312 | timelo = gRandom->Uniform(last-first+1);
|
---|
313 |
|
---|
314 | timelo += first-numh;
|
---|
315 |
|
---|
316 | // If more than 6 lo-gain slices have saturated this is
|
---|
317 | // no physical event. We just assume that something with
|
---|
318 | // the extraction is wrong
|
---|
319 | if (numsatlo>6)
|
---|
320 | deltasumlo=deltatimelo=-1;
|
---|
321 |
|
---|
322 | //if (TMath::Abs(timelo-fOffsetLoGain - timehi)>1.0)
|
---|
323 | // deltatimelo = -1;
|
---|
324 | }
|
---|
325 |
|
---|
326 | // Now store the result in the corresponding containers
|
---|
327 | MExtractedSignalPix &pix = (*fSignals)[pixidx];
|
---|
328 | MArrivalTimePix &tix = (*fArrTime)[pixidx];
|
---|
329 | pix.SetExtractedSignal(sumhi, deltasumhi, sumlo, deltasumlo);
|
---|
330 | pix.SetGainSaturation(numsathi, numsatlo);
|
---|
331 |
|
---|
332 | tix.SetArrivalTime(timehi, deltatimehi, timelo-fOffsetLoGain, deltatimelo);
|
---|
333 | tix.SetGainSaturation(numsathi, numsatlo);
|
---|
334 | } /* while (pixel.Next()) */
|
---|
335 |
|
---|
336 | fArrTime->SetReadyToSave();
|
---|
337 | fSignals->SetReadyToSave();
|
---|
338 |
|
---|
339 | return kTRUE;
|
---|
340 | }
|
---|
341 |
|
---|
342 | // --------------------------------------------------------------------------
|
---|
343 | //
|
---|
344 | // In addition to the resources of the base-class MExtractor:
|
---|
345 | // MJPedestal.MExtractor.LoGainStartShift: -2.8
|
---|
346 | //
|
---|
347 | Int_t MExtractTimeAndCharge::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
348 | {
|
---|
349 | Bool_t rc = MExtractTime::ReadEnv(env, prefix, print);
|
---|
350 |
|
---|
351 | if (IsEnvDefined(env, prefix, "LoGainStartShift", print))
|
---|
352 | {
|
---|
353 | fLoGainStartShift = GetEnvValue(env, prefix, "LoGainStartShift", fgLoGainStartShift);
|
---|
354 | SetLoGainStartShift(fLoGainStartShift);
|
---|
355 | rc = kTRUE;
|
---|
356 | }
|
---|
357 |
|
---|
358 | if (IsEnvDefined(env, prefix, "LoGainSwitch", print))
|
---|
359 | {
|
---|
360 | fLoGainSwitch = GetEnvValue(env, prefix, "LoGainSwitch", fLoGainSwitch);
|
---|
361 | rc = kTRUE;
|
---|
362 | }
|
---|
363 |
|
---|
364 | return rc;
|
---|
365 | }
|
---|
366 |
|
---|
367 | void MExtractTimeAndCharge::Print(Option_t *o) const
|
---|
368 | {
|
---|
369 | MExtractTime::Print(o);
|
---|
370 |
|
---|
371 | *fLog << dec;
|
---|
372 | *fLog << " LoGainStartShift: " << fLoGainStartShift << endl;
|
---|
373 | *fLog << " LoGainSwitch: " << (Int_t)fLoGainSwitch << endl;
|
---|
374 | }
|
---|