- for(Int_t l1=0;l1<end[0];l1++){//loop on layer 1
- AliITSclusterV2* cl0 = (AliITSclusterV2*)listlayer[0]->At(l1);
- TVector3** recp = new TVector3*[3];
- TVector3** errs = new TVector3*[3];
- recp[0] = new TVector3(primaryVertex[0],primaryVertex[1],primaryVertex[2]);
- errs[0] = new TVector3(errorsprimvert[0],errorsprimvert[1],errorsprimvert[2]);
- Double_t x1,y1,z1,sx1,sy1,sz1;
- Double_t x2,y2,z2,sx2,sy2,sz2;
- AliITSclusterV2* p1=0;
- AliITSclusterV2* p2=0;
-
- for(Int_t l2=0;l2<end[1];l2++){//loop on layer 2
- AliITSclusterV2* cl1 = (AliITSclusterV2*)listlayer[1]->At(l2);
- for(Int_t l3=0;l3<end[2];l3++){ //loop on layer 3
- AliITSclusterV2* cl2 = (AliITSclusterV2*)listlayer[2]->At(l3);
-
- if(cl0==0 && cl1!=0) {
- p2 = cl2;
- p1=cl1;
-
- }
- if(cl0!=0 && cl1==0){
- p1=cl0;
- p2=cl2;
- }
- if(cl0!=0 && cl1!=0){
- p1=cl0;
- p2=cl1;
- }
- Int_t module1 = p1->GetDetectorIndex()+firstmod[0];
- Int_t module2 = p2->GetDetectorIndex()+firstmod[1];
- GetClusterGCoordinates(p1,module1,x1,y1,z1);
- GetClusterGCoordinates(p2,module2,x2,y2,z2);
- GetClusterGErrors(p1,module1,sx1,sy1,sz1);
- GetClusterGErrors(p2,module2,sx2,sy2,sz2);
- Double_t phi1=TMath::ATan2(y1,x1);
- recp[1] = new TVector3(x1,y1,z1);
- errs[1] = new TVector3(sx1,sy1,sz1);
- recp[2] = new TVector3(x2,y2,z2);
- errs[2] = new TVector3(sx2,sy2,sz2);
-
- //fit on the Riemann sphere
- Float_t seed1,seed2,seed3;
- AliITSRiemannFit fit;
- Int_t rf = fit.FitHelix(3,recp,errs,seed1,seed2,seed3); //this gives phi,tgl,curvature to start Kalman Filter
- if(rf==0) continue;
- Double_t phi=seed1;
- Double_t tgl=seed2;
-
- if(phi1>0){
- if(seed1>-TMath::Pi() && seed1<-0.5*TMath::Pi()){
- phi=seed1+1.5*TMath::Pi();
- tgl=seed2;
- }
- if(seed1>-0.5*TMath::Pi() && seed1<0.5*TMath::Pi()){
- phi=seed1+0.5*TMath::Pi();
- tgl=(-1)*seed2;
- }
- if(seed1>0.5*TMath::Pi() && seed1<TMath::Pi()){
- phi=seed1-0.5*TMath::Pi();
- tgl=seed2;
- }
- }
- if(phi1<0){
- if(seed1>-TMath::Pi() && seed1<-0.5*TMath::Pi()){
- phi=seed1+0.5*TMath::Pi();
- tgl=(-1)*seed2;
- }
- if(seed1>-0.5*TMath::Pi() && seed1<0.5*TMath::Pi()){
- phi=seed1-0.5*TMath::Pi();
- tgl=seed2;
- }
- if(seed1>0.5*TMath::Pi() && seed1<TMath::Pi()){
- phi=seed1-1.5*TMath::Pi();
- tgl=(-1)*seed2;
- }
- }
-
- Int_t layer,ladder,detector;
- fGeom->GetModuleId(module1,layer,ladder,detector);
- Float_t yclu1 = p1->GetY();
- Float_t zclu1 = p1->GetZ();
- Double_t cv=Curvature(primaryVertex[0],primaryVertex[1],x1,y1,x2,y2);
-
- for(Int_t l4=0;l4<end[3];l4++){ //loop on layer 4
- AliITSclusterV2* cl3 = (AliITSclusterV2*)listlayer[3]->At(l4);
- for(Int_t l5=0;l5<end[4];l5++){ //loop on layer 5
- AliITSclusterV2* cl4 = (AliITSclusterV2*)listlayer[4]->At(l5);
- for(Int_t l6=0;l6<end[5];l6++){ //loop on layer 6
- AliITSclusterV2* cl5 = (AliITSclusterV2*)listlayer[5]->At(l6);
- AliITStrackSA* trac = new AliITStrackSA(layer,ladder,detector,yclu1,zclu1,phi,tgl,cv,1);
-
- if(cl5!=0) trac->AddClusterV2(5,(clind5[l6] & 0x0fffffff)>>0);
- if(cl4!=0) trac->AddClusterV2(4,(clind4[l5] & 0x0fffffff)>>0);
- if(cl3!=0) trac->AddClusterV2(3,(clind3[l4] & 0x0fffffff)>>0);
- if(cl2!=0) trac->AddClusterV2(2,(clind2[l3] & 0x0fffffff)>>0);
- if(cl1!=0) trac->AddClusterV2(1,(clind1[l2] & 0x0fffffff)>>0);
- if(cl0!=0) trac->AddClusterV2(0,(clind0[l1] & 0x0fffffff)>>0);
-
- //fit with Kalman filter using AliITStrackerV2::RefitAt()
-
- AliITStrackV2* ot = new AliITStrackV2(*trac);
-
- ot->ResetCovariance();
- ot->ResetClusters();
-
- if(RefitAt(49.,ot,trac)){ //fit from layer 1 to layer 6
-
- otrack2 = new AliITStrackV2(*ot);
- otrack2->ResetCovariance();
- otrack2->ResetClusters();
- //fit from layer 6 to layer 1
- if(RefitAt(3.7,otrack2,ot)) listoftracks->AddLast(otrack2);
-
- }
-
- delete ot;
- delete trac;
- }//end loop layer 6
- }//end loop layer 5
- }//end loop layer 4
-
- for(Int_t i=1;i<3;i++){
- delete recp[i];
- delete errs[i];
- }
+
+ Int_t firstLay=-1,secondLay=-1;
+ for(Int_t i=0;i<AliITSgeomTGeo::GetNLayers();i++) {
+ if(end[i]==0) {
+ end[i]=1;
+ }else{
+ if(firstLay==-1) {
+ firstLay=i;
+ } else if(secondLay==-1) {
+ secondLay=i;
+ }
+ }
+ }
+
+ if(firstLay==-1 || (secondLay==-1 && !onePoint)) return 0;
+ TClonesArray &arrMI= *fListOfTracks;
+ TClonesArray &arrSA= *fListOfSATracks;
+ Int_t nFoundTracks=0;
+
+
+ for(Int_t l0=0;l0<end[0];l0++){ //loop on layer 1
+ indices[0]=l0;
+ for(Int_t l1=0;l1<end[1];l1++){ //loop on layer 2
+ indices[1]=l1;
+ for(Int_t l2=0;l2<end[2];l2++){ //loop on layer 3
+ indices[2]=l2;
+ for(Int_t l3=0;l3<end[3];l3++){ //loop on layer 4
+ indices[3]=l3;
+ for(Int_t l4=0;l4<end[4];l4++){ //loop on layer 5
+ indices[4]=l4;
+ for(Int_t l5=0;l5<end[5];l5++){ //loop on layer 6
+ indices[5]=l5;
+
+ // estimate curvature from 2 innermost points (or innermost point + vertex)
+
+ Int_t iFirstLay=indices[firstLay];
+ Int_t mrk1=clmark[firstLay][iFirstLay];
+
+ AliITSRecPoint* p1=(AliITSRecPoint*)listlayer[firstLay][iFirstLay];
+ Int_t module1 = p1->GetDetectorIndex()+firstmod[firstLay];
+ Int_t layer,ladder,detector;
+ AliITSgeomTGeo::GetModuleId(module1,layer,ladder,detector);
+ Double_t yclu1 = p1->GetY();
+ Double_t zclu1 = p1->GetZ();
+
+ Double_t x1,y1,z1;
+ Double_t x2,y2,z2;
+ Double_t cv=0,tgl2=0,phi2=0;
+ AliITSclusterTable* arr1 = (AliITSclusterTable*)GetClusterCoord(firstLay,mrk1);
+ x1 = arr1->GetX();
+ y1 = arr1->GetY();
+ z1 = arr1->GetZ();
+
+ if(secondLay>0) {
+ Int_t iSecondLay=indices[secondLay];
+ Int_t mrk2=clmark[secondLay][iSecondLay];
+ AliITSclusterTable* arr2 = (AliITSclusterTable*)GetClusterCoord(secondLay,mrk2);
+ x2 = arr2->GetX();
+ y2 = arr2->GetY();
+ z2 = arr2->GetZ();
+ cv = Curvature(primaryVertex[0],primaryVertex[1],x1,y1,x2,y2);
+ tgl2 = (z2-z1)/TMath::Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
+ phi2 = TMath::ATan2((y2-y1),(x2-x1));
+ } else { // special case of 1-point tracks, only for cosmics (B=0)
+ x2 = primaryVertex[0];
+ y2 = primaryVertex[1];
+ z2 = primaryVertex[2];
+ cv = 0;
+ tgl2 = (z1-z2)/TMath::Sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
+ phi2 = TMath::ATan2((y1-y2),(x1-x2));
+ }
+
+ // create track and attach it the RecPoints
+ AliITStrackSA trac(layer,ladder,detector,yclu1,zclu1,phi2,tgl2,cv,1);
+ for(Int_t iLay=5; iLay>=0; iLay--){
+ Int_t iInLay=indices[iLay];
+ AliITSRecPoint* cl=(AliITSRecPoint*)listlayer[iLay][iInLay];
+ if(cl!=0){
+ trac.AddClusterV2(iLay,(clind[iLay][iInLay] & 0x0fffffff)>>0);
+ trac.AddClusterMark(iLay,clmark[iLay][iInLay]);
+ }
+ }
+
+ //fit with Kalman filter using AliITStrackerMI::RefitAt()
+ AliITStrackSA ot(trac);
+
+ ot.ResetCovariance(10.);
+ ot.ResetClusters();
+
+ // Propagate inside the innermost layer with a cluster
+ if(ot.Propagate(ot.GetX()-0.1*ot.GetX())) {
+
+ if(RefitAt(AliITSRecoParam::GetrInsideITSscreen(),&ot,&trac)){ //fit from layer 1 to layer 6
+ AliITStrackMI otrack2(ot);
+ otrack2.ResetCovariance(10.);
+ otrack2.ResetClusters();
+ //fit from layer 6 to layer 1
+ if(RefitAt(AliITSRecoParam::GetrInsideSPD1(),&otrack2,&ot)) {
+ new(arrMI[nFoundTracks]) AliITStrackMI(otrack2);
+ new(arrSA[nFoundTracks]) AliITStrackSA(trac);
+ ++nFoundTracks;
+ }
+
+ }
+ }
+ }//end loop layer 6
+ }//end loop layer 5
+ }//end loop layer 4