]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMCEvent.cxx
setting of the class name of the entry's object included in all constructors
[u/mrichter/AliRoot.git] / STEER / AliMCEvent.cxx
index 286c9a96716bcb697aad244616a083c4b591e7e1..896f7d4ee083ca3bf4408c374be155dff70e55f7 100644 (file)
 #include <TClonesArray.h>
 #include <TRefArray.h>
 #include <TList.h>
+#include <TArrayF.h>
 
 #include "AliLog.h"
 #include "AliMCEvent.h"
+#include "AliMCVertex.h"
 #include "AliStack.h"
 #include "AliTrackReference.h"
 #include "AliHeader.h"
@@ -43,7 +45,7 @@ Int_t AliMCEvent::fgkBgLabelOffset(10000000);
 AliMCEvent::AliMCEvent():
     AliVEvent(),
     fStack(0),
-    fMCParticles(new TClonesArray("AliMCParticle",1000)),
+    fMCParticles(0),
     fMCParticleMap(0),
     fHeader(new AliHeader()),
     fTRBuffer(0),
@@ -55,7 +57,9 @@ AliMCEvent::AliMCEvent():
     fNparticles(-1),
     fSubsidiaryEvents(0),
     fPrimaryOffset(0),
-    fSecondaryOffset(0)
+    fSecondaryOffset(0),
+    fExternal(0),
+    fVertex(0)
 {
     // Default constructor
 }
@@ -75,7 +79,9 @@ AliMCEvent::AliMCEvent(const AliMCEvent& mcEvnt) :
     fNparticles(mcEvnt.fNparticles),
     fSubsidiaryEvents(0),
     fPrimaryOffset(0),
-    fSecondaryOffset(0)
+    fSecondaryOffset(0),
+    fExternal(0),
+    fVertex(mcEvnt.fVertex)
 { 
 // Copy constructor
 }
@@ -100,6 +106,8 @@ void AliMCEvent::ConnectTreeE (TTree* tree)
 void AliMCEvent::ConnectTreeK (TTree* tree)
 {
     // Connect the kinematics tree to the stack
+    if (!fMCParticles) fMCParticles = new TClonesArray("AliMCParticle",1000);
+    //
     fStack = fHeader->Stack();
     fStack->ConnectTree(tree);
     //
@@ -165,11 +173,6 @@ Int_t AliMCEvent::GetParticleAndTR(Int_t i, TParticle*& particle, TClonesArray*&
 void AliMCEvent::Clean()
 {
     // Clean-up before new trees are connected
-//    if (fHeader) {
-//     delete fHeader;
-//     fHeader = 0;
-//    }
-
     delete fStack; fStack = 0;
 
     // Clear TR
@@ -454,12 +457,18 @@ void AliMCEvent::ReorderAndExpandTreeTR()
     fTreeTR = fTmpTreeTR;
 }
 
-AliMCParticle* AliMCEvent::GetTrack(Int_t i) const
+AliVParticle* AliMCEvent::GetTrack(Int_t i) const
 {
     // Get MC Particle i
     //
+
+    if (fExternal) {
+       return ((AliVParticle*) (fMCParticles->At(i)));
+    }
+    
     //
     // Check first if this explicitely accesses the subsidiary event
+    
     if (i >= BgLabelOffset()) {
        if (fSubsidiaryEvents) {
            AliMCEvent* bgEvent = (AliMCEvent*) (fSubsidiaryEvents->At(1));
@@ -560,7 +569,7 @@ AliMCParticle* AliMCEvent::GetTrack(Int_t i) const
     return mcParticle;
 }
 
-    AliGenEventHeader* AliMCEvent::GenEventHeader() {return (fHeader->GenEventHeader());}
+AliGenEventHeader* AliMCEvent::GenEventHeader() const {return (fHeader->GenEventHeader());}
 
 
 void AliMCEvent::AddSubsidiaryEvent(AliMCEvent* event) 
@@ -626,6 +635,8 @@ Bool_t AliMCEvent::IsPhysicalPrimary(Int_t i)
 
 void AliMCEvent::InitEvent()
 {
+//
+// Initialize the subsidiary event structure
     if (fSubsidiaryEvents) {
        TIter next(fSubsidiaryEvents);
        AliMCEvent* evt;
@@ -649,6 +660,37 @@ void AliMCEvent::InitEvent()
        }
     }
 }
+void AliMCEvent::PreReadAll()                              
+{
+    // Preread the MC information
+    Int_t i;
+    // secondaries
+    for (i = fStack->GetNprimary(); i < fStack->GetNtrack(); i++) 
+    {
+       GetTrack(i);
+    }
+    // primaries
+    for (i = 0; i < fStack->GetNprimary(); i++) 
+    {
+       GetTrack(i);
+    }
+    
+    
+}
+
+
+const AliVVertex * AliMCEvent::GetPrimaryVertex() const 
+{
+    // Create a MCVertex object from the MCHeader information
+    TArrayF v;
+    GenEventHeader()->PrimaryVertex(v) ;
+    if (!fVertex) {
+       fVertex = new AliMCVertex(v[0], v[1], v[2]);
+    } else {
+       ((AliMCVertex*) fVertex)->SetPosition(v[0], v[1], v[2]);
+    }
+    return fVertex;
+}
 
 
 ClassImp(AliMCEvent)