]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AliGeant4/AliPrimaryGeneratorAction.cxx
moving TG4G3Cut/Control, TG4G3Cut/ControlVector from physics commented
[u/mrichter/AliRoot.git] / AliGeant4 / AliPrimaryGeneratorAction.cxx
index 74340f285bf26b871fd60ea9d7d94aab379ca83b..ddf838b53c943694cc8145d3eab0a0b942e388ad 100644 (file)
@@ -12,7 +12,7 @@
 #include "AliRun.h"
 #include "AliGenerator.h"
 
-#include "TG3Units.h"
+#include "TG4G3Units.h"
 
 #include <G4Event.hh>
 #include <G4ParticleTable.hh>
 #include <Randomize.hh>
 
 #include <TParticle.h>
-#include <TClonesArray.h>
 
 AliPrimaryGeneratorAction::AliPrimaryGeneratorAction()
   : fGenerator(kAliGenerator),
     fNofGunParticles(1),
-    fVerboseLevel(0),
-    fParticleArray(0)
+    fVerboseLevel(0)
 {
 //
   fParticleGun = new AliParticleGun();
@@ -68,7 +66,6 @@ void AliPrimaryGeneratorAction::ConstructGenerator()
 // Constructs selected generator.
 // ---
 
-  fParticleArray = 0;
   switch (fGenerator) { 
     case kGun:
       // gun is constructed interactively      
@@ -147,9 +144,8 @@ void AliPrimaryGeneratorAction::ConstructAliGenerator()
     text = text + "   No AliGenerator is defined in gAlice.";
     AliGlobals::Exception(text);
   }  
-  // fill AliRun::fParticles array 
+  // fill AliRun::fParticleMap array 
   generator->Generate();
-  fParticleArray = gAlice->Particles();
 }
 
 void AliPrimaryGeneratorAction::GenerateAliGeneratorPrimaries(G4Event* event)
@@ -167,81 +163,76 @@ void AliPrimaryGeneratorAction::GenerateAliGeneratorPrimaries(G4Event* event)
   //G4cout << " nofParticles: " <<  nofParticles << G4endl;
   for( G4int i=0; i<nofParticles; i++ ) {    
   
-    // get particle from TClonesArray
-    TObject* particleTObject
-      = fParticleArray->UncheckedAt(i);      
-    TParticle* particle
-      = dynamic_cast<TParticle*>(particleTObject);
-
-    // check particle type
-    if (!particle) {
-      G4String text =
-        "AliPrimaryGeneratorAction::GenerateAliGeneratorPrimaries\n";
-      text = text + "Unknown particle type";           
-      AliGlobals::Exception(text);
-    }  
-     
-    // get particle definition from G4ParticleTable
-    G4int pdgEncoding = particle->GetPdgCode();
-    G4ParticleTable* particleTable 
-      = G4ParticleTable::GetParticleTable();                
-    G4ParticleDefinition* particleDefinition = 0;    
-    if (pdgEncoding != 0) 
-      particleDefinition = particleTable->FindParticle(pdgEncoding);
-    else {
-      G4String name = particle->GetName();
-      if (name == "Rootino")   
-        particleDefinition = particleTable->FindParticle("geantino");
-    }  
+    // get the particle from AliRun stack
+    TParticle* particle = gAlice->Particle(i);
+
+    
+    if (!particle->TestBit(kDoneBit)) {
+      // only particles that didn't die (decay) in primary generator
+      // will be transformed to G4 objects   
+
+      // get particle definition from G4ParticleTable
+      G4int pdgEncoding = particle->GetPdgCode();
+      G4ParticleTable* particleTable 
+        = G4ParticleTable::GetParticleTable();                        
+      G4ParticleDefinition* particleDefinition = 0;      
+      if (pdgEncoding != 0) 
+        particleDefinition = particleTable->FindParticle(pdgEncoding);
+      else {
+        G4String name = particle->GetName();
+        if (name == "Rootino") 
+            particleDefinition = particleTable->FindParticle("geantino");
+      }        
   
-    if (particleDefinition==0) {
-      G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
-      G4String text = 
-        "AliPrimaryGeneratorAction::GenerateAliGeneratorPrimaries:\n";
-      text = text + "   G4ParticleTable::FindParticle() failed.";
-      AliGlobals::Exception(text);
-    }  
-
-    // get/create vertex
-    G4ThreeVector position 
-      = G4ThreeVector(particle->Vx()*TG3Units::Length(),
-                      particle->Vy()*TG3Units::Length(),
-                     particle->Vz()*TG3Units::Length());
-    G4double time = particle->T()*TG3Units::Time(); 
-    G4PrimaryVertex* vertex;
-    if ( i==0 || position != previousPosition || time != previousTime ) {   
-      // create a new vertex 
-      // in case position and time of gun particle are different from 
-      // previous values
-      // (vertex objects are destroyed in G4EventManager::ProcessOneEvent()
-      // when event is deleted)  
-      vertex = new G4PrimaryVertex(position, time);
-      event->AddPrimaryVertex(vertex);
-
-      previousVertex = vertex;
-      previousPosition = position;
-      previousTime = time;
-    }
-    else 
-      vertex = previousVertex;
-
-    // create a primary particle and add it to the vertex
-    // (primaryParticle objects are destroyed in G4EventManager::ProcessOneEvent()
-    // when event and then vertex is deleted)
-    G4double px = particle->Px()*TG3Units::Energy();
-    G4double py = particle->Py()*TG3Units::Energy();
-    G4double pz = particle->Pz()*TG3Units::Energy();
-    G4PrimaryParticle* primaryParticle 
-      = new G4PrimaryParticle(particleDefinition, px, py, pz);
-      
-    // set polarization
-    TVector3 polarization;
-    particle->GetPolarisation(polarization);
-    primaryParticle
-      ->SetPolarization(polarization.X(), polarization.Y(), polarization.Z());    
+      if (particleDefinition==0) {
+        G4cout << "pdgEncoding: " << pdgEncoding << G4endl;
+        G4String text = 
+            "AliPrimaryGeneratorAction::GenerateAliGeneratorPrimaries:\n";
+        text = text + "   G4ParticleTable::FindParticle() failed.";
+        AliGlobals::Exception(text);
+      }        
+
+      // get/create vertex
+      G4ThreeVector position 
+        = G4ThreeVector(particle->Vx()*TG4G3Units::Length(),
+                        particle->Vy()*TG4G3Units::Length(),
+                       particle->Vz()*TG4G3Units::Length());
+      G4double time = particle->T()*TG4G3Units::Time(); 
+      G4PrimaryVertex* vertex;
+      if ( i==0 || position != previousPosition || time != previousTime ) {   
+        // create a new vertex 
+        // in case position and time of gun particle are different from 
+        // previous values
+        // (vertex objects are destroyed in G4EventManager::ProcessOneEvent()
+        // when event is deleted)  
+        vertex = new G4PrimaryVertex(position, time);
+        event->AddPrimaryVertex(vertex);
+
+        previousVertex = vertex;
+        previousPosition = position;
+        previousTime = time;
+      }
+      else 
+        vertex = previousVertex;
+
+      // create a primary particle and add it to the vertex
+      // (primaryParticle objects are destroyed in G4EventManager::ProcessOneEvent()
+      // when event and then vertex is deleted)
+      G4double px = particle->Px()*TG4G3Units::Energy();
+      G4double py = particle->Py()*TG4G3Units::Energy();
+      G4double pz = particle->Pz()*TG4G3Units::Energy();
+      G4PrimaryParticle* primaryParticle 
+        = new G4PrimaryParticle(particleDefinition, px, py, pz);
+        
+      // set polarization
+      TVector3 polarization;
+      particle->GetPolarisation(polarization);
+      primaryParticle
+        ->SetPolarization(polarization.X(), polarization.Y(), polarization.Z());    
     
-    // add primary particle to the vertex
-    vertex->SetPrimary(primaryParticle);
+      // add primary particle to the vertex
+      vertex->SetPrimary(primaryParticle);
+    }   
   }
 }
 
@@ -259,7 +250,7 @@ void AliPrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
   ConstructGenerator();
   
   // generate primary vertices
-  if (fParticleArray)  {
+  if (fGenerator == kAliGenerator)  {
     // use AliGenerator if set
     GenerateAliGeneratorPrimaries(event);