DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4ParticleGun.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/InstanceCount.h>
17 #include <DDG4/Geant4Context.h>
18 #include <DDG4/Geant4Primary.h>
19 #include <DDG4/Geant4ParticleGun.h>
21 #include <CLHEP/Units/SystemOfUnits.h>
22 
23 // C/C++ include files
24 #include <limits>
25 
26 using namespace dd4hep::sim;
27 
29 Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const std::string& nam)
30  : Geant4IsotropeGenerator(ctxt,nam), m_shotNo(0)
31 {
33  m_needsControl = true;
34  declareProperty("Standalone", m_standalone = true);
35  declareProperty("mask", m_mask);
36  declareProperty("isotrop", m_isotrop = false);
37  declareProperty("standalone", m_standalone);
38  // Backwards compatibility: Un-capitalize
39  declareProperty("position", m_position);
40  declareProperty("distribution", m_distribution);
41  declareProperty("direction", m_direction);
42  declareProperty("particle", m_particleName);
43  declareProperty("multiplicity", m_multiplicity);
44  declareProperty("print", m_print = true);
45 }
46 
50 }
51 
53 void Geant4ParticleGun::getParticleDirection(int num, ROOT::Math::XYZVector& direction, double& momentum) const {
54  ( m_isotrop )
55  ? this->Geant4IsotropeGenerator::getParticleDirection(num, direction, momentum)
56  : this->Geant4ParticleGenerator::getParticleDirection(num, direction, momentum);
57 }
58 
60 void Geant4ParticleGun::operator()(G4Event* event) {
61  double r = m_direction.R(), eps = std::numeric_limits<float>::epsilon();
62  if ( r > eps ) {
63  m_direction.SetXYZ(m_direction.X()/r, m_direction.Y()/r, m_direction.Z()/r);
64  }
65 
66  if ( m_standalone ) {
68  }
69 
70  //bit wasteful to always set this :(
71  if( m_energy != -1 ){
74  }
75 
76  print("Shoot [%d] [%.3f , %.3f] GeV %s pos:(%.3f %.3f %.3f)[mm] dir:(%6.3f %6.3f %6.3f)",
77  m_shotNo, m_momentumMin/CLHEP::GeV, m_momentumMax/CLHEP::GeV, m_particleName.c_str(),
78  m_position.X()/CLHEP::mm, m_position.Y()/CLHEP::mm, m_position.Z()/CLHEP::mm,
79  m_direction.X(), m_direction.Y(), m_direction.Z());
81  if ( m_print ) {
83  }
84  ++m_shotNo;
85  if ( m_standalone ) {
86  mergeInteractions(this,context());
87  generatePrimaries(this,context(),event);
88  }
89 }
dd4hep::sim::Geant4ParticleGenerator::m_multiplicity
int m_multiplicity
Property: Desired multiplicity of the particles to be shot.
Definition: Geant4ParticleGenerator.h:56
dd4hep::sim::Geant4ParticleGun::m_standalone
bool m_standalone
Property: Standalone mode: includes interaction merging and primary generation.
Definition: Geant4ParticleGun.h:61
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4ParticleGenerator::m_mask
int m_mask
Property: User mask passed to all particles in the generated interaction.
Definition: Geant4ParticleGenerator.h:58
dd4hep::sim::mergeInteractions
int mergeInteractions(const Geant4Action *caller, const Geant4Context *context)
Merge all interactions present in the context.
Definition: Geant4InputHandling.cpp:226
dd4hep::sim::generationInitialization
int generationInitialization(const Geant4Action *caller, const Geant4Context *context)
Initialize the generation of one event.
Definition: Geant4InputHandling.cpp:143
dd4hep::sim::Geant4ParticleGenerator::m_momentumMin
double m_momentumMin
Property: Minimal momentum value.
Definition: Geant4ParticleGenerator.h:52
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4ParticleGun::m_isotrop
bool m_isotrop
Property: Isotrope particles?
Definition: Geant4ParticleGun.h:59
Geant4InputHandling.h
dd4hep::sim::Geant4ParticleGenerator::m_energy
double m_energy
Property: Fixed momentum value, overwrites momentumMin and momentumMax if set.
Definition: Geant4ParticleGenerator.h:50
dd4hep::sim::generatePrimaries
int generatePrimaries(const Geant4Action *caller, const Geant4Context *context, G4Event *event)
Generate all primary vertices corresponding to the merged interaction.
Definition: Geant4InputHandling.cpp:476
epsilon
const double epsilon
Definition: test_cellid_position_converter.cpp:41
dd4hep::sim::Geant4ParticleGenerator::m_direction
ROOT::Math::XYZVector m_direction
Property: Shooting direction of the gun.
Definition: Geant4ParticleGenerator.h:42
dd4hep::sim::Geant4ParticleGun::Geant4ParticleGun
Geant4ParticleGun(Geant4Context *context, const std::string &name)
Standard constructor.
dd4hep::sim::Geant4ParticleGenerator::operator()
virtual void operator()(G4Event *event) override
Callback to generate primary particles.
Definition: Geant4ParticleGenerator.cpp:120
dd4hep::sim::Geant4ParticleGenerator::m_position
ROOT::Math::XYZVector m_position
Property: Position of the gun in space.
Definition: Geant4ParticleGenerator.h:44
dd4hep::sim::Geant4ParticleGenerator::m_momentumMax
double m_momentumMax
Property: Maximal momentum value.
Definition: Geant4ParticleGenerator.h:54
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4ParticleGun::operator()
virtual void operator()(G4Event *event)
Callback to generate primary particles.
dd4hep::sim::Geant4ParticleGun::m_print
bool m_print
Property: Enable printout.
Definition: Geant4ParticleGun.h:63
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:41
dd4hep::sim::Geant4ParticleGun::~Geant4ParticleGun
virtual ~Geant4ParticleGun()
Default destructor.
dd4hep::sim::Geant4ParticleGenerator::m_particleName
std::string m_particleName
Property: Particle name.
Definition: Geant4ParticleGenerator.h:46
Geant4Primary.h
Geant4ParticleGun.h
dd4hep::sim::Geant4ParticleGun::getParticleDirection
virtual void getParticleDirection(int, ROOT::Math::XYZVector &direction, double &momentum) const
Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = [m_momentumM...
dd4hep::sim::Geant4IsotropeGenerator::getParticleDirection
virtual void getParticleDirection(int num, ROOT::Math::XYZVector &direction, double &momentum) const override
Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = [m_momentumM...
Definition: Geant4IsotropeGenerator.cpp:119
InstanceCount.h
dd4hep::sim::Geant4ParticleGenerator::getParticleDirection
virtual void getParticleDirection(int num, ROOT::Math::XYZVector &direction, double &momentum) const
Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = m_energy)
Definition: Geant4ParticleGenerator.cpp:56
dd4hep::sim::Geant4ParticleGenerator::printInteraction
virtual void printInteraction(int mask) const
Print single particle interaction identified by its mask.
Definition: Geant4ParticleGenerator.cpp:84
Printout.h
Geant4Context.h
dd4hep::sim::Geant4ParticleGun::m_shotNo
int m_shotNo
Shot number in sequence.
Definition: Geant4ParticleGun.h:65
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4IsotropeGenerator
Generate particles isotrop in space around origine (0,0,0)
Definition: Geant4IsotropeGenerator.h:31
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270