]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMixedEvent.cxx
Changes for report #69974: Virtual class for calorimeter analysis objects
[u/mrichter/AliRoot.git] / STEER / AliMixedEvent.cxx
index 65aa4b970f2fdf050dd5cd33880f80cbff642519..7b651f1e5db4da8ef8f0bf3cb653a271bf62342e 100644 (file)
 #include <TMath.h>
 #include <TMatrix.h>
 #include <TMatrixD.h>
+#include "AliESDCaloCluster.h"
+#include "AliAODCaloCluster.h"
+#include "AliAODCaloCells.h"
+#include "AliESDCaloCells.h"
+#include "AliLog.h"
+#include "AliVCaloCells.h"
+
 
 ClassImp(AliMixedEvent)
 
 
 AliMixedEvent::AliMixedEvent() :
-    AliVEvent(),
-    fEventList(),
-    fNEvents(0),       
-    fNumberOfTracks(0),
-    fNTracksCumul(0),
-    fMeanVertex(0)
+  AliVEvent(),
+  fEventList(),
+  fNEvents(0),       
+  fNumberOfTracks(0),
+  fNumberOfCaloClusters(0), 
+  fNumberOfPHOSCells(0), 
+  fNumberOfEMCALCells(0),
+  fNTracksCumul(0),
+  fNCaloClustersCumul(0),
+  fNPHOSCellsCumul(0), 
+  fNEMCALCellsCumul(0), 
+  fPHOSCells(NULL), 
+  fEMCALCells(NULL), 
+  fMeanVertex(0)
 {
     // Default constructor
 }
 
 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
-    AliVEvent(Evnt),
-    fEventList(),
-    fNEvents(0),
-    fNumberOfTracks(0),
-    fNTracksCumul(0),
-    fMeanVertex(0)
+  AliVEvent(Evnt),
+  fEventList(),
+  fNEvents(0),
+  fNumberOfTracks(0),
+  fNumberOfCaloClusters(0), 
+  fNumberOfPHOSCells(0), 
+  fNumberOfEMCALCells(0),
+  fNTracksCumul(0),
+  fNCaloClustersCumul(0),
+  fNPHOSCellsCumul(0), 
+  fNEMCALCellsCumul(0), 
+  fPHOSCells(NULL), 
+  fEMCALCells(NULL), 
+  fMeanVertex(0)
 { } // Copy constructor
 
 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
@@ -63,6 +86,14 @@ AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
   return *this; 
 }
 
+AliMixedEvent::~AliMixedEvent() 
+{
+    // dtor
+  Reset();
+  delete fPHOSCells ; 
+  delete fEMCALCells ; 
+} 
+
 
 void AliMixedEvent::AddEvent(AliVEvent* evt)
 {
@@ -74,19 +105,79 @@ void AliMixedEvent::AddEvent(AliVEvent* evt)
 void AliMixedEvent::Init()
 {
     // Initialize meta information
-    fNEvents = fEventList.GetEntries();
-    fNTracksCumul = new Int_t[fNEvents];
-    fNumberOfTracks = 0;
-    TIter next(&fEventList);
-    AliVEvent* event;
-    Int_t iev = 0;
+  fNEvents = fEventList.GetEntries();
+  fNTracksCumul = new Int_t[fNEvents];
+  fNumberOfTracks = 0;
+  fNCaloClustersCumul = new Int_t[fNEvents];
+  fNumberOfCaloClusters = 0;
+  fNumberOfPHOSCells    = 0;  
+  fNumberOfEMCALCells   = 0; 
+  fNPHOSCellsCumul  = new Int_t[fNEvents];
+  fNEMCALCellsCumul = new Int_t[fNEvents];
+
+  TIter next(&fEventList);
+  AliVEvent* event;
+  Int_t iev = 0;
     
-    while((event = (AliVEvent*)next())) {
-       fNTracksCumul[iev++] = fNumberOfTracks;
-       fNumberOfTracks += (event->GetNumberOfTracks());
+  while((event = (AliVEvent*)next())) {
+    fNTracksCumul[iev] = fNumberOfTracks;
+    fNumberOfTracks += (event->GetNumberOfTracks());
+    fNCaloClustersCumul[iev] = fNumberOfCaloClusters;
+    fNumberOfCaloClusters += event->GetNumberOfCaloClusters(); 
+    fNPHOSCellsCumul[iev] = fNumberOfPHOSCells;
+    if (event->GetPHOSCells()) 
+      fNumberOfPHOSCells += event->GetPHOSCells()->GetNumberOfCells(); 
+    fNEMCALCellsCumul[iev] = fNumberOfEMCALCells;
+    if (event->GetEMCALCells()) 
+      fNumberOfEMCALCells += event->GetEMCALCells()->GetNumberOfCells(); 
+    iev++ ;  
+  }
+  if (!fPHOSCells) {
+    AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
+    if (dynamic_cast<AliESDCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
+      fPHOSCells = new AliESDCaloCells() ; 
+    } else if (dynamic_cast<AliAODCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
+      fPHOSCells = new AliAODCaloCells() ; 
+    } else {
+      AliFatal("Unrecognized CaloCluster type (not ESD nor AOD)") ; 
     }
-}
+  }
+  fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ; 
+  fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
+
+  if (!fEMCALCells){
+    AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
+    if (dynamic_cast<AliESDCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
+      fEMCALCells = new AliESDCaloCells() ; 
+    } else if (dynamic_cast<AliAODCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
+      fEMCALCells = new AliAODCaloCells() ; 
+    } else {
+      AliFatal("Unrecognized CaloCluster type (not ESD nor AOD)") ; 
+    }
+  }
+  fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ; 
+  fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
+
+  next.Reset() ; 
+  Short_t phosPos = 0, emcalPos = 0; 
 
+  while((event = (AliVEvent*)next())) {
+    if (event->GetPHOSCells()) {
+      Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
+      AliVCaloCells * phosCells = event->GetPHOSCells() ; 
+      for (Int_t icell = 0; icell < ncells; icell++) {
+        fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), phosCells->GetTime(icell)) ; 
+      }
+    }
+    if (event->GetEMCALCells()) {
+      Int_t ncells = event->GetEMCALCells()->GetNumberOfCells() ;
+      AliVCaloCells * emcalCells = event->GetEMCALCells() ; 
+      for (Int_t icell = 0; icell < ncells; icell++) {
+        fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), emcalCells->GetTime(icell)) ; 
+      }
+    }
+  }  
+}
 
 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
 {
@@ -99,33 +190,92 @@ AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
     return (evt->GetTrack(irel));
 }
 
+AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
+{
+    // Return calo cluster # i
+  Int_t iEv  = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
+  while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
+  
+  Int_t irel = i - fNCaloClustersCumul[iEv];
+  AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
+  return (evt->GetCaloCluster(irel));
+}
+
 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
 {
-    // Return track # i
+    // Return vertex of track # i
     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
     while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
     return (evt->GetPrimaryVertex());
 }
 
+const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
+{
+    // Return vertex of event # i
+  if (i > fNEvents)
+    AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;  
+  AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
+  return (evt->GetPrimaryVertex());
+}
+
 void AliMixedEvent::Reset()
 {
     // Reset the event
-    fEventList.Clear();
-    fNEvents = 0;
-    fNumberOfTracks = 0;
-    if (fNTracksCumul) {
-       delete[]  fNTracksCumul;
-       fNTracksCumul = 0;
-    }
+  fEventList.Clear();
+  fNEvents = 0;
+  fNumberOfTracks = 0;
+  fNumberOfCaloClusters = 0;
+  fNumberOfPHOSCells = 0;
+  fNumberOfEMCALCells = 0;
+  if (fNTracksCumul) {
+    delete[]  fNTracksCumul;
+    fNTracksCumul = 0;
+  }
+  if (fNCaloClustersCumul) {
+    delete[]  fNCaloClustersCumul;
+    fNCaloClustersCumul = 0;
+  }
+  if (fNPHOSCellsCumul) {
+    delete[]  fNPHOSCellsCumul;
+    fNPHOSCellsCumul = 0;
+  }
+  if (fNEMCALCellsCumul) {
+    delete[]  fNEMCALCellsCumul;
+    fNEMCALCellsCumul = 0;
+  }
+  if (fPHOSCells) {
+     fPHOSCells->DeleteContainer();
+  }
+  if (fEMCALCells) {
+    fEMCALCells->DeleteContainer();
+  }
 }
 
-Int_t AliMixedEvent::EventIndex(Int_t itrack)
+Int_t AliMixedEvent::EventIndex(Int_t itrack) const
 {
   // Return the event index for track #itrack
   return  TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
 }
 
+Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
+{
+    // Return the event index for track #itrack
+  return  TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
+}
+
+Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
+{
+    // Return the event index for track #itrack
+  return  TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
+}
+
+Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
+{
+    // Return the event index for track #itrack
+  return  TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
+}
+
 Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){
 //
 // Calculate the mean vertex psoitions from events in the buffer