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 | // 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 | // Input Containers:
|
---|
41 | // MRawEvtData
|
---|
42 | // MRawRunHeader
|
---|
43 | // MPedestalCam
|
---|
44 | //
|
---|
45 | // Output Containers:
|
---|
46 | // MExtractedSignalCam
|
---|
47 | //
|
---|
48 | //////////////////////////////////////////////////////////////////////////////
|
---|
49 | #include "MExtractor.h"
|
---|
50 |
|
---|
51 | #include <fstream>
|
---|
52 |
|
---|
53 | #include "MLog.h"
|
---|
54 | #include "MLogManip.h"
|
---|
55 |
|
---|
56 | #include "MParList.h"
|
---|
57 |
|
---|
58 | #include "MRawEvtData.h"
|
---|
59 | #include "MRawEvtPixelIter.h"
|
---|
60 | #include "MRawRunHeader.h"
|
---|
61 |
|
---|
62 | #include "MPedestalCam.h"
|
---|
63 | #include "MPedestalPix.h"
|
---|
64 |
|
---|
65 | #include "MExtractedSignalCam.h"
|
---|
66 | #include "MExtractedSignalPix.h"
|
---|
67 |
|
---|
68 | ClassImp(MExtractor);
|
---|
69 |
|
---|
70 | using namespace std;
|
---|
71 |
|
---|
72 | const Byte_t MExtractor::fgSaturationLimit = 254;
|
---|
73 | // --------------------------------------------------------------------------
|
---|
74 | //
|
---|
75 | // Default constructor.
|
---|
76 | //
|
---|
77 | // Set:
|
---|
78 | // - all pointers to NULL
|
---|
79 | // - all variables to 0
|
---|
80 | // - fSaturationLimit to fgSaturationLimit
|
---|
81 | //
|
---|
82 | // Call:
|
---|
83 | // - AddToBranchList("MRawEvtData.*")
|
---|
84 | //
|
---|
85 | MExtractor::MExtractor(const char *name, const char *title)
|
---|
86 | : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
|
---|
87 | fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.),
|
---|
88 | fSaturationLimit(fgSaturationLimit)
|
---|
89 | {
|
---|
90 |
|
---|
91 | fName = name ? name : "MExtractor";
|
---|
92 | fTitle = title ? title : "Base class for signal extractors";
|
---|
93 |
|
---|
94 | AddToBranchList("MRawEvtData.*");
|
---|
95 |
|
---|
96 | SetRange();
|
---|
97 | }
|
---|
98 |
|
---|
99 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
100 | {
|
---|
101 |
|
---|
102 | fHiGainFirst = hifirst;
|
---|
103 | fHiGainLast = hilast;
|
---|
104 |
|
---|
105 | fLoGainFirst = lofirst;
|
---|
106 | fLoGainLast = lolast;
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | // --------------------------------------------------------------------------
|
---|
112 | //
|
---|
113 | // The PreProcess searches for the following input containers:
|
---|
114 | // - MRawEvtData
|
---|
115 | // - MRawRunHeader
|
---|
116 | // - MPedestalCam
|
---|
117 | //
|
---|
118 | // The following output containers are also searched and created if
|
---|
119 | // they were not found:
|
---|
120 | //
|
---|
121 | // - MExtractedSignalCam
|
---|
122 | //
|
---|
123 | Int_t MExtractor::PreProcess(MParList *pList)
|
---|
124 | {
|
---|
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 |
|
---|
181 | Int_t lastdesired = (Int_t)(fLoGainLast);
|
---|
182 | Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
|
---|
183 |
|
---|
184 | if (lastdesired > lastavailable)
|
---|
185 | {
|
---|
186 | const Int_t diff = lastdesired - lastavailable;
|
---|
187 | *fLog << endl;
|
---|
188 | *fLog << warn << GetDescriptor()
|
---|
189 | << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [",
|
---|
190 | (int)fLoGainFirst,",",lastdesired,
|
---|
191 | "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
|
---|
192 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
|
---|
193 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
|
---|
194 | }
|
---|
195 |
|
---|
196 | lastdesired = (Int_t)fHiGainLast;
|
---|
197 | lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
|
---|
198 |
|
---|
199 | if (lastdesired > lastavailable)
|
---|
200 | {
|
---|
201 | const Int_t diff = lastdesired - lastavailable;
|
---|
202 | *fLog << endl;
|
---|
203 | *fLog << warn << GetDescriptor()
|
---|
204 | << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
|
---|
205 | (int)fHiGainFirst,",",lastdesired,
|
---|
206 | "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
|
---|
207 | *fLog << warn << GetDescriptor()
|
---|
208 | << Form("%s%2i%s",": Will use ",diff," samples from the Low-Gain for the High-Gain extraction")
|
---|
209 | << endl;
|
---|
210 | fHiGainLast -= diff;
|
---|
211 | fHiLoLast = diff;
|
---|
212 | }
|
---|
213 |
|
---|
214 | return kTRUE;
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 |
|
---|
219 | void MExtractor::FindSignalHiGain(Byte_t *firstused, Byte_t *logain, Int_t &sum, Byte_t &sat) const
|
---|
220 | {
|
---|
221 | return;
|
---|
222 | }
|
---|
223 |
|
---|
224 | void MExtractor::FindSignalLoGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
|
---|
225 | {
|
---|
226 | return;
|
---|
227 | }
|
---|
228 |
|
---|
229 | // --------------------------------------------------------------------------
|
---|
230 | //
|
---|
231 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
232 | // pixel in the MExtractedSignalCam container.
|
---|
233 | //
|
---|
234 | Int_t MExtractor::Process()
|
---|
235 | {
|
---|
236 |
|
---|
237 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
238 | fSignals->Clear();
|
---|
239 |
|
---|
240 | while (pixel.Next())
|
---|
241 | {
|
---|
242 | Int_t sumhi = 0;
|
---|
243 | Byte_t sathi = 0;
|
---|
244 |
|
---|
245 | FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
|
---|
246 |
|
---|
247 | Int_t sumlo = 0;
|
---|
248 | Byte_t satlo = 0;
|
---|
249 |
|
---|
250 | if (pixel.HasLoGain())
|
---|
251 | FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
|
---|
252 |
|
---|
253 | const Int_t pixid = pixel.GetPixelId();
|
---|
254 |
|
---|
255 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
256 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
257 |
|
---|
258 | const Float_t pedes = ped.GetPedestal();
|
---|
259 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
260 |
|
---|
261 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
---|
262 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
---|
263 |
|
---|
264 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
265 |
|
---|
266 | } /* while (pixel.Next()) */
|
---|
267 |
|
---|
268 | fSignals->SetReadyToSave();
|
---|
269 |
|
---|
270 | return kTRUE;
|
---|
271 | }
|
---|
272 |
|
---|
273 | // --------------------------------------------------------------------------
|
---|
274 | //
|
---|
275 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
276 | // to a macro. In the original root implementation it is used to write
|
---|
277 | // gui elements to a macro-file.
|
---|
278 | //
|
---|
279 | void MExtractor::StreamPrimitive(ofstream &out) const
|
---|
280 | {
|
---|
281 |
|
---|
282 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
283 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
284 |
|
---|
285 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
286 | {
|
---|
287 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
288 | out << (int)fSaturationLimit << ");" << endl;
|
---|
289 | }
|
---|
290 |
|
---|
291 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
292 | out << (int)fHiGainFirst;
|
---|
293 | out << ", " << (int)fHiGainLast;
|
---|
294 | out << ", " << (int)fLoGainFirst;
|
---|
295 | out << ", " << (int)fLoGainLast;
|
---|
296 | out << ");" << endl;
|
---|
297 | }
|
---|
298 |
|
---|