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, 09/2003 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MExtractSignal
|
---|
28 | //
|
---|
29 | //////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MExtractSignal.h"
|
---|
31 |
|
---|
32 | #include <fstream>
|
---|
33 |
|
---|
34 | #include "MLog.h"
|
---|
35 | #include "MLogManip.h"
|
---|
36 |
|
---|
37 | #include "MParList.h"
|
---|
38 | #include "MGeomCam.h"
|
---|
39 |
|
---|
40 | #include "MRawEvtData.h"
|
---|
41 | #include "MRawEvtPixelIter.h"
|
---|
42 |
|
---|
43 | #include "MPedestalCam.h"
|
---|
44 | #include "MPedestalPix.h"
|
---|
45 |
|
---|
46 | #include "MExtractedSignalCam.h"
|
---|
47 | #include "MExtractedSignalPix.h"
|
---|
48 |
|
---|
49 | ClassImp(MExtractSignal);
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 |
|
---|
53 | const Byte_t MExtractSignal::fgSaturationLimit = 254;
|
---|
54 | const Byte_t MExtractSignal::fgFirst = 3;
|
---|
55 | const Byte_t MExtractSignal::fgLast = 10;
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Default constructor.
|
---|
60 | //
|
---|
61 | MExtractSignal::MExtractSignal(const char *name, const char *title)
|
---|
62 | : fSaturationLimit(fgSaturationLimit)
|
---|
63 | {
|
---|
64 |
|
---|
65 | fName = name ? name : "MExtractSignal";
|
---|
66 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
67 |
|
---|
68 | AddToBranchList("MRawEvtData.*");
|
---|
69 |
|
---|
70 | SetRange();
|
---|
71 | }
|
---|
72 |
|
---|
73 | void MExtractSignal::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
74 | {
|
---|
75 |
|
---|
76 | fNumHiGainSamples = hilast-hifirst+1;
|
---|
77 | fNumLoGainSamples = lolast-lofirst+1;
|
---|
78 |
|
---|
79 | fHiGainFirst = hifirst;
|
---|
80 | fLoGainFirst = lofirst;
|
---|
81 |
|
---|
82 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
---|
83 | fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
|
---|
84 | }
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // The PreProcess searches for the following input containers:
|
---|
89 | // - MRawEvtData
|
---|
90 | // - MPedestalCam
|
---|
91 | //
|
---|
92 | // The following output containers are also searched and created if
|
---|
93 | // they were not found:
|
---|
94 | //
|
---|
95 | // - MExtractedSignalCam
|
---|
96 | //
|
---|
97 | Int_t MExtractSignal::PreProcess(MParList *pList)
|
---|
98 | {
|
---|
99 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
100 | if (!fRawEvt)
|
---|
101 | {
|
---|
102 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
103 | return kFALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
---|
108 | if (!fSignals)
|
---|
109 | return kFALSE;
|
---|
110 |
|
---|
111 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
|
---|
112 | fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
|
---|
113 |
|
---|
114 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
115 | if (!fPedestals)
|
---|
116 | {
|
---|
117 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
118 | return kFALSE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | return kTRUE;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | // --------------------------------------------------------------------------
|
---|
126 | //
|
---|
127 | // The ReInit searches for the following input containers:
|
---|
128 | // - MRawRunHeader
|
---|
129 | //
|
---|
130 | Bool_t MExtractSignal::ReInit(MParList *pList )
|
---|
131 | {
|
---|
132 | MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
133 | if (!cam)
|
---|
134 | {
|
---|
135 | *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
|
---|
136 | return kFALSE;
|
---|
137 | }
|
---|
138 |
|
---|
139 | // FIXME: This solution may change in the future, MExtractedSignal
|
---|
140 | // must be similar to MCerPhotEvt not to MPedestalCam
|
---|
141 | // (Have to think about the mean size of both solutions)
|
---|
142 | fSignals->InitSize(cam->GetNumPixels());
|
---|
143 |
|
---|
144 | return kTRUE;
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | // --------------------------------------------------------------------------
|
---|
149 | //
|
---|
150 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
151 | // pixel in the MExtractedSignalCam container.
|
---|
152 | //
|
---|
153 | Int_t MExtractSignal::Process()
|
---|
154 | {
|
---|
155 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
156 | fSignals->Clear();
|
---|
157 |
|
---|
158 | UInt_t satlo=0;
|
---|
159 |
|
---|
160 | while (pixel.Next())
|
---|
161 | {
|
---|
162 | UShort_t satHi = 0;
|
---|
163 | UShort_t satLo = 0;
|
---|
164 |
|
---|
165 | Byte_t *ptr = pixel.GetHiGainSamples();
|
---|
166 | Byte_t *first = ptr + fHiGainFirst;
|
---|
167 | Byte_t *last = ptr + fHiGainFirst + fNumHiGainSamples;
|
---|
168 |
|
---|
169 | UInt_t sumHi = 0;
|
---|
170 | UInt_t sumLo = 0;
|
---|
171 |
|
---|
172 | const Int_t pixid = pixel.GetPixelId();
|
---|
173 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
174 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
175 |
|
---|
176 | const Float_t pedes = ped.GetPedestal();
|
---|
177 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
178 |
|
---|
179 | Byte_t maxhi = 0;
|
---|
180 | Byte_t midhi = 0;
|
---|
181 |
|
---|
182 | for (ptr=first;ptr<last;ptr++)
|
---|
183 | {
|
---|
184 |
|
---|
185 | if (*ptr > maxhi)
|
---|
186 | {
|
---|
187 | maxhi = *ptr;
|
---|
188 | midhi = ptr-first;
|
---|
189 | }
|
---|
190 |
|
---|
191 | sumHi += *ptr;
|
---|
192 |
|
---|
193 | if (*ptr >= fSaturationLimit)
|
---|
194 | satHi++;
|
---|
195 |
|
---|
196 | }
|
---|
197 |
|
---|
198 | ptr = pixel.GetLoGainSamples();
|
---|
199 | first = ptr + fLoGainFirst;
|
---|
200 | last = ptr + fLoGainFirst + fNumLoGainSamples;
|
---|
201 | Byte_t maxlo = 0;
|
---|
202 | Byte_t midlo = 0;
|
---|
203 |
|
---|
204 | for (ptr=first;ptr<last;ptr++)
|
---|
205 | {
|
---|
206 |
|
---|
207 | if (*ptr > maxlo)
|
---|
208 | {
|
---|
209 | maxlo = *ptr;
|
---|
210 | midlo = ptr-first;
|
---|
211 | }
|
---|
212 |
|
---|
213 | sumLo += *ptr;
|
---|
214 |
|
---|
215 | if (*ptr >= fSaturationLimit)
|
---|
216 | satLo++;
|
---|
217 | }
|
---|
218 |
|
---|
219 | if (satLo)
|
---|
220 | satlo++;
|
---|
221 |
|
---|
222 | pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
|
---|
223 | pedrms*fSqrtHiGainSamples,
|
---|
224 | ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples),
|
---|
225 | pedrms*fSqrtLoGainSamples);
|
---|
226 |
|
---|
227 | pix.SetGainSaturation(satHi, satHi, satLo);
|
---|
228 |
|
---|
229 | // FIXME: Arrival time has to be stored in MArrivalTime!
|
---|
230 | if (satHi)
|
---|
231 | pix.SetArrivalTimes((Float_t)(midlo+fLoGainFirst),0.,0.);
|
---|
232 | else
|
---|
233 | pix.SetArrivalTimes((Float_t)(midhi+fHiGainFirst),0.,0.);
|
---|
234 |
|
---|
235 | } /* while (pixel.Next()) */
|
---|
236 |
|
---|
237 | if (satlo)
|
---|
238 | *fLog << warn << "WARNING - Lo Gain saturated in " << satlo << " pixels." << endl;
|
---|
239 |
|
---|
240 |
|
---|
241 | fSignals->SetReadyToSave();
|
---|
242 |
|
---|
243 | return kTRUE;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // --------------------------------------------------------------------------
|
---|
247 | //
|
---|
248 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
249 | // to a macro. In the original root implementation it is used to write
|
---|
250 | // gui elements to a macro-file.
|
---|
251 | //
|
---|
252 | void MExtractSignal::StreamPrimitive(ofstream &out) const
|
---|
253 | {
|
---|
254 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
255 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
256 |
|
---|
257 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
258 | {
|
---|
259 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
260 | out << (int)fSaturationLimit << ");" << endl;
|
---|
261 | }
|
---|
262 |
|
---|
263 | const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
|
---|
264 | const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
|
---|
265 | const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
|
---|
266 | const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
|
---|
267 |
|
---|
268 | if (!arg1)
|
---|
269 | return;
|
---|
270 |
|
---|
271 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
272 | out << (int)fLoGainFirst;
|
---|
273 | if (arg2)
|
---|
274 | {
|
---|
275 | out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
|
---|
276 | if (arg3)
|
---|
277 | {
|
---|
278 | out << ", " << (int)fLoGainFirst;
|
---|
279 | if (arg4)
|
---|
280 | out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | out << ");" << endl;
|
---|
284 | }
|
---|