]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCclusterer.cxx
Updated from the TPC-PreRelease branch
[u/mrichter/AliRoot.git] / TPC / AliTPCclusterer.cxx
CommitLineData
73042f01 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
16/*
17$Log$
18Revision 1.1.2.1 2000/06/25 08:53:55 kowal2
19Splitted from AliTPCtracking
20
21*/
22
23//-------------------------------------------------------
24// Implementation of the TPC clusterer
25//
26// Origin: Jouri Belikov, CERN, Jouri.Belikov@cern.ch
27//-------------------------------------------------------
28
29#include "AliTPCclusterer.h"
30#include "AliTPCcluster.h"
31#include <TObjArray.h>
32#include <TFile.h>
33#include "AliTPCClustersArray.h"
34#include "AliTPCClustersRow.h"
35#include "AliDigits.h"
36#include "AliSimDigits.h"
37#include "AliTPCParam.h"
38#include <iostream.h>
39
40void AliTPCclusterer::FindPeaks(Int_t k,Int_t max,
41AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
42 //find local maxima
43 if (n<31)
44 if (IsMaximum(k,max,b)) {
45 idx[n]=k; msk[n]=(2<<n);
46 n++;
47 }
48 b[k].SetMask(0);
49 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
50 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
51 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
52 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
53}
54
55void AliTPCclusterer::MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
56 //mark this peak
57 UShort_t q=bins[k].GetQ();
58
59 bins[k].SetMask(bins[k].GetMask()|m);
60
61 if (bins[k-max].GetQ() <= q)
62 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
63 if (bins[k-1 ].GetQ() <= q)
64 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
65 if (bins[k+max].GetQ() <= q)
66 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
67 if (bins[k+1 ].GetQ() <= q)
68 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
69}
70
71void AliTPCclusterer::MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,
72AliTPCcluster &c) {
73 //make cluster using digits of this peak
74 Float_t q=(Float_t)bins[k].GetQ();
75 Int_t i=k/max, j=k-i*max;
76
77 c.SetQ(c.GetQ()+q);
78 c.SetY(c.GetY()+i*q);
79 c.SetZ(c.GetZ()+j*q);
80 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
81 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
82
83 bins[k].SetMask(0xFFFFFFFE);
84
85 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
86 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
87 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
88 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);
89}
90
91//_____________________________________________________________________________
92void AliTPCclusterer::Digits2Clusters(const AliTPCParam *par, TFile *of)
93{
94 //-----------------------------------------------------------------
95 // This is a simple cluster finder.
96 //-----------------------------------------------------------------
97 TDirectory *savedir=gDirectory;
98
99 if (!of->IsOpen()) {
100 cerr<<"AliTPC::Digits2Clusters(): output file not open !\n";
101 return;
102 }
103
104 const Int_t kMAXZ=par->GetMaxTBin()+2;
105
106 TTree *t = (TTree *)gDirectory->Get("TreeD_75x40_100x60");
107 AliSimDigits digarr, *dummy=&digarr;
108 t->GetBranch("Segment")->SetAddress(&dummy);
109 Stat_t nentries = t->GetEntries();
110
111 of->cd();
112
113 ((AliTPCParam*)par)->Write(par->GetTitle());
114 AliTPCClustersArray carray;
115 carray.Setup(par);
116 carray.SetClusterType("AliTPCcluster");
117 carray.MakeTree();
118
119 Int_t nclusters=0;
120
121 for (Int_t n=0; n<nentries; n++) {
122 t->GetEvent(n);
123 Int_t sec, row;
124 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
125 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
126 continue;
127 }
128
129 AliTPCClustersRow *clrow=carray.CreateRow(sec,row);
130
131 Float_t rx=par->GetPadRowRadii(sec,row);
132
133 Int_t npads, sign;
134 {
135 const Int_t kNIS=par->GetNInnerSector(), kNOS=par->GetNOuterSector();
136 if (sec < kNIS) {
137 npads = par->GetNPadsLow(row);
138 sign = (sec < kNIS/2) ? 1 : -1;
139 } else {
140 npads = par->GetNPadsUp(row);
141 sign = ((sec-kNIS) < kNOS/2) ? 1 : -1;
142 }
143 }
144
145 const Int_t kMAXBIN=kMAXZ*(npads+2);
146 AliBin *bins=new AliBin[kMAXBIN];
147 for (Int_t ii=0;ii<kMAXBIN;ii++) {
148 bins[ii].SetQ(0); bins[ii].SetMask(0xFFFFFFFE);
149 }
150
151 digarr.First();
152 do {
153 Short_t dig=digarr.CurrentDigit();
154 if (dig<=par->GetZeroSup()) continue;
155 Int_t j=digarr.CurrentRow()+1, i=digarr.CurrentColumn()+1;
156 bins[i*kMAXZ+j].SetQ(dig);
157 bins[i*kMAXZ+j].SetMask(1);
158 } while (digarr.Next());
159
160 Int_t ncl=0;
161 for (Int_t i=0; i<kMAXBIN; i++) {
162 if ((bins[i].GetMask()&1) == 0) continue;
163 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
164 FindPeaks(i, kMAXZ, bins, idx, msk, npeaks);
165
166 if (npeaks>30) continue;
167
168 Int_t k,l;
169 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
170 if (idx[k] < 0) continue; //this peak is already removed
171 for (l=k+1; l<npeaks; l++) {
172 if (idx[l] < 0) continue; //this peak is already removed
173 Int_t ki=idx[k]/kMAXZ, kj=idx[k] - ki*kMAXZ;
174 Int_t li=idx[l]/kMAXZ, lj=idx[l] - li*kMAXZ;
175 Int_t di=TMath::Abs(ki - li);
176 Int_t dj=TMath::Abs(kj - lj);
177 if (di>1 || dj>1) continue;
178 if (bins[idx[k]].GetQ() > bins[idx[l]].GetQ()) {
179 msk[l]=msk[k];
180 idx[l]*=-1;
181 } else {
182 msk[k]=msk[l];
183 idx[k]*=-1;
184 break;
185 }
186 }
187 }
188
189 for (k=0; k<npeaks; k++) {
190 MarkPeak(TMath::Abs(idx[k]), kMAXZ, bins, msk[k]);
191 }
192
193 for (k=0; k<npeaks; k++) {
194 if (idx[k] < 0) continue; //removed peak
195 AliTPCcluster c;
196 MakeCluster(idx[k], kMAXZ, bins, msk[k], c);
197 if (c.GetQ() < 5) continue; //noise cluster
198 c.SetY(c.GetY()/c.GetQ());
199 c.SetZ(c.GetZ()/c.GetQ());
200
201 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
202 Float_t w=par->GetPadPitchWidth(sec);
203 c.SetSigmaY2((s2 + 1./12.)*w*w);
204 if (s2 != 0.) {
205 c.SetSigmaY2(c.GetSigmaY2()*0.108);
206 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
207 }
208
209 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
210 w=par->GetZWidth();
211 c.SetSigmaZ2((s2 + 1./12.)*w*w);
212 if (s2 != 0.) {
213 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
214 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
215 }
216
217 c.SetY((c.GetY() - 0.5 - 0.5*npads)*par->GetPadPitchWidth(sec));
218 c.SetZ(par->GetZWidth()*(c.GetZ()-1));
219 c.SetZ(c.GetZ() - 3.*par->GetZSigma()); // PASA delay
220 c.SetZ(sign*(par->GetZLength() - c.GetZ()));
221
222 if (rx<230./250.*TMath::Abs(c.GetZ())) continue;
223
224 Int_t ki=idx[k]/kMAXZ, kj=idx[k] - ki*kMAXZ;
225 c.SetLabel(digarr.GetTrackID(kj-1,ki-1,0),0);
226 c.SetLabel(digarr.GetTrackID(kj-1,ki-1,1),1);
227 c.SetLabel(digarr.GetTrackID(kj-1,ki-1,2),2);
228
229 c.SetQ(bins[idx[k]].GetQ());
230
231 if (ki==1 || ki==npads || kj==1 || kj==kMAXZ-2) {
232 c.SetSigmaY2(c.GetSigmaY2()*25.);
233 c.SetSigmaZ2(c.GetSigmaZ2()*4.);
234 }
235 clrow->InsertCluster(&c); ncl++;
236 }
237 }
238 carray.StoreRow(sec,row);
239 carray.ClearRow(sec,row);
240
241 cerr<<"sector, row, compressed digits, clusters: "
242 <<sec<<' '<<row<<' '<<digarr.GetSize()<<' '<<ncl<<" \r";
243
244 nclusters+=ncl;
245
246 delete[] bins;
247 }
248
249 cerr<<"Number of found clusters : "<<nclusters<<" \n";
250
251 carray.GetTree()->Write();
252 savedir->cd();
253}
254