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, 04/2004 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MExtractor
|
---|
28 | // ==========
|
---|
29 | //
|
---|
30 | // Base class for the signal extractors, used the functions
|
---|
31 | // FindSignalHiGain() and FindSignalLoGain() to extract the signal and
|
---|
32 | // substract the pedestal value
|
---|
33 | //
|
---|
34 | // The following variables have to be set by the derived class and
|
---|
35 | // do not have defaults:
|
---|
36 | // - fNumHiGainSamples
|
---|
37 | // - fNumLoGainSamples
|
---|
38 | // - fSqrtHiGainSamples
|
---|
39 | // - fSqrtLoGainSamples
|
---|
40 | //
|
---|
41 | // The signal extractor classes can be setup from an environmental
|
---|
42 | // setup file. For more information see ReadEnv and MEvtLoop::ReadEnv
|
---|
43 | //
|
---|
44 | //
|
---|
45 | // IMPORTANT: For all classes you derive from MExtractor make sure that:
|
---|
46 | // - Print() is correctly implemented
|
---|
47 | // - Clone() works
|
---|
48 | // - Class Version number != 0 and the I/O works PERFECTLY
|
---|
49 | // - only data members which are necessary for the setup (not the ones
|
---|
50 | // created in PreProcess and Process) are written
|
---|
51 | // - the version number is maintained!
|
---|
52 | // - If the flag fNoiseCalculation is set, the signal extractor should
|
---|
53 | // calculate the pure noise contriubtion from a fixed window in time.
|
---|
54 | //
|
---|
55 | //
|
---|
56 | // Input Containers:
|
---|
57 | // MRawEvtData
|
---|
58 | // MRawRunHeader
|
---|
59 | // MPedestalCam
|
---|
60 | //
|
---|
61 | // Output Containers:
|
---|
62 | // MExtractedSignalCam
|
---|
63 | //
|
---|
64 | //////////////////////////////////////////////////////////////////////////////
|
---|
65 | #include "MExtractor.h"
|
---|
66 |
|
---|
67 | #include <fstream>
|
---|
68 |
|
---|
69 | #include "MLog.h"
|
---|
70 | #include "MLogManip.h"
|
---|
71 |
|
---|
72 | #include "MParList.h"
|
---|
73 |
|
---|
74 | #include "MRawEvtData.h"
|
---|
75 | #include "MRawEvtPixelIter.h"
|
---|
76 | #include "MRawRunHeader.h"
|
---|
77 |
|
---|
78 | #include "MPedestalCam.h"
|
---|
79 | #include "MPedestalPix.h"
|
---|
80 |
|
---|
81 | #include "MExtractedSignalCam.h"
|
---|
82 | #include "MExtractedSignalPix.h"
|
---|
83 |
|
---|
84 | ClassImp(MExtractor);
|
---|
85 |
|
---|
86 | using namespace std;
|
---|
87 |
|
---|
88 | const Byte_t MExtractor::fgSaturationLimit = 254;
|
---|
89 | const TString MExtractor::fgNamePedestalCam = "MPedestalCam";
|
---|
90 | const Float_t MExtractor::fgOffsetLoGain = 1.51; // 5 ns
|
---|
91 | // --------------------------------------------------------------------------
|
---|
92 | //
|
---|
93 | // Default constructor.
|
---|
94 | //
|
---|
95 | // Set:
|
---|
96 | // - all pointers to NULL
|
---|
97 | // - all variables to 0
|
---|
98 | // - fSaturationLimit to fgSaturationLimit
|
---|
99 | // - fNamePedestalCam to fgNamePedestalCam
|
---|
100 | // - fNoiseCalculation to kFALSE
|
---|
101 | //
|
---|
102 | // Call:
|
---|
103 | // - AddToBranchList("MRawEvtData.*")
|
---|
104 | //
|
---|
105 | MExtractor::MExtractor(const char *name, const char *title)
|
---|
106 | : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
|
---|
107 | fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.)
|
---|
108 | {
|
---|
109 | fName = name ? name : "MExtractor";
|
---|
110 | fTitle = title ? title : "Base class for signal extractors";
|
---|
111 |
|
---|
112 | AddToBranchList("MRawEvtData.*");
|
---|
113 |
|
---|
114 | SetNamePedestalCam();
|
---|
115 | SetOffsetLoGain();
|
---|
116 | SetRange();
|
---|
117 | SetSaturationLimit();
|
---|
118 | SetNoiseCalculation(kFALSE);
|
---|
119 | }
|
---|
120 |
|
---|
121 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
122 | {
|
---|
123 | fHiGainFirst = hifirst;
|
---|
124 | fHiGainLast = hilast;
|
---|
125 |
|
---|
126 | fLoGainFirst = lofirst;
|
---|
127 | fLoGainLast = lolast;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // The PreProcess searches for the following input containers:
|
---|
133 | // - MRawEvtData
|
---|
134 | // - MRawRunHeader
|
---|
135 | // - MPedestalCam
|
---|
136 | //
|
---|
137 | // The following output containers are also searched and created if
|
---|
138 | // they were not found:
|
---|
139 | //
|
---|
140 | // - MExtractedSignalCam
|
---|
141 | //
|
---|
142 | Int_t MExtractor::PreProcess(MParList *pList)
|
---|
143 | {
|
---|
144 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
145 | if (!fRawEvt)
|
---|
146 | {
|
---|
147 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
148 | return kFALSE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
---|
152 | if (!fRunHeader)
|
---|
153 | {
|
---|
154 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
---|
155 | return kFALSE;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
|
---|
160 | if (!fPedestals)
|
---|
161 | {
|
---|
162 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
163 | return kFALSE;
|
---|
164 | }
|
---|
165 |
|
---|
166 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
---|
167 | if (!fSignals)
|
---|
168 | return kFALSE;
|
---|
169 |
|
---|
170 | return kTRUE;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // --------------------------------------------------------------------------
|
---|
174 | //
|
---|
175 | // The ReInit searches for:
|
---|
176 | // - MRawRunHeader::GetNumSamplesHiGain()
|
---|
177 | // - MRawRunHeader::GetNumSamplesLoGain()
|
---|
178 | //
|
---|
179 | // In case that the variable fLoGainLast is smaller than
|
---|
180 | // the even part of the number of samples obtained from the run header, a
|
---|
181 | // warning is given an the range is set back accordingly. A call to:
|
---|
182 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
---|
183 | // is performed in that case. The variable diff means here the difference
|
---|
184 | // between the requested range (fLoGainLast) and the available one. Note that
|
---|
185 | // the functions SetRange() are mostly overloaded and perform more checks,
|
---|
186 | // modifying the ranges again, if necessary.
|
---|
187 | //
|
---|
188 | // In case that the variable fHiGainLast is smaller than the available range
|
---|
189 | // obtained from the run header, a warning is given that a part of the low-gain
|
---|
190 | // samples are used for the extraction of the high-gain signal.
|
---|
191 | //
|
---|
192 | // Call:
|
---|
193 | // - MExtractedSignalCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
---|
194 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
195 | //
|
---|
196 | Bool_t MExtractor::ReInit(MParList *pList)
|
---|
197 | {
|
---|
198 |
|
---|
199 | const Int_t logainsamples = fRunHeader->GetNumSamplesLoGain();
|
---|
200 |
|
---|
201 | Int_t lastdesired;
|
---|
202 | Int_t lastavailable;
|
---|
203 |
|
---|
204 | if (logainsamples)
|
---|
205 | {
|
---|
206 |
|
---|
207 | lastdesired = (Int_t)(fLoGainLast);
|
---|
208 | lastavailable = logainsamples-1;
|
---|
209 |
|
---|
210 | if (lastavailable < 0)
|
---|
211 | *fLog << warn << GetDescriptor() << " - WARNING: Number of available Low-Gain Slices is smaller than or equal zero!" << endl;
|
---|
212 |
|
---|
213 | if (lastdesired > lastavailable)
|
---|
214 | {
|
---|
215 | const Int_t diff = lastdesired - lastavailable;
|
---|
216 |
|
---|
217 | *fLog << endl;
|
---|
218 | *fLog << warn << GetDescriptor() << ": Selected Lo Gain FADC Window [";
|
---|
219 | *fLog << Form("%2i,%2i", (int)fLoGainFirst, lastdesired);
|
---|
220 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
---|
221 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
|
---|
222 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
|
---|
223 | }
|
---|
224 | }
|
---|
225 | else
|
---|
226 | SetRange(fHiGainFirst, fHiGainLast, 0,0);
|
---|
227 |
|
---|
228 | const Int_t higainsamples = fRunHeader->GetNumSamplesHiGain();
|
---|
229 |
|
---|
230 | if (higainsamples <= 0)
|
---|
231 | {
|
---|
232 | *fLog << err << GetDescriptor();
|
---|
233 | *fLog << " - ERROR: Number of available High-Gain Slices is smaller than or equal zero!" << endl;
|
---|
234 | return kFALSE;
|
---|
235 | }
|
---|
236 |
|
---|
237 | lastdesired = (Int_t)fHiGainLast;
|
---|
238 | lastavailable = higainsamples-1;
|
---|
239 |
|
---|
240 | if (lastdesired > lastavailable)
|
---|
241 | {
|
---|
242 | const Int_t diff = lastdesired - lastavailable;
|
---|
243 |
|
---|
244 | *fLog << endl;
|
---|
245 | *fLog << warn << GetDescriptor() << ": Selected Hi Gain FADC Window [";
|
---|
246 | *fLog << Form("%2i,%2i", (int)fHiGainFirst,lastdesired);
|
---|
247 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
---|
248 | *fLog << warn << GetDescriptor() << ": Will use ";
|
---|
249 | *fLog << Form("%2i", diff) << " samples from the Low-Gain for the High-Gain extraction";
|
---|
250 | *fLog << endl;
|
---|
251 |
|
---|
252 | fHiGainLast -= diff;
|
---|
253 | fHiLoLast = diff;
|
---|
254 | }
|
---|
255 |
|
---|
256 | return kTRUE;
|
---|
257 | }
|
---|
258 |
|
---|
259 |
|
---|
260 | /*
|
---|
261 | void MExtractor::FindPedestalLoGain(Byte_t *maxpos, Float_t &sum) const
|
---|
262 | {
|
---|
263 |
|
---|
264 | Byte_t *p = maxpos-4;
|
---|
265 | Byte_t *end = maxpos-2;
|
---|
266 |
|
---|
267 | Int_t summ = 0;
|
---|
268 |
|
---|
269 | while (p<end)
|
---|
270 | summ += *p++;
|
---|
271 |
|
---|
272 | sum = summ/2.;
|
---|
273 |
|
---|
274 | return;
|
---|
275 | }
|
---|
276 | */
|
---|
277 | // --------------------------------------------------------------------------
|
---|
278 | //
|
---|
279 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
280 | // pixel in the MExtractedSignalCam container.
|
---|
281 | //
|
---|
282 | Int_t MExtractor::Process()
|
---|
283 | {
|
---|
284 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
285 | fSignals->Clear();
|
---|
286 |
|
---|
287 | while (pixel.Next())
|
---|
288 | {
|
---|
289 | Float_t sumhi = 0.;
|
---|
290 | Byte_t sathi = 0;
|
---|
291 |
|
---|
292 | FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
|
---|
293 |
|
---|
294 | Float_t sumlo = 0.;
|
---|
295 | Byte_t satlo = 0;
|
---|
296 |
|
---|
297 | if (pixel.HasLoGain())
|
---|
298 | FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
|
---|
299 |
|
---|
300 | const Int_t pixid = pixel.GetPixelId();
|
---|
301 |
|
---|
302 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
303 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
304 |
|
---|
305 | const Float_t pedes = ped.GetPedestal();
|
---|
306 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
307 |
|
---|
308 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
---|
309 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
---|
310 |
|
---|
311 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
312 |
|
---|
313 | } /* while (pixel.Next()) */
|
---|
314 |
|
---|
315 | fSignals->SetReadyToSave();
|
---|
316 |
|
---|
317 | return kTRUE;
|
---|
318 | }
|
---|
319 |
|
---|
320 | // --------------------------------------------------------------------------
|
---|
321 | //
|
---|
322 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
323 | // to a macro. In the original root implementation it is used to write
|
---|
324 | // gui elements to a macro-file.
|
---|
325 | //
|
---|
326 | void MExtractor::StreamPrimitive(ofstream &out) const
|
---|
327 | {
|
---|
328 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
329 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
330 |
|
---|
331 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
332 | {
|
---|
333 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
334 | out << (int)fSaturationLimit << ");" << endl;
|
---|
335 | }
|
---|
336 |
|
---|
337 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
338 | out << (int)fHiGainFirst;
|
---|
339 | out << ", " << (int)fHiGainLast;
|
---|
340 | out << ", " << (int)fLoGainFirst;
|
---|
341 | out << ", " << (int)fLoGainLast;
|
---|
342 | out << ");" << endl;
|
---|
343 | }
|
---|
344 |
|
---|
345 | // --------------------------------------------------------------------------
|
---|
346 | //
|
---|
347 | // Read the setup from a TEnv, eg:
|
---|
348 | // MJPedestal.MExtractor.HiGainFirst: 5
|
---|
349 | // MJPedestal.MExtractor.LoGainFirst: 5
|
---|
350 | // MJPedestal.MExtractor.HiGainLast: 10
|
---|
351 | // MJPedestal.MExtractor.LoGainLast: 10
|
---|
352 | // MJPedestal.MExtractor.SaturationLimit: 88
|
---|
353 | //
|
---|
354 | Int_t MExtractor::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
355 | {
|
---|
356 | Byte_t hf = fHiGainFirst;
|
---|
357 | Byte_t lf = fLoGainFirst;
|
---|
358 | Byte_t hl = fHiGainLast;
|
---|
359 | Byte_t ll = fLoGainLast;
|
---|
360 |
|
---|
361 | Bool_t rc = kFALSE;
|
---|
362 |
|
---|
363 | if (IsEnvDefined(env, prefix, "HiGainFirst", print))
|
---|
364 | {
|
---|
365 | hf = GetEnvValue(env, prefix, "HiGainFirst", hf);
|
---|
366 | rc = kTRUE;
|
---|
367 | }
|
---|
368 | if (IsEnvDefined(env, prefix, "LoGainFirst", print))
|
---|
369 | {
|
---|
370 | lf = GetEnvValue(env, prefix, "LoGainFirst", lf);
|
---|
371 | rc = kTRUE;
|
---|
372 | }
|
---|
373 |
|
---|
374 | if (IsEnvDefined(env, prefix, "HiGainLast", print))
|
---|
375 | {
|
---|
376 | hl = GetEnvValue(env, prefix, "HiGainLast", hl);
|
---|
377 | rc = kTRUE;
|
---|
378 | }
|
---|
379 | if (IsEnvDefined(env, prefix, "LoGainLast", print))
|
---|
380 | {
|
---|
381 | ll = GetEnvValue(env, prefix, "LoGainLast", ll);
|
---|
382 | rc = kTRUE;
|
---|
383 | }
|
---|
384 |
|
---|
385 | SetRange(hf, hl, lf, ll);
|
---|
386 |
|
---|
387 | if (IsEnvDefined(env, prefix, "OffsetLoGain", print))
|
---|
388 | {
|
---|
389 | SetOffsetLoGain(GetEnvValue(env, prefix, "OffsetLoGain", fOffsetLoGain));
|
---|
390 | rc = kTRUE;
|
---|
391 | }
|
---|
392 |
|
---|
393 | if (IsEnvDefined(env, prefix, "SaturationLimit", print))
|
---|
394 | {
|
---|
395 | SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", fSaturationLimit));
|
---|
396 | rc = kTRUE;
|
---|
397 | }
|
---|
398 |
|
---|
399 | if (IsEnvDefined(env, prefix, "NoiseCalculation", print))
|
---|
400 | {
|
---|
401 | SetNoiseCalculation(GetEnvValue(env, prefix, "NoiseCalculation", fNoiseCalculation));
|
---|
402 | rc = kTRUE;
|
---|
403 | }
|
---|
404 |
|
---|
405 | // Be carefull: Returning kERROR is not forseen in derived classes
|
---|
406 | return rc;
|
---|
407 | }
|
---|
408 |
|
---|
409 | void MExtractor::Print(Option_t *o) const
|
---|
410 | {
|
---|
411 | *fLog << all;
|
---|
412 |
|
---|
413 | if (IsA()==MExtractor::Class())
|
---|
414 | *fLog << GetDescriptor() << ":" << endl;
|
---|
415 |
|
---|
416 | *fLog << " Hi Gain Range: " << (int)fHiGainFirst << " " << (int)fHiGainLast << endl;
|
---|
417 | *fLog << " Lo Gain Range: " << (int)fLoGainFirst << " " << (int)fLoGainLast << endl;
|
---|
418 | *fLog << " Num Samples Hi: " << fNumHiGainSamples << endl;
|
---|
419 | *fLog << " Num Samples Lo: " << fNumHiGainSamples << endl;
|
---|
420 | *fLog << " Saturation Lim: " << (int)fSaturationLimit << endl;
|
---|
421 | }
|
---|