+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;
+}
+
+
+Bool_t AliESD::Clean(Float_t *cleanPars) {
+ //
+ // Remove the data which are not needed for the physics analysis.
+ //
+ // 1) Cleaning the V0 candidates
+ // ---------------------------
+ // If the cosine of the V0 pointing angle "csp" and
+ // the DCA between the daughter tracks "dca" does not satisfy
+ // the conditions
+ //
+ // csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
+ //
+ // an attempt to remove this V0 candidate from ESD is made.
+ //
+ // The V0 candidate gets removed if it does not belong to any
+ // recosntructed cascade decay
+ //
+ // 12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
+ //
+ // 2) Cleaning the tracks
+ // ----------------------
+ // If track's transverse parameter is larger than cleanPars[2]
+ // OR
+ // track's longitudinal parameter is larger than cleanPars[3]
+ // an attempt to remove this track from ESD is made.
+ //
+ // The track gets removed if it does not come
+ // from a reconstructed decay
+ //
+ Bool_t rc=kFALSE;
+
+ Float_t dcaMax=cleanPars[0];
+ Float_t cspMin=cleanPars[1];
+
+ Int_t nV0s=GetNumberOfV0s();
+ for (Int_t i=nV0s-1; i>=0; i--) {
+ AliESDv0 *v0=GetV0(i);
+
+ Float_t dca=v0->GetDcaV0Daughters();
+ Float_t csp=v0->GetV0CosineOfPointingAngle();
+ Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
+ if (csp > cspcut) continue;
+
+ if (RemoveV0(i)) rc=kTRUE;
+ }
+
+
+ Float_t dmax=cleanPars[2], zmax=cleanPars[3];
+
+ const AliESDVertex *vertex=GetVertex();
+ Bool_t vtxOK=vertex->GetStatus();
+
+ Int_t nTracks=GetNumberOfTracks();
+ for (Int_t i=nTracks-1; i>=0; i--) {
+ AliESDtrack *track=GetTrack(i);
+ Float_t xy,z; track->GetImpactParameters(xy,z);
+ if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
+ if (RemoveTrack(i)) rc=kTRUE;
+ }
+ }
+
+ return rc;
+}
+
+Int_t AliESD::AddV0(const AliESDv0 *v) {
+ //
+ // Add V0
+ //
+ Int_t idx=fV0s.GetEntriesFast();
+ new(fV0s[idx]) AliESDv0(*v);
+ return idx;
+}