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

Last change on this file since 8339 was 8250, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 5.9 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.2 2007-01-15 12:06:15 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
37ClassImp(MPedestalSubtractedEvt);
38
39using 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//
49void 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//
71Float_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//
84Byte_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//
102Int_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 Byte_t *p0 = GetSamplesRaw(idx);
106
107 Byte_t *sathi0 = 0; // first saturating hi-gain slice
108 Byte_t *sathi1 = 0; // last saturating hi-gain slice
109
110 Int_t num = 0;
111
112 const Byte_t *end = p0+last;
113 for (Byte_t *ptr=p0+first; ptr<=end; ptr++)
114 {
115 if (*ptr>=limit)
116 {
117 sathi1 = ptr;
118 if (!sathi0)
119 sathi0 = ptr;
120 num++;
121 }
122 }
123
124 last = sathi1 ? sathi1-p0 : -1;
125 first = sathi0 ? sathi0-p0 : -1;
126
127 return num;
128}
129
130// --------------------------------------------------------------------------
131//
132// Get the maximum of the slices [first,last] of pixel index.
133//
134// The position returned is the index of the position of the pedestal
135// subtracted maximum w.r.t. to first.
136// The value returned is the maximum of the raw-data.
137//
138// Warning: No range checks and no sanity checks are done!
139//
140Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Int_t &val) const
141{
142 // Get pointer to first slice to be considered
143 Byte_t const *samb = GetSamplesRaw(idx);
144 Float_t const *samf = GetSamples(idx);
145
146 Byte_t const *ptrb = samb+first;
147 Float_t const *ptrf = samf+first;
148
149 // The best information so far: the first slice is the maximum
150 const Byte_t *maxb = ptrb;
151 const Float_t *maxf = ptrf;
152
153 // Store the pointer to the first slice
154// const Byte_t *begb = ptrb;
155 const Float_t *begf = ptrf;
156
157 // Calculate the last slice to be considered
158 const Byte_t *endb = samb+last;
159
160 while (ptrb<endb)
161 {
162 // Pre-increment: check the second slice first
163 if (*++ptrb>*maxb)
164 maxb = ptrb;
165 if (*++ptrf>*maxf)
166 maxf = ptrf;
167 }
168
169 val = *maxb;
170 return maxf-begf;
171}
172
173/*
174#include <TSpline.h>
175#include "MArrayD.h"
176void MPedestalSubtractedEvt::InterpolateSaturation(const Int_t idx, Int_t limit, Int_t first, Int_t last) const
177{
178 MArrayD x(GetNumSamples());
179 MArrayD y(GetNumSamples());
180
181 Float_t *s = GetSamples(idx);
182
183 Int_t n = 0;
184 for (unsigned int i=0; i<GetNumSamples(); i++)
185 {
186 if (s[i]>limit)
187 continue;
188 x[n] = i;
189 y[n] = s[i];
190 n++;
191 }
192
193 TSpline5 sp("", x.GetArray(), y.GetArray(), n);
194
195 for (unsigned int i=0; i<GetNumSamples(); i++)
196 {
197 if (s[i]>limit)
198 s[i] = sp.Eval(i);
199 }
200}
201*/
Note: See TracBrowser for help on using the repository browser.