4 // Author: I. Hrivnacova
6 // Class AliPrimaryGeneratorAction
7 // -------------------------------
8 // See the class description in the header file.
10 #include "AliPrimaryGeneratorAction.h"
11 #include "AliPrimaryGeneratorMessenger.h"
12 #include "AliParticleGun.h"
13 #include "AliGunParticle.h"
14 #include "AliGlobals.h"
16 #include "TG4G3Units.h"
17 #include "TG4PrimaryGeneratorAction.h"
18 #include "TG4TrackingAction.h"
21 #include <G4ParticleTable.hh>
22 #include <G4ParticleDefinition.hh>
24 #include <Randomize.hh>
26 #include <TParticle.h>
27 #include <TVirtualMCApplication.h>
29 //_____________________________________________________________________________
30 AliPrimaryGeneratorAction::AliPrimaryGeneratorAction()
31 : AliVerbose("primaryGeneratorAction"),
39 //_____________________________________________________________________________
40 AliPrimaryGeneratorAction::~AliPrimaryGeneratorAction() {
46 //_____________________________________________________________________________
47 void AliPrimaryGeneratorAction::ConstructGenerator()
49 // Constructs selected generator.
54 // gun is constructed interactively
57 ConstructGeantinoGenerator(false);
59 case kChargedGeantino:
60 ConstructGeantinoGenerator(true);
67 //_____________________________________________________________________________
68 void AliPrimaryGeneratorAction::ConstructGeantinoGenerator(G4bool isCharged)
70 // Geantino with random momentum direction
71 // (the default generator).
77 G4ParticleTable* particleTable
78 = G4ParticleTable::GetParticleTable();
80 for (G4int i=0; i< fNofGunParticles; i++)
82 G4ParticleDefinition* particleDef = 0;
84 particleDef = particleTable->FindParticle("geantino");
86 particleDef = particleTable->FindParticle("chargedgeantino");
89 G4String text = "AliPrimaryGeneratorAction::GenerateGeantino:\n";
90 text = text + " G4ParticleTable::FindParticle() failed.";
91 AliGlobals::Exception(text);
95 RandFlat::shootArray(3,rn);
99 G4ThreeVector momentumDir(px, py, pz);
101 G4double energy = 1.*GeV;
102 G4ThreeVector position(0.,0.,0.);
104 G4ThreeVector polarization(0.,0.,0.);
106 AliGunParticle * gunParticle
107 = new AliGunParticle(particleDef, momentumDir, energy, position, time,
110 fParticleGun.AddParticle(gunParticle);
112 if (VerboseLevel() > 1) {
113 G4cout << "Geantino generator has been built." << G4endl;
119 //_____________________________________________________________________________
120 void AliPrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
122 // Generates primary particles by the selected generator.
125 if (fGenerator == kStack) {
128 TG4PrimaryGeneratorAction action;
129 action.GeneratePrimaries(event);
131 // Do not save primary particles
132 // (they would be stored twice)
133 TG4TrackingAction* trackingAction
134 = TG4TrackingAction::Instance();
135 if (trackingAction) trackingAction->SetSavePrimaries(false);
140 TVirtualMCApplication::Instance()->BeginEvent();
142 // Construct particle gun
143 ConstructGenerator();
145 // Generate primary vertices
146 fParticleGun.GeneratePrimaryVertex(event);
148 // Primary particles have to be saved in stack
149 TG4TrackingAction* trackingAction
150 = TG4TrackingAction::Instance();
151 if (trackingAction) trackingAction->SetSavePrimaries(true);
155 //_____________________________________________________________________________
156 void AliPrimaryGeneratorAction::SetGenerator(AliPrimaryGenerator generator)
161 fGenerator = generator;
164 //_____________________________________________________________________________
165 void AliPrimaryGeneratorAction::SetNofGunParticles(G4int nofParticles)
167 // Sets number of primary particles.
168 // This method is applied only to "gun" type generators
169 // (and not to AliGenerator from AliRoot).
172 fNofGunParticles = nofParticles;