+
+//______________________________________________________________________________
+void AliESDEvent::SetTOFcluster(Int_t ntofclusters,AliESDTOFCluster *cluster,Int_t *mapping)
+{
+ // Reset TClonesArray of TOF clusters
+ if (!fESDTOFClusters) {
+ AliError("fESDTOFClusters is not initialized");
+ return;
+ }
+ fESDTOFClusters->Clear();
+
+ Int_t goodhit[20000];
+ if(mapping){
+ for(Int_t i=0;i < 20000;i++){
+ goodhit[i] = 0;
+ }
+ }
+
+ for(Int_t i=0;i < ntofclusters;i++){
+
+ if(cluster[i].GetNMatchableTracks() || !mapping){
+ if(mapping)
+ mapping[i] = fESDTOFClusters->GetEntriesFast();
+
+ // update TClonesArray
+ TClonesArray &ftr = *fESDTOFClusters;
+ AliESDTOFCluster *clusterTBW = new(ftr[fESDTOFClusters->GetEntriesFast()])AliESDTOFCluster(cluster[i]);
+
+ if(mapping){
+ // loop over hit in the cluster
+ for(Int_t k=0;k < clusterTBW->GetNTOFhits();k++){
+ Int_t ipos = clusterTBW->GetHitIndex(k);
+ goodhit[ipos] = 1; // hit should be kept
+ }
+ }
+ }
+ }
+
+ if(mapping){
+ AliInfo(Form("TOF cluster before of matching = %i , after = %i\n",ntofclusters,fESDTOFClusters->GetEntriesFast()));
+ Int_t hitnewpos[20000]={0};
+ Int_t nhitOriginal = fESDTOFHits->GetEntries();
+ for(Int_t i=0;i < fESDTOFHits->GetEntries();i++){
+ if(goodhit[i]){
+ hitnewpos[i] = i;
+ }
+ else{ // remove hit and decrease the hit array
+ TClonesArray &a=*fESDTOFHits;
+ Int_t lastpos = fESDTOFHits->GetEntries()-1;
+
+ if(i == lastpos)
+ delete a.RemoveAt(i);
+ else{
+ Int_t nhitBefore = fESDTOFHits->GetEntries();
+ for(Int_t k=nhitBefore-1;k>i;k--){ // find the last good track
+ if(!goodhit[k]){ // remove track
+ delete a.RemoveAt(k);
+ if(k-i==1) delete a.RemoveAt(i);
+ }
+ else{ // replace last one to the "i"
+ AliESDTOFHit *last = (AliESDTOFHit *) fESDTOFHits->At(k);
+ delete a.RemoveAt(i);
+ new (a[i]) AliESDTOFHit(*last);
+ delete a.RemoveAt(k);
+ hitnewpos[k] = i;
+ k = 0;
+ }
+ }
+ }
+ }
+ }
+
+ // remap cluster to hits
+ for(Int_t i=0;i < fESDTOFClusters->GetEntries();i++){
+ AliESDTOFCluster *cl = (AliESDTOFCluster *) fESDTOFClusters->At(i);
+ // loop over hit in the cluster
+ for(Int_t k=0;k < cl->GetNTOFhits();k++){
+ cl->SetHitIndex(k,hitnewpos[cl->GetHitIndex(k)]);
+ }
+ }
+ AliInfo(Form("TOF hit before of matching = %i , after = %i\n",nhitOriginal,fESDTOFHits->GetEntriesFast()));
+ } // end mapping
+
+}
+
+//______________________________________________________________________________
+void AliESDEvent::SetTOFcluster(Int_t ntofclusters,AliESDTOFCluster *cluster[],Int_t *mapping)
+{
+ // Reset TClonesArray of TOF clusters
+ if(fESDTOFClusters)fESDTOFClusters->Delete();
+
+ Int_t goodhit[20000];
+ if(mapping){
+ for(Int_t i=0;i < 20000;i++){
+ goodhit[i] = 0;
+ }
+ }
+
+ for(Int_t i=0;i < ntofclusters;i++){
+
+ if(cluster[i]->GetNMatchableTracks() || !mapping){
+ if(mapping)
+ mapping[i] = fESDTOFClusters->GetEntriesFast();
+
+ // update TClonesArray
+ TClonesArray &ftr = *fESDTOFClusters;
+ AliESDTOFCluster *clusterTBW = new(ftr[fESDTOFClusters->GetEntriesFast()])AliESDTOFCluster(*(cluster[i]));
+
+ if(mapping){
+ // loop over hit in the cluster
+ for(Int_t k=0;k < clusterTBW->GetNTOFhits();k++){
+ Int_t ipos = clusterTBW->GetHitIndex(k);
+ goodhit[ipos] = 1; // hit should be kept
+ }
+ }
+ }
+ }
+
+ if(mapping){
+ AliInfo(Form("TOF cluster before of matching = %i , after = %i\n",ntofclusters,fESDTOFClusters->GetEntriesFast()));
+ Int_t hitnewpos[20000]={0};
+ Int_t nhitOriginal = fESDTOFHits->GetEntries();
+ for(Int_t i=0;i < fESDTOFHits->GetEntries();i++){
+ if(goodhit[i]){
+ hitnewpos[i] = i;
+ }
+ else{ // remove hit and decrease the hit array
+ TClonesArray &a=*fESDTOFHits;
+ Int_t lastpos = fESDTOFHits->GetEntries()-1;
+
+ if(i == lastpos)
+ delete a.RemoveAt(i);
+ else{
+ Int_t nhitBefore = fESDTOFHits->GetEntries();
+ for(Int_t k=nhitBefore-1;k>i;k--){ // find the last good track
+ if(!goodhit[k]){ // remove track
+ delete a.RemoveAt(k);
+ if(k-i==1) delete a.RemoveAt(i);
+ }
+ else{ // replace last one to the "i"
+ AliESDTOFHit *last = (AliESDTOFHit *) fESDTOFHits->At(k);
+ delete a.RemoveAt(i);
+ new (a[i]) AliESDTOFHit(*last);
+ delete a.RemoveAt(k);
+ hitnewpos[k] = i;
+ k = 0;
+ }
+ }
+ }
+ }
+ }
+
+ // remap cluster to hits
+ for(Int_t i=0;i < fESDTOFClusters->GetEntries();i++){
+ AliESDTOFCluster *cl = (AliESDTOFCluster *) fESDTOFClusters->At(i);
+ // loop over hit in the cluster
+ for(Int_t k=0;k < cl->GetNTOFhits();k++){
+ cl->SetHitIndex(k,hitnewpos[cl->GetHitIndex(k)]);
+ }
+ }
+ AliInfo(Form("TOF hit before of matching = %i , after = %i\n",nhitOriginal,fESDTOFHits->GetEntriesFast()));
+ } // end mapping
+
+}
+
+//______________________________________________________________________________
+void AliESDEvent::ConnectTracks() {
+// Connect tracks to this event
+ if (fTracksConnected || !fTracks || !fTracks->GetEntriesFast()) return;
+ AliESDtrack *track;
+ TIter next(fTracks);
+ while ((track=(AliESDtrack*)next())) track->SetESDEvent(this);
+ //
+ // The same for TOF clusters
+ if (fESDTOFClusters) {
+ AliESDTOFCluster *clus;
+ TIter nextTOF(fESDTOFClusters);
+ while ((clus=(AliESDTOFCluster*)nextTOF())) clus->SetEvent((AliVEvent *) this);
+ }
+ fTracksConnected = kTRUE;
+ //
+}
+
+//______________________________________________________________________________
+AliESDfriend* AliESDEvent::FindFriend() const
+{
+ return static_cast<AliESDfriend*>(FindListObject("AliESDfriend"));
+}
+
+AliVEvent::EDataLayoutType AliESDEvent::GetDataLayoutType() const {return AliVEvent::kESD;}
+