]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSclusterTable.cxx
Primary vertex reconstruction and standalone ITS tracking in the reconstruction chain
[u/mrichter/AliRoot.git] / ITS / AliITSclusterTable.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, 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 // Class used to simplify some operations with clusters.                 //
18 // -Function FillArray fills an array wich contains, for each            //
19 //  ITS module, an array with the indices of all the clusters detected   //
20 //  by the module. The indices correspond to the cluster indices in class// 
21 //  AliITSlayer of AliITStrackerV2.                                      //
22 //  This function is used in AliITStrackerSA::FindTracks.                // 
23 // -Function FillArrayLabel fills an array wich contains, for each       //
24 //  particle label, and for each layer, the information on clusters:     //
25 //  0 if there is no cluster, 1 if there is a cluster with this label.   //
26 //  This function is used to define trackable tracks.                    //
27 // -Function FillArrayCoorAngles fills arrays wich contains, for each    //
28 //  layer, the global coordinates, errors on x,y,z and angles lambda     //
29 //  and phi for each cluster                                             //
30 ///////////////////////////////////////////////////////////////////////////
31
32
33 #include "AliITSclusterTable.h"
34 #include "AliITSclusterV2.h"
35 #include "AliITSgeom.h"
36 #include "AliITStrackerSA.h"
37 #include<TBranch.h>
38 #include<TClonesArray.h>
39 #include<TTree.h>
40 ClassImp(AliITSclusterTable)
41
42 //__________________________________________________________
43 AliITSclusterTable::AliITSclusterTable(){
44 // Default constructor
45   fDet=0;
46   fNCl = 0;
47   fLbl=0;
48   fGeom = 0;
49   fTracker = 0;
50   fPhiList = 0; 
51   fLambdaList = 0;
52   fXList = 0;
53   fYList =0;
54   fZList =0;
55   fSxList = 0;
56   fSyList =0;
57   fSzList =0;
58   for(Int_t i=0;i<3;i++){fPrimaryVertex[i]=0;}
59 }
60
61 //__________________________________________________________
62 AliITSclusterTable::AliITSclusterTable(AliITSgeom* geom, AliITStrackerSA* tracker,Double_t* primaryVertex) {
63 // Standard constructor
64   fDet=0;
65   Int_t nm = geom->GetIndexMax();
66   fNCl = new Int_t[nm];
67   for(Int_t i=0;i<nm;i++){fNCl[i]=0;}
68   fLbl=0;
69   fGeom = geom;
70   fTracker = tracker;
71   for(Int_t i=0;i<3;i++){fPrimaryVertex[i]=primaryVertex[i];}
72   fPhiList = 0;
73   fLambdaList = 0;
74   fXList = 0;
75   fYList = 0;
76   fZList =0;
77   fSxList = 0;
78   fSyList =0;
79   fSzList =0;
80 }
81
82 //______________________________________________________________________
83 AliITSclusterTable::AliITSclusterTable(const AliITSclusterTable &tab) : 
84                     TObject(tab) {
85   // Copy constructor
86   // Copies are not allowed. The method is protected to avoid misuse.
87   Error("AliITSclusterTable","Copy constructor not allowed\n");
88 }
89
90 //______________________________________________________________________
91 AliITSclusterTable& AliITSclusterTable::operator=(const 
92                     AliITSclusterTable& /* tab */){
93   // Assignment operator
94   // Assignment is not allowed. The method is protected to avoid misuse.
95   Error("= operator","Assignment operator not allowed\n");
96   return *this;
97 }
98
99 //__________________________________________________________
100 AliITSclusterTable::~AliITSclusterTable(){
101 // Destructor
102   Int_t nm = fGeom->GetIndexMax();
103   if(fDet){
104     for (Int_t i=0; i<nm; i++){
105       delete fDet[i];
106     }
107     delete[] fDet;
108   }
109   if (fLbl)delete [] fLbl; // memory leak!
110   if (fNCl)delete [] fNCl;
111   for (Int_t i = 0; i < fGeom->GetNlayers(); i++) {
112     if (fPhiList) delete fPhiList[i];
113     if (fLambdaList) delete fLambdaList[i];
114     if (fXList) delete fXList[i];
115     if (fYList) delete fYList[i];
116     if (fZList) delete fZList[i];
117     if (fSxList) delete fSxList[i];
118     if (fSyList) delete fSyList[i];
119     if (fSzList) delete fSzList[i];
120   }
121   if (fPhiList) delete[] fPhiList;
122   if (fLambdaList) delete[] fLambdaList;
123   if (fXList) delete[] fXList;
124   if (fYList) delete[] fYList;
125   if (fZList) delete[] fZList;
126   if (fSxList) delete[] fSxList;
127   if (fSyList) delete[] fSyList;
128   if (fSzList) delete[] fSzList;
129 }
130
131 //__________________________________________________________
132
133 void AliITSclusterTable::FillArray(TTree* clusterTree){
134   
135   //
136   Int_t nm = fGeom->GetIndexMax();
137   fDet = new TArrayI*[nm];
138
139   TArrayI** vect = new TArrayI*[fGeom->GetNlayers()];
140   
141   Int_t * firstmod = new Int_t[fGeom->GetNlayers()+1];
142   firstmod[fGeom->GetNlayers()]=fGeom->GetIndexMax();  // upper limit
143   for(Int_t nlayer=0;nlayer<fGeom->GetNlayers();nlayer++){
144     firstmod[nlayer] = fGeom->GetModuleIndex(nlayer+1,1,1);
145     Int_t ncl = fTracker->GetNumberOfClustersLayer(nlayer);
146     vect[nlayer]=new TArrayI(ncl); 
147     for(Int_t j=0;j<ncl;j++){
148       AliITSclusterV2* cl = fTracker->GetClusterLayer(nlayer,j);
149       vect[nlayer]->AddAt(cl->GetDetectorIndex()+firstmod[nlayer],j);
150     }
151   }
152     
153   TBranch *brancht=(TBranch*)clusterTree->GetBranch("Clusters");
154   if(!brancht) Warning("FillArray","No cluster branch");
155   TClonesArray* clus = new TClonesArray("AliITSclusterV2",10000);
156   brancht->SetAddress(&clus);
157  
158   
159   for(Int_t mod=0;mod<nm;mod++){
160     Int_t nc=0;
161     clusterTree->GetEvent(mod);
162     Int_t ncl = clus->GetEntries();
163     fDet[mod] = new TArrayI(ncl);
164     fNCl[mod]= ncl;
165     Int_t nlr = FindIndex(fGeom->GetNlayers(),firstmod,mod);
166     if(nlr<0){
167       Fatal("FillArray","Wrong module number %d . Limits: %d , %d",mod,firstmod[0],firstmod[fGeom->GetNlayers()+1]);
168       exit(1);
169     }
170     else {
171       for(Int_t n=0;n<vect[nlr]->GetSize();n++){
172         Int_t mm=vect[nlr]->At(n);
173         if(mm==mod) {fDet[mod]->AddAt(n,nc); nc+=1; }
174       }
175     }
176   }
177
178
179   clus->Delete();
180   delete clus;
181   for(Int_t n=0;n<fGeom->GetNlayers();n++)delete vect[n];
182   delete [] vect;
183   delete [] firstmod;
184 }
185
186 //_________________________________________________________________
187 void AliITSclusterTable::FillArrayLabel(Int_t numberofparticles){
188   //
189
190
191   fLbl = new TArrayI*[numberofparticles];
192   const Int_t knm =fGeom->GetNlayers();
193   for(Int_t nlab=0;nlab<numberofparticles;nlab++){
194     fLbl[nlab] = new TArrayI(knm);
195     Int_t * nn = new Int_t[knm]; 
196     for(Int_t i=0;i<knm;i++)nn[i]=0;
197     for(Int_t nlayer=0;nlayer<knm;nlayer++){
198       Int_t ncl = fTracker->GetNumberOfClustersLayer(nlayer);
199       while(ncl--){
200         AliITSclusterV2* cl = fTracker->GetClusterLayer(nlayer,ncl);
201         if(cl->IsUsed()==1) continue;
202         if(cl->GetLabel(0)==nlab || cl->GetLabel(1)==nlab || cl->GetLabel(2)==nlab){
203           nn[nlayer]+=1;
204           cl->Use();
205           break;
206         }
207       }     
208       fLbl[nlab]->AddAt(nn[nlayer],nlayer);
209     }
210     delete [] nn;
211   }
212
213 }
214
215 //_______________________________________________________________
216 Int_t AliITSclusterTable::ThisParticleIsTrackable(Int_t label,Int_t numberofpoints){
217
218   //Returns 1 if particle with label "label" is trackable. 
219    
220   Int_t nb=0;
221   for(Int_t i=0;i<fGeom->GetNlayers();i++){
222     Int_t ncl = fLbl[label]->At(i);
223     if(ncl>0) nb++;
224   }
225   if(nb>=numberofpoints) return 1;
226   else return 0;
227
228 }
229
230 //_______________________________________________________________
231 Int_t AliITSclusterTable::FindIndex(Int_t ndim, Int_t *ptr, Int_t value){
232 // ptr[ndim+1] is an array of integers
233 // ndim is its dimension minus 1
234 // value is a number such as:  ptr[0]<=value < ptr[ndim]
235 // if ptr[i]<=value<ptr[i+1] the index i is returned;  -1 if out of bounds
236   Int_t retval = -1;
237   for(Int_t k=0;k<ndim;k++){
238     if(value>=ptr[k] && value <ptr[k+1]){
239       retval = k;
240       break;
241     }
242   }
243   return retval;
244 }
245
246 void AliITSclusterTable::FillArrayCoorAngles(){
247   //Fill arrays with phi,lambda and indices of clusters for each layer
248   Info("FillArrayCoorAngles","Filling Array...");
249
250   fPhiList = new TArrayD*[fGeom->GetNlayers()];
251   fLambdaList = new TArrayD*[fGeom->GetNlayers()];
252   fXList = new TArrayD*[fGeom->GetNlayers()];
253   fYList = new TArrayD*[fGeom->GetNlayers()];
254   fZList = new TArrayD*[fGeom->GetNlayers()];
255   fSxList = new TArrayD*[fGeom->GetNlayers()];
256   fSyList = new TArrayD*[fGeom->GetNlayers()];
257   fSzList = new TArrayD*[fGeom->GetNlayers()];
258
259   Int_t * firstmod = new Int_t[fGeom->GetNlayers()+1];
260   firstmod[fGeom->GetNlayers()]=fGeom->GetIndexMax();  // upper limit
261
262   for(Int_t nlay=0;nlay<fGeom->GetNlayers();nlay++){
263     firstmod[nlay] = fGeom->GetModuleIndex(nlay+1,1,1);
264     Int_t ncl = fTracker->GetNumberOfClustersLayer(nlay);
265     fPhiList[nlay] = new TArrayD(ncl);
266     fLambdaList[nlay]=new TArrayD(ncl);
267     fXList[nlay]=new TArrayD(ncl);
268     fYList[nlay]=new TArrayD(ncl);
269     fZList[nlay]=new TArrayD(ncl);
270     fSxList[nlay]=new TArrayD(ncl);
271     fSyList[nlay]=new TArrayD(ncl);
272     fSzList[nlay]=new TArrayD(ncl);
273
274     for(Int_t j=0;j<ncl;j++){
275       AliITSclusterV2* cl = fTracker->GetClusterLayer(nlay,j);
276       Double_t phi=0;Double_t lambda=0;
277       Double_t x=0;Double_t y=0;Double_t z=0;
278       Double_t sx=0;Double_t sy=0;Double_t sz=0;
279       Int_t module = cl->GetDetectorIndex()+firstmod[nlay];
280       GetCoorAngles(cl,module,phi,lambda,x,y,z);
281       GetCoorErrors(cl,module,sx,sy,sz);
282       fPhiList[nlay]->AddAt(phi,j);
283       fLambdaList[nlay]->AddAt(lambda,j);
284       fXList[nlay]->AddAt(x,j);
285       fYList[nlay]->AddAt(y,j);
286       fZList[nlay]->AddAt(z,j);
287       fSxList[nlay]->AddAt(sx,j);
288       fSyList[nlay]->AddAt(sy,j);
289       fSzList[nlay]->AddAt(sz,j);
290       
291     }
292     
293   }
294   
295   delete [] firstmod;
296 }
297
298 void AliITSclusterTable::GetCoorAngles(AliITSclusterV2* cl,Int_t module,Double_t &phi,Double_t &lambda, Double_t &x, Double_t &y,Double_t &z){
299   //Returns values of phi (azimuthal) and lambda angles for a given cluster
300   
301   Double_t rot[9];     fGeom->GetRotMatrix(module,rot);
302   Int_t lay,lad,det; fGeom->GetModuleId(module,lay,lad,det);
303   Float_t tx,ty,tz;  fGeom->GetTrans(lay,lad,det,tx,ty,tz);     
304
305   Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
306   Double_t phi1=TMath::Pi()/2+alpha;
307   if (lay==1) phi1+=TMath::Pi();
308
309   Double_t cp=TMath::Cos(phi1), sp=TMath::Sin(phi1);
310   Double_t r=tx*cp+ty*sp;
311
312   x= r*cp - cl->GetY()*sp;
313   y= r*sp + cl->GetY()*cp;
314   z=cl->GetZ();
315   
316   phi=TMath::ATan2(y,x);
317   lambda=TMath::ATan2(z-fPrimaryVertex[2],TMath::Sqrt((x-fPrimaryVertex[0])*(x-fPrimaryVertex[0])+(y-fPrimaryVertex[1])*(y-fPrimaryVertex[1])));
318 }
319
320 void AliITSclusterTable::GetCoorErrors(AliITSclusterV2* cl, Int_t module,Double_t &sx,Double_t &sy, Double_t &sz){
321
322   //returns x,y,z of cluster in global coordinates
323
324   Double_t rot[9];     fGeom->GetRotMatrix(module,rot);
325   Int_t lay,lad,det; fGeom->GetModuleId(module,lay,lad,det);
326  
327   Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
328   Double_t phi=TMath::Pi()/2+alpha;
329   if (lay==1) phi+=TMath::Pi();
330
331   Double_t cp=TMath::Cos(phi), sp=TMath::Sin(phi);
332
333  
334   sx = TMath::Sqrt(sp*sp*cl->GetSigmaY2());
335   sy = TMath::Sqrt(cp*cp*cl->GetSigmaY2());
336   sz = TMath::Sqrt(cl->GetSigmaZ2());
337
338 }