DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4ParticleGun.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/Printout.h"
17 #include "DD4hep/InstanceCount.h"
18 #include "DDG4/Geant4Context.h"
19 #include "DDG4/Geant4Primary.h"
20 #include "DDG4/Geant4ParticleGun.h"
22 #include "CLHEP/Units/SystemOfUnits.h"
23 
24 // C/C++ include files
25 #include <limits>
26 
27 using namespace std;
28 using namespace DD4hep::Simulation;
29 
31 Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const string& nam)
32  : Geant4IsotropeGenerator(ctxt,nam), m_shotNo(0)
33 {
35  m_needsControl = true;
36  declareProperty("isotrop", m_isotrop = false);
37  declareProperty("Standalone", m_standalone = true);
38  // Backwards compatibility: Un-capitalize
39  declareProperty("position", m_position);
40  declareProperty("direction", m_direction);
41  declareProperty("energy", m_energy);
42  declareProperty("particle", m_particleName);
43  declareProperty("multiplicity", m_multiplicity);
44  declareProperty("print", m_print = true);
45 }
46 
50 }
51 
53 void Geant4ParticleGun::operator()(G4Event* event) {
54  if ( m_isotrop ) {
55  double mom = 0.0;
57  }
58  else {
59  double r = m_direction.R(), eps = numeric_limits<float>::epsilon();
60  if ( r > eps ) {
61  m_direction.SetXYZ(m_direction.X()/r, m_direction.Y()/r, m_direction.Z()/r);
62  }
63  }
64 
65  if ( m_standalone ) {
67  }
69  print("Shoot [%d] %.3f GeV %s pos:(%.3f %.3f %.3f)[mm] dir:(%6.3f %6.3f %6.3f)",
72  m_direction.X(),m_direction.Y(), m_direction.Z());
73  if ( m_print ) {
75  }
76  ++m_shotNo;
77  if ( m_standalone ) {
78  mergeInteractions(this,context());
79  generatePrimaries(this,context(),event);
80  }
81 }
Generate particles isotrop in space around origine (0,0,0)
ROOT::Math::XYZVector m_direction
Property: Shooting direction of the gun.
ROOT::Math::XYZVector m_position
Property: Position of the gun in space.
bool m_standalone
Property: Standalone mode: includes interaction merging and primary generation.
bool m_print
Property: Enable printout.
static void decrement(T *)
Decrement count according to type information.
bool m_isotrop
Property: Isotrope particles?
int m_shotNo
Shot number in sequence.
virtual void operator()(G4Event *event)
Callback to generate primary particles.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
virtual void printInteraction(int mask) const
Print single particle interaction identified by its mask.
static const double GeV
Definition: DD4hepUnits.h:149
int m_multiplicity
Property: Desired multiplicity of the particles to be shot.
virtual void operator()(G4Event *event)
Callback to generate primary particles.
virtual void getParticleDirection(int num, ROOT::Math::XYZVector &direction, double &momentum) const
Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = m_energy) ...
int m_mask
Property: User mask passed to all particles in the generated interaction.
int mergeInteractions(const Geant4Action *caller, const Geant4Context *context)
Merge all interactions present in the context.
int generatePrimaries(const Geant4Action *caller, const Geant4Context *context, G4Event *event)
Generate all primary vertices corresponding to the merged interaction.
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:101
std::string m_particleName
Property: Particle name.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
double m_energy
Property: Particle energy.
Generic context to extend user, run and event information.
virtual ~Geant4ParticleGun()
Default destructor.
static const double mm
Definition: DD4hepUnits.h:69
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:358
int generationInitialization(const Geant4Action *caller, const Geant4Context *context)
Initialize the generation of one event.