source: trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc2.cc@ 3158

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