source: trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc@ 2903

Last change on this file since 2903 was 2903, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.5 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, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MArrivalTime
28//
29// Times are calculated using the TSpline5 Root Class
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MArrivalTime.h"
33
34#include "MGeomCam.h"
35#include "MGeomPix.h"
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MRawEvtPixelIter.h"
41#include "MRawEvtData.h"
42
43ClassImp(MArrivalTime);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Creates an object containing the arrival time for each pixel in the event
50//
51MArrivalTime::MArrivalTime(const char *name, const char *title)
52{
53 fName = name ? name : "MArrivalTime";
54 fTitle = title ? title : "Photons arrival times Information";
55}
56
57// Sets every pixel arrival time to -1
58void MArrivalTime::CleanArray(const MGeomCam &geom)
59{
60 fData.Set(geom.GetNumPixels());
61 fData.Reset(-1.0);
62}
63
64void MArrivalTime::InitSize(Int_t i)
65{
66
67 if (fData.GetSize() >= i)
68 return;
69 else
70 fData.Set(i);
71}
72
73//
74// Set the arrival time in one pixel
75//
76void MArrivalTime::SetTime(Int_t i, Float_t t)
77{
78
79 if (i >= fData.GetSize())
80 fData.Set(i+1);
81
82 fData.AddAt(t,i);
83}
84
85//
86// Calculates the arrival time for each pixel
87// Possible Methods
88// Case 1: Spline5 (From TSpline5 Root Class)
89//
90//
91
92void MArrivalTime::Calc(const Byte_t *fadcSamples, const Short_t nSlice,
93 const Short_t idx, const MGeomCam &geom)
94{
95
96//Some casts are needed because TSpline5 constructor accepts only Double_t values
97 Double_t ptr[nSlice];
98
99 for (Int_t i = 0; i < nSlice; i++)
100 ptr[i]=(Double_t)fadcSamples[i];
101
102 TSpline5 *spline = new TSpline5("spline",(Double_t) 0,
103 (Double_t)(nSlice - 1),ptr,nSlice);
104//Now find the maximum evaluating the spline function at every 1/10 time slice
105 Double_t abscissa=0.0;
106 Double_t maxAb=0.0;
107 Double_t maxOrd=0.0;
108 Double_t swap;
109 while (abscissa <= nSlice - 1)
110 {
111 swap=spline->Eval(abscissa);
112 if (swap > maxOrd)
113 {
114 maxOrd = swap;
115 maxAb = abscissa;
116 }
117 abscissa += 0.1;
118 }
119 fData[idx]=maxAb;
120}
121
122// -------------------------------------------------------------------------
123//
124// Finds the clusters with similar Arrival Time
125//
126// PRELIMINARY!! For now the Arrival Time is not the one calculated with
127// the splines, but it's the Max Slice Idx
128//
129// TEST!! This method is used only for test. Do not use it until
130// it becomes stable
131//
132
133void MArrivalTime::EvalClusters(const MRawEvtData &evt, const MGeomCam &geom)
134{
135 const Int_t n = geom.GetNumPixels();
136
137 fData2.Set(n);
138 fData2.Reset(-1.0);
139 fData3.Set(n);
140 fData3.Reset(-1.0);
141 fData4.Set(n);
142 fData4.Reset(-1.0);
143 fData5.Set(n);
144 fData5.Reset(-1.0);
145
146 MRawEvtPixelIter pixel((MRawEvtData*)&evt);
147
148// Array that says if a pixel has been already checked or not
149
150 for (Int_t i = 0; i < n; i++)
151 fPixelChecked[i] = kFALSE;
152
153// This fakeData array will be subsituted with the fData Array.
154 fakeData.Set(n);
155 fakeData.Reset();
156
157 while ( pixel.Next() )
158 {
159 fakeData[pixel.GetPixelId()]=pixel.GetIdxMaxHiLoGainSample();
160 }
161// End of fakeData preparation
162 *fLog << warn << "fin qui bene" << endl;
163// Max dimension of cluster
164 Short_t dimCluster;
165
166 while ( pixel.Next() )
167 {
168 if (!fPixelChecked[pixel.GetPixelId()])
169 {
170 dimCluster = 0;
171 fCluster.Set(n);
172 fCluster.Reset(-1);
173 fCluster[dimCluster]=pixel.GetPixelId();
174 dimCluster++;
175
176 CheckNeighbours(evt,geom,
177 pixel.GetPixelId(), &dimCluster);
178
179 if (dimCluster > 4)
180 {
181 for (Int_t i = 0; i < dimCluster; i++)
182 fData5[fCluster[i]]=fakeData[fCluster[i]];
183 }
184 if (dimCluster > 3)
185 {
186 for (Int_t i = 0; i < dimCluster; i++)
187 fData4[fCluster[i]]=fakeData[fCluster[i]];
188 }
189 if (dimCluster > 2)
190 {
191 for (Int_t i = 0; i < dimCluster; i++)
192 fData3[fCluster[i]]=fakeData[fCluster[i]];
193 }
194 if (dimCluster > 1)
195 {
196 for (Int_t i = 0; i < dimCluster; i++)
197 fData2[fCluster[i]]=fakeData[fCluster[i]];
198 }
199 }
200 }
201
202}
203
204// --------------------------------------------------------------------------
205//
206// Function to check the nearest neighbour pixels arrivaltime
207//
208
209void MArrivalTime::CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
210 Short_t idx, Short_t *dimCluster)
211{
212 Byte_t numNeighbors=geom[idx].GetNumNeighbors();
213 fPixelChecked[idx] = kTRUE;
214
215 for (Byte_t i=0x00; i < numNeighbors; i++)
216 {
217
218 if (!fPixelChecked[geom[idx].GetNeighbor(i)] &&
219 fakeData[idx] == fakeData[geom[idx].GetNeighbor(i)])
220 {
221 fCluster[*dimCluster]=geom[idx].GetNeighbor(i);
222 *dimCluster++;
223 CheckNeighbours(evt, geom,
224 geom[idx].GetNeighbor(i), dimCluster);
225 }
226 }
227}
228// --------------------------------------------------------------------------
229//
230// Returns the arrival time value
231//
232
233Bool_t MArrivalTime::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
234{
235 if (idx<0 || idx>=fData.GetSize())
236 return kFALSE;
237
238 switch (type)
239 {
240 case 0:
241 case 1:
242 val = fData[idx];
243 break;
244 case 2:
245 val = fData2[idx];
246 break;
247 case 3:
248 val = fData3[idx];
249 break;
250 case 4:
251 val = fData4[idx];
252 break;
253 case 5:
254 val = fData5[idx];
255 break;
256 }
257
258 return kTRUE;
259}
260
261void MArrivalTime::DrawPixelContent(Int_t num) const
262{
263 *fLog << warn << "MArrivalTime::DrawPixelContent - not available." << endl;
264}
Note: See TracBrowser for help on using the repository browser.