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