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

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