+ helixes[i0].GetAngle(phase[0][0],helixes[i1],phase[0][1],hangles);
+ Double_t deltah[2],deltabest;
+ if (hangles[2]<2.8) continue;
+ if (npoints>0){
+ Int_t ibest=0;
+ helixes[i0].ParabolicDCA(helixes[i1],phase[0][0],phase[0][1],radius[0],deltah[0],2);
+ if (npoints==2){
+ helixes[i0].ParabolicDCA(helixes[i1],phase[1][0],phase[1][1],radius[1],deltah[1],2);
+ if (deltah[1]<deltah[0]) ibest=1;
+ }
+ deltabest = TMath::Sqrt(deltah[ibest]);
+ helixes[i0].Evaluate(phase[ibest][0],xyz0);
+ helixes[i1].Evaluate(phase[ibest][1],xyz1);
+ helixes[i0].GetAngle(phase[ibest][0],helixes[i1],phase[ibest][1],hangles);
+ Double_t radiusbest = TMath::Sqrt(radius[ibest]);
+ //
+ if (deltabest>6) continue;
+ if (mindcar+mindcaz<40 && (hangles[2]<3.12||deltabest>3)) continue;
+ Bool_t lsign =kFALSE;
+ if (hangles[2]>3.06) lsign =kTRUE;
+ //
+ if (lsign){
+ circular[i0] = kTRUE;
+ circular[i1] = kTRUE;
+ if (track0->OneOverPt()<track1->OneOverPt()){
+ track0->SetCircular(track0->GetCircular()+1);
+ track1->SetCircular(track1->GetCircular()+2);
+ }
+ else{
+ track1->SetCircular(track1->GetCircular()+1);
+ track0->SetCircular(track0->GetCircular()+2);
+ }
+ }
+ if (lsign&&AliTPCReconstructor::StreamLevel()>1){
+ //debug stream
+ Int_t lab0=track0->GetLabel();
+ Int_t lab1=track1->GetLabel();
+ TTreeSRedirector &cstream = *fDebugStreamer;
+ cstream<<"Curling"<<
+ "lab0="<<lab0<<
+ "lab1="<<lab1<<
+ "Tr0.="<<track0<<
+ "Tr1.="<<track1<<
+ "dca0="<<dca[i0]<<
+ "dca1="<<dca[i1]<<
+ "mindcar="<<mindcar<<
+ "mindcaz="<<mindcaz<<
+ "delta="<<delta<<
+ "rmean="<<rmean<<
+ "npoints="<<npoints<<
+ "hangles0="<<hangles[0]<<
+ "hangles2="<<hangles[2]<<
+ "xyz0="<<xyz0[2]<<
+ "xyzz1="<<xyz1[2]<<
+ "z0="<<z0[i0]<<
+ "z1="<<z0[i1]<<
+ "radius="<<radiusbest<<
+ "deltabest="<<deltabest<<
+ "phase0="<<phase[ibest][0]<<
+ "phase1="<<phase[ibest][1]<<
+ "\n";
+ }
+ }
+ }
+ }
+ //
+ // Finf kinks loop
+ //
+ //
+ for (Int_t i =0;i<nentries;i++){
+ if (sign[i]==0) continue;
+ AliTPCseed * track0 = (AliTPCseed*)array->At(i);
+ if (track0==0) {
+ AliInfo("seed==0");
+ continue;
+ }
+ ntracks++;
+ //
+ Double_t cradius0 = 40*40;
+ Double_t cradius1 = 270*270;
+ Double_t cdist1=8.;
+ Double_t cdist2=8.;
+ Double_t cdist3=0.55;
+ for (Int_t j =i+1;j<nentries;j++){
+ nall++;
+ if (sign[j]*sign[i]<1) continue;
+ if ( (nclusters[i]+nclusters[j])>200) continue;
+ if ( (nclusters[i]+nclusters[j])<80) continue;
+ if ( TMath::Abs(zm[i]-zm[j])>60.) continue;
+ if ( TMath::Abs(fim[i]-fim[j])>0.6 && TMath::Abs(fim[i]-fim[j])<5.7 ) continue;
+ //AliTPCseed * track1 = (AliTPCseed*)array->At(j); Double_t phase[2][2],radius[2];
+ Int_t npoints = helixes[i].GetRPHIintersections(helixes[j], phase, radius,20);
+ if (npoints<1) continue;
+ // cuts on radius
+ if (npoints==1){
+ if (radius[0]<cradius0||radius[0]>cradius1) continue;
+ }
+ else{
+ if ( (radius[0]<cradius0||radius[0]>cradius1) && (radius[1]<cradius0||radius[1]>cradius1) ) continue;
+ }
+ //
+ Double_t delta1=10000,delta2=10000;
+ // cuts on the intersection radius
+ helixes[i].LinearDCA(helixes[j],phase[0][0],phase[0][1],radius[0],delta1);
+ if (radius[0]<20&&delta1<1) continue; //intersection at vertex
+ if (radius[0]<10&&delta1<3) continue; //intersection at vertex
+ if (npoints==2){
+ helixes[i].LinearDCA(helixes[j],phase[1][0],phase[1][1],radius[1],delta2);
+ if (radius[1]<20&&delta2<1) continue; //intersection at vertex
+ if (radius[1]<10&&delta2<3) continue; //intersection at vertex
+ }
+ //
+ Double_t distance1 = TMath::Min(delta1,delta2);
+ if (distance1>cdist1) continue; // cut on DCA linear approximation
+ //
+ npoints = helixes[i].GetRPHIintersections(helixes[j], phase, radius,20);
+ helixes[i].ParabolicDCA(helixes[j],phase[0][0],phase[0][1],radius[0],delta1);
+ if (radius[0]<20&&delta1<1) continue; //intersection at vertex
+ if (radius[0]<10&&delta1<3) continue; //intersection at vertex
+ //
+ if (npoints==2){
+ helixes[i].ParabolicDCA(helixes[j],phase[1][0],phase[1][1],radius[1],delta2);
+ if (radius[1]<20&&delta2<1) continue; //intersection at vertex
+ if (radius[1]<10&&delta2<3) continue; //intersection at vertex
+ }
+ distance1 = TMath::Min(delta1,delta2);
+ Float_t rkink =0;
+ if (delta1<delta2){
+ rkink = TMath::Sqrt(radius[0]);
+ }
+ else{
+ rkink = TMath::Sqrt(radius[1]);
+ }
+ if (distance1>cdist2) continue;
+ //
+ //
+ AliTPCseed * track1 = (AliTPCseed*)array->At(j);
+ //
+ //
+ Int_t row0 = GetRowNumber(rkink);
+ if (row0<10) continue;
+ if (row0>150) continue;
+ //
+ //
+ Float_t dens00=-1,dens01=-1;
+ Float_t dens10=-1,dens11=-1;
+ //
+ Int_t found,foundable,ishared;
+ track0->GetClusterStatistic(0,row0-5, found, foundable,ishared,kFALSE);
+ if (foundable>5) dens00 = Float_t(found)/Float_t(foundable);
+ track0->GetClusterStatistic(row0+5,155, found, foundable,ishared,kFALSE);
+ if (foundable>5) dens01 = Float_t(found)/Float_t(foundable);
+ //
+ track1->GetClusterStatistic(0,row0-5, found, foundable,ishared,kFALSE);
+ if (foundable>10) dens10 = Float_t(found)/Float_t(foundable);
+ track1->GetClusterStatistic(row0+5,155, found, foundable,ishared,kFALSE);
+ if (foundable>10) dens11 = Float_t(found)/Float_t(foundable);
+ //
+ if (dens00<dens10 && dens01<dens11) continue;
+ if (dens00>dens10 && dens01>dens11) continue;
+ if (TMath::Max(dens00,dens10)<0.1) continue;
+ if (TMath::Max(dens01,dens11)<0.3) continue;
+ //
+ if (TMath::Min(dens00,dens10)>0.6) continue;
+ if (TMath::Min(dens01,dens11)>0.6) continue;
+
+ //
+ AliTPCseed * ktrack0, *ktrack1;
+ if (dens00>dens10){
+ ktrack0 = track0;
+ ktrack1 = track1;
+ }
+ else{
+ ktrack0 = track1;
+ ktrack1 = track0;
+ }
+ if (TMath::Abs(ktrack0->GetC())>5) continue; // cut on the curvature for mother particle
+ AliExternalTrackParam paramm(*ktrack0);
+ AliExternalTrackParam paramd(*ktrack1);
+ if (row0>60&&ktrack1->GetReference().GetX()>90.)new (¶md) AliExternalTrackParam(ktrack1->GetReference());
+ //
+ //
+ kink->SetMother(paramm);
+ kink->SetDaughter(paramd);
+ kink->Update();
+
+ Float_t x[3] = { kink->GetPosition()[0],kink->GetPosition()[1],kink->GetPosition()[2]};
+ Int_t index[4];
+ fkParam->Transform0to1(x,index);
+ fkParam->Transform1to2(x,index);
+ row0 = GetRowNumber(x[0]);
+
+ if (kink->GetR()<100) continue;
+ if (kink->GetR()>240) continue;
+ if (kink->GetPosition()[2]/kink->GetR()>AliTPCReconstructor::GetCtgRange()) continue; //out of fiducial volume
+ if (kink->GetDistance()>cdist3) continue;
+ Float_t dird = kink->GetDaughterP()[0]*kink->GetPosition()[0]+kink->GetDaughterP()[1]*kink->GetPosition()[1]; // rough direction estimate
+ if (dird<0) continue;
+
+ Float_t dirm = kink->GetMotherP()[0]*kink->GetPosition()[0]+kink->GetMotherP()[1]*kink->GetPosition()[1]; // rough direction estimate
+ if (dirm<0) continue;
+ Float_t mpt = TMath::Sqrt(kink->GetMotherP()[0]*kink->GetMotherP()[0]+kink->GetMotherP()[1]*kink->GetMotherP()[1]);
+ if (mpt<0.2) continue;
+
+ if (mpt<1){
+ //for high momenta momentum not defined well in first iteration
+ Double_t qt = TMath::Sin(kink->GetAngle(2))*ktrack1->GetP();
+ if (qt>0.35) continue;
+ }
+
+ kink->SetLabel(CookLabel(ktrack0,0.4,0,row0),0);
+ kink->SetLabel(CookLabel(ktrack1,0.4,row0,160),1);
+ if (dens00>dens10){
+ kink->SetTPCDensity(dens00,0,0);
+ kink->SetTPCDensity(dens01,0,1);
+ kink->SetTPCDensity(dens10,1,0);
+ kink->SetTPCDensity(dens11,1,1);
+ kink->SetIndex(i,0);
+ kink->SetIndex(j,1);
+ }
+ else{
+ kink->SetTPCDensity(dens10,0,0);
+ kink->SetTPCDensity(dens11,0,1);
+ kink->SetTPCDensity(dens00,1,0);
+ kink->SetTPCDensity(dens01,1,1);
+ kink->SetIndex(j,0);
+ kink->SetIndex(i,1);
+ }
+
+ if (mpt<1||kink->GetAngle(2)>0.1){
+ // angle and densities not defined yet
+ if (kink->GetTPCDensityFactor()<0.8) continue;
+ if ((2-kink->GetTPCDensityFactor())*kink->GetDistance() >0.25) continue;
+ if (kink->GetAngle(2)*ktrack0->GetP()<0.003) continue; //too small angle
+ if (kink->GetAngle(2)>0.2&&kink->GetTPCDensityFactor()<1.15) continue;
+ if (kink->GetAngle(2)>0.2&&kink->GetTPCDensity(0,1)>0.05) continue;
+
+ Float_t criticalangle = track0->GetSigmaSnp2()+track0->GetSigmaTgl2();
+ criticalangle+= track1->GetSigmaSnp2()+track1->GetSigmaTgl2();
+ criticalangle= 3*TMath::Sqrt(criticalangle);
+ if (criticalangle>0.02) criticalangle=0.02;
+ if (kink->GetAngle(2)<criticalangle) continue;
+ }
+ //
+ Int_t drow = Int_t(2.+0.5/(0.05+kink->GetAngle(2))); // overlap region defined
+ Float_t shapesum =0;
+ Float_t sum = 0;
+ for ( Int_t row = row0-drow; row<row0+drow;row++){
+ if (row<0) continue;
+ if (row>155) continue;
+ if (ktrack0->GetClusterPointer(row)){
+ AliTPCTrackerPoint *point =ktrack0->GetTrackPoint(row);
+ shapesum+=point->GetSigmaY()+point->GetSigmaZ();
+ sum++;
+ }
+ if (ktrack1->GetClusterPointer(row)){
+ AliTPCTrackerPoint *point =ktrack1->GetTrackPoint(row);
+ shapesum+=point->GetSigmaY()+point->GetSigmaZ();
+ sum++;
+ }
+ }
+ if (sum<4){
+ kink->SetShapeFactor(-1.);
+ }
+ else{
+ kink->SetShapeFactor(shapesum/sum);
+ }
+ // esd->AddKink(kink);
+ //
+ // kink->SetMother(paramm);
+ //kink->SetDaughter(paramd);
+
+ Double_t chi2P2 = paramm.GetParameter()[2]-paramd.GetParameter()[2];
+ chi2P2*=chi2P2;
+ chi2P2/=paramm.GetCovariance()[5]+paramd.GetCovariance()[5];
+ Double_t chi2P3 = paramm.GetParameter()[3]-paramd.GetParameter()[3];
+ chi2P3*=chi2P3;
+ chi2P3/=paramm.GetCovariance()[9]+paramd.GetCovariance()[9];
+ //
+ if (AliTPCReconstructor::StreamLevel()>1) {
+ (*fDebugStreamer)<<"kinkLpt"<<
+ "chi2P2="<<chi2P2<<
+ "chi2P3="<<chi2P3<<
+ "p0.="<<¶mm<<
+ "p1.="<<¶md<<
+ "k.="<<kink<<
+ "\n";
+ }
+ if ( chi2P2+chi2P3<AliTPCReconstructor::GetRecoParam()->GetKinkAngleCutChi2(0)){
+ continue;
+ }
+ //
+ kinks->AddLast(kink);
+ kink = new AliKink;
+ ncandidates++;
+ }
+ }
+ //
+ // sort the kinks according quality - and refit them towards vertex
+ //
+ Int_t nkinks = kinks->GetEntriesFast();
+ Float_t *quality = new Float_t[nkinks];
+ Int_t *indexes = new Int_t[nkinks];
+ AliTPCseed **mothers = new AliTPCseed*[nkinks]; memset(mothers, 0, nkinks*sizeof(AliTPCseed*));
+ AliTPCseed **daughters = new AliTPCseed*[nkinks]; memset(daughters, 0, nkinks*sizeof(AliTPCseed*));
+ //
+ //
+ for (Int_t i=0;i<nkinks;i++){
+ quality[i] =100000;
+ AliKink *kinkl = (AliKink*)kinks->At(i);
+ //
+ // refit kinks towards vertex
+ //
+ Int_t index0 = kinkl->GetIndex(0);
+ Int_t index1 = kinkl->GetIndex(1);
+ AliTPCseed * ktrack0 = (AliTPCseed*)array->At(index0);
+ AliTPCseed * ktrack1 = (AliTPCseed*)array->At(index1);
+ //
+ Int_t sumn=ktrack0->GetNumberOfClusters()+ktrack1->GetNumberOfClusters();
+ //
+ // Refit Kink under if too small angle
+ //
+ if (kinkl->GetAngle(2)<0.05){
+ kinkl->SetTPCRow0(GetRowNumber(kinkl->GetR()));
+ Int_t row0 = kinkl->GetTPCRow0();
+ Int_t drow = Int_t(2.+0.5/(0.05+kinkl->GetAngle(2)));
+ //
+ //
+ Int_t last = row0-drow;
+ if (last<40) last=40;
+ if (last<ktrack0->GetFirstPoint()+25) last = ktrack0->GetFirstPoint()+25;
+ AliTPCseed* seed0 = ReSeed(ktrack0,last,kFALSE);
+ //
+ //
+ Int_t first = row0+drow;
+ if (first>130) first=130;
+ if (first>ktrack1->GetLastPoint()-25) first = TMath::Max(ktrack1->GetLastPoint()-25,30);
+ AliTPCseed* seed1 = ReSeed(ktrack1,first,kTRUE);
+ //
+ if (seed0 && seed1){
+ kinkl->SetStatus(1,8);
+ if (RefitKink(*seed0,*seed1,*kinkl)) kinkl->SetStatus(1,9);
+ row0 = GetRowNumber(kinkl->GetR());
+ sumn = seed0->GetNumberOfClusters()+seed1->GetNumberOfClusters();
+ mothers[i] = new ( NextFreeSeed() ) AliTPCseed(*seed0);
+ mothers[i]->SetPoolID(fLastSeedID);
+ daughters[i] = new (NextFreeSeed() ) AliTPCseed(*seed1);
+ daughters[i]->SetPoolID(fLastSeedID);
+ }
+ else{
+ delete kinks->RemoveAt(i);
+ if (seed0) MarkSeedFree( seed0 );
+ if (seed1) MarkSeedFree( seed1 );
+ continue;
+ }
+ if (kinkl->GetDistance()>0.5 || kinkl->GetR()<110 || kinkl->GetR()>240) {
+ delete kinks->RemoveAt(i);
+ if (seed0) MarkSeedFree( seed0 );
+ if (seed1) MarkSeedFree( seed1 );
+ continue;
+ }
+ //
+ MarkSeedFree( seed0 );
+ MarkSeedFree( seed1 );
+ }
+ //
+ if (kinkl) quality[i] = 160*((0.1+kinkl->GetDistance())*(2.-kinkl->GetTPCDensityFactor()))/(sumn+40.); //the longest -clossest will win
+ }
+ TMath::Sort(nkinks,quality,indexes,kFALSE);
+ //
+ //remove double find kinks
+ //
+ for (Int_t ikink0=1;ikink0<nkinks;ikink0++){
+ AliKink * kink0 = (AliKink*) kinks->At(indexes[ikink0]);
+ if (!kink0) continue;
+ //
+ for (Int_t ikink1=0;ikink1<ikink0;ikink1++){
+ kink0 = (AliKink*) kinks->At(indexes[ikink0]);
+ if (!kink0) continue;
+ AliKink * kink1 = (AliKink*) kinks->At(indexes[ikink1]);
+ if (!kink1) continue;
+ // if not close kink continue
+ if (TMath::Abs(kink1->GetPosition()[2]-kink0->GetPosition()[2])>10) continue;
+ if (TMath::Abs(kink1->GetPosition()[1]-kink0->GetPosition()[1])>10) continue;
+ if (TMath::Abs(kink1->GetPosition()[0]-kink0->GetPosition()[0])>10) continue;
+ //
+ AliTPCseed &mother0 = *mothers[indexes[ikink0]];
+ AliTPCseed &daughter0 = *daughters[indexes[ikink0]];
+ AliTPCseed &mother1 = *mothers[indexes[ikink1]];
+ AliTPCseed &daughter1 = *daughters[indexes[ikink1]];
+ Int_t row0 = (kink0->GetTPCRow0()+kink1->GetTPCRow0())/2;
+ //
+ Int_t same = 0;
+ Int_t both = 0;
+ Int_t samem = 0;
+ Int_t bothm = 0;
+ Int_t samed = 0;
+ Int_t bothd = 0;
+ //
+ for (Int_t i=0;i<row0;i++){
+ if (mother0.GetClusterIndex(i)>0 && mother1.GetClusterIndex(i)>0){
+ both++;
+ bothm++;
+ if (mother0.GetClusterIndex(i)==mother1.GetClusterIndex(i)){
+ same++;
+ samem++;
+ }
+ }
+ }
+
+ for (Int_t i=row0;i<158;i++){
+ //if (daughter0.GetClusterIndex(i)>0 && daughter0.GetClusterIndex(i)>0){ // RS: Bug?
+ if (daughter0.GetClusterIndex(i)>0 && daughter1.GetClusterIndex(i)>0){
+ both++;
+ bothd++;
+ if (mother0.GetClusterIndex(i)==mother1.GetClusterIndex(i)){
+ same++;
+ samed++;
+ }
+ }
+ }
+ Float_t ratio = Float_t(same+1)/Float_t(both+1);
+ Float_t ratiom = Float_t(samem+1)/Float_t(bothm+1);
+ Float_t ratiod = Float_t(samed+1)/Float_t(bothd+1);
+ if (ratio>0.3 && ratiom>0.5 &&ratiod>0.5) {
+ Int_t sum0 = mother0.GetNumberOfClusters()+daughter0.GetNumberOfClusters();
+ Int_t sum1 = mother1.GetNumberOfClusters()+daughter1.GetNumberOfClusters();
+ if (sum1>sum0){
+ shared[kink0->GetIndex(0)]= kTRUE;
+ shared[kink0->GetIndex(1)]= kTRUE;
+ delete kinks->RemoveAt(indexes[ikink0]);
+ break;
+ }
+ else{
+ shared[kink1->GetIndex(0)]= kTRUE;
+ shared[kink1->GetIndex(1)]= kTRUE;
+ delete kinks->RemoveAt(indexes[ikink1]);
+ }
+ }
+ }
+ }
+
+
+ for (Int_t i=0;i<nkinks;i++){
+ AliKink * kinkl = (AliKink*) kinks->At(indexes[i]);
+ if (!kinkl) continue;
+ kinkl->SetTPCRow0(GetRowNumber(kinkl->GetR()));
+ Int_t index0 = kinkl->GetIndex(0);
+ Int_t index1 = kinkl->GetIndex(1);
+ if (circular[index0]||(circular[index1]&&kinkl->GetDistance()>0.2)) continue;
+ kinkl->SetMultiple(usage[index0],0);
+ kinkl->SetMultiple(usage[index1],1);
+ if (kinkl->GetMultiple()[0]+kinkl->GetMultiple()[1]>2) continue;
+ if (kinkl->GetMultiple()[0]+kinkl->GetMultiple()[1]>0 && quality[indexes[i]]>0.2) continue;
+ if (kinkl->GetMultiple()[0]+kinkl->GetMultiple()[1]>0 && kinkl->GetDistance()>0.2) continue;
+ if (circular[index0]||(circular[index1]&&kinkl->GetDistance()>0.1)) continue;
+
+ AliTPCseed * ktrack0 = (AliTPCseed*)array->At(index0);
+ AliTPCseed * ktrack1 = (AliTPCseed*)array->At(index1);
+ if (!ktrack0 || !ktrack1) continue;
+ Int_t index = esd->AddKink(kinkl);
+ //
+ //
+ if ( ktrack0->GetKinkIndex(0)==0 && ktrack1->GetKinkIndex(0)==0) { //best kink
+ if (mothers[indexes[i]]->GetNumberOfClusters()>20 && daughters[indexes[i]]->GetNumberOfClusters()>20 &&
+ (mothers[indexes[i]]->GetNumberOfClusters()+daughters[indexes[i]]->GetNumberOfClusters())>100){
+ *ktrack0 = *mothers[indexes[i]];
+ *ktrack1 = *daughters[indexes[i]];
+ }
+ }
+ //
+ ktrack0->SetKinkIndex(usage[index0],-(index+1));
+ ktrack1->SetKinkIndex(usage[index1], (index+1));
+ usage[index0]++;
+ usage[index1]++;
+ }
+ //
+ // Remove tracks corresponding to shared kink's
+ //
+ for (Int_t i=0;i<nentries;i++){
+ AliTPCseed * track0 = (AliTPCseed*)array->At(i);
+ if (!track0) continue;
+ if (track0->GetKinkIndex(0)!=0) continue;
+ if (shared[i]) MarkSeedFree( array->RemoveAt(i) );
+ }
+
+ //
+ //
+ RemoveUsed2(array,0.5,0.4,30);
+ UnsignClusters();
+ for (Int_t i=0;i<nentries;i++){
+ AliTPCseed * track0 = (AliTPCseed*)array->At(i);
+ if (!track0) continue;
+ track0->CookdEdx(0.02,0.6);
+ track0->CookPID();
+ }
+ //
+ for (Int_t i=0;i<nentries;i++){
+ AliTPCseed * track0 = (AliTPCseed*)array->At(i);
+ if (!track0) continue;
+ if (track0->Pt()<1.4) continue;
+ //remove double high momenta tracks - overlapped with kink candidates
+ Int_t ishared=0;
+ Int_t all =0;
+ for (Int_t icl=track0->GetFirstPoint();icl<track0->GetLastPoint(); icl++){
+ if (track0->GetClusterPointer(icl)!=0){
+ all++;
+ if (track0->GetClusterPointer(icl)->IsUsed(10)) ishared++;
+ }
+ }
+ if (Float_t(ishared+1)/Float_t(all+1)>0.5) {
+ MarkSeedFree( array->RemoveAt(i) );
+ continue;
+ }
+ //
+ if (track0->GetKinkIndex(0)!=0) continue;
+ if (track0->GetNumberOfClusters()<80) continue;
+
+ AliTPCseed *pmother = new( NextFreeSeed() ) AliTPCseed();
+ pmother->SetPoolID(fLastSeedID);
+ AliTPCseed *pdaughter = new( NextFreeSeed() ) AliTPCseed();
+ pdaughter->SetPoolID(fLastSeedID);
+ AliKink *pkink = new AliKink;
+
+ AliTPCseed & mother = *pmother;
+ AliTPCseed & daughter = *pdaughter;
+ AliKink & kinkl = *pkink;
+ if (CheckKinkPoint(track0,mother,daughter, kinkl)){
+ if (mother.GetNumberOfClusters()<30||daughter.GetNumberOfClusters()<20) {
+ MarkSeedFree( pmother );
+ MarkSeedFree( pdaughter );
+ delete pkink;
+ continue; //too short tracks
+ }
+ if (mother.Pt()<1.4) {
+ MarkSeedFree( pmother );
+ MarkSeedFree( pdaughter );
+ delete pkink;
+ continue;
+ }
+ Int_t row0= kinkl.GetTPCRow0();
+ if (kinkl.GetDistance()>0.5 || kinkl.GetR()<110. || kinkl.GetR()>240.) {
+ MarkSeedFree( pmother );
+ MarkSeedFree( pdaughter );
+ delete pkink;
+ continue;
+ }
+ //
+ Int_t index = esd->AddKink(&kinkl);
+ mother.SetKinkIndex(0,-(index+1));
+ daughter.SetKinkIndex(0,index+1);
+ if (mother.GetNumberOfClusters()>50) {
+ MarkSeedFree( array->RemoveAt(i) );
+ AliTPCseed* mtc = new( NextFreeSeed() ) AliTPCseed(mother);
+ mtc->SetPoolID(fLastSeedID);
+ array->AddAt(mtc,i);
+ }
+ else{
+ AliTPCseed* mtc = new( NextFreeSeed() ) AliTPCseed(mother);
+ mtc->SetPoolID(fLastSeedID);
+ array->AddLast(mtc);
+ }
+ AliTPCseed* dtc = new( NextFreeSeed() ) AliTPCseed(daughter);
+ dtc->SetPoolID(fLastSeedID);
+ array->AddLast(dtc);
+ for (Int_t icl=0;icl<row0;icl++) {
+ if (mother.GetClusterPointer(icl)) mother.GetClusterPointer(icl)->Use(20);
+ }
+ //
+ for (Int_t icl=row0;icl<158;icl++) {
+ if (daughter.GetClusterPointer(icl)) daughter.GetClusterPointer(icl)->Use(20);
+ }
+ //
+ }
+ MarkSeedFree( pmother );
+ MarkSeedFree( pdaughter );
+ delete pkink;
+ }
+
+ delete [] daughters;
+ delete [] mothers;
+ //
+ //
+ delete [] dca;
+ delete []circular;
+ delete []shared;
+ delete []quality;
+ delete []indexes;
+ //
+ delete kink;
+ delete[]fim;
+ delete[] zm;
+ delete[] z0;
+ delete [] usage;
+ delete[] alpha;
+ delete[] nclusters;
+ delete[] sign;
+ delete[] helixes;
+ kinks->Delete();
+ delete kinks;
+
+ AliInfo(Form("Ncandidates=\t%d\t%d\t%d\t%d\n",esd->GetNumberOfKinks(),ncandidates,ntracks,nall));
+ timer.Print();
+}
+*/
+
+Int_t AliTPCtrackerMI::RefitKink(AliTPCseed &mother, AliTPCseed &daughter, const AliESDkink &knk)
+{
+ //
+ // refit kink towards to the vertex
+ //
+ //
+ AliKink &kink=(AliKink &)knk;
+
+ Int_t row0 = GetRowNumber(kink.GetR());
+ FollowProlongation(mother,0);
+ mother.Reset(kFALSE);
+ //
+ FollowProlongation(daughter,row0);
+ daughter.Reset(kFALSE);
+ FollowBackProlongation(daughter,158);
+ daughter.Reset(kFALSE);
+ Int_t first = TMath::Max(row0-20,30);
+ Int_t last = TMath::Min(row0+20,140);
+ //
+ const Int_t kNdiv =5;
+ AliTPCseed param0[kNdiv]; // parameters along the track
+ AliTPCseed param1[kNdiv]; // parameters along the track
+ AliKink kinks[kNdiv]; // corresponding kink parameters
+ //
+ Int_t rows[kNdiv];
+ for (Int_t irow=0; irow<kNdiv;irow++){
+ rows[irow] = first +((last-first)*irow)/(kNdiv-1);
+ }
+ // store parameters along the track
+ //
+ for (Int_t irow=0;irow<kNdiv;irow++){
+ FollowBackProlongation(mother, rows[irow]);
+ FollowProlongation(daughter,rows[kNdiv-1-irow]);
+ param0[irow] = mother;
+ param1[kNdiv-1-irow] = daughter;
+ }
+ //
+ // define kinks
+ for (Int_t irow=0; irow<kNdiv-1;irow++){
+ if (param0[irow].GetNumberOfClusters()<kNdiv||param1[irow].GetNumberOfClusters()<kNdiv) continue;
+ kinks[irow].SetMother(param0[irow]);
+ kinks[irow].SetDaughter(param1[irow]);
+ kinks[irow].Update();
+ }
+ //
+ // choose kink with best "quality"
+ Int_t index =-1;
+ Double_t mindist = 10000;
+ for (Int_t irow=0;irow<kNdiv;irow++){
+ if (param0[irow].GetNumberOfClusters()<20||param1[irow].GetNumberOfClusters()<20) continue;
+ if (TMath::Abs(kinks[irow].GetR())>240.) continue;
+ if (TMath::Abs(kinks[irow].GetR())<100.) continue;
+ //
+ Float_t normdist = TMath::Abs(param0[irow].GetX()-kinks[irow].GetR())*(0.1+kink.GetDistance());
+ normdist/= (param0[irow].GetNumberOfClusters()+param1[irow].GetNumberOfClusters()+40.);
+ if (normdist < mindist){
+ mindist = normdist;
+ index = irow;
+ }
+ }
+ //
+ if (index==-1) return 0;
+ //
+ //
+ param0[index].Reset(kTRUE);
+ FollowProlongation(param0[index],0);
+ //
+ mother = param0[index];
+ daughter = param1[index]; // daughter in vertex
+ //
+ kink.SetMother(mother);
+ kink.SetDaughter(daughter);
+ kink.Update();
+ kink.SetTPCRow0(GetRowNumber(kink.GetR()));
+ kink.SetTPCncls(param0[index].GetNumberOfClusters(),0);
+ kink.SetTPCncls(param1[index].GetNumberOfClusters(),1);
+ kink.SetLabel(CookLabel(&mother,0.4, 0,kink.GetTPCRow0()),0);
+ kink.SetLabel(CookLabel(&daughter,0.4, kink.GetTPCRow0(),160),1);
+ mother.SetLabel(kink.GetLabel(0));
+ daughter.SetLabel(kink.GetLabel(1));
+
+ return 1;
+}
+
+
+void AliTPCtrackerMI::UpdateKinkQualityM(AliTPCseed * seed){
+ //
+ // update Kink quality information for mother after back propagation
+ //
+ if (seed->GetKinkIndex(0)>=0) return;
+ for (Int_t ikink=0;ikink<3;ikink++){
+ Int_t index = seed->GetKinkIndex(ikink);
+ if (index>=0) break;
+ index = TMath::Abs(index)-1;
+ AliESDkink * kink = fEvent->GetKink(index);
+ kink->SetTPCDensity(-1,0,0);
+ kink->SetTPCDensity(1,0,1);
+ //
+ Int_t row0 = kink->GetTPCRow0() - 2 - Int_t( 0.5/ (0.05+kink->GetAngle(2)));
+ if (row0<15) row0=15;
+ //
+ Int_t row1 = kink->GetTPCRow0() + 2 + Int_t( 0.5/ (0.05+kink->GetAngle(2)));
+ if (row1>145) row1=145;
+ //
+ Int_t found,foundable,shared;
+ seed->GetClusterStatistic(0,row0, found, foundable,shared,kFALSE);
+ if (foundable>5) kink->SetTPCDensity(Float_t(found)/Float_t(foundable),0,0);
+ seed->GetClusterStatistic(row1,155, found, foundable,shared,kFALSE);
+ if (foundable>5) kink->SetTPCDensity(Float_t(found)/Float_t(foundable),0,1);
+ }
+
+}
+
+void AliTPCtrackerMI::UpdateKinkQualityD(AliTPCseed * seed){
+ //
+ // update Kink quality information for daughter after refit
+ //
+ if (seed->GetKinkIndex(0)<=0) return;
+ for (Int_t ikink=0;ikink<3;ikink++){
+ Int_t index = seed->GetKinkIndex(ikink);
+ if (index<=0) break;
+ index = TMath::Abs(index)-1;
+ AliESDkink * kink = fEvent->GetKink(index);
+ kink->SetTPCDensity(-1,1,0);
+ kink->SetTPCDensity(-1,1,1);
+ //
+ Int_t row0 = kink->GetTPCRow0() -2 - Int_t( 0.5/ (0.05+kink->GetAngle(2)));
+ if (row0<15) row0=15;
+ //
+ Int_t row1 = kink->GetTPCRow0() +2 + Int_t( 0.5/ (0.05+kink->GetAngle(2)));
+ if (row1>145) row1=145;
+ //
+ Int_t found,foundable,shared;
+ seed->GetClusterStatistic(0,row0, found, foundable,shared,kFALSE);
+ if (foundable>5) kink->SetTPCDensity(Float_t(found)/Float_t(foundable),1,0);
+ seed->GetClusterStatistic(row1,155, found, foundable,shared,kFALSE);
+ if (foundable>5) kink->SetTPCDensity(Float_t(found)/Float_t(foundable),1,1);
+ }