1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.1 2006-10-24 08:22: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 |
|
---|
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 pixels, UInt_t samples)
|
---|
50 | {
|
---|
51 | fNumSamples = samples;
|
---|
52 | fNumPixels = pixels;
|
---|
53 |
|
---|
54 | fSamples.Set(pixels*samples);
|
---|
55 | fSamplesRaw.Set(pixels*samples);
|
---|
56 |
|
---|
57 | fSamples.Reset();
|
---|
58 | fSamplesRaw.Reset();
|
---|
59 | }
|
---|
60 |
|
---|
61 | // --------------------------------------------------------------------------
|
---|
62 | //
|
---|
63 | // Return a pointer to the first slice with subtracted pedestal of
|
---|
64 | // the samples of the pixel with given pixel-index. If the number
|
---|
65 | // exceeds the number of pixels NULL is returned.
|
---|
66 | //
|
---|
67 | // The user is responsible not to exceed the slices for one pixel!
|
---|
68 | //
|
---|
69 | Float_t *MPedestalSubtractedEvt::GetSamples(UInt_t pixel) const
|
---|
70 | {
|
---|
71 | return pixel>=fNumPixels ? NULL : fSamples.GetArray()+pixel*fNumSamples;
|
---|
72 | }
|
---|
73 |
|
---|
74 | // --------------------------------------------------------------------------
|
---|
75 | //
|
---|
76 | // Return a pointer to the first slice of the raw-data samples of the pixel
|
---|
77 | // with given pixel-index. If the number exceeds the number of
|
---|
78 | // pixels NULL is returned.
|
---|
79 | //
|
---|
80 | // The user is responsible not to exceed the slices for one pixel!
|
---|
81 | //
|
---|
82 | Byte_t *MPedestalSubtractedEvt::GetSamplesRaw(UInt_t pixel) const
|
---|
83 | {
|
---|
84 | return pixel>=fNumPixels ? NULL : fSamplesRaw.GetArray()+pixel*fNumSamples;
|
---|
85 | }
|
---|
86 |
|
---|
87 | // --------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // Return some information about saturation in the raw-data of pixel idx.
|
---|
90 | //
|
---|
91 | // The search range is defined by [first,last]. Saturation is considered if
|
---|
92 | // contents is >= limit.
|
---|
93 | //
|
---|
94 | // The number of saturating slices are returned and first/last are filled
|
---|
95 | // with the first and last saturating slice index w.r.t. the beginning of
|
---|
96 | // the raw-data of this pixel not first.
|
---|
97 | //
|
---|
98 | // Warning: No range checks and no sanity checks are done!
|
---|
99 | //
|
---|
100 | Int_t MPedestalSubtractedEvt::GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const
|
---|
101 | {
|
---|
102 | // Determin saturation of hi-gains
|
---|
103 | Byte_t *p0 = GetSamplesRaw(idx);
|
---|
104 |
|
---|
105 | Byte_t *sathi0 = 0; // first saturating hi-gain slice
|
---|
106 | Byte_t *sathi1 = 0; // last saturating hi-gain slice
|
---|
107 |
|
---|
108 | Int_t num = 0;
|
---|
109 |
|
---|
110 | const Byte_t *end = p0+last;
|
---|
111 | for (Byte_t *ptr=p0+first; ptr<=end; ptr++)
|
---|
112 | {
|
---|
113 | if (*ptr>=limit)
|
---|
114 | {
|
---|
115 | sathi1 = ptr;
|
---|
116 | if (!sathi0)
|
---|
117 | sathi0 = ptr;
|
---|
118 | num++;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | last = sathi1 ? sathi1-p0 : -1;
|
---|
123 | first = sathi0 ? sathi0-p0 : -1;
|
---|
124 |
|
---|
125 | return num;
|
---|
126 | }
|
---|
127 |
|
---|
128 | // --------------------------------------------------------------------------
|
---|
129 | //
|
---|
130 | // Get the maximum of the slices [first,last] of pixel index.
|
---|
131 | //
|
---|
132 | // The position returned is the index of the position of the pedestal
|
---|
133 | // subtracted maximum w.r.t. to first.
|
---|
134 | // The value returned is the maximum of the raw-data.
|
---|
135 | //
|
---|
136 | // Warning: No range checks and no sanity checks are done!
|
---|
137 | //
|
---|
138 | Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Int_t &val) const
|
---|
139 | {
|
---|
140 | // Get pointer to first slice to be considered
|
---|
141 | Byte_t const *samb = GetSamplesRaw(idx);
|
---|
142 | Float_t const *samf = GetSamples(idx);
|
---|
143 |
|
---|
144 | Byte_t const *ptrb = samb+first;
|
---|
145 | Float_t const *ptrf = samf+first;
|
---|
146 |
|
---|
147 | // The best information so far: the first slice is the maximum
|
---|
148 | const Byte_t *maxb = ptrb;
|
---|
149 | const Float_t *maxf = ptrf;
|
---|
150 |
|
---|
151 | // Store the pointer to the first slice
|
---|
152 | // const Byte_t *begb = ptrb;
|
---|
153 | const Float_t *begf = ptrf;
|
---|
154 |
|
---|
155 | // Calculate the last slice to be considered
|
---|
156 | const Byte_t *endb = samb+last;
|
---|
157 |
|
---|
158 | while (ptrb<endb)
|
---|
159 | {
|
---|
160 | // Pre-increment: check the second slice first
|
---|
161 | if (*++ptrb>*maxb)
|
---|
162 | maxb = ptrb;
|
---|
163 | if (*++ptrf>*maxf)
|
---|
164 | maxf = ptrf;
|
---|
165 | }
|
---|
166 |
|
---|
167 | val = *maxb;
|
---|
168 | return maxf-begf;
|
---|
169 | }
|
---|
170 |
|
---|