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

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