]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliStack.cxx
silvermy@ornl.gov - SMcalib - directory with tools for SuperModule calibrations at...
[u/mrichter/AliRoot.git] / STEER / AliStack.cxx
index c26ccaea7a283cba1ab6e4f791e1da3ab14435fa..30349d72cea3e134d35899018fc767f193c3b29d 100644 (file)
@@ -41,8 +41,8 @@ ClassImp(AliStack)
 
 //_______________________________________________________________________
 AliStack::AliStack():
-  fParticles(0),
-  fParticleMap(0),
+  fParticles("TParticle", 1000),
+  fParticleMap(),
   fParticleFileMap(0),
   fParticleBuffer(0),
   fCurrentTrack(0),
@@ -62,8 +62,8 @@ AliStack::AliStack():
 
 //_______________________________________________________________________
 AliStack::AliStack(Int_t size, const char* /*evfoldname*/):
-  fParticles(new TClonesArray("TParticle",1000)),
-  fParticleMap(new TObjArray(size)),
+  fParticles("TParticle",1000),
+  fParticleMap(size),
   fParticleFileMap(0),
   fParticleBuffer(0),
   fCurrentTrack(0),
@@ -84,8 +84,8 @@ AliStack::AliStack(Int_t size, const char* /*evfoldname*/):
 //_______________________________________________________________________
 AliStack::AliStack(const AliStack& st):
     TVirtualMCStack(st),
-    fParticles(new TClonesArray("TParticle",1000)),
-    fParticleMap(new TObjArray(*st.Particles())),
+    fParticles("TParticle",1000),
+    fParticleMap(*(st.Particles())),
     fParticleFileMap(st.fParticleFileMap),
     fParticleBuffer(0),
     fCurrentTrack(0),
@@ -115,11 +115,7 @@ AliStack::~AliStack()
   // Destructor
   //
   
-  if (fParticles) {
-    fParticles->Delete();
-    delete fParticles;
-  }
-  delete fParticleMap;
+    fParticles.Clear();
 }
 
 //
@@ -134,8 +130,8 @@ void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
   //
   // Load a track on the stack
   //
-  // done     0 if the track has to be transported
-  //          1 if not
+  // done     1 if the track has to be transported
+  //          0 if not
   // parent   identifier of the parent track. -1 for a primary
   // pdg    particle code
   // pmom     momentum GeV/c
@@ -184,8 +180,8 @@ void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg,
   //
   // Load a track on the stack
   //
-  // done        0 if the track has to be transported
-  //             1 if not
+  // done        1 if the track has to be transported
+  //             0 if not
   // parent      identifier of the parent track. -1 for a primary
   // pdg         particle code
   // kS          generation status code
@@ -206,9 +202,8 @@ void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg,
   const Int_t kLastDaughter=-1;
 
 
-  TClonesArray &particles = *fParticles;
   TParticle* particle
-    = new(particles[fLoadPoint++]) 
+    = new(fParticles[fLoadPoint++]) 
       TParticle(pdg, is, parent, -1, kFirstDaughter, kLastDaughter,
                px, py, pz, e, vx, vy, vz, tof);
    
@@ -216,17 +211,25 @@ void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg,
   particle->SetWeight(weight);
   particle->SetUniqueID(mech);
 
-  if(!done) particle->SetBit(kDoneBit);
+  
+  
+  if(!done) {
+      particle->SetBit(kDoneBit);
+  } else {
+      particle->SetBit(kTransportBit);
+  }
+  
+  
 
   //  Declare that the daughter information is valid
   particle->SetBit(kDaughtersBit);
   //  Add the particle to the stack
   
   
-  fParticleMap->AddAtAndExpand(particle, fNtrack);//CHECK!!
+  fParticleMap.AddAtAndExpand(particle, fNtrack);//CHECK!!
 
   if(parent>=0) {
-      particle = dynamic_cast<TParticle*>(fParticleMap->At(parent));
+      particle = dynamic_cast<TParticle*>(fParticleMap.At(parent));
       if (particle) {
          particle->SetLastDaughter(fNtrack);
          if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
@@ -284,21 +287,20 @@ TParticle*  AliStack::PopPrimaryForTracking(Int_t i)
 }      
 
 //_____________________________________________________________________________
-void AliStack::PurifyKine()
+Bool_t AliStack::PurifyKine()
 {
   //
   // Compress kinematic tree keeping only flagged particles
   // and renaming the particle id's in all the hits
   //
 
-  TObjArray &particles = *fParticleMap;
-  int nkeep=fHgwmk+1, parent, i;
+  int nkeep = fHgwmk + 1, parent, i;
   TParticle *part, *father;
-  fTrackLabelMap.Set(particles.GetLast()+1);
+  fTrackLabelMap.Set(fParticleMap.GetLast()+1);
 
   // Save in Header total number of tracks before compression
   // If no tracks generated return now
-  if(fHgwmk+1 == fNtrack) return;
+  if(fHgwmk+1 == fNtrack) return kFALSE;
 
   // First pass, invalid Daughter information
   for(i=0; i<fNtrack; i++) {
@@ -306,7 +308,7 @@ void AliStack::PurifyKine()
       if(i<=fHgwmk) fTrackLabelMap[i]=i ; 
       else {
          fTrackLabelMap[i] = -99;
-         if((part=dynamic_cast<TParticle*>(particles.At(i)))) {
+         if((part=dynamic_cast<TParticle*>(fParticleMap.At(i)))) {
 //
 //        Check of this track should be kept for physics reasons 
              if (KeepPhysics(part)) KeepTrack(i);
@@ -320,34 +322,31 @@ void AliStack::PurifyKine()
   // Invalid daughter information for the parent of the first particle
   // generated. This may or may not be the current primary according to
   // whether decays have been recorded among the primaries
-  part = dynamic_cast<TParticle*>(particles.At(fHgwmk+1));
-  particles.At(part->GetFirstMother())->ResetBit(kDaughtersBit);
+  part = dynamic_cast<TParticle*>(fParticleMap.At(fHgwmk+1));
+  fParticleMap.At(part->GetFirstMother())->ResetBit(kDaughtersBit);
   // Second pass, build map between old and new numbering
   for(i=fHgwmk+1; i<fNtrack; i++) {
-      if(particles.At(i)->TestBit(kKeepBit)) {
-         
+      if(fParticleMap.At(i)->TestBit(kKeepBit)) {
          // This particle has to be kept
          fTrackLabelMap[i]=nkeep;
          // If old and new are different, have to move the pointer
-         if(i!=nkeep) particles[nkeep]=particles.At(i);
-         part = dynamic_cast<TParticle*>(particles.At(nkeep));
-         
+         if(i!=nkeep) fParticleMap[nkeep]=fParticleMap.At(i);
+         part = dynamic_cast<TParticle*>(fParticleMap.At(nkeep));
          // as the parent is always *before*, it must be already
          // in place. This is what we are checking anyway!
          if((parent=part->GetFirstMother())>fHgwmk) 
              if(fTrackLabelMap[parent]==-99) Fatal("PurifyKine","fTrackLabelMap[%d] = -99!\n",parent);
              else part->SetFirstMother(fTrackLabelMap[parent]);
-         
          nkeep++;
       }
   }
   
   // Fix daughters information
   for (i=fHgwmk+1; i<nkeep; i++) {
-      part = dynamic_cast<TParticle*>(particles.At(i));
+      part = dynamic_cast<TParticle*>(fParticleMap.At(i));
       parent = part->GetFirstMother();
       if(parent>=0) {
-         father = dynamic_cast<TParticle*>(particles.At(parent));
+         father = dynamic_cast<TParticle*>(fParticleMap.At(parent));
          if(father->TestBit(kDaughtersBit)) {
              
              if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
@@ -364,31 +363,32 @@ void AliStack::PurifyKine()
   // Now the output bit, from fHgwmk to nkeep we write everything and we erase
   if(nkeep > fParticleFileMap.GetSize()) fParticleFileMap.Set(Int_t (nkeep*1.5));
   for (i=fHgwmk+1; i<nkeep; ++i) {
-      fParticleBuffer = dynamic_cast<TParticle*>(particles.At(i));
+      fParticleBuffer = dynamic_cast<TParticle*>(fParticleMap.At(i));
       fParticleFileMap[i]=static_cast<Int_t>(TreeK()->GetEntries());
       TreeK()->Fill();
-      particles[i]=fParticleBuffer=0;
+      fParticleMap[i]=fParticleBuffer=0;
   }
   
-  for (i=nkeep; i<fNtrack; ++i) particles[i]=0;
+  for (i = nkeep; i < fNtrack; ++i) fParticleMap[i]=0;
   
   Int_t toshrink = fNtrack-fHgwmk-1;
   fLoadPoint-=toshrink;
   
-  
-  for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles->RemoveAt(i);
+  for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles.RemoveAt(i);
   fNtrack=nkeep;
   fHgwmk=nkeep-1;
+  return kTRUE;
 }
 
-void AliStack::ReorderKine()
+
+Bool_t AliStack::ReorderKine()
 {
 //
 // In some transport code children might not come in a continuous sequence.
 // In this case the stack  has  to  be reordered in order to establish the 
 // mother daughter relation using index ranges.
 //    
-  if(fHgwmk+1 == fNtrack) return;
+  if(fHgwmk+1 == fNtrack) return kFALSE;
 
   //
   // Howmany secondaries have been produced ?
@@ -396,15 +396,14 @@ void AliStack::ReorderKine()
     
   if (nNew > 0) {
       Int_t i, j;
-      TObjArray &particles = *fParticleMap;
       TArrayI map1(nNew);
       //
       // Copy pointers to temporary array
       TParticle** tmp = new TParticle*[nNew];
       
       for (i = 0; i < nNew; i++) {
-         if (particles.At(fHgwmk + 1 + i)) {
-             tmp[i] = (TParticle*) (particles.At(fHgwmk + 1 + i));
+         if (fParticleMap.At(fHgwmk + 1 + i)) {
+             tmp[i] = (TParticle*) (fParticleMap.At(fHgwmk + 1 + i));
          } else {
              tmp[i] = 0x0;
          }
@@ -415,7 +414,7 @@ void AliStack::ReorderKine()
       //
       // Reset  LoadPoint 
       // 
-      fLoadPoint = fHgwmk + 1;
+      Int_t loadPoint = fHgwmk + 1;
       //
       // Re-Push particles into stack 
       // The outer loop is over parents, the inner over children.
@@ -426,7 +425,7 @@ void AliStack::ReorderKine()
          TParticle* parP;
          if (i == -1) {
              ipa  = tmp[0]->GetFirstMother();
-             parP =dynamic_cast<TParticle*>(particles.At(ipa));
+             parP =dynamic_cast<TParticle*>(fParticleMap.At(ipa));
          } else {
              ipa = (fHgwmk + 1 + i);
               // Skip deleted particles
@@ -449,18 +448,18 @@ void AliStack::ReorderKine()
              Int_t jpa = tmp[j]->GetFirstMother();
               // Check if daughter of current parent
              if (jpa == ipa) {
-                 particles[fLoadPoint] = tmp[j];
+                 fParticleMap[loadPoint] = tmp[j];
                  // Re-establish daughter information
-                 parP->SetLastDaughter(fLoadPoint);
-                 if (parP->GetFirstDaughter() == -1) parP->SetFirstDaughter(fLoadPoint);
+                 parP->SetLastDaughter(loadPoint);
+                 if (parP->GetFirstDaughter() == -1) parP->SetFirstDaughter(loadPoint);
                  // Set Mother information
                  if (i != -1) {
                      tmp[j]->SetFirstMother(map1[i]);
                  } 
                  // Build the map
-                 map1[j] = fLoadPoint;
+                 map1[j] = loadPoint;
                  // Increase load point
-                 fLoadPoint++;
+                 loadPoint++;
              }
          } // children
       } // parents
@@ -479,6 +478,8 @@ void AliStack::ReorderKine()
          }
       }
   } // new particles poduced
+  
+  return kTRUE;
 }
 
 Bool_t AliStack::KeepPhysics(TParticle* part)
@@ -533,12 +534,12 @@ void AliStack::FinishEvent()
   Bool_t allFilled = kFALSE;
   TObject *part;
   for(Int_t i=0; i<fHgwmk+1; ++i) 
-    if((part=fParticleMap->At(i))) {
+    if((part=fParticleMap.At(i))) {
       fParticleBuffer = dynamic_cast<TParticle*>(part);
       fParticleFileMap[i]= static_cast<Int_t>(TreeK()->GetEntries());
       TreeK()->Fill();
       fParticleBuffer=0;      
-      fParticleMap->AddAt(0,i);      
+      fParticleMap.AddAt(0,i);      
       
       // When all primaries were filled no particle!=0
       // should be left => to be removed later.
@@ -566,7 +567,7 @@ void AliStack::FlagTrack(Int_t track)
 
   Int_t curr=track;
   while(1) {
-    particle=dynamic_cast<TParticle*>(fParticleMap->At(curr));
+    particle=dynamic_cast<TParticle*>(fParticleMap.At(curr));
     
     // If the particle is flagged the three from here upward is saved already
     if(particle->TestBit(kKeepBit)) return;
@@ -586,14 +587,14 @@ void AliStack::KeepTrack(Int_t track)
   // Flags a track to be kept
   //
   
-  fParticleMap->At(track)->SetBit(kKeepBit);
+  fParticleMap.At(track)->SetBit(kKeepBit);
 }
 
 //_____________________________________________________________________________
-void  AliStack::Reset(Int_t size) 
+void  AliStack::Clean(Int_t size) 
 {
   //
-  // Resets stack
+  // Reset stack data except for fTreeK
   //
   
   fNtrack=0;
@@ -601,26 +602,30 @@ void  AliStack::Reset(Int_t size)
   fHgwmk=0;
   fLoadPoint=0;
   fCurrent = -1;
-  fTreeK = 0x0;
   ResetArrays(size);
 }
 
+//_____________________________________________________________________________
+void  AliStack::Reset(Int_t size) 
+{
+  //
+  // Reset stack data including fTreeK
+  //
+
+  Clean(size);
+  delete fParticleBuffer; fParticleBuffer = 0;
+  fTreeK = 0x0;
+}
+
 //_____________________________________________________________________________
 void  AliStack::ResetArrays(Int_t size) 
 {
   //
   // Resets stack arrays
   //
-
-  if (fParticles) 
-    fParticles->Clear();
-  else
-    fParticles = new TClonesArray("TParticle",1000);
-  if (fParticleMap) {
-    fParticleMap->Clear();
-    if (size>0) fParticleMap->Expand(size);}
-  else
-    fParticleMap = new TObjArray(size);
+  fParticles.Clear();
+  fParticleMap.Clear();
+  if (size>0) fParticleMap.Expand(size);
 }
 
 //_____________________________________________________________________________
@@ -642,8 +647,8 @@ TParticle* AliStack::Particle(Int_t i)
   //
   // Return particle with specified ID
 
-  if(!fParticleMap->At(i)) {
-    Int_t nentries = fParticles->GetEntriesFast();
+  if(!fParticleMap.At(i)) {
+    Int_t nentries = fParticles.GetEntriesFast();
     // algorithmic way of getting entry index
     // (primary particles are filled after secondaries)
     Int_t entry = TreeKEntry(i);
@@ -658,11 +663,11 @@ TParticle* AliStack::Particle(Int_t i)
     // Load particle at entry into fParticleBuffer
     TreeK()->GetEntry(entry);
     // Add to the TClonesarray
-    new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
+    new (fParticles[nentries]) TParticle(*fParticleBuffer);
     // Store a pointer in the TObjArray
-    fParticleMap->AddAt((*fParticles)[nentries],i);
+    fParticleMap.AddAt(fParticles[nentries],i);
   }
-  return dynamic_cast<TParticle*>(fParticleMap->At(i));
+  return dynamic_cast<TParticle*>(fParticleMap.At(i));
 }
 
 //_____________________________________________________________________________
@@ -708,7 +713,7 @@ Int_t AliStack::GetCurrentParentTrackNumber() const
   // Return number of the parent of the current track
   //
   
-  TParticle* current = (TParticle*)fParticleMap->At(fCurrent);
+  TParticle* current = (TParticle*)fParticleMap.At(fCurrent);
 
   if (current) 
     return current->GetFirstMother();
@@ -741,7 +746,7 @@ void AliStack::DumpPart (Int_t i) const
   //
   // Dumps particle i in the stack
   //
-  dynamic_cast<TParticle*>(fParticleMap->At(i))->Print();
+  dynamic_cast<TParticle*>(fParticleMap.At(i))->Print();
 }
 
 //_____________________________________________________________________________
@@ -782,12 +787,11 @@ void AliStack::DumpLoadedStack() const
   // that are loaded in memory.
   //
 
-  TObjArray &particles = *fParticleMap;
   printf(
         "\n\n=======================================================================\n");
   for (Int_t i=0;i<fNtrack;i++) 
     {
-      TParticle* particle = dynamic_cast<TParticle*>(particles[i]);
+      TParticle* particle = dynamic_cast<TParticle*>(fParticleMap[i]);
       if (particle) {
         printf("-> %d ",i); particle->Print();
         printf("--------------------------------------------------------------\n");
@@ -813,11 +817,10 @@ void AliStack::CleanParents()
   // Set parent/daughter relations
   //
   
-  TObjArray &particles = *fParticleMap;
   TParticle *part;
   int i;
   for(i=0; i<fHgwmk+1; i++) {
-    part = dynamic_cast<TParticle*>(particles.At(i));
+    part = dynamic_cast<TParticle*>(fParticleMap.At(i));
     if(part) if(!part->TestBit(kDaughtersBit)) {
       part->SetFirstDaughter(-1);
       part->SetLastDaughter(-1);
@@ -837,7 +840,7 @@ TParticle* AliStack::GetNextParticle()
   // search secondaries
   //for(Int_t i=fNtrack-1; i>=0; i--) {
   for(Int_t i=fNtrack-1; i>fHgwmk; i--) {
-      particle = dynamic_cast<TParticle*>(fParticleMap->At(i));
+      particle = dynamic_cast<TParticle*>(fParticleMap.At(i));
       if ((particle) && (!particle->TestBit(kDoneBit))) {
          fCurrent=i;    
          return particle;
@@ -847,7 +850,7 @@ TParticle* AliStack::GetNextParticle()
   // take next primary if all secondaries were done
   while (fCurrentPrimary>=0) {
       fCurrent = fCurrentPrimary;    
-      particle = dynamic_cast<TParticle*>(fParticleMap->At(fCurrentPrimary--));
+      particle = dynamic_cast<TParticle*>(fParticleMap.At(fCurrentPrimary--));
       if ((particle) && (!particle->TestBit(kDoneBit))) {
          return particle;
       } 
@@ -873,7 +876,7 @@ void AliStack::ConnectTree(TTree* tree)
 //
 //  Creates branch for writing particles
 //
-    
+
   fTreeK = tree;
     
   AliDebug(1, "Connecting TreeK");
@@ -918,20 +921,7 @@ void AliStack::ConnectTree(TTree* tree)
   else
     AliWarning("Branch Dir is NOT SET");
 }
-//__________________________________________________________________________________________
 
-
-void AliStack::BeginEvent()
-{
-// start a new event
- Reset();
-}
-
-//_____________________________________________________________________________
-void AliStack::FinishRun()
-{
-// Clean TreeK information
-}
 //_____________________________________________________________________________
 
 Bool_t AliStack::GetEvent()
@@ -948,39 +938,45 @@ Bool_t AliStack::GetEvent()
 
 Bool_t AliStack::IsStable(Int_t pdg) const
 {
-//
-// Decide whether particle (pdg) is stable
-//
+  //
+  // Decide whether particle (pdg) is stable
+  //
+  
+  
+  // All ions/nucleons are considered as stable
+  // Nuclear code is 10LZZZAAAI
+  if(pdg>1000000000)return kTRUE;
 
-    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
-    };
+  const Int_t kNstable = 15;
+  Int_t i;
+  
+  Int_t pdgStable[kNstable] = {
+    kGamma,             // Photon
+    kElectron,          // Electron
+    kMuonPlus,          // Muon 
+    kPiPlus,            // Pion
+    kKPlus,             // Kaon
+    kK0Short,           // K0s
+    kK0Long,            // K0l
+    kProton,            // Proton 
+    kNeutron,           // Neutron
+    kLambda0,           // Lambda_0
+    kSigmaMinus,        // Sigma Minus
+    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;
-       }
+  Bool_t isStable = kFALSE;
+  for (i = 0; i < kNstable; i++) {
+    if (pdg == TMath::Abs(pdgStable[i])) {
+      isStable = kTRUE;
+      break;
     }
-
-    return isStable;
+  }
+  
+  return isStable;
 }
 
 Bool_t AliStack::IsPhysicalPrimary(Int_t index)
@@ -996,7 +992,7 @@ Bool_t AliStack::IsPhysicalPrimary(Int_t index)
     
     //
     // Initial state particle
-    if (ist > 20) return kFALSE;
+    if (ist > 1) return kFALSE;
     
     Int_t pdg = TMath::Abs(p->GetPdgCode());
     
@@ -1010,10 +1006,16 @@ Bool_t AliStack::IsPhysicalPrimary(Int_t index)
 //
 // 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());
+// Check if it comes from a pi0 decay
+//
+// What about the pi0 Dalitz ??
+//     if ((mpdg == kPi0) && (imo < GetNprimary())) return kTRUE; 
+
+// Check if this is a heavy flavor decay product
        Int_t mfl  = Int_t (mpdg / TMath::Power(10, Int_t(TMath::Log10(mpdg))));
        //
        // Light hadron
@@ -1028,7 +1030,7 @@ Bool_t AliStack::IsPhysicalPrimary(Int_t index)
        // 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();
+           imo = pm->GetFirstMother();
            pm  =  Particle(imo);
        }
        mpdg = TMath::Abs(pm->GetPdgCode());
@@ -1041,4 +1043,3 @@ Bool_t AliStack::IsPhysicalPrimary(Int_t index)
        } 
     } // produced by generator ?
 } 
-