source: trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc@ 3188

Last change on this file since 3188 was 3032, checked in by gaug, 21 years ago
*** empty log message ***
File size: 5.7 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): Sebastian Raducci 12/2003 <mailto:raducci@fisica.uniud.it>
19!
20! Copyright: MAGIC Software Development, 2002-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MArrivalTimeCalc
28//
29// This is a task that calculates the arrival times of photons.
30// It returns the absolute maximum of the spline that interpolates
31// the FADC slices
32//
33// Input Containers:
34// MRawEvtData
35//
36// Output Containers:
37// MArrivalTime
38// MRawEvtData
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MArrivalTimeCalc.h"
42
43#include <TSpline.h>
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MParList.h"
49
50#include "MGeomCam.h"
51#include "MArrivalTime.h"
52#include "MRawEvtData.h"
53#include "MRawEvtPixelIter.h"
54
55ClassImp(MArrivalTimeCalc);
56
57using namespace std;
58
59// --------------------------------------------------------------------------
60//
61// Default constructor.
62//
63// Initialize step size by default to 0.03 time slices == 100 ps.
64//
65MArrivalTimeCalc::MArrivalTimeCalc(const char *name, const char *title)
66 : fStepSize(0.03)
67{
68
69 fName = name ? name : "MArrivalTimeCalc";
70 fTitle = title ? title : "Calculate photons arrival time";
71
72}
73
74// --------------------------------------------------------------------------
75//
76// The PreProcess searches for the following input containers:
77// - MRawEvtData
78// - MArrivalTime
79//
80// The following output containers are also searched and created if
81// they were not found:
82// - MArrivalTime
83//
84
85Int_t MArrivalTimeCalc::PreProcess(MParList *pList)
86{
87
88
89 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
90 if (!fRawEvt)
91 {
92 *fLog << err << "MRawEvtData not found... aborting." << endl;
93 return kFALSE;
94 }
95
96 fArrTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
97 if (!fArrTime)
98 return kFALSE;
99
100 return kTRUE;
101}
102
103// --------------------------------------------------------------------------
104//
105// The ReInit searches for the following input containers:
106// - MGeomCam
107//
108Bool_t MArrivalTimeCalc::ReInit(MParList *pList)
109{
110 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
111 if (!cam)
112 {
113 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
114 return kFALSE;
115 }
116
117 return kTRUE;
118}
119
120// --------------------------------------------------------------------------
121//
122// Evaluation of the mean arrival times (spline interpolation)
123// per pixel and store them in the MArrivalTime container.
124//
125Int_t MArrivalTimeCalc::Process()
126{
127
128 MRawEvtPixelIter pixel(fRawEvt);
129
130 while (pixel.Next())
131 {
132
133 const UInt_t idx = pixel.GetPixelId();
134 Float_t max = 0.;
135
136
137 //
138 // If pixel is saturated we use LoGains
139 //
140 if (pixel.GetMaxHiGainSample() == 0xff && pixel.HasLoGain())
141 {
142
143 const Short_t nslices = fRawEvt->GetNumLoGainSamples();
144 max = Calc(pixel.GetLoGainSamples(),nslices);
145 }
146
147
148 //
149 // Use HiGains
150 //
151 else if (pixel.HasLoGain())
152 {
153
154 const Short_t nslices = fRawEvt->GetNumHiGainSamples();
155 max = Calc(pixel.GetHiGainSamples(),nslices);
156 }
157
158 //
159 // If pixel is saturated and hasn't lo gains we do nothing, it's value remains -1
160 //
161 fArrTime->SetTime(idx,max);
162
163 }
164
165 fArrTime->SetReadyToSave();
166
167 return kTRUE;
168}
169
170// --------------------------------------------------------------------------
171//
172// Calculates the arrival time for each pixel
173// Possible Methods
174// Case 1: Spline5 (From TSpline5 Root Class)
175//
176Float_t MArrivalTimeCalc::Calc(const Byte_t *fadcSamples, const Short_t nslices)
177{
178
179 //
180 // Initialize a double pointer with filled FADC slices
181 //
182 Double_t ptr[nslices];
183
184 //
185 // Initialize the spline
186 //
187 for (Int_t i=0; i<nslices; i++)
188 ptr[i]=(Double_t)fadcSamples[i];
189
190 TSpline5 spline("spline",0.,(Double_t)(nslices - 1),ptr,nslices);
191
192 //
193 // Now find the half maximum (!)
194 // evaluating the spline function at every fStepSize time slice
195 //
196 Double_t abscissa=0;
197 Double_t maxAb =0;
198 Double_t maxOrd =0;
199
200 while (abscissa <= nslices - 1)
201 {
202 const Double_t swap = spline.Eval(abscissa);
203
204 if (swap > maxOrd)
205 {
206 maxOrd = swap;
207 maxAb = abscissa;
208 }
209 // make step size a bit bigger first
210 abscissa += fStepSize;
211 // abscissa += fStepSize;
212 }
213
214 //
215 // another (much smaller) loop to move back from the maximum
216 //
217 Double_t halfMaxAb = 0;
218
219 abscissa = maxAb;
220
221 while (abscissa > 0)
222 {
223
224 const Double_t swap = spline.Eval(abscissa);
225
226 if (swap < maxOrd/2.)
227 {
228 halfMaxAb = abscissa;
229 break;
230 }
231
232 abscissa -= fStepSize;
233 }
234
235
236 // return (Float_t)maxAb;
237 return (Float_t)halfMaxAb;
238}
239
Note: See TracBrowser for help on using the repository browser.