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