1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.6 2007-06-16 22:08:00 tbretz Exp $
|
---|
3 | ! --------------------------------------------------------------------------
|
---|
4 | !
|
---|
5 | ! *
|
---|
6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | ! *
|
---|
11 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
12 | ! * documentation for any purpose is hereby granted without fee,
|
---|
13 | ! * provided that the above copyright notice appear in all copies and
|
---|
14 | ! * that both that copyright notice and this permission notice appear
|
---|
15 | ! * in supporting documentation. It is provided "as is" without express
|
---|
16 | ! * or implied warranty.
|
---|
17 | ! *
|
---|
18 | !
|
---|
19 | !
|
---|
20 | ! Author(s): Thomas Bretz, 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2006
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // MPedestalSubtractedEvt
|
---|
30 | //
|
---|
31 | // Storage container to store the raw FADC values.
|
---|
32 | //
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | #include "MPedestalSubtractedEvt.h"
|
---|
36 |
|
---|
37 | ClassImp(MPedestalSubtractedEvt);
|
---|
38 |
|
---|
39 | using namespace std;
|
---|
40 |
|
---|
41 | // --------------------------------------------------------------------------
|
---|
42 | //
|
---|
43 | // Initialize number of samples (per pixel) and number of pixels.
|
---|
44 | //
|
---|
45 | // Initialize the correct length of fSamples and fSamplesRaw
|
---|
46 | //
|
---|
47 | // And reset its contents to 0.
|
---|
48 | //
|
---|
49 | void MPedestalSubtractedEvt::InitSamples(UInt_t samples, UInt_t pixels)
|
---|
50 | {
|
---|
51 | fNumSamples = samples;
|
---|
52 |
|
---|
53 | if (pixels>0)
|
---|
54 | fNumPixels = pixels;
|
---|
55 |
|
---|
56 | fSamples.Set(fNumPixels*fNumSamples);
|
---|
57 | fSamplesRaw.Set(fNumPixels*fNumSamples);
|
---|
58 |
|
---|
59 | fSamples.Reset();
|
---|
60 | fSamplesRaw.Reset();
|
---|
61 | }
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Return a pointer to the first slice with subtracted pedestal of
|
---|
66 | // the samples of the pixel with given pixel-index. If the number
|
---|
67 | // exceeds the number of pixels NULL is returned.
|
---|
68 | //
|
---|
69 | // The user is responsible not to exceed the slices for one pixel!
|
---|
70 | //
|
---|
71 | Float_t *MPedestalSubtractedEvt::GetSamples(UInt_t pixel) const
|
---|
72 | {
|
---|
73 | return pixel>=fNumPixels ? NULL : fSamples.GetArray()+pixel*fNumSamples;
|
---|
74 | }
|
---|
75 |
|
---|
76 | // --------------------------------------------------------------------------
|
---|
77 | //
|
---|
78 | // Return a pointer to the first slice of the raw-data samples of the pixel
|
---|
79 | // with given pixel-index. If the number exceeds the number of
|
---|
80 | // pixels NULL is returned.
|
---|
81 | //
|
---|
82 | // The user is responsible not to exceed the slices for one pixel!
|
---|
83 | //
|
---|
84 | USample_t *MPedestalSubtractedEvt::GetSamplesRaw(UInt_t pixel) const
|
---|
85 | {
|
---|
86 | return pixel>=fNumPixels ? NULL : fSamplesRaw.GetArray()+pixel*fNumSamples;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // --------------------------------------------------------------------------
|
---|
90 | //
|
---|
91 | // Return some information about saturation in the raw-data of pixel idx.
|
---|
92 | //
|
---|
93 | // The search range is defined by [first,last]. Saturation is considered if
|
---|
94 | // contents is >= limit.
|
---|
95 | //
|
---|
96 | // The number of saturating slices are returned and first/last are filled
|
---|
97 | // with the first and last saturating slice index w.r.t. the beginning of
|
---|
98 | // the raw-data of this pixel not first.
|
---|
99 | //
|
---|
100 | // Warning: No range checks and no sanity checks are done!
|
---|
101 | //
|
---|
102 | Int_t MPedestalSubtractedEvt::GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const
|
---|
103 | {
|
---|
104 | // Determin saturation of hi-gains
|
---|
105 | USample_t *p0 = GetSamplesRaw(idx);
|
---|
106 |
|
---|
107 | USample_t *sat0 = 0; // first saturating slice
|
---|
108 | USample_t *sat1 = 0; // last saturating slice
|
---|
109 |
|
---|
110 | Int_t num = 0;
|
---|
111 |
|
---|
112 | const USample_t *end = p0+last;
|
---|
113 | for (USample_t *ptr=p0+first; ptr<=end; ptr++)
|
---|
114 | {
|
---|
115 | if (*ptr>=limit)
|
---|
116 | {
|
---|
117 | sat1 = ptr;
|
---|
118 | if (!sat0)
|
---|
119 | sat0 = ptr;
|
---|
120 | num++;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | last = sat1 ? sat1-p0 : -1;
|
---|
125 | first = sat0 ? sat0-p0 : -1;
|
---|
126 |
|
---|
127 | return num;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Get the maximum of the pedestal subtracted slices [first,last] of
|
---|
133 | // pixel with index idx.
|
---|
134 | //
|
---|
135 | // The position returned is the index of the position of the pedestal
|
---|
136 | // subtracted maximum w.r.t. to first.
|
---|
137 | // The value returned is the maximum corresponding to this index.
|
---|
138 | //
|
---|
139 | // Warning: No range checks and no sanity checks are done!
|
---|
140 | //
|
---|
141 | Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Float_t &val) const
|
---|
142 | {
|
---|
143 | // Get pointer to first slice to be considered
|
---|
144 | Float_t const *sam = GetSamples(idx);
|
---|
145 |
|
---|
146 | Float_t const *beg = sam+first;
|
---|
147 |
|
---|
148 | // The best information so far: the first slice is the maximum
|
---|
149 | const Float_t *max = beg;
|
---|
150 |
|
---|
151 | for (const Float_t *ptr=beg+1; ptr<=sam+last; ptr++)
|
---|
152 | if (*ptr>*max)
|
---|
153 | max = ptr;
|
---|
154 |
|
---|
155 | val = *max;
|
---|
156 | return max-beg;
|
---|
157 | }
|
---|
158 |
|
---|
159 | // --------------------------------------------------------------------------
|
---|
160 | //
|
---|
161 | // Get the maximum of the raw slices [first,last] of pixel with index idx.
|
---|
162 | //
|
---|
163 | // The position returned is the index of the position of the raw-data
|
---|
164 | // w.r.t. to first.
|
---|
165 | // The value returned is the maximum corresponding to this index.
|
---|
166 | //
|
---|
167 | // Warning: No range checks and no sanity checks are done!
|
---|
168 | //
|
---|
169 | Int_t MPedestalSubtractedEvt::GetRawMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const
|
---|
170 | {
|
---|
171 | // Get pointer to first slice to be considered
|
---|
172 | USample_t const *sam = GetSamplesRaw(idx);
|
---|
173 |
|
---|
174 | USample_t const *beg = sam+first;
|
---|
175 |
|
---|
176 | // The best information so far: the first slice is the maximum
|
---|
177 | const USample_t *max = beg;
|
---|
178 |
|
---|
179 | for (const USample_t *ptr=beg+1; ptr<=sam+last; ptr++)
|
---|
180 | if (*ptr>*max)
|
---|
181 | max = ptr;
|
---|
182 |
|
---|
183 | val = *max;
|
---|
184 | return max-beg;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /*
|
---|
188 | #include <TSpline.h>
|
---|
189 | #include "MArrayD.h"
|
---|
190 | void MPedestalSubtractedEvt::InterpolateSaturation(const Int_t idx, Int_t limit, Int_t first, Int_t last) const
|
---|
191 | {
|
---|
192 | MArrayD x(GetNumSamples());
|
---|
193 | MArrayD y(GetNumSamples());
|
---|
194 |
|
---|
195 | Float_t *s = GetSamples(idx);
|
---|
196 |
|
---|
197 | Int_t n = 0;
|
---|
198 | for (unsigned int i=0; i<GetNumSamples(); i++)
|
---|
199 | {
|
---|
200 | if (s[i]>limit)
|
---|
201 | continue;
|
---|
202 | x[n] = i;
|
---|
203 | y[n] = s[i];
|
---|
204 | n++;
|
---|
205 | }
|
---|
206 |
|
---|
207 | TSpline5 sp("", x.GetArray(), y.GetArray(), n);
|
---|
208 |
|
---|
209 | for (unsigned int i=0; i<GetNumSamples(); i++)
|
---|
210 | {
|
---|
211 | if (s[i]>limit)
|
---|
212 | s[i] = sp.Eval(i);
|
---|
213 | }
|
---|
214 | }
|
---|
215 | */
|
---|