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