| 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 "MLogManip.h"
|
|---|
| 35 |
|
|---|
| 36 | ClassImp(MPedestalSubtractedEvt);
|
|---|
| 37 |
|
|---|
| 38 | using namespace std;
|
|---|
| 39 |
|
|---|
| 40 | // --------------------------------------------------------------------------
|
|---|
| 41 | //
|
|---|
| 42 | // Initialize number of samples (per pixel) and number of pixels.
|
|---|
| 43 | //
|
|---|
| 44 | // Initialize the correct length of fSamples and fSamplesRaw
|
|---|
| 45 | //
|
|---|
| 46 | // And reset its contents to 0.
|
|---|
| 47 | //
|
|---|
| 48 | void MPedestalSubtractedEvt::InitSamples(UInt_t samples, UInt_t pixels)
|
|---|
| 49 | {
|
|---|
| 50 | fNumSamples = samples;
|
|---|
| 51 |
|
|---|
| 52 | if (pixels>0)
|
|---|
| 53 | fNumPixels = pixels;
|
|---|
| 54 |
|
|---|
| 55 | fSamples.Set(fNumPixels*fNumSamples);
|
|---|
| 56 | fSamplesRaw.Set(fNumPixels*fNumSamples);
|
|---|
| 57 |
|
|---|
| 58 | fSamples.Reset();
|
|---|
| 59 | fSamplesRaw.Reset();
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | // --------------------------------------------------------------------------
|
|---|
| 63 | //
|
|---|
| 64 | // Return a pointer to the first slice with subtracted pedestal of
|
|---|
| 65 | // the samples of the pixel with given pixel-index. If the number
|
|---|
| 66 | // exceeds the number of pixels NULL is returned.
|
|---|
| 67 | //
|
|---|
| 68 | // The user is responsible not to exceed the slices for one pixel!
|
|---|
| 69 | //
|
|---|
| 70 | Float_t *MPedestalSubtractedEvt::GetSamples(UInt_t pixel) const
|
|---|
| 71 | {
|
|---|
| 72 | return pixel>=fNumPixels ? NULL : fSamples.GetArray()+pixel*fNumSamples;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // --------------------------------------------------------------------------
|
|---|
| 76 | //
|
|---|
| 77 | // Return a pointer to the first slice of the raw-data samples of the pixel
|
|---|
| 78 | // with given pixel-index. If the number exceeds the number of
|
|---|
| 79 | // pixels NULL is returned.
|
|---|
| 80 | //
|
|---|
| 81 | // The user is responsible not to exceed the slices for one pixel!
|
|---|
| 82 | //
|
|---|
| 83 | USample_t *MPedestalSubtractedEvt::GetSamplesRaw(UInt_t pixel) const
|
|---|
| 84 | {
|
|---|
| 85 | return pixel>=fNumPixels ? NULL : fSamplesRaw.GetArray()+pixel*fNumSamples;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | // --------------------------------------------------------------------------
|
|---|
| 89 | //
|
|---|
| 90 | // Return some information about saturation in the raw-data of pixel idx.
|
|---|
| 91 | //
|
|---|
| 92 | // The search range is defined by [first,last]. Saturation is considered if
|
|---|
| 93 | // contents is >= limit.
|
|---|
| 94 | //
|
|---|
| 95 | // The number of saturating slices are returned and first/last are filled
|
|---|
| 96 | // with the first and last saturating slice index w.r.t. the beginning of
|
|---|
| 97 | // the raw-data of this pixel not first.
|
|---|
| 98 | //
|
|---|
| 99 | // Warning: No range checks and no sanity checks are done!
|
|---|
| 100 | //
|
|---|
| 101 | Int_t MPedestalSubtractedEvt::GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const
|
|---|
| 102 | {
|
|---|
| 103 | // Determin saturation of hi-gains
|
|---|
| 104 | USample_t *p0 = GetSamplesRaw(idx);
|
|---|
| 105 |
|
|---|
| 106 | USample_t *sat0 = 0; // first saturating slice
|
|---|
| 107 | USample_t *sat1 = 0; // last saturating slice
|
|---|
| 108 |
|
|---|
| 109 | Int_t num = 0;
|
|---|
| 110 |
|
|---|
| 111 | const USample_t *end = p0+last;
|
|---|
| 112 | for (USample_t *ptr=p0+first; ptr<=end; ptr++)
|
|---|
| 113 | {
|
|---|
| 114 | if (*ptr>=limit)
|
|---|
| 115 | {
|
|---|
| 116 | sat1 = ptr;
|
|---|
| 117 | if (!sat0)
|
|---|
| 118 | sat0 = ptr;
|
|---|
| 119 | num++;
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | last = sat1 ? sat1-p0 : -1;
|
|---|
| 124 | first = sat0 ? sat0-p0 : -1;
|
|---|
| 125 |
|
|---|
| 126 | return num;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | // --------------------------------------------------------------------------
|
|---|
| 130 | //
|
|---|
| 131 | // Get the maximum of the pedestal subtracted slices [first,last] of
|
|---|
| 132 | // pixel with index idx.
|
|---|
| 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 corresponding to this index.
|
|---|
| 137 | //
|
|---|
| 138 | // Warning: No range checks and no sanity checks are done!
|
|---|
| 139 | //
|
|---|
| 140 | Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Float_t &val) const
|
|---|
| 141 | {
|
|---|
| 142 | // Get pointer to first slice to be considered
|
|---|
| 143 | Float_t const *sam = GetSamples(idx);
|
|---|
| 144 |
|
|---|
| 145 | Float_t const *beg = sam+first;
|
|---|
| 146 |
|
|---|
| 147 | // The best information so far: the first slice is the maximum
|
|---|
| 148 | const Float_t *max = beg;
|
|---|
| 149 |
|
|---|
| 150 | for (const Float_t *ptr=beg+1; ptr<=sam+last; ptr++)
|
|---|
| 151 | if (*ptr>*max)
|
|---|
| 152 | max = ptr;
|
|---|
| 153 |
|
|---|
| 154 | val = *max;
|
|---|
| 155 | return max-beg;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | // --------------------------------------------------------------------------
|
|---|
| 159 | //
|
|---|
| 160 | // Get the maximum of the raw slices [first,last] of pixel with index idx.
|
|---|
| 161 | //
|
|---|
| 162 | // The position returned is the index of the position of the raw-data
|
|---|
| 163 | // w.r.t. to first.
|
|---|
| 164 | // The value returned is the maximum corresponding to this index.
|
|---|
| 165 | //
|
|---|
| 166 | // Warning: No range checks and no sanity checks are done!
|
|---|
| 167 | //
|
|---|
| 168 | Int_t MPedestalSubtractedEvt::GetRawMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const
|
|---|
| 169 | {
|
|---|
| 170 | // Get pointer to first slice to be considered
|
|---|
| 171 | USample_t const *sam = GetSamplesRaw(idx);
|
|---|
| 172 |
|
|---|
| 173 | USample_t const *beg = sam+first;
|
|---|
| 174 |
|
|---|
| 175 | // The best information so far: the first slice is the maximum
|
|---|
| 176 | const USample_t *max = beg;
|
|---|
| 177 |
|
|---|
| 178 | for (const USample_t *ptr=beg+1; ptr<=sam+last; ptr++)
|
|---|
| 179 | if (*ptr>*max)
|
|---|
| 180 | max = ptr;
|
|---|
| 181 |
|
|---|
| 182 | val = *max;
|
|---|
| 183 | return max-beg;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | void MPedestalSubtractedEvt::Print(Option_t *o) const
|
|---|
| 187 | {
|
|---|
| 188 | *fLog << all << GetDescriptor() << endl;
|
|---|
| 189 | *fLog << " Num Pixels: " << fNumPixels << " (" << fNumSamples << " samples)" << endl;
|
|---|
| 190 | *fLog << " Samples raw:" << hex << endl;;
|
|---|
| 191 | for (UInt_t idx=0; idx<fNumPixels; idx++)
|
|---|
| 192 | {
|
|---|
| 193 | *fLog << setw(4) << dec << idx << hex << ":";
|
|---|
| 194 | for (UInt_t i=0; i<fNumSamples; i++)
|
|---|
| 195 | *fLog << " " << fSamplesRaw[idx*fNumSamples+i];
|
|---|
| 196 | *fLog << endl;
|
|---|
| 197 | }
|
|---|
| 198 | *fLog << dec << endl;
|
|---|
| 199 | *fLog << " Samples:" << endl;;
|
|---|
| 200 | for (UInt_t idx=0; idx<fNumPixels; idx++)
|
|---|
| 201 | {
|
|---|
| 202 | *fLog << setw(4) << idx << ":";
|
|---|
| 203 | for (UInt_t i=0; i<fNumSamples; i++)
|
|---|
| 204 | *fLog << " " << fSamples[idx*fNumSamples+i];
|
|---|
| 205 | *fLog << endl;
|
|---|
| 206 | }
|
|---|
| 207 | *fLog << endl;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | /*
|
|---|
| 211 | #include <TSpline.h>
|
|---|
| 212 | #include "MArrayD.h"
|
|---|
| 213 | void MPedestalSubtractedEvt::InterpolateSaturation(const Int_t idx, Int_t limit, Int_t first, Int_t last) const
|
|---|
| 214 | {
|
|---|
| 215 | MArrayD x(GetNumSamples());
|
|---|
| 216 | MArrayD y(GetNumSamples());
|
|---|
| 217 |
|
|---|
| 218 | Float_t *s = GetSamples(idx);
|
|---|
| 219 |
|
|---|
| 220 | Int_t n = 0;
|
|---|
| 221 | for (unsigned int i=0; i<GetNumSamples(); i++)
|
|---|
| 222 | {
|
|---|
| 223 | if (s[i]>limit)
|
|---|
| 224 | continue;
|
|---|
| 225 | x[n] = i;
|
|---|
| 226 | y[n] = s[i];
|
|---|
| 227 | n++;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | TSpline5 sp("", x.GetArray(), y.GetArray(), n);
|
|---|
| 231 |
|
|---|
| 232 | for (unsigned int i=0; i<GetNumSamples(); i++)
|
|---|
| 233 | {
|
|---|
| 234 | if (s[i]>limit)
|
|---|
| 235 | s[i] = sp.Eval(i);
|
|---|
| 236 | }
|
|---|
| 237 | }
|
|---|
| 238 | */
|
|---|