]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDClusteringV2.cxx
change Ds selection
[u/mrichter/AliRoot.git] / PMD / AliPMDClusteringV2.cxx
CommitLineData
8c7250c5 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
090026bf 16/* $Id$ */
17
8c7250c5 18//-----------------------------------------------------//
19// //
20// Source File : PMDClusteringV2.cxx //
21// //
22// clustering code for alice pmd //
23// //
24//-----------------------------------------------------//
25
26/* --------------------------------------------------------------------
27 Code developed by S. C. Phatak, Institute of Physics,
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
30 builds up superclusters and breaks them into clusters. The input is
562718f9 31 in TObjarray and cluster information is in TObjArray.
32 integer clno gives total number of clusters in the supermodule.
33 fClusters is the global ( public ) variables.
8c7250c5 34 Others are local ( private ) to the code.
35 At the moment, the data is read for whole detector ( all supermodules
36 and pmd as well as cpv. This will have to be modify later )
37 LAST UPDATE : October 23, 2002
38-----------------------------------------------------------------------*/
39
090026bf 40#include <Riostream.h>
41#include <TMath.h>
8c7250c5 42#include <TObjArray.h>
562718f9 43#include <TArrayI.h>
8c7250c5 44
562718f9 45#include "AliPMDcludata.h"
8c7250c5 46#include "AliPMDcluster.h"
47#include "AliPMDClustering.h"
48#include "AliPMDClusteringV2.h"
49#include "AliLog.h"
50
51ClassImp(AliPMDClusteringV2)
52
53const Double_t AliPMDClusteringV2::fgkSqroot3by2=0.8660254; // sqrt(3.)/2.
54
55AliPMDClusteringV2::AliPMDClusteringV2():
562718f9 56 fPMDclucont(new TObjArray()),
8c7250c5 57 fCutoff(0.0)
58{
59 for(int i = 0; i < kNDIMX; i++)
60 {
61 for(int j = 0; j < kNDIMY; j++)
62 {
63 fCoord[0][i][j] = i+j/2.;
64 fCoord[1][i][j] = fgkSqroot3by2*j;
8c7250c5 65 }
66 }
67}
68// ------------------------------------------------------------------------ //
562718f9 69
70
71AliPMDClusteringV2::AliPMDClusteringV2(const AliPMDClusteringV2& pmdclv2):
72 AliPMDClustering(pmdclv2),
73 fPMDclucont(0),
74 fCutoff(0)
75{
76 // copy constructor
77 AliError("Copy constructor not allowed ");
78
79}
80// ------------------------------------------------------------------------ //
81AliPMDClusteringV2 &AliPMDClusteringV2::operator=(const AliPMDClusteringV2& /*pmdclv2*/)
82{
83 // copy constructor
84 AliError("Assignment operator not allowed ");
85 return *this;
86}
87// ------------------------------------------------------------------------ //
8c7250c5 88AliPMDClusteringV2::~AliPMDClusteringV2()
89{
562718f9 90 delete fPMDclucont;
8c7250c5 91}
92// ------------------------------------------------------------------------ //
562718f9 93
94void AliPMDClusteringV2::DoClust(Int_t idet, Int_t ismn,
920e13db 95 Int_t celltrack[48][96],
96 Int_t cellpid[48][96],
97 Double_t celladc[48][96],
22bd512d 98 TObjArray *pmdcont)
8c7250c5 99{
100 // main function to call other necessary functions to do clustering
101 //
102 AliPMDcluster *pmdcl = 0;
103
2c1131dd 104 const Float_t ktwobysqrt3 = 1.1547; // 2./sqrt(3.)
105 const Int_t kNmaxCell = 19; // # of cells surrounding a cluster center
562718f9 106 Int_t i, j, nmx1, incr, id, jd;
107 Int_t ndimXr = 0;
108 Int_t ndimYr = 0;
2c1131dd 109 Int_t celldataX[kNmaxCell], celldataY[kNmaxCell];
920e13db 110 Int_t celldataTr[kNmaxCell], celldataPid[kNmaxCell];
b0e4d1e1 111 Float_t celldataAdc[kNmaxCell];
562718f9 112 Float_t clusdata[6];
8c7250c5 113 Double_t cutoff, ave;
562718f9 114 Double_t edepcell[kNMX];
8c7250c5 115
8c7250c5 116
117 if (ismn < 12)
118 {
119 ndimXr = 96;
120 ndimYr = 48;
121 }
122 else if (ismn >= 12 && ismn <= 23)
123 {
124 ndimXr = 48;
125 ndimYr = 96;
126 }
562718f9 127
78fc1b96 128 for (i =0; i < kNMX; i++)
8c7250c5 129 {
562718f9 130 edepcell[i] = 0.;
8c7250c5 131 }
562718f9 132
8c7250c5 133 for (id = 0; id < ndimXr; id++)
134 {
135 for (jd = 0; jd < ndimYr; jd++)
136 {
562718f9 137 j = jd;
138 i = id + (ndimYr/2-1) - (jd/2);
139 Int_t ij = i + j*kNDIMX;
8c7250c5 140 if (ismn < 12)
141 {
562718f9 142 edepcell[ij] = celladc[jd][id];
8c7250c5 143 }
144 else if (ismn >= 12 && ismn <= 23)
145 {
562718f9 146 edepcell[ij] = celladc[id][jd];
8c7250c5 147 }
148
149 }
150 }
151
562718f9 152 Int_t iord1[kNMX];
df4e6759 153 TMath::Sort((Int_t)kNMX,edepcell,iord1);// order the data
8c7250c5 154 cutoff = fCutoff; // cutoff used to discard cells having ener. dep.
562718f9 155 ave = 0.;
156 nmx1 = -1;
8c7250c5 157
562718f9 158 for(i = 0;i < kNMX; i++)
8c7250c5 159 {
562718f9 160 if(edepcell[i] > 0.)
161 {
162 ave += edepcell[i];
163 }
164 if(edepcell[i] > cutoff )
165 {
166 nmx1++;
167 }
8c7250c5 168 }
562718f9 169
8c7250c5 170 AliDebug(1,Form("Number of cells having energy >= %f are %d",cutoff,nmx1));
562718f9 171
172 if (nmx1 == 0)
173 {
174 nmx1 = 1;
175 }
176 ave = ave/nmx1;
177
8c7250c5 178 AliDebug(1,Form("Number of cells in a SuperM = %d and Average = %f",
179 kNMX,ave));
8c7250c5 180
562718f9 181 incr = CrClust(ave, cutoff, nmx1,iord1, edepcell);
182 RefClust(incr,edepcell );
183
184 Int_t nentries1 = fPMDclucont->GetEntries();
185 AliDebug(1,Form("Detector Plane = %d Serial Module No = %d Number of clusters = %d",idet, ismn, nentries1));
186 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
187 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
8c7250c5 188 {
562718f9 189 AliPMDcludata *pmdcludata =
190 (AliPMDcludata*)fPMDclucont->UncheckedAt(ient1);
191 Float_t cluXC = pmdcludata->GetClusX();
192 Float_t cluYC = pmdcludata->GetClusY();
193 Float_t cluADC = pmdcludata->GetClusADC();
194 Float_t cluCELLS = pmdcludata->GetClusCells();
195 Float_t cluSIGX = pmdcludata->GetClusSigmaX();
196 Float_t cluSIGY = pmdcludata->GetClusSigmaY();
197
8c7250c5 198 Float_t cluY0 = ktwobysqrt3*cluYC;
199 Float_t cluX0 = cluXC - cluY0/2.;
562718f9 200
8c7250c5 201 //
202 // Cluster X centroid is back transformed
203 //
204 if (ismn < 12)
205 {
206 clusdata[0] = cluX0 - (24-1) + cluY0/2.;
207 }
562718f9 208 else if (ismn >= 12 && ismn <= 23)
8c7250c5 209 {
210 clusdata[0] = cluX0 - (48-1) + cluY0/2.;
211 }
212
562718f9 213 clusdata[1] = cluY0;
214 clusdata[2] = cluADC;
215 clusdata[3] = cluCELLS;
216 clusdata[4] = cluSIGX;
217 clusdata[5] = cluSIGY;
8c7250c5 218 //
219 // Cells associated with a cluster
220 //
2c1131dd 221 for (Int_t ihit = 0; ihit < kNmaxCell; ihit++)
8c7250c5 222 {
562718f9 223 Int_t dummyXY = pmdcludata->GetCellXY(ihit);
224
225 Int_t celldumY = dummyXY%10000;
226 Int_t celldumX = dummyXY/10000;
c1339151 227 Float_t cellY = (Float_t) celldumY/10;
228 Float_t cellX = (Float_t) celldumX/10;
229
562718f9 230 //
231 // Cell X centroid is back transformed
232 //
233 if (ismn < 12)
234 {
c1339151 235 celldataX[ihit] = (Int_t) ((cellX - (24-1) + cellY/2.) + 0.5);
562718f9 236 }
237 else if (ismn >= 12 && ismn <= 23)
238 {
c1339151 239 celldataX[ihit] = (Int_t) ((cellX - (48-1) + cellY/2.) + 0.5 );
562718f9 240 }
b0e4d1e1 241 celldataY[ihit] = (Int_t) (cellY + 0.5);
b6d6a9b5 242
243 Int_t irow = celldataX[ihit];
244 Int_t icol = celldataY[ihit];
245
246 if ((irow >= 0 && irow < 48) && (icol >= 0 && icol < 96))
247 {
248 celldataTr[ihit] = celltrack[irow][icol];
249 celldataPid[ihit] = cellpid[irow][icol];
250 celldataAdc[ihit] = (Float_t) celladc[irow][icol];
251 }
252 else
253 {
254 celldataTr[ihit] = -1;
255 celldataPid[ihit] = -1;
256 celldataAdc[ihit] = -1;
257 }
258
8c7250c5 259 }
260
920e13db 261 pmdcl = new AliPMDcluster(idet, ismn, clusdata, celldataX, celldataY,
b0e4d1e1 262 celldataTr, celldataPid, celldataAdc);
8c7250c5 263 pmdcont->Add(pmdcl);
264 }
2c1131dd 265 fPMDclucont->Delete();
8c7250c5 266}
267// ------------------------------------------------------------------------ //
562718f9 268Int_t AliPMDClusteringV2::CrClust(Double_t ave, Double_t cutoff, Int_t nmx1,
269 Int_t iord1[], Double_t edepcell[])
8c7250c5 270{
271 // Does crude clustering
272 // Finds out only the big patch by just searching the
273 // connected cells
274 //
275
562718f9 276 Int_t i,j,k,id1,id2,icl, numcell;
277 Int_t jd1,jd2, icell, cellcount;
278 Int_t clust[2][5000];
279 static Int_t neibx[6] = {1,0,-1,-1,0,1}, neiby[6] = {0,1,1,0,-1,-1};
8c7250c5 280
281 // neibx and neiby define ( incremental ) (i,j) for the neighbours of a
282 // cell. There are six neighbours.
283 // cellcount --- total number of cells having nonzero ener dep
284 // numcell --- number of cells in a given supercluster
562718f9 285
8c7250c5 286 AliDebug(1,Form("kNMX = %d nmx1 = %d kNDIMX = %d kNDIMY = %d ave = %f cutoff = %f",kNMX,nmx1,kNDIMX,kNDIMY,ave,cutoff));
287
562718f9 288 for (j=0; j < kNDIMX; j++)
289 {
290 for(k=0; k < kNDIMY; k++)
291 {
292 fInfocl[0][j][k] = 0;
293 fInfocl[1][j][k] = 0;
294 }
295 }
296
297 for(i=0; i < kNMX; i++)
298 {
299 fInfcl[0][i] = -1;
300
301 j = iord1[i];
302 id2 = j/kNDIMX;
303 id1 = j-id2*kNDIMX;
304
305 if(edepcell[j] <= cutoff)
306 {
307 fInfocl[0][id1][id2] = -1;
308 }
8c7250c5 309 }
8c7250c5 310 // ---------------------------------------------------------------
311 // crude clustering begins. Start with cell having largest adc
312 // count and loop over the cells in descending order of adc count
313 // ---------------------------------------------------------------
562718f9 314 icl = -1;
315 cellcount = -1;
316 for(icell=0; icell <= nmx1; icell++)
317 {
318 j = iord1[icell];
319 id2 = j/kNDIMX;
320 id1 = j-id2*kNDIMX;
321 if(fInfocl[0][id1][id2] == 0 )
322 {
323 // ---------------------------------------------------------------
324 // icl -- cluster #, numcell -- # of cells in it, clust -- stores
325 // coordinates of the cells in a cluster, fInfocl[0][i1][i2] is 1 for
326 // primary and 2 for secondary cells,
327 // fInfocl[1][i1][i2] stores cluster #
328 // ---------------------------------------------------------------
329 icl++;
330 numcell = 0;
331 cellcount++;
332 fInfocl[0][id1][id2] = 1;
333 fInfocl[1][id1][id2] = icl;
334 fInfcl[0][cellcount] = icl;
335 fInfcl[1][cellcount] = id1;
336 fInfcl[2][cellcount] = id2;
337
338 clust[0][numcell] = id1;
339 clust[1][numcell] = id2;
340 for(i = 1; i < 5000; i++)
341 {
342 clust[0][i] = -1;
343 }
344 // ---------------------------------------------------------------
345 // check for adc count in neib. cells. If ne 0 put it in this clust
346 // ---------------------------------------------------------------
347 for(i = 0; i < 6; i++)
348 {
349 jd1 = id1 + neibx[i];
350 jd2 = id2 + neiby[i];
8c7250c5 351 if( (jd1 >= 0 && jd1 < kNDIMX) && (jd2 >= 0 && jd2 < kNDIMY) &&
562718f9 352 fInfocl[0][jd1][jd2] == 0)
353 {
354 numcell++;
355 fInfocl[0][jd1][jd2] = 2;
356 fInfocl[1][jd1][jd2] = icl;
357 clust[0][numcell] = jd1;
358 clust[1][numcell] = jd2;
359 cellcount++;
360 fInfcl[0][cellcount] = icl;
361 fInfcl[1][cellcount] = jd1;
362 fInfcl[2][cellcount] = jd2;
363 }
364 }
365 // ---------------------------------------------------------------
366 // check adc count for neighbour's neighbours recursively and
367 // if nonzero, add these to the cluster.
368 // ---------------------------------------------------------------
369 for(i = 1;i < 5000; i++)
370 {
371 if(clust[0][i] != -1)
372 {
373 id1 = clust[0][i];
374 id2 = clust[1][i];
375 for(j = 0; j < 6 ; j++)
376 {
377 jd1 = id1 + neibx[j];
378 jd2 = id2 + neiby[j];
379 if( (jd1 >= 0 && jd1 < kNDIMX) &&
380 (jd2 >= 0 && jd2 < kNDIMY)
381 && fInfocl[0][jd1][jd2] == 0 )
382 {
383 fInfocl[0][jd1][jd2] = 2;
384 fInfocl[1][jd1][jd2] = icl;
385 numcell++;
386 clust[0][numcell] = jd1;
387 clust[1][numcell] = jd2;
388 cellcount++;
389 fInfcl[0][cellcount] = icl;
390 fInfcl[1][cellcount] = jd1;
391 fInfcl[2][cellcount] = jd2;
392 }
393 }
394 }
8c7250c5 395 }
8c7250c5 396 }
8c7250c5 397 }
8c7250c5 398 return cellcount;
399}
400// ------------------------------------------------------------------------ //
562718f9 401 void AliPMDClusteringV2::RefClust(Int_t incr, Double_t edepcell[])
8c7250c5 402{
403 // Does the refining of clusters
404 // Takes the big patch and does gaussian fitting and
405 // finds out the more refined clusters
8c7250c5 406
c1339151 407 const Float_t ktwobysqrt3 = 1.1547;
2c1131dd 408 const Int_t kNmaxCell = 19;
409
562718f9 410 AliPMDcludata *pmdcludata = 0;
c1339151 411
78fc1b96 412 Int_t i12;
562718f9 413 Int_t i, j, k, i1, i2, id, icl, itest, ihld;
414 Int_t ig, nsupcl, clno, clX,clY;
2c1131dd 415 Int_t clxy[kNmaxCell];
c1339151 416
562718f9 417 Float_t clusdata[6];
418 Double_t x1, y1, z1, x2, y2, z2, rr;
c1339151 419
420 Int_t kndim = incr + 1;
421
422 TArrayI testncl;
423 TArrayI testindex;
424
425 Int_t *ncl, *iord;
426
427 Double_t *x, *y, *z, *xc, *yc, *zc, *cells, *rcl, *rcs;
428
429 ncl = new Int_t [kndim];
430 iord = new Int_t [kndim];
431 x = new Double_t [kndim];
432 y = new Double_t [kndim];
433 z = new Double_t [kndim];
434 xc = new Double_t [kndim];
435 yc = new Double_t [kndim];
436 zc = new Double_t [kndim];
437 cells = new Double_t [kndim];
438 rcl = new Double_t [kndim];
439 rcs = new Double_t [kndim];
562718f9 440
441 for(Int_t kk = 0; kk < 15; kk++)
442 {
443 if( kk < 6 )clusdata[kk] = 0.;
444 }
445
8c7250c5 446 // nsupcl = # of superclusters; ncl[i]= # of cells in supercluster i
447 // x, y and z store (x,y) coordinates of and energy deposited in a cell
448 // xc, yc store (x,y) coordinates of the cluster center
562718f9 449 // zc stores the energy deposited in a cluster, rc is cluster radius
8c7250c5 450
562718f9 451 clno = -1;
8c7250c5 452 nsupcl = -1;
c1339151 453
454 for(i = 0; i < kndim; i++)
562718f9 455 {
456 ncl[i] = -1;
8c7250c5 457 }
c1339151 458 for(i = 0; i <= incr; i++)
562718f9 459 {
460 if(fInfcl[0][i] != nsupcl)
461 {
462 nsupcl++;
463 }
464 if (nsupcl > 4500)
465 {
466 AliWarning("RefClust: Too many superclusters!");
467 nsupcl = 4500;
468 break;
469 }
470 ncl[nsupcl]++;
471 }
472
8c7250c5 473 AliDebug(1,Form("Number of cells = %d Number of Superclusters = %d",
474 incr+1,nsupcl+1));
562718f9 475
476 id = -1;
477 icl = -1;
c1339151 478 for(i = 0; i <= nsupcl; i++)
562718f9 479 {
480 if(ncl[i] == 0)
8c7250c5 481 {
562718f9 482 id++;
483 icl++;
484 // one cell super-clusters --> single cluster
485 // cluster center at the centyer of the cell
486 // cluster radius = half cell dimension
487 if (clno >= 5000)
8c7250c5 488 {
562718f9 489 AliWarning("RefClust: Too many clusters! more than 5000");
490 return;
8c7250c5 491 }
562718f9 492 clno++;
493 i1 = fInfcl[1][id];
494 i2 = fInfcl[2][id];
78fc1b96 495 i12 = i1 + i2*kNDIMX;
562718f9 496 clusdata[0] = fCoord[0][i1][i2];
497 clusdata[1] = fCoord[1][i1][i2];
498 clusdata[2] = edepcell[i12];
499 clusdata[3] = 1.;
500 clusdata[4] = 0.0;
501 clusdata[5] = 0.0;
502
503 //cell information
c1339151 504
505 clY = (Int_t)((ktwobysqrt3*fCoord[1][i1][i2])*10);
506 clX = (Int_t)((fCoord[0][i1][i2] - clY/20.)*10);
507 clxy[0] = clX*10000 + clY ;
508
2c1131dd 509 for(Int_t icltr = 1; icltr < kNmaxCell; icltr++)
562718f9 510 {
511 clxy[icltr] = -1;
512 }
513 pmdcludata = new AliPMDcludata(clusdata,clxy);
514 fPMDclucont->Add(pmdcludata);
515
516
8c7250c5 517 }
562718f9 518 else if(ncl[i] == 1)
8c7250c5 519 {
562718f9 520 // two cell super-cluster --> single cluster
521 // cluster center is at ener. dep.-weighted mean of two cells
522 // cluster radius == half cell dimension
523 id++;
524 icl++;
525 if (clno >= 5000)
8c7250c5 526 {
527 AliWarning("RefClust: Too many clusters! more than 5000");
528 return;
529 }
562718f9 530 clno++;
531 i1 = fInfcl[1][id];
532 i2 = fInfcl[2][id];
78fc1b96 533 i12 = i1 + i2*kNDIMX;
562718f9 534
535 x1 = fCoord[0][i1][i2];
536 y1 = fCoord[1][i1][i2];
537 z1 = edepcell[i12];
538
539 id++;
540 i1 = fInfcl[1][id];
541 i2 = fInfcl[2][id];
542 i12 = i1 + i2*kNDIMX;
543
544 x2 = fCoord[0][i1][i2];
545 y2 = fCoord[1][i1][i2];
546 z2 = edepcell[i12];
547
548 clusdata[0] = (x1*z1+x2*z2)/(z1+z2);
549 clusdata[1] = (y1*z1+y2*z2)/(z1+z2);
550 clusdata[2] = z1+z2;
551 clusdata[3] = 2.;
552 clusdata[4] = (TMath::Sqrt(z1*z2))/(z1+z2);
553 clusdata[5] = 0.0;
554
c1339151 555 clY = (Int_t)((ktwobysqrt3*y1)*10);
556 clX = (Int_t)((x1 - clY/20.)*10);
557 clxy[0] = clX*10000 + clY ;
558
c1339151 559 clY = (Int_t)((ktwobysqrt3*y2)*10);
560 clX = (Int_t)((x2 - clY/20.)*10);
561 clxy[1] = clX*10000 + clY ;
562
2c1131dd 563 for(Int_t icltr = 2; icltr < kNmaxCell; icltr++)
8c7250c5 564 {
562718f9 565 clxy[icltr] = -1;
8c7250c5 566 }
562718f9 567 pmdcludata = new AliPMDcludata(clusdata, clxy);
568 fPMDclucont->Add(pmdcludata);
8c7250c5 569 }
562718f9 570 else{
571 id++;
572 iord[0] = 0;
573 // super-cluster of more than two cells - broken up into smaller
574 // clusters gaussian centers computed. (peaks separated by > 1 cell)
575 // Begin from cell having largest energy deposited This is first
576 // cluster center
577 // *****************************************************************
578 // NOTE --- POSSIBLE MODIFICATION: ONE MAY NOT BREAKING SUPERCLUSTERS
579 // IF NO. OF CELLS IS NOT TOO LARGE ( SAY 5 OR 6 )
580 // SINCE WE EXPECT THE SUPERCLUSTER
581 // TO BE A SINGLE CLUSTER
582 //*******************************************************************
583
584 i1 = fInfcl[1][id];
585 i2 = fInfcl[2][id];
78fc1b96 586 i12 = i1 + i2*kNDIMX;
562718f9 587
588 x[0] = fCoord[0][i1][i2];
589 y[0] = fCoord[1][i1][i2];
590 z[0] = edepcell[i12];
591
592 iord[0] = 0;
593 for(j = 1; j <= ncl[i]; j++)
594 {
595
596 id++;
597 i1 = fInfcl[1][id];
598 i2 = fInfcl[2][id];
78fc1b96 599 i12 = i1 + i2*kNDIMX;
562718f9 600 iord[j] = j;
601 x[j] = fCoord[0][i1][i2];
602 y[j] = fCoord[1][i1][i2];
603 z[j] = edepcell[i12];
604 }
605
606 // arranging cells within supercluster in decreasing order
607 for(j = 1; j <= ncl[i];j++)
608 {
609 itest = 0;
610 ihld = iord[j];
611 for(i1 = 0; i1 < j; i1++)
612 {
613 if(itest == 0 && z[iord[i1]] < z[ihld])
614 {
615 itest = 1;
616 for(i2 = j-1;i2 >= i1;i2--)
617 {
618 iord[i2+1] = iord[i2];
619 }
620 iord[i1] = ihld;
621 }
622 }
623 }
624
625
626 // compute the number of clusters and their centers ( first
627 // guess )
628 // centers must be separated by cells having smaller ener. dep.
629 // neighbouring centers should be either strong or well-separated
630 ig = 0;
631 xc[ig] = x[iord[0]];
632 yc[ig] = y[iord[0]];
633 zc[ig] = z[iord[0]];
634 for(j = 1; j <= ncl[i]; j++)
635 {
636 itest = -1;
637 x1 = x[iord[j]];
638 y1 = y[iord[j]];
639 for(k = 0; k <= ig; k++)
640 {
641 x2 = xc[k];
642 y2 = yc[k];
643 rr = Distance(x1,y1,x2,y2);
644 //************************************************************
645 // finetuning cluster splitting
646 // the numbers zc/4 and zc/10 may need to be changed.
647 // Also one may need to add one more layer because our
648 // cells are smaller in absolute scale
649 //************************************************************
650
651
652 if( rr >= 1.1 && rr < 1.8 && z[iord[j]] > zc[k]/4.) itest++;
653 if( rr >= 1.8 && rr < 2.1 && z[iord[j]] > zc[k]/10.) itest++;
654 if( rr >= 2.1)itest++;
655 }
656
657 if(itest == ig)
658 {
659 ig++;
660 xc[ig] = x1;
661 yc[ig] = y1;
662 zc[ig] = z[iord[j]];
663 }
664 }
c1339151 665 ClustDetails(ncl[i], ig, x, y ,z, xc, yc, zc, rcl, rcs, cells,
666 testncl, testindex);
562718f9 667
668 Int_t pp = 0;
669 for(j = 0; j <= ig; j++)
670 {
671 clno++;
672 if (clno >= 5000)
673 {
674 AliWarning("RefClust: Too many clusters! more than 5000");
675 return;
676 }
677 clusdata[0] = xc[j];
678 clusdata[1] = yc[j];
679 clusdata[2] = zc[j];
680 clusdata[4] = rcl[j];
681 clusdata[5] = rcs[j];
682 if(ig == 0)
683 {
2c1131dd 684 clusdata[3] = ncl[i] + 1;
562718f9 685 }
686 else
687 {
688 clusdata[3] = cells[j];
689 }
690 // cell information
691 Int_t ncellcls = testncl[j];
2c1131dd 692 if( ncellcls < kNmaxCell )
562718f9 693 {
694 for(Int_t kk = 1; kk <= ncellcls; kk++)
695 {
696 Int_t ll = testindex[pp];
c1339151 697 clY = (Int_t)((ktwobysqrt3*y[ll])*10);
698 clX = (Int_t)((x[ll] - clY/20.)*10);
699 clxy[kk-1] = clX*10000 + clY ;
c1339151 700
562718f9 701 pp++;
702 }
2c1131dd 703 for(Int_t icltr = ncellcls ; icltr < kNmaxCell; icltr++)
562718f9 704 {
705 clxy[icltr] = -1;
706 }
707 }
708 pmdcludata = new AliPMDcludata(clusdata, clxy);
709 fPMDclucont->Add(pmdcludata);
710 }
711 testncl.Set(0);
712 testindex.Set(0);
713 }
8c7250c5 714 }
c1339151 715 delete [] ncl;
716 delete [] iord;
717 delete [] x;
718 delete [] y;
719 delete [] z;
720 delete [] xc;
721 delete [] yc;
722 delete [] zc;
723 delete [] cells;
724 delete [] rcl;
725 delete [] rcs;
8c7250c5 726}
8c7250c5 727// ------------------------------------------------------------------------ //
c1339151 728void AliPMDClusteringV2::ClustDetails(Int_t ncell, Int_t nclust, Double_t x[],
729 Double_t y[], Double_t z[],Double_t xc[],
730 Double_t yc[], Double_t zc[],
731 Double_t rcl[], Double_t rcs[],
732 Double_t cells[], TArrayI &testncl,
562718f9 733 TArrayI &testindex)
8c7250c5 734{
735 // function begins
736 //
8c7250c5 737
c1339151 738 Int_t kndim1 = ncell + 1;//ncell
739 Int_t kndim2 = 20;
740 Int_t kndim3 = nclust + 1;//nclust
78fc1b96 741
562718f9 742 Int_t i, j, k, i1, i2;
562718f9 743 Double_t x1, y1, x2, y2, rr, b, c, r1, r2;
744 Double_t sumx, sumy, sumxy, sumxx, sum, sum1, sumyy;
8c7250c5 745
c1339151 746 Double_t *str, *str1, *xcl, *ycl, *cln;
747 Int_t **cell;
748 Int_t ** cluster;
749 Double_t **clustcell;
750 str = new Double_t [kndim3];
751 str1 = new Double_t [kndim3];
752 xcl = new Double_t [kndim3];
753 ycl = new Double_t [kndim3];
754 cln = new Double_t [kndim3];
562718f9 755
c1339151 756 clustcell = new Double_t *[kndim3];
757 cell = new Int_t *[kndim3];
758 cluster = new Int_t *[kndim1];
562718f9 759 for(i = 0; i < kndim1; i++)
760 {
c1339151 761 cluster[i] = new Int_t [kndim2];
762 }
763
764 for(i = 0; i < kndim3; i++)
765 {
766 str[i] = 0;
767 str1[i] = 0;
768 xcl[i] = 0;
769 ycl[i] = 0;
770 cln[i] = 0;
771
772 cell[i] = new Int_t [kndim2];
773 clustcell[i] = new Double_t [kndim1];
774 for(j = 0; j < kndim1; j++)
8c7250c5 775 {
c1339151 776 clustcell[i][j] = 0;
562718f9 777 }
c1339151 778 for(j = 0; j < kndim2; j++)
562718f9 779 {
c1339151 780 cluster[i][j] = 0;
781 cell[i][j] = 0;
8c7250c5 782 }
562718f9 783 }
c1339151 784
562718f9 785 if(nclust > 0)
786 {
787 // more than one cluster
788 // checking cells shared between several clusters.
789 // First check if the cell is within
790 // one cell unit ( nearest neighbour). Else,
791 // if it is within 1.74 cell units ( next nearest )
792 // Else if it is upto 2 cell units etc.
793
794 for (i = 0; i <= ncell; i++)
8c7250c5 795 {
c1339151 796 x1 = x[i];
797 y1 = y[i];
562718f9 798 cluster[i][0] = 0;
2c1131dd 799
562718f9 800 // distance <= 1 cell unit
2c1131dd 801
562718f9 802 for(j = 0; j <= nclust; j++)
8c7250c5 803 {
c1339151 804 x2 = xc[j];
805 y2 = yc[j];
8c7250c5 806 rr = Distance(x1, y1, x2, y2);
562718f9 807 if(rr <= 1.)
8c7250c5 808 {
809 cluster[i][0]++;
810 i1 = cluster[i][0];
811 cluster[i][i1] = j;
812 }
813 }
562718f9 814 // next nearest neighbour
815 if(cluster[i][0] == 0)
816 {
817 for(j=0; j<=nclust; j++)
818 {
c1339151 819 x2 = xc[j];
820 y2 = yc[j];
562718f9 821 rr = Distance(x1, y1, x2, y2);
822 if(rr <= TMath::Sqrt(3.))
823 {
824 cluster[i][0]++;
825 i1 = cluster[i][0];
826 cluster[i][i1] = j;
827 }
828 }
829 }
830 // next-to-next nearest neighbour
831 if(cluster[i][0] == 0)
832 {
833 for(j=0; j<=nclust; j++)
834 {
c1339151 835 x2 = xc[j];
836 y2 = yc[j];
562718f9 837 rr = Distance(x1, y1, x2, y2);
838 if(rr <= 2.)
839 {
840 cluster[i][0]++;
841 i1 = cluster[i][0];
842 cluster[i][i1] = j;
843 }
844 }
845 }
846 // one more
847 if(cluster[i][0] == 0)
848 {
849 for(j = 0; j <= nclust; j++)
850 {
c1339151 851 x2 = xc[j];
852 y2 = yc[j];
562718f9 853 rr = Distance(x1, y1, x2, y2);
854 if(rr <= 2.7)
855 {
856 cluster[i][0]++;
857 i1 = cluster[i][0];
858 cluster[i][i1] = j;
859 }
860 }
861 }
8c7250c5 862 }
562718f9 863
864 // computing cluster strength. Some cells are shared.
865 for(i = 0; i <= ncell; i++)
8c7250c5 866 {
562718f9 867 if(cluster[i][0] != 0)
8c7250c5 868 {
562718f9 869 i1 = cluster[i][0];
870 for(j = 1; j <= i1; j++)
8c7250c5 871 {
562718f9 872 i2 = cluster[i][j];
c1339151 873 str[i2] += z[i]/i1;
8c7250c5 874 }
875 }
876 }
562718f9 877
878 for(k = 0; k < 5; k++)
8c7250c5 879 {
562718f9 880 for(i = 0; i <= ncell; i++)
8c7250c5 881 {
562718f9 882 if(cluster[i][0] != 0)
8c7250c5 883 {
562718f9 884 i1=cluster[i][0];
885 sum=0.;
886 for(j = 1; j <= i1; j++)
887 {
888 sum += str[cluster[i][j]];
889 }
890
891 for(j = 1; j <= i1; j++)
892 {
893 i2 = cluster[i][j];
c1339151 894 str1[i2] += z[i]*str[i2]/sum;
895 clustcell[i2][i] = z[i]*str[i2]/sum;
562718f9 896 }
8c7250c5 897 }
898 }
562718f9 899
900
901 for(j = 0; j <= nclust; j++)
902 {
903 str[j] = str1[j];
904 str1[j] = 0.;
905 }
8c7250c5 906 }
562718f9 907
908 for(i = 0; i <= nclust; i++)
909 {
910 sumx = 0.;
911 sumy = 0.;
912 sum = 0.;
913 sum1 = 0.;
914 for(j = 0; j <= ncell; j++)
915 {
916 if(clustcell[i][j] != 0)
917 {
c1339151 918 sumx += clustcell[i][j]*x[j];
919 sumy += clustcell[i][j]*y[j];
562718f9 920 sum += clustcell[i][j];
c1339151 921 sum1 += clustcell[i][j]/z[j];
562718f9 922 }
923 }
924 //** xcl and ycl are cluster centroid positions ( center of gravity )
925
926 xcl[i] = sumx/sum;
927 ycl[i] = sumy/sum;
928 cln[i] = sum1;
929 sumxx = 0.;
930 sumyy = 0.;
931 sumxy = 0.;
932 for(j = 0; j <= ncell; j++)
933 {
c1339151 934 sumxx += clustcell[i][j]*(x[j]-xcl[i])*(x[j]-xcl[i])/sum;
935 sumyy += clustcell[i][j]*(y[j]-ycl[i])*(y[j]-ycl[i])/sum;
936 sumxy += clustcell[i][j]*(x[j]-xcl[i])*(y[j]-ycl[i])/sum;
562718f9 937 }
938 b = sumxx+sumyy;
939 c = sumxx*sumyy-sumxy*sumxy;
940 // ******************r1 and r2 are major and minor axes ( r1 > r2 ).
941 r1 = b/2.+TMath::Sqrt(b*b/4.-c);
942 r2 = b/2.-TMath::Sqrt(b*b/4.-c);
943 // final assignments to proper external variables
c1339151 944 xc[i] = xcl[i];
945 yc[i] = ycl[i];
946 zc[i] = str[i];
947 cells[i] = cln[i];
948 rcl[i] = r1;
949 rcs[i] = r2;
950
8c7250c5 951 }
562718f9 952
953 //To get the cell position in a cluster
954
955 for(Int_t ii=0; ii<= ncell; ii++)
956 {
957 Int_t jj = cluster[ii][0];
958 for(Int_t kk=1; kk<= jj; kk++)
8c7250c5 959 {
562718f9 960 Int_t ll = cluster[ii][kk];
961 cell[ll][0]++;
962 cell[ll][cell[ll][0]] = ii;
8c7250c5 963 }
562718f9 964 }
965
966 testncl.Set(nclust+1);
967 Int_t counter = 0;
968
969 for(Int_t ii=0; ii <= nclust; ii++)
970 {
971 testncl[ii] = cell[ii][0];
972 counter += testncl[ii];
973 }
974 testindex.Set(counter);
975 Int_t ll = 0;
976 for(Int_t ii=0; ii<= nclust; ii++)
977 {
978 for(Int_t jj = 1; jj<= testncl[ii]; jj++)
979 {
980 Int_t kk = cell[ii][jj];
981 testindex[ll] = kk;
982 ll++;
983 }
984 }
985
986 }
c1339151 987 else if(nclust == 0)
562718f9 988 {
8c7250c5 989 sumx = 0.;
990 sumy = 0.;
991 sum = 0.;
992 sum1 = 0.;
562718f9 993 i = 0;
994 for(j = 0; j <= ncell; j++)
995 {
c1339151 996 sumx += z[j]*x[j];
997 sumy += z[j]*y[j];
998 sum += z[j];
562718f9 999 sum1++;
8c7250c5 1000 }
8c7250c5 1001 xcl[i] = sumx/sum;
1002 ycl[i] = sumy/sum;
1003 cln[i] = sum1;
562718f9 1004 sumxx = 0.;
1005 sumyy = 0.;
1006 sumxy = 0.;
1007 for(j = 0; j <= ncell; j++)
1008 {
c1339151 1009 sumxx += clustcell[i][j]*(x[j]-xcl[i])*(x[j]-xcl[i])/sum;
1010 sumyy += clustcell[i][j]*(y[j]-ycl[i])*(y[j]-ycl[i])/sum;
1011 sumxy += clustcell[i][j]*(x[j]-xcl[i])*(y[j]-ycl[i])/sum;
562718f9 1012 }
1013 b = sumxx+sumyy;
1014 c = sumxx*sumyy-sumxy*sumxy;
1015 r1 = b/2.+ TMath::Sqrt(b*b/4.-c);
1016 r2 = b/2.- TMath::Sqrt(b*b/4.-c);
1017
1018 // To get the cell position in a cluster
1019 testncl.Set(nclust+1);
c1339151 1020 testindex.Set(ncell+1);
2c1131dd 1021 cell[0][0] = ncell + 1;
562718f9 1022 testncl[0] = cell[0][0];
1023 Int_t ll = 0;
c1339151 1024 for(Int_t ii = 1; ii <= ncell; ii++)
562718f9 1025 {
1026 cell[0][ii]=ii;
562718f9 1027 Int_t kk = cell[0][ii];
1028 testindex[ll] = kk;
1029 ll++;
1030 }
1031 // final assignments
c1339151 1032 xc[i] = xcl[i];
1033 yc[i] = ycl[i];
c1339151 1034 zc[i] = sum;
1035 cells[i] = cln[i];
1036 rcl[i] = r1;
1037 rcs[i] = r2;
1038 }
1039 for(i = 0; i < kndim3; i++)
1040 {
1041 delete [] clustcell[i];
1042 delete [] cell[i];
1043 }
1044 delete [] clustcell;
1045 delete [] cell;
1046 for(i = 0; i <kndim1 ; i++)
1047 {
1048 delete [] cluster[i];
8c7250c5 1049 }
c1339151 1050 delete [] cluster;
1051 delete [] str;
1052 delete [] str1;
1053 delete [] xcl;
1054 delete [] ycl;
1055 delete [] cln;
8c7250c5 1056}
1057
1058// ------------------------------------------------------------------------ //
1059Double_t AliPMDClusteringV2::Distance(Double_t x1, Double_t y1,
1060 Double_t x2, Double_t y2)
1061{
562718f9 1062 return TMath::Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
8c7250c5 1063}
1064// ------------------------------------------------------------------------ //
1065void AliPMDClusteringV2::SetEdepCut(Float_t decut)
1066{
1067 fCutoff = decut;
1068}
1069// ------------------------------------------------------------------------ //