+
+Bool_t AliESD::RemoveKink(Int_t rm) {
+ // ---------------------------------------------------------
+ // Remove a kink candidate and references to it from ESD,
+ // if this candidate does not come from a reconstructed decay
+ // Not yet implemented...
+ // ---------------------------------------------------------
+ Int_t last=GetNumberOfKinks()-1;
+ if ((rm<0)||(rm>last)) return kFALSE;
+
+ return kTRUE;
+}
+
+Bool_t AliESD::RemoveV0(Int_t rm) {
+ // ---------------------------------------------------------
+ // Remove a V0 candidate and references to it from ESD,
+ // if this candidate does not come from a reconstructed decay
+ // ---------------------------------------------------------
+ Int_t last=GetNumberOfV0s()-1;
+ if ((rm<0)||(rm>last)) return kFALSE;
+
+ AliESDv0 *v0=GetV0(rm);
+ Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
+
+ v0=GetV0(last);
+ Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
+
+ Int_t used=0;
+
+ // Check if this V0 comes from a reconstructed decay
+ Int_t ncs=GetNumberOfCascades();
+ for (Int_t n=0; n<ncs; n++) {
+ AliESDcascade *cs=GetCascade(n);
+
+ Int_t csIdxP=cs->GetPindex();
+ Int_t csIdxN=cs->GetNindex();
+
+ if (idxP==csIdxP)
+ if (idxN==csIdxN) return kFALSE;
+
+ if (csIdxP==lastIdxP)
+ if (csIdxN==lastIdxN) used++;
+ }
+
+ //Replace the removed V0 with the last V0
+ TClonesArray &a=fV0s;
+ delete a.RemoveAt(rm);
+
+ if (rm==last) return kTRUE;
+
+ //v0 is pointing to the last V0 candidate...
+ new (a[rm]) AliESDv0(*v0);
+ delete a.RemoveAt(last);
+
+ if (!used) return kTRUE;
+
+
+ // Remap the indices of the daughters of reconstructed decays
+ for (Int_t n=0; n<ncs; n++) {
+ AliESDcascade *cs=GetCascade(n);
+
+
+ Int_t csIdxP=cs->GetPindex();
+ Int_t csIdxN=cs->GetNindex();
+
+ if (csIdxP==lastIdxP)
+ if (csIdxN==lastIdxN) {
+ cs->AliESDv0::SetIndex(1,idxP);
+ cs->AliESDv0::SetIndex(0,idxN);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+
+ return kTRUE;
+}
+
+Bool_t AliESD::RemoveTrack(Int_t rm) {
+ // ---------------------------------------------------------
+ // Remove a track and references to it from ESD,
+ // if this track does not come from a reconstructed decay
+ // ---------------------------------------------------------
+ Int_t last=GetNumberOfTracks()-1;
+ if ((rm<0)||(rm>last)) return kFALSE;
+
+ Int_t used=0;
+
+ // Check if this track comes from the reconstructed primary vertex
+ if (fPrimaryVertex.GetStatus()) {
+ UShort_t *primIdx=fPrimaryVertex.GetIndices();
+ Int_t n=fPrimaryVertex.GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+ }
+
+ // Check if this track comes from a reconstructed decay
+ Int_t nv0=GetNumberOfV0s();
+ for (Int_t n=0; n<nv0; n++) {
+ AliESDv0 *v0=GetV0(n);
+
+ Int_t idx=v0->GetNindex();
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+
+ idx=v0->GetPindex();
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+
+ Int_t ncs=GetNumberOfCascades();
+ for (Int_t n=0; n<ncs; n++) {
+ AliESDcascade *cs=GetCascade(n);
+
+ Int_t idx=cs->GetIndex();
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+
+ Int_t nkn=GetNumberOfKinks();
+ for (Int_t n=0; n<nkn; n++) {
+ AliESDkink *kn=GetKink(n);
+
+ Int_t idx=kn->GetIndex(0);
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+
+ idx=kn->GetIndex(1);
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+
+
+ //Replace the removed track with the last track
+ TClonesArray &a=fTracks;
+ delete a.RemoveAt(rm);
+
+ if (rm==last) return kTRUE;
+
+ AliESDtrack *t=GetTrack(last);
+ t->SetID(rm);
+ new (a[rm]) AliESDtrack(*t);
+ delete a.RemoveAt(last);
+
+
+ if (!used) return kTRUE;
+
+
+ // Remap the indices of the tracks used for the primary vertex reconstruction
+ if (fPrimaryVertex.GetStatus()) {
+ UShort_t *primIdx=fPrimaryVertex.GetIndices();
+ Int_t n=fPrimaryVertex.GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (idx==last) {
+ primIdx[n]=Short_t(rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+ }
+
+ // Remap the indices of the daughters of reconstructed decays
+ for (Int_t n=0; n<nv0; n++) {
+ AliESDv0 *v0=GetV0(n);
+ if (v0->GetIndex(0)==last) {
+ v0->SetIndex(0,rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ if (v0->GetIndex(1)==last) {
+ v0->SetIndex(1,rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+
+ for (Int_t n=0; n<ncs; n++) {
+ AliESDcascade *cs=GetCascade(n);
+ if (cs->GetIndex()==last) {
+ cs->SetIndex(rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+
+ for (Int_t n=0; n<nkn; n++) {
+ AliESDkink *kn=GetKink(n);
+ if (kn->GetIndex(0)==last) {
+ kn->SetIndex(rm,0);
+ used--;
+ if (!used) return kTRUE;
+ }
+ if (kn->GetIndex(1)==last) {
+ kn->SetIndex(rm,1);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+
+ return kTRUE;