]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliStack.cxx
Updates received from Yermia
[u/mrichter/AliRoot.git] / STEER / AliStack.cxx
index fbf97c7e11875caff8881c2e844b0a6926602daf..747481180ce3d4ddf9fb18433b60ca86fbb65a58 100644 (file)
@@ -26,7 +26,9 @@
 ///////////////////////////////////////////////////////////////////////////////
 
  
+#include <TClonesArray.h>
 #include <TObjArray.h>
+#include <TPDGCode.h>
 #include <TParticle.h>
 #include <TParticlePDG.h>
 #include <TTree.h>
@@ -47,6 +49,7 @@ AliStack::AliStack():
   fParticleMap(0),
   fParticleFileMap(0),
   fParticleBuffer(0),
+  fCurrentTrack(0),
   fTreeK(0),
   fNtrack(0),
   fNprimary(0),
@@ -67,6 +70,7 @@ AliStack::AliStack(Int_t size, const char* evfoldname):
   fParticleMap(new TObjArray(size)),
   fParticleFileMap(0),
   fParticleBuffer(0),
+  fCurrentTrack(0),
   fTreeK(0),
   fNtrack(0),
   fNprimary(0),
@@ -83,25 +87,26 @@ AliStack::AliStack(Int_t size, const char* evfoldname):
 
 //_______________________________________________________________________
 AliStack::AliStack(const AliStack& st):
-  TVirtualMCStack(st),
-  fParticles(0),
-  fParticleMap(0),
-  fParticleFileMap(0),
-  fParticleBuffer(0),
-  fTreeK(0),
-  fNtrack(0),
-  fNprimary(0),
-  fCurrent(-1),
-  fCurrentPrimary(-1),
-  fHgwmk(0),
-  fLoadPoint(0)
+    TVirtualMCStack(st),
+    fParticles(new TClonesArray("TParticle",1000)),
+    fParticleMap(new TObjArray(*st.Particles())),
+    fParticleFileMap(st.fParticleFileMap),
+    fParticleBuffer(0),
+    fCurrentTrack(0),
+    fTreeK((TTree*)(st.fTreeK->Clone())),
+    fNtrack(st.GetNtrack()),
+    fNprimary(st.GetNprimary()),
+    fCurrent(-1),
+    fCurrentPrimary(-1),
+    fHgwmk(0),
+    fLoadPoint(0),
+    fEventFolderName(0)
 {
-  //
-  // Copy constructor
-  //
-  st.Copy(*this);
+    // Copy constructor
+    ConnectTree();
 }
 
+
 //_______________________________________________________________________
 void AliStack::Copy(TObject&) const
 {
@@ -304,8 +309,7 @@ void AliStack::PurifyKine()
   if(fHgwmk+1 == fNtrack) return;
 
   // First pass, invalid Daughter information
-
-  for(i=0; i<fNtrack; i++) {
+   for(i=0; i<fNtrack; i++) {
     // Preset map, to be removed later
     if(i<=fHgwmk) map[i]=i ; 
     else {
@@ -364,6 +368,7 @@ void AliStack::PurifyKine()
       }
     }
   }
+
   
   // Now loop on all registered hit lists
   TList* hitLists = gAlice->GetMCApp()->GetHitLists();
@@ -373,6 +378,7 @@ void AliStack::PurifyKine()
   while((hitList = dynamic_cast<TCollection*>(next()))) {
     TIter nexthit(hitList);
     AliHit *hit;
+    
     while((hit = dynamic_cast<AliHit*>(nexthit()))) {
        hit->SetTrack(map[hit->GetTrack()]);
     }
@@ -427,7 +433,7 @@ void AliStack::ReorderKine()
   //
   // Howmany secondaries have been produced ?
   Int_t nNew = fNtrack - fHgwmk - 1;
-  
+    
   if (nNew > 0) {
       Int_t i, j;
       TObjArray &particles = *fParticleMap;
@@ -438,13 +444,7 @@ void AliStack::ReorderKine()
       
       for (i = 0; i < nNew; i++) {
          if (particles.At(fHgwmk + 1 + i)) {
-//           tmp[i] = (TParticle*) (particles.At(fHgwmk + 1 + i))->Clone();
              tmp[i] = (TParticle*) (particles.At(fHgwmk + 1 + i));
-
-//           if (((TParticle*) (particles.At(fHgwmk + 1 + i)))->TestBit(kKeepBit))
-//               tmp[i]->SetBit(kKeepBit);
-//           if (((TParticle*) (particles.At(fHgwmk + 1 + i)))->TestBit(kDoneBit))
-//               tmp[i]->SetBit(kDoneBit);
          } else {
              tmp[i] = 0x0;
          }
@@ -461,7 +461,7 @@ void AliStack::ReorderKine()
       // The outer loop is over parents, the inner over children.
       // -1 refers to the primary particle
       //
-      for (i = -1; i < nNew - 1; i++) {
+      for (i = -1; i < nNew-1; i++) {
          Int_t ipa;
          TParticle* parP;
          if (i == -1) {
@@ -476,9 +476,12 @@ void AliStack::ReorderKine()
              parP = tmp[i];
          }
           // Reset daughter information
+
+         Int_t idaumin = parP->GetFirstDaughter() - fHgwmk - 1;
+         Int_t idaumax = parP->GetLastDaughter()  - fHgwmk - 1;
          parP->SetFirstDaughter(-1);
          parP->SetLastDaughter(-1);
-         for (j = i + 1; j < nNew; j++) {
+         for (j = idaumin; j <= idaumax; j++) {
               // Skip deleted particles
              if (!tmp[j])        continue;
               // Skip particles already handled
@@ -1041,3 +1044,100 @@ void AliStack::SetEventFolderName(const char* foldname)
  //Sets event folder name
  fEventFolderName = foldname;
 }
+
+Bool_t AliStack::IsStable(Int_t pdg) const
+{
+//
+// Decide whether particle (pdg) is stable
+//
+
+    const Int_t kNstable = 14;
+    Int_t i;
+
+    Int_t pdgStable[kNstable] = {
+       kGamma,             // Photon
+       kElectron,          // Electron
+       kMuonPlus,          // Muon 
+       kPiPlus,            // Pion
+       kKPlus,             // Kaon
+       kProton,            // Proton 
+       kNeutron,           // Neutron
+       kLambda0,           // Lambda_0
+       kSigmaMinus,        // Sigma Minus
+       kSigma0,            // Sigma_0
+       kSigmaPlus,         // Sigma Plus
+       3312,               // Xsi Minus 
+       3322,               // Xsi 
+       3334,               // Omega
+    };
+    
+    Bool_t isStable = kFALSE;
+    for (i = 0; i < kNstable; i++) {
+       if (pdg == TMath::Abs(pdgStable[i])) {
+           isStable = kTRUE;
+           break;
+       }
+    }
+
+    return isStable;
+}
+
+Bool_t AliStack::IsPhysicalPrimary(Int_t index)
+{
+    //
+    // Test if a particle is a physical primary according to the following definition:
+    // Particles produced in the collision including products of strong and
+    // electromagnetic decay and excluding feed-down from weak decays of strange
+    // particles.
+    //
+    TParticle* p = Particle(index);
+    Int_t ist = p->GetStatusCode();
+    
+    //
+    // Initial state particle
+    if (ist > 20) return kFALSE;
+    
+    Int_t pdg = TMath::Abs(p->GetPdgCode());
+    
+    if (!IsStable(pdg)) return kFALSE;
+    
+    if (index < GetNprimary()) {
+//
+// Particle produced by generator
+       return kTRUE;
+    } else {
+//
+// Particle produced during transport
+//
+// Check if this is a heavy flavor decay product
+       Int_t imo =  p->GetFirstMother();
+       TParticle* pm  = Particle(imo);
+       Int_t mpdg = TMath::Abs(pm->GetPdgCode());
+       Int_t mfl  = Int_t (mpdg / TMath::Power(10, Int_t(TMath::Log10(mpdg))));
+       //
+       // Light hadron
+       if (mfl < 4) return kFALSE;
+       
+       //
+       // Heavy flavor hadron produced by generator
+       if (imo <  GetNprimary()) {
+           return kTRUE;
+       }
+       
+       // To be sure that heavy flavor has not been produced in a secondary interaction
+       // Loop back to the generated mother
+       while (imo >=  GetNprimary()) {
+           imo = p->GetFirstMother();
+           pm  =  Particle(imo);
+       }
+       mpdg = TMath::Abs(pm->GetPdgCode());
+       mfl  = Int_t (mpdg / TMath::Power(10, Int_t(TMath::Log10(mpdg))));
+
+       if (mfl < 4) {
+           return kFALSE;
+       } else {
+           return kTRUE;
+       } 
+    } // produced by generator ?
+} 
+