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, 02/2004 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MExtractBlindPixel
|
---|
28 | //
|
---|
29 | //////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MExtractBlindPixel.h"
|
---|
31 |
|
---|
32 | #include <fstream>
|
---|
33 |
|
---|
34 | #include "MLog.h"
|
---|
35 | #include "MLogManip.h"
|
---|
36 |
|
---|
37 | #include "MParList.h"
|
---|
38 |
|
---|
39 | #include "MRawEvtData.h"
|
---|
40 | #include "MRawEvtPixelIter.h"
|
---|
41 |
|
---|
42 | #include "MPedestalCam.h"
|
---|
43 | #include "MPedestalPix.h"
|
---|
44 |
|
---|
45 | #include "MExtractedSignalBlindPixel.h"
|
---|
46 |
|
---|
47 | ClassImp(MExtractBlindPixel);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | const UInt_t MExtractBlindPixel::fgBlindPixelIdx = 559;
|
---|
52 | const Byte_t MExtractBlindPixel::fgSaturationLimit = 254;
|
---|
53 | const Byte_t MExtractBlindPixel::fgFirst = 3;
|
---|
54 | const Byte_t MExtractBlindPixel::fgLast = 14;
|
---|
55 |
|
---|
56 | // --------------------------------------------------------------------------
|
---|
57 | //
|
---|
58 | // Default constructor.
|
---|
59 | //
|
---|
60 | MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title)
|
---|
61 | : fSaturationLimit(fgSaturationLimit)
|
---|
62 | {
|
---|
63 |
|
---|
64 | fName = name ? name : "MExtractBlindPixel";
|
---|
65 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
66 |
|
---|
67 | AddToBranchList("MRawEvtData.*");
|
---|
68 |
|
---|
69 | SetBlindPixelIdx();
|
---|
70 | SetSaturationLimit();
|
---|
71 | SetRange();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void MExtractBlindPixel::SetRange(Byte_t first, Byte_t last)
|
---|
75 | {
|
---|
76 |
|
---|
77 | fNumSamples = last-first+1;
|
---|
78 | fFirst = first;
|
---|
79 | fLast = last;
|
---|
80 |
|
---|
81 | fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
|
---|
82 | }
|
---|
83 |
|
---|
84 | // --------------------------------------------------------------------------
|
---|
85 | //
|
---|
86 | // The PreProcess searches for the following input containers:
|
---|
87 | // - MRawEvtData
|
---|
88 | // - MPedestalCam
|
---|
89 | //
|
---|
90 | // The following output containers are also searched and created if
|
---|
91 | // they were not found:
|
---|
92 | //
|
---|
93 | // - MExtractedBlindPixel
|
---|
94 | //
|
---|
95 | Int_t MExtractBlindPixel::PreProcess(MParList *pList)
|
---|
96 | {
|
---|
97 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
98 | if (!fRawEvt)
|
---|
99 | {
|
---|
100 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
101 | return kFALSE;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel"));
|
---|
106 | if (!fBlindPixel)
|
---|
107 | return kFALSE;
|
---|
108 |
|
---|
109 | fBlindPixel->SetUsedFADCSlices(fFirst, fLast);
|
---|
110 |
|
---|
111 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
112 |
|
---|
113 | if (!fPedestals)
|
---|
114 | {
|
---|
115 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
116 | return kFALSE;
|
---|
117 | }
|
---|
118 |
|
---|
119 | const MPedestalPix &ped = (*fPedestals)[fBlindPixelIdx];
|
---|
120 |
|
---|
121 | if (&ped)
|
---|
122 | {
|
---|
123 | fPedestal = ped.GetPedestal();
|
---|
124 | fPedRms = ped.GetPedestalRms();
|
---|
125 | }
|
---|
126 | else
|
---|
127 | {
|
---|
128 | *fLog << err << " Cannot find MPedestalPix of the Blind Pixel (idx="
|
---|
129 | << fBlindPixelIdx << ")" << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | // --------------------------------------------------------------------------
|
---|
137 | //
|
---|
138 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
139 | // pixel in the MExtractedBlindPixel container.
|
---|
140 | //
|
---|
141 | Int_t MExtractBlindPixel::Process()
|
---|
142 | {
|
---|
143 |
|
---|
144 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
145 |
|
---|
146 | fBlindPixel->Clear();
|
---|
147 |
|
---|
148 | pixel.Jump(fBlindPixelIdx);
|
---|
149 |
|
---|
150 | UInt_t sat = 0;
|
---|
151 | UInt_t max = 0;
|
---|
152 |
|
---|
153 | Byte_t *ptr = pixel.GetHiGainSamples();
|
---|
154 |
|
---|
155 | UInt_t sumhi = 0;
|
---|
156 | UInt_t sumlo = 0;
|
---|
157 | //
|
---|
158 | // We need a dedicated signal extractor for the blind pixel
|
---|
159 | //
|
---|
160 | Int_t diff = 0;
|
---|
161 | UInt_t first = fFirst;
|
---|
162 | UInt_t last = fLast;
|
---|
163 |
|
---|
164 | if (last > 15)
|
---|
165 | {
|
---|
166 | diff = last - 15;
|
---|
167 | last = 15;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | Byte_t *start = ptr + first - 1;
|
---|
172 | Byte_t *end = ptr + last - 1;
|
---|
173 |
|
---|
174 | ptr = start;
|
---|
175 |
|
---|
176 | Int_t sum = 0;
|
---|
177 |
|
---|
178 | while (ptr<=end)
|
---|
179 | {
|
---|
180 | sum += *ptr;
|
---|
181 |
|
---|
182 | if (*ptr > max)
|
---|
183 | max = *ptr;
|
---|
184 |
|
---|
185 | if (*ptr++ >= fSaturationLimit)
|
---|
186 | sat++;
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (diff > 0)
|
---|
190 | {
|
---|
191 | ptr = pixel.GetLoGainSamples();
|
---|
192 | end = ptr + diff - 1;
|
---|
193 |
|
---|
194 | while (ptr<=end)
|
---|
195 | {
|
---|
196 |
|
---|
197 | sum += *ptr;
|
---|
198 |
|
---|
199 | if (*ptr > max)
|
---|
200 | max = *ptr;
|
---|
201 |
|
---|
202 | if (*ptr++ >= fSaturationLimit)
|
---|
203 | sat++;
|
---|
204 |
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | sumhi = sum;
|
---|
209 |
|
---|
210 | ptr = pixel.GetLoGainSamples();
|
---|
211 |
|
---|
212 | start = ptr + fFirst - 1;
|
---|
213 | end = ptr + fLast - 1;
|
---|
214 |
|
---|
215 | ptr = start;
|
---|
216 |
|
---|
217 | sum = 0;
|
---|
218 |
|
---|
219 | while (ptr<=end)
|
---|
220 | {
|
---|
221 |
|
---|
222 | sum += *ptr;
|
---|
223 |
|
---|
224 | if (*ptr > max)
|
---|
225 | max = *ptr;
|
---|
226 |
|
---|
227 | if (*ptr++ >= fSaturationLimit)
|
---|
228 | sat++;
|
---|
229 | }
|
---|
230 |
|
---|
231 | sumlo = sum;
|
---|
232 |
|
---|
233 | fBlindPixel->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
|
---|
234 | fBlindPixel->SetSaturation(sat);
|
---|
235 |
|
---|
236 | if (sat)
|
---|
237 | *fLog << warn << "WARNING - saturation occurred in the Blind Pixel " << endl;
|
---|
238 |
|
---|
239 | fBlindPixel->SetReadyToSave();
|
---|
240 |
|
---|
241 | return kTRUE;
|
---|
242 | }
|
---|
243 |
|
---|
244 | // --------------------------------------------------------------------------
|
---|
245 | //
|
---|
246 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
247 | // to a macro. In the original root implementation it is used to write
|
---|
248 | // gui elements to a macro-file.
|
---|
249 | //
|
---|
250 | void MExtractBlindPixel::StreamPrimitive(ofstream &out) const
|
---|
251 | {
|
---|
252 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
253 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
254 |
|
---|
255 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
256 | {
|
---|
257 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
258 | out << (int)fSaturationLimit << ");" << endl;
|
---|
259 | }
|
---|
260 |
|
---|
261 | const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
|
---|
262 | const Bool_t arg1 = arg2 || fFirst != fgFirst;
|
---|
263 |
|
---|
264 | if (!arg1)
|
---|
265 | return;
|
---|
266 |
|
---|
267 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
268 | out << (int)fFirst;
|
---|
269 | if (arg2)
|
---|
270 | out << ", " << (int)(fNumSamples+fFirst-1);
|
---|
271 | out << ");" << endl;
|
---|
272 | }
|
---|