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