source: trunk/MagicSoft/Mars/msignal/MArrivalTimeCalc.cc@ 3414

Last change on this file since 3414 was 3413, checked in by raducci, 21 years ago
*** empty log message ***
File size: 5.3 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 "MCubicSpline.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MParList.h"
49
50#include "MGeomCam.h"
51#include "MArrivalTimeCam.h"
52#include "MArrivalTimePix.h"
53
54#include "MRawEvtData.h"
55#include "MRawEvtPixelIter.h"
56
57#include "MPedestalCam.h"
58#include "MPedestalPix.h"
59
60ClassImp(MArrivalTimeCalc);
61
62using namespace std;
63
64// --------------------------------------------------------------------------
65//
66// Default constructor.
67//
68//
69MArrivalTimeCalc::MArrivalTimeCalc(const char *name, const char *title)
70{
71
72 fName = name ? name : "MArrivalTimeCalc";
73 fTitle = title ? title : "Calculate photons arrival time";
74
75}
76
77// --------------------------------------------------------------------------
78//
79// The PreProcess searches for the following input containers:
80// - MRawEvtData
81// - MPedestalCam
82//
83// The following output containers are also searched and created if
84// they were not found:
85// - MArrivalTimeCam
86//
87
88Int_t MArrivalTimeCalc::PreProcess(MParList *pList)
89{
90
91
92 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
93 if (!fRawEvt)
94 {
95 *fLog << err << "MRawEvtData not found... aborting." << endl;
96 return kFALSE;
97 }
98
99 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
100 if (!fPedestals)
101 {
102 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
103 return kFALSE;
104 }
105
106
107 fArrTime = (MArrivalTimeCam*)pList->FindCreateObj(AddSerialNumber("MArrivalTimeCam"));
108 if (!fArrTime)
109 return kFALSE;
110
111 return kTRUE;
112}
113
114// --------------------------------------------------------------------------
115//
116// The ReInit searches for the following input containers:
117// - MGeomCam
118//
119Bool_t MArrivalTimeCalc::ReInit(MParList *pList)
120{
121 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
122 if (!cam)
123 {
124 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
125 return kFALSE;
126 }
127
128 return kTRUE;
129}
130
131// --------------------------------------------------------------------------
132//
133// Evaluation of the mean arrival times (spline interpolation)
134// per pixel and store them in the MArrivalTime container.
135//
136Int_t MArrivalTimeCalc::Process()
137{
138
139 MRawEvtPixelIter pixel(fRawEvt);
140
141 while (pixel.Next())
142 {
143
144 const UInt_t idx = pixel.GetPixelId();
145 Float_t time = 0.;
146
147
148 //
149 // If pixel is saturated we use LoGains
150 //
151 if (pixel.GetMaxHiGainSample() == 0xff && pixel.HasLoGain())
152 {
153
154 const Short_t nslices = fRawEvt->GetNumLoGainSamples();
155 time = Calc(pixel.GetLoGainSamples(),nslices,idx);
156 }
157
158
159 //
160 // Use HiGains
161 //
162 else if (pixel.HasLoGain())
163 {
164
165 const Short_t nslices = fRawEvt->GetNumHiGainSamples();
166 time = Calc(pixel.GetHiGainSamples(),nslices,idx);
167 }
168
169 //
170 // If pixel is saturated and hasn't lo gains we do nothing, it's value remains -1
171 //
172 MArrivalTimePix &pix = (*fArrTime)[idx];
173 pix.SetArrivalTime(time,0.);
174 }
175
176 fArrTime->SetReadyToSave();
177
178 return kTRUE;
179}
180
181// --------------------------------------------------------------------------
182//
183// Calculates the arrival time for each pixel
184// Possible Methods
185// Case 1: MCubicSpline (3rd order spline)
186//
187Float_t MArrivalTimeCalc::Calc(const Byte_t *fadcSamples, const Short_t nslices, const UInt_t idx)
188{
189
190 //
191 // Initialize the spline
192 //
193 MCubicSpline *spline = new MCubicSpline(fadcSamples);
194
195 //
196 // Now find the maximum
197 //
198 Double_t abMaximum = spline->EvalAbMax();
199 Double_t maximum = spline->EvalMax();
200 const MPedestalPix &ped = (*fPedestals)[idx];
201 const Double_t pedestal = ped.GetPedestal();
202 const Double_t halfMax = (maximum + pedestal)/2.;
203 Float_t time = (halfMax > pedestal) ? (Float_t ) spline->FindVal(halfMax,abMaximum,'l'): 0.0;
204 delete spline;
205 return time;
206
207}
208
Note: See TracBrowser for help on using the repository browser.