#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();
// Constructs selected generator.
// ---
- fParticleArray = 0;
switch (fGenerator) {
case kGun:
// gun is constructed interactively
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)
//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);
+ }
}
}
ConstructGenerator();
// generate primary vertices
- if (fParticleArray) {
+ if (fGenerator == kAliGenerator) {
// use AliGenerator if set
GenerateAliGeneratorPrimaries(event);