]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliStack.cxx
Remove fTree from destructor
[u/mrichter/AliRoot.git] / STEER / AliStack.cxx
index ad1fb8432bd9c64129c1733b81b74376e1df5ceb..0d008605d40ff62104437fe83b1322446df3b639 100644 (file)
 
 /*
 $Log$
+Revision 1.16  2001/11/20 09:27:55  hristov
+Possibility to investigate a primary of not yet loaded particle (I.Hrivnacova)
+
+Revision 1.15  2001/09/04 15:10:37  hristov
+Additional protection is included to avoid some problems using Hijing
+
+Revision 1.14  2001/08/30 09:44:06  hristov
+VertexSource_t added to avoid the warnings
+
+Revision 1.13  2001/08/29 13:31:42  morsch
+Protection against (fTreeK == 0) in destructor.
+
+Revision 1.12  2001/07/27 13:03:13  hristov
+Default Branch split level set to 99
+
+Revision 1.11  2001/07/27 12:34:20  jchudoba
+remove the dummy argument in GetEvent method
+
+Revision 1.10  2001/07/20 10:13:54  morsch
+In Particle(Int_t) use GetEntriesFast to speed up the procedure.
+
+Revision 1.9  2001/07/03 08:10:57  hristov
+J.Chudoba's changes merged correctly with the HEAD
+
+Revision 1.6  2001/05/31 06:59:06  fca
+Clean setting and deleting of fParticleBuffer
+
+Revision 1.5  2001/05/30 12:18:46  hristov
+Loop variables declared once
+
+Revision 1.4  2001/05/25 07:25:20  hristov
+AliStack destructor corrected (I.Hrivnacova)
+
 Revision 1.3  2001/05/22 14:33:16  hristov
 Minor changes
 
@@ -59,12 +92,12 @@ AliStack::AliStack(Int_t size)
   // Create the particles arrays 
   fParticles      = new TClonesArray("TParticle",1000);
   fParticleMap    = new TObjArray(size);
-  fParticleBuffer = new TParticle();
-  fNtrack         =  0;
-  fNprimary       0;
+  fParticleBuffer = 0;
+  fNtrack         = 0;
+  fNprimary       = 0;
   fCurrent        = -1;
   fCurrentPrimary = -1;
-  fTreeK          =  0;
+  fTreeK          = 0;
 }
 
 
@@ -76,14 +109,14 @@ AliStack::AliStack()
   //
   
   // Create the particles arrays 
-  fParticles      = new TClonesArray("TParticle",1000);
-  fParticleMap    = new TObjArray(10000);
-  fParticleBuffer = new TParticle();
-  fNtrack         =  0;
+  fParticles      = 0;
+  fParticleMap    = 0;
+  fParticleBuffer = 0;
+  fNtrack         = 0;
   fCurrent        = -1;
-  fNprimary       0;
+  fNprimary       = 0;
   fCurrentPrimary = -1;
-  fTreeK          =  0;
+  fTreeK          = 0;
 }
 
 
@@ -100,7 +133,7 @@ AliStack::~AliStack()
     delete fParticles;
   }
   delete fParticleMap;
-  delete fTreeK;
+  if (fTreeK) delete fTreeK;
 }
 
 //
@@ -144,9 +177,9 @@ void AliStack::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
   Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
                        pmom[1]*pmom[1]+pmom[2]*pmom[2]);
   
-//  printf("Loading  mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n",
-//  mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS);
-
+//    printf("Loading  mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n",
+//        mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS);
+  
   TClonesArray &particles = *fParticles;
   TParticle* particle
    = new(particles[fLoadPoint++]) 
@@ -165,8 +198,13 @@ void AliStack::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
 
   if(parent>=0) {
     particle = (TParticle*) fParticleMap->At(parent);
-    particle->SetLastDaughter(fNtrack);
-    if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
+    if (particle) {
+      particle->SetLastDaughter(fNtrack);
+      if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
+    }
+    else {
+      printf("Error in AliStack::SetTrack: Parent %d does not exist\n",parent);
+    }
   } 
   else { 
     //
@@ -232,8 +270,13 @@ void AliStack::SetTrack(Int_t done, Int_t parent, Int_t pdg,
 
   if(parent>=0) {
     particle = (TParticle*) fParticleMap->At(parent);
-    particle->SetLastDaughter(fNtrack);
-    if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
+    if (particle) {
+      particle->SetLastDaughter(fNtrack);
+      if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
+    }
+    else {
+      printf("Error in AliStack::SetTrack: Parent %d does not exist\n",parent);
+    }
   } 
   else { 
     //
@@ -258,7 +301,7 @@ void AliStack::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
   
 
   TParticle* track = GetNextParticle();
-//  cout << "GetNextTrack():" << fCurrent << fNprimary << endl;
+//    cout << "GetNextTrack():" << fCurrent << fNprimary << endl;
 
   if(track) {
     mtrack=fCurrent;
@@ -277,7 +320,7 @@ void AliStack::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
     polar[2]=pol.Z();
     tof=track->T();
     track->SetBit(kDoneBit);
-    //cout << "Filled params" << endl;
+//      cout << "Filled params" << endl;
   }
   else 
     mtrack=-1;
@@ -401,7 +444,7 @@ void AliStack::PurifyKine()
      fParticleBuffer = (TParticle*) particles.At(i);
      fParticleFileMap[i]=(Int_t) fTreeK->GetEntries();
      fTreeK->Fill();
-     particles[i]=0;
+     particles[i]=fParticleBuffer=0;
    }
 
    for (i=nkeep; i<fNtrack; ++i) particles[i]=0;
@@ -445,7 +488,9 @@ void AliStack::FinishEvent()
       fParticleBuffer = (TParticle*) part;
       fParticleFileMap[i]= (Int_t) fTreeK->GetEntries();
       fTreeK->Fill();
-      (*fParticleMap)[i]=0;      
+      //PH      (*fParticleMap)[i]=fParticleBuffer=0;      
+      fParticleBuffer=0;      
+      fParticleMap->AddAt(0,i);      
       
       // When all primaries were filled no particle!=0
       // should be left => to be removed later.
@@ -459,7 +504,7 @@ void AliStack::FinishEvent()
         // To be removed later and replaced with break.
       if(!allFilled) allFilled = kTRUE;
     } 
-  //cout << "Nof particles: " << fNtrack << endl;
+//    cout << "Nof particles: " << fNtrack << endl;
   //Reset();   
 } 
 
@@ -519,9 +564,15 @@ void  AliStack::ResetArrays(Int_t size)
   // Resets stack arrays
   //
 
-  fParticles->Clear();
-  fParticleMap->Clear();
-  if (size>0) fParticleMap->Expand(size);  
+  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);
 }
 
 //_____________________________________________________________________________
@@ -545,8 +596,9 @@ TParticle* AliStack::Particle(Int_t i)
   //
   // Return particle with specified ID
   
-  if(!(*fParticleMap)[i]) {
-    Int_t nentries = fParticles->GetEntries();
+  //PH  if(!(*fParticleMap)[i]) {
+  if(!fParticleMap->At(i)) {
+    Int_t nentries = fParticles->GetEntriesFast();
     // algorithmic way of getting entry index
     // (primary particles are filled after secondaries)
     Int_t entry;
@@ -567,24 +619,23 @@ TParticle* AliStack::Particle(Int_t i)
     new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
     fParticleMap->AddAt((*fParticles)[nentries],i);
   }
-  return (TParticle *) (*fParticleMap)[i];
+  //PH  return (TParticle *) (*fParticleMap)[i];
+  return (TParticle *) fParticleMap->At(i);
 }
 
 //_____________________________________________________________________________
-Int_t AliStack::GetPrimary(Int_t id) const
+Int_t AliStack::GetPrimary(Int_t id)
 {
   //
   // Return number of primary that has generated track
   //
   
   int current, parent;
-  TParticle *part;
   //
   parent=id;
   while (1) {
     current=parent;
-    part = (TParticle *)fParticleMap->At(current);
-    parent=part->GetFirstMother();
+    parent=Particle(current)->GetFirstMother();
     if(parent<0) return current;
   }
 }
@@ -596,7 +647,8 @@ void AliStack::DumpPart (Int_t i) const
   // Dumps particle i in the stack
   //
   
-  ((TParticle*) (*fParticleMap)[i])->Print();
+  //PH  ((TParticle*) (*fParticleMap)[i])->Print();
+  ((TParticle*) fParticleMap->At(i))->Print();
 }
 
 //_____________________________________________________________________________
@@ -606,9 +658,11 @@ void AliStack::DumpPStack ()
   // Dumps the particle stack
   //
 
+  Int_t i;
+
   printf(
         "\n\n=======================================================================\n");
-  for (Int_t i=0;i<fNtrack;i++) 
+  for (i=0;i<fNtrack;i++) 
     {
       TParticle* particle = Particle(i);
       if (particle) {
@@ -624,7 +678,7 @@ void AliStack::DumpPStack ()
   
   // print  particle file map
   printf("\nParticle file map: \n");
-  for (Int_t i=0; i<fNtrack; i++) 
+  for (i=0; i<fNtrack; i++) 
       printf("   %d th entry: %d \n",i,fParticleFileMap[i]);
 }
 
@@ -728,12 +782,12 @@ void AliStack::MakeTree(Int_t event, const char *file)
   TBranch *branch=0;
   // Make Kinematics Tree
   char hname[30];
-  //    printf("\n MakeTree called %d", event);
+//    printf("\n MakeTree called %d", event);
   if (!fTreeK) {
     sprintf(hname,"TreeK%d",event);
     fTreeK = new TTree(hname,"Kinematics");
     //  Create a branch for particles
-    branch = fTreeK->Branch("Particles", "TParticle", &fParticleBuffer, 4000, 1);          
+    branch = fTreeK->Branch("Particles", "TParticle", &fParticleBuffer, 4000);          
     fTreeK->Write(0,TObject::kOverwrite);
   }
 }
@@ -765,10 +819,11 @@ void AliStack::FinishRun()
 }
 
 //_____________________________________________________________________________
-void AliStack::GetEvent(Int_t event)
+Bool_t AliStack::GetEvent(Int_t event)
 {
 //
 // Get new event from TreeK
+
     // Reset/Create the particle stack
     if (fTreeK) delete fTreeK;
     
@@ -777,14 +832,18 @@ void AliStack::GetEvent(Int_t event)
     sprintf(treeName,"TreeK%d",event);
     fTreeK = (TTree*)gDirectory->Get(treeName);
 
-    if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticleBuffer);
-
-  else    
+    if (fTreeK) 
+      fTreeK->SetBranchAddress("Particles", &fParticleBuffer);
+    else {
       Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
-//
-//    printf("\n primaries %d", fNprimary);
-//    printf("\n tracks    %d", fNtrack);    
-//
+      return kFALSE;
+    }
+//      printf("\n primaries %d", fNprimary);
+//      printf("\n tracks    %d", fNtrack);    
+      
     Int_t size = (Int_t)fTreeK->GetEntries();
     ResetArrays(size);
+    return kTRUE;
 }
+
+//----------------------------------------------------------------------