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

Last change on this file since 2970 was 2944, 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 return kTRUE;
113}
114
115// --------------------------------------------------------------------------
116//
117// Evaluation of the mean arrival times (spline interpolation)
118// per pixel and store them in the MArrivalTime container.
119//
120Int_t MArrivalTimeCalc::Process()
121{
122
123 MRawEvtPixelIter pixel(fRawEvt);
124
125 while (pixel.Next())
126 {
127
128 const UInt_t idx = pixel.GetPixelId();
129 Float_t max = 0.;
130
131
132 //
133 // If pixel is saturated we use LoGains
134 //
135 if (pixel.GetMaxHiGainSample() == 0xff && pixel.HasLoGain())
136 {
137
138 const Short_t nslices = fRawEvt->GetNumLoGainSamples();
139 max = Calc(pixel.GetLoGainSamples(),nslices);
140 }
141
142
143 //
144 // Use HiGains
145 //
146 else if (pixel.HasLoGain())
147 {
148
149 const Short_t nslices = fRawEvt->GetNumHiGainSamples();
150 max = Calc(pixel.GetHiGainSamples(),nslices);
151 }
152
153 //
154 // If pixel is saturated and hasn't lo gains we do nothing, it's value remains -1
155 //
156 fArrTime->SetTime(idx,max);
157
158 }
159
160 fArrTime->SetReadyToSave();
161
162 return kTRUE;
163}
164
165// --------------------------------------------------------------------------
166//
167// Calculates the arrival time for each pixel
168// Possible Methods
169// Case 1: Spline5 (From TSpline5 Root Class)
170//
171Float_t MArrivalTimeCalc::Calc(const Byte_t *fadcSamples, const Short_t nslices)
172{
173
174 //
175 // Initialize a double pointer with filled FADC slices
176 //
177 Double_t ptr[nslices];
178
179 //
180 // Initialize the spline
181 //
182 for (Int_t i=0; i<nslices; i++)
183 ptr[i]=(Double_t)fadcSamples[i];
184
185 TSpline5 spline("spline",0.,(Double_t)(nslices - 1),ptr,nslices);
186
187 //
188 // Now find the maximum evaluating the spline function at every 1/10 time slice
189 //
190 Double_t abscissa=0;
191 Double_t maxAb =0;
192 Double_t maxOrd =0;
193
194 while (abscissa <= nslices - 1)
195 {
196 const Double_t swap = spline.Eval(abscissa);
197
198 if (swap > maxOrd)
199 {
200 maxOrd = swap;
201 maxAb = abscissa;
202 }
203 abscissa += fStepSize;
204 }
205
206 return (Float_t)maxAb;
207}
208
Note: See TracBrowser for help on using the repository browser.