source: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc@ 9488

Last change on this file since 9488 was 9226, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.2 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.7 2009-01-17 14:52:41 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#include "MPedestalSubtractedEvt.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
131// --------------------------------------------------------------------------
132//
133// Get the maximum of the pedestal subtracted slices [first,last] of
134// pixel with index idx.
135//
136// The position returned is the index of the position of the pedestal
137// subtracted maximum w.r.t. to first.
138// The value returned is the maximum corresponding to this index.
139//
140// Warning: No range checks and no sanity checks are done!
141//
142Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Float_t &val) const
143{
144 // Get pointer to first slice to be considered
145 Float_t const *sam = GetSamples(idx);
146
147 Float_t const *beg = sam+first;
148
149 // The best information so far: the first slice is the maximum
150 const Float_t *max = beg;
151
152 for (const Float_t *ptr=beg+1; ptr<=sam+last; ptr++)
153 if (*ptr>*max)
154 max = ptr;
155
156 val = *max;
157 return max-beg;
158}
159
160// --------------------------------------------------------------------------
161//
162// Get the maximum of the raw slices [first,last] of pixel with index idx.
163//
164// The position returned is the index of the position of the raw-data
165// w.r.t. to first.
166// The value returned is the maximum corresponding to this index.
167//
168// Warning: No range checks and no sanity checks are done!
169//
170Int_t MPedestalSubtractedEvt::GetRawMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const
171{
172 // Get pointer to first slice to be considered
173 USample_t const *sam = GetSamplesRaw(idx);
174
175 USample_t const *beg = sam+first;
176
177 // The best information so far: the first slice is the maximum
178 const USample_t *max = beg;
179
180 for (const USample_t *ptr=beg+1; ptr<=sam+last; ptr++)
181 if (*ptr>*max)
182 max = ptr;
183
184 val = *max;
185 return max-beg;
186}
187
188void MPedestalSubtractedEvt::Print(Option_t *o) const
189{
190 *fLog << all << GetDescriptor() << endl;
191 *fLog << " Num Pixels: " << fNumPixels << " (" << fNumSamples << " samples)" << endl;
192 *fLog << " Samples raw:" << hex << endl;;
193 for (UInt_t idx=0; idx<fNumPixels; idx++)
194 {
195 *fLog << setw(4) << dec << idx << hex << ":";
196 for (UInt_t i=0; i<fNumSamples; i++)
197 *fLog << " " << fSamplesRaw[idx*fNumSamples+i];
198 *fLog << endl;
199 }
200 *fLog << dec << endl;
201 *fLog << " Samples:" << endl;;
202 for (UInt_t idx=0; idx<fNumPixels; idx++)
203 {
204 *fLog << setw(4) << idx << ":";
205 for (UInt_t i=0; i<fNumSamples; i++)
206 *fLog << " " << fSamples[idx*fNumSamples+i];
207 *fLog << endl;
208 }
209 *fLog << endl;
210}
211
212/*
213#include <TSpline.h>
214#include "MArrayD.h"
215void MPedestalSubtractedEvt::InterpolateSaturation(const Int_t idx, Int_t limit, Int_t first, Int_t last) const
216{
217 MArrayD x(GetNumSamples());
218 MArrayD y(GetNumSamples());
219
220 Float_t *s = GetSamples(idx);
221
222 Int_t n = 0;
223 for (unsigned int i=0; i<GetNumSamples(); i++)
224 {
225 if (s[i]>limit)
226 continue;
227 x[n] = i;
228 y[n] = s[i];
229 n++;
230 }
231
232 TSpline5 sp("", x.GetArray(), y.GetArray(), n);
233
234 for (unsigned int i=0; i<GetNumSamples(); i++)
235 {
236 if (s[i]>limit)
237 s[i] = sp.Eval(i);
238 }
239}
240*/
Note: See TracBrowser for help on using the repository browser.