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, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MExtractSignal2
|
---|
29 | //
|
---|
30 | // Calculate the signal as the fWindowSize time slices which have the highest
|
---|
31 | // integral contents.
|
---|
32 | //
|
---|
33 | //
|
---|
34 | //
|
---|
35 | //////////////////////////////////////////////////////////////////////////////
|
---|
36 | #include "MExtractSignal2.h"
|
---|
37 |
|
---|
38 | #include "MLog.h"
|
---|
39 | #include "MLogManip.h"
|
---|
40 |
|
---|
41 | #include "MParList.h"
|
---|
42 |
|
---|
43 | #include "MRawEvtData.h"
|
---|
44 | #include "MRawEvtPixelIter.h"
|
---|
45 |
|
---|
46 | #include "MPedestalCam.h"
|
---|
47 | #include "MPedestalPix.h"
|
---|
48 |
|
---|
49 | #include "MExtractedSignalCam.h"
|
---|
50 | #include "MExtractedSignalPix.h"
|
---|
51 |
|
---|
52 | //#include "MArrivalTime.h"
|
---|
53 |
|
---|
54 | ClassImp(MExtractSignal2);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | const Byte_t MExtractSignal2::fgSaturationLimit = 254;
|
---|
59 | const Byte_t MExtractSignal2::fgFirst = 0;
|
---|
60 | const Byte_t MExtractSignal2::fgLast = 14;
|
---|
61 | const Byte_t MExtractSignal2::fgWindowSize = 6;
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Default constructor.
|
---|
66 | //
|
---|
67 | MExtractSignal2::MExtractSignal2(const char *name, const char *title)
|
---|
68 | : fSaturationLimit(fgSaturationLimit)
|
---|
69 | {
|
---|
70 |
|
---|
71 | fName = name ? name : "MExtractSignal2";
|
---|
72 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
73 |
|
---|
74 | AddToBranchList("MRawEvtData.*");
|
---|
75 |
|
---|
76 | SetRange();
|
---|
77 | }
|
---|
78 |
|
---|
79 | void MExtractSignal2::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast, Byte_t windowsize)
|
---|
80 | {
|
---|
81 |
|
---|
82 | fNumHiGainSamples = hilast-hifirst+1;
|
---|
83 | fNumLoGainSamples = lolast-lofirst+1;
|
---|
84 |
|
---|
85 | fHiGainFirst = hifirst;
|
---|
86 | fLoGainFirst = lofirst;
|
---|
87 |
|
---|
88 |
|
---|
89 | fWindowSize = windowsize & ~1;
|
---|
90 |
|
---|
91 | if (fWindowSize != windowsize)
|
---|
92 | *fLog << warn << "MExtractSignal2::SetRange - window size has to be even, set to: " << int(fWindowSize) << " samples " << endl;
|
---|
93 |
|
---|
94 | if (fWindowSize<2)
|
---|
95 | {
|
---|
96 | fWindowSize = 2;
|
---|
97 | *fLog << warn << "MExtractSignal2::SetRange - window size set to two samples" << endl;
|
---|
98 | }
|
---|
99 |
|
---|
100 | if (fWindowSize > fNumHiGainSamples)
|
---|
101 | {
|
---|
102 | fWindowSize = fNumLoGainSamples & ~1;
|
---|
103 | *fLog << warn << "MExtractSignal2::SetRange - window size set to " << int(fWindowSize) << " samples " << endl;
|
---|
104 | }
|
---|
105 |
|
---|
106 | if (fWindowSize > fNumLoGainSamples)
|
---|
107 | {
|
---|
108 | fWindowSize = fNumLoGainSamples & ~1;
|
---|
109 | *fLog << warn << "MExtractSignal2::SetRange - window size set to " << int(fWindowSize) << " samples " << endl;
|
---|
110 | }
|
---|
111 |
|
---|
112 | fWindowSizeSqrt = TMath::Sqrt((Float_t)fWindowSize);
|
---|
113 |
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | // --------------------------------------------------------------------------
|
---|
119 | //
|
---|
120 | // The PreProcess searches for the following input containers:
|
---|
121 | // - MRawEvtData
|
---|
122 | // - MPedestalCam
|
---|
123 | //
|
---|
124 | // The following output containers are also searched and created if
|
---|
125 | // they were not found:
|
---|
126 | //
|
---|
127 | // - MExtractedSignalCam
|
---|
128 | //
|
---|
129 | Int_t MExtractSignal2::PreProcess(MParList *pList)
|
---|
130 | {
|
---|
131 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
132 | if (!fRawEvt)
|
---|
133 | {
|
---|
134 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
135 | return kFALSE;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
---|
140 | if (!fSignals)
|
---|
141 | return kFALSE;
|
---|
142 |
|
---|
143 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
|
---|
144 | fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
|
---|
145 |
|
---|
146 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
147 | if (!fPedestals)
|
---|
148 | {
|
---|
149 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
150 | return kFALSE;
|
---|
151 | }
|
---|
152 | /*
|
---|
153 | fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
|
---|
154 | if (!fArrivalTime)
|
---|
155 | return kFALSE;
|
---|
156 | */
|
---|
157 | return kTRUE;
|
---|
158 | }
|
---|
159 |
|
---|
160 | void MExtractSignal2::FindSignal(Byte_t *ptr, Byte_t size, Int_t &max, Int_t &sat) const
|
---|
161 | {
|
---|
162 | const Byte_t *end = ptr + size;
|
---|
163 |
|
---|
164 | Int_t sum=0;
|
---|
165 |
|
---|
166 | //
|
---|
167 | // Calculate the sum of the first fWindowSize slices
|
---|
168 | //
|
---|
169 | sat = 0;
|
---|
170 | Byte_t *p = ptr;
|
---|
171 | while (p<ptr+fWindowSize)
|
---|
172 | {
|
---|
173 | sum += *p;
|
---|
174 | if (*p++ >= fSaturationLimit)
|
---|
175 | sat++;
|
---|
176 | }
|
---|
177 |
|
---|
178 | //
|
---|
179 | // Check for saturation in all other slices
|
---|
180 | //
|
---|
181 | while (p<end)
|
---|
182 | if (*p++ >= fSaturationLimit)
|
---|
183 | sat++;
|
---|
184 |
|
---|
185 | //
|
---|
186 | // Calculate the i-th sum as
|
---|
187 | // sum_i+1 = sum_i + slice[i+8] - slice[i]
|
---|
188 | // This is fast and accurate (because we are using int's)
|
---|
189 | //
|
---|
190 | max=sum;
|
---|
191 | for (p=ptr; p+fWindowSize<end; p++)
|
---|
192 | {
|
---|
193 | sum += *(p+fWindowSize) - *p;
|
---|
194 | if (sum>max)
|
---|
195 | max = sum;
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | // --------------------------------------------------------------------------
|
---|
200 | //
|
---|
201 | // Calculate the integral of the FADC of fWindowSize time slices which have the
|
---|
202 | // highest signal
|
---|
203 | //
|
---|
204 | Int_t MExtractSignal2::Process()
|
---|
205 | {
|
---|
206 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
207 | fSignals->Clear();
|
---|
208 |
|
---|
209 | Int_t sat=0;
|
---|
210 | while (pixel.Next())
|
---|
211 | {
|
---|
212 | //
|
---|
213 | // Find signal in hi- and lo-gain
|
---|
214 | //
|
---|
215 | Int_t sumhi, sathi;
|
---|
216 | FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);
|
---|
217 |
|
---|
218 | Int_t sumlo=0;
|
---|
219 | Int_t satlo=0;
|
---|
220 | if (pixel.HasLoGain())
|
---|
221 | {
|
---|
222 | FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
|
---|
223 | if (satlo)
|
---|
224 | sat++;
|
---|
225 | }
|
---|
226 |
|
---|
227 | //
|
---|
228 | // Take correspodning pedestal
|
---|
229 | //
|
---|
230 | const Int_t pixid = pixel.GetPixelId();
|
---|
231 |
|
---|
232 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
233 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
234 |
|
---|
235 | const Float_t pedes = ped.GetPedestal();
|
---|
236 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
237 |
|
---|
238 | //
|
---|
239 | // Set extracted signal with pedestal substracted
|
---|
240 | //
|
---|
241 | pix.SetExtractedSignal(sumhi - pedes*fWindowSize, pedrms*fWindowSizeSqrt,
|
---|
242 | sumlo - pedes*fWindowSize, pedrms*fWindowSizeSqrt);
|
---|
243 |
|
---|
244 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
245 | } /* while (pixel.Next()) */
|
---|
246 |
|
---|
247 | //
|
---|
248 | // Print a warning if evant has saturationg lo-gains
|
---|
249 | //
|
---|
250 | if (sat)
|
---|
251 | *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
|
---|
252 |
|
---|
253 | fSignals->SetReadyToSave();
|
---|
254 |
|
---|
255 | return kTRUE;
|
---|
256 | }
|
---|