]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDEvent.cxx
Base class (AliMisaligner); each detector will provide its derived class,
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.cxx
index eddc4acd00290f4a21df3d5a27c2e6f046848577..2324baf8cd8d95341cef4e96421787b6ce3fe91d 100644 (file)
@@ -245,7 +245,7 @@ AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
       }
       else if(mine->InheritsFrom("TCollection")){
        if(mine->InheritsFrom("TClonesArray"))
-         dynamic_cast<TClonesArray*>(mine)->SetClass(its->ClassName());
+         dynamic_cast<TClonesArray*>(mine)->SetClass(dynamic_cast<TClonesArray*>(its)->GetClass());
        dynamic_cast<TCollection*>(mine)->SetName(name);
       }
       AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
@@ -639,6 +639,15 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     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();
@@ -654,6 +663,20 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     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;
@@ -718,6 +741,17 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
        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++) {
@@ -734,6 +768,21 @@ Bool_t  AliESDEvent::RemoveTrack(Int_t rm) const {
     }
   }
 
+  // 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;
 }
 
@@ -883,9 +932,9 @@ void  AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex)
   }
 }
 
-void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) 
+void  AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex) 
 {
-  // Set the primary vertex
+  // Set the primary vertex reconstructed using he ESD tracks.
   // use already allocated space
   if(fPrimaryVertex){
     *fPrimaryVertex = *vertex;
@@ -893,6 +942,23 @@ void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex)
   }
 }
 
+const AliESDVertex * AliESDEvent::GetPrimaryVertex() const 
+{
+  //
+  // Get the "best" available reconstructed primary vertex.
+  //
+  if(fPrimaryVertex){
+    if (fPrimaryVertex->GetStatus()) return fPrimaryVertex;
+  }
+  if(fSPDVertex){
+    if (fSPDVertex->GetStatus()) return fSPDVertex;
+  }
+  if(fTPCVertex) return fTPCVertex;
+  
+  AliWarning("No primary vertex available. Returning the \"default\"...");
+  return fSPDVertex;
+}
+
 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) 
 {
   // Set the SPD Multiplicity
@@ -1113,6 +1179,7 @@ void AliESDEvent::WriteToTree(TTree* tree) const {
 
   while ((obj = next())) {
     branchname.Form("%s", obj->GetName());
+    if(branchname.CompareTo("AliESDfriend")==0)branchname = "ESDfriend.";
     if ((kSplitlevel > 1) &&  !obj->InheritsFrom(TClonesArray::Class())) {
       if(!branchname.EndsWith("."))branchname += ".";
     }
@@ -1341,7 +1408,8 @@ void AliESDEvent::CopyFromOldESD()
            0,
            fESDOld->GetZDCN2Energy(),
            fESDOld->GetZDCP2Energy(),
-           fESDOld->GetZDCParticipants());
+           fESDOld->GetZDCParticipants(),
+          0);
 
     // FMD
     
@@ -1358,7 +1426,7 @@ void AliESDEvent::CopyFromOldESD()
 
     if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
 
-    if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
+    if(fESDOld->GetPrimaryVertex())SetPrimaryVertexTracks(fESDOld->GetPrimaryVertex());
 
     if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());