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