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

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