source: trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc@ 7098

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