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 | // MExtractor
|
---|
27 | // ==========
|
---|
28 | //
|
---|
29 | // Base class for the signal extractors, used the functions
|
---|
30 | // FindSignalHiGain() and FindSignalLoGain() to extract the signal and
|
---|
31 | // substract the pedestal value
|
---|
32 | //
|
---|
33 | // The following variables have to be set by the derived class and
|
---|
34 | // do not have defaults:
|
---|
35 | // - fNumHiGainSamples
|
---|
36 | // - fNumLoGainSamples
|
---|
37 | // - fSqrtHiGainSamples
|
---|
38 | // - fSqrtLoGainSamples
|
---|
39 | //
|
---|
40 | // The signal extractor classes can be setup from an environmental
|
---|
41 | // setup file. For more information see ReadEnv and MEvtLoop::ReadEnv
|
---|
42 | //
|
---|
43 | //
|
---|
44 | // IMPORTANT: For all classes you derive from MExtractor make sure that:
|
---|
45 | // - Print() is correctly implemented
|
---|
46 | // - Clone() works
|
---|
47 | // - Class Version number != 0 and the I/O works PERFECTLY
|
---|
48 | // - only data members which are necessary for the setup (not the ones
|
---|
49 | // created in PreProcess and Process) are written
|
---|
50 | // - the version number is maintained!
|
---|
51 | // - If the flag fNoiseCalculation is set, the signal extractor should
|
---|
52 | // calculate the pure noise contriubtion from a fixed window in time.
|
---|
53 | //
|
---|
54 | // The following figure gives and example of possible inheritance trees.
|
---|
55 | // An extractor class can inherit from each of the following base classes:
|
---|
56 | // - MExtractor
|
---|
57 | // - MExtractTime
|
---|
58 | // - MExtractTimeAndCharge
|
---|
59 | //
|
---|
60 | //Begin_Html
|
---|
61 | /*
|
---|
62 | <img src="images/ExtractorClasses.gif">
|
---|
63 | */
|
---|
64 | //End_Html
|
---|
65 | //
|
---|
66 | // Input Containers:
|
---|
67 | // MRawEvtData
|
---|
68 | // MRawRunHeader
|
---|
69 | // MPedestalCam
|
---|
70 | //
|
---|
71 | // Output Containers:
|
---|
72 | // MExtractedSignalCam
|
---|
73 | //
|
---|
74 | //////////////////////////////////////////////////////////////////////////////
|
---|
75 | #include "MExtractor.h"
|
---|
76 |
|
---|
77 | #include <fstream>
|
---|
78 |
|
---|
79 | #include "MLog.h"
|
---|
80 | #include "MLogManip.h"
|
---|
81 |
|
---|
82 | #include "MParList.h"
|
---|
83 |
|
---|
84 | #include "MRawEvtData.h"
|
---|
85 | #include "MRawEvtPixelIter.h"
|
---|
86 | #include "MRawRunHeader.h"
|
---|
87 |
|
---|
88 | #include "MPedestalCam.h"
|
---|
89 | #include "MPedestalPix.h"
|
---|
90 |
|
---|
91 | #include "MExtractedSignalCam.h"
|
---|
92 | #include "MExtractedSignalPix.h"
|
---|
93 |
|
---|
94 | ClassImp(MExtractor);
|
---|
95 |
|
---|
96 | using namespace std;
|
---|
97 |
|
---|
98 | const Byte_t MExtractor::fgSaturationLimit = 250;
|
---|
99 | const TString MExtractor::fgNamePedestalCam = "MPedestalCam";
|
---|
100 | const TString MExtractor::fgNameSignalCam = "MExtractedSignalCam";
|
---|
101 | const Float_t MExtractor::fgOffsetLoGain = 1.51; // 5 ns
|
---|
102 | // --------------------------------------------------------------------------
|
---|
103 | //
|
---|
104 | // Default constructor.
|
---|
105 | //
|
---|
106 | // Set:
|
---|
107 | // - all pointers to NULL
|
---|
108 | // - all variables to 0
|
---|
109 | // - fSaturationLimit to fgSaturationLimit
|
---|
110 | // - fNamePedestalCam to fgNamePedestalCam
|
---|
111 | // - fNameSignalCam to fgNameSignalCam
|
---|
112 | // - fNoiseCalculation to kFALSE
|
---|
113 | //
|
---|
114 | // Call:
|
---|
115 | // - AddToBranchList("MRawEvtData.*")
|
---|
116 | //
|
---|
117 | MExtractor::MExtractor(const char *name, const char *title)
|
---|
118 | : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
|
---|
119 | fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.)
|
---|
120 | {
|
---|
121 | fName = name ? name : "MExtractor";
|
---|
122 | fTitle = title ? title : "Base class for signal extractors";
|
---|
123 |
|
---|
124 | AddToBranchList("MRawEvtData.*");
|
---|
125 |
|
---|
126 | SetNamePedestalCam();
|
---|
127 | SetNameSignalCam();
|
---|
128 | SetOffsetLoGain();
|
---|
129 | SetSaturationLimit();
|
---|
130 | SetNoiseCalculation(kFALSE);
|
---|
131 | }
|
---|
132 |
|
---|
133 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
134 | {
|
---|
135 |
|
---|
136 | Clear();
|
---|
137 |
|
---|
138 | fHiGainFirst = hifirst;
|
---|
139 | fHiGainLast = hilast;
|
---|
140 |
|
---|
141 | fLoGainFirst = lofirst;
|
---|
142 | fLoGainLast = lolast;
|
---|
143 | }
|
---|
144 |
|
---|
145 | //-----------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // - Set the variable fHiLoLast to 0 (will be initialized later in ReInit()
|
---|
148 | // - Get the pointers to:
|
---|
149 | // MRawEvtData
|
---|
150 | // MRawRunHeader
|
---|
151 | // MPedestalCam
|
---|
152 | //
|
---|
153 | Int_t MExtractor::PreProcessStd(MParList *pList)
|
---|
154 | {
|
---|
155 |
|
---|
156 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
157 | if (!fRawEvt)
|
---|
158 | {
|
---|
159 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
160 | return kFALSE;
|
---|
161 | }
|
---|
162 |
|
---|
163 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
---|
164 | if (!fRunHeader)
|
---|
165 | {
|
---|
166 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
---|
167 | return kFALSE;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | if (fPedestals)
|
---|
172 | return kTRUE;
|
---|
173 |
|
---|
174 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
|
---|
175 | if (!fPedestals)
|
---|
176 | {
|
---|
177 | *fLog << err << fNamePedestalCam << " not found... aborting" << endl;
|
---|
178 | return kFALSE;
|
---|
179 | }
|
---|
180 |
|
---|
181 | return kTRUE;
|
---|
182 | }
|
---|
183 |
|
---|
184 | // --------------------------------------------------------------------------
|
---|
185 | //
|
---|
186 | // The PreProcess searches for the following input containers:
|
---|
187 | // - MRawEvtData
|
---|
188 | // - MRawRunHeader
|
---|
189 | // - MPedestalCam
|
---|
190 | //
|
---|
191 | // The following output containers are also searched and created if
|
---|
192 | // they were not found:
|
---|
193 | //
|
---|
194 | // - MExtractedSignalCam
|
---|
195 | //
|
---|
196 | Int_t MExtractor::PreProcess(MParList *pList)
|
---|
197 | {
|
---|
198 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
|
---|
199 | if (!fSignals)
|
---|
200 | return kFALSE;
|
---|
201 |
|
---|
202 | return PreProcessStd(pList);
|
---|
203 | }
|
---|
204 |
|
---|
205 | // --------------------------------------------------------------------------
|
---|
206 | //
|
---|
207 | // The ReInit searches for:
|
---|
208 | // - MRawRunHeader::GetNumSamplesHiGain()
|
---|
209 | // - MRawRunHeader::GetNumSamplesLoGain()
|
---|
210 | //
|
---|
211 | // In case that the variable fLoGainLast is smaller than
|
---|
212 | // the even part of the number of samples obtained from the run header, a
|
---|
213 | // warning is given an the range is set back accordingly. A call to:
|
---|
214 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
---|
215 | // is performed in that case. The variable diff means here the difference
|
---|
216 | // between the requested range (fLoGainLast) and the available one. Note that
|
---|
217 | // the functions SetRange() are mostly overloaded and perform more checks,
|
---|
218 | // modifying the ranges again, if necessary.
|
---|
219 | //
|
---|
220 | // In case that the variable fHiGainLast is smaller than the available range
|
---|
221 | // obtained from the run header, a warning is given that a part of the low-gain
|
---|
222 | // samples are used for the extraction of the high-gain signal.
|
---|
223 | //
|
---|
224 | Bool_t MExtractor::ReInit(MParList *pList)
|
---|
225 | {
|
---|
226 |
|
---|
227 | const Int_t logainsamples = fRunHeader->GetNumSamplesLoGain();
|
---|
228 |
|
---|
229 | Int_t lastdesired;
|
---|
230 | Int_t lastavailable;
|
---|
231 |
|
---|
232 | if (logainsamples)
|
---|
233 | {
|
---|
234 |
|
---|
235 | lastdesired = (Int_t)(fLoGainLast);
|
---|
236 | lastavailable = logainsamples-1;
|
---|
237 |
|
---|
238 | if (lastavailable < 0)
|
---|
239 | *fLog << warn << GetDescriptor() << " - WARNING: Number of available Low-Gain Slices is smaller than or equal zero!" << endl;
|
---|
240 |
|
---|
241 | if (lastdesired > lastavailable)
|
---|
242 | {
|
---|
243 | const Int_t diff = lastdesired - lastavailable;
|
---|
244 |
|
---|
245 | *fLog << endl;
|
---|
246 | *fLog << warn << GetDescriptor() << ": Selected Lo Gain FADC Window [";
|
---|
247 | *fLog << Form("%2i,%2i", (int)fLoGainFirst, lastdesired);
|
---|
248 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
---|
249 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
|
---|
250 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
|
---|
251 | }
|
---|
252 | }
|
---|
253 | else
|
---|
254 | SetRange(fHiGainFirst, fHiGainLast, 0,0);
|
---|
255 |
|
---|
256 | const Int_t higainsamples = fRunHeader->GetNumSamplesHiGain();
|
---|
257 |
|
---|
258 | if (higainsamples <= 0)
|
---|
259 | {
|
---|
260 | *fLog << err << GetDescriptor();
|
---|
261 | *fLog << " - ERROR: Number of available High-Gain Slices is smaller than or equal zero!" << endl;
|
---|
262 | return kFALSE;
|
---|
263 | }
|
---|
264 |
|
---|
265 | lastdesired = (Int_t)fHiGainLast;
|
---|
266 | lastavailable = higainsamples-1;
|
---|
267 |
|
---|
268 | if (lastdesired > lastavailable)
|
---|
269 | {
|
---|
270 | const Int_t diff = lastdesired - lastavailable;
|
---|
271 |
|
---|
272 | *fLog << endl;
|
---|
273 | *fLog << inf << GetDescriptor() << ": Selected Hi Gain FADC Window [";
|
---|
274 | *fLog << Form("%2i,%2i", (int)fHiGainFirst,lastdesired);
|
---|
275 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
---|
276 | *fLog << inf << GetDescriptor() << ": Will use ";
|
---|
277 | *fLog << Form("%2i", diff) << " samples from the Low-Gain for the High-Gain extraction";
|
---|
278 | *fLog << endl;
|
---|
279 |
|
---|
280 | fHiGainLast -= diff;
|
---|
281 | fHiLoLast = diff;
|
---|
282 | }
|
---|
283 |
|
---|
284 | return kTRUE;
|
---|
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 |
|
---|
295 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
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 << " Gain Overlap to Lo: " << (int)fHiLoLast << endl;
|
---|
427 | *fLog << " Saturation Lim: " << (int)fSaturationLimit << endl;
|
---|
428 | *fLog << " Num Samples HiGain: " << fNumHiGainSamples << " LoGain: " << fNumLoGainSamples << endl;
|
---|
429 | }
|
---|