]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Code to find the MC header for a given track (itrk < nprimary)
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 6 Dec 2012 12:24:31 +0000 (12:24 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 6 Dec 2012 12:24:31 +0000 (12:24 +0000)
MvL

STEER/STEERBase/AliMCEvent.cxx
STEER/STEERBase/AliMCEvent.h

index 8d7ad47e9232e238b283c22b8cf86e974b85e9ce..363ea01c126ca10fa1a16c047f227d00696b427a 100644 (file)
@@ -594,6 +594,39 @@ void AliMCEvent::AddSubsidiaryEvent(AliMCEvent* event)
     fSubsidiaryEvents->Add(event);
 }
 
+AliGenEventHeader *AliMCEvent::FindHeader(Int_t ipart) {
+  //
+  // Get Header belonging to this track; 
+  // only works for primaries (i.e. particles coming from the Generator)
+  // Also sorts out the case of Cocktail event (get header of subevent in cocktail generetor header)  
+  //
+
+  AliMCEvent *event = this;
+
+  if (fSubsidiaryEvents) {
+    // Get pointer to subevent if needed
+    ipart = FindIndexAndEvent(ipart,event); 
+  }
+
+  AliGenEventHeader* header = event->GenEventHeader();
+  if (ipart >= header->NProduced()) {
+    AliWarning(Form("Not a primary -- returning 0 (idx %d, nPrimary %d)",ipart,header->NProduced()));
+    return 0;
+  }
+  AliGenCocktailEventHeader *coHeader = dynamic_cast<AliGenCocktailEventHeader*>(header);
+  if (coHeader) { // Cocktail event
+    TList* headerList = coHeader->GetHeaders();
+    TIter headIt(headerList);
+    Int_t nproduced = 0;
+    do { // Go trhough all headers and look for the correct one
+      header = (AliGenEventHeader*) headIt();
+      nproduced += header->NProduced();
+    } while (header && ipart >= nproduced);
+  }
+
+  return header;
+}
+
 Int_t AliMCEvent::FindIndexAndEvent(Int_t oldidx, AliMCEvent*& event) const
 {
     // Find the index and event in case of composed events like signal + background
index 26ca291d0e11c0f0d6d04f21eba70c4ab234a047..b286a9cf425c9a4cf9de53c1fb8372a09abee7e1 100644 (file)
@@ -133,6 +133,7 @@ public:
     virtual void      SetParticleArray(TClonesArray* mcParticles) 
        {fMCParticles = mcParticles; fNparticles = fMCParticles->GetEntries(); fExternal = kTRUE;}
     
+  virtual AliGenEventHeader *FindHeader(Int_t ipart);
     //Following needed only for mixed event
   virtual Int_t        EventIndex(Int_t)       const {return 0;}
   virtual Int_t        EventIndexForCaloCluster(Int_t) const {return 0;}