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];
66 for(Int_t i=0; i<fkSize-1; i++) fClustersTmp[i]=NULL;
69 //______________________________________________________________________
70 AliITSSortTrkl::AliITSSortTrkl(TClonesArray &tclo, Int_t n, Double_t cut, Double_t rcut):TObject(),
81 // Constructor based on a TClonesArray of AliStrLine
82 Int_t numtrack=tclo.GetEntriesFast();
84 AliFatal(Form("Insufficient number of tracks (%d )",numtrack));
87 TObject *member = tclo[0];
88 TString str(member->ClassName());
89 if(!(str.Contains("AliStrLine"))){
90 AliFatal(Form("Wrong type of class in input TClonesArray (%s )",str.Data()));
93 Int_t siz = numtrack*(numtrack-1)/2;
95 AliError(Form("fkSize is too small. It is %d and it should be %d",fkSize,siz));
97 fPairs = new AliITSTracklPairs* [fkSize];
98 fClustersTmp = new Int_t* [fkSize-1];
99 for(Int_t i=0; i<fkSize-1; i++) fClustersTmp[i]=NULL;
100 for(Int_t i=0;i<numtrack-1;i++){
101 AliStrLine *one = (AliStrLine*)tclo[i];
102 for(Int_t j=i+1;j<numtrack;j++){
103 AliStrLine *two = (AliStrLine*)tclo[j];
105 one->Cross(two,point);
106 Double_t dca = one->GetDCA(two);
107 if(dca>fCut)continue;
108 Double_t rad=TMath::Sqrt(point[0]*point[0]+point[1]*point[1]);
109 if(rad>fCoarseMaxRCut)continue;
110 AddPairs(i,j,dca,point);
115 //______________________________________________________________________
116 AliITSSortTrkl::~AliITSSortTrkl(){
119 for(Int_t i=0;i<fIndex;i++)delete fPairs[i];
124 for(Int_t i=0;i<fNoClus;i++)delete [] fClusters[i];
130 //______________________________________________________________________
131 void AliITSSortTrkl::DeleteClustersTmp(){
132 // fClustersTmp is deleted
134 for(Int_t i=0;i<fIndex-1;i++){
136 delete []fClustersTmp[i];
139 delete [] fClustersTmp;
144 //______________________________________________________________________
145 Int_t AliITSSortTrkl::AddPairs(Int_t t1, Int_t t2, Double_t dca, Double_t *coo){
146 // Add a tracklet pair at current position
147 fPairs[fIndex] = new AliITSTracklPairs(t1,t2,dca,coo);
148 // cout<<"Pair "<<fIndex<<" Tracklets "<<t1<<" and "<<t2<<". DCA= "<<dca<<" Crossing "<<coo[0]<<" "<<coo[1]<<" "<<coo[2]<<endl;
153 //______________________________________________________________________
154 Int_t AliITSSortTrkl::FindClusters(){
157 AliWarning(Form("fIndex = %d",fIndex));
161 fMark.ResetAllBits();
162 PrepareClustersTmp();
163 // cout<<"AliITSSortTrkl::FindClusters fkSize "<<fkSize<<"; fIndex "<<fIndex<<endl;
164 for(Int_t i=0; i<fIndex-1;i++){
165 Int_t *v=fClustersTmp[i];
166 AliDebug(25,Form("Starting clustering for pair number %d",i));
169 AliDebug(25,Form("Clusters starting from pair %d : %d",i,v[0]));
172 // arr will contain the labels of the tracks associated to
173 // the cluster of pairs starting from pair i.
174 Int_t *arr=FindLabels(v+1,2*(v[0]+1),dim);
177 cout<<"AliITSSortTrkl::FindClusters: Pairs involved \n";
178 for(Int_t j=1;j<=v[0]+1;j++){
180 if(j%10==0)cout<<endl;
183 cout<<"AliITSSortTrkl::FindClusters: Tracklets involved\n";
184 for(Int_t j=0;j<dim;j++){
186 if(j%10==0 && j>0)cout<<endl;
191 //In the following loop, all the pairs having
192 // one tracklet already associated to the cluster starting
193 // at pair i are marked, in order to be excluded from further
195 for(Int_t j=0;j<fIndex;j++){
196 if(fMark.TestBitNumber(j))continue;
197 for(Int_t k=0;k<dim;k++){
198 if(fPairs[j]->HasTrack(arr[k])){
199 fMark.SetBitNumber(j);
200 // cout<<"Marked pair "<<j<<" because has tracklet "<<arr[k]<<endl;
209 // The following method builds the array fClusters
214 //______________________________________________________________________
215 void AliITSSortTrkl::Cleanup(){
216 // empty arrays are eliminated, the others are sorted according
217 // to cluster multiplicity
218 AliDebug(25,Form("fIndex = %d",fIndex));
219 Int_t *siz = new Int_t[fIndex-1];
220 Int_t *index = new Int_t[fIndex-1];
222 for(Int_t i=0; i<fIndex-1;i++){
223 Int_t *v=fClustersTmp[i];
232 AliDebug(25,Form("fNoClus = %d",fNoClus));
233 TMath::Sort(fIndex-1,siz,index);
234 fClusters = new Int_t* [fNoClus];
235 fSize = new Int_t [fNoClus];
236 for(Int_t i=0;i<fNoClus;i++){
237 // cout<<"AliITSSortTrkl::Cleanup: Cluster number "<<i<<"; Index= "<<index[i]<<endl;
238 Int_t curind = index[i];
239 Int_t *v=fClustersTmp[curind];
240 fClusters[i] = new Int_t[v[0]+1];
242 // cout<<"AliITSSortTrkl::Cleanup: Size = "<<fSize[i]<<endl;
243 Int_t *vext=fClusters[i];
245 for(Int_t j=1;j<fSize[i];j++)vext[j]=v[j];
247 for(Int_t j=0;j<fSize[i];j++){
249 if(j%10 == 0 && j!=0)cout<<endl;
258 //______________________________________________________________________
259 Int_t* AliITSSortTrkl::GetTrackletsLab(Int_t index, Int_t& dim) const {
260 // Returns the tracklet labels corresponding to cluster index
261 // Calling code must take care of memory deallocation
262 AliDebug(25,Form("called with parameters %d %d",index,dim));
267 Int_t dimmax = 2*GetSizeOfCluster(index);
268 AliDebug(25,Form("dimmax = %d",dimmax));
273 Int_t *v = GetClusters(index);
274 return FindLabels(v,dimmax,dim);
277 //______________________________________________________________________
278 Int_t* AliITSSortTrkl::FindLabels(Int_t *v, Int_t dimmax, Int_t& dim) const {
279 // Returns the tracklet labels corresponding to te list of pairs
281 // Calling code must take care of memory deallocation
283 // cout<<"AliITSSortTrkl::Findlabels parameters "<<v<<" dimmax = "<<dimmax<<" dim "<<dim<<endl;
284 Int_t *arr = new Int_t [dimmax];
286 for(Int_t i=0; i<dimmax/2; i++){
287 AliITSTracklPairs *pai=GetPairsAt(v[i]);
288 arr[j++]=pai->GetTrack1();
289 // cout<<"AliITSSortTrkl::FindLabels - i="<<i<<" arr["<<j-1<<"]= "<<arr[j-1]<<endl;
290 arr[j++]=pai->GetTrack2();
291 // cout<<"AliITSSortTrkl::FindLabels arr["<<j-1<<"]= "<<arr[j-1]<<endl;
293 SortAndClean(dimmax,arr,dim);
296 //______________________________________________________________________
297 void AliITSSortTrkl::SortAndClean(Int_t numb, Int_t *arr, Int_t& numb2){
298 // Array arr (with numb elements) is sorted in ascending order.
299 // Then possible reoccurrences
300 // of elements are eliminated. numb2 is the number of remaining elements
303 // cout<<"AliITSSortTrkl::SortAndClean - Parameters: numb= "<<numb<<" numb2= "<<numb2<<endl;
305 Int_t* index = new Int_t[numb];
306 TMath::Sort(numb,arr,index,kFALSE);
307 Int_t* tmp = new Int_t[numb];
309 tmp[0] = arr[index[0]];
310 for(Int_t i=1;i<numb;i++){
311 if(arr[index[i]] != tmp[numb2]){
313 tmp[numb2]=arr[index[i]];
318 cout<<"AliITSSortTrkl::SortAndClean - numb2 = "<<numb2<<endl;
319 for(Int_t i=0;i<numb;i++){
322 cout<<"arr["<<i<<"]= "<<arr[i]<<endl;
333 //______________________________________________________________________
334 void AliITSSortTrkl::PrepareClustersTmp(){
335 // prepare arrays of clusters
336 for(Int_t i=0; i<fIndex-1;i++){
337 fClustersTmp[i] = new Int_t [fIndex+1];
338 Int_t *v = fClustersTmp[i];
340 for(Int_t j=1;j<fIndex+1;j++)v[j]=-1;
345 //______________________________________________________________________
346 void AliITSSortTrkl::Clustering(Int_t i,Int_t *v){
347 // recursive method to build up clusters starting from point i
348 AliDebug(25,Form("Clustering called for pair %d",i));
349 if(fMark.TestBitNumber(i)){
350 AliDebug(25,Form("Leaving Clustering for pair %d - nothing done",i));
353 AliITSTracklPairs *p1 = fPairs[i];
354 for(Int_t j=0;j<fIndex;j++){
356 if(fMark.TestBitNumber(j))continue;
357 AliITSTracklPairs *p2 = fPairs[j];
358 Double_t dist = p1->GetDistance(*p2);
359 // AliInfo(Form(" ******* i %d , j %d . Distance %g ",i,j,dist));
362 Bool_t already = kFALSE;
363 for(Int_t k=1;k<=dimclu;k++){
364 if(v[k]==j)already=kTRUE;
369 fMark.SetBitNumber(i);
370 AliDebug(25,Form("Marked pair %d - and call Clustering for pair %d",i,j));
373 fMark.SetBitNumber(j);
374 AliDebug(25,Form("Marked pair %d",j));
378 AliDebug(25,Form("Leaving Clustering for pair %d ",i));