]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/ESD/AliESDEvent.cxx
Geometry for run3 implemented with updated TDI
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDEvent.cxx
index 8dd0cff8956b828db66fe07e322670d48407cc1f..3bb69e763cb014339fe7dadbe0ab0db60c091ddb 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+/* $Id: AliESDEvent.cxx 64008 2013-08-28 13:09:59Z hristov $ */
 
 //-----------------------------------------------------------------
 //           Implementation of the AliESDEvent class
@@ -46,6 +46,7 @@
 #include "AliESDMuonTrack.h"
 #include "AliESDMuonCluster.h"
 #include "AliESDMuonPad.h"
+#include "AliESDMuonGlobalTrack.h"       // AU
 #include "AliESDPmdTrack.h"
 #include "AliESDTrdTrack.h"
 #include "AliESDVertex.h"
 #include "AliRawDataErrorLog.h"
 #include "AliLog.h"
 #include "AliESDACORDE.h"
+#include "AliESDAD.h"
 #include "AliESDHLTDecision.h"
 #include "AliCentrality.h"
 #include "AliESDCosmicTrack.h"
 #include "AliTriggerConfiguration.h"
 #include "AliTriggerClass.h"
 #include "AliTriggerCluster.h"
-#ifdef MFT_UPGRADE
-#include "AliESDMFT.h"
-#endif
 #include "AliEventplane.h"
 
-
 ClassImp(AliESDEvent)
 
-
-
 // here we define the names, some classes are no TNamed, therefore the classnames 
 // are the Names
   const char* AliESDEvent::fgkESDListName[kESDListN] = {"AliESDRun",
@@ -105,6 +101,7 @@ ClassImp(AliESDEvent)
                                                        "MuonTracks",
                                                        "MuonClusters",
                                                        "MuonPads",
+                                                       "MuonGlobalTracks",      // AU
                                                        "PmdTracks",
                                                        "AliESDTrdTrigger",
                                                        "TrdTracks",
@@ -117,12 +114,13 @@ ClassImp(AliESDEvent)
                                                        "PHOSCells",
                                                        "AliRawDataErrorLogs",
                                                        "AliESDACORDE",
+                                                       "AliESDAD",
                                                        "AliTOFHeader",
-                                                        "CosmicTracks"
-                              #ifdef MFT_UPGRADE
-//                             , "AliESDMFT"
-                                                       #endif
-  };
+                                                        "CosmicTracks",
+                                                       "AliESDTOFCluster",
+                                                       "AliESDTOFHit",
+                                                       "AliESDTOFMatch"};
+
 
 //______________________________________________________________________________
 AliESDEvent::AliESDEvent():
@@ -141,6 +139,7 @@ AliESDEvent::AliESDEvent():
   fPHOSTrigger(0),
   fEMCALTrigger(0),
   fESDACORDE(0),
+  fESDAD(0),
   fTrdTrigger(0),
   fSPDPileupVertices(0),
   fTrkPileupVertices(0),
@@ -148,6 +147,7 @@ AliESDEvent::AliESDEvent():
   fMuonTracks(0),
   fMuonClusters(0),
   fMuonPads(0),
+  fMuonGlobalTracks(0),    // AU
   fPmdTracks(0),
   fTrdTracks(0),
   fTrdTracklets(0),
@@ -157,19 +157,22 @@ AliESDEvent::AliESDEvent():
   fCaloClusters(0),
   fEMCALCells(0), fPHOSCells(0),
   fCosmicTracks(0),
+  fESDTOFClusters(0),
+  fESDTOFHits(0),
+  fESDTOFMatches(0),
   fErrorLogs(0),
   fOldMuonStructure(kFALSE),
   fESDOld(0),
   fESDFriendOld(0),
   fConnected(kFALSE),
   fUseOwnList(kFALSE),
+  fTracksConnected(kFALSE),
   fTOFHeader(0),
   fCentrality(0),
   fEventplane(0),
-  fDetectorStatus(0xFFFFFFFF)
-  #ifdef MFT_UPGRADE
-//  , fESDMFT(0)
-  #endif
+  fDetectorStatus(0xFFFFFFFF),
+  fDAQDetectorPattern(0xFFFF),
+  fDAQAttributes(0xFFFF)
 {
 }
 //______________________________________________________________________________
@@ -189,6 +192,7 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
   fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
   fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
   fESDACORDE(new AliESDACORDE(*esd.fESDACORDE)),
+  fESDAD(new AliESDAD(*esd.fESDAD)),
   fTrdTrigger(new AliESDTrdTrigger(*esd.fTrdTrigger)),
   fSPDPileupVertices(new TClonesArray(*esd.fSPDPileupVertices)),
   fTrkPileupVertices(new TClonesArray(*esd.fTrkPileupVertices)),
@@ -196,6 +200,7 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
   fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
   fMuonClusters(new TClonesArray(*esd.fMuonClusters)),
   fMuonPads(new TClonesArray(*esd.fMuonPads)),
+  fMuonGlobalTracks(new TClonesArray(*esd.fMuonGlobalTracks)),     // AU
   fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
   fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
   fTrdTracklets(new TClonesArray(*esd.fTrdTracklets)),
@@ -206,21 +211,22 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
   fEMCALCells(new AliESDCaloCells(*esd.fEMCALCells)),
   fPHOSCells(new AliESDCaloCells(*esd.fPHOSCells)),
   fCosmicTracks(new TClonesArray(*esd.fCosmicTracks)),
+  fESDTOFClusters(esd.fESDTOFClusters ? new TClonesArray(*esd.fESDTOFClusters) : 0),
+  fESDTOFHits(esd.fESDTOFHits ? new TClonesArray(*esd.fESDTOFHits) : 0),
+  fESDTOFMatches(esd.fESDTOFMatches ? new TClonesArray(*esd.fESDTOFMatches) : 0),
   fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
   fOldMuonStructure(esd.fOldMuonStructure),
   fESDOld(esd.fESDOld ? new AliESD(*esd.fESDOld) : 0),
   fESDFriendOld(esd.fESDFriendOld ? new AliESDfriend(*esd.fESDFriendOld) : 0),
   fConnected(esd.fConnected),
   fUseOwnList(esd.fUseOwnList),
+  fTracksConnected(kFALSE),
   fTOFHeader(new AliTOFHeader(*esd.fTOFHeader)),
   fCentrality(new AliCentrality(*esd.fCentrality)),
   fEventplane(new AliEventplane(*esd.fEventplane)),
-  fDetectorStatus(esd.fDetectorStatus)
-  #ifdef MFT_UPGRADE
-//  , fESDMFT(new AliESDMFT(*esd.fESDMFT))
-  #endif
-
-
+  fDetectorStatus(esd.fDetectorStatus),
+  fDAQDetectorPattern(esd.fDAQDetectorPattern),
+  fDAQAttributes(esd.fDAQAttributes)
 {
   printf("copying ESD event...\n");   // AU
   // CKB init in the constructor list and only add here ...
@@ -241,6 +247,7 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
   AddObject(fTrkPileupVertices);
   AddObject(fTracks);
   AddObject(fMuonTracks);
+  AddObject(fMuonGlobalTracks);    // AU
   AddObject(fPmdTracks);
   AddObject(fTrdTracks);
   AddObject(fTrdTracklets);
@@ -251,15 +258,17 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
   AddObject(fEMCALCells);
   AddObject(fPHOSCells);
   AddObject(fCosmicTracks);
+  AddObject(fESDTOFClusters);
+  AddObject(fESDTOFHits);
+  AddObject(fESDTOFMatches);
   AddObject(fErrorLogs);
   AddObject(fESDACORDE);
+  AddObject(fESDAD);
   AddObject(fTOFHeader);
   AddObject(fMuonClusters);
   AddObject(fMuonPads);
-  #ifdef MFT_UPGRADE
-//  AddObject(fESDMFT);
-  #endif
   GetStdContent();
+  ConnectTracks();
 
 }
 
@@ -267,7 +276,7 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
 AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
 
   // Assignment operator
-
+  printf("operator = ESD\n");
   if(&source == this) return *this;
   AliVEvent::operator=(source);
 
@@ -357,9 +366,13 @@ AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
 
   fConnected  = source.fConnected;
   fUseOwnList = source.fUseOwnList;
-  
+
   fDetectorStatus = source.fDetectorStatus;
+  fDAQDetectorPattern = source.fDAQDetectorPattern;
+  fDAQAttributes = source.fDAQAttributes;
 
+  fTracksConnected = kFALSE;
+  ConnectTracks();
   return *this;
 }
 
@@ -382,6 +395,7 @@ AliESDEvent::~AliESDEvent()
   if (fCentrality) delete fCentrality;
   if (fEventplane) delete fEventplane;
   
+
 }
 
 void AliESDEvent::Copy(TObject &obj) const {
@@ -407,7 +421,8 @@ void AliESDEvent::Reset()
   // Reset the standard contents
   ResetStdContent(); 
   fDetectorStatus = 0xFFFFFFFF;
-
+  fDAQDetectorPattern = 0xFFFF;
+  fDAQAttributes = 0xFFFF;
   //  reset for the old data without AliESDEvent...
   if(fESDOld)fESDOld->Reset();
   if(fESDFriendOld){
@@ -445,6 +460,7 @@ void AliESDEvent::Reset()
 
 }
 
+//______________________________________________________________________________
 Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
   //
   // funtion to reset using the already allocated space
@@ -460,6 +476,7 @@ Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
   return kTRUE;
 }
 
+//______________________________________________________________________________
 void AliESDEvent::ResetStdContent()
 {
   // Reset the standard contents
@@ -480,6 +497,13 @@ void AliESDEvent::ResetStdContent()
     fESDACORDE->~AliESDACORDE();
     new (fESDACORDE) AliESDACORDE();   
   } 
+
+  if(fESDAD){
+    fESDAD->~AliESDAD();
+    new (fESDAD) AliESDAD();   
+  } 
+
+
   if(fESDTZERO) fESDTZERO->Reset(); 
   // CKB no clear/reset implemented
   if(fTPCVertex){
@@ -510,21 +534,17 @@ void AliESDEvent::ResetStdContent()
     fTrdTrigger->~AliESDTrdTrigger();
     new (fTrdTrigger) AliESDTrdTrigger();
   }
-  #ifdef MFT_UPGRADE
-  //if(fESDMFT){
-//     fESDMFT->~AliESDMFT();
-//     new (fESDMFT) AliESDMFT();
- // }  
-  #endif
        
   if(fPHOSTrigger)fPHOSTrigger->DeAllocate(); 
   if(fEMCALTrigger)fEMCALTrigger->DeAllocate(); 
   if(fSPDPileupVertices)fSPDPileupVertices->Delete();
   if(fTrkPileupVertices)fTrkPileupVertices->Delete();
+  fTracksConnected = kFALSE;
   if(fTracks)fTracks->Delete();
   if(fMuonTracks)fMuonTracks->Clear("C");
   if(fMuonClusters)fMuonClusters->Clear("C");
   if(fMuonPads)fMuonPads->Clear("C");
+  if(fMuonGlobalTracks)fMuonGlobalTracks->Clear("C");     // AU
   if(fPmdTracks)fPmdTracks->Delete();
   if(fTrdTracks)fTrdTracks->Delete();
   if(fTrdTracklets)fTrdTracklets->Delete();
@@ -535,6 +555,9 @@ void AliESDEvent::ResetStdContent()
   if(fPHOSCells)fPHOSCells->DeleteContainer();
   if(fEMCALCells)fEMCALCells->DeleteContainer();
   if(fCosmicTracks)fCosmicTracks->Delete();
+  if(fESDTOFClusters)fESDTOFClusters->Clear();
+  if(fESDTOFHits)fESDTOFHits->Clear();
+  if(fESDTOFMatches)fESDTOFMatches->Clear();
   if(fErrorLogs) fErrorLogs->Delete();
 
   // don't reset fconnected fConnected and the list
@@ -542,6 +565,7 @@ void AliESDEvent::ResetStdContent()
 }
 
 
+//______________________________________________________________________________
 Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
   //
   // Add V0
@@ -557,16 +581,24 @@ Bool_t AliESDEvent::IsDetectorInTriggerCluster(TString detector, AliTriggerConfi
   // Check if a given detector was read-out in the analyzed event
   const TObjArray& classesArray=trigConf->GetClasses();
   ULong64_t trigMask=GetTriggerMask();
+  ULong64_t trigMaskNext50=GetTriggerMaskNext50();
   Int_t nclasses = classesArray.GetEntriesFast();
   for(Int_t iclass=0; iclass < nclasses; iclass++ ) {
     AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
-    Int_t classMask=trclass->GetMask();
+    ULong64_t classMask=trclass->GetMask();
+    ULong64_t classMaskNext50=trclass->GetMaskNext50();
     if(trigMask & classMask){
       TString detList=trclass->GetCluster()->GetDetectorsInCluster();
       if(detList.Contains(detector.Data())){
        return kTRUE;
       }
     }
+    if(trigMaskNext50 & classMaskNext50){
+      TString detList=trclass->GetCluster()->GetDetectorsInCluster();
+      if(detList.Contains(detector.Data())){
+       return kTRUE;
+      }
+    }
   }
   return kFALSE; 
 }
@@ -577,19 +609,20 @@ void AliESDEvent::Print(Option_t *) const
   // Print header information of the event
   //
   printf("ESD run information\n");
-  printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
+  printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld %lld Magnetic field %f \n",
         GetEventNumberInFile(),
         GetBunchCrossNumber(),
         GetOrbitNumber(),
         GetPeriodNumber(),
         GetRunNumber(),
         GetTriggerMask(),
+        GetTriggerMaskNext50(),
         GetMagneticField() );
   if (fPrimaryVertex)
     printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
-          fPrimaryVertex->GetXv(), fPrimaryVertex->GetXRes(),
-          fPrimaryVertex->GetYv(), fPrimaryVertex->GetYRes(),
-          fPrimaryVertex->GetZv(), fPrimaryVertex->GetZRes());
+          fPrimaryVertex->GetX(), fPrimaryVertex->GetXRes(),
+          fPrimaryVertex->GetY(), fPrimaryVertex->GetYRes(),
+          fPrimaryVertex->GetZ(), fPrimaryVertex->GetZRes());
   printf("Mean vertex in RUN: X=%.4f Y=%.4f Z=%.4f cm\n",
         GetDiamondX(),GetDiamondY(),GetDiamondZ());
   if(fSPDMult)
@@ -602,6 +635,7 @@ void AliESDEvent::Print(Option_t *) const
   printf("Number of tracks: \n");
   printf("                 charged   %d\n", GetNumberOfTracks());
   printf("                 muon      %d\n", GetNumberOfMuonTracks());
+  printf("                 glob muon %d\n", GetNumberOfMuonGlobalTracks());    // AU
   printf("                 pmd       %d\n", GetNumberOfPmdTracks());
   printf("                 trd       %d\n", GetNumberOfTrdTracks());
   printf("                 trd trkl  %d\n", GetNumberOfTrdTracklets());
@@ -618,10 +652,6 @@ void AliESDEvent::Print(Option_t *) const
   printf("                 muClusters %d\n", fMuonClusters ? fMuonClusters->GetEntriesFast() : 0);
   printf("                 muPad     %d\n", fMuonPads ? fMuonPads->GetEntriesFast() : 0);
   if (fCosmicTracks) printf("                 Cosmics   %d\n",  GetNumberOfCosmicTracks());
-  #ifdef MFT_UPGRADE
-  //printf("                 MFT     %s\n", (fESDMFT ? "yes" : "no"));
-  #endif
-       
        
   TObject* pHLTDecision=GetHLTTriggerDecision();
   printf("HLT trigger decision: %s\n", pHLTDecision?pHLTDecision->GetOption():"not available");
@@ -630,10 +660,12 @@ void AliESDEvent::Print(Option_t *) const
   return;
 }
 
-void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const {
-  //
-  // Attaches the complementary info to the ESD
-  //
+//______________________________________________________________________________
+void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const 
+{
+//
+// Attaches the complementary info to the ESD
+//
   if (!ev) return;
 
   // to be sure that we set the tracks also
@@ -649,23 +681,27 @@ void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const {
   }
 }
 
-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...
-  // ---------------------------------------------------------
+//______________________________________________________________________________
+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
-  // ---------------------------------------------------------
+//______________________________________________________________________________
+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;
 
@@ -725,11 +761,13 @@ Bool_t  AliESDEvent::RemoveV0(Int_t rm) const {
   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
-  // ---------------------------------------------------------
+//______________________________________________________________________________
+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;
 
@@ -813,12 +851,14 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     }
   }
 
-
-
+  // from here on we remove the track
+  //
   //Replace the removed track with the last track 
   TClonesArray &a=*fTracks;
+  AliESDtrack* trm = GetTrack(rm);
+  trm->SuppressTOFMatches(); // remove reference to this track from stored TOF clusters
   delete a.RemoveAt(rm);
-
+  //
   if (rm==last) return kTRUE;
 
   AliESDtrack *t=GetTrack(last);
@@ -827,7 +867,6 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
   new (a[rm]) AliESDtrack(*t);
   delete a.RemoveAt(last);
 
-
   if (!used) return kTRUE;
   
 
@@ -924,8 +963,9 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
   return kTRUE;
 }
 
-
-Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
+//______________________________________________________________________________
+Bool_t AliESDEvent::Clean(Float_t *cleanPars) 
+{
   //
   // Remove the data which are not needed for the physics analysis.
   //
@@ -989,6 +1029,7 @@ Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
   return rc;
 }
 
+//______________________________________________________________________________
 Char_t  AliESDEvent::AddPileupVertexSPD(const AliESDVertex *vtx) 
 {
     // Add a pileup primary vertex reconstructed with SPD
@@ -999,6 +1040,7 @@ Char_t  AliESDEvent::AddPileupVertexSPD(const AliESDVertex *vtx)
     return n;
 }
 
+//______________________________________________________________________________
 Char_t  AliESDEvent::AddPileupVertexTracks(const AliESDVertex *vtx) 
 {
     // Add a pileup primary vertex reconstructed with SPD
@@ -1009,21 +1051,25 @@ Char_t  AliESDEvent::AddPileupVertexTracks(const AliESDVertex *vtx)
     return n;
 }
 
+//______________________________________________________________________________
 Int_t  AliESDEvent::AddTrack(const AliESDtrack *t) 
 {
     // Add track
     TClonesArray &ftr = *fTracks;
     AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
     track->SetID(fTracks->GetEntriesFast()-1);
+    track->SetESDEvent(this);
     return  track->GetID();    
 }
 
+//______________________________________________________________________________
 AliESDtrack*  AliESDEvent::NewTrack() 
 {
     // Add a new track
     TClonesArray &ftr = *fTracks;
     AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack();
     track->SetID(fTracks->GetEntriesFast()-1);
+    track->SetESDEvent(this);
     return  track;
 }
 
@@ -1079,6 +1125,16 @@ AliESDMuonTrack* AliESDEvent::GetMuonTrack(Int_t i)
   return track;
 }
 
+//______________________________________________________________________________
+AliESDMuonGlobalTrack* AliESDEvent::GetMuonGlobalTrack(Int_t i)                      // AU
+{
+  // get the MUON+MFT track at the position i in the internal array of track
+  if (!fMuonGlobalTracks) return 0x0;
+  AliESDMuonGlobalTrack *track = (AliESDMuonGlobalTrack*) fMuonGlobalTracks->UncheckedAt(i);
+  track->SetESDEvent(this);
+  return track;
+}
+
 //______________________________________________________________________________
 void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) 
 {
@@ -1089,6 +1145,15 @@ void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t)
 }
 
 //______________________________________________________________________________
+void AliESDEvent::AddMuonGlobalTrack(const AliESDMuonGlobalTrack *t)                             // AU
+{
+  // add a MUON+MFT track
+  TClonesArray &fmu = *fMuonGlobalTracks;
+  new (fmu[fMuonGlobalTracks->GetEntriesFast()]) AliESDMuonGlobalTrack(*t);
+}
+
+//______________________________________________________________________________
+
 AliESDMuonTrack* AliESDEvent::NewMuonTrack() 
 {
   // create a new MUON track at the end of the internal array of track
@@ -1096,6 +1161,14 @@ AliESDMuonTrack* AliESDEvent::NewMuonTrack()
   return new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack();
 }
 
+//______________________________________________________________________________
+AliESDMuonGlobalTrack* AliESDEvent::NewMuonGlobalTrack()                                         // AU
+{
+  // create a new MUON+MFT track at the end of the internal array of track
+  TClonesArray &fmu = *fMuonGlobalTracks;
+  return new(fmu[fMuonGlobalTracks->GetEntriesFast()]) AliESDMuonGlobalTrack();
+}
+
 //______________________________________________________________________________
 Int_t AliESDEvent::GetNumberOfMuonClusters()
 {
@@ -1174,44 +1247,57 @@ AliESDMuonPad* AliESDEvent::NewMuonPad()
   return new(fmu[fMuonPads->GetEntriesFast()]) AliESDMuonPad();
 }
 
+//______________________________________________________________________________
 void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) 
 {
   TClonesArray &fpmd = *fPmdTracks;
   new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
 }
 
+//______________________________________________________________________________
 void AliESDEvent::SetTrdTrigger(const AliESDTrdTrigger *t)
 {
   *fTrdTrigger = *t;
 }
 
+//______________________________________________________________________________
 void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) 
 {
   TClonesArray &ftrd = *fTrdTracks;
   new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
 }
 
+//______________________________________________________________________________
 void AliESDEvent::AddTrdTracklet(const AliESDTrdTracklet *trkl)
 {
   new ((*fTrdTracklets)[fTrdTracklets->GetEntriesFast()]) AliESDTrdTracklet(*trkl);
 }
 
+//______________________________________________________________________________
+void AliESDEvent::AddTrdTracklet(UInt_t trackletWord, Short_t hcid, Int_t label)
+{
+  new ((*fTrdTracklets)[fTrdTracklets->GetEntriesFast()]) AliESDTrdTracklet(trackletWord, hcid, label);
+}
+
+//______________________________________________________________________________
 Int_t AliESDEvent::AddKink(const AliESDkink *c) 
 {
-    // Add kink
-    TClonesArray &fk = *fKinks;
-    AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
-    kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
-    return fKinks->GetEntriesFast()-1;
+  // Add kink
+  TClonesArray &fk = *fKinks;
+  AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
+  kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
+  return fKinks->GetEntriesFast()-1;
 }
 
 
+//______________________________________________________________________________
 void AliESDEvent::AddCascade(const AliESDcascade *c) 
 {
   TClonesArray &fc = *fCascades;
   new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
 }
 
+//______________________________________________________________________________
 void AliESDEvent::AddCosmicTrack(const AliESDCosmicTrack *t) 
 {
   TClonesArray &ft = *fCosmicTracks;
@@ -1219,21 +1305,24 @@ void AliESDEvent::AddCosmicTrack(const AliESDCosmicTrack *t)
 } 
 
 
+//______________________________________________________________________________
 Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) 
 {
-    // Add calocluster
-    TClonesArray &fc = *fCaloClusters;
-    AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
-    clus->SetID(fCaloClusters->GetEntriesFast()-1);
-    return fCaloClusters->GetEntriesFast()-1;
-  }
+  // Add calocluster
+  TClonesArray &fc = *fCaloClusters;
+  AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
+  clus->SetID(fCaloClusters->GetEntriesFast()-1);
+  return fCaloClusters->GetEntriesFast()-1;
+}
 
 
+//______________________________________________________________________________
 void  AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) const {
   TClonesArray &errlogs = *fErrorLogs;
   new(errlogs[errlogs.GetEntriesFast()])  AliRawDataErrorLog(*log);
 }
 
+//______________________________________________________________________________
 void AliESDEvent::SetZDCData(const AliESDZDC * obj)
 { 
   // use already allocated space
@@ -1241,6 +1330,7 @@ void AliESDEvent::SetZDCData(const AliESDZDC * obj)
     *fESDZDC = *obj;
 }
 
+//______________________________________________________________________________
 void  AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex) 
 {
   // Set the TPC vertex
@@ -1251,6 +1341,7 @@ void  AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex)
   }
 }
 
+//______________________________________________________________________________
 void  AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex) 
 {
   // Set the SPD vertex
@@ -1261,6 +1352,7 @@ void  AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex)
   }
 }
 
+//______________________________________________________________________________
 void  AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex) 
 {
   // Set the primary vertex reconstructed using he ESD tracks.
@@ -1271,6 +1363,7 @@ void  AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex)
   }
 }
 
+//______________________________________________________________________________
 const AliESDVertex * AliESDEvent::GetPrimaryVertex() const 
 {
   //
@@ -1288,6 +1381,7 @@ const AliESDVertex * AliESDEvent::GetPrimaryVertex() const
   return fSPDVertex;
 }
 
+//______________________________________________________________________________
 AliESDVertex * AliESDEvent::PrimaryVertexTracksUnconstrained() const 
 {
   //
@@ -1313,6 +1407,7 @@ AliESDVertex * AliESDEvent::PrimaryVertexTracksUnconstrained() const
   return vertex;
 }
 
+//______________________________________________________________________________
 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) 
 {
   // Set the SPD Multiplicity
@@ -1322,6 +1417,7 @@ void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul)
 }
 
 
+//______________________________________________________________________________
 void AliESDEvent::SetFMDData(AliESDFMD * obj) 
 { 
   // use already allocated space
@@ -1330,6 +1426,7 @@ void AliESDEvent::SetFMDData(AliESDFMD * obj)
   }
 }
 
+//______________________________________________________________________________
 void AliESDEvent::SetVZEROData(const AliESDVZERO * obj)
 { 
   // use already allocated space
@@ -1337,6 +1434,7 @@ void AliESDEvent::SetVZEROData(const AliESDVZERO * obj)
     *fESDVZERO = *obj;
 }
 
+//______________________________________________________________________________
 void AliESDEvent::SetTZEROData(const AliESDTZERO * obj)
 { 
   // use already allocated space
@@ -1344,21 +1442,22 @@ void AliESDEvent::SetTZEROData(const AliESDTZERO * obj)
     *fESDTZERO = *obj;
 }
 
-#ifdef MFT_UPGRADE
-//void AliESDEvent::SetMFTData(AliESDMFT * obj)
-//{ 
-//  if(fESDMFT)
-//     *fESDMFT = *obj;
-//}
-#endif
 
+//______________________________________________________________________________
 void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
 {
   if(fESDACORDE)
     *fESDACORDE = *obj;
 }
 
+//______________________________________________________________________________
+void AliESDEvent::SetADData(AliESDAD * obj)
+{
+  if(fESDAD)
+    *fESDAD = *obj;
+}
 
+//______________________________________________________________________________
 void AliESDEvent::GetESDfriend(AliESDfriend *ev) const 
 {
   //
@@ -1378,10 +1477,11 @@ void AliESDEvent::GetESDfriend(AliESDfriend *ev) const
 
   }
 
-  AliESDfriend *fr = (AliESDfriend*)(const_cast<AliESDEvent*>(this)->FindListObject("AliESDfriend"));
+  AliESDfriend *fr = (AliESDfriend*)(const_cast<AliESDEvent*>(this)->FindFriend());
   if (fr) ev->SetVZEROfriend(fr->GetVZEROfriend());
 }
 
+//______________________________________________________________________________
 void AliESDEvent::AddObject(TObject* obj) 
 {
   // Add an object to the list of object.
@@ -1391,7 +1491,7 @@ void AliESDEvent::AddObject(TObject* obj)
   fESDObjects->AddLast(obj);
 }
 
-
+//______________________________________________________________________________
 void AliESDEvent::GetStdContent() 
 {
   // set pointers for standard content
@@ -1415,6 +1515,7 @@ void AliESDEvent::GetStdContent()
   fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonTracks]);
   fMuonClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonClusters]);
   fMuonPads = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonPads]);
+  fMuonGlobalTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonGlobalTracks]);         // AU
   fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kPmdTracks]);
   fTrdTrigger = (AliESDTrdTrigger*)fESDObjects->FindObject(fgkESDListName[kTrdTrigger]);
   fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracks]);
@@ -1427,13 +1528,15 @@ void AliESDEvent::GetStdContent()
   fPHOSCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kPHOSCells]);
   fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kErrorLogs]);
   fESDACORDE = (AliESDACORDE*)fESDObjects->FindObject(fgkESDListName[kESDACORDE]);
+  fESDAD = (AliESDAD*)fESDObjects->FindObject(fgkESDListName[kESDAD]);
   fTOFHeader = (AliTOFHeader*)fESDObjects->FindObject(fgkESDListName[kTOFHeader]);
   fCosmicTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCosmicTracks]);
-  #ifdef MFT_UPGRADE
// fESDMFT = (AliESDMFT*)fESDObjects->FindObject(fgkESDListName[kESDMFT]);
-  #endif
+  fESDTOFClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTOFclusters]);
 fESDTOFHits = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTOFhit]);
+  fESDTOFMatches = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTOFmatch]);
 }
 
+//______________________________________________________________________________
 void AliESDEvent::SetStdNames(){
   // Set the names of the standard contents
   // 
@@ -1453,12 +1556,13 @@ void AliESDEvent::SetStdNames(){
   }
 } 
 
-
+//______________________________________________________________________________
 void AliESDEvent::CreateStdContent(Bool_t bUseThisList){
   fUseOwnList = bUseThisList;
   CreateStdContent();
 }
 
+//______________________________________________________________________________
 void AliESDEvent::CreateStdContent() 
 {
   // create the standard AOD content and set pointers
@@ -1482,6 +1586,7 @@ void AliESDEvent::CreateStdContent()
   AddObject(new TClonesArray("AliESDMuonTrack",0));
   AddObject(new TClonesArray("AliESDMuonCluster",0));
   AddObject(new TClonesArray("AliESDMuonPad",0));
+  AddObject(new TClonesArray("AliESDMuonGlobalTrack",0));   // AU
   AddObject(new TClonesArray("AliESDPmdTrack",0));
   AddObject(new AliESDTrdTrigger());
   AddObject(new TClonesArray("AliESDTrdTrack",0));
@@ -1494,11 +1599,12 @@ void AliESDEvent::CreateStdContent()
   AddObject(new AliESDCaloCells());
   AddObject(new TClonesArray("AliRawDataErrorLog",0));
   AddObject(new AliESDACORDE()); 
+  AddObject(new AliESDAD()); 
   AddObject(new AliTOFHeader());
   AddObject(new TClonesArray("AliESDCosmicTrack",0));
-  #ifdef MFT_UPGRADE
-  //AddObject(new AliESDMFT());
-  #endif
+  AddObject(new TClonesArray("AliESDTOFCluster",0));
+  AddObject(new TClonesArray("AliESDTOFHit",0));
+  AddObject(new TClonesArray("AliESDTOFMatch",0));
        
   // check the order of the indices against enum...
 
@@ -1508,6 +1614,7 @@ void AliESDEvent::CreateStdContent()
   GetStdContent();
 }
 
+//______________________________________________________________________________
 void AliESDEvent::CompleteStdContent() 
 {
   // Create missing standard objects and add them to the TList of objects
@@ -1534,6 +1641,7 @@ void AliESDEvent::CompleteStdContent()
   }
 }
 
+//______________________________________________________________________________
 TObject* AliESDEvent::FindListObject(const char *name) const {
 //
 // Find object with name "name" in the list of branches
@@ -1544,6 +1652,7 @@ TObject* AliESDEvent::FindListObject(const char *name) const {
   return 0;
 } 
 
+//______________________________________________________________________________
 Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
 {
   // fills the provided TRefArray with all found phos clusters
@@ -1563,6 +1672,7 @@ Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
   return clusters->GetEntriesFast();
 }
 
+//______________________________________________________________________________
 Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
 {
   // fills the provided TRefArray with all found emcal clusters
@@ -1582,6 +1692,7 @@ Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
   return clusters->GetEntriesFast();
 }
 
+//______________________________________________________________________________
 void AliESDEvent::WriteToTree(TTree* tree) const {
   // Book the branches as in TTree::Branch(TCollection*)
   // but add a "." at the end of top level branches which are
@@ -1607,10 +1718,13 @@ void AliESDEvent::WriteToTree(TTree* tree) const {
       tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),kBufsize, splitLevel);
     }
   }
+
   tree->Branch("fDetectorStatus",(void*)&fDetectorStatus,"fDetectorStatus/l");
+  tree->Branch("fDAQDetectorPattern",(void*)&fDAQDetectorPattern,"fDAQDetectorPattern/i");
+  tree->Branch("fDAQAttributes",(void*)&fDAQAttributes,"fDAQAttributes/i");
 }
 
-
+//______________________________________________________________________________
 void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
 //
 // Connect the ESDEvent to a tree
@@ -1708,6 +1822,8 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
       fESDObjects->Delete();
       fESDObjects = connectedList;
       tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus); //PH probably redundant
+      tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
+      tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
       GetStdContent(); 
       fOldMuonStructure = fESDObjects->TestBit(BIT(23));
       fConnected = true;
@@ -1772,6 +1888,9 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
       }
     }
     tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus);
+    tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
+    tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
+
     GetStdContent();
     // when reading back we are not owner of the list 
     // must not delete it
@@ -1808,6 +1927,9 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
       }
     }
     tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus);
+    tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
+    tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
+
     GetStdContent();
     // when reading back we are not owner of the list 
     // must not delete it
@@ -1815,7 +1937,7 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
   }
 }
 
-
+//______________________________________________________________________________
 void AliESDEvent::CopyFromOldESD()
 {
   // Method which copies over everthing from the old esd structure to the 
@@ -1907,14 +2029,10 @@ void AliESDEvent::CopyFromOldESD()
       AddCaloCluster(fESDOld->GetCaloCluster(i));
     }
          
-       #ifdef MFT_UPGRADE  
-       // MFT
-//     if (fESDOld->GetMFTData()) SetMFTData(fESDOld->GetMFTData());
-    #endif
-
   }// if fesdold
 }
 
+//______________________________________________________________________________
 Bool_t AliESDEvent::IsEventSelected(const char *trigExpr) const
 {
   // Check if the event satisfies the trigger
@@ -1922,12 +2040,13 @@ Bool_t AliESDEvent::IsEventSelected(const char *trigExpr) const
   // trigExpr can be any logical expression
   // of the trigger classes defined in AliESDRun
   // In case of wrong syntax return kTRUE.
+  // Modified by rl for 100 classes - to be tested
 
   TString expr(trigExpr);
   if (expr.IsNull()) return kTRUE;
 
   ULong64_t mask = GetTriggerMask();
-  for(Int_t itrig = 0; itrig < AliESDRun::kNTriggerClasses; itrig++) {
+  for(Int_t itrig = 0; itrig < AliESDRun::kNTriggerClasses/2; itrig++) {
     if (mask & (1ull << itrig)) {
       expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig),"1");
     }
@@ -1935,6 +2054,15 @@ Bool_t AliESDEvent::IsEventSelected(const char *trigExpr) const
       expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig),"0");
     }
   }
+  ULong64_t maskNext50 = GetTriggerMaskNext50();
+  for(Int_t itrig = 0; itrig < AliESDRun::kNTriggerClasses/2; itrig++) {
+    if (maskNext50 & (1ull << itrig)) {
+      expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig+50),"1");
+    }
+    else {
+      expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig+50),"0");
+    }
+  }
 
   Int_t error;
   if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
@@ -1946,6 +2074,7 @@ Bool_t AliESDEvent::IsEventSelected(const char *trigExpr) const
 
 }
 
+//______________________________________________________________________________
 TObject*  AliESDEvent::GetHLTTriggerDecision() const
 {
   // get the HLT trigger decission object
@@ -1968,6 +2097,7 @@ TString   AliESDEvent::GetHLTTriggerDescription() const
   return description;
 }
 
+//______________________________________________________________________________
 Bool_t    AliESDEvent::IsHLTTriggerFired(const char* name) const
 {
   // get the HLT trigger decission description
@@ -2076,6 +2206,7 @@ void AliESDEvent::EstimateMultiplicity(Int_t &tracklets, Int_t &trITSTPC, Int_t
   //
 }
 
+//______________________________________________________________________________
 Bool_t AliESDEvent::IsPileupFromSPDInMultBins() const {
     Int_t nTracklets=GetMultiplicity()->GetNumberOfTracklets();
     if(nTracklets<20) return IsPileupFromSPD(3,0.8);
@@ -2083,6 +2214,7 @@ Bool_t AliESDEvent::IsPileupFromSPDInMultBins() const {
     else return IsPileupFromSPD(5,0.8);
 }
 
+//______________________________________________________________________________
 void  AliESDEvent::SetTOFHeader(const AliTOFHeader *header)
 {
   //
@@ -2102,18 +2234,21 @@ void  AliESDEvent::SetTOFHeader(const AliTOFHeader *header)
 
 }
 
+//______________________________________________________________________________
 AliCentrality* AliESDEvent::GetCentrality()
 {
     if (!fCentrality) fCentrality = new AliCentrality();
     return  fCentrality;
 }
 
+//______________________________________________________________________________
 AliEventplane* AliESDEvent::GetEventplane()
 {
     if (!fEventplane) fEventplane = new AliEventplane();
     return  fEventplane;
 }
 
+//______________________________________________________________________________
 Float_t AliESDEvent::GetVZEROEqMultiplicity(Int_t i) const
 {
   // Get VZERO Multiplicity for channel i
@@ -2131,3 +2266,194 @@ Float_t AliESDEvent::GetVZEROEqMultiplicity(Int_t i) const
 
   return (fESDVZERO->GetMultiplicity(i)/factor);
 }
+
+//______________________________________________________________________________
+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;}
+