Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// $Id: Geant4Hits.h 513 2013-04-05 14:31:53Z gaede $
//====================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
#ifndef DD4HEP_DDG4_GEANT4PARTICLEGUN_H
#define DD4HEP_DDG4_GEANT4PARTICLEGUN_H
// Framework include files
#include "DDG4/Geant4GeneratorAction.h"
// Forward declarations
class G4ParticleDefinition;
class G4ParticleGun;
/*
* DD4hep namespace declaration
*/
namespace DD4hep {
/*
* Simulation namespace declaration
*/
namespace Simulation {
/** @class Geant4ParticleGun Geant4ParticleGun.h DDG4/Geant4ParticleGun.h
*
* Implementation wrapper of the Geant4 particle gun
*
* @author M.Frank
* @version 1.0
*/
class Geant4ParticleGun : public Geant4GeneratorAction {
protected:
/// Position and shooting direction of the gun
struct { double x,y,z; } m_position, m_direction;
/// Particle energy
double m_energy;
/// Desired multiplicity of the particles to be shot
int m_multiplicity;
/// Particle name
std::string m_particleName;
/// Pointer to geant4 particle definition
G4ParticleDefinition* m_particle;
/// Pointer to the particle gun itself
G4ParticleGun* m_gun;
public:
/// Standard constructor
Geant4ParticleGun(Geant4Context* context, const std::string& name);
/// Default destructor
virtual ~Geant4ParticleGun();
/// Callback to generate primary particles
virtual void operator()(G4Event* event);
};
} // End namespace Simulation
} // End namespace DD4hep
#endif /* DD4HEP_DDG4_GEANT4PARTICLEGUN_H */
// $Id: Geant4Converter.cpp 603 2013-06-13 21:15:14Z markus.frank $
//====================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
// Framework include files
#include "DD4hep/InstanceCount.h"
//#include "DDG4/Geant4ParticleGun.h"
#include "DDG4/Factories.h"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
// C/C++ include files
#include <stdexcept>
using namespace DD4hep::Simulation;
DECLARE_GEANT4ACTION(Geant4ParticleGun)
/// Standard constructor
Geant4ParticleGun::Geant4ParticleGun(Geant4Context* context, const std::string& name)
: Geant4GeneratorAction(context,name), m_particle(0), m_gun(0)
{
InstanceCount::increment(this);
declareProperty("energy", m_energy=50*MeV);
declareProperty("multiplicity", m_multiplicity=1);
declareProperty("pos_x", m_position.x = 0);
declareProperty("pos_y", m_position.y = 0);
declareProperty("pos_z", m_position.z = 0);
declareProperty("direction_x", m_direction.x = 1);
declareProperty("direction_y", m_direction.y = 1);
declareProperty("direction_z", m_direction.z = 0.3);
declareProperty("particle", m_particleName= "e-");
}
/// Default destructor
Geant4ParticleGun::~Geant4ParticleGun() {
if ( m_gun ) delete m_gun;
InstanceCount::decrement(this);
}
/// Callback to generate primary particles
void Geant4ParticleGun::operator()(G4Event* event) {
if ( 0 == m_gun ) {
m_gun = new G4ParticleGun(m_multiplicity);
}
if ( 0 == m_particle || m_particle->GetParticleName() != m_particleName.c_str() ) {
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
m_particle = particleTable->FindParticle(m_particleName);
if ( 0 == m_particle ) {
throw std::runtime_error("Bad particle type!");
}
}
m_gun->SetParticleDefinition(m_particle);
m_gun->SetParticleEnergy(m_energy);
m_gun->SetParticleMomentumDirection(G4ThreeVector(m_direction.x,m_direction.y,m_direction.z));
m_gun->SetParticlePosition(G4ThreeVector(m_position.x,m_position.y,m_position.z));
m_gun->GeneratePrimaryVertex(event);
}