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 **************************************************************************/
18 //-------------------------------------------------------
19 // Implementation of the TPC clusterer
21 // Origin: Jouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-------------------------------------------------------
24 #include "AliTPCclusterer.h"
25 #include "AliTPCcluster.h"
26 #include <TObjArray.h>
28 #include "AliDigits.h"
29 #include "AliSimDigits.h"
30 #include "AliTPCParam.h"
31 #include "AliTPCClustersRow.h"
34 ClassImp(AliTPCclusterer)
37 //____________________________________________________
38 AliTPCclusterer::AliTPCclusterer(const AliTPCclusterer ¶m)
47 //-----------------------------------------------------
48 AliTPCclusterer & AliTPCclusterer::operator =(const AliTPCclusterer & param)
51 // assignment operator - dummy
56 //____________________________________________________
57 void AliTPCclusterer::FindPeaks(Int_t k,Int_t max,
58 AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
61 if (IsMaximum(k,max,b)) {
62 idx[n]=k; msk[n]=(2<<n);
66 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
67 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
68 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
69 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
72 void AliTPCclusterer::MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
74 UShort_t q=bins[k].GetQ();
76 bins[k].SetMask(bins[k].GetMask()|m);
78 if (bins[k-max].GetQ() <= q)
79 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
80 if (bins[k-1 ].GetQ() <= q)
81 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
82 if (bins[k+max].GetQ() <= q)
83 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
84 if (bins[k+1 ].GetQ() <= q)
85 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
88 void AliTPCclusterer::MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,
90 //make cluster using digits of this peak
91 Float_t q=(Float_t)bins[k].GetQ();
92 Int_t i=k/max, j=k-i*max;
97 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
98 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
100 bins[k].SetMask(0xFFFFFFFE);
102 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
103 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
104 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
105 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);
108 //_____________________________________________________________________________
109 Int_t AliTPCclusterer::Digits2Clusters(TTree *dTree, TTree *cTree) {
110 //-----------------------------------------------------------------
111 // This is a simple cluster finder.
112 //-----------------------------------------------------------------
113 TBranch *branch=dTree->GetBranch("Segment");
115 Error("Digits2Cluster","Can't get the branch !");
118 AliSimDigits digarr, *dummy=&digarr;
119 branch->SetAddress(&dummy);
121 AliTPCClustersRow ddd,*clrow=&ddd;
122 clrow = new AliTPCClustersRow("AliTPCcluster");
123 cTree->Branch("Segment","AliTPCClustersRow",&clrow,32000,200);
125 const Int_t kMAXZ=fPar->GetMaxTBin()+2;
129 Int_t nentries = (Int_t)dTree->GetEntries();
130 for (Int_t n=0; n<nentries; n++) {
135 if (!fPar->AdjustSectorRow(digarr.GetID(),sec,row)) {
136 Error("Digits2Clusters","!nvalid segment ID ! %d",digarr.GetID());
140 clrow->SetID(digarr.GetID());
142 cTree->GetBranch("Segment")->SetAddress(&clrow);
144 Float_t rx=fPar->GetPadRowRadii(sec,row);
148 const Int_t kNIS=fPar->GetNInnerSector(), kNOS=fPar->GetNOuterSector();
150 npads = fPar->GetNPadsLow(row);
151 sign = (sec < kNIS/2) ? 1 : -1;
153 npads = fPar->GetNPadsUp(row);
154 sign = ((sec-kNIS) < kNOS/2) ? 1 : -1;
158 const Int_t kMAXBIN=kMAXZ*(npads+2);
159 AliBin *bins=new AliBin[kMAXBIN];
160 for (Int_t ii=0;ii<kMAXBIN;ii++) {
161 bins[ii].SetQ(0); bins[ii].SetMask(0xFFFFFFFE);
166 Short_t dig=digarr.CurrentDigit();
167 if (dig<=fPar->GetZeroSup()) continue;
168 Int_t j=digarr.CurrentRow()+1, i=digarr.CurrentColumn()+1;
169 bins[i*kMAXZ+j].SetQ(dig);
170 bins[i*kMAXZ+j].SetMask(1);
171 } while (digarr.Next());
174 for (Int_t i=0; i<kMAXBIN; i++) {
175 if ((bins[i].GetMask()&1) == 0) continue;
176 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
177 FindPeaks(i, kMAXZ, bins, idx, msk, npeaks);
179 if (npeaks>30) continue;
182 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
183 if (idx[k] < 0) continue; //this peak is already removed
184 for (l=k+1; l<npeaks; l++) {
185 if (idx[l] < 0) continue; //this peak is already removed
186 Int_t ki=idx[k]/kMAXZ, kj=idx[k] - ki*kMAXZ;
187 Int_t li=idx[l]/kMAXZ, lj=idx[l] - li*kMAXZ;
188 Int_t di=TMath::Abs(ki - li);
189 Int_t dj=TMath::Abs(kj - lj);
190 if (di>1 || dj>1) continue;
191 if (bins[idx[k]].GetQ() > bins[idx[l]].GetQ()) {
202 for (k=0; k<npeaks; k++) {
203 MarkPeak(TMath::Abs(idx[k]), kMAXZ, bins, msk[k]);
206 for (k=0; k<npeaks; k++) {
207 if (idx[k] < 0) continue; //removed peak
209 MakeCluster(idx[k], kMAXZ, bins, msk[k], c);
210 if (c.GetQ() < 5) continue; //noise cluster
211 c.SetY(c.GetY()/c.GetQ());
212 c.SetZ(c.GetZ()/c.GetQ());
214 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
215 Float_t w=fPar->GetPadPitchWidth(sec);
216 c.SetSigmaY2((s2 + 1./12.)*w*w);
218 c.SetSigmaY2(c.GetSigmaY2()*0.108);
219 if (sec<fPar->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
222 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
224 c.SetSigmaZ2((s2 + 1./12.)*w*w);
226 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
227 if (sec<fPar->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
230 c.SetY((c.GetY() - 0.5 - 0.5*npads)*fPar->GetPadPitchWidth(sec));
231 c.SetZ(fPar->GetZWidth()*(c.GetZ()-1));
232 c.SetZ(c.GetZ() - 3.*fPar->GetZSigma()); // PASA delay
233 c.SetZ(sign*(fPar->GetZLength(sec) - c.GetZ()));
235 if (rx<230./250.*TMath::Abs(c.GetZ())) continue;
237 Int_t ki=idx[k]/kMAXZ, kj=idx[k] - ki*kMAXZ;
238 c.SetLabel(digarr.GetTrackID(kj-1,ki-1,0),0);
239 c.SetLabel(digarr.GetTrackID(kj-1,ki-1,1),1);
240 c.SetLabel(digarr.GetTrackID(kj-1,ki-1,2),2);
242 c.SetQ(bins[idx[k]].GetQ());
244 if (ki==1 || ki==npads || kj==1 || kj==kMAXZ-2) {
245 c.SetSigmaY2(c.GetSigmaY2()*25.);
246 c.SetSigmaZ2(c.GetSigmaZ2()*4.);
248 clrow->InsertCluster(&c); ncl++;
253 clrow->GetArray()->Clear();
260 Info("Digits2Cluster","Number of found clusters : %d",nclusters);