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 | ! Thomas Bretz, 01/2004
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MExtractFixedWindow
|
---|
29 | //
|
---|
30 | // Extracts the signal from a fixed window in a given range by summing up the
|
---|
31 | // slice contents.
|
---|
32 | //
|
---|
33 | // Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
|
---|
34 | // to modify the ranges. Ranges have to be an even number. In case of odd
|
---|
35 | // ranges, the last slice will be reduced by one.
|
---|
36 | // Defaults are:
|
---|
37 | //
|
---|
38 | // fHiGainFirst = fgHiGainFirst = 3
|
---|
39 | // fHiGainLast = fgHiGainLast = 14
|
---|
40 | // fLoGainFirst = fgLoGainFirst = 3
|
---|
41 | // fLoGainLast = fgLoGainLast = 14
|
---|
42 | //
|
---|
43 | //////////////////////////////////////////////////////////////////////////////
|
---|
44 | #include "MExtractFixedWindow.h"
|
---|
45 | #include "MExtractor.h"
|
---|
46 |
|
---|
47 | #include <fstream>
|
---|
48 |
|
---|
49 | #include "MExtractedSignalCam.h"
|
---|
50 |
|
---|
51 | #include "MLog.h"
|
---|
52 | #include "MLogManip.h"
|
---|
53 |
|
---|
54 | ClassImp(MExtractFixedWindow);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | const Byte_t MExtractFixedWindow::fgHiGainFirst = 3;
|
---|
59 | const Byte_t MExtractFixedWindow::fgHiGainLast = 14;
|
---|
60 | const Byte_t MExtractFixedWindow::fgLoGainFirst = 3;
|
---|
61 | const Byte_t MExtractFixedWindow::fgLoGainLast = 14;
|
---|
62 | // --------------------------------------------------------------------------
|
---|
63 | //
|
---|
64 | // Default constructor.
|
---|
65 | //
|
---|
66 | // Calls:
|
---|
67 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
---|
68 | //
|
---|
69 | MExtractFixedWindow::MExtractFixedWindow(const char *name, const char *title)
|
---|
70 | {
|
---|
71 | fName = name ? name : "MExtractFixedWindow";
|
---|
72 | fTitle = title ? title : "Signal Extractor for a fixed FADC window";
|
---|
73 |
|
---|
74 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
---|
75 |
|
---|
76 | }
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // SetRange:
|
---|
81 | //
|
---|
82 | // Checks:
|
---|
83 | // - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
|
---|
84 | // - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
|
---|
85 | // - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
|
---|
86 | // - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
|
---|
87 | //
|
---|
88 | // Calls:
|
---|
89 | // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
90 | //
|
---|
91 | // Sets:
|
---|
92 | // - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
|
---|
93 | // - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
|
---|
94 | // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
|
---|
95 | // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
|
---|
96 | //
|
---|
97 | void MExtractFixedWindow::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
98 | {
|
---|
99 |
|
---|
100 | const Byte_t windowhi = hilast-hifirst+1;
|
---|
101 | const Byte_t whieven = windowhi & ~1;
|
---|
102 |
|
---|
103 | if (whieven != windowhi)
|
---|
104 | {
|
---|
105 | *fLog << warn << GetDescriptor()
|
---|
106 | << Form("%s%2i%s%2i",": Hi Gain window size has to be even, set last slice from "
|
---|
107 | ,(int)hilast," to ",(int)(hilast-1)) << endl;
|
---|
108 | hilast -= 1;
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (whieven<2)
|
---|
112 | {
|
---|
113 | *fLog << warn << GetDescriptor()
|
---|
114 | << Form("%s%2i%s%2i",": Hi Gain window is smaller than 2 FADC sampes, set last slice from"
|
---|
115 | ,(int)hilast," to ",(int)(hifirst+1)) << endl;
|
---|
116 | hilast = hifirst+1;
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | if (lolast != 0)
|
---|
121 | {
|
---|
122 | const Byte_t windowlo = lolast-lofirst+1;
|
---|
123 | const Byte_t wloeven = windowlo & ~1;
|
---|
124 |
|
---|
125 | if (wloeven != windowlo)
|
---|
126 | {
|
---|
127 | *fLog << warn << GetDescriptor()
|
---|
128 | << Form("%s%2i%s%2i",": Lo Gain window size has to be even, set last slice from "
|
---|
129 | ,(int)lolast," to ",(int)(lolast-1)) << endl;
|
---|
130 | lolast -= 1;
|
---|
131 | }
|
---|
132 |
|
---|
133 | if (wloeven<2)
|
---|
134 | {
|
---|
135 | *fLog << warn << GetDescriptor()
|
---|
136 | << Form("%s%2i%s%2i",": Lo Gain window is smaller than 2 FADC sampes, set last slice from"
|
---|
137 | ,(int)lolast," to ",(int)(lofirst+1)) << endl;
|
---|
138 | lolast = lofirst+1;
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
---|
143 |
|
---|
144 | fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
|
---|
145 | if (fLoGainLast != 0)
|
---|
146 | fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1);
|
---|
147 | else
|
---|
148 | fNumLoGainSamples = 0.;
|
---|
149 |
|
---|
150 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
---|
151 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
---|
152 |
|
---|
153 | }
|
---|
154 |
|
---|
155 | // --------------------------------------------------------------------------
|
---|
156 | //
|
---|
157 | // The ReInit calls:
|
---|
158 | // - MExtractor::ReInit()
|
---|
159 | // - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
|
---|
160 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
161 | //
|
---|
162 | Bool_t MExtractFixedWindow::ReInit(MParList *pList)
|
---|
163 | {
|
---|
164 |
|
---|
165 | MExtractor::ReInit(pList);
|
---|
166 |
|
---|
167 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
|
---|
168 | fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
---|
169 |
|
---|
170 |
|
---|
171 | *fLog << endl;
|
---|
172 | *fLog << inf << GetDescriptor() << ": Taking " << fNumHiGainSamples
|
---|
173 | << " HiGain samples from slice " << (Int_t)fHiGainFirst
|
---|
174 | << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
|
---|
175 | *fLog << inf << GetDescriptor() << ": Taking " << fNumLoGainSamples
|
---|
176 | << " LoGain samples from slice " << (Int_t)fLoGainFirst
|
---|
177 | << " to " << (Int_t)fLoGainLast << " incl" << endl;
|
---|
178 | return kTRUE;
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | // --------------------------------------------------------------------------
|
---|
183 | //
|
---|
184 | // FindSignalHiGain:
|
---|
185 | //
|
---|
186 | // - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
|
---|
187 | // - Sum up contents of *ptr
|
---|
188 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
189 | //
|
---|
190 | // - If fHiLoLast is not 0, loop also from logain to (logain+fHiLoLast)
|
---|
191 | // - Sum up contents of logain
|
---|
192 | // - If *logain is greater than fSaturationLimit, raise sat by 1
|
---|
193 | //
|
---|
194 | void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
|
---|
195 | {
|
---|
196 |
|
---|
197 | Int_t summ = 0;
|
---|
198 |
|
---|
199 | Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
|
---|
200 |
|
---|
201 | while (ptr<end)
|
---|
202 | {
|
---|
203 | summ += *ptr;
|
---|
204 | if (*ptr++ >= fSaturationLimit)
|
---|
205 | sat++;
|
---|
206 | }
|
---|
207 |
|
---|
208 | Byte_t *p = logain;
|
---|
209 | end = logain + fHiLoLast;
|
---|
210 | while (p<end)
|
---|
211 | {
|
---|
212 | summ += *p;
|
---|
213 | if (*p++ >= fSaturationLimit)
|
---|
214 | sat++;
|
---|
215 | }
|
---|
216 |
|
---|
217 | sum = (Float_t)summ;
|
---|
218 |
|
---|
219 | return;
|
---|
220 | }
|
---|
221 |
|
---|
222 | // --------------------------------------------------------------------------
|
---|
223 | //
|
---|
224 | // FindSignalLoGain:
|
---|
225 | //
|
---|
226 | // - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
|
---|
227 | // - Sum up contents of *ptr
|
---|
228 | // - If *ptr is greater than fSaturationLimit, raise sat by 1
|
---|
229 | // - If fHiLoLast is set, loop from logain to (logain+fHiLoLast)
|
---|
230 | // - Add contents of *logain to sum
|
---|
231 | //
|
---|
232 | void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
|
---|
233 | {
|
---|
234 |
|
---|
235 | Int_t summ = 0;
|
---|
236 |
|
---|
237 | Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
|
---|
238 |
|
---|
239 | while (ptr<end)
|
---|
240 | {
|
---|
241 | summ += *ptr;
|
---|
242 |
|
---|
243 | if (*ptr++ >= fSaturationLimit)
|
---|
244 | sat++;
|
---|
245 | }
|
---|
246 |
|
---|
247 | sum = (Float_t)summ;
|
---|
248 | }
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
253 | // to a macro. In the original root implementation it is used to write
|
---|
254 | // gui elements to a macro-file.
|
---|
255 | //
|
---|
256 | void MExtractFixedWindow::StreamPrimitive(ofstream &out) const
|
---|
257 | {
|
---|
258 |
|
---|
259 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
260 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
261 |
|
---|
262 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
263 | {
|
---|
264 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
265 | out << (int)fSaturationLimit << ");" << endl;
|
---|
266 | }
|
---|
267 |
|
---|
268 | const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLoGainLast;
|
---|
269 | const Bool_t arg3 = arg4 || fLoGainFirst != fgLoGainFirst;
|
---|
270 | const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgHiGainLast;
|
---|
271 | const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
|
---|
272 |
|
---|
273 | if (!arg1)
|
---|
274 | return;
|
---|
275 |
|
---|
276 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
277 | out << (int)fLoGainFirst;
|
---|
278 | if (arg2)
|
---|
279 | {
|
---|
280 | out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
|
---|
281 | if (arg3)
|
---|
282 | {
|
---|
283 | out << ", " << (int)fLoGainFirst;
|
---|
284 | if (arg4)
|
---|
285 | out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
|
---|
286 | }
|
---|
287 | }
|
---|
288 | out << ");" << endl;
|
---|
289 | }
|
---|
290 |
|
---|
291 | void MExtractFixedWindow::Print(Option_t *o) const
|
---|
292 | {
|
---|
293 | *fLog << all;
|
---|
294 | *fLog << GetDescriptor() << ":" << endl;
|
---|
295 | MExtractor::Print(o);
|
---|
296 | }
|
---|