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

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