]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliPrimaryGeneratorAction.cxx
Removing old classes from LinkDef
[u/mrichter/AliRoot.git] / AliGeant4 / AliPrimaryGeneratorAction.cxx
1 // $Id$
2 // Category: run
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliPrimaryGeneratorAction
7 // -------------------------------
8 // See the class description in the header file.
9
10 #include "AliPrimaryGeneratorAction.h"
11 #include "AliPrimaryGeneratorMessenger.h"
12 #include "AliParticleGun.h"
13 #include "AliGunParticle.h"
14 #include "AliGlobals.h"
15
16 #include "TG4G3Units.h"
17 #include "TG4PrimaryGeneratorAction.h"
18 #include "TG4TrackingAction.h"
19
20 #include <G4Event.hh>
21 #include <G4ParticleTable.hh>
22 #include <G4ParticleDefinition.hh>
23
24 #include <Randomize.hh>
25
26 #include <TParticle.h>
27 #include <TVirtualMCApplication.h>
28
29 //_____________________________________________________________________________
30 AliPrimaryGeneratorAction::AliPrimaryGeneratorAction()
31   : AliVerbose("primaryGeneratorAction"),
32     fGenerator(kStack),
33     fNofGunParticles(1),
34     fParticleGun(),
35     fMessenger(this) {
36 //
37 }
38
39 //_____________________________________________________________________________
40 AliPrimaryGeneratorAction::~AliPrimaryGeneratorAction() {
41 //
42 }
43
44 // private methods
45
46 //_____________________________________________________________________________
47 void AliPrimaryGeneratorAction::ConstructGenerator()
48 {
49 // Constructs selected generator.
50 // ---
51
52   switch (fGenerator) { 
53     case kGun:
54       // gun is constructed interactively      
55       return;
56     case kGeantino: 
57       ConstructGeantinoGenerator(false);
58       return;
59     case kChargedGeantino:  
60       ConstructGeantinoGenerator(true);
61       return;
62     case kStack:
63       return;
64   }
65 }   
66       
67 //_____________________________________________________________________________
68 void AliPrimaryGeneratorAction::ConstructGeantinoGenerator(G4bool isCharged)
69 {
70 // Geantino with random momentum direction
71 // (the default generator).
72 // ---
73
74   // reset gun
75   fParticleGun.Reset();     
76
77   G4ParticleTable* particleTable 
78     = G4ParticleTable::GetParticleTable();
79
80   for (G4int i=0; i< fNofGunParticles; i++)
81   {
82     G4ParticleDefinition* particleDef = 0; 
83     if (!isCharged)
84       particleDef = particleTable->FindParticle("geantino");
85     else  
86       particleDef = particleTable->FindParticle("chargedgeantino");
87
88     if (!particleDef) {
89       G4String text = "AliPrimaryGeneratorAction::GenerateGeantino:\n";
90       text = text + "   G4ParticleTable::FindParticle() failed.";
91       AliGlobals::Exception(text);
92     }  
93       
94     G4double rn[3];
95     RandFlat::shootArray(3,rn);
96     G4double px=rn[0];
97     G4double py=rn[1];
98     G4double pz=rn[2];
99     G4ThreeVector momentumDir(px, py, pz);
100
101     G4double energy = 1.*GeV;
102     G4ThreeVector position(0.,0.,0.);
103     G4double time = 0.;
104     G4ThreeVector polarization(0.,0.,0.);
105     
106     AliGunParticle * gunParticle
107       = new AliGunParticle(particleDef, momentumDir, energy, position, time, 
108               polarization);
109
110     fParticleGun.AddParticle(gunParticle);     
111   } 
112   if (VerboseLevel() > 1) { 
113     G4cout << "Geantino generator has been built." << G4endl; 
114   }
115
116             
117 // public methods
118
119 //_____________________________________________________________________________
120 void AliPrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
121 {
122 // Generates primary particles by the selected generator.
123 // ---
124
125   if (fGenerator == kStack)  {
126
127     // Use MC stack
128     TG4PrimaryGeneratorAction action;
129     action.GeneratePrimaries(event);
130
131     // Do not save primary particles
132     // (they would be stored twice)
133     TG4TrackingAction* trackingAction
134       =  TG4TrackingAction::Instance();
135     if (trackingAction) trackingAction->SetSavePrimaries(false);
136   }  
137   else {
138   
139     // Begin of Event
140     TVirtualMCApplication::Instance()->BeginEvent();
141
142     // Construct particle gun
143     ConstructGenerator();
144   
145     // Generate primary vertices
146     fParticleGun.GeneratePrimaryVertex(event);
147
148     // Primary particles have to be saved in stack
149     TG4TrackingAction* trackingAction
150       =  TG4TrackingAction::Instance();
151     if (trackingAction) trackingAction->SetSavePrimaries(true);
152   }  
153 }
154
155 //_____________________________________________________________________________
156 void AliPrimaryGeneratorAction::SetGenerator(AliPrimaryGenerator generator)
157
158 // Sets generator.
159 // ---
160
161   fGenerator = generator; 
162 }
163
164 //_____________________________________________________________________________
165 void AliPrimaryGeneratorAction::SetNofGunParticles(G4int nofParticles)
166
167 // Sets number of primary particles.
168 // This method is applied only to "gun" type generators
169 // (and not to AliGenerator from AliRoot).
170 // ---
171
172   fNofGunParticles = nofParticles;
173 }