]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDEvent.cxx
- Compute parameter covariances including absorber dispersion effects
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.cxx
index a2629bb7eea36ec0c913197d02e7194a847cf088..f88690d1c64e82da71df790837506244f264bc19 100644 (file)
 //-----------------------------------------------------------------
 
 #include "TList.h"
+#include "TRefArray.h"
 #include <TNamed.h>
 
+#include "AliLog.h"
 #include "AliESDEvent.h"
 #include "AliESDfriend.h"
 #include "AliESDVZERO.h"
 #include "AliESDHLTtrack.h"
 #include "AliESDFMD.h"
 #include "AliESD.h"
+#include "AliESDMuonTrack.h"
+#include "AliESDPmdTrack.h"
+#include "AliESDTrdTrack.h"
+#include "AliESDVertex.h"
+#include "AliESDcascade.h"
+#include "AliESDPmdTrack.h"
+#include "AliESDTrdTrack.h"
+#include "AliESDVertex.h"
+#include "AliESDcascade.h"
+#include "AliESDkink.h"
+#include "AliESDtrack.h"
+#include "AliESDHLTtrack.h"
+#include "AliESDCaloCluster.h"
+#include "AliESDv0.h"
+#include "AliESDFMD.h"
+#include "AliESDVZERO.h"
+#include "AliMultiplicity.h"
+#include "AliRawDataErrorLog.h"
 
 
 ClassImp(AliESDEvent)
@@ -56,12 +76,13 @@ ClassImp(AliESDEvent)
                                                       "PmdTracks",
                                                       "TrdTracks",
                                                       "V0s",
-                                                      "Cascadess",
+                                                      "Cascades",
                                                       "Kinks",
                                                       "CaloClusters",
                                                       "AliRawDataErrorLogs"};
 //______________________________________________________________________________
 AliESDEvent::AliESDEvent():
+  AliVEvent(),
   fESDObjects(new TList()),
   fESDRun(0),
   fHeader(0),
@@ -93,7 +114,7 @@ AliESDEvent::AliESDEvent():
 }
 //______________________________________________________________________________
 AliESDEvent::AliESDEvent(const AliESDEvent& esd):
-  TObject(esd),
+  AliVEvent(esd),
   fESDObjects(new TList()),
   fESDRun(new AliESDRun(*esd.fESDRun)),
   fHeader(new AliESDHeader(*esd.fHeader)),
@@ -155,7 +176,7 @@ AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
   // Assignment operator
 
   if(&source == this) return *this;
-  TObject::operator=(source);
+  AliVEvent::operator=(source);
 
   fESDRun = new AliESDRun(*source.fESDRun);
   fHeader = new AliESDHeader(*source.fHeader);
@@ -259,25 +280,30 @@ void AliESDEvent::ResetStdContent()
   if(fESDTZERO) fESDTZERO->Reset(); 
   // CKB no clear/reset implemented
   if(fSPDVertex){
+    fSPDVertex->~AliESDVertex();
     new (fSPDVertex) AliESDVertex();
     fSPDVertex->SetName(fESDListName[kSPDVertex]);
   }
   if(fPrimaryVertex){
+    fPrimaryVertex->~AliESDVertex();
     new (fPrimaryVertex) AliESDVertex();
     fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
   }
-  if(fSPDMult)new (fSPDMult) AliMultiplicity();
+  if(fSPDMult){
+    fSPDMult->~AliMultiplicity();
+    new (fSPDMult) AliMultiplicity();
+  }
   if(fPHOSTrigger)fPHOSTrigger->Reset(); 
   if(fEMCALTrigger)fEMCALTrigger->Reset(); 
-  if(fTracks)fTracks->Clear();
+  if(fTracks)fTracks->Delete();
   if(fMuonTracks)fMuonTracks->Clear();
   if(fPmdTracks)fPmdTracks->Clear();
   if(fTrdTracks)fTrdTracks->Clear();
   if(fV0s)fV0s->Clear();
   if(fCascades)fCascades->Clear();
   if(fKinks)fKinks->Clear();
-  if(fCaloClusters)fCaloClusters->Clear();
-  if(fErrorLogs) fErrorLogs->Clear();
+  if(fCaloClusters)fCaloClusters->Delete();
+  if(fErrorLogs) fErrorLogs->Delete();
 
   // don't reset fconnected fConnected ;
 
@@ -334,6 +360,8 @@ void AliESDEvent::Print(Option_t *) const
   printf("                 emcal     %d\n", GetNumberOfEMCALClusters());
   printf("                 FMD       %s\n", (fESDFMD ? "yes" : "no"));
   printf("                 VZERO     %s\n", (fESDVZERO ? "yes" : "no"));
+
+  return;
 }
 
 void AliESDEvent::SetESDfriend(const AliESDfriend *ev) {
@@ -354,6 +382,249 @@ void AliESDEvent::SetESDfriend(const AliESDfriend *ev) {
   }
 }
 
+Bool_t  AliESDEvent::RemoveKink(Int_t rm) {
+  // ---------------------------------------------------------
+  // 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) {
+  // ---------------------------------------------------------
+  // 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) {
+  // ---------------------------------------------------------
+  // 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 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 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 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=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  AliESDEvent::AddTrack(const AliESDtrack *t) {
     // Add track
     TClonesArray &ftr = *fTracks;
@@ -362,6 +633,24 @@ Int_t  AliESDEvent::AddTrack(const AliESDtrack *t) {
     return  track->GetID();    
 }
 
+ void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) {
+    TClonesArray &fmu = *fMuonTracks;
+    new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
+}
+
+void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) {
+  TClonesArray &fpmd = *fPmdTracks;
+  new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
+}
+
+void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) {
+  TClonesArray &ftrd = *fTrdTracks;
+  new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
+}
+
+
+
+
 Int_t AliESDEvent::AddKink(const AliESDkink *c) {
     // Add kink
     TClonesArray &fk = *fKinks;
@@ -370,6 +659,13 @@ Int_t AliESDEvent::AddKink(const AliESDkink *c) {
     return fKinks->GetEntriesFast()-1;
 }
 
+
+void AliESDEvent::AddCascade(const AliESDcascade *c) {
+  TClonesArray &fc = *fCascades;
+  new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
+}
+
+
 Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) {
     // Add calocluster
     TClonesArray &fc = *fCaloClusters;
@@ -379,26 +675,37 @@ Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) {
   }
 
 
+  void  AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) {
+    TClonesArray &errlogs = *fErrorLogs;
+    new(errlogs[errlogs.GetEntriesFast()])  AliRawDataErrorLog(*log);
+  }
+
 void  AliESDEvent::SetVertex(const AliESDVertex *vertex) {
   // use already allocated space
   if(fSPDVertex){
-    new(fSPDVertex)  AliESDVertex(*vertex);
+    *fSPDVertex = *vertex;
     fSPDVertex->SetName(fESDListName[kSPDVertex]);
   }
 }
 
 void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) {
-  // use already allocated space
   if(fPrimaryVertex){
-    new(fPrimaryVertex)  AliESDVertex(*vertex);
+    *fPrimaryVertex = *vertex;
     fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
   }
 }
 
+void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) {
+  if(fSPDMult){
+    *fSPDMult = *mul;
+  }
+}
+
+
 void AliESDEvent::SetFMDData(AliESDFMD * obj) { 
   // use already allocated space
   if(fESDFMD){
-    new(fESDFMD) AliESDFMD(*obj); 
+    *fESDFMD = *obj;
   }
 }
 
@@ -417,9 +724,12 @@ void AliESDEvent::GetESDfriend(AliESDfriend *ev) const {
   Int_t ntrk=GetNumberOfTracks();
 
   for (Int_t i=0; i<ntrk; i++) {
-    const AliESDtrack *t=GetTrack(i);
+    AliESDtrack *t=GetTrack(i);
     const AliESDfriendTrack *f=t->GetFriendTrack();
     ev->AddTrack(f);
+
+    t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
+
   }
 }
 
@@ -513,9 +823,6 @@ void AliESDEvent::CreateStdContent()
   SetStdNames();
   // read back pointers
   GetStdContent();
-
-
-
 }
 
 TObject* AliESDEvent::FindListObject(const char *name){
@@ -523,9 +830,50 @@ TObject* AliESDEvent::FindListObject(const char *name){
   return 0;
 } 
 
+Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
+{
+  // fills the provided TRefArray with all found phos clusters
+
+  clusters->Clear();
+
+  AliESDCaloCluster *cl = 0;
+  for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
+
+    if ( cl = GetCaloCluster(i)) {
+      if (cl->IsPHOS()){
+       clusters->Add(cl);
+       printf("IsPHOS %d Size: %d \n",i,clusters->GetEntriesFast());
+      }
+    }
+  }
+  return clusters->GetEntriesFast();
+}
+
+Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
+{
+  // fills the provided TRefArray with all found phos clusters
+
+  clusters->Clear();
+
+  AliESDCaloCluster *cl = 0;
+  for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
+
+    if ( cl = GetCaloCluster(i)) {
+      if (cl->IsEMCAL()){
+       clusters->Add(cl);
+       printf("IsEMCAL %d Size: %d \n",i,clusters->GetEntriesFast());
+      }
+    }
+  }
+  return clusters->GetEntriesFast();
+}
+
+
 void AliESDEvent::ReadFromTree(TTree *tree){
-  
+
+  // load the TTree
+  tree->LoadTree(0);
+
   // if we find the "ESD" branch on the tree we do have the old structure
   if(tree->GetBranch("ESD")){
       char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
@@ -560,7 +908,8 @@ void AliESDEvent::ReadFromTree(TTree *tree){
     if (connectedList) {
       // If connected use the connected list if objects
       fESDObjects->Delete();
-      fESDObjects = connectedList; 
+      fESDObjects = connectedList;
+      GetStdContent(); 
       fConnected = true;
       return;
     }
@@ -588,7 +937,6 @@ void AliESDEvent::ReadFromTree(TTree *tree){
       if(bname.CompareTo("AliESDfriend")==0)
        {
          // AliESDfriend does not have a name ...
-         printf("Setting AlieSDFrien \n");
          tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
        }
       else{
@@ -661,7 +1009,7 @@ void AliESDEvent::CopyFromOldESD()
 
     // FMD
     
-    SetFMDData(fESDOld->GetFMDData());
+    if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
 
     // T0
 
@@ -670,13 +1018,13 @@ void AliESDEvent::CopyFromOldESD()
     //  leave amps out
 
     // VZERO
-    SetVZEROData(fESDOld->GetVZEROData());
+    if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
 
-    SetVertex(fESDOld->GetVertex());
+    if(fESDOld->GetVertex())SetVertex(fESDOld->GetVertex());
 
-    SetPrimaryVertex(fESDOld->GetPrimaryVertex());
+    if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
 
-    SetMultiplicity(fESDOld->GetMultiplicity());
+    if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
     
     for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
       AddTrack(fESDOld->GetTrack(i));