source: tags/Mars-V0.9.2/msignal/MExtractFixedWindow.cc

Last change on this file was 7043, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.7 KB
Line 
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
54ClassImp(MExtractFixedWindow);
55
56using namespace std;
57
58const Byte_t MExtractFixedWindow::fgHiGainFirst = 3;
59const Byte_t MExtractFixedWindow::fgHiGainLast = 14;
60const Byte_t MExtractFixedWindow::fgLoGainFirst = 3;
61const Byte_t MExtractFixedWindow::fgLoGainLast = 14;
62// --------------------------------------------------------------------------
63//
64// Default constructor.
65//
66// Calls:
67// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
68//
69MExtractFixedWindow::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//
97void 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 const Int_t wshigain = fHiGainLast-fHiGainFirst+1;
154 const Int_t wslogain = fLoGainLast-fLoGainFirst+1;
155
156 switch (wshigain)
157 {
158 case 2:
159 SetResolutionPerPheHiGain(0.021);
160 break;
161 case 4:
162 case 6:
163 case 8:
164 case 10:
165 case 12:
166 case 14:
167 SetResolutionPerPheHiGain(0.011);
168 break;
169 default:
170 *fLog << warn << GetDescriptor() << ": Could not set the hi-gain extractor resolution/phe for window size " << wshigain << endl;
171 }
172
173 switch (wslogain)
174 {
175 case 4:
176 SetResolutionPerPheLoGain(0.063);
177 break;
178 case 6:
179 SetResolutionPerPheLoGain(0.017);
180 break;
181 case 8:
182 case 10:
183 SetResolutionPerPheLoGain(0.011);
184 break;
185 default:
186 *fLog << warn << GetDescriptor() << ": Could not set the lo-gain extractor resolution/phe for window size " << wslogain << endl;
187 }
188}
189
190// --------------------------------------------------------------------------
191//
192// The ReInit calls:
193// - MExtractor::ReInit()
194// - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
195// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
196//
197Bool_t MExtractFixedWindow::ReInit(MParList *pList)
198{
199
200 MExtractor::ReInit(pList);
201
202 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
203 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
204
205
206 *fLog << endl;
207 *fLog << inf << "Taking " << fNumHiGainSamples
208 << " HiGain samples from slice " << (Int_t)fHiGainFirst
209 << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
210 *fLog << inf << "Taking " << fNumLoGainSamples
211 << " LoGain samples from slice " << (Int_t)fLoGainFirst
212 << " to " << (Int_t)fLoGainLast << " incl" << endl;
213 return kTRUE;
214
215}
216
217// --------------------------------------------------------------------------
218//
219// FindSignalHiGain:
220//
221// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
222// - Sum up contents of *ptr
223// - If *ptr is greater than fSaturationLimit, raise sat by 1
224//
225// - If fHiLoLast is not 0, loop also from logain to (logain+fHiLoLast)
226// - Sum up contents of logain
227// - If *logain is greater than fSaturationLimit, raise sat by 1
228//
229void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
230{
231
232 Int_t summ = 0;
233
234 Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
235
236 while (ptr<end)
237 {
238 summ += *ptr;
239 if (*ptr++ >= fSaturationLimit)
240 sat++;
241 }
242
243 Byte_t *p = logain;
244 end = logain + fHiLoLast;
245 while (p<end)
246 {
247 summ += *p;
248 if (*p++ >= fSaturationLimit)
249 sat++;
250 }
251
252 sum = (Float_t)summ;
253
254 return;
255}
256
257// --------------------------------------------------------------------------
258//
259// FindSignalLoGain:
260//
261// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
262// - Sum up contents of *ptr
263// - If *ptr is greater than fSaturationLimit, raise sat by 1
264// - If fHiLoLast is set, loop from logain to (logain+fHiLoLast)
265// - Add contents of *logain to sum
266//
267void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
268{
269
270 Int_t summ = 0;
271
272 Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
273
274 while (ptr<end)
275 {
276 summ += *ptr;
277
278 if (*ptr++ >= fSaturationLimit)
279 sat++;
280 }
281
282 sum = (Float_t)summ;
283}
284
285// --------------------------------------------------------------------------
286//
287// Implementation of SavePrimitive. Used to write the call to a constructor
288// to a macro. In the original root implementation it is used to write
289// gui elements to a macro-file.
290//
291void MExtractFixedWindow::StreamPrimitive(ofstream &out) const
292{
293
294 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
295 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
296
297 if (fSaturationLimit!=fgSaturationLimit)
298 {
299 out << " " << GetUniqueName() << ".SetSaturationLimit(";
300 out << (int)fSaturationLimit << ");" << endl;
301 }
302
303 const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLoGainLast;
304 const Bool_t arg3 = arg4 || fLoGainFirst != fgLoGainFirst;
305 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgHiGainLast;
306 const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
307
308 if (!arg1)
309 return;
310
311 out << " " << GetUniqueName() << ".SetRange(";
312 out << (int)fLoGainFirst;
313 if (arg2)
314 {
315 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
316 if (arg3)
317 {
318 out << ", " << (int)fLoGainFirst;
319 if (arg4)
320 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
321 }
322 }
323 out << ");" << endl;
324}
325
326void MExtractFixedWindow::Print(Option_t *o) const
327{
328 *fLog << all;
329 *fLog << GetDescriptor() << ":" << endl;
330 MExtractor::Print(o);
331}
Note: See TracBrowser for help on using the repository browser.