Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
CCalPrimaryGeneratorAction Class Reference

#include <CCalPrimaryGeneratorAction.hh>

Inheritance diagram for CCalPrimaryGeneratorAction:
G4VUserPrimaryGeneratorAction

Public Member Functions

 CCalPrimaryGeneratorAction ()
 
 ~CCalPrimaryGeneratorAction ()
 
void GeneratePrimaries (G4Event *anEvent)
 
void SetVerboseLevel (G4int val)
 
void SetRandom (G4String val)
 
void SetScan (G4String val)
 
void SetMinimumEnergy (G4double p)
 
void SetMaximumEnergy (G4double p)
 
void SetMinimumPhi (G4double p)
 
void SetMaximumPhi (G4double p)
 
void SetStepsPhi (G4int val)
 
void SetMinimumEta (G4double p)
 
void SetMaximumEta (G4double p)
 
void SetStepsEta (G4int val)
 
void SetGunPosition (const G4ThreeVector &pos) const
 
void SetRunNo (G4int val)
 
G4ThreeVector GetParticlePosition ()
 
G4double GetParticleEnergy ()
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Definition at line 66 of file CCalPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

CCalPrimaryGeneratorAction::CCalPrimaryGeneratorAction ( )

Definition at line 48 of file CCalPrimaryGeneratorAction.cc.

References python.hepunit::degree, G4ParticleTable::FindParticle(), G4ParticleTable::GetParticleTable(), python.hepunit::GeV, SetMaximumEnergy(), SetMaximumEta(), SetMaximumPhi(), SetMinimumEnergy(), SetMinimumEta(), SetMinimumPhi(), G4ParticleGun::SetParticleDefinition(), G4ParticleGun::SetParticleEnergy(), G4ParticleGun::SetParticleMomentumDirection(), G4VPrimaryGenerator::SetParticlePosition(), SetStepsEta(), SetStepsPhi(), and python.hepunit::TeV.

48  : particleGun(0),
49  generatorInput(singleFixed), verboseLevel(0), n_particle(1),
50  particleName("pi-"), particleEnergy(100*GeV), particlePosition(0.,0.,0.),
51  particleDir(1.,1.,0.1), isInitialized(0), scanSteps(0) {
52 
53  //Initialise the messenger
54  gunMessenger = new CCalPrimaryGeneratorMessenger(this);
55 
56  //Default settings:
59  SetMinimumEta(0.);
60  SetMaximumEta(3.5);
62  SetMaximumPhi(360.*degree);
63  SetStepsPhi(1);
64  SetStepsEta(1);
65 
66  // Number of particles per gun
67  particleGun = new G4ParticleGun(n_particle);
68 
69  // Getting particle definition
71  G4ParticleDefinition* particle = particleTable->FindParticle(particleName);
72  particleGun->SetParticleDefinition(particle);
73 
74  // Setting particle properties
75  particleGun->SetParticleEnergy(particleEnergy);
76  particleGun->SetParticleMomentumDirection(particleDir);
77  particleGun->SetParticlePosition(particlePosition);
78  print(0);
79 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
void SetParticlePosition(G4ThreeVector aPosition)
tuple degree
Definition: hepunit.py:69
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111
G4bool isInitialized()
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
CCalPrimaryGeneratorAction::~CCalPrimaryGeneratorAction ( )

Definition at line 81 of file CCalPrimaryGeneratorAction.cc.

81  {
82  if (gunMessenger)
83  delete gunMessenger;
84  if (particleGun)
85  delete particleGun;
86 }

Member Function Documentation

void CCalPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 88 of file CCalPrimaryGeneratorAction.cc.

References python.hepunit::deg, G4cout, G4endl, G4ParticleGun::GeneratePrimaryVertex(), python.hepunit::GeV, G4ParticleGun::SetParticleEnergy(), G4ParticleGun::SetParticleMomentumDirection(), CLHEP::RandFlat::shoot(), singleRandom, and singleScan.

88  {
89 
90  if (isInitialized == 0) initialize();
91 
92  if (generatorInput == singleRandom) {
93  particleEnergy = CLHEP::RandFlat::shoot(energyMin,energyMax);
94  particleGun->SetParticleEnergy(particleEnergy);
95 
96  G4double eta = CLHEP::RandFlat::shoot(etaMin,etaMax);
97  G4double phi = CLHEP::RandFlat::shoot(phiMin,phiMax);
98  G4double theta = std::atan(std::exp(-eta))*2.;
99  G4double randomX = std::sin(theta)*std::cos(phi);
100  G4double randomY = std::sin(theta)*std::sin(phi);
101  G4double randomZ = std::cos(theta);
102 
103  particleDir = G4ThreeVector(randomX,randomY,randomZ);
104  particleGun->SetParticleMomentumDirection(particleDir);
105 #ifdef debug
106  if (verboseLevel >= 2 ) {
107  G4cout << "Energy " << particleEnergy/GeV << " GeV; Theta "
108  << theta/deg << " degree; Phi " << phi/deg << " degree" << G4endl;
109  G4cout << "Shooting in " << particleDir << " direction "<< G4endl;
110  }
111 #endif
112  } else if (generatorInput == singleScan) {
113  G4double scanEtaStep, scanPhiStep;
114  if (scanSteps == 0) {
115  scanPhiStep = (phiMax - phiMin) / phiSteps;
116  phiValue = phiMin - scanPhiStep; //first step is going to change scanCurrentPhiValue
117  etaValue = etaMin;
118  }
119 
120  scanEtaStep = (etaMax - etaMin) / etaSteps;
121  scanPhiStep = (phiMax - phiMin) / phiSteps;
122 #ifdef debug
123  if (verboseLevel > 2 ) {
124  G4cout << " scanEtaStep " << scanEtaStep << " # of Steps " << etaSteps
125  << G4endl;
126  G4cout << " scanPhiStep " << scanPhiStep << " # of Steps " << phiSteps
127  << G4endl;
128  }
129 #endif
130 
131  //----- First scan in phi, then in eta
132  if (phiMax - phiValue < 1.E-6 * scanPhiStep) { // !only <= 1.E6 steps allowed
133  if (etaMax - etaValue < 1.E-6 * scanEtaStep) { // !only <= 1.E6 steps allowed
134  G4cout << " Scan completed!" << G4endl;
135  return;
136  } else {
137  etaValue += scanEtaStep;
138  phiValue = phiMin;
139  }
140  } else {
141  phiValue += scanPhiStep;
142  }
143  G4double theta = std::atan(std::exp(-etaValue))*2.;
144 
145  G4double scanX = std::sin(theta)*std::cos(phiValue);
146  G4double scanY = std::sin(theta)*std::sin(phiValue);
147  G4double scanZ = std::cos(theta);
148  if (verboseLevel >= 2 ) {
149  G4cout << "Scan eta " << etaValue << " Phi " << phiValue/deg
150  << " theta " << theta/deg << G4endl;
151  }
152  particleDir = G4ThreeVector(scanX,scanY,scanZ);
153  particleGun->SetParticleMomentumDirection(particleDir);
154 #ifdef debug
155  if (verboseLevel > 2 ) {
156  G4cout << "Shooting in " << particleDir << " direction "<< G4endl;
157  }
158 #endif
159  scanSteps++;
160  }
161 
162  // Generate GEANT4 primary vertex
163  particleGun->GeneratePrimaryVertex(anEvent);
164 }
CLHEP::Hep3Vector G4ThreeVector
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
static double shoot()
Definition: RandFlat.cc:59
G4GLOB_DLL std::ostream G4cout
void SetParticleEnergy(G4double aKineticEnergy)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4bool isInitialized()
void initialize(Config const *const theConfig=0)
Initialize the particle table.
G4double CCalPrimaryGeneratorAction::GetParticleEnergy ( )
inline

Definition at line 91 of file CCalPrimaryGeneratorAction.hh.

References G4ParticleGun::GetParticleEnergy().

Referenced by CCalEndOfEventAction::EndOfEventAction().

91 {return particleGun->GetParticleEnergy();}
G4double GetParticleEnergy() const
G4ThreeVector CCalPrimaryGeneratorAction::GetParticlePosition ( )
inline

Definition at line 90 of file CCalPrimaryGeneratorAction.hh.

References G4VPrimaryGenerator::GetParticlePosition().

Referenced by CCalEndOfEventAction::EndOfEventAction().

90 {return particleGun->GetParticlePosition();}
G4ThreeVector GetParticlePosition()
void CCalPrimaryGeneratorAction::SetGunPosition ( const G4ThreeVector pos) const

Definition at line 327 of file CCalPrimaryGeneratorAction.cc.

References G4VPrimaryGenerator::SetParticlePosition().

327  {
328 
329  particleGun->SetParticlePosition(pos);
330 }
void SetParticlePosition(G4ThreeVector aPosition)
void CCalPrimaryGeneratorAction::SetMaximumEnergy ( G4double  p)

Definition at line 215 of file CCalPrimaryGeneratorAction.cc.

References G4cerr, G4cout, G4endl, and python.hepunit::GeV.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

215  {
216 
217  if (p <= 0.) {
218  G4cerr << "CCalPrimaryGeneratorAction::SetMaximumEnergy: value " << p/GeV
219  << "GeV is out of bounds, it will not be used" << G4endl;
220  G4cerr << " Should be >0. Please check" << G4endl;
221  } else {
222  energyMax = p;
223 #ifdef debug
224  if (verboseLevel >= 1 ) {
225  G4cout << " CCalPrimaryGeneratorAction: setting max. value of energy to "
226  << energyMax/GeV << " GeV " << G4endl;
227  }
228 #endif
229  }
230 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalPrimaryGeneratorAction::SetMaximumEta ( G4double  p)

Definition at line 299 of file CCalPrimaryGeneratorAction.cc.

References G4cout, and G4endl.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

299  {
300 
301  etaMax = p;
302 #ifdef debug
303  if (verboseLevel >= 1 ) {
304  G4cout << " CCalPrimaryGeneratorAction: setting max. value of eta to "
305  << etaMax << G4endl;
306  }
307 #endif
308 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void CCalPrimaryGeneratorAction::SetMaximumPhi ( G4double  p)

Definition at line 251 of file CCalPrimaryGeneratorAction.cc.

References G4cerr, G4cout, G4endl, and python.hepunit::pi.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

251  {
252 
253  if (std::fabs(p)>2.*pi) {
254  G4cerr << "CCalPrimaryGeneratorAction::SetMaximumPhi: setting value quite "
255  << "large" << G4endl;
256  G4cerr << " Should be given in radians - Please check" << G4endl;
257  } else {
258  phiMax = std::fabs(p);
259 #ifdef debug
260  if (verboseLevel >= 1 ) {
261  G4cout << " CCalPrimaryGeneratorAction: setting max. value of phi to "
262  << phiMax << G4endl;
263  }
264 #endif
265  }
266 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalPrimaryGeneratorAction::SetMinimumEnergy ( G4double  p)

Definition at line 197 of file CCalPrimaryGeneratorAction.cc.

References G4cerr, G4cout, G4endl, and python.hepunit::GeV.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

197  {
198 
199  if (p <= 0.) {
200  G4cerr << "CCalPrimaryGeneratorAction::SetMinimumEnergy: value " << p/GeV
201  << "GeV is out of bounds, it will not be used" << G4endl;
202  G4cerr << " Should be >0. Please check" << G4endl;
203  } else {
204  energyMin = p;
205 #ifdef debug
206  if (verboseLevel >= 1 ) {
207  G4cout << " CCalPrimaryGeneratorAction: setting min. value of energy to "
208  << energyMin/GeV << " GeV " << G4endl;
209  }
210 #endif
211  }
212 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalPrimaryGeneratorAction::SetMinimumEta ( G4double  p)

Definition at line 287 of file CCalPrimaryGeneratorAction.cc.

References G4cout, and G4endl.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

287  {
288 
289  etaMin = p;
290 #ifdef debug
291  if (verboseLevel >= 1 ) {
292  G4cout << " CCalPrimaryGeneratorAction: setting min. value of eta to "
293  << etaMin << G4endl;
294  }
295 #endif
296 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void CCalPrimaryGeneratorAction::SetMinimumPhi ( G4double  p)

Definition at line 233 of file CCalPrimaryGeneratorAction.cc.

References G4cerr, G4cout, G4endl, and python.hepunit::pi.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

233  {
234 
235  if (std::fabs(p)>2.*pi) {
236  G4cerr << "CCalPrimaryGeneratorAction::SetMinimumPhi: setting value quite "
237  << "large" << G4endl;
238  G4cerr << " Should be given in radians - Please check" << G4endl;
239  } else {
240  phiMin = std::fabs(p);
241 #ifdef debug
242  if (verboseLevel >= 1 ) {
243  G4cout << " CCalPrimaryGeneratorAction: setting min. value of phi to "
244  << phiMin << G4endl;
245  }
246 #endif
247  }
248 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalPrimaryGeneratorAction::SetRandom ( G4String  val)

Definition at line 172 of file CCalPrimaryGeneratorAction.cc.

References singleFixed, and singleRandom.

Referenced by CCalPrimaryGeneratorMessenger::SetNewValue().

172  {
173 
174  if (val=="on") {
175  generatorInput = singleRandom;
176  print (1);
177  } else {
178  generatorInput = singleFixed;
179  print (1);
180  }
181 }
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111
void CCalPrimaryGeneratorAction::SetRunNo ( G4int  val)

Definition at line 332 of file CCalPrimaryGeneratorAction.cc.

References G4RunManager::GetRunManager(), and G4RunManager::SetRunIDCounter().

Referenced by CCalPrimaryGeneratorMessenger::SetNewValue().

332  {
334 }
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
void SetRunIDCounter(G4int i)
void CCalPrimaryGeneratorAction::SetScan ( G4String  val)

Definition at line 184 of file CCalPrimaryGeneratorAction.cc.

References singleFixed, and singleScan.

Referenced by CCalPrimaryGeneratorMessenger::SetNewValue().

184  {
185 
186  if (val=="on") {
187  generatorInput = singleScan;
188  scanSteps = 0;
189  print (1);
190  } else {
191  generatorInput = singleFixed;
192  print (1);
193  }
194 }
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111
void CCalPrimaryGeneratorAction::SetStepsEta ( G4int  val)

Definition at line 311 of file CCalPrimaryGeneratorAction.cc.

References G4cerr, G4cout, and G4endl.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

311  {
312 
313  if (val <= 0) {
314  G4cerr<<"CCalPrimaryGeneratorAction::SetStepsEta: value " << val << " is out of bounds, it will not be used"<<G4endl;
315  G4cerr<<" Should be > 0 Please check"<<G4endl;
316  } else {
317  etaSteps = val;
318 #ifdef debug
319  if (verboseLevel >= 1 ) {
320  G4cout << " CCalPrimaryGeneratorAction: setting no. of steps in eta to "
321  << etaSteps << G4endl;
322  }
323 #endif
324  }
325 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalPrimaryGeneratorAction::SetStepsPhi ( G4int  val)

Definition at line 269 of file CCalPrimaryGeneratorAction.cc.

References G4cerr, G4cout, and G4endl.

Referenced by CCalPrimaryGeneratorAction(), and CCalPrimaryGeneratorMessenger::SetNewValue().

269  {
270 
271  if (val <= 0) {
272  G4cerr << "CCalPrimaryGeneratorAction::SetStepsPhi: value " << val
273  << " is out of bounds, it will not be used" << G4endl;
274  G4cerr << " Should be > 0 Please check" << G4endl;
275  } else {
276  phiSteps = val;
277 #ifdef debug
278  if (verboseLevel >= 1 ) {
279  G4cout << " CCalPrimaryGeneratorAction: setting no. of steps in phi to "
280  << phiSteps << G4endl;
281  }
282 #endif
283  }
284 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalPrimaryGeneratorAction::SetVerboseLevel ( G4int  val)

Definition at line 167 of file CCalPrimaryGeneratorAction.cc.

Referenced by CCalPrimaryGeneratorMessenger::SetNewValue().

167  {
168  verboseLevel = val;
169 }

The documentation for this class was generated from the following files: