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