]>
Commit | Line | Data |
---|---|---|
1 | /*************************************************************************** | |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | //-----------------------------------------------------// | |
19 | // // | |
20 | // Source File : PMDClusteringV1.cxx, Version 00 // | |
21 | // // | |
22 | // Date : September 26 2002 // | |
23 | // // | |
24 | // clustering code for alice pmd // | |
25 | // // | |
26 | //-----------------------------------------------------// | |
27 | ||
28 | /* -------------------------------------------------------------------- | |
29 | Code developed by S. C. Phatak, Institute of Physics, | |
30 | Bhubaneswar 751 005 ( phatak@iopb.res.in ) Given the energy deposited | |
31 | ( or ADC value ) in each cell of supermodule ( pmd or cpv ), the code | |
32 | builds up superclusters and breaks them into clusters. The input is | |
33 | in array fEdepCell[kNDIMX][kNDIMY] and cluster information is in array | |
34 | fClusters[5][5000]. integer fClno gives total number of clusters in the | |
35 | supermodule. | |
36 | ||
37 | fEdepCell, fClno and fClusters are the only global ( public ) variables. | |
38 | Others are local ( private ) to the code. | |
39 | At the moment, the data is read for whole detector ( all supermodules | |
40 | and pmd as well as cpv. This will have to be modify later ) | |
41 | LAST UPDATE : October 23, 2002 | |
42 | -----------------------------------------------------------------------*/ | |
43 | ||
44 | #include <Riostream.h> | |
45 | #include <TMath.h> | |
46 | #include <TNtuple.h> | |
47 | #include <TObjArray.h> | |
48 | #include <stdio.h> | |
49 | ||
50 | #include "AliPMDcluster.h" | |
51 | #include "AliPMDClustering.h" | |
52 | #include "AliPMDClusteringV1.h" | |
53 | #include "AliLog.h" | |
54 | ||
55 | ClassImp(AliPMDClusteringV1) | |
56 | ||
57 | const Double_t AliPMDClusteringV1::fgkSqroot3by2=0.8660254; // sqrt(3.)/2. | |
58 | ||
59 | AliPMDClusteringV1::AliPMDClusteringV1(): | |
60 | fClno(0), | |
61 | fCutoff(0.0) | |
62 | { | |
63 | for(int i = 0; i < kNDIMX; i++) | |
64 | { | |
65 | for(int j = 0; j < kNDIMY; j++) | |
66 | { | |
67 | fCoord[0][i][j] = i+j/2.; | |
68 | fCoord[1][i][j] = fgkSqroot3by2*j; | |
69 | fEdepCell[i][j] = 0; | |
70 | } | |
71 | } | |
72 | } | |
73 | // ------------------------------------------------------------------------ // | |
74 | AliPMDClusteringV1::~AliPMDClusteringV1() | |
75 | { | |
76 | ||
77 | } | |
78 | // ------------------------------------------------------------------------ // | |
79 | void AliPMDClusteringV1::DoClust(Int_t idet, Int_t ismn, Double_t celladc[48][96], TObjArray *pmdcont) | |
80 | { | |
81 | // main function to call other necessary functions to do clustering | |
82 | // | |
83 | AliPMDcluster *pmdcl = 0; | |
84 | /* | |
85 | int id and jd defined to read the input data. | |
86 | It is assumed that for data we have 0 <= id <= 48 | |
87 | and 0 <= jd <=96 | |
88 | */ | |
89 | ||
90 | int i, i1, i2, j, nmx1, incr, id, jd; | |
91 | Int_t celldataX[15], celldataY[15]; | |
92 | Float_t clusdata[6]; | |
93 | ||
94 | Double_t cutoff, ave; | |
95 | ||
96 | const float ktwobysqrt3 = 1.1547; // 2./sqrt(3.) | |
97 | ||
98 | // ndimXr and ndimYr are different because of different module size | |
99 | ||
100 | Int_t ndimXr =0; | |
101 | Int_t ndimYr =0; | |
102 | ||
103 | if (ismn < 12) | |
104 | { | |
105 | ndimXr = 96; | |
106 | ndimYr = 48; | |
107 | } | |
108 | else if (ismn >= 12 && ismn <= 23) | |
109 | { | |
110 | ndimXr = 48; | |
111 | ndimYr = 96; | |
112 | } | |
113 | ||
114 | for (Int_t i =0; i < kNDIMX; i++) | |
115 | { | |
116 | for (Int_t j =0; j < kNDIMY; j++) | |
117 | { | |
118 | fEdepCell[i][j] = 0; | |
119 | fCellTrNo[i][j] = -1; | |
120 | } | |
121 | } | |
122 | ||
123 | for (id = 0; id < ndimXr; id++) | |
124 | { | |
125 | for (jd = 0; jd < ndimYr; jd++) | |
126 | { | |
127 | j=jd; | |
128 | i=id+(ndimYr/2-1)-(jd/2); | |
129 | ||
130 | if (ismn < 12) | |
131 | { | |
132 | fEdepCell[i][j] = celladc[jd][id]; | |
133 | fCellTrNo[i][j] = jd*10000+id; /* for association */ | |
134 | } | |
135 | else if (ismn >= 12 && ismn <= 23) | |
136 | { | |
137 | fEdepCell[i][j] = celladc[id][jd]; | |
138 | fCellTrNo[i][j] = id*10000+jd; /* for association */ | |
139 | } | |
140 | ||
141 | } | |
142 | } | |
143 | Order(); // order the data | |
144 | cutoff = fCutoff; // cutoff used to discard cells having ener. dep. | |
145 | ave=0.; | |
146 | nmx1=-1; | |
147 | ||
148 | for(j=0;j<kNMX; j++) | |
149 | { | |
150 | i1 = fIord[0][j]; | |
151 | i2 = fIord[1][j]; | |
152 | if (fEdepCell[i1][i2] > 0.) {ave = ave + fEdepCell[i1][i2];} | |
153 | if (fEdepCell[i1][i2] > cutoff ) nmx1 = nmx1 + 1; | |
154 | } | |
155 | ||
156 | AliDebug(1,Form("Number of cells having energy >= %f are %d",cutoff,nmx1)); | |
157 | ||
158 | if (nmx1 == 0) nmx1 = 1; | |
159 | ave=ave/nmx1; | |
160 | ||
161 | AliDebug(1,Form("Number of cells in a SuperM = %d and Average = %f", | |
162 | kNMX,ave)); | |
163 | ||
164 | incr = CrClust(ave, cutoff, nmx1); | |
165 | RefClust(incr); | |
166 | ||
167 | AliDebug(1,Form("Detector Plane = %d Serial Module No = %d Number of clusters = %d",idet, ismn, fClno)); | |
168 | ||
169 | ||
170 | for(i1=0; i1<=fClno; i1++) | |
171 | { | |
172 | Float_t cluXC = (Float_t) fClusters[0][i1]; | |
173 | Float_t cluYC = (Float_t) fClusters[1][i1]; | |
174 | Float_t cluADC = (Float_t) fClusters[2][i1]; | |
175 | Float_t cluCELLS = (Float_t) fClusters[3][i1]; | |
176 | Float_t cluRAD = (Float_t) fClusters[4][i1]; | |
177 | Float_t cluY0 = ktwobysqrt3*cluYC; | |
178 | Float_t cluX0 = cluXC - cluY0/2.; | |
179 | ||
180 | ||
181 | // | |
182 | // Cluster X centroid is back transformed | |
183 | // | |
184 | if (ismn < 12) | |
185 | { | |
186 | clusdata[0] = cluX0 - (24-1) + cluY0/2.; | |
187 | } | |
188 | else if (ismn >= 12 && ismn <= 23) | |
189 | { | |
190 | clusdata[0] = cluX0 - (48-1) + cluY0/2.; | |
191 | } | |
192 | ||
193 | clusdata[1] = cluY0; | |
194 | clusdata[2] = cluADC; | |
195 | clusdata[3] = cluCELLS; | |
196 | clusdata[4] = cluRAD; | |
197 | clusdata[5] = 0.; | |
198 | ||
199 | // | |
200 | // Cells associated with a cluster | |
201 | // | |
202 | for (Int_t ihit = 0; ihit < 15; ihit++) | |
203 | { | |
204 | ||
205 | if (ismn < 12) | |
206 | { | |
207 | celldataX[ihit] = fClTr[ihit][i1]%10000; | |
208 | celldataY[ihit] = fClTr[ihit][i1]/10000; | |
209 | } | |
210 | else if (ismn >= 12 && ismn <= 23) | |
211 | { | |
212 | celldataX[ihit] = fClTr[ihit][i1]/10000; | |
213 | celldataY[ihit] = fClTr[ihit][i1]%10000; | |
214 | } | |
215 | } | |
216 | //printf("%d %f %f\n",idet,cluXC,cluYC ); | |
217 | pmdcl = new AliPMDcluster(idet, ismn, clusdata, celldataX, celldataY); | |
218 | pmdcont->Add(pmdcl); | |
219 | } | |
220 | } | |
221 | // ------------------------------------------------------------------------ // | |
222 | void AliPMDClusteringV1::Order() | |
223 | { | |
224 | // Sorting algorithm | |
225 | // sorts the ADC values from higher to lower | |
226 | // | |
227 | double dd[kNMX]; | |
228 | // matrix fEdepCell converted into | |
229 | // one dimensional array dd. adum a place holder for double | |
230 | int i, j, i1, i2, iord1[kNMX]; | |
231 | // information of | |
232 | // ordering is stored in iord1, original array not ordered | |
233 | // | |
234 | // define arrays dd and iord1 | |
235 | for(i1=0; i1 < kNDIMX; i1++) | |
236 | { | |
237 | for(i2=0; i2 < kNDIMY; i2++) | |
238 | { | |
239 | i = i1 + i2*kNDIMX; | |
240 | iord1[i] = i; | |
241 | dd[i] = fEdepCell[i1][i2]; | |
242 | } | |
243 | } | |
244 | ||
245 | TMath::Sort(kNMX,dd,iord1); //PH Using much better algorithm... | |
246 | // store the sorted information in fIord for later use | |
247 | for(i=0; i<kNMX; i++) | |
248 | { | |
249 | j = iord1[i]; | |
250 | i2 = j/kNDIMX; | |
251 | i1 = j-i2*kNDIMX; | |
252 | fIord[0][i]=i1; | |
253 | fIord[1][i]=i2; | |
254 | } | |
255 | } | |
256 | // ------------------------------------------------------------------------ // | |
257 | int AliPMDClusteringV1::CrClust(double ave, double cutoff, int nmx1) | |
258 | { | |
259 | // Does crude clustering | |
260 | // Finds out only the big patch by just searching the | |
261 | // connected cells | |
262 | // | |
263 | int i,j,k,id1,id2,icl, numcell, clust[2][5000]; | |
264 | int jd1,jd2, icell, cellcount; | |
265 | static int neibx[6]={1,0,-1,-1,0,1}, neiby[6]={0,1,1,0,-1,-1}; | |
266 | // neibx and neiby define ( incremental ) (i,j) for the neighbours of a | |
267 | // cell. There are six neighbours. | |
268 | // cellcount --- total number of cells having nonzero ener dep | |
269 | // numcell --- number of cells in a given supercluster | |
270 | // ofstream ofl0("cells_loc",ios::out); | |
271 | // initialize fInfocl[2][kNDIMX][kNDIMY] | |
272 | ||
273 | AliDebug(1,Form("kNMX = %d nmx1 = %d kNDIMX = %d kNDIMY = %d ave = %f cutoff = %f",kNMX,nmx1,kNDIMX,kNDIMY,ave,cutoff)); | |
274 | ||
275 | for (j=0; j < kNDIMX; j++){ | |
276 | for(k=0; k < kNDIMY; k++){ | |
277 | fInfocl[0][j][k] = 0; | |
278 | fInfocl[1][j][k] = 0; | |
279 | } | |
280 | } | |
281 | for(i=0; i < kNMX; i++){ | |
282 | fInfcl[0][i] = -1; | |
283 | id1=fIord[0][i]; | |
284 | id2=fIord[1][i]; | |
285 | if(fEdepCell[id1][id2] <= cutoff){fInfocl[0][id1][id2]=-1;} | |
286 | } | |
287 | // --------------------------------------------------------------- | |
288 | // crude clustering begins. Start with cell having largest adc | |
289 | // count and loop over the cells in descending order of adc count | |
290 | // --------------------------------------------------------------- | |
291 | icl=-1; | |
292 | cellcount=-1; | |
293 | for(icell=0; icell <= nmx1; icell++){ | |
294 | id1=fIord[0][icell]; | |
295 | id2=fIord[1][icell]; | |
296 | if(fInfocl[0][id1][id2] == 0 ){ | |
297 | // --------------------------------------------------------------- | |
298 | // icl -- cluster #, numcell -- # of cells in it, clust -- stores | |
299 | // coordinates of the cells in a cluster, fInfocl[0][i1][i2] is 1 for | |
300 | // primary and 2 for secondary cells, | |
301 | // fInfocl[1][i1][i2] stores cluster # | |
302 | // --------------------------------------------------------------- | |
303 | icl=icl+1; | |
304 | numcell=0; | |
305 | cellcount = cellcount + 1; | |
306 | fInfocl[0][id1][id2]=1; | |
307 | fInfocl[1][id1][id2]=icl; | |
308 | fInfcl[0][cellcount]=icl; | |
309 | fInfcl[1][cellcount]=id1; | |
310 | fInfcl[2][cellcount]=id2; | |
311 | ||
312 | clust[0][numcell]=id1; | |
313 | clust[1][numcell]=id2; | |
314 | for(i=1; i<5000; i++)clust[0][i]=0; | |
315 | // --------------------------------------------------------------- | |
316 | // check for adc count in neib. cells. If ne 0 put it in this clust | |
317 | // --------------------------------------------------------------- | |
318 | for(i=0; i<6; i++){ | |
319 | jd1=id1+neibx[i]; | |
320 | jd2=id2+neiby[i]; | |
321 | if( (jd1 >= 0 && jd1 < kNDIMX) && (jd2 >= 0 && jd2 < kNDIMY) && | |
322 | fInfocl[0][jd1][jd2] == 0){ | |
323 | numcell=numcell+1; | |
324 | fInfocl[0][jd1][jd2]=2; | |
325 | fInfocl[1][jd1][jd2]=icl; | |
326 | clust[0][numcell]=jd1; | |
327 | clust[1][numcell]=jd2; | |
328 | cellcount=cellcount+1; | |
329 | fInfcl[0][cellcount]=icl; | |
330 | fInfcl[1][cellcount]=jd1; | |
331 | fInfcl[2][cellcount]=jd2; | |
332 | } | |
333 | } | |
334 | // --------------------------------------------------------------- | |
335 | // check adc count for neighbour's neighbours recursively and | |
336 | // if nonzero, add these to the cluster. | |
337 | // --------------------------------------------------------------- | |
338 | for(i=1;i < 5000;i++){ | |
339 | if(clust[0][i] != 0){ | |
340 | id1=clust[0][i]; | |
341 | id2=clust[1][i]; | |
342 | for(j=0; j<6 ; j++){ | |
343 | jd1=id1+neibx[j]; | |
344 | jd2=id2+neiby[j]; | |
345 | if( (jd1 >= 0 && jd1 < kNDIMX) && (jd2 >= 0 && jd2 < kNDIMY) && | |
346 | fInfocl[0][jd1][jd2] == 0 ){ | |
347 | fInfocl[0][jd1][jd2] = 2; | |
348 | fInfocl[1][jd1][jd2] = icl; | |
349 | numcell = numcell + 1; | |
350 | clust[0][numcell] = jd1; | |
351 | clust[1][numcell] = jd2; | |
352 | cellcount = cellcount+1; | |
353 | fInfcl[0][cellcount] = icl; | |
354 | fInfcl[1][cellcount] = jd1; | |
355 | fInfcl[2][cellcount] = jd2; | |
356 | } | |
357 | } | |
358 | } | |
359 | } | |
360 | } | |
361 | } | |
362 | ||
363 | // for(icell=0; icell<=cellcount; icell++){ | |
364 | // ofl0 << fInfcl[0][icell] << " " << fInfcl[1][icell] << " " << | |
365 | // fInfcl[2][icell] << endl; | |
366 | //} | |
367 | ||
368 | return cellcount; | |
369 | } | |
370 | // ------------------------------------------------------------------------ // | |
371 | void AliPMDClusteringV1::RefClust(int incr) | |
372 | { | |
373 | // Does the refining of clusters | |
374 | // Takes the big patch and does gaussian fitting and | |
375 | // finds out the more refined clusters | |
376 | // | |
377 | int i, j, k, i1, i2, id, icl, ncl[4500], iord[4500], itest; | |
378 | int ihld; | |
379 | int ig, nsupcl, lev1[20], lev2[20]; | |
380 | double x[4500], y[4500], z[4500], x1, y1, z1, x2, y2, z2, dist; | |
381 | double xc[4500], yc[4500], zc[4500], cells[4500], sum, rc[4500], rr; | |
382 | ||
383 | ||
384 | //asso | |
385 | Int_t t[4500],cellCount[4500]; | |
386 | for(i=0; i<4500; i++) | |
387 | { | |
388 | t[i]=-1; | |
389 | cellCount[i]=0; | |
390 | } | |
391 | ||
392 | ||
393 | // fClno counts the final clusters | |
394 | // nsupcl = # of superclusters; ncl[i]= # of cells in supercluster i | |
395 | // x, y and z store (x,y) coordinates of and energy deposited in a cell | |
396 | // xc, yc store (x,y) coordinates of the cluster center | |
397 | // zc stores the energy deposited in a cluster | |
398 | // rc is cluster radius | |
399 | // finally the cluster information is put in 2-dimensional array clusters | |
400 | //ofstream ofl1("checking.5",ios::app); | |
401 | fClno = -1; | |
402 | nsupcl = -1; | |
403 | for(i=0; i<4500; i++){ncl[i]=-1;} | |
404 | for(i=0; i<= incr; i++){ | |
405 | if(fInfcl[0][i] != nsupcl){ nsupcl=nsupcl+1; } | |
406 | if (nsupcl > 4500) { | |
407 | AliWarning("RefClust: Too many superclusters!"); | |
408 | nsupcl = 4500; | |
409 | break; | |
410 | } | |
411 | ||
412 | ncl[nsupcl]=ncl[nsupcl]+1; | |
413 | } | |
414 | ||
415 | AliDebug(1,Form("Number of cells = %d Number of Superclusters = %d", | |
416 | incr+1,nsupcl+1)); | |
417 | id=-1; | |
418 | icl=-1; | |
419 | for(i=0; i<=nsupcl; i++) { | |
420 | if(ncl[i] == 0){ | |
421 | id=id+1; | |
422 | icl=icl+1; | |
423 | // one cell super-clusters --> single cluster | |
424 | // cluster center at the centyer of the cell | |
425 | // cluster radius = half cell dimension | |
426 | if (fClno >= 5000) { | |
427 | AliWarning("RefClust: Too many clusters! more than 5000"); | |
428 | return; | |
429 | } | |
430 | fClno = fClno + 1; | |
431 | i1 = fInfcl[1][id]; | |
432 | i2 = fInfcl[2][id]; | |
433 | fClusters[0][fClno] = fCoord[0][i1][i2]; | |
434 | fClusters[1][fClno] = fCoord[1][i1][i2]; | |
435 | fClusters[2][fClno] = fEdepCell[i1][i2]; | |
436 | fClusters[3][fClno] = 1.; | |
437 | fClusters[4][fClno] = 0.5; | |
438 | ||
439 | //association | |
440 | ||
441 | fClTr[0][fClno]=fCellTrNo[i1][i2]; | |
442 | for(Int_t icltr=1;icltr<14;icltr++) | |
443 | { | |
444 | fClTr[icltr][fClno]=-1; | |
445 | } | |
446 | ||
447 | //ofl1 << icl << " " << fCoord[0][i1][i2] << " " << fCoord[1][i1][i2] << | |
448 | //" " << fEdepCell[i1][i2] << " " << fClusters[3][fClno] <<endl; | |
449 | ||
450 | }else if(ncl[i] == 1){ | |
451 | // two cell super-cluster --> single cluster | |
452 | // cluster center is at ener. dep.-weighted mean of two cells | |
453 | // cluster radius == half cell dimension | |
454 | id = id + 1; | |
455 | icl = icl+1; | |
456 | if (fClno >= 5000) { | |
457 | AliWarning("RefClust: Too many clusters! more than 5000"); | |
458 | return; | |
459 | } | |
460 | fClno = fClno+1; | |
461 | i1 = fInfcl[1][id]; | |
462 | i2 = fInfcl[2][id]; | |
463 | x1 = fCoord[0][i1][i2]; | |
464 | y1 = fCoord[1][i1][i2]; | |
465 | z1 = fEdepCell[i1][i2]; | |
466 | ||
467 | //asso | |
468 | fClTr[0][fClno]=fCellTrNo[i1][i2]; | |
469 | // | |
470 | ||
471 | id = id+1; | |
472 | i1 = fInfcl[1][id]; | |
473 | i2 = fInfcl[2][id]; | |
474 | x2 = fCoord[0][i1][i2]; | |
475 | y2 = fCoord[1][i1][i2]; | |
476 | z2 = fEdepCell[i1][i2]; | |
477 | ||
478 | //asso | |
479 | ||
480 | fClTr[1][fClno]=fCellTrNo[i1][i2]; | |
481 | for(Int_t icltr=2;icltr<14;icltr++) | |
482 | { | |
483 | fClTr[icltr][fClno] = -1; | |
484 | } | |
485 | // | |
486 | ||
487 | fClusters[0][fClno] = (x1*z1+x2*z2)/(z1+z2); | |
488 | fClusters[1][fClno] = (y1*z1+y2*z2)/(z1+z2); | |
489 | fClusters[2][fClno] = z1+z2; | |
490 | fClusters[3][fClno] = 2.; | |
491 | fClusters[4][fClno] = 0.5; | |
492 | ||
493 | ||
494 | //ofl1 << icl << " " << fClusters[0][fClno] << " " << fClusters[1][fClno] | |
495 | // << " " << fClusters[2][fClno] << " " <<fClusters[3][fClno] <<endl; | |
496 | } | |
497 | else{ | |
498 | ||
499 | //asso | |
500 | for(Int_t icg=0;icg<4500;icg++) | |
501 | { | |
502 | cellCount[icg]=0; | |
503 | } | |
504 | // | |
505 | ||
506 | id = id + 1; | |
507 | iord[0] = 0; | |
508 | // super-cluster of more than two cells - broken up into smaller | |
509 | // clusters gaussian centers computed. (peaks separated by > 1 cell) | |
510 | // Begin from cell having largest energy deposited This is first | |
511 | // cluster center | |
512 | i1 = fInfcl[1][id]; | |
513 | i2 = fInfcl[2][id]; | |
514 | x[0] = fCoord[0][i1][i2]; | |
515 | y[0] = fCoord[1][i1][i2]; | |
516 | z[0] = fEdepCell[i1][i2]; | |
517 | ||
518 | //asso | |
519 | t[0]=fCellTrNo[i1][i2]; | |
520 | // | |
521 | ||
522 | iord[0] = 0; | |
523 | for(j=1;j<=ncl[i];j++){ | |
524 | ||
525 | id = id + 1; | |
526 | i1 = fInfcl[1][id]; | |
527 | i2 = fInfcl[2][id]; | |
528 | iord[j] = j; | |
529 | x[j] = fCoord[0][i1][i2]; | |
530 | y[j] = fCoord[1][i1][i2]; | |
531 | z[j] = fEdepCell[i1][i2]; | |
532 | ||
533 | //asso | |
534 | t[j]=fCellTrNo[i1][i2]; | |
535 | // | |
536 | ||
537 | ||
538 | } | |
539 | // arranging cells within supercluster in decreasing order | |
540 | for(j=1;j<=ncl[i];j++){ | |
541 | itest=0; | |
542 | ihld=iord[j]; | |
543 | for(i1=0;i1<j;i1++){ | |
544 | if(itest == 0 && z[iord[i1]] < z[ihld]){ | |
545 | itest=1; | |
546 | for(i2=j-1;i2>=i1;i2--){ | |
547 | iord[i2+1]=iord[i2]; | |
548 | } | |
549 | iord[i1]=ihld; | |
550 | } | |
551 | } | |
552 | } | |
553 | ||
554 | // compute the number of Gaussians and their centers ( first | |
555 | // guess ) | |
556 | // centers must be separated by cells having smaller ener. dep. | |
557 | // neighbouring centers should be either strong or well-separated | |
558 | ig=0; | |
559 | xc[ig]=x[iord[0]]; | |
560 | yc[ig]=y[iord[0]]; | |
561 | zc[ig]=z[iord[0]]; | |
562 | for(j=1;j<=ncl[i];j++){ | |
563 | itest=-1; | |
564 | x1=x[iord[j]]; | |
565 | y1=y[iord[j]]; | |
566 | for(k=0;k<=ig;k++){ | |
567 | x2=xc[k]; y2=yc[k]; | |
568 | rr=Distance(x1,y1,x2,y2); | |
569 | if( rr >= 1.1 && rr < 1.8 && z[iord[j]] > zc[k]/4.) | |
570 | itest=itest+1; | |
571 | if( rr >= 1.8 && rr < 2.1 && z[iord[j]] > zc[k]/10.) | |
572 | itest=itest+1; | |
573 | if( rr >= 2.1)itest=itest+1; | |
574 | } | |
575 | if(itest == ig){ | |
576 | ig=ig+1; | |
577 | xc[ig]=x1; | |
578 | yc[ig]=y1; | |
579 | zc[ig]=z[iord[j]]; | |
580 | } | |
581 | } | |
582 | // for(j=0; j<=ig; j++){ | |
583 | //ofl1 << icl+j+1 << " " << xc[j] << " " <<yc[j] <<" "<<zc[j]<<endl; | |
584 | //} | |
585 | // GaussFit to adjust cluster parameters to minimize | |
586 | GaussFit(ncl[i], ig, x[0], y[0] ,z[0], xc[0], yc[0], zc[0], rc[0]); | |
587 | icl=icl+ig+1; | |
588 | // compute the number of cells belonging to each cluster. | |
589 | // cell is shared between several clusters ( if they are equidistant | |
590 | // from it ) in the ratio of cluster energy deposition | |
591 | for(j=0; j<=ig; j++){ | |
592 | cells[j]=0.; | |
593 | } | |
594 | if(ig > 0){ | |
595 | for(j=0; j<=ncl[i]; j++){ | |
596 | lev1[j]=0; | |
597 | lev2[j]=0; | |
598 | for(k=0; k<=ig; k++){ | |
599 | dist=Distance(x[j], y[j], xc[k], yc[k]); | |
600 | if(dist < sqrt(3.) ){ | |
601 | ||
602 | //asso | |
603 | fClTr[cellCount[k]][fClno+k+1]=t[j]; | |
604 | cellCount[k]++; | |
605 | // | |
606 | ||
607 | lev1[0]++; | |
608 | i1=lev1[0]; | |
609 | lev1[i1]=k; | |
610 | }else{ | |
611 | if(dist < 2.1){ | |
612 | lev2[0]++; | |
613 | i1=lev2[0]; | |
614 | lev2[i1]=k; | |
615 | } | |
616 | } | |
617 | } | |
618 | if(lev1[0] != 0){ | |
619 | if(lev1[0] == 1){cells[lev1[1]]=cells[lev1[1]]+1.;} | |
620 | else{ | |
621 | sum=0.; | |
622 | for(k=1; k<=lev1[0]; k++){ | |
623 | sum=sum+zc[lev1[k]]; | |
624 | } | |
625 | for(k=1; k<=lev1[0]; k++){ | |
626 | cells[lev1[k]]=cells[lev1[k]]+zc[lev1[k]]/sum; | |
627 | } | |
628 | } | |
629 | }else{ | |
630 | if(lev2[0] == 0){cells[lev2[1]]=cells[lev2[1]]+1.;} | |
631 | else{ | |
632 | sum=0.; | |
633 | for(k=1; k<=lev2[0]; k++){ | |
634 | sum=sum+zc[lev2[k]]; | |
635 | } | |
636 | for(k=1; k<=lev2[0]; k++){ | |
637 | cells[lev2[k]]=cells[lev2[k]]+zc[lev2[k]]/sum; | |
638 | } | |
639 | } | |
640 | } | |
641 | } | |
642 | } | |
643 | ||
644 | // zero rest of the cell array | |
645 | //asso | |
646 | for(k=0; k<=ig; k++) | |
647 | { | |
648 | for(Int_t icltr=cellCount[k];icltr<14;icltr++) | |
649 | { | |
650 | fClTr[icltr][fClno]=-1; | |
651 | } | |
652 | } | |
653 | // | |
654 | ||
655 | ||
656 | ||
657 | for(j=0; j<=ig; j++){ | |
658 | if (fClno >= 5000) { | |
659 | AliWarning("RefClust: Too many clusters! more than 5000"); | |
660 | return; | |
661 | } | |
662 | fClno = fClno + 1; | |
663 | fClusters[0][fClno] = xc[j]; | |
664 | fClusters[1][fClno] = yc[j]; | |
665 | fClusters[2][fClno] = zc[j]; | |
666 | fClusters[4][fClno] = rc[j]; | |
667 | if(ig == 0){ | |
668 | fClusters[3][fClno] = ncl[i]; | |
669 | }else{ | |
670 | fClusters[3][fClno] = cells[j]; | |
671 | } | |
672 | } | |
673 | } | |
674 | } | |
675 | } | |
676 | // ------------------------------------------------------------------------ // | |
677 | void AliPMDClusteringV1::GaussFit(Int_t ncell, Int_t nclust, Double_t &x, Double_t &y ,Double_t &z, Double_t &xc, Double_t &yc, Double_t &zc, Double_t &rc) | |
678 | { | |
679 | // Does gaussian fitting | |
680 | // | |
681 | int i, j, i1, i2, novar, idd, jj; | |
682 | double xx[4500], yy[4500], zz[4500], xxc[4500], yyc[4500]; | |
683 | double a[4500], b[4500], c[4500], d[4500], ha[4500], hb[4500]; | |
684 | double hc[4500], hd[4500], zzc[4500], rrc[4500]; | |
685 | int neib[4500][50]; | |
686 | double sum, dx, dy, str, str1, aint, sum1, rr, dum; | |
687 | double x1, x2, y1, y2; | |
688 | str = 0.; | |
689 | str1 = 0.; | |
690 | rr = 0.3; | |
691 | novar = 0; | |
692 | j = 0; // Just put not to see the compiler warning, BKN | |
693 | ||
694 | for(i=0; i<=ncell; i++) | |
695 | { | |
696 | xx[i] = *(&x+i); | |
697 | yy[i] = *(&y+i); | |
698 | zz[i] = *(&z+i); | |
699 | str = str + zz[i]; | |
700 | } | |
701 | for(i=0; i<=nclust; i++) | |
702 | { | |
703 | xxc[i] = *(&xc+i); | |
704 | yyc[i] = *(&yc+i); | |
705 | zzc[i] = *(&zc+i); | |
706 | str1 = str1 + zzc[i]; | |
707 | rrc[i] = 0.5; | |
708 | } | |
709 | for(i=0; i<=nclust; i++) | |
710 | { | |
711 | zzc[i] = str/str1*zzc[i]; | |
712 | ha[i] = xxc[i]; | |
713 | hb[i] = yyc[i]; | |
714 | hc[i] = zzc[i]; | |
715 | hd[i] = rrc[i]; | |
716 | x1 = xxc[i]; | |
717 | y1 = yyc[i]; | |
718 | } | |
719 | for(i=0; i<=ncell; i++){ | |
720 | idd=0; | |
721 | x1=xx[i]; | |
722 | y1=yy[i]; | |
723 | for(j=0; j<=nclust; j++){ | |
724 | x2=xxc[j]; | |
725 | y2=yyc[j]; | |
726 | if(Distance(x1,y1,x2,y2) <= 3.){ idd=idd+1; neib[i][idd]=j; } | |
727 | } | |
728 | neib[i][0]=idd; | |
729 | } | |
730 | sum=0.; | |
731 | for(i1=0; i1<=ncell; i1++){ | |
732 | aint=0.; | |
733 | idd=neib[i1][0]; | |
734 | for(i2=1; i2<=idd; i2++){ | |
735 | jj=neib[i1][i2]; | |
736 | dx=xx[i1]-xxc[jj]; | |
737 | dy=yy[i1]-yyc[jj]; | |
738 | dum=rrc[j]*rrc[jj]+rr*rr; | |
739 | aint=aint+exp(-(dx*dx+dy*dy)/dum)*zzc[idd]*rr*rr/dum; | |
740 | } | |
741 | sum=sum+(aint-zz[i1])*(aint-zz[i1])/str; | |
742 | } | |
743 | // jmax=nclust*1000; | |
744 | // if(nclust > 20)jmax=20000; | |
745 | // for(j=0; j<jmax; j++){ | |
746 | str1=0.; | |
747 | for(i=0; i<=nclust; i++){ | |
748 | a[i]=xxc[i]+0.6*(Ranmar()-0.5); | |
749 | b[i]=yyc[i]+0.6*(Ranmar()-0.5); | |
750 | c[i]=zzc[i]*(1.+(Ranmar()-0.5)*0.2); | |
751 | str1=str1+zzc[i]; | |
752 | d[i]=rrc[i]*(1.+(Ranmar()-0.5)*0.1); | |
753 | if(d[i] < 0.25)d[i]=0.25; | |
754 | } | |
755 | for(i=0; i<=nclust; i++){ c[i]=c[i]*str/str1; } | |
756 | sum1=0.; | |
757 | for(i1=0; i1<=ncell; i1++){ | |
758 | aint=0.; | |
759 | idd=neib[i1][0]; | |
760 | for(i2=1; i2<=idd; i2++){ | |
761 | jj=neib[i1][i2]; | |
762 | dx=xx[i1]-a[jj]; | |
763 | dy=yy[i1]-b[jj]; | |
764 | dum=d[jj]*d[jj]+rr*rr; | |
765 | aint=aint+exp(-(dx*dx+dy*dy)/dum)*c[i2]*rr*rr/dum; | |
766 | } | |
767 | sum1=sum1+(aint-zz[i1])*(aint-zz[i1])/str; | |
768 | } | |
769 | ||
770 | if(sum1 < sum){ | |
771 | for(i2=0; i2<=nclust; i2++){ | |
772 | xxc[i2]=a[i2]; | |
773 | yyc[i2]=b[i2]; | |
774 | zzc[i2]=c[i2]; | |
775 | rrc[i2]=d[i2]; | |
776 | sum=sum1; | |
777 | } | |
778 | } | |
779 | // } | |
780 | for(j=0; j<=nclust; j++){ | |
781 | *(&xc+j)=xxc[j]; | |
782 | *(&yc+j)=yyc[j]; | |
783 | *(&zc+j)=zzc[j]; | |
784 | *(&rc+j)=rrc[j]; | |
785 | } | |
786 | } | |
787 | // ------------------------------------------------------------------------ // | |
788 | double AliPMDClusteringV1::Distance(double x1, double y1, double x2, double y2) | |
789 | { | |
790 | return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); | |
791 | } | |
792 | // ------------------------------------------------------------------------ // | |
793 | double AliPMDClusteringV1::Ranmar() const | |
794 | { | |
795 | // Universal random number generator proposed by Marsaglia and Zaman | |
796 | // in report FSU-SCRI-87-50 | |
797 | ||
798 | // clock_t start; | |
799 | int ii, jj; | |
800 | static int i=96, j=32, itest=0, i1, i2, i3, i4, i5; | |
801 | static double u[97], c, cd, cm, s, t; | |
802 | static double uni; | |
803 | int count1,count2,idum; | |
804 | /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */ | |
805 | if (itest == 0) { | |
806 | //******************************************************* | |
807 | // following three lines if the seed to be provided by computer | |
808 | // start = time(NULL); | |
809 | // ii=start; | |
810 | // jj=start; | |
811 | //******************************************************* | |
812 | //following two lines for fixed seed ( during testing only. Else | |
813 | //use preceeing three lines | |
814 | ii=8263; | |
815 | jj=5726; | |
816 | if(ii > 31328 ) ii = ii - ( ii / 31328 ) * 31328; | |
817 | if(jj > 30081 ) jj = jj - ( jj / 30081 ) * 30081; | |
818 | itest=itest+1; | |
819 | if((( ii > 0 ) && ( ii <= 31328 )) && (( jj > 0 ) && | |
820 | ( jj <= 30081 ))){ | |
821 | i1=ii/177+2; i2=ii-(i1-2)*177+2; i3=jj/169+1; i4=jj-(i3-1)*169; | |
822 | i4 = jj - (i3-1)*169; | |
823 | count1=0; | |
824 | while ( count1 < 97 ){ | |
825 | s=0.; | |
826 | t=0.5; | |
827 | count2=0; | |
828 | while( count2 < 24 ){ | |
829 | idum=i1*i2/179; | |
830 | idum=( i1*i2 - (i1*i2/179)*179 ) * i3; | |
831 | i5=idum-(idum/179)*179; | |
832 | i1=i2; i2=i3; i3=i5; idum=53*i4+1; i4=idum-(idum/169)*169; | |
833 | if( i4*i5-((i4*i5)/64)*64 >= 32 ) s=s+t; | |
834 | t=0.5*t; | |
835 | count2=count2+1; | |
836 | } | |
837 | u[count1] = s; | |
838 | count1 = count1 +1; | |
839 | } | |
840 | c = 362436./16777216.; cd = 7654321./16777216.; | |
841 | cm = 16777213./16777216.; | |
842 | } | |
843 | else{ | |
844 | AliWarning("Wrong initialization"); | |
845 | } | |
846 | } | |
847 | else{ | |
848 | uni = u[i] - u[j]; | |
849 | if( uni < 0.) uni = uni + 1; | |
850 | u[i] = uni; | |
851 | i = i -1; | |
852 | if( i < 0 ) i = 96; | |
853 | j = j - 1; | |
854 | if ( j < 0 ) j = 96; | |
855 | c = c - cd; | |
856 | if( c < 0. ) c = c+cm; | |
857 | uni = uni-c ; | |
858 | if( uni < 0. )uni = uni+1.; | |
859 | } | |
860 | return uni; | |
861 | } | |
862 | // ------------------------------------------------------------------------ // | |
863 | void AliPMDClusteringV1::SetEdepCut(Float_t decut) | |
864 | { | |
865 | fCutoff = decut; | |
866 | } | |
867 | // ------------------------------------------------------------------------ // |