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

Last change on this file since 2894 was 2785, checked in by raducci, 21 years ago
*** empty log message ***
File size: 6.2 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
64//
65// Calculates the arrival time for each pixel
66// Possible Methods
67// Case 1: Spline5 (From TSpline5 Root Class)
68//
69//
70
71void MArrivalTime::Calc(const Byte_t *fadcSamples, const Short_t nSlice,
72 const Short_t idx, const MGeomCam &geom)
73{
74
75//Some casts are needed because TSpline5 constructor accepts only Double_t values
76 Double_t ptr[nSlice];
77
78 for (Int_t i = 0; i < nSlice; i++)
79 ptr[i]=(Double_t)fadcSamples[i];
80
81 TSpline5 *spline = new TSpline5("spline",(Double_t) 0,
82 (Double_t)(nSlice - 1),ptr,nSlice);
83//Now find the maximum evaluating the spline function at every 1/10 time slice
84 Double_t abscissa=0.0;
85 Double_t maxAb=0.0;
86 Double_t maxOrd=0.0;
87 Double_t swap;
88 while (abscissa <= nSlice - 1)
89 {
90 swap=spline->Eval(abscissa);
91 if (swap > maxOrd)
92 {
93 maxOrd = swap;
94 maxAb = abscissa;
95 }
96 abscissa += 0.1;
97 }
98 fData[idx]=maxAb;
99}
100
101// -------------------------------------------------------------------------
102//
103// Finds the clusters with similar Arrival Time
104//
105// PRELIMINARY!! For now the Arrival Time is not the one calculated with
106// the splines, but it's the Max Slice Idx
107//
108// TEST!! This method is used only for test. Do not use it until
109// it becomes stable
110//
111
112void MArrivalTime::EvalClusters(const MRawEvtData &evt, const MGeomCam &geom)
113{
114 const Int_t n = geom.GetNumPixels();
115
116 fData2.Set(n);
117 fData2.Reset(-1.0);
118 fData3.Set(n);
119 fData3.Reset(-1.0);
120 fData4.Set(n);
121 fData4.Reset(-1.0);
122 fData5.Set(n);
123 fData5.Reset(-1.0);
124
125 MRawEvtPixelIter pixel((MRawEvtData*)&evt);
126
127// Array that says if a pixel has been already checked or not
128
129 for (Int_t i = 0; i < n; i++)
130 fPixelChecked[i] = kFALSE;
131
132// This fakeData array will be subsituted with the fData Array.
133 fakeData.Set(n);
134 fakeData.Reset();
135
136 while ( pixel.Next() )
137 {
138 fakeData[pixel.GetPixelId()]=pixel.GetIdxMaxHiLoGainSample();
139 }
140// End of fakeData preparation
141 *fLog << warn << "fin qui bene" << endl;
142// Max dimension of cluster
143 Short_t dimCluster;
144
145 while ( pixel.Next() )
146 {
147 if (!fPixelChecked[pixel.GetPixelId()])
148 {
149 dimCluster = 0;
150 fCluster.Set(n);
151 fCluster.Reset(-1);
152 fCluster[dimCluster]=pixel.GetPixelId();
153 dimCluster++;
154
155 CheckNeighbours(evt,geom,
156 pixel.GetPixelId(), &dimCluster);
157
158 if (dimCluster > 4)
159 {
160 for (Int_t i = 0; i < dimCluster; i++)
161 fData5[fCluster[i]]=fakeData[fCluster[i]];
162 }
163 if (dimCluster > 3)
164 {
165 for (Int_t i = 0; i < dimCluster; i++)
166 fData4[fCluster[i]]=fakeData[fCluster[i]];
167 }
168 if (dimCluster > 2)
169 {
170 for (Int_t i = 0; i < dimCluster; i++)
171 fData3[fCluster[i]]=fakeData[fCluster[i]];
172 }
173 if (dimCluster > 1)
174 {
175 for (Int_t i = 0; i < dimCluster; i++)
176 fData2[fCluster[i]]=fakeData[fCluster[i]];
177 }
178 }
179 }
180
181}
182
183// --------------------------------------------------------------------------
184//
185// Function to check the nearest neighbour pixels arrivaltime
186//
187
188void MArrivalTime::CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
189 Short_t idx, Short_t *dimCluster)
190{
191 Byte_t numNeighbors=geom[idx].GetNumNeighbors();
192 fPixelChecked[idx] = kTRUE;
193
194 for (Byte_t i=0x00; i < numNeighbors; i++)
195 {
196
197 if (!fPixelChecked[geom[idx].GetNeighbor(i)] &&
198 fakeData[idx] == fakeData[geom[idx].GetNeighbor(i)])
199 {
200 fCluster[*dimCluster]=geom[idx].GetNeighbor(i);
201 *dimCluster++;
202 CheckNeighbours(evt, geom,
203 geom[idx].GetNeighbor(i), dimCluster);
204 }
205 }
206}
207// --------------------------------------------------------------------------
208//
209// Returns the arrival time value
210//
211
212Bool_t MArrivalTime::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
213{
214 if (idx<0 || idx>=fData.GetSize())
215 return kFALSE;
216
217 switch (type)
218 {
219 case 0:
220 case 1:
221 val = fData[idx];
222 break;
223 case 2:
224 val = fData2[idx];
225 break;
226 case 3:
227 val = fData3[idx];
228 break;
229 case 4:
230 val = fData4[idx];
231 break;
232 case 5:
233 val = fData5[idx];
234 break;
235 }
236
237 return kTRUE;
238}
239
240void MArrivalTime::DrawPixelContent(Int_t num) const
241{
242 *fLog << warn << "MArrivalTime::DrawPixelContent - not available." << endl;
243}
Note: See TracBrowser for help on using the repository browser.