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