+Bool_t AliESDEvent::RemoveKink(Int_t rm) const {
+ // ---------------------------------------------------------
+ // 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 AliESDEvent::RemoveV0(Int_t rm) const {
+ // ---------------------------------------------------------
+ // 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 AliESDEvent::RemoveTrack(Int_t rm) const {
+ // ---------------------------------------------------------
+ // 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 vertices
+ if (fTPCVertex && fTPCVertex->GetStatus()) {
+ UShort_t *primIdx=fTPCVertex->GetIndices();
+ Int_t n=fTPCVertex->GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (rm==idx) return kFALSE;
+ if (idx==last) used++;
+ }
+ }
+ if (fPrimaryVertex && 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++;
+
+ AliESDv0 *v0=cs;
+ 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 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++;
+ }
+
+ // Check if this track is associated with a CaloCluster
+ Int_t ncl=GetNumberOfCaloClusters();
+ for (Int_t n=0; n<ncl; n++) {
+ AliESDCaloCluster *cluster=GetCaloCluster(n);
+ TArrayI *arr=cluster->GetTracksMatched();
+ Int_t s=arr->GetSize();
+ while (s--) {
+ Int_t idx=arr->At(s);
+ 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 (fTPCVertex && fTPCVertex->GetStatus()) {
+ UShort_t *primIdx=fTPCVertex->GetIndices();
+ Int_t n=fTPCVertex->GetNIndices();
+ while (n--) {
+ Int_t idx=Int_t(primIdx[n]);
+ if (idx==last) {
+ primIdx[n]=Short_t(rm);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+ }
+ if (fPrimaryVertex && 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;
+ }
+ AliESDv0 *v0=cs;
+ 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<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;
+ }
+ }
+
+ // Remap the indices of the tracks accosicated with CaloClusters
+ for (Int_t n=0; n<ncl; n++) {
+ AliESDCaloCluster *cluster=GetCaloCluster(n);
+ TArrayI *arr=cluster->GetTracksMatched();
+ Int_t s=arr->GetSize();
+ while (s--) {
+ Int_t idx=arr->At(s);
+ if (idx==last) {
+ arr->AddAt(rm,s);
+ used--;
+ if (!used) return kTRUE;
+ }
+ }
+ }
+
+ return kTRUE;
+}
+
+
+Bool_t AliESDEvent::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=GetPrimaryVertexSPD();
+ 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;
+}
+
+Char_t AliESDEvent::AddPileupVertexSPD(const AliESDVertex *vtx)
+{
+ // Add a pileup primary vertex reconstructed with SPD
+ TClonesArray &ftr = *fSPDPileupVertices;
+ Char_t n=Char_t(ftr.GetEntriesFast());
+ AliESDVertex *vertex = new(ftr[n]) AliESDVertex(*vtx);
+ vertex->SetID(n);
+ return n;
+}
+
+Char_t AliESDEvent::AddPileupVertexTracks(const AliESDVertex *vtx)
+{
+ // Add a pileup primary vertex reconstructed with SPD
+ TClonesArray &ftr = *fTrkPileupVertices;
+ Char_t n=Char_t(ftr.GetEntriesFast());
+ AliESDVertex *vertex = new(ftr[n]) AliESDVertex(*vtx);
+ vertex->SetID(n);
+ return n;
+}
+
+Int_t AliESDEvent::AddTrack(const AliESDtrack *t)
+{