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 | // Input Containers:
|
---|
45 | // MRawEvtData
|
---|
46 | // MRawRunHeader
|
---|
47 | // MPedestalCam
|
---|
48 | //
|
---|
49 | // Output Containers:
|
---|
50 | // MExtractedSignalCam
|
---|
51 | //
|
---|
52 | //////////////////////////////////////////////////////////////////////////////
|
---|
53 | #include "MExtractor.h"
|
---|
54 |
|
---|
55 | #include <fstream>
|
---|
56 |
|
---|
57 | #include "MLog.h"
|
---|
58 | #include "MLogManip.h"
|
---|
59 |
|
---|
60 | #include "MParList.h"
|
---|
61 |
|
---|
62 | #include "MRawEvtData.h"
|
---|
63 | #include "MRawEvtPixelIter.h"
|
---|
64 | #include "MRawRunHeader.h"
|
---|
65 |
|
---|
66 | #include "MPedestalCam.h"
|
---|
67 | #include "MPedestalPix.h"
|
---|
68 |
|
---|
69 | #include "MExtractedSignalCam.h"
|
---|
70 | #include "MExtractedSignalPix.h"
|
---|
71 |
|
---|
72 | ClassImp(MExtractor);
|
---|
73 |
|
---|
74 | using namespace std;
|
---|
75 |
|
---|
76 | const Byte_t MExtractor::fgSaturationLimit = 254;
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Default constructor.
|
---|
81 | //
|
---|
82 | // Set:
|
---|
83 | // - all pointers to NULL
|
---|
84 | // - all variables to 0
|
---|
85 | // - fSaturationLimit to fgSaturationLimit
|
---|
86 | //
|
---|
87 | // Call:
|
---|
88 | // - AddToBranchList("MRawEvtData.*")
|
---|
89 | //
|
---|
90 | MExtractor::MExtractor(const char *name, const char *title)
|
---|
91 | : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
|
---|
92 | fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.),
|
---|
93 | fSaturationLimit(fgSaturationLimit)
|
---|
94 | {
|
---|
95 | fName = name ? name : "MExtractor";
|
---|
96 | fTitle = title ? title : "Base class for signal extractors";
|
---|
97 |
|
---|
98 | AddToBranchList("MRawEvtData.*");
|
---|
99 |
|
---|
100 | SetRange();
|
---|
101 | }
|
---|
102 |
|
---|
103 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
104 | {
|
---|
105 | fHiGainFirst = hifirst;
|
---|
106 | fHiGainLast = hilast;
|
---|
107 |
|
---|
108 | fLoGainFirst = lofirst;
|
---|
109 | fLoGainLast = lolast;
|
---|
110 | }
|
---|
111 |
|
---|
112 | // --------------------------------------------------------------------------
|
---|
113 | //
|
---|
114 | // The PreProcess searches for the following input containers:
|
---|
115 | // - MRawEvtData
|
---|
116 | // - MRawRunHeader
|
---|
117 | // - MPedestalCam
|
---|
118 | //
|
---|
119 | // The following output containers are also searched and created if
|
---|
120 | // they were not found:
|
---|
121 | //
|
---|
122 | // - MExtractedSignalCam
|
---|
123 | //
|
---|
124 | Int_t MExtractor::PreProcess(MParList *pList)
|
---|
125 | {
|
---|
126 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
127 | if (!fRawEvt)
|
---|
128 | {
|
---|
129 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
---|
134 | if (!fRunHeader)
|
---|
135 | {
|
---|
136 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
---|
137 | return kFALSE;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
---|
142 | if (!fSignals)
|
---|
143 | return kFALSE;
|
---|
144 |
|
---|
145 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
146 | if (!fPedestals)
|
---|
147 | {
|
---|
148 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
149 | return kFALSE;
|
---|
150 | }
|
---|
151 |
|
---|
152 | return kTRUE;
|
---|
153 | }
|
---|
154 |
|
---|
155 | // --------------------------------------------------------------------------
|
---|
156 | //
|
---|
157 | // The ReInit searches for:
|
---|
158 | // - MRawRunHeader::GetNumSamplesHiGain()
|
---|
159 | // - MRawRunHeader::GetNumSamplesLoGain()
|
---|
160 | //
|
---|
161 | // In case that the variable fLoGainLast is smaller than
|
---|
162 | // the even part of the number of samples obtained from the run header, a
|
---|
163 | // warning is given an the range is set back accordingly. A call to:
|
---|
164 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
---|
165 | // is performed in that case. The variable diff means here the difference
|
---|
166 | // between the requested range (fLoGainLast) and the available one. Note that
|
---|
167 | // the functions SetRange() are mostly overloaded and perform more checks,
|
---|
168 | // modifying the ranges again, if necessary.
|
---|
169 | //
|
---|
170 | // In case that the variable fHiGainLast is smaller than the available range
|
---|
171 | // obtained from the run header, a warning is given that a part of the low-gain
|
---|
172 | // samples are used for the extraction of the high-gain signal.
|
---|
173 | //
|
---|
174 | // Call:
|
---|
175 | // - MExtractedSignalCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
---|
176 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
177 | //
|
---|
178 | Bool_t MExtractor::ReInit(MParList *pList)
|
---|
179 | {
|
---|
180 | Int_t lastdesired = (Int_t)(fLoGainLast);
|
---|
181 | Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
|
---|
182 |
|
---|
183 | if (lastavailable < 0)
|
---|
184 | *fLog << warn << GetDescriptor() << " - WARNING: Number of available Low-Gain Slices is smaller than or equal zero!" << endl;
|
---|
185 |
|
---|
186 | if (lastdesired > lastavailable)
|
---|
187 | {
|
---|
188 | const Int_t diff = lastdesired - lastavailable;
|
---|
189 |
|
---|
190 | *fLog << endl;
|
---|
191 | *fLog << warn << GetDescriptor() << ": Selected Lo Gain FADC Window [";
|
---|
192 | *fLog << Form("%2i,%2i", (int)fLoGainFirst, lastdesired);
|
---|
193 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
---|
194 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
|
---|
195 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
|
---|
196 | }
|
---|
197 |
|
---|
198 | lastdesired = (Int_t)fHiGainLast;
|
---|
199 | lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
|
---|
200 |
|
---|
201 | if (lastavailable < 0)
|
---|
202 | {
|
---|
203 | *fLog << err << GetDescriptor();
|
---|
204 | *fLog << " - ERROR: Number of available High-Gain Slices is smaller than or equal zero!" << endl;
|
---|
205 | return kFALSE;
|
---|
206 | }
|
---|
207 |
|
---|
208 | if (lastdesired > lastavailable)
|
---|
209 | {
|
---|
210 | const Int_t diff = lastdesired - lastavailable;
|
---|
211 |
|
---|
212 | *fLog << endl;
|
---|
213 | *fLog << warn << GetDescriptor() << ": Selected Hi Gain FADC Window [";
|
---|
214 | *fLog << Form("%2i,%2i", (int)fHiGainFirst,lastdesired);
|
---|
215 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
---|
216 | *fLog << warn << GetDescriptor() << ": Will use ";
|
---|
217 | *fLog << Form("%2i", diff) << " samples from the Low-Gain for the High-Gain extraction";
|
---|
218 | *fLog << endl;
|
---|
219 |
|
---|
220 | fHiGainLast -= diff;
|
---|
221 | fHiLoLast = diff;
|
---|
222 | }
|
---|
223 |
|
---|
224 | return kTRUE;
|
---|
225 | }
|
---|
226 |
|
---|
227 | // --------------------------------------------------------------------------
|
---|
228 | //
|
---|
229 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
230 | // pixel in the MExtractedSignalCam container.
|
---|
231 | //
|
---|
232 | Int_t MExtractor::Process()
|
---|
233 | {
|
---|
234 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
235 | fSignals->Clear();
|
---|
236 |
|
---|
237 | while (pixel.Next())
|
---|
238 | {
|
---|
239 | Float_t sumhi = 0.;
|
---|
240 | Byte_t sathi = 0;
|
---|
241 |
|
---|
242 | FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
|
---|
243 |
|
---|
244 | Float_t sumlo = 0.;
|
---|
245 | Byte_t satlo = 0;
|
---|
246 |
|
---|
247 | if (pixel.HasLoGain())
|
---|
248 | FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
|
---|
249 |
|
---|
250 | const Int_t pixid = pixel.GetPixelId();
|
---|
251 |
|
---|
252 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
253 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
254 |
|
---|
255 | const Float_t pedes = ped.GetPedestal();
|
---|
256 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
257 |
|
---|
258 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
---|
259 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
---|
260 |
|
---|
261 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
262 |
|
---|
263 | } /* while (pixel.Next()) */
|
---|
264 |
|
---|
265 | fSignals->SetReadyToSave();
|
---|
266 |
|
---|
267 | return kTRUE;
|
---|
268 | }
|
---|
269 |
|
---|
270 | // --------------------------------------------------------------------------
|
---|
271 | //
|
---|
272 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
273 | // to a macro. In the original root implementation it is used to write
|
---|
274 | // gui elements to a macro-file.
|
---|
275 | //
|
---|
276 | void MExtractor::StreamPrimitive(ofstream &out) const
|
---|
277 | {
|
---|
278 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
279 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
280 |
|
---|
281 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
282 | {
|
---|
283 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
284 | out << (int)fSaturationLimit << ");" << endl;
|
---|
285 | }
|
---|
286 |
|
---|
287 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
288 | out << (int)fHiGainFirst;
|
---|
289 | out << ", " << (int)fHiGainLast;
|
---|
290 | out << ", " << (int)fLoGainFirst;
|
---|
291 | out << ", " << (int)fLoGainLast;
|
---|
292 | out << ");" << endl;
|
---|
293 | }
|
---|
294 |
|
---|
295 | // --------------------------------------------------------------------------
|
---|
296 | //
|
---|
297 | // Read the setup from a TEnv, eg:
|
---|
298 | // MJPedestal.MExtractor.HiGainFirst: 5
|
---|
299 | // MJPedestal.MExtractor.LoGainFirst: 5
|
---|
300 | // MJPedestal.MExtractor.HiGainLast: 10
|
---|
301 | // MJPedestal.MExtractor.LoGainLast: 10
|
---|
302 | // MJPedestal.MExtractor.SaturationLimit: 88
|
---|
303 | //
|
---|
304 | Bool_t MExtractor::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
305 | {
|
---|
306 | Byte_t hf = fHiGainFirst;
|
---|
307 | Byte_t lf = fLoGainFirst;
|
---|
308 | Byte_t hl = fHiGainLast;
|
---|
309 | Byte_t ll = fLoGainLast;
|
---|
310 |
|
---|
311 | if (IsEnvDefined(env, prefix, "HiGainFirst", print))
|
---|
312 | hf = GetEnvValue(env, prefix, "HiGainFirst", hf);
|
---|
313 | if (IsEnvDefined(env, prefix, "LoGainFirst", print))
|
---|
314 | lf = GetEnvValue(env, prefix, "LoGainFirst", lf);
|
---|
315 |
|
---|
316 | if (IsEnvDefined(env, prefix, "HiGainLast", print))
|
---|
317 | hl = GetEnvValue(env, prefix, "HiGainLast", hl);
|
---|
318 | if (IsEnvDefined(env, prefix, "LoGainLast", print))
|
---|
319 | ll = GetEnvValue(env, prefix, "LoGainLast", ll);
|
---|
320 |
|
---|
321 | SetRange(hf, hl, lf, ll);
|
---|
322 |
|
---|
323 | if (IsEnvDefined(env, prefix, "SaturationLimit", print))
|
---|
324 | SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", fSaturationLimit));
|
---|
325 |
|
---|
326 | return kTRUE;
|
---|
327 | }
|
---|