1 /**************************************************************************
2 * Copyright(c) 2009-2010, 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 **************************************************************************/
16 #include<TClonesArray.h>
18 #include "AliStrLine.h"
19 #include "AliITSSortTrkl.h"
23 ////////////////////////////////////////////////////////////////////////
24 // Helper class for finding multiple primary vertices //
25 // To be used by AliITSVertexer3D //
26 // It is based on the association of pairs of tracklets //
27 // obtained by matching reconstructed points onthe first //
29 // Origin M. Masera masera@to.infn.it //
30 ////////////////////////////////////////////////////////////////////////
33 ClassImp(AliITSSortTrkl)
35 //______________________________________________________________________
36 AliITSSortTrkl::AliITSSortTrkl():TObject(),
48 // Default constructor
51 //______________________________________________________________________
52 AliITSSortTrkl::AliITSSortTrkl(Int_t n, Double_t cut):TObject(),
63 // Standard constructor
64 fPairs = new AliITSTracklPairs* [fkSize];
65 fClustersTmp = new Int_t* [fkSize-1];
68 //______________________________________________________________________
69 AliITSSortTrkl::AliITSSortTrkl(TClonesArray &tclo, Int_t n, Double_t cut, Double_t rcut):TObject(),
80 // Constructor based on a TClonesArray of AliStrLine
81 Int_t numtrack=tclo.GetEntriesFast();
83 AliFatal(Form("Insufficient number of tracks (%d )",numtrack));
86 TObject *member = tclo[0];
87 TString str(member->ClassName());
88 if(!(str.Contains("AliStrLine"))){
89 AliFatal(Form("Wrong type of class in input TClonesArray (%s )",str.Data()));
92 Int_t siz = numtrack*(numtrack-1)/2;
94 AliError(Form("fkSize is too small. It is %d and it should be %d",fkSize,siz));
96 fPairs = new AliITSTracklPairs* [fkSize];
97 fClustersTmp = new Int_t* [fkSize-1];
98 for(Int_t i=0;i<numtrack-1;i++){
99 AliStrLine *one = (AliStrLine*)tclo[i];
100 for(Int_t j=i+1;j<numtrack;j++){
101 AliStrLine *two = (AliStrLine*)tclo[j];
103 one->Cross(two,point);
104 Double_t dca = one->GetDCA(two);
105 if(dca>fCut)continue;
106 Double_t rad=TMath::Sqrt(point[0]*point[0]+point[1]*point[1]);
107 if(rad>fCoarseMaxRCut)continue;
108 AddPairs(i,j,dca,point);
113 //______________________________________________________________________
114 AliITSSortTrkl::~AliITSSortTrkl(){
117 for(Int_t i=0;i<fIndex;i++)delete fPairs[i];
122 for(Int_t i=0;i<fNoClus;i++)delete []fClusters[i];
128 //______________________________________________________________________
129 void AliITSSortTrkl::DeleteClustersTmp(){
130 // fClustersTmp is deleted
132 for(Int_t i=0;i<fIndex-1;i++)delete []fClustersTmp[i];
138 //______________________________________________________________________
139 Int_t AliITSSortTrkl::AddPairs(Int_t t1, Int_t t2, Double_t dca, Double_t *coo){
140 // Add a tracklet pair at current position
141 fPairs[fIndex] = new AliITSTracklPairs(t1,t2,dca,coo);
142 // cout<<"Pair "<<fIndex<<" Tracklets "<<t1<<" and "<<t2<<". DCA= "<<dca<<" Crossing "<<coo[0]<<" "<<coo[1]<<" "<<coo[2]<<endl;
147 //______________________________________________________________________
148 Int_t AliITSSortTrkl::FindClusters(){
150 fMark.ResetAllBits();
151 PrepareClustersTmp();
152 for(Int_t i=0; i<fIndex-1;i++){
153 Int_t *v=fClustersTmp[i];
156 AliInfo(Form("Clusters starting from pair %d : %d",i,v[0]));
159 Int_t *arr=FindLabels(v+1,2*(v[0]+1),dim);
160 cout<<"Pairs involved \n";
161 for(Int_t j=1;j<=v[0];j++){
163 if(j%10==0)cout<<endl;
166 cout<<"Tracklets involved\n";
167 for(Int_t j=0;j<dim;j++){
169 if(j%10==0 && j>0)cout<<endl;
172 for(Int_t j=0;j<fIndex;j++){
173 if(fMark.TestBitNumber(j))continue;
174 for(Int_t k=0;k<dim;k++){
175 if(fPairs[j]->HasTrack(arr[k])){
176 fMark.SetBitNumber(j);
177 // cout<<"Marked pair "<<j<<" because has tracklet "<<arr[k]<<endl;
189 //______________________________________________________________________
190 void AliITSSortTrkl::Cleanup(){
191 // empty arrays are eliminated, the others are sorted according
192 // to cluster multiplicity
193 Int_t *siz = new Int_t[fIndex-1];
194 Int_t *index = new Int_t[fIndex-1];
196 for(Int_t i=0; i<fIndex-1;i++){
197 Int_t *v=fClustersTmp[i];
206 TMath::Sort(fIndex-1,siz,index);
207 fClusters = new Int_t* [fNoClus];
208 fSize = new Int_t [fNoClus];
209 for(Int_t i=0;i<fNoClus;i++){
210 Int_t curind = index[i];
211 Int_t *v=fClustersTmp[curind];
212 fClusters[i] = new Int_t[v[0]+1];
214 Int_t *vext=fClusters[i];
216 for(Int_t j=1;j<fSize[i];j++)vext[j]=v[j];
222 //______________________________________________________________________
223 Int_t* AliITSSortTrkl::GetTrackletsLab(Int_t index, Int_t& dim) const {
224 // Returns the tracklet labels corresponding to cluster index
225 // Calling code must take care of memory deallocation
230 Int_t dimmax = 2*GetSizeOfCluster(index);
235 Int_t *v = GetClusters(index);
236 return FindLabels(v,dimmax,dim);
239 //______________________________________________________________________
240 Int_t* AliITSSortTrkl::FindLabels(Int_t *v, Int_t dimmax, Int_t& dim) const {
241 // Returns the tracklet labels corresponding to te list of pairs
243 // Calling code must take care of memory deallocation
244 Int_t *arr = new Int_t [dimmax];
246 for(Int_t i=0; i<dimmax/2; i++){
247 AliITSTracklPairs *pai=GetPairsAt(v[i]);
248 arr[j++]=pai->GetTrack1();
249 arr[j++]=pai->GetTrack2();
251 SortAndClean(dimmax,arr,dim);
254 //______________________________________________________________________
255 void AliITSSortTrkl::SortAndClean(Int_t numb, Int_t *arr, Int_t& numb2){
256 // Array arr (with numb elements) is sorted in ascending order.
257 // Then possible reoccurrences
258 // of elements are eliminated. numb2 is the number of remaining elements
261 Int_t* index = new Int_t[numb];
262 TMath::Sort(numb,arr,index,kFALSE);
263 Int_t* tmp = new Int_t[numb];
265 tmp[0] = arr[index[0]];
266 for(Int_t i=1;i<numb;i++){
267 if(arr[index[i]] != tmp[numb2]){
269 tmp[numb2]=arr[index[i]];
273 for(Int_t i=0;i<numb;i++){
285 //______________________________________________________________________
286 void AliITSSortTrkl::PrepareClustersTmp(){
287 // prepare arrays of clusters
288 for(Int_t i=0; i<fIndex-1;i++){
289 fClustersTmp[i] = new Int_t [fIndex-i];
290 Int_t *v = fClustersTmp[i];
292 for(Int_t j=1;j<fIndex-i;j++)v[j]=-1;
296 //______________________________________________________________________
297 void AliITSSortTrkl::Clustering(Int_t i,Int_t *v){
298 // recursive method to build up clusters starting from point i
299 if(fMark.TestBitNumber(i))return;
300 AliITSTracklPairs *p1 = fPairs[i];
301 for(Int_t j=i+1;j<fIndex;j++){
302 if(fMark.TestBitNumber(j))continue;
303 AliITSTracklPairs *p2 = fPairs[j];
304 Double_t dist = p1->GetDistance(*p2);
305 // AliInfo(Form(" ******* i %d , j %d . Distance %g ",i,j,dist));
308 Bool_t already = kFALSE;
309 for(Int_t k=1;k<=dimclu;k++){
310 if(v[k]==j)already=kTRUE;
315 fMark.SetBitNumber(j);
316 fMark.SetBitNumber(i);