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