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