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

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