]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITStrackerSA.cxx
Fix import of track-references. Apparently they are now stored in a
[u/mrichter/AliRoot.git] / ITS / AliITStrackerSA.cxx
CommitLineData
13918578 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
bf6adc12 16/* $Id$ */
17
13918578 18////////////////////////////////////////////////////
19// Stand alone tracker class //
20// Origin: Elisabetta Crescio //
21// e-mail: crescio@to.infn.it //
22// tracks are saved as AliITStrackV2 objects //
23////////////////////////////////////////////////////
24
aa4b78e1 25#include <stdlib.h>
bf6adc12 26
27#include <TArrayI.h>
13918578 28#include <TBranch.h>
13918578 29#include <TObjArray.h>
30#include <TTree.h>
bf6adc12 31
af885e0f 32#include "AliESDEvent.h"
bf6adc12 33#include "AliESDVertex.h"
34#include "AliESDtrack.h"
bf6adc12 35#include "AliITSVertexer.h"
13918578 36#include "AliITSclusterTable.h"
00a7cc50 37#include "AliITSRecPoint.h"
cc088660 38#include "AliITSgeomTGeo.h"
13918578 39#include "AliITStrackSA.h"
bf6adc12 40#include "AliITStrackerSA.h"
e340bb86 41#include "AliITSReconstructor.h"
bf6adc12 42#include "AliRun.h"
13918578 43
44ClassImp(AliITStrackerSA)
45
46//____________________________________________________________________________
e399f961 47AliITStrackerSA::AliITStrackerSA():AliITStrackerMI(),
48fPhiEstimate(0),
1966f03c 49fITSStandAlone(0),
e399f961 50fLambdac(0),
51fPhic(0),
52fCoef1(0),
53fCoef2(0),
54fCoef3(0),
55fNloop(0),
56fPhiWin(0),
57fLambdaWin(0),
58fVert(0),
59fVertexer(0),
e399f961 60fListOfTracks(0),
61fITSclusters(0),
62fSixPoints(0),
b8ed1a92 63fOuterStartLayer(0),
e399f961 64fCluLayer(0),
65fCluCoord(0){
13918578 66 // Default constructor
67 Init();
627b6db6 68
13918578 69}
2257f27e 70//____________________________________________________________________________
cc088660 71AliITStrackerSA::AliITStrackerSA(const Char_t *geom):AliITStrackerMI(0),
e399f961 72fPhiEstimate(0),
1966f03c 73fITSStandAlone(0),
e399f961 74fLambdac(0),
75fPhic(0),
76fCoef1(0),
77fCoef2(0),
78fCoef3(0),
79fNloop(0),
80fPhiWin(0),
81fLambdaWin(0),
82fVert(0),
83fVertexer(0),
e399f961 84fListOfTracks(0),
85fITSclusters(0),
86fSixPoints(0),
b8ed1a92 87fOuterStartLayer(0),
e399f961 88fCluLayer(0),
89fCluCoord(0)
2257f27e 90{
91 // Standard constructor (Vertex is known and passed to this obj.)
cc088660 92 if (geom) {
93 AliWarning("\"geom\" is actually a dummy argument !");
94 }
95
2257f27e 96 Init();
97 fVert = 0;
627b6db6 98
2257f27e 99}
100
13918578 101//____________________________________________________________________________
cc088660 102AliITStrackerSA::AliITStrackerSA(const Char_t *geom, AliESDVertex *vert):AliITStrackerMI(0),
e399f961 103fPhiEstimate(0),
1966f03c 104fITSStandAlone(0),
e399f961 105fLambdac(0),
106fPhic(0),
107fCoef1(0),
108fCoef2(0),
109fCoef3(0),
110fNloop(0),
111fPhiWin(0),
112fLambdaWin(0),
113fVert(vert),
114fVertexer(0),
e399f961 115fListOfTracks(0),
116fITSclusters(0),
117fSixPoints(0),
b8ed1a92 118fOuterStartLayer(0),
e399f961 119fCluLayer(0),
1966f03c 120fCluCoord(0)
13918578 121{
122 // Standard constructor (Vertex is known and passed to this obj.)
cc088660 123 if (geom) {
124 AliWarning("\"geom\" is actually a dummy argument !");
125 }
13918578 126 Init();
627b6db6 127
13918578 128}
129
13918578 130//____________________________________________________________________________
cc088660 131AliITStrackerSA::AliITStrackerSA(const Char_t *geom, AliITSVertexer *vertexer):AliITStrackerMI(0),
e399f961 132fPhiEstimate(0),
1966f03c 133fITSStandAlone(0),
e399f961 134fLambdac(0),
135fPhic(0),
136fCoef1(0),
137fCoef2(0),
138fCoef3(0),
139fNloop(0),
140fPhiWin(0),
141fLambdaWin(0),
142fVert(),
143fVertexer(vertexer),
e399f961 144fListOfTracks(0),
145fITSclusters(0),
146fSixPoints(0),
b8ed1a92 147fOuterStartLayer(0),
e399f961 148fCluLayer(0),
1966f03c 149fCluCoord(0)
13918578 150{
151 // Standard constructor (Vertex is unknown - vertexer is passed to this obj)
cc088660 152 if (geom) {
153 AliWarning("\"geom\" is actually a dummy argument !");
154 }
13918578 155 Init();
156 fVertexer = vertexer;
627b6db6 157
13918578 158}
159
160//____________________________________________________________________________
e399f961 161AliITStrackerSA::AliITStrackerSA(const AliITStrackerSA& tracker):AliITStrackerMI(),
162fPhiEstimate(tracker.fPhiEstimate),
1966f03c 163fITSStandAlone(tracker.fITSStandAlone),
e399f961 164fLambdac(tracker.fLambdac),
165fPhic(tracker.fPhic),
166fCoef1(tracker.fCoef1),
167fCoef2(tracker.fCoef2),
168fCoef3(tracker.fCoef3),
169fNloop(tracker.fNloop),
170fPhiWin(tracker.fPhiWin),
171fLambdaWin(tracker.fLambdaWin),
172fVert(tracker.fVert),
173fVertexer(tracker.fVertexer),
e399f961 174fListOfTracks(tracker.fListOfTracks),
175fITSclusters(tracker.fITSclusters),
176fSixPoints(tracker.fSixPoints),
b8ed1a92 177fOuterStartLayer(tracker.fOuterStartLayer),
e399f961 178fCluLayer(tracker.fCluLayer),
179fCluCoord(tracker.fCluCoord) {
13918578 180 // Copy constructor
13918578 181 for(Int_t i=0;i<2;i++){
182 fPoint1[i]=tracker.fPoint1[i];
183 fPoint2[i]=tracker.fPoint2[i];
184 fPoint3[i]=tracker.fPoint3[i];
185 fPointc[i]=tracker.fPointc[i];
186 }
13918578 187 if(tracker.fVertexer && tracker.fVert){
d681bb2d 188 fVert = new AliESDVertex(*tracker.fVert);
13918578 189 }
190 else {
191 fVert = tracker.fVert;
192 }
cc088660 193 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
7e5bf5af 194 fCluLayer[i] = tracker.fCluLayer[i];
195 fCluCoord[i] = tracker.fCluCoord[i];
196 }
13918578 197}
7d62fb64 198//______________________________________________________________________
e399f961 199AliITStrackerSA& AliITStrackerSA::operator=(const AliITStrackerSA& source){
200 // Assignment operator.
201 this->~AliITStrackerSA();
202 new(this) AliITStrackerSA(source);
203 return *this;
204
7d62fb64 205}
13918578 206
207//____________________________________________________________________________
208AliITStrackerSA::~AliITStrackerSA(){
209 // destructor
d681bb2d 210 // if fVertexer is not null, the AliESDVertex obj. is owned by this class
13918578 211 // and is deleted here
212 if(fVertexer){
213 if(fVert)delete fVert;
214 }
215 fVert = 0;
216 fVertexer = 0;
7e5bf5af 217
13918578 218 if(fPhiWin)delete []fPhiWin;
219 if(fLambdaWin)delete []fLambdaWin;
4e05ab9a 220 fListOfTracks->Delete();
adda6c2b 221 delete fListOfTracks;
7e5bf5af 222 if(fCluLayer){
cc088660 223 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
7e5bf5af 224 if(fCluLayer[i]){
225 fCluLayer[i]->Delete();
226 delete fCluLayer[i];
227 }
228 }
229 delete [] fCluLayer;
230 }
231 if(fCluCoord){
cc088660 232 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
7e5bf5af 233 if(fCluCoord[i]){
234 fCluCoord[i]->Delete();
235 delete fCluCoord[i];
236 }
237 }
238 delete [] fCluCoord;
627b6db6 239 }
7e5bf5af 240
7e5bf5af 241}
13918578 242
1966f03c 243//____________________________________________________________________________
af885e0f 244Int_t AliITStrackerSA::Clusters2Tracks(AliESDEvent *event){
1966f03c 245// This method is used to find and fit the tracks. By default the corresponding
246// method in the parent class is invoked. In this way a combined tracking
247// TPC+ITS is performed. If the flag fITSStandAlone is true, the tracking
248// is done in the ITS only. In the standard reconstruction chain this option
249// can be set via AliReconstruction::SetOption("ITS","onlyITS")
250 Int_t rc=0;
251 if(!fITSStandAlone){
252 rc=AliITStrackerMI::Clusters2Tracks(event);
253 }
254 else {
255 AliDebug(1,"Stand Alone flag set: doing tracking in ITS alone\n");
256 }
257 if(!rc) rc=FindTracks(event);
258 return rc;
259}
260
13918578 261//____________________________________________________________________________
262void AliITStrackerSA::Init(){
263 // Reset all data members
264 fPhiEstimate=0;
265 for(Int_t i=0;i<3;i++){fPoint1[i]=0;fPoint2[i]=0;fPoint3[i]=0;}
266 fLambdac=0;
267 fPhic=0;
268 fCoef1=0;
269 fCoef2=0;
270 fCoef3=0;
271 fPointc[0]=0;
272 fPointc[1]=0;
273 fVert = 0;
274 fVertexer = 0;
5b4dedce 275 Int_t nLoops=AliITSReconstructor::GetRecoParam()->GetNLoopsSA();
276 if(nLoops==33){
277 SetFixedWindowSizes();
278 }else{
279 Double_t phimin=AliITSReconstructor::GetRecoParam()->GetMinPhiSA();
280 Double_t phimax=AliITSReconstructor::GetRecoParam()->GetMaxPhiSA();
281 Double_t lambmin=AliITSReconstructor::GetRecoParam()->GetMinLambdaSA();
282 Double_t lambmax=AliITSReconstructor::GetRecoParam()->GetMaxLambdaSA();
283 SetCalculatedWindowSizes(nLoops,phimin,phimax,lambmin,lambmax);
284 }
2257f27e 285 fITSclusters = 0;
286 SetSixPoints();
b8ed1a92 287 SetOuterStartLayer(0);
1966f03c 288 SetSAFlag(kFALSE);
4e05ab9a 289 fListOfTracks=new TObjArray(0,0);
7e5bf5af 290 fCluLayer = 0;
291 fCluCoord = 0;
627b6db6 292 }
13918578 293//_______________________________________________________________________
294void AliITStrackerSA::ResetForFinding(){
295 // Reset data members used in all loops during track finding
296 fPhiEstimate=0;
297 for(Int_t i=0;i<3;i++){fPoint1[i]=0;fPoint2[i]=0;fPoint3[i]=0;}
298 fLambdac=0;
299 fPhic=0;
300 fCoef1=0;
301 fCoef2=0;
302 fCoef3=0;
303 fPointc[0]=0;
304 fPointc[1]=0;
4e05ab9a 305 fListOfTracks->Delete();
13918578 306}
bef31448 307
7e5bf5af 308
2257f27e 309
bef31448 310//______________________________________________________________________
af885e0f 311Int_t AliITStrackerSA::FindTracks(AliESDEvent* event){
bef31448 312
7e5bf5af 313// Track finder using the ESD object
314
2257f27e 315
7e5bf5af 316 //controllare numero cluster sui layer1 e 2 (morti?)
317 //non trova tracce...controllare..
4e05ab9a 318
2257f27e 319 if(!fITSclusters){
320 Fatal("FindTracks","ITS cluster tree is not accessed - Abort!!!\n Please use method SetClusterTree to pass the pointer to the tree\n");
321 return -1;
bef31448 322 }
7e5bf5af 323
324
325 //Reads event and mark clusters of traks already found, with flag kITSin
ebda3140 326 Int_t nentr=event->GetNumberOfTracks();
5a03f353 327 if(AliITSReconstructor::GetRecoParam()->GetSAUseAllClusters()==kFALSE) {
328 while (nentr--) {
329 AliESDtrack *track=event->GetTrack(nentr);
330 if (track->GetStatus()&AliESDtrack::kITSin==AliESDtrack::kITSin){
331 Int_t idx[12];
332 Int_t ncl = track->GetITSclusters(idx);
333 for(Int_t k=0;k<ncl;k++){
334 AliITSRecPoint* cll = (AliITSRecPoint*)GetCluster(idx[k]);
335 cll->SetBit(kSAflag);
336 }
ebda3140 337 }
338 }
339 }
340 //Get primary vertex
341 Double_t primaryVertex[3];
342 event->GetVertex()->GetXYZ(primaryVertex);
343 //Creates TClonesArray with clusters for each layer. The clusters already used
344 //by AliITStrackerMI are not considered
345 Int_t nclusters[6]={0,0,0,0,0,0};
346 Int_t dmar[6]={0,0,0,0,0,0};
347 if (fCluLayer == 0) {
348 fCluLayer = new TClonesArray*[AliITSgeomTGeo::GetNLayers()];
349 fCluCoord = new TClonesArray*[AliITSgeomTGeo::GetNLayers()];
350 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
351 fCluLayer[i]=0;
352 fCluCoord[i]=0;
353 }
354 }
355 Int_t * firstmod = new Int_t[AliITSgeomTGeo::GetNLayers()];
356 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
357 firstmod[i]=AliITSgeomTGeo::GetModuleIndex(i+1,1,1);
358 AliITSlayer &layer=fgLayers[i];
25be2b21 359 if (!AliITSReconstructor::GetRecoParam()->GetLayersToSkip(i)) {
360 for(Int_t cli=0;cli<layer.GetNumberOfClusters();cli++){
361 AliITSRecPoint* cls = (AliITSRecPoint*)layer.GetCluster(cli);
362 if(cls->TestBit(kSAflag)==kTRUE) continue; //clusters used by TPC prol.
363 if(cls->GetQ()==0) continue; //fake clusters dead zones
364 nclusters[i]++;
365 }
ebda3140 366 }
367 dmar[i]=0;
368 delete fCluLayer[i];
369 fCluLayer[i] = new TClonesArray("AliITSRecPoint",nclusters[i]);
370 delete fCluCoord[i];
371 fCluCoord[i] = new TClonesArray("AliITSclusterTable",nclusters[i]);
372 }
373
374 for(Int_t ilay=0;ilay<AliITSgeomTGeo::GetNLayers();ilay++){
375 TClonesArray &clulay = *fCluLayer[ilay];
376 TClonesArray &clucoo = *fCluCoord[ilay];
377 AliITSlayer &layer=fgLayers[ilay];
25be2b21 378 if (!AliITSReconstructor::GetRecoParam()->GetLayersToSkip(ilay)) {
379 for(Int_t cli=0;cli<layer.GetNumberOfClusters();cli++){
380 AliITSRecPoint* cls = (AliITSRecPoint*)layer.GetCluster(cli);
381 if(cls->TestBit(kSAflag)==kTRUE) continue;
382 if(cls->GetQ()==0) continue;
383 Double_t phi=0;Double_t lambda=0;
384 Float_t x=0;Float_t y=0;Float_t z=0;
385 Float_t sx=0;Float_t sy=0;Float_t sz=0;
386 GetCoorAngles(cls,phi,lambda,x,y,z,primaryVertex);
387 GetCoorErrors(cls,sx,sy,sz);
388 new (clulay[dmar[ilay]]) AliITSRecPoint(*cls);
389 new (clucoo[dmar[ilay]]) AliITSclusterTable(x,y,z,sx,sy,sz,phi,lambda,cli);
390 dmar[ilay]++;
391 }
ebda3140 392 }
393 }
7e5bf5af 394
ebda3140 395 Int_t minNPoints = (fSixPoints ? AliITSgeomTGeo::GetNLayers() : AliITSgeomTGeo::GetNLayers()-1);
396 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
397 if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(i)) {
398 minNPoints--;
399 }
400 }
7e5bf5af 401
402
ebda3140 403 Int_t ntrack=0;
404 //loop on the different windows
405 Int_t * nn = new Int_t[AliITSgeomTGeo::GetNLayers()];//counter for clusters on each layer
406 for(Int_t nloop=0;nloop<fNloop;nloop++){
407 for(Int_t ncl=0;ncl<fCluLayer[0]->GetEntries();ncl++){ //loop starting from layer 0
408
409 ResetForFinding();
410 Int_t pflag=0;
411
412 AliITSRecPoint* cl = (AliITSRecPoint*)fCluLayer[0]->At(ncl);
413
414 if(!cl) continue;
415 if (cl->GetQ()<=0) continue;
416
417 AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(0,ncl);
418 fPhic = arr->GetPhi();
419 fLambdac = arr->GetLambda();
420 if (TMath::Abs(fLambdac)>0.26*TMath::Pi()) continue;
421 fPhiEstimate = fPhic;
422 AliITStrackSA* trs = new AliITStrackSA();
423 fPoint1[0]=primaryVertex[0];
424 fPoint1[1]=primaryVertex[1];
425
426
427 fPoint2[0]=arr->GetX();
428 fPoint2[1]=arr->GetY();
429 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){ nn[i]=0;}
430 nn[0] = SearchClusters(0,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
431 nn[1] = SearchClusters(1,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
bef31448 432 if(nn[1]>0){
433 pflag=1;
434 fPoint3[0] = fPointc[0];
435 fPoint3[1] = fPointc[1];
436 }
cfe729e0 437 nn[2] = SearchClusters(2,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
bef31448 438 if(nn[1]==0 && nn[2]==0) pflag=0;
439 if(nn[2]!=0 && nn[1]!=0){ pflag=1; UpdatePoints();}
440 if(nn[2]!=0 && nn[1]==0){
441 pflag=1;
442 fPoint3[0]=fPointc[0];
443 fPoint3[1]=fPointc[1];
444 }
13918578 445
cfe729e0 446 nn[3] = SearchClusters(3,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
bef31448 447 pflag=1;
448 if(nn[3]!=0) UpdatePoints();
cfe729e0 449 nn[4] = SearchClusters(4,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
bef31448 450 pflag=1;
451 if(nn[4]!=0) UpdatePoints();
cfe729e0 452 nn[5] = SearchClusters(5,fPhiWin[nloop],fLambdaWin[nloop],trs,primaryVertex[2],pflag);
bef31448 453
454
455 Int_t layOK=0;
2755f080 456 //check of the candidate track
457 for(Int_t nnp=0;nnp<AliITSgeomTGeo::GetNLayers();nnp++) {
bef31448 458 if(nn[nnp]!=0) layOK+=1;
459 }
7e5bf5af 460
5a03f353 461 if(layOK>=minNPoints) {
2755f080 462 AliITStrackV2* tr2 = 0;
ebda3140 463 tr2 = FitTrack(trs,primaryVertex);
2755f080 464 if(!tr2) continue;
7e5bf5af 465
bef31448 466 AliESDtrack outtrack;
467 outtrack.UpdateTrackParams(tr2,AliESDtrack::kITSin);
468 event->AddTrack(&outtrack);
bef31448 469 ntrack++;
bef31448 470 }
471 delete trs;
7e5bf5af 472 }//end loop on clusters of layer1
7e5bf5af 473 //end loop2
ebda3140 474 }
2755f080 475
ebda3140 476 delete[] nn;
2755f080 477
7e5bf5af 478
ebda3140 479 minNPoints--;
7e5bf5af 480
ebda3140 481 //if 5/6 points are required, second loop starting
482 //from second layer (SPD2), to find tracks with point of
483 //layer 1 missing
484 if(!fSixPoints) {
485 //printf("looking from SPD2\n");
486 // counter for clusters on each layer
487 Int_t * nn = new Int_t[AliITSgeomTGeo::GetNLayers()-1];
488 for(Int_t nloop=0;nloop<fNloop;nloop++){
489 Int_t ncl2=fCluLayer[1]->GetEntries();
490 while(ncl2--){ //loop starting from layer 2
491 ResetForFinding();
492 Int_t pflag=0;
493 AliITSRecPoint* cl = (AliITSRecPoint*)fCluLayer[1]->At(ncl2);
494
495 if(!cl) continue;
496 AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(1,ncl2);
497 fPhic = arr->GetPhi();
498 fLambdac = arr->GetLambda();
499 fPhiEstimate = fPhic;
500
501 AliITStrackSA* trs = new AliITStrackSA();
502 fPoint1[0]=primaryVertex[0];
503 fPoint1[1]=primaryVertex[1];
504
505 fPoint2[0]=arr->GetX();
506 fPoint2[1]=arr->GetY();
507 for(Int_t kk=0;kk<AliITSgeomTGeo::GetNLayers()-1;kk++)nn[kk] = 0;
508 nn[0] = SearchClusters(1,fPhiWin[nloop],fLambdaWin[nloop],
509 trs,primaryVertex[2],pflag);
510 nn[1] = SearchClusters(2,fPhiWin[nloop],fLambdaWin[nloop],
511 trs,primaryVertex[2],pflag);
512 if(nn[1]!=0){
513 pflag=1;
514 fPoint3[0]=fPointc[0];
515 fPoint3[1]=fPointc[1];
516 }
517 nn[2]= SearchClusters(3,fPhiWin[nloop],fLambdaWin[nloop],
518 trs,primaryVertex[2],pflag);
519 if(nn[2]!=0){
520 pflag=1;
521 UpdatePoints();
522 }
523 nn[3]= SearchClusters(4,fPhiWin[nloop],fLambdaWin[nloop],
524 trs,primaryVertex[2],pflag);
525 if(nn[3]!=0){
526 pflag=1;
527 UpdatePoints();
528 }
529 nn[4]=SearchClusters(5,fPhiWin[nloop],fLambdaWin[nloop],
530 trs,primaryVertex[2],pflag);
531
5a03f353 532 Int_t layOK=0;
ebda3140 533 for(Int_t nnp=0;nnp<AliITSgeomTGeo::GetNLayers()-1;nnp++){
5a03f353 534 if(nn[nnp]!=0) layOK+=1;
ebda3140 535 }
5a03f353 536 if(layOK>=minNPoints){ // 5/6
ebda3140 537 AliITStrackV2* tr2 = 0;
538 tr2 = FitTrack(trs,primaryVertex);
539 if(!tr2) continue;
540
541 AliESDtrack outtrack;
542 outtrack.UpdateTrackParams(tr2,AliESDtrack::kITSin);
543 event->AddTrack(&outtrack);
544 ntrack++;
545
546 }
547
bef31448 548 delete trs;
549 }//end loop on clusters of layer2
ebda3140 550 }
551
552 delete [] nn;
553 } //end opt="5/6"
554
555 // search for tracks starting from SPD2, SDD1, SDD2, SSD2
556 // for cosmics (A. Dainese 31.07.07)
557 if(fOuterStartLayer>0) {
558 for(Int_t innLay=1; innLay<=fOuterStartLayer; innLay++) {
559 //printf("Searching from layer %d outward\n",innLay);
560 minNPoints=AliITSgeomTGeo::GetNLayers()-innLay;
561 for(Int_t i=innLay;i<AliITSgeomTGeo::GetNLayers();i++)
562 if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(i))
563 minNPoints--;
564 // counter for clusters on each layer
565 Int_t * nn = new Int_t[AliITSgeomTGeo::GetNLayers()-innLay];
566 for(Int_t nloop=0;nloop<fNloop;nloop++){
567 Int_t nclInnLay=fCluLayer[innLay]->GetEntries();
568 while(nclInnLay--){ //loop starting from layer innLay
569 ResetForFinding();
570 Int_t pflag=0;
571 AliITSRecPoint* cl = (AliITSRecPoint*)fCluLayer[innLay]->At(nclInnLay);
572
573 if(!cl) continue;
574 AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(innLay,nclInnLay);
575 fPhic = arr->GetPhi();
576 fLambdac = arr->GetLambda();
577 fPhiEstimate = fPhic;
578
579 AliITStrackSA* trs = new AliITStrackSA();
580 fPoint1[0]=primaryVertex[0];
581 fPoint1[1]=primaryVertex[1];
582 fPoint2[0]=arr->GetX();
583 fPoint2[1]=arr->GetY();
584
585 Int_t kk;
586 for(kk=0;kk<AliITSgeomTGeo::GetNLayers()-innLay;kk++) nn[kk] = 0;
587
588 kk=0;
589 nn[kk] = SearchClusters(innLay,fPhiWin[nloop],fLambdaWin[nloop],
b8ed1a92 590 trs,primaryVertex[2],pflag);
ebda3140 591 for(Int_t nextLay=innLay+1; nextLay<AliITSgeomTGeo::GetNLayers(); nextLay++) {
592 kk++;
593 nn[kk] = SearchClusters(nextLay,fPhiWin[nloop],fLambdaWin[nloop],
594 trs,primaryVertex[2],pflag);
595 if(nn[kk]!=0){
596 pflag=1;
597 if(kk==1) {
598 fPoint3[0]=fPointc[0];
599 fPoint3[1]=fPointc[1];
600 } else {
601 UpdatePoints();
602 }
603 }
604 }
605
5a03f353 606 Int_t layOK=0;
ebda3140 607 for(Int_t nnp=0;nnp<AliITSgeomTGeo::GetNLayers()-innLay;nnp++){
5a03f353 608 if(nn[nnp]!=0) layOK+=1;
ebda3140 609 }
5a03f353 610 if(layOK>=minNPoints){
ebda3140 611 AliITStrackV2* tr2 = 0;
612 tr2 = FitTrack(trs,primaryVertex);
613 if(!tr2) continue;
614
615
616 AliESDtrack outtrack;
617 outtrack.UpdateTrackParams(tr2,AliESDtrack::kITSin);
618 event->AddTrack(&outtrack);
619 ntrack++;
620
621 }
622
623 delete trs;
624 }//end loop on clusters of innLay
625 } //end loop on window sizes
626
627 delete [] nn;
628 } //end loop on innLay
629 } //end if(fOuterStartLayer>0)
630
5a03f353 631
632 // search for 1-point tracks, only for cosmics
633 // (A.Dainese 21.03.08)
634 if(AliITSReconstructor::GetRecoParam()->GetSAOnePointTracks() &&
635 TMath::Abs(event->GetMagneticField())<0.01) {
636 for(Int_t innLay=0; innLay<=fOuterStartLayer; innLay++) {
637 // counter for clusters on each layer
638 Int_t * nn = new Int_t[AliITSgeomTGeo::GetNLayers()-innLay];
639 for(Int_t nloop=0;nloop<fNloop;nloop++){
640 Int_t nclInnLay=fCluLayer[innLay]->GetEntries();
641 while(nclInnLay--){ //loop starting from layer innLay
642 ResetForFinding();
643 Int_t pflag=0;
644 AliITSRecPoint* cl = (AliITSRecPoint*)fCluLayer[innLay]->At(nclInnLay);
645
646 if(!cl) continue;
647 AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(innLay,nclInnLay);
648 fPhic = arr->GetPhi();
649 fLambdac = arr->GetLambda();
650 fPhiEstimate = fPhic;
651
652 AliITStrackSA* trs = new AliITStrackSA();
653 fPoint1[0]=primaryVertex[0];
654 fPoint1[1]=primaryVertex[1];
655 fPoint2[0]=arr->GetX();
656 fPoint2[1]=arr->GetY();
657
658 Int_t kk;
659 for(kk=0;kk<AliITSgeomTGeo::GetNLayers()-innLay;kk++) nn[kk] = 0;
660
661 kk=0;
662 nn[kk] = SearchClusters(innLay,fPhiWin[nloop],fLambdaWin[nloop],
663 trs,primaryVertex[2],pflag);
664 for(Int_t nextLay=innLay+1; nextLay<AliITSgeomTGeo::GetNLayers(); nextLay++) {
665 kk++;
666 nn[kk] = SearchClusters(nextLay,fPhiWin[nloop],fLambdaWin[nloop],
667 trs,primaryVertex[2],pflag);
668 if(nn[kk]!=0){
669 pflag=1;
670 if(kk==1) {
671 fPoint3[0]=fPointc[0];
672 fPoint3[1]=fPointc[1];
673 } else {
674 UpdatePoints();
675 }
676 }
677 }
678
679 Int_t layOK=0;
680 for(Int_t nnp=0;nnp<AliITSgeomTGeo::GetNLayers()-innLay;nnp++){
681 if(nn[nnp]!=0) layOK+=1;
682 }
683 if(layOK==1) {
684 AliITStrackV2* tr2 = 0;
685 Bool_t onePoint = kTRUE;
686 tr2 = FitTrack(trs,primaryVertex,onePoint);
687 if(!tr2) continue;
688
689 AliESDtrack outtrack;
690 outtrack.UpdateTrackParams(tr2,AliESDtrack::kITSin);
691 event->AddTrack(&outtrack);
692 ntrack++;
693
694 }
695
696 delete trs;
697 }//end loop on clusters of innLay
698 } //end loop on window sizes
699
700 delete [] nn;
701 } //end loop on innLay
702 } // end search 1-point tracks
ebda3140 703
bef31448 704 delete [] firstmod;
bef31448 705 Info("FindTracks","Number of found tracks: %d",event->GetNumberOfTracks());
2257f27e 706 return 0;
bef31448 707
708}
7e5bf5af 709
13918578 710//________________________________________________________________________
711
5a03f353 712AliITStrackV2* AliITStrackerSA::FitTrack(AliITStrackSA* tr,Double_t *primaryVertex,Bool_t onePoint) {
ebda3140 713 //fit of the found track (most general case, also <6 points, layers missing)
714 // A.Dainese 16.11.07
13918578 715
13918578 716
cc088660 717 Int_t * firstmod = new Int_t[AliITSgeomTGeo::GetNLayers()];
cc088660 718 TObjArray** listlayer = new TObjArray*[AliITSgeomTGeo::GetNLayers()];
ebda3140 719 Int_t ** clind=new Int_t*[AliITSgeomTGeo::GetNLayers()];
720 Int_t ** clmark=new Int_t*[AliITSgeomTGeo::GetNLayers()];
cc088660 721 Int_t * nnn = new Int_t[AliITSgeomTGeo::GetNLayers()];
722 Int_t * kkk = new Int_t[AliITSgeomTGeo::GetNLayers()];
13918578 723
ebda3140 724 const Int_t maxclu=AliITStrackSA::GetMaxNumberOfClusters();
13918578 725
ebda3140 726 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
b8ed1a92 727 firstmod[i]=AliITSgeomTGeo::GetModuleIndex(i+1,1,1);
b8ed1a92 728 listlayer[i] = new TObjArray(0,0);
ebda3140 729 nnn[i]=0;
730 kkk[i]=0;
731 clind[i]=new Int_t[maxclu];
732 clmark[i]=new Int_t[maxclu];
733 for(Int_t j=0;j<maxclu; j++){
734 clind[i][j]=0;
735 clmark[i][j]=0;
b8ed1a92 736 }
737 }
2755f080 738
2755f080 739
740 Int_t nclusters = tr->GetNumberOfClustersSA();
2755f080 741 for(Int_t ncl=0;ncl<nclusters;ncl++){
742 Int_t index = tr->GetClusterIndexSA(ncl);
743 AliITSRecPoint* cl = (AliITSRecPoint*)GetCluster(index);
744 if(cl->TestBit(kSAflag)==kTRUE) cl->ResetBit(kSAflag);
745 Int_t lay = (index & 0xf0000000) >> 28;
ebda3140 746 listlayer[lay]->AddLast(cl);
747 Int_t ind=nnn[lay];
748 clind[lay][ind]=index;
2755f080 749 }
750 delete [] nnn;
751
752 for(Int_t nlay=0;nlay<AliITSgeomTGeo::GetNLayers();nlay++){
753 for(Int_t ncl=0;ncl<tr->GetNumberOfMarked(nlay);ncl++){
754 Int_t mark = tr->GetClusterMark(nlay,ncl);
ebda3140 755 Int_t ind=kkk[nlay];
756 clmark[nlay][ind]=mark;
2755f080 757 }
758 }
759
760 delete [] kkk;
761
762 Int_t firstLay=-1,secondLay=-1;
763 Int_t * end = new Int_t[AliITSgeomTGeo::GetNLayers()];
764 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
765 if(listlayer[i]->GetEntries()==0) {
766 end[i]=1;
767 } else {
768 end[i]=listlayer[i]->GetEntries();
769 if(firstLay==-1) {
770 firstLay=i;
771 } else if(secondLay==-1) {
772 secondLay=i;
773 }
774 }
775 }
776
5a03f353 777 if(firstLay==-1 || (secondLay==-1 && !onePoint)) {
225a692b 778 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
779 delete listlayer[i];
780 delete clind[i];
781 delete clmark[i];
782 }
783 delete [] listlayer;
784 delete [] clind;
785 delete [] clmark;
786 delete [] firstmod;
787 delete [] end;
788 return 0;
789 }
790
2755f080 791 TClonesArray* listSA = new TClonesArray("AliITStrackSA");
792 TClonesArray &tri = *listSA;
793 Int_t nlist=0;
794
795 for(Int_t l0=0;l0<end[0];l0++){ //loop on layer 1
796 AliITSRecPoint* cl0 = (AliITSRecPoint*)listlayer[0]->At(l0);
797 for(Int_t l1=0;l1<end[1];l1++){ //loop on layer 2
798 AliITSRecPoint* cl1 = (AliITSRecPoint*)listlayer[1]->At(l1);
799 for(Int_t l2=0;l2<end[2];l2++){ //loop on layer 3
800 AliITSRecPoint* cl2 = (AliITSRecPoint*)listlayer[2]->At(l2);
801 for(Int_t l3=0;l3<end[3];l3++){ //loop on layer 4
802 AliITSRecPoint* cl3 = (AliITSRecPoint*)listlayer[3]->At(l3);
803 for(Int_t l4=0;l4<end[4];l4++){ //loop on layer 5
804 AliITSRecPoint* cl4 = (AliITSRecPoint*)listlayer[4]->At(l4);
805 for(Int_t l5=0;l5<end[5];l5++){ //loop on layer 6
806 AliITSRecPoint* cl5 = (AliITSRecPoint*)listlayer[5]->At(l5);
807
808
809 Double_t x1,y1,z1,sx1,sy1,sz1;
810 Double_t x2,y2,z2,sx2,sy2,sz2;
811 AliITSRecPoint* p1=0;
812 AliITSRecPoint* p2=0;
813 Int_t index1=0,index2=0;
814 Int_t mrk1=0,mrk2=0;
815
816 switch(firstLay) {
817 case 0:
818 p1=cl0;
ebda3140 819 index1=clind[0][l0];mrk1=clmark[0][l0];
2755f080 820 break;
821 case 1:
822 p1=cl1;
ebda3140 823 index1=clind[1][l1];mrk1=clmark[1][l1];
2755f080 824 break;
825 case 2:
826 p1=cl2;
ebda3140 827 index1=clind[2][l2];mrk1=clmark[2][l2];
2755f080 828 break;
829 case 3:
830 p1=cl3;
ebda3140 831 index1=clind[3][l3];mrk1=clmark[3][l3];
2755f080 832 break;
833 case 4:
834 p1=cl4;
ebda3140 835 index1=clind[4][l4];mrk1=clmark[4][l4];
2755f080 836 break;
837 }
838
839 switch(secondLay) {
840 case 1:
841 p2=cl1;
ebda3140 842 index2=clind[1][l1];mrk2=clmark[1][l1];
2755f080 843 break;
844 case 2:
845 p2=cl2;
ebda3140 846 index2=clind[2][l2];mrk2=clmark[2][l2];
2755f080 847 break;
848 case 3:
849 p2=cl3;
ebda3140 850 index2=clind[3][l3];mrk2=clmark[3][l3];
2755f080 851 break;
852 case 4:
853 p2=cl4;
ebda3140 854 index2=clind[4][l4];mrk2=clmark[4][l4];
2755f080 855 break;
856 case 5:
857 p2=cl5;
ebda3140 858 index2=clind[5][l5];mrk2=clmark[5][l5];
2755f080 859 break;
5a03f353 860 default:
861 p2=0;
862 index2=-1;mrk2=-1;
863 break;
2755f080 864 }
865
866 Int_t module1 = p1->GetDetectorIndex()+firstmod[firstLay];
5a03f353 867 Int_t layer,ladder,detector;
868 AliITSgeomTGeo::GetModuleId(module1,layer,ladder,detector);
869 Float_t yclu1 = p1->GetY();
870 Float_t zclu1 = p1->GetZ();
871 Double_t cv=0,tgl2=0,phi2=0;
2755f080 872
873 Int_t cln1=mrk1;
2755f080 874 AliITSclusterTable* arr1 = (AliITSclusterTable*)GetClusterCoord(firstLay,cln1);
2755f080 875 x1 = arr1->GetX();
2755f080 876 y1 = arr1->GetY();
2755f080 877 z1 = arr1->GetZ();
2755f080 878 sx1 = arr1->GetSx();
2755f080 879 sy1 = arr1->GetSy();
2755f080 880 sz1 = arr1->GetSz();
225a692b 881
5a03f353 882 if(secondLay>0) {
883 Int_t cln2=mrk2;
884 AliITSclusterTable* arr2 = (AliITSclusterTable*)GetClusterCoord(secondLay,cln2);
885 x2 = arr2->GetX();
886 y2 = arr2->GetY();
887 z2 = arr2->GetZ();
888 sx2 = arr2->GetSx();
889 sy2 = arr2->GetSy();
890 sz2 = arr2->GetSz();
891 cv = Curvature(primaryVertex[0],primaryVertex[1],x1,y1,x2,y2);
892 tgl2 = (z2-z1)/TMath::Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
893 phi2 = TMath::ATan2((y2-y1),(x2-x1));
894 } else { // special case of 1-point tracks, only for cosmics (B=0)
895 x2 = primaryVertex[0];
896 y2 = primaryVertex[1];
897 z2 = primaryVertex[2];
898 cv = 0;
899 tgl2 = (z1-z2)/TMath::Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
900 phi2 = TMath::ATan2((y1-y2),(x1-x2));
901 }
902
903
2755f080 904 AliITStrackSA* trac = new AliITStrackSA(layer,ladder,detector,yclu1,zclu1,phi2,tgl2,cv,1);
225a692b 905
906
2755f080 907 if(cl5!=0) {
ebda3140 908 trac->AddClusterV2(5,(clind[5][l5] & 0x0fffffff)>>0);
909 trac->AddClusterMark(5,clmark[5][l5]);
b8ed1a92 910 }
911 if(cl4!=0){
ebda3140 912 trac->AddClusterV2(4,(clind[4][l4] & 0x0fffffff)>>0);
913 trac->AddClusterMark(4,clmark[4][l4]);
b8ed1a92 914 }
915 if(cl3!=0){
ebda3140 916 trac->AddClusterV2(3,(clind[3][l3] & 0x0fffffff)>>0);
917 trac->AddClusterMark(3,clmark[3][l3]);
b8ed1a92 918 }
919 if(cl2!=0){
ebda3140 920 trac->AddClusterV2(2,(clind[2][l2] & 0x0fffffff)>>0);
921 trac->AddClusterMark(2,clmark[2][l2]);
b8ed1a92 922 }
923 if(cl1!=0){
ebda3140 924 trac->AddClusterV2(1,(clind[1][l1] & 0x0fffffff)>>0);
925 trac->AddClusterMark(1,clmark[1][l1]);
b8ed1a92 926 }
927 if(cl0!=0){
ebda3140 928 trac->AddClusterV2(0,(clind[0][l0] & 0x0fffffff)>>0);
929 trac->AddClusterMark(0,clmark[0][l0]);
b8ed1a92 930 }
931
b8ed1a92 932 //fit with Kalman filter using AliITStrackerMI::RefitAt()
933 AliITStrackMI* ot = new AliITStrackSA(*trac);
934
935 ot->ResetCovariance(10.);
936 ot->ResetClusters();
937
e50912db 938 if(RefitAt(AliITSRecoParam::GetrInsideITSscreen(),ot,trac)){ //fit from layer 1 to layer 6
b8ed1a92 939 AliITStrackMI *otrack2 = new AliITStrackMI(*ot);
940 otrack2->ResetCovariance(10.);
941 otrack2->ResetClusters();
942 //fit from layer 6 to layer 1
e50912db 943 if(RefitAt(AliITSRecoParam::GetrInsideSPD1(),otrack2,ot)) {
b8ed1a92 944 fListOfTracks->AddLast(otrack2);
945 new (tri[nlist]) AliITStrackSA(*trac);
946 nlist++;
947 } else {
948 delete otrack2;
949 }
950
951 }
952
953 delete ot;
954 delete trac;
955 }//end loop layer 6
956 }//end loop layer 5
957 }//end loop layer 4
958 }//end loop layer 3
959 }//end loop layer 2
960 }//end loop layer 1
961
962 delete [] end;
963
225a692b 964
b8ed1a92 965
966 Int_t dim=fListOfTracks->GetEntries();
967 if(dim==0){
968 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
969 delete listlayer[i];
ebda3140 970 delete clind[i];
971 delete clmark[i];
b8ed1a92 972 }
973 delete [] listlayer;
ebda3140 974 delete [] clind;
975 delete [] clmark;
b8ed1a92 976 listSA->Delete();
977 delete listSA;
978 delete [] firstmod;
979 return 0;
980 }
981
982 Int_t lowchi2 = FindTrackLowChiSquare(fListOfTracks,dim);
983 AliITStrackV2* otrack =(AliITStrackV2*)fListOfTracks->At(lowchi2);
984 AliITStrackSA* trsa = (AliITStrackSA*)listSA->At(lowchi2);
985
986 if(otrack==0) {
987 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
988 delete listlayer[i];
ebda3140 989 delete clind[i];
990 delete clmark[i];
b8ed1a92 991 }
992 delete [] listlayer;
ebda3140 993 delete [] clind;
994 delete [] clmark;
b8ed1a92 995 listSA->Delete();
996 delete listSA;
997 delete [] firstmod;
ebda3140 998 delete [] clind;
999 delete [] clmark;
b8ed1a92 1000 return 0;
1001 }
1002 Int_t * indexc = new Int_t[AliITSgeomTGeo::GetNLayers()];
1003 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) indexc[i]=0;
1004 for(Int_t nind=0;nind<otrack->GetNumberOfClusters();nind++){
1005 indexc[nind] = otrack->GetClusterIndex(nind);
1006 }
1007 Int_t labl[6][3];
1008 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
1009 if(i<otrack->GetNumberOfClusters()) {
1010 AliITSRecPoint* cl = (AliITSRecPoint*)GetCluster(indexc[i]);
1011 labl[i][0]=cl->GetLabel(0);
1012 labl[i][1]=cl->GetLabel(1);
1013 labl[i][2]=cl->GetLabel(2);
1014 } else {
1015 labl[i][0]=-1;
1016 labl[i][1]=-1;
1017 labl[i][2]=-1;
1018 }
1019 }
1020 delete [] indexc;
2755f080 1021
b8ed1a92 1022 CookLabel(otrack,0.); //MI change - to see fake ratio
1023
1024 Int_t label=FindLabel(labl[0][0],labl[1][0],labl[2][0],labl[3][0],labl[4][0],labl[5][0]);
1025 Int_t lflag=0;
2755f080 1026 for(Int_t i=0;i<otrack->GetNumberOfClusters();i++)
b8ed1a92 1027 if(labl[i][0]==label || labl[i][1]==label || labl[i][2]==label) lflag++;
1028
2755f080 1029 if(lflag<otrack->GetNumberOfClusters()) label = -label;
b8ed1a92 1030 otrack->SetLabel(label);
1031
1032 //remove clusters of found track
1033 for(Int_t nlay=0;nlay<AliITSgeomTGeo::GetNLayers();nlay++){
1034 for(Int_t cln=0;cln<trsa->GetNumberOfMarked(nlay);cln++){
1035 Int_t index = trsa->GetClusterMark(nlay,cln);
1036 fCluLayer[nlay]->RemoveAt(index);
1037 RemoveClusterCoord(nlay,index);
1038 fCluLayer[nlay]->Compress();
7e5bf5af 1039 }
1040 }
1041 listSA->Delete();
1042 delete listSA;
1043
cc088660 1044 for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++){
13918578 1045 delete listlayer[i];
ebda3140 1046 delete clind[i];
1047 delete clmark[i];
13918578 1048 }
c09cece6 1049 delete [] listlayer;
037efb75 1050 delete [] firstmod;
ebda3140 1051 delete [] clind;
1052 delete [] clmark;
13918578 1053 return otrack;
1054
1055}
1056
bef31448 1057
4e05ab9a 1058
bef31448 1059//_______________________________________________________
7e5bf5af 1060Int_t AliITStrackerSA::SearchClusters(Int_t layer,Double_t phiwindow,Double_t lambdawindow, AliITStrackSA* trs,Double_t /*zvertex*/,Int_t pflag){
13918578 1061 //function used to to find the clusters associated to the track
2755f080 1062
1063 if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(layer)) return 0;
1064
13918578 1065 Int_t nc=0;
1066 AliITSlayer &lay = fgLayers[layer];
7e5bf5af 1067 Double_t r=lay.GetR();
2755f080 1068 if(pflag==1){
cfe729e0 1069 Float_t cx1,cx2,cy1,cy2;
1070 FindEquation(fPoint1[0],fPoint1[1],fPoint2[0],fPoint2[1],fPoint3[0],fPoint3[1],fCoef1,fCoef2,fCoef3);
1071 if (FindIntersection(fCoef1,fCoef2,fCoef3,-r*r,cx1,cy1,cx2,cy2)==0)
1072 return 0;
1966f03c 1073 Double_t fi1=TMath::ATan2(cy1-fPoint1[1],cx1-fPoint1[0]);
1074 Double_t fi2=TMath::ATan2(cy2-fPoint1[1],cx2-fPoint1[0]);
cfe729e0 1075 fPhiEstimate=ChoosePoint(fi1,fi2,fPhic);
1076 }
13918578 1077
7e5bf5af 1078
1079 Int_t ncl = fCluLayer[layer]->GetEntries();
1080 for (Int_t index=0; index<ncl; index++) {
00a7cc50 1081 AliITSRecPoint *c = (AliITSRecPoint*)fCluLayer[layer]->At(index);
7e5bf5af 1082 if (!c) continue;
1083 if (c->GetQ()<=0) continue;
1084
1085 AliITSclusterTable* arr = (AliITSclusterTable*)GetClusterCoord(layer,index);
1086 Double_t phi = arr->GetPhi();
cfe729e0 1087 if (TMath::Abs(phi-fPhiEstimate)>phiwindow) continue;
494fda7c 1088
7e5bf5af 1089 Double_t lambda = arr->GetLambda();
cfe729e0 1090 if (TMath::Abs(lambda-fLambdac)>lambdawindow) continue;
1091
7e5bf5af 1092 if(trs->GetNumberOfClustersSA()==trs->GetMaxNumberOfClusters()) return 0;
1093 if(trs->GetNumberOfMarked(layer)==trs->GetMaxNMarkedPerLayer()) return 0;
1094 Int_t orind = arr->GetOrInd();
1095 trs->AddClusterSA(layer,orind);
1096 trs->AddClusterMark(layer,index);
1097
cfe729e0 1098 nc++;
1099 fLambdac=lambda;
1100 fPhiEstimate=phi;
cfe729e0 1101
7e5bf5af 1102 fPointc[0]=arr->GetX();
1103 fPointc[1]=arr->GetY();
1104
cfe729e0 1105 }
1106 return nc;
1107}
13918578 1108
bef31448 1109//________________________________________________________________
1110void AliITStrackerSA::UpdatePoints(){
1111 //update of points for the estimation of the curvature
13918578 1112
bef31448 1113 fPoint2[0]=fPoint3[0];
1114 fPoint2[1]=fPoint3[1];
1115 fPoint3[0]=fPointc[0];
1116 fPoint3[1]=fPointc[1];
13918578 1117
1118
13918578 1119}
13918578 1120
13918578 1121//___________________________________________________________________
1122Int_t AliITStrackerSA::FindEquation(Float_t x1, Float_t y1, Float_t x2, Float_t y2, Float_t x3, Float_t y3,Float_t& a, Float_t& b, Float_t& c){
1123
1124 //given (x,y) of three recpoints (in global coordinates)
1125 //returns the parameters a,b,c of circonference x*x + y*y +a*x + b*y +c
1126
1127 Float_t den = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
1128 if(den==0) return 0;
1129 a = ((y3-y1)*(x2*x2+y2*y2-x1*x1-y1*y1)-(y2-y1)*(x3*x3+y3*y3-x1*x1-y1*y1))/den;
1130 b = -(x2*x2-x1*x1+y2*y2-y1*y1+a*(x2-x1))/(y2-y1);
1131 c = -x1*x1-y1*y1-a*x1-b*y1;
1132 return 1;
1133 }
1134//__________________________________________________________________________
1135 Int_t AliITStrackerSA::FindIntersection(Float_t a1, Float_t b1, Float_t c1, Float_t c2,Float_t& x1,Float_t& y1, Float_t& x2, Float_t& y2){
1136
1137 //Finds the intersection between the circonference of the track and the circonference centered in (0,0) represented by one layer
1138 //c2 is -rlayer*rlayer
1139
1140 if(a1==0) return 0;
3a2f227d 1141 Double_t m = c2-c1;
1142 Double_t aA = (b1*b1)/(a1*a1)+1;
1143 Double_t bB = (-2*m*b1/(a1*a1));
1144 Double_t cC = c2+(m*m)/(a1*a1);
1145 Double_t dD = bB*bB-4*aA*cC;
1146 if(dD<0) return 0;
13918578 1147
3a2f227d 1148 y1 = (-bB+TMath::Sqrt(dD))/(2*aA);
1149 y2 = (-bB-TMath::Sqrt(dD))/(2*aA);
13918578 1150 x1 = (c2-c1-b1*y1)/a1;
1151 x2 = (c2-c1-b1*y2)/a1;
1152
1153 return 1;
1154}
1155//____________________________________________________________________
1156Double_t AliITStrackerSA::Curvature(Double_t x1,Double_t y1,Double_t
1157x2,Double_t y2,Double_t x3,Double_t y3){
1158
1159 //calculates the curvature of track
1160 Double_t den = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
1161 if(den==0) return 0;
1162 Double_t a = ((y3-y1)*(x2*x2+y2*y2-x1*x1-y1*y1)-(y2-y1)*(x3*x3+y3*y3-x1*x1-y1*y1))/den;
1163 Double_t b = -(x2*x2-x1*x1+y2*y2-y1*y1+a*(x2-x1))/(y2-y1);
1164 Double_t c = -x1*x1-y1*y1-a*x1-b*y1;
1165 Double_t xc=-a/2.;
1166
1167 if((a*a+b*b-4*c)<0) return 0;
1168 Double_t rad = TMath::Sqrt(a*a+b*b-4*c)/2.;
1169 if(rad==0) return 0;
1170
1171 if((x1>0 && y1>0 && x1<xc)) rad*=-1;
1172 if((x1<0 && y1>0 && x1<xc)) rad*=-1;
1173 // if((x1<0 && y1<0 && x1<xc)) rad*=-1;
1174 // if((x1>0 && y1<0 && x1<xc)) rad*=-1;
1175
1176 return 1/rad;
1177
1178}
7e5bf5af 1179
1180
13918578 1181//____________________________________________________________________
1182Double_t AliITStrackerSA::ChoosePoint(Double_t p1, Double_t p2, Double_t pp){
1183
1184 //Returns the point closest to pp
1185
1186 Double_t diff1 = p1-pp;
1187 Double_t diff2 = p2-pp;
1188
1189 if(TMath::Abs(diff1)<TMath::Abs(diff2)) fPhiEstimate=p1;
1190 else fPhiEstimate=p2;
1191 return fPhiEstimate;
1192
1193}
1194
1195
1196//_________________________________________________________________
7e5bf5af 1197Int_t AliITStrackerSA::FindTrackLowChiSquare(TObjArray* tracklist, Int_t dim) const {
52a9777e 1198 // returns track with lowers chi square
13918578 1199 if(dim==1){
7e5bf5af 1200 //AliITStrackV2* trk = (AliITStrackV2*)tracklist->At(0);
1201 //return trk;
1202 return 0;
13918578 1203 }
52a9777e 1204 if(dim==0) return 0;
037efb75 1205 Double_t * chi2 = new Double_t[dim];
1206 Int_t * index = new Int_t[dim];
13918578 1207 for(Int_t i=0;i<dim;i++){
1208 AliITStrackV2* trk = (AliITStrackV2*)tracklist->At(i);
1209 chi2[i]=trk->GetChi2();
1210 index[i]=i;
1211 }
1212
1213 Int_t w=0;Double_t value;
1214 Int_t lp;
1215 while(w<dim){
1216 for(Int_t j=w+1;j<dim;j++){
1217 if(chi2[w]<chi2[j]){
bef31448 1218 value=chi2[w];
1219 chi2[w]=chi2[j];
1220 chi2[j]=value;
1221 lp=index[w];
1222 index[w]=index[j];
1223 index[j]=lp;
13918578 1224 }
1225 }
1226 w++;
1227 }
52a9777e 1228 Int_t tmp = index[dim-1];
037efb75 1229 delete [] chi2;
1230 delete [] index;
52a9777e 1231 return tmp;
13918578 1232}
1233
1234//__________________________________________________________
2755f080 1235Int_t AliITStrackerSA::FindLabel(Int_t l0, Int_t l1, Int_t l2, Int_t l3, Int_t l4, Int_t l5){
13918578 1236
1237 //function used to determine the track label
1238
2755f080 1239 Int_t lb[6] = {l0,l1,l2,l3,l4,l5};
13918578 1240 Int_t aa[6]={1,1,1,1,1,1};
1241 Int_t ff=0;
1242 Int_t ll=0;
1243 Int_t k=0;Int_t w=0;Int_t num=6;
8b3779ef 1244 for(Int_t i=5;i>=0;i--) if(lb[i]==-1) num=i;
13918578 1245
1246 while(k<num){
1247
1248 for(Int_t i=k+1;i<num;i++){
1249
1250 if(lb[k]==lb[i] && aa[k]!=0){
1251
1252 aa[k]+=1;
1253 aa[i]=0;
1254 }
1255 }
8b3779ef 1256 k++;
13918578 1257 }
1258
1259 while(w<num){
8b3779ef 1260
13918578 1261 for(Int_t j=0;j<6;j++){
1262 if(aa[w]<aa[j]){
1263 ff=aa[w];
1264 aa[w]=aa[j];
1265 aa[j]=ff;
1266 ll=lb[w];
1267 lb[w]=lb[j];
1268 lb[j]=ll;
1269 }
1270 }
8b3779ef 1271 w++;
13918578 1272 }
8b3779ef 1273
1274 if(num<1) return -1;
1275 return lb[num-1];
13918578 1276}
1277
1278//_____________________________________________________________________________
1279Int_t AliITStrackerSA::Label(Int_t gl1, Int_t gl2, Int_t gl3, Int_t gl4, Int_t gl5, Int_t gl6,Int_t gl7, Int_t gl8, Int_t gl9, Int_t gl10,Int_t gl11,
2755f080 1280Int_t gl12, Int_t gl13, Int_t gl14,Int_t gl15, Int_t gl16, Int_t gl17, Int_t gl18, Int_t minNPoints){
13918578 1281
1282
1283 //function used to assign label to the found track. If track is fake, the label is negative
1284
1285 Int_t lb0[6] = {gl1,gl2,gl3,gl4,gl5,gl6};
1286 Int_t lb1[6] = {gl7,gl8,gl9,gl10,gl11,gl12};
1287 Int_t lb2[6] = {gl13,gl14,gl15,gl16,gl17,gl18};
1288 Int_t ll=FindLabel(lb0[0],lb0[1],lb0[2],lb0[3],lb0[4],lb0[5]);
1289 Int_t lflag=0;Int_t num=6;
1290 if(lb0[5]==-1 && lb1[5]==-1 && lb2[5]==-1) num=5;
1291
1292 for(Int_t i=0;i<num;i++){
1293 if(lb0[i]==ll || lb1[i]==ll || lb2[i]==ll) lflag+=1;
1294 }
1295
2755f080 1296 if(lflag>=minNPoints) return ll;
13918578 1297 else return -ll;
1298
1299
1300}
13918578 1301//_____________________________________________________________________________
5b4dedce 1302void AliITStrackerSA::SetCalculatedWindowSizes(Int_t n, Float_t phimin, Float_t phimax, Float_t lambdamin, Float_t lambdamax){
1303 // Set sizes of the phi and lambda windows used for track finding
1304 fNloop = n;
1305 if(fPhiWin) delete [] fPhiWin;
1306 if(fLambdaWin) delete [] fLambdaWin;
1307 fPhiWin = new Double_t[fNloop];
1308 fLambdaWin = new Double_t[fNloop];
1309 Float_t stepPhi=(phimax-phimin)/(Float_t)(fNloop-1);
1310 Float_t stepLambda=(lambdamax-lambdamin)/(Float_t)(fNloop-1);
1311 for(Int_t k=0;k<fNloop;k++){
1312 Float_t phi=phimin+k*stepPhi;
1313 Float_t lam=lambdamin+k*stepLambda;
1314 fPhiWin[k]=phi;
1315 fLambdaWin[k]=lam;
1316 }
1317}
1318//_____________________________________________________________________________
1319void AliITStrackerSA::SetFixedWindowSizes(Int_t n, Double_t *phi, Double_t *lam){
13918578 1320 // Set sizes of the phi and lambda windows used for track finding
1321 fNloop = n;
1322 if(phi){ // user defined values
1323 fPhiWin = new Double_t[fNloop];
1324 fLambdaWin = new Double_t[fNloop];
1325 for(Int_t k=0;k<fNloop;k++){
1326 fPhiWin[k]=phi[k];
1327 fLambdaWin[k]=lam[k];
1328 }
1329 }
1330 else { // default values
627b6db6 1331
1332 Double_t phid[33] = {0.002,0.003,0.004,0.0045,0.0047,
bef31448 1333 0.005,0.0053,0.0055,
1334 0.006,0.0063,0.0065,0.007,0.0073,0.0075,0.0077,
1335 0.008,0.0083,0.0085,0.0087,0.009,0.0095,0.0097,
627b6db6 1336 0.01,0.0105,0.011,0.0115,0.012,0.0125,0.013,0.0135,0.0140,0.0145};
1337 Double_t lambdad[33] = {0.003,0.004,0.005,0.005,0.005,
1338 0.005,0.005,0.006,
1339 0.006,0.006,0.006,0.007,0.007,0.007,0.007,
1340 0.007,0.007,0.007,0.007,0.007,0.007,0.007,
1341 0.008,0.008,0.008,0.008,0.008,0.008,0.008,0.008,0.008,0.008};
bef31448 1342
627b6db6 1343 if(fNloop!=33){
1344 fNloop = 33;
13918578 1345 }
627b6db6 1346
1347
13918578 1348 fPhiWin = new Double_t[fNloop];
1349 fLambdaWin = new Double_t[fNloop];
e340bb86 1350
e340bb86 1351 Double_t factor=AliITSReconstructor::GetRecoParam()->GetFactorSAWindowSizes(); // possibility to enlarge windows for cosmics reco with large misalignments (A.Dainese)
2755f080 1352
1353 for(Int_t k=0;k<fNloop;k++){
e340bb86 1354 fPhiWin[k]=phid[k]*factor;
1355 fLambdaWin[k]=lambdad[k]*factor;
13918578 1356 }
1357
1358 }
1359
1360}
7e5bf5af 1361//_______________________________________________________________________
cc088660 1362void AliITStrackerSA::GetCoorAngles(AliITSRecPoint* cl,Double_t &phi,Double_t &lambda, Float_t &x, Float_t &y,Float_t &z,Double_t* vertex){
7e5bf5af 1363 //Returns values of phi (azimuthal) and lambda angles for a given cluster
cc088660 1364/*
7e5bf5af 1365 Double_t rot[9]; fGeom->GetRotMatrix(module,rot);
1366 Int_t lay,lad,det; fGeom->GetModuleId(module,lay,lad,det);
1367 Float_t tx,ty,tz; fGeom->GetTrans(lay,lad,det,tx,ty,tz);
1368
1369 Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
1370 Double_t phi1=TMath::Pi()/2+alpha;
1371 if (lay==1) phi1+=TMath::Pi();
1372
1373 Float_t cp=TMath::Cos(phi1), sp=TMath::Sin(phi1);
1374 Float_t r=tx*cp+ty*sp;
1375
cc088660 1376 xyz= r*cp - cl->GetY()*sp;
7e5bf5af 1377 y= r*sp + cl->GetY()*cp;
1378 z=cl->GetZ();
cc088660 1379*/
1380 Float_t xyz[3];
1381 cl->GetGlobalXYZ(xyz);
1382 x=xyz[0];
1383 y=xyz[1];
1384 z=xyz[2];
1385
1966f03c 1386 phi=TMath::ATan2(y-vertex[1],x-vertex[0]);
7e5bf5af 1387 lambda=TMath::ATan2(z-vertex[2],TMath::Sqrt((x-vertex[0])*(x-vertex[0])+(y-vertex[1])*(y-vertex[1])));
1388}
13918578 1389
7e5bf5af 1390//________________________________________________________________________
cc088660 1391void AliITStrackerSA::GetCoorErrors(AliITSRecPoint* cl,Float_t &sx,Float_t &sy, Float_t &sz){
7e5bf5af 1392
cc088660 1393 //returns sigmax, y, z of cluster in global coordinates
1394/*
7e5bf5af 1395 Double_t rot[9]; fGeom->GetRotMatrix(module,rot);
cc088660 1396 Int_t lay,lad,det;
1397 AliITSgeomTGeo::GetModuleId(module,lay,lad,det);
7e5bf5af 1398
1399 Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
1400 Double_t phi=TMath::Pi()/2+alpha;
1401 if (lay==1) phi+=TMath::Pi();
1402
1403 Float_t cp=TMath::Cos(phi), sp=TMath::Sin(phi);
cc088660 1404*/
1405 Float_t covm[6];
1406 cl->GetGlobalCov(covm);
1407 sx=TMath::Sqrt(covm[0]);
1408 sy=TMath::Sqrt(covm[3]);
1409 sz=TMath::Sqrt(covm[5]);
1410/*
7e5bf5af 1411 sx = TMath::Sqrt(sp*sp*cl->GetSigmaY2());
1412 sy = TMath::Sqrt(cp*cp*cl->GetSigmaY2());
1413 sz = TMath::Sqrt(cl->GetSigmaZ2());
cc088660 1414*/
7e5bf5af 1415}