source: trunk/MagicSoft/Mars/msignal/MExtractor.cc@ 9366

Last change on this file since 9366 was 9069, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 11.3 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! Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2007
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// The following figure gives and example of possible inheritance trees.
56// An extractor class can inherit from each of the following base classes:
57// - MExtractor
58// - MExtractTime
59// - MExtractTimeAndCharge
60//
61//Begin_Html
62/*
63<img src="images/ExtractorClasses.gif">
64*/
65//End_Html
66//
67//
68// Class Version 6:
69// ----------------
70// + Float_t fResolutionPerPheHiGain; // Extractor-dependent charge resolution per phe for high-gain (see TDAS-0502).
71// + Float_t fResolutionPerPheLoGain; // Extractor-dependent charge resolution per phe for low-gain (see TDAS-0502).
72//
73// Class Version 7:
74// ----------------
75// - Byte_t fHiLoLast; // Number of slices in fLoGainSamples counted for the High-Gain signal
76//
77// Class Version 8:
78// ----------------
79// - Byte_t fSaturationLimit;
80// + Uint_t fSaturationLimit;
81//
82// Class Version 9:
83// ----------------
84// - MPedestalCam fPedestals
85//
86//
87// Input Containers:
88// MRawEvtData
89// MRawRunHeader
90// MPedestalCam
91//
92// Output Containers:
93// MExtractedSignalCam
94//
95//////////////////////////////////////////////////////////////////////////////
96#include "MExtractor.h"
97
98#include <fstream>
99
100#include "MLog.h"
101#include "MLogManip.h"
102
103#include "MParList.h"
104
105#include "MRawEvtData.h"
106#include "MRawEvtPixelIter.h"
107#include "MRawRunHeader.h"
108
109#include "MPedestalCam.h"
110#include "MPedestalPix.h"
111//#include "MPedestalSubtractEvt.h"
112
113#include "MExtractedSignalCam.h"
114#include "MExtractedSignalPix.h"
115
116ClassImp(MExtractor);
117
118using namespace std;
119
120const UInt_t MExtractor::fgSaturationLimit = 245;
121const char *MExtractor::fgNameSignalCam = "MExtractedSignalCam";
122const Float_t MExtractor::fgOffsetLoGain = 1.51; // 5 ns
123
124// --------------------------------------------------------------------------
125//
126// Default constructor.
127//
128// Set:
129// - all pointers to NULL
130// - all variables to 0
131// - fSaturationLimit to fgSaturationLimit
132// - fNameSignalCam to fgNameSignalCam
133// - fNoiseCalculation to kFALSE
134//
135MExtractor::MExtractor(const char *name, const char *title)
136 : fResolutionPerPheHiGain(0), fResolutionPerPheLoGain(0),
137 fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL), fSignal(NULL),
138 fLoGainLast(0), fNumHiGainSamples(0), fNumLoGainSamples(0)
139{
140 fName = name ? name : "MExtractor";
141 fTitle = title ? title : "Base class for signal extractors";
142
143 SetNameSignalCam();
144 SetOffsetLoGain();
145 SetSaturationLimit();
146 SetNoiseCalculation(kFALSE);
147}
148
149void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Int_t lofirst, Byte_t lolast)
150{
151 fHiGainFirst = hifirst;
152 fHiGainLast = hilast;
153
154 fLoGainFirst = lofirst;
155 fLoGainLast = lolast;
156}
157
158//-----------------------------------------------------------------------
159//
160// - Set the variable fHiLoLast to 0 (will be initialized later in ReInit()
161// - Get the pointers to:
162// MRawEvtData
163// MRawRunHeader
164//
165Int_t MExtractor::PreProcessStd(MParList *pList)
166{
167
168 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
169 if (!fRawEvt)
170 {
171 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
172 return kFALSE;
173 }
174
175 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
176 if (!fRunHeader)
177 {
178 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
179 return kFALSE;
180 }
181
182 fSignal = (MPedestalSubtractedEvt*)pList->FindObject(AddSerialNumber("MPedestalSubtractedEvt"));
183 if (!fSignal)
184 {
185 *fLog << err << AddSerialNumber("MPedestalSubtractedEvt") << " not found... aborting." << endl;
186 return kFALSE;
187 }
188
189 return kTRUE;
190}
191
192// --------------------------------------------------------------------------
193//
194// The PreProcess searches for the following input containers:
195// - MRawEvtData
196// - MRawRunHeader
197//
198// The following output containers are also searched and created if
199// they were not found:
200//
201// - MExtractedSignalCam
202//
203Int_t MExtractor::PreProcess(MParList *pList)
204{
205 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam",AddSerialNumber(fNameSignalCam));
206 if (!fSignals)
207 return kFALSE;
208
209 return PreProcessStd(pList);
210}
211
212// --------------------------------------------------------------------------
213//
214// The ReInit searches for:
215// - MRawRunHeader::GetNumSamplesHiGain()
216// - MRawRunHeader::GetNumSamplesLoGain()
217//
218// In case that the variable fLoGainLast is smaller than
219// the even part of the number of samples obtained from the run header, a
220// warning is given an the range is set back accordingly. A call to:
221// - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
222// is performed in that case. The variable diff means here the difference
223// between the requested range (fLoGainLast) and the available one. Note that
224// the functions SetRange() are mostly overloaded and perform more checks,
225// modifying the ranges again, if necessary.
226//
227// In case that the variable fHiGainLast is smaller than the available range
228// obtained from the run header, a warning is given that a part of the low-gain
229// samples are used for the extraction of the high-gain signal.
230//
231Bool_t MExtractor::ReInit(MParList *pList)
232{
233 const Int_t numl = fRunHeader->GetNumSamplesLoGain();
234 const Int_t numh = fRunHeader->GetNumSamplesHiGain();
235 const Int_t num = numh+numl;
236
237 if (fHiGainLast>=num)
238 {
239 *fLog << err << "MExtractor: ERROR - Last hi-gain slice " << (int)fHiGainLast << " must not exceed " << num-1 << endl;
240 return kFALSE;
241 }
242 if (fLoGainLast>=num)
243 {
244 *fLog << err << "MExtractor: ERROR - Last lo-gain slice " << (int)fLoGainLast << " must not exceed " << num-1 << endl;
245 return kFALSE;
246 }
247
248 if (numl==0)
249 {
250 *fLog << inf << "No lo-gains... resetting lo-gain range";
251 fLoGainFirst=0;
252 fLoGainLast =0;
253 *fLog << "." << endl;
254 }
255
256 return kTRUE;
257}
258
259// --------------------------------------------------------------------------
260//
261// Calculate the integral of the FADC time slices and store them as a new
262// pixel in the MExtractedSignalCam container.
263//
264Int_t MExtractor::Process()
265{
266 return kERROR;
267}
268
269// --------------------------------------------------------------------------
270//
271// Implementation of SavePrimitive. Used to write the call to a constructor
272// to a macro. In the original root implementation it is used to write
273// gui elements to a macro-file.
274//
275void MExtractor::StreamPrimitive(ostream &out) const
276{
277 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
278 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
279
280 if (fSaturationLimit!=fgSaturationLimit)
281 {
282 out << " " << GetUniqueName() << ".SetSaturationLimit(";
283 out << (int)fSaturationLimit << ");" << endl;
284 }
285
286 out << " " << GetUniqueName() << ".SetRange(";
287 out << (int)fHiGainFirst;
288 out << ", " << (int)fHiGainLast;
289 out << ", " << (int)fLoGainFirst;
290 out << ", " << (int)fLoGainLast;
291 out << ");" << endl;
292}
293
294// --------------------------------------------------------------------------
295//
296// Read the setup from a TEnv, eg:
297// MJPedestal.MExtractor.HiGainFirst: 5
298// MJPedestal.MExtractor.LoGainFirst: 5
299// MJPedestal.MExtractor.HiGainLast: 10
300// MJPedestal.MExtractor.LoGainLast: 10
301// MJPedestal.MExtractor.SaturationLimit: 88
302//
303Int_t MExtractor::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
304{
305 Byte_t hf = fHiGainFirst;
306 Int_t lf = fLoGainFirst;
307 Byte_t hl = fHiGainLast;
308 Byte_t ll = fLoGainLast;
309
310 Bool_t rc = kFALSE;
311
312 if (IsEnvDefined(env, prefix, "HiGainFirst", print))
313 {
314 hf = GetEnvValue(env, prefix, "HiGainFirst", hf);
315 rc = kTRUE;
316 }
317 if (IsEnvDefined(env, prefix, "LoGainFirst", print))
318 {
319 lf = GetEnvValue(env, prefix, "LoGainFirst", lf);
320 rc = kTRUE;
321 }
322
323 if (IsEnvDefined(env, prefix, "HiGainLast", print))
324 {
325 hl = GetEnvValue(env, prefix, "HiGainLast", hl);
326 rc = kTRUE;
327 }
328 if (IsEnvDefined(env, prefix, "LoGainLast", print))
329 {
330 ll = GetEnvValue(env, prefix, "LoGainLast", ll);
331 rc = kTRUE;
332 }
333
334 SetRange(hf, hl, lf, ll);
335
336 if (IsEnvDefined(env, prefix, "OffsetLoGain", print))
337 {
338 SetOffsetLoGain(GetEnvValue(env, prefix, "OffsetLoGain", fOffsetLoGain));
339 rc = kTRUE;
340 }
341
342 if (IsEnvDefined(env, prefix, "SaturationLimit", print))
343 {
344 SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", (Int_t)fSaturationLimit));
345 rc = kTRUE;
346 }
347
348 if (IsEnvDefined(env, prefix, "NoiseCalculation", print))
349 {
350 SetNoiseCalculation(GetEnvValue(env, prefix, "NoiseCalculation", fNoiseCalculation));
351 rc = kTRUE;
352 }
353
354 // Be carefull: Returning kERROR is not forseen in derived classes
355 return rc;
356}
357
358void MExtractor::Print(Option_t *o) const
359{
360 *fLog << GetDescriptor() << ":" << endl;
361
362 *fLog << " Hi Gain Range: " << Form("%2d %2d", fHiGainFirst, fHiGainLast) << endl;
363 *fLog << " Saturation Lim: " << Form("%3d", fSaturationLimit) << endl;
364 if (HasLoGain())
365 {
366 *fLog << " Lo Gain Range: " << Form("%2d %2d", fLoGainFirst, fLoGainLast) << endl;
367 *fLog << " Num Samples Hi/Lo: " << Form("%2.1f %2.1f", fNumHiGainSamples, fNumLoGainSamples) << endl;
368 }
369}
Note: See TracBrowser for help on using the repository browser.