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