source: trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc@ 3884

Last change on this file since 3884 was 3883, checked in by gaug, 22 years ago
*** empty log message ***
File size: 6.4 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): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
20! Markus Gaug , 04/2004 <mailto:markus@ifae.es>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26
27//////////////////////////////////////////////////////////////////////////////
28//
29// MExtractSlidingWindow
30//
31// Extracts the signal from a sliding window of size fHiGainWindowSize and
32// fLoGainWindowSize. The signal is the one which maximizes the integral
33// contents.
34//
35//////////////////////////////////////////////////////////////////////////////
36#include "MExtractSlidingWindow.h"
37#include "MExtractor.h"
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42
43ClassImp(MExtractSlidingWindow);
44
45using namespace std;
46
47const Byte_t MExtractSlidingWindow::fgHiGainFirst = 3;
48const Byte_t MExtractSlidingWindow::fgHiGainLast = 14;
49const Byte_t MExtractSlidingWindow::fgLoGainFirst = 3;
50const Byte_t MExtractSlidingWindow::fgLoGainLast = 14;
51const Byte_t MExtractSlidingWindow::fgHiGainWindowSize = 6;
52const Byte_t MExtractSlidingWindow::fgLoGainWindowSize = 6;
53// --------------------------------------------------------------------------
54//
55// Default constructor.
56//
57MExtractSlidingWindow::MExtractSlidingWindow(const char *name, const char *title)
58 : fWindowSizeHiGain(fgHiGainWindowSize),
59 fWindowSizeLoGain(fgLoGainWindowSize)
60{
61
62 fName = name ? name : "MExtractSlidingWindow";
63 fTitle = title ? title : "Signal Extractor for a sliding FADC window";
64
65 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
66}
67
68void MExtractSlidingWindow::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
69{
70
71 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
72
73 //
74 // Redo the checks if the window is still inside the ranges
75 //
76
77 SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);
78
79}
80
81void MExtractSlidingWindow::SetWindowSize(Byte_t windowh, Byte_t windowl)
82{
83
84 fWindowSizeHiGain = windowh & ~1;
85 fWindowSizeLoGain = windowl & ~1;
86
87 if (fWindowSizeHiGain != windowh)
88 *fLog << warn << GetDescriptor() << ": Hi Gain window size has to be even, set to: "
89 << int(fWindowSizeHiGain) << " samples " << endl;
90
91 if (fWindowSizeLoGain != windowl)
92 *fLog << warn << GetDescriptor() << ": Lo Gain window size has to be even, set to: "
93 << int(fWindowSizeLoGain) << " samples " << endl;
94
95 const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
96 const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1;
97
98 if (fWindowSizeHiGain > availhirange)
99 {
100 *fLog << warn << GetDescriptor()
101 << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",(int)fWindowSizeHiGain,
102 " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl;
103 *fLog << warn << GetDescriptor()
104 << ": Will set window size to: " << (int)availhirange << endl;
105 fWindowSizeHiGain = availhirange;
106 }
107
108 if (fWindowSizeLoGain > availlorange)
109 {
110 *fLog << warn << GetDescriptor()
111 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",(int)fWindowSizeLoGain,
112 " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl;
113 *fLog << warn << GetDescriptor()
114 << ": Will set window size to: " << (int)availlorange << endl;
115 fWindowSizeLoGain = availlorange;
116 }
117
118 if (fWindowSizeHiGain<2)
119 {
120 fWindowSizeHiGain = 2;
121 *fLog << warn << GetDescriptor() << ": Hi Gain window size set to two samples" << endl;
122 }
123
124 if (fWindowSizeLoGain<2)
125 {
126 fWindowSizeLoGain = 2;
127 *fLog << warn << GetDescriptor() << ": Lo Gain window size set to two samples" << endl;
128 }
129
130 fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
131 fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
132
133 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
134 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
135
136}
137
138
139void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Int_t &max, Byte_t &sat) const
140{
141 const Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
142
143 Int_t sum=0;
144
145 //
146 // Calculate the sum of the first fWindowSize slices
147 //
148 sat = 0;
149 Byte_t *p = ptr;
150 while (p<ptr+fWindowSizeHiGain)
151 {
152 sum += *p;
153 if (*p++ >= fSaturationLimit)
154 sat++;
155 }
156
157 //
158 // Check for saturation in all other slices
159 //
160 while (p<end)
161 if (*p++ >= fSaturationLimit)
162 sat++;
163
164 //
165 // Calculate the i-th sum as
166 // sum_i+1 = sum_i + slice[i+8] - slice[i]
167 // This is fast and accurate (because we are using int's)
168 //
169 max=sum;
170 for (p=ptr; p+fWindowSizeHiGain<end; p++)
171 {
172 sum += *(p+fWindowSizeHiGain) - *p;
173 if (sum>max)
174 max = sum;
175 }
176}
177
178
179void MExtractSlidingWindow::FindSignalLoGain(Byte_t *ptr, Int_t &max, Byte_t &sat) const
180{
181 const Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
182
183 Int_t sum=0;
184
185 //
186 // Calculate the sum of the first fWindowSize slices
187 //
188 sat = 0;
189 Byte_t *p = ptr;
190 while (p<ptr+fWindowSizeLoGain)
191 {
192 sum += *p;
193 if (*p++ >= fSaturationLimit)
194 sat++;
195 }
196
197 //
198 // Check for saturation in all other slices
199 //
200 while (p<end)
201 if (*p++ >= fSaturationLimit)
202 sat++;
203
204 //
205 // Calculate the i-th sum as
206 // sum_i+1 = sum_i + slice[i+8] - slice[i]
207 // This is fast and accurate (because we are using int's)
208 //
209 max=sum;
210 for (p=ptr; p+fWindowSizeLoGain<end; p++)
211 {
212 sum += *(p+fWindowSizeLoGain) - *p;
213 if (sum>max)
214 max = sum;
215 }
216}
217
Note: See TracBrowser for help on using the repository browser.