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