]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinderSPD.cxx
Modifications associated with remerging the Ba/Sa and Dubna pixel simulations,
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderSPD.cxx
CommitLineData
c98c0281 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 **************************************************************************/
bf3f2830 15//
16// Cluster finder
17// for Silicon pixels
18//
19//
c98c0281 20#include "AliITSClusterFinderSPD.h"
21#include "AliITS.h"
e869281d 22#include "AliITSdigitSPD.h"
41b19549 23#include "AliITSRawClusterSPD.h"
c98c0281 24#include "AliITSRecPoint.h"
aacedc3e 25#include "AliITSresponseSPD.h"
26#include "AliITSsegmentationSPD.h"
c98c0281 27#include "AliRun.h"
28
9e1e0cd7 29//#define DEBUG
c98c0281 30
31ClassImp(AliITSClusterFinderSPD)
32
aacedc3e 33//______________________________________________________________________
34AliITSClusterFinderSPD::AliITSClusterFinderSPD():AliITSClusterFinder(),
35fDz(0.0),
36fDx(0.0),
37fMinNCells(0){
38 // constructor
39}
c98c0281 40//----------------------------------------------------------
9e1e0cd7 41AliITSClusterFinderSPD::AliITSClusterFinderSPD(AliITSsegmentation *seg,
aacedc3e 42 AliITSresponse *res):
43AliITSClusterFinder(seg,res),
44fDz(0.0),
45fDx(0.0),
46fMinNCells(0){
9e1e0cd7 47 // constructor
48
c98c0281 49 SetDx();
50 SetDz();
51}
aacedc3e 52//----------------------------------------------------------
53AliITSClusterFinderSPD::AliITSClusterFinderSPD(AliITSsegmentation *seg,
54 TClonesArray *digits,
55 TClonesArray *recp):
56AliITSClusterFinder(seg,0),
57fDz(0.0),
58fDx(0.0),
59fMinNCells(0){
9e1e0cd7 60 // constructor
61
aacedc3e 62 SetDigits(digits);
63 SetClusters(recp);
9e1e0cd7 64 SetDx();
65 SetDz();
c98c0281 66}
9e1e0cd7 67//_____________________________________________________________________
ac74f489 68AliITSClusterFinderSPD::AliITSClusterFinderSPD(
69 const AliITSClusterFinderSPD &source): AliITSClusterFinder(source){
9e1e0cd7 70 // Copy Constructor
71
72 if(&source == this) return;
aacedc3e 73 this->fDz = source.fDz;
74 this->fDx = source.fDx;
75 this->fMinNCells = source.fMinNCells;
9e1e0cd7 76 return;
c98c0281 77}
9e1e0cd7 78//______________________________________________________________________
79AliITSClusterFinderSPD& AliITSClusterFinderSPD::operator=(
80 const AliITSClusterFinderSPD &source) {
81 // Assignment operator
82
83 if(&source == this) return *this;
aacedc3e 84 this->fDz = source.fDz;
85 this->fDx = source.fDx;
86 this->fMinNCells = source.fMinNCells;
9e1e0cd7 87 return *this;
c98c0281 88}
9e1e0cd7 89//______________________________________________________________________
90void AliITSClusterFinderSPD::FindRawClusters(Int_t module){
91 // input of Cluster Finder
92 Int_t digitcount = 0;
93 Int_t numberd = 100000;
c98c0281 94 Int_t *digx = new Int_t[numberd];
95 Int_t *digz = new Int_t[numberd];
96 Int_t *digtr1 = new Int_t[numberd];
97 Int_t *digtr2 = new Int_t[numberd];
98 Int_t *digtr3 = new Int_t[numberd];
99 Int_t *digtr4 = new Int_t[numberd];
c98c0281 100 // output of Cluster Finder
9e1e0cd7 101 Int_t numberc = 10000;
aacedc3e 102 Double_t *xcenterl = new Double_t[numberc];
103 Double_t *zcenterl = new Double_t[numberc];
104 Double_t *errxcenter = new Double_t[numberc];
105 Double_t *errzcenter = new Double_t[numberc];
c98c0281 106 Int_t *tr1clus = new Int_t[numberc];
107 Int_t *tr2clus = new Int_t[numberc];
108 Int_t *tr3clus = new Int_t[numberc];
9e1e0cd7 109 Int_t nclus;
c98c0281 110
aacedc3e 111 SetModule(module);
c98c0281 112 digitcount=0;
aacedc3e 113 Int_t ndigits = Digits()->GetEntriesFast();
c98c0281 114 if (!ndigits) return;
115
ee86d557 116 AliITSdigitSPD *dig;
aacedc3e 117 Int_t ndig=0,i;
118 if(GetDebug(4)){
119 cout << "FindRawcluters"<<endl;
120 scanf("%d",ndig);
121 } // end if GetDebug
c98c0281 122 for(ndig=0; ndig<ndigits; ndig++) {
aacedc3e 123 dig= (AliITSdigitSPD*)GetDigit(ndig);
124 digx[digitcount] = dig->GetCoord2()+1; //starts at 1
125 digz[digitcount] = dig->GetCoord1()+1; //starts at 1
126 digtr1[digitcount] = dig->GetTrack(0);
127 digtr2[digitcount] = -3;
128 digtr3[digitcount] = -3;
129 if(GetDebug(5)){
130 cout << "digtr1["<<digitcount <<"]="<<digtr1[digitcount];
131 cout << " fTracks["<<0<<"]="<<dig->GetTrack(0)<<": ";
132 } // end if GetDebug
133 i=1;
134 while(digtr1[digitcount]==dig->GetTrack(i) && i<dig->GetNTracks()) i++;
135 if(GetDebug(5)) cout << " fTracks["<<i<<"]="<<dig->GetTrack(i);
136 if(i<dig->GetNTracks()){
137 digtr2[digitcount] = dig->GetTrack(i);
138 if(GetDebug(5)) cout<<"digtr2["<<digitcount <<"]="
139 <<digtr2[digitcount]<<": ";
140 while((digtr1[digitcount]==dig->GetTrack(i) ||
141 digtr2[digitcount]==dig->GetTrack(i))&&
142 i<=dig->GetNTracks()) i++;
143 if(i<dig->GetNTracks()) digtr3[digitcount] = dig->GetTrack(i);
144 if(GetDebug(5)){
145 cout << " fTracks["<<i<<"]=";
146 if(i<dig->GetNTracks()) cout <<dig->GetTrack(i);
147 cout << "digtr3["<<digitcount <<"]="<<digtr3[digitcount];
148 } // end if GetDebug
149 } // end if
150 if(GetDebug(4)) cout<<endl;
151 digtr4[digitcount] = dig->GetSignal();
152 digitcount++;
9e1e0cd7 153 } // end for ndig
c98c0281 154 ClusterFinder(digitcount,digx,digz,digtr1,digtr2,digtr3,digtr4,
aacedc3e 155 nclus,xcenterl,zcenterl,errxcenter,errzcenter,
156 tr1clus, tr2clus, tr3clus);
c98c0281 157 DigitToPoint(nclus,xcenterl,zcenterl,errxcenter,errzcenter,
aacedc3e 158 tr1clus, tr2clus, tr3clus);
9e1e0cd7 159 delete[] digx;
160 delete[] digz;
161 delete[] digtr1;
162 delete[] digtr2;
163 delete[] digtr3;
164 delete[] digtr4;
165 delete[] xcenterl;
166 delete[] zcenterl;
167 delete[] errxcenter;
168 delete[] errzcenter;
169 delete[] tr1clus;
170 delete[] tr2clus;
171 delete[] tr3clus;
c98c0281 172}
9e1e0cd7 173//----------------------------------------------------------------------
174void AliITSClusterFinderSPD::ClusterFinder(Int_t ndigits,Int_t digx[],
175 Int_t digz[],Int_t digtr1[],
176 Int_t digtr2[],Int_t digtr3[],
177 Int_t digtr4[],Int_t &nclus,
aacedc3e 178 Double_t xcenter[],Double_t zcenter[],
179 Double_t errxcenter[],
180 Double_t errzcenter[],
9e1e0cd7 181 Int_t tr1clus[],Int_t tr2clus[],
aacedc3e 182 Int_t tr3clus[]){
9e1e0cd7 183 // Search for clusters of fired pixels (digits). Two digits are linked
184 // inside a cluster if they are countiguous both in row or column
185 // direction. Diagonal digits are not linked.
186 // xcenter, ycenter, zcenter are the coordinates of the center
187 // of each found cluster, calculated from the averaging the corresponding
188 // coordinate of the center of the linked digits. The coordinates are
189 // given in the local reference sistem.
190 // errxcenter, errycenter, errzcenter are the errors associated to
191 // the corresponding average.
192 Int_t if1, min, max, nd;
193 Int_t x1, z1, t1, t2, t3, t4;
194 Int_t ndx, ndz, ndxmin=0, ndxmax=0, ndzmin=0, ndzmax=0;
aacedc3e 195 Double_t dx, dz;
9e1e0cd7 196 Int_t i,k,ipos=0;
197 Float_t xdum, zdum;
198 Int_t kmax, sigmax;
aacedc3e 199 Double_t deltax, deltaz;
200 Double_t ndig;
9e1e0cd7 201 Int_t numberd = 10000;
202 Int_t *ifpad = new Int_t[numberd];
203 Int_t *xpad = new Int_t[numberd];
204 Int_t *zpad = new Int_t[numberd];
205 Int_t *tr1pad = new Int_t[numberd];
206 Int_t *tr2pad = new Int_t[numberd];
207 Int_t *tr3pad = new Int_t[numberd];
208 Int_t *tr4pad = new Int_t[numberd];
209 Int_t *iclus = new Int_t[numberd];
210
211 nclus=1;
212 for (i=0; i < ndigits ; i++){
aacedc3e 213 ifpad[i] = -1;
214 iclus[i] = 0;
9e1e0cd7 215 } // end for i
216
217 ifpad[0]=0;
218 for (i=0; i < ndigits-1 ; i++) {
aacedc3e 219 if ( ifpad[i] == -1 ) {
220 nclus++;
221 ipos++;
222 ifpad[i]=nclus-1;
223 } // end if ipad[i]
224 for (Int_t j=i+1 ; j < ndigits ; j++) {
225 if (ifpad[j]== -1 ) {
226 dx = TMath::Abs(digx[i]-digx[j]);
227 dz = TMath::Abs(digz[i]-digz[j]);
228 // if ( ( dx+dz )==1 ) //clusters are not diagonal
229 if(( dx+dz )==1 || (dx==1 && dz==1)){
230 //diagonal clusters allowed
231 ipos++;
232 ifpad[j] = ifpad[i];
233
234 x1 = digx[j];
235 z1 = digz[j];
236 digx[j] = digx[ipos];
237 digz[j] = digz[ipos];
238 digx[ipos] = x1;
239 digz[ipos] = z1;
240
241 t1 = digtr1[j];
242 t2 = digtr2[j];
243 t3 = digtr3[j];
244 t4 = digtr4[j];
245 digtr1[j] = digtr1[ipos];
246 digtr2[j] = digtr2[ipos];
247 digtr3[j] = digtr3[ipos];
248 digtr4[j] = digtr4[ipos];
249 digtr1[ipos] = t1;
250 digtr2[ipos] = t2;
251 digtr3[ipos] = t3;
252 digtr4[ipos] = t4;
253
254 if1 = ifpad[j];
255 ifpad[j] = ifpad[ipos];
256 ifpad[ipos] = if1;
257 } // end dx+dx...
258 }// end if ifpad[j]== -1
259 } // end for j
9e1e0cd7 260 }//end loop on digits
261 if ( ifpad[ndigits-1] == -1 ) {
aacedc3e 262 nclus++;
263 ifpad[ndigits-1]=nclus-1;
9e1e0cd7 264 } // end if ifpad[ndigits-1] == -1
aacedc3e 265
9e1e0cd7 266 for (i=0 ; i < ndigits ; i++) iclus[ifpad[i]]++;
267
268 min=0;
269 max=0;
270 // loop on found clusters
271 for (i=0 ; i < nclus ; i++){
aacedc3e 272 min = max;
273 max += iclus[i];
274 deltax = GetSeg()->Dpx(0);
275 if (iclus[i]!=1){
276 //cluster with more than one digit
277 nd=iclus[i];
278 ndig=(Double_t) nd;
279 Int_t count=0;
280 for (k=min;k<min+nd;k++){
281 xpad[count] = digx[k];
282 zpad[count] = digz[k];
9e1e0cd7 283
aacedc3e 284 tr1pad[count] = digtr1[k];
285 tr2pad[count] = digtr2[k];
286 tr3pad[count] = digtr3[k];
287 tr4pad[count] = digtr4[k];
288
289 count++;
290 } // end for k
291 ndxmin = xpad[TMath::LocMin(nd,xpad)];
292 ndxmax = xpad[TMath::LocMax(nd,xpad)];
293 ndzmin = zpad[TMath::LocMin(nd,zpad)];
294 ndzmax = zpad[TMath::LocMax(nd,zpad)];
295 ndx = ndxmax - ndxmin+1;
296 ndz = ndzmax - ndzmin+1;
297
298 // calculate x and z coordinates of the center of the cluster
299 GetSeg()->GetPadCxz(digx[min],digz[min]-1,xdum, zdum);
300
301 if (ndx == 1) {
302 xcenter[i] = xdum;
303 }else{
304 xcenter[i] = 0.;
305 for (k=0;k<nd;k++) {
306 GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
307 xcenter[i] += (xdum / nd);
308 } // end for k
309 } // end if ndx
310
311 if (ndz == 1) {
312 zcenter[i] = zdum;
313 } else {
314 zcenter[i] = 0.;
315 for (k=0;k<nd;k++) {
316 GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
317 zcenter[i] += (zdum / nd);
318 } // end for k
319 } // end if ndz
320
321 // error on points in x and z directions
322
323 if (ndx == 1) {
324 errxcenter[i] = deltax / TMath::Sqrt(12.);
325 } else {
326 errxcenter[i] = 0.;
327 for (k=0;k<nd;k++){
328 GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
329 errxcenter[i] += ((xdum-xcenter[i])*(xdum-xcenter[i]))/
330 (nd*(nd-1));
331 } // end for k
332 errxcenter[i] = TMath::Sqrt(errxcenter[i]);
333 } // end if ndx
334 if (ndz == 1) {
335 deltaz = GetSeg()->Dpz(digz[min]);
336 errzcenter[i] = deltaz / TMath::Sqrt(12.);
337 } else {
338 errzcenter[i] = 0.;
339 for (k=0;k<nd;k++){
340 GetSeg()->GetPadCxz(xpad[k],zpad[k]-1,xdum,zdum);
341 errzcenter[i] += ((zdum-zcenter[i])*(zdum-zcenter[i]))/
342 (nd*(nd-1));
343 } // end for k
344 errzcenter[i] = TMath::Sqrt(errzcenter[i]);
345 } // end if ndz
346 // take three track numbers for the cluster
347 // choose the track numbers of the digit with higher signal
348 kmax = 0;
349 sigmax = 0;
350 for (k=0;k<nd;k++){
351 if(tr4pad[k] > sigmax){
352 sigmax = tr4pad[k];
353 kmax = k;
354 } // end if tr4pad[k]
355 } // end for k
356 if(sigmax != 0) {
357 tr1clus[i]= tr1pad[kmax];
358 tr2clus[i]= tr2pad[kmax];
359 tr3clus[i]= tr3pad[kmax];
360 } else {
361 tr1clus[i]= -2;
362 tr2clus[i]= -2;
363 tr3clus[i]= -2;
364 } // end if sigmax
365 } else {
366 // cluster with single digit
367 ndig= 1.;
368 ndx = 1;
369 ndz = 1;
370 GetSeg()->GetPadCxz(digx[min],digz[min]-1,xdum,zdum);
371 xcenter[i] = xdum;
372 zcenter[i] = zdum;
373 tr1clus[i]=digtr1[min];
374 tr2clus[i]=digtr2[min];
375 tr3clus[i]=digtr3[min];
376 deltaz = GetSeg()->Dpz(digz[min]);
377 errxcenter[i] = deltax / TMath::Sqrt(12.);
378 errzcenter[i] = deltaz / TMath::Sqrt(12.);
379 } // end if iclus[i]
9e1e0cd7 380
aacedc3e 381 // store the cluster information to the AliITSRawCLusterSPD object
382 static AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
9e1e0cd7 383
aacedc3e 384 //put the cluster center in local reference frame of the detector
385 // and in microns
386 xcenter[i] = xcenter[i] - GetSeg()->Dx()/2.;
387 zcenter[i] = zcenter[i] - GetSeg()->Dz()/2.;
9e1e0cd7 388
aacedc3e 389 AliITSRawClusterSPD *clust = new AliITSRawClusterSPD(zcenter[i], //f
390 xcenter[i], //f
391 ndig, //f
392 ndz,ndx, //ii
393 ndxmin,ndxmax,//ii
394 (Double_t) ndzmin,
395 (Double_t) ndzmax,
396 0,GetModule());
397 iTS->AddCluster(0,clust);
398 delete clust;
9e1e0cd7 399 }//end loop on clusters
400 delete[] ifpad;
401 delete[] xpad ;
402 delete[] zpad ;
403 delete[] iclus;
404 delete[] tr1pad;
405 delete[] tr2pad;
406 delete[] tr3pad;
407 delete[] tr4pad;
c98c0281 408}
9e1e0cd7 409//______________________________________________________----------------
c98c0281 410void AliITSClusterFinderSPD::DigitToPoint(Int_t nclus,
aacedc3e 411 Double_t *xcenter,Double_t *zcenter,
412 Double_t *errxcenter,
413 Double_t *errzcenter,
9e1e0cd7 414 Int_t *tr1clus, Int_t *tr2clus,
415 Int_t *tr3clus){
416 // A point is associated to each cluster of SPD digits. The points
417 // and their associated errors are stored in the file galiceSP.root.
aacedc3e 418 Double_t l[3],xg,zg;
419 const Double_t kconv = 1.0e-4; // micron -> cm
9e1e0cd7 420
421 // get rec points
422 static AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
423 for (Int_t i=0; i<nclus; i++){
c98c0281 424 l[0] = kconv*xcenter[i];
aacedc3e 425 l[1] = kconv*GetSeg()->Dy()/2.;
c98c0281 426 l[2] = kconv*zcenter[i];
427
428 xg = l[0];
429 zg = l[2];
430
aacedc3e 431 Double_t sigma2x = (kconv*errxcenter[i]) * (kconv*errxcenter[i]);
432 Double_t sigma2z = (kconv*errzcenter[i]) * (kconv*errzcenter[i]);
c98c0281 433 AliITSRecPoint rnew;
434 rnew.SetX(xg);
435 rnew.SetZ(zg);
436 rnew.SetQ(1.);
437 rnew.SetdEdX(0.);
438 rnew.SetSigmaX2(sigma2x);
439 rnew.SetSigmaZ2(sigma2z);
440 rnew.fTracks[0]=tr1clus[i];
441 rnew.fTracks[1]=tr2clus[i];
442 rnew.fTracks[2]=tr3clus[i];
443 iTS->AddRecPoint(rnew);
9e1e0cd7 444 } // end for i
c98c0281 445}