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

Last change on this file since 4693 was 4340, checked in by gaug, 20 years ago
*** empty log message ***
File size: 8.6 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 windowlo = lolast-lofirst+1;
102
103 const Byte_t whieven = windowhi & ~1;
104 const Byte_t wloeven = windowlo & ~1;
105
106 if (whieven != windowhi)
107 {
108 *fLog << warn << GetDescriptor()
109 << Form("%s%2i%s%2i",": Hi Gain window size has to be even, set last slice from "
110 ,(int)hilast," to ",(int)(hilast-1)) << endl;
111 hilast -= 1;
112 }
113
114 if (wloeven != windowlo)
115 {
116 *fLog << warn << GetDescriptor()
117 << Form("%s%2i%s%2i",": Lo Gain window size has to be even, set last slice from "
118 ,(int)lolast," to ",(int)(lolast-1)) << endl;
119 lolast -= 1;
120 }
121
122 if (whieven<2)
123 {
124 *fLog << warn << GetDescriptor()
125 << Form("%s%2i%s%2i",": Hi Gain window is smaller than 2 FADC sampes, set last slice from"
126 ,(int)hilast," to ",(int)(hifirst+1)) << endl;
127 hilast = hifirst+1;
128 }
129
130 if (wloeven<2)
131 {
132 *fLog << warn << GetDescriptor()
133 << Form("%s%2i%s%2i",": Lo Gain window is smaller than 2 FADC sampes, set last slice from"
134 ,(int)lolast," to ",(int)(lofirst+1)) << endl;
135 lolast = lofirst+1;
136 }
137
138
139 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
140
141 fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
142 fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1);
143
144 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
145 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
146
147}
148
149// --------------------------------------------------------------------------
150//
151// The ReInit calls:
152// - MExtractor::ReInit()
153// - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
154// fLoGainFirst, fLoGainLast, fNumLoGainSamples);
155//
156Bool_t MExtractFixedWindow::ReInit(MParList *pList)
157{
158
159 MExtractor::ReInit(pList);
160
161 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
162 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
163
164
165 *fLog << endl;
166 *fLog << inf << GetDescriptor() << ": Taking " << fNumHiGainSamples
167 << " HiGain FADC samples from slice: " << (Int_t)fHiGainFirst
168 << " to (including) slice: " << (Int_t)(fHiGainLast+fHiLoLast) << endl;
169 *fLog << inf << GetDescriptor() << ": Taking " << fNumLoGainSamples
170 << " LoGain FADC samples from slice: " << (Int_t)fLoGainFirst
171 << " to (including) slice: " << (Int_t)fLoGainLast << endl;
172 return kTRUE;
173
174}
175
176// --------------------------------------------------------------------------
177//
178// FindSignalHiGain:
179//
180// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
181// - Sum up contents of *ptr
182// - If *ptr is greater than fSaturationLimit, raise sat by 1
183//
184// - If fHiLoLast is not 0, loop also from logain to (logain+fHiLoLast)
185// - Sum up contents of logain
186// - If *logain is greater than fSaturationLimit, raise sat by 1
187//
188void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
189{
190
191 Int_t summ = 0;
192
193 Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
194
195 while (ptr<end)
196 {
197 summ += *ptr;
198 if (*ptr++ >= fSaturationLimit)
199 sat++;
200 }
201
202 Byte_t *p = logain;
203 end = logain + fHiLoLast;
204 while (p<end)
205 {
206 summ += *p;
207 if (*p++ >= fSaturationLimit)
208 sat++;
209 }
210
211 sum = (Float_t)summ;
212
213 return;
214}
215
216// --------------------------------------------------------------------------
217//
218// FindSignalLoGain:
219//
220// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
221// - Sum up contents of *ptr
222// - If *ptr is greater than fSaturationLimit, raise sat by 1
223// - If fHiLoLast is set, loop from logain to (logain+fHiLoLast)
224// - Add contents of *logain to sum
225//
226void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
227{
228
229 Int_t summ = 0;
230
231 Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
232
233 while (ptr<end)
234 {
235 summ += *ptr;
236
237 if (*ptr++ >= fSaturationLimit)
238 sat++;
239 }
240
241 sum = (Float_t)summ;
242}
243
244// --------------------------------------------------------------------------
245//
246// Implementation of SavePrimitive. Used to write the call to a constructor
247// to a macro. In the original root implementation it is used to write
248// gui elements to a macro-file.
249//
250void MExtractFixedWindow::StreamPrimitive(ofstream &out) const
251{
252
253 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
254 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
255
256 if (fSaturationLimit!=fgSaturationLimit)
257 {
258 out << " " << GetUniqueName() << ".SetSaturationLimit(";
259 out << (int)fSaturationLimit << ");" << endl;
260 }
261
262 const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLoGainLast;
263 const Bool_t arg3 = arg4 || fLoGainFirst != fgLoGainFirst;
264 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgHiGainLast;
265 const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
266
267 if (!arg1)
268 return;
269
270 out << " " << GetUniqueName() << ".SetRange(";
271 out << (int)fLoGainFirst;
272 if (arg2)
273 {
274 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
275 if (arg3)
276 {
277 out << ", " << (int)fLoGainFirst;
278 if (arg4)
279 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
280 }
281 }
282 out << ");" << endl;
283}
Note: See TracBrowser for help on using the repository browser.