source: tags/Mars-V1.0/msignal/MExtractor.cc

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