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