source: branches/MarsISDCBranchBasedOn17887/msignal/MExtractFixedWindow.cc@ 18378

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