source: trunk/MagicSoft/Mars/mtemp/mifae/library/MIslandCalc.cc@ 4218

Last change on this file since 4218 was 4218, checked in by aliu, 20 years ago
*** empty log message ***
File size: 6.8 KB
Line 
1/* ======================================================================== *\
2!
3!
4! Author(s): Ester Aliu, 2/2004 <aliu@ifae.es>
5!
6! Last Update: 5/2004
7!
8\* ======================================================================== */
9
10/////////////////////////////////////////////////////////////////////////////
11//
12// MIslandCalc
13//
14// The Island Calc task calculates the some islands parameters for each
15// of the events such as:
16//
17// - fIslNum // number of islands
18// - fIslId[577] // island Id
19// - fPixNum[20]; // number of pixels in the island
20// - fSigToNoise[20]; // signal to noise of the island
21// - fTime[20][577] // mean of the arrival time
22// - fTimeSpread[20]; // mean arrival time spread of the island
23//
24//
25// Input Containers:
26// MGeomCam
27// MCerPhotEvt
28// MPedestalCam
29// MArrivalTimeCam
30//
31// Output Containers:
32// MIslands
33//
34/////////////////////////////////////////////////////////////////////////////
35#include "MIslandCalc.h"
36
37#include <stdlib.h> // atof
38#include <fstream> // ofstream, SavePrimitive
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MIslands.h"
44
45#include "MParList.h"
46
47#include "MGeomPix.h"
48#include "MGeomCam.h"
49
50#include "MCerPhotPix.h"
51#include "MCerPhotEvt.h"
52
53#include "MPedestalCam.h"
54#include "MPedestalPix.h"
55
56#include "MArrivalTimeCam.h"
57#include "MArrivalTimePix.h"
58
59ClassImp(MIslandCalc);
60
61
62using namespace std;
63
64// --------------------------------------------------------------------------
65//
66// Default constructor.
67//
68MIslandCalc::MIslandCalc(const char* name, const char* title)
69 : fIsl(NULL)
70{
71 fName = name ? name : "MIslandCalc";
72 fTitle = title ? title : "Calculate island parameters";
73}
74
75
76// --------------------------------------------------------------------------
77Int_t MIslandCalc::PreProcess (MParList *pList)
78{
79 fCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
80 if (!fCam)
81 {
82 *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
83 return kFALSE;
84 }
85
86 fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
87 if (!fEvt)
88 {
89 *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
90 return kFALSE;
91 }
92
93 fPed = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
94 if (!fPed)
95 {
96 *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fTime = (MArrivalTimeCam*)pList->FindObject(AddSerialNumber("MArrivalTimeCam"));
101 if (!fTime)
102 {
103 *fLog << dbginf << "MArrivalTimeCam not found... aborting." << endl;
104 return kFALSE;
105 }
106
107 if (strlen(fIslName) > 0)
108 {
109 fIsl = (MIslands*)pList->FindCreateObj("MIslands", AddSerialNumber(fIslName));
110 //cout << "kk1" << endl;
111 }
112 else
113 {
114 fIsl = (MIslands*)pList->FindCreateObj(AddSerialNumber("MIslands"));
115 //cout << "kk2" << endl;
116 }
117 if (!fIsl)
118 return kFALSE;
119
120 return kTRUE;
121}
122
123
124Int_t MIslandCalc::Process()
125{
126
127 Float_t noise;
128 Float_t signal;
129
130 Int_t npix = 577;
131
132 Int_t sflag;
133 Int_t control;
134
135 Int_t nvect = 0;
136 Int_t fIslNum = 0;
137
138 Int_t vect[50][577];
139
140 Int_t zeros[50];
141
142 for(Int_t m = 0; m < 50 ; m++)
143 for(Int_t n = 0; n < npix ; n++)
144 vect[m][n] = 0;
145
146 for(Int_t n = 0; n < 50 ; n++)
147 zeros[n] = 0;
148
149
150 MCerPhotPix *pix;
151
152 //loop over all pixels
153 MCerPhotEvtIter Next(fEvt, kFALSE);
154
155 while ((pix=static_cast<MCerPhotPix*>(Next())))
156 {
157 const Int_t idx = pix->GetPixId();
158
159 const MGeomPix &gpix = (*fCam)[idx];
160 const Int_t nnmax = gpix.GetNumNeighbors();
161
162 if( fEvt->IsPixelUsed(idx))
163 {
164 sflag = 0;
165
166 for(Int_t j=0; j < nnmax ; j++)
167 {
168 const Int_t idx2 = gpix.GetNeighbor(j);
169
170 if (idx2 < idx)
171 {
172 for(Int_t k = 1; k <= nvect; k++)
173 {
174 if (vect[k][idx2] == 1)
175 {
176 sflag = 1;
177 vect[k][idx] = 1;
178 }
179 }
180 }
181 }
182
183 if (sflag == 0)
184 {
185 nvect++;
186 vect[nvect][idx] = 1;
187 }
188
189 }
190 }
191
192 fIslNum = nvect;
193
194
195 // Repeated Chain Corrections
196
197 for(Int_t i = 1; i <= nvect; i++)
198 {
199 for(Int_t j = i+1; j <= nvect; j++)
200 {
201 control = 0;
202 for(Int_t k = 0; k < npix; k++)
203 {
204
205 if (vect[i][k] == 1 && vect[j][k] == 1)
206 {
207 control = 1;
208 break;
209 }
210 }
211 if (control == 1)
212 {
213 for(Int_t k = 0; k < npix; k++)
214 {
215 if(vect[j][k] == 1)
216 vect[i][k] = 1;
217 vect[j][k] = 0;
218 zeros[j] = 1;
219 }
220 fIslNum = fIslNum-1;
221 }
222
223 }
224 }
225
226
227 Int_t l = 1;
228
229 for(Int_t i = 1; i<= nvect ; i++)
230 {
231 if (zeros[i] == 0)
232 {
233 for(Int_t k = 0; k<npix; k++)
234 {
235 vect[l][k] = vect[i][k];
236 }
237 l++;
238 }
239 }
240
241
242 //set the number of islands in one event
243 fIsl->SetIslNum(fIslNum);
244
245 //examine each island...
246 Int_t fPixNum[fIslNum];
247 Float_t fSigToNoise[fIslNum];
248 Float_t time[577];
249 Float_t timeVariance[fIslNum];
250
251 //reset the "sets" functions
252 if (fIslNum <1)
253 fIsl->SetIslNum(0);
254
255 for(Int_t i = 0; i<20 ;i++)
256 {
257 fIsl->SetPixNum(i,-1);
258 fIsl->SetSigToNoise(i,-1);
259 fIsl->SetTimeSpread(i,-1);
260
261 for(Int_t idx = 0; idx<npix; idx++)
262 {
263 fIsl->SetIslId(idx, -1);
264 fIsl->SetArrivalTime(i, idx, -1 );
265 }
266 }
267
268
269 for(Int_t i = 1; i<=fIslNum ; i++)
270 {
271 Int_t n = 0;
272 Int_t ncore = 0;
273
274 Float_t MIN = 10000;
275 Float_t MAX = 0;
276
277 signal = 0;
278 noise = 0;
279 fPixNum[i-1] = 0;
280 timeVariance[i-1] = 0;
281
282 for(Int_t idx=0 ; idx<npix ; idx++)
283 {
284
285 MCerPhotPix *pix = fEvt->GetPixById(idx);
286 const MPedestalPix &ped = (*fPed)[idx];
287 const MArrivalTimePix &timepix = (*fTime)[idx];
288
289 if (pix == NULL) break;
290
291 if (vect[i][idx]==1){
292
293 fPixNum[i-1]++;
294 signal += pix->GetNumPhotons() * (fCam->GetPixRatio(idx));
295 noise += pow(ped.GetPedestalRms(),2);
296
297 time[n] = timepix.IsLoGainUsed() ? timepix.GetArrivalTimeLoGain() : timepix.GetArrivalTimeHiGain();
298
299
300 if (fEvt->IsPixelCore(idx)){
301
302 if (time[n] > MAX)
303 MAX = time[n];
304 if (time[n] < MIN)
305 MIN = time[n];
306
307 ncore++;
308 }
309
310 fIsl->SetIslId(idx, i-1);
311 fIsl->SetArrivalTime(i-1, idx, time[n]);
312
313 n++;
314 }
315
316 }
317
318 // Float_t mean = timeVariance[i-1]/ncore;
319
320 timeVariance[i-1] = 0;
321
322 timeVariance[i-1] = (MAX - MIN)/ncore;
323 timeVariance[i-1] = (MAX - MIN)/ncore;
324
325 fSigToNoise[i-1]= (Float_t)signal/(Float_t)sqrt(noise);
326
327 fIsl->SetPixNum(i-1,fPixNum[i-1]);
328 fIsl->SetSigToNoise(i-1,fSigToNoise[i-1]);
329 fIsl->SetTimeSpread(i-1, timeVariance[i-1]);
330
331 }
332
333 fIsl->SetReadyToSave();
334
335 return 1;
336
337}
338
339
Note: See TracBrowser for help on using the repository browser.