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

Last change on this file since 3842 was 3628, checked in by gaug, 21 years ago
*** empty log message ***
File size: 5.4 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! Author(s): Sebastian Raducci 12/2003 <mailto:raducci@fisica.uniud.it>
18!
19! Copyright: MAGIC Software Development, 2002-2004
20!
21!
22\* ======================================================================== */
23
24//////////////////////////////////////////////////////////////////////////////
25//
26// MArrivalTimeCalc
27//
28// This is a task that calculates the arrival times of photons.
29// It returns the absolute maximum of the spline that interpolates
30// the FADC slices
31//
32// Input Containers:
33// MRawEvtData
34//
35// Output Containers:
36// MArrivalTime
37// MRawEvtData
38//
39//////////////////////////////////////////////////////////////////////////////
40#include "MArrivalTimeCalc.h"
41
42#include "MCubicSpline.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48
49#include "MGeomCam.h"
50#include "MArrivalTimeCam.h"
51#include "MArrivalTimePix.h"
52
53#include "MRawEvtData.h"
54#include "MRawEvtPixelIter.h"
55
56#include "MPedestalCam.h"
57#include "MPedestalPix.h"
58
59ClassImp(MArrivalTimeCalc);
60
61using namespace std;
62
63const Byte_t MArrivalTimeCalc::fgSaturationLimit = 254;
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 SetSaturationLimit();
76}
77
78// --------------------------------------------------------------------------
79//
80// The PreProcess searches for the following input containers:
81// - MRawEvtData
82// - MPedestalCam
83//
84// The following output containers are also searched and created if
85// they were not found:
86// - MArrivalTimeCam
87//
88
89Int_t MArrivalTimeCalc::PreProcess(MParList *pList)
90{
91
92
93 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
94 if (!fRawEvt)
95 {
96 *fLog << err << "MRawEvtData not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
101 if (!fPedestals)
102 {
103 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
104 return kFALSE;
105 }
106
107
108 fArrTime = (MArrivalTimeCam*)pList->FindCreateObj(AddSerialNumber("MArrivalTimeCam"));
109 if (!fArrTime)
110 return kFALSE;
111
112 return kTRUE;
113}
114
115// --------------------------------------------------------------------------
116//
117// The ReInit searches for the following input containers:
118// - MGeomCam
119//
120Bool_t MArrivalTimeCalc::ReInit(MParList *pList)
121{
122 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
123 if (!cam)
124 {
125 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
126 return kFALSE;
127 }
128
129 return kTRUE;
130}
131
132// --------------------------------------------------------------------------
133//
134// Evaluation of the mean arrival times (spline interpolation)
135// per pixel and store them in the MArrivalTime container.
136//
137Int_t MArrivalTimeCalc::Process()
138{
139
140 MRawEvtPixelIter pixel(fRawEvt);
141
142 while (pixel.Next())
143 {
144
145 const UInt_t idx = pixel.GetPixelId();
146 Float_t time = 0.;
147
148
149 //
150 // If pixel is saturated we use LoGains
151 //
152 if ((pixel.GetMaxHiGainSample() >= fSaturationLimit) && pixel.HasLoGain())
153 {
154
155 const Short_t nslices = fRawEvt->GetNumLoGainSamples();
156 time = Calc(pixel.GetLoGainSamples(),nslices,idx);
157 }
158
159
160 //
161 // Use HiGains
162 //
163 else if (pixel.HasLoGain())
164 {
165
166 const Short_t nslices = fRawEvt->GetNumHiGainSamples();
167 time = Calc(pixel.GetHiGainSamples(),nslices,idx);
168 }
169
170 //
171 // If pixel is saturated and hasn't lo gains we do nothing, it's value remains -1
172 //
173 MArrivalTimePix &pix = (*fArrTime)[idx];
174 pix.SetArrivalTime(time,0.);
175 }
176
177 fArrTime->SetReadyToSave();
178
179 return kTRUE;
180}
181
182// --------------------------------------------------------------------------
183//
184// Calculates the arrival time for each pixel
185// Possible Methods
186// Case 1: MCubicSpline (3rd order spline)
187//
188Float_t MArrivalTimeCalc::Calc(const Byte_t *fadcSamples, const Short_t nslices, const UInt_t idx)
189{
190
191 //
192 // Initialize the spline
193 //
194 MCubicSpline *spline = new MCubicSpline(fadcSamples);
195
196 //
197 // Now find the maximum
198 //
199 Double_t abMaximum = spline->EvalAbMax();
200 Double_t maximum = spline->EvalMax();
201 const MPedestalPix &ped = (*fPedestals)[idx];
202 const Double_t pedestal = ped.GetPedestal();
203 const Double_t halfMax = (maximum + pedestal)/2.;
204 Float_t time = (halfMax > pedestal) ? (Float_t ) spline->FindVal(halfMax,abMaximum,'l'): 0.0;
205 delete spline;
206 return time;
207
208}
209
Note: See TracBrowser for help on using the repository browser.