source: trunk/Mars/mpedestal/MPedestalSubtractedEvt.cc@ 13389

Last change on this file since 13389 was 12625, checked in by tbretz, 13 years ago
Added possibility to return mean and rms in GetPixelContant
File size: 8.0 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, 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MPedestalSubtractedEvt
28//
29// Storage container to store the raw FADC values.
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MPedestalSubtractedEvt.h"
33
34#include <TMath.h>
35
36#include "MLogManip.h"
37
38ClassImp(MPedestalSubtractedEvt);
39
40using namespace std;
41
42// --------------------------------------------------------------------------
43//
44// Initialize number of samples (per pixel) and number of pixels.
45//
46// Initialize the correct length of fSamples and fSamplesRaw
47//
48// And reset its contents to 0.
49//
50void MPedestalSubtractedEvt::InitSamples(UInt_t samples, UInt_t pixels)
51{
52 fNumSamples = samples;
53
54 if (pixels>0)
55 fNumPixels = pixels;
56
57 fSamples.Set(fNumPixels*fNumSamples);
58 fSamplesRaw.Set(fNumPixels*fNumSamples);
59
60 fSamples.Reset();
61 fSamplesRaw.Reset();
62}
63
64// --------------------------------------------------------------------------
65//
66// Return a pointer to the first slice with subtracted pedestal of
67// the samples of the pixel with given pixel-index. If the number
68// exceeds the number of pixels NULL is returned.
69//
70// The user is responsible not to exceed the slices for one pixel!
71//
72Float_t *MPedestalSubtractedEvt::GetSamples(UInt_t pixel) const
73{
74 return pixel>=fNumPixels ? NULL : fSamples.GetArray()+pixel*fNumSamples;
75}
76
77// --------------------------------------------------------------------------
78//
79// Return a pointer to the first slice of the raw-data samples of the pixel
80// with given pixel-index. If the number exceeds the number of
81// pixels NULL is returned.
82//
83// The user is responsible not to exceed the slices for one pixel!
84//
85USample_t *MPedestalSubtractedEvt::GetSamplesRaw(UInt_t pixel) const
86{
87 return pixel>=fNumPixels ? NULL : fSamplesRaw.GetArray()+pixel*fNumSamples;
88}
89
90// --------------------------------------------------------------------------
91//
92// Return some information about saturation in the raw-data of pixel idx.
93//
94// The search range is defined by [first,last]. Saturation is considered if
95// contents is >= limit.
96//
97// The number of saturating slices are returned and first/last are filled
98// with the first and last saturating slice index w.r.t. the beginning of
99// the raw-data of this pixel not first.
100//
101// Warning: No range checks and no sanity checks are done!
102//
103Int_t MPedestalSubtractedEvt::GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const
104{
105 // Determin saturation of hi-gains
106 USample_t *p0 = GetSamplesRaw(idx);
107
108 USample_t *sat0 = 0; // first saturating slice
109 USample_t *sat1 = 0; // last saturating slice
110
111 Int_t num = 0;
112
113 const USample_t *end = p0+last;
114 for (USample_t *ptr=p0+first; ptr<=end; ptr++)
115 {
116 if (*ptr>=limit)
117 {
118 sat1 = ptr;
119 if (!sat0)
120 sat0 = ptr;
121 num++;
122 }
123 }
124
125 last = sat1 ? sat1-p0 : -1;
126 first = sat0 ? sat0-p0 : -1;
127
128 return num;
129}
130
131void MPedestalSubtractedEvt::GetStat(const Int_t idx, Float_t &mean, Float_t &rms) const
132{
133 if (fNumSamples<20)
134 return;
135
136 // Get pointer to first slice to be considered
137 Float_t const *sam = GetSamples(idx);
138 Float_t const *beg = sam;
139
140 Double_t sum = 0;
141 Double_t sum2 = 0;
142
143 for (const Float_t *ptr=beg+10; ptr<sam+fNumSamples-10; ptr++)
144 {
145 sum += *ptr;
146 sum2 += *ptr * *ptr;
147 }
148
149 sum /= fNumSamples-20;
150 sum2 /= fNumSamples-20;
151
152 mean = sum;
153 rms = TMath::Sqrt(sum2 - sum * sum);
154}
155
156// --------------------------------------------------------------------------
157//
158// Get the maximum of the pedestal subtracted slices [first,last] of
159// pixel with index idx.
160//
161// The position returned is the index of the position of the pedestal
162// subtracted maximum w.r.t. to first.
163// The value returned is the maximum corresponding to this index.
164//
165// Warning: No range checks and no sanity checks are done!
166//
167Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Float_t &val) const
168{
169 // Get pointer to first slice to be considered
170 Float_t const *sam = GetSamples(idx);
171
172 Float_t const *beg = sam+first;
173
174 // The best information so far: the first slice is the maximum
175 const Float_t *max = beg;
176
177 for (const Float_t *ptr=beg+1; ptr<=sam+last; ptr++)
178 if (*ptr>*max)
179 max = ptr;
180
181 val = *max;
182 return max-beg;
183}
184
185// --------------------------------------------------------------------------
186//
187// Get the maximum of the raw slices [first,last] of pixel with index idx.
188//
189// The position returned is the index of the position of the raw-data
190// w.r.t. to first.
191// The value returned is the maximum corresponding to this index.
192//
193// Warning: No range checks and no sanity checks are done!
194//
195Int_t MPedestalSubtractedEvt::GetRawMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const
196{
197 // Get pointer to first slice to be considered
198 USample_t const *sam = GetSamplesRaw(idx);
199
200 USample_t const *beg = sam+first;
201
202 // The best information so far: the first slice is the maximum
203 const USample_t *max = beg;
204
205 for (const USample_t *ptr=beg+1; ptr<=sam+last; ptr++)
206 if (*ptr>*max)
207 max = ptr;
208
209 val = *max;
210 return max-beg;
211}
212
213void MPedestalSubtractedEvt::Print(Option_t *o) const
214{
215 *fLog << all << GetDescriptor() << endl;
216 *fLog << " Num Pixels: " << fNumPixels << " (" << fNumSamples << " samples)" << endl;
217 *fLog << " Samples raw:" << hex << endl;;
218 for (UInt_t idx=0; idx<fNumPixels; idx++)
219 {
220 *fLog << setw(4) << dec << idx << hex << ":";
221 for (UInt_t i=0; i<fNumSamples; i++)
222 *fLog << " " << fSamplesRaw[idx*fNumSamples+i];
223 *fLog << endl;
224 }
225 *fLog << dec << endl;
226 *fLog << " Samples:" << endl;;
227 for (UInt_t idx=0; idx<fNumPixels; idx++)
228 {
229 *fLog << setw(4) << idx << ":";
230 for (UInt_t i=0; i<fNumSamples; i++)
231 *fLog << " " << fSamples[idx*fNumSamples+i];
232 *fLog << endl;
233 }
234 *fLog << endl;
235}
236
237Bool_t MPedestalSubtractedEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
238{
239 switch (type)
240 {
241 case 0:
242 case 1:
243 {
244 Float_t mean, rms;
245 GetStat(idx, mean, rms);
246 val = type==0 ? mean : rms;
247 }
248 break;
249 case 2:
250 {
251 Float_t flt;
252 GetMaxPos(idx, flt);
253 val = flt;
254 }
255 break;
256 }
257
258 return kTRUE;
259}
260
261/*
262#include <TSpline.h>
263#include "MArrayD.h"
264void MPedestalSubtractedEvt::InterpolateSaturation(const Int_t idx, Int_t limit, Int_t first, Int_t last) const
265{
266 MArrayD x(GetNumSamples());
267 MArrayD y(GetNumSamples());
268
269 Float_t *s = GetSamples(idx);
270
271 Int_t n = 0;
272 for (unsigned int i=0; i<GetNumSamples(); i++)
273 {
274 if (s[i]>limit)
275 continue;
276 x[n] = i;
277 y[n] = s[i];
278 n++;
279 }
280
281 TSpline5 sp("", x.GetArray(), y.GetArray(), n);
282
283 for (unsigned int i=0; i<GetNumSamples(); i++)
284 {
285 if (s[i]>limit)
286 s[i] = sp.Eval(i);
287 }
288}
289*/
Note: See TracBrowser for help on using the repository browser.