1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 #include "AliITSClusterFinderSPD.h"
18 #include "AliITSMapA1.h"
20 #include "AliITSdigit.h"
21 #include "AliITSRawCluster.h"
22 #include "AliITSRecPoint.h"
23 #include "AliITSsegmentation.h"
24 #include "AliITSresponse.h"
29 ClassImp(AliITSClusterFinderSPD)
31 //----------------------------------------------------------
32 AliITSClusterFinderSPD::AliITSClusterFinderSPD
33 (AliITSsegmentation *seg, TClonesArray *digits, TClonesArray *recp)
39 fNclusters= fClusters->GetEntriesFast();
42 fMap=new AliITSMapA1(fSegmentation,fDigits);
46 //_____________________________________________________________________________
47 AliITSClusterFinderSPD::AliITSClusterFinderSPD()
61 //_____________________________________________________________________________
62 AliITSClusterFinderSPD::~AliITSClusterFinderSPD()
65 if (fMap) delete fMap;
69 //__________________________________________________________________________
70 AliITSClusterFinderSPD::AliITSClusterFinderSPD(const AliITSClusterFinderSPD &source){
72 if(&source == this) return;
73 this->fClusters = source.fClusters ;
74 this->fNclusters = source.fNclusters ;
75 this->fMap = source.fMap ;
76 this->fDz = source.fDz ;
77 this->fDx = source.fDx ;
78 this->fMinNCells = source.fMinNCells ;
82 //_________________________________________________________________________
83 AliITSClusterFinderSPD&
84 AliITSClusterFinderSPD::operator=(const AliITSClusterFinderSPD &source) {
85 // Assignment operator
86 if(&source == this) return *this;
87 this->fClusters = source.fClusters ;
88 this->fNclusters = source.fNclusters ;
89 this->fMap = source.fMap ;
90 this->fDz = source.fDz ;
91 this->fDx = source.fDx ;
92 this->fMinNCells = source.fMinNCells ;
96 //_____________________________________________________________________________
97 void AliITSClusterFinderSPD::SetMap()
101 if(!fMap) fMap=new AliITSMapA1(fSegmentation,fDigits);
105 //_____________________________________________________________________________
107 void AliITSClusterFinderSPD::Find1DClusters()
109 // Find one dimensional clusters, i.e.
110 // in r*phi(x) direction for each colunm in z direction
112 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
114 // retrieve the parameters
115 Int_t fNofPixels = fSegmentation->Npz();
116 Int_t fMaxNofSamples = fSegmentation->Npx();
118 // read in digits -> do not apply threshold
119 // signal in fired pixels is always 1
123 Int_t nofFoundClusters = 0;
126 for(k=0;k<fNofPixels;k++) {
128 Int_t mmax = 10; // a size of the window for the cluster finding
130 for(it=0;it<fMaxNofSamples;it++) {
138 for(m=0;m<mmax;m++) { // find the cluster inside the window
140 if(id >= fMaxNofSamples) break; // ! no possible for the fadc
142 if(fMap->TestHit(k,id) == kUnused) { // start of the cluster
144 if(lclx == 1) xstart = id;
148 if(lclx > 0 && fMap->TestHit(k,id) == kEmpty) {
149 // end of cluster if a gap exists
157 if(lclx == 0 && ilcl == 0) it = id; // no cluster in the window,
158 // continue the "it" loop
160 if(id >= fMaxNofSamples && lclx == 0) break; // the x row finished
162 if(id < fMaxNofSamples && ilcl == 0 && lclx > 0) {
163 // cluster end is outside of the window,
164 mmax += 5; // increase mmax and repeat the cluster
169 if(id >= fMaxNofSamples && lclx > 0) { // the x row finished but
170 xstop = fMaxNofSamples - 1; // the end cluster exists
174 // --- Calculate z and x coordinates for one dimensional clusters
176 if(ilcl == 1) { // new cluster exists
180 Float_t clusterCharge = 0.;
181 Float_t zpitch = fSegmentation->Dpz(k+1);
182 Float_t clusterZ, dummyX;
184 fSegmentation->GetPadCxz(dummy,k,dummyX,clusterZ);
185 Float_t zstart = clusterZ - 0.5*zpitch;
186 Float_t zstop = clusterZ + 0.5*zpitch;
187 Float_t clusterX = 0.;
188 Int_t xstartfull = xstart;
189 Int_t xstopfull = xstop;
190 Int_t clusterSizeX = lclx;
191 Int_t clusterSizeZ = 1;
194 for(its=xstart; its<=xstop; its++) {
196 if (fMap->GetHitIndex(k,its)>=0) firedpixel=1;
197 clusterCharge += firedpixel;
198 clusterX +=its + 0.5;
200 Float_t fRphiPitch = fSegmentation->Dpx(dummy);
201 clusterX /= (clusterSizeX/fRphiPitch); // center of gravity for x
204 //printf("ClusterZ ClusterX %f %f \n",clusterZ, clusterX);
206 // Int_t nclusters = fClusters->GetEntriesFast();
207 // cout << nclusters << " clusters" << endl;
208 // cout<< "Create point"<<endl;
210 // Write the points (coordinates and some cluster information) to the
211 // AliITSRawClusterSPD object
213 AliITSRawClusterSPD *clust = new AliITSRawClusterSPD(clusterZ,clusterX,clusterCharge,clusterSizeZ,clusterSizeX,xstart,xstop,xstartfull,xstopfull,zstart,zstop,k);
214 // fClusters->Add(point);
215 iTS->AddCluster(0,clust);
217 // cout << "Cluster at Ladder: " << fLadder << ", Detector: " <<fDetector<<endl;
219 // cout<<" end of cluster finding for Z pixel "<<endl;
221 } // new cluster (ilcl=1)
222 } // X direction loop (it)
223 } // Z direction loop (k)
230 //_____________________________________________________________________________
231 void AliITSClusterFinderSPD::GroupClusters()
233 // Find two dimensional clusters, i.e. group one dimensional clusters
234 // into two dimensional ones (go both in x and z directions).
236 // get number of clusters for this module
237 Int_t nofClusters = fClusters->GetEntriesFast();
238 nofClusters -= fNclusters;
240 AliITSRawClusterSPD *clusterI;
241 AliITSRawClusterSPD *clusterJ;
243 Int_t *label=new Int_t[nofClusters];
245 for(i=0; i<nofClusters; i++) label[i] = 0;
246 for(i=0; i<nofClusters; i++) {
247 if(label[i] != 0) continue;
248 for(j=i+1; j<nofClusters; j++) {
249 if(label[j] != 0) continue;
250 clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
251 clusterJ = (AliITSRawClusterSPD*) fClusters->At(j);
252 Bool_t pair = clusterI->Brother(clusterJ,fDz,fDx);
255 // if((clusterI->XStop() == clusterJ->XStart()-1)||(clusterI->XStart()==clusterJ->XStop()+1)) cout<<"!! Diagonal cluster"<<endl;
257 cout << "clusters " << i << "," << j << " before grouping" << endl;
258 clusterI->PrintInfo();
259 clusterJ->PrintInfo();
261 clusterI->Add(clusterJ);
262 // cout << "remove cluster " << j << endl;
264 fClusters->RemoveAt(j);
266 cout << "cluster " << i << " after grouping" << endl;
267 clusterI->PrintInfo();
273 fClusters->Compress();
274 // Int_t totalNofClusters = fClusters->GetEntriesFast();
275 // cout << " Nomber of clusters at the group end ="<< totalNofClusters<<endl;
283 //_____________________________________________________________________________
285 void AliITSClusterFinderSPD::TracksInCluster()
288 // Find tracks creating one cluster
290 // get number of clusters for this module
291 Int_t nofClusters = fClusters->GetEntriesFast();
292 nofClusters -= fNclusters;
294 //printf("nofClusters fNclusters %d %d\n",nofClusters,fNclusters); //commented 18-09-00
296 Int_t i, ix, iz, jx, jz, xstart, xstop, zstart, zstop, nclx, nclz;
297 // Int_t signal, track0, track1, track2;
298 const Int_t trmax = 100;
299 Int_t cltracks[trmax], itr, tracki, ii, is, js, ie, ntr, tr0, tr1, tr2;
301 for(i=0; i<nofClusters; i++) {
303 memset(cltracks,-1,sizeof(int)*trmax);
306 AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
307 //printf("clusterI %p\n",clusterI); //commented 18-09-00
309 nclx = clusterI->NclX();
310 nclz = clusterI->NclZ();
311 xstart = clusterI->XStartf();
312 xstop = clusterI->XStopf();
313 zstart = clusterI->Zend()-nclz+1;
314 zstop = clusterI->Zend();
318 for(iz=0; iz<nclz; iz++) {
320 for(ix=0; ix<nclx; ix++) {
322 ind = fMap->GetHitIndex(jz,jx);
323 //printf("ind %d\n",ind); // commented 18-09-00
324 // this part must be wrong - the index of the digit
325 // can be zero but not -1 !!! comment out this part
326 // and replace it - see below
328 if(ind == 0 && iz >= 0 && ix > 0) {
331 if(ind == 0 && iz > 0 && ix >= 0) {
334 if(ind == 0 && iz == 0 && ix == 0 && i > 0) {
338 // change the conditions above to :
339 if (ind < 0) continue;
341 AliITSdigitSPD *dig = (AliITSdigitSPD*)fMap->GetHit(jz,jx);
342 if (!dig) printf("SPD: something wrong ! dig %p\n",dig);
345 track0=dig->fTracks[0];
346 track1=dig->fTracks[1];
347 track2=dig->fTracks[2];
349 for(itr=0; itr<3; itr++) {
350 tracki = dig->fTracks[itr];
351 //printf("tracki %d\n",tracki); //commented 18-09-00
354 cltracks[ii-1] = tracki;
360 for(is=0; is<trmax; is++) {
361 if(cltracks[is]<0) continue;
362 for(js=is+1; js<trmax; js++) {
363 if(cltracks[js]<0) continue;
364 if(cltracks[js]==cltracks[is]) cltracks[js]=-5;
369 for(ie=0; ie<trmax; ie++) {
370 if(cltracks[ie] >= 0) {
372 if(ntr==1) tr0=cltracks[ie];
373 if(ntr==2) tr1=cltracks[ie];
374 if(ntr==3) tr2=cltracks[ie];
378 if(ntr == 0) ntr = 1;
380 clusterI->SetNTracks(ntr);
381 clusterI->SetTracks(tr0,tr1,tr2);
386 //_____________________________________________________________________________
388 void AliITSClusterFinderSPD::GetRecPoints()
391 AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
393 // get number of clusters for this module
394 Int_t nofClusters = fClusters->GetEntriesFast();
395 nofClusters -= fNclusters;
396 const Float_t kconv = 1.0e-4;
397 const Float_t kRMSx = 12.0*kconv; // microns -> cm ITS TDR Table 1.3
398 const Float_t kRMSz = 120.0*kconv; // resolution for 425 micron pixel
400 Float_t spdLength = fSegmentation->Dz();
401 Float_t spdWidth = fSegmentation->Dx();
404 Int_t track0, track1, track2;
406 for(i=0; i<nofClusters; i++) {
408 AliITSRawClusterSPD *clusterI = (AliITSRawClusterSPD*) fClusters->At(i);
409 clusterI->GetTracks(track0, track1, track2);
412 rnew.SetX((clusterI->X() - spdWidth/2)*kconv);
413 rnew.SetZ((clusterI->Z() - spdLength/2)*kconv);
416 rnew.SetSigmaX2(kRMSx*kRMSx);
417 rnew.SetSigmaZ2(kRMSz*kRMSz);
418 rnew.fTracks[0]=track0;
419 rnew.fTracks[1]=track1;
420 rnew.fTracks[2]=track2;
421 iTS->AddRecPoint(rnew);
427 //_____________________________________________________________________________
429 void AliITSClusterFinderSPD::FindRawClusters()