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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/* #include <dataclasses/physics/I3Particle.h> */
#include "G4Interface.h"
#include "G4BeamTestDetectorConstruction.h"
#include "G4BeamTestPhysicsList.h"
#include "G4BeamTestUserTrackingAction.h"
#include "G4BeamTestUserSteppingAction.h"
/* #include <icetray/I3Logging.h> */
#ifdef G4VIS_USE
#include <G4VisExecutive.hh>
#endif
#include <G4ParticleGun.hh>
#include <G4ParticleTable.hh>
#include <G4ParticleDefinition.hh>
/* #include <G4UImanager.hh> */
G4Interface* G4Interface::g4Interface_ = NULL;
G4Interface::G4Interface(const std::string& visMacro):
detector_(NULL), initialized_(false),
eventInitialized_(false), visMacro_(visMacro)
{
g4Interface_ = this;
// Visualization manager
#ifdef G4VIS_USE
visManager_ = NULL;
visManager_ = new G4VisExecutive();
visManager_->Initialize();
#endif
}
G4Interface::~G4Interface()
{
g4Interface_ = NULL;
#ifdef G4VIS_USE
if(visManager_) delete visManager_;
#endif
}
void G4Interface::InstallTank(G4BeamTestTank* tank)
{
if(initialized_)
{
/* log_fatal("G4Interface aleady initialized. Cannot install tank!"); */
G4cout << "G4Interface aleady initialized. Cannot install tank!" << G4endl;
return;
}
if(!detector_) detector_ = new G4BeamTestDetectorConstruction();
detector_->InstallTank(tank);
}
void G4Interface::InitializeEvent()
{
///
/// An IceTray EVENT corresponds to a G4RUN
/// where each injected particle initiates an G4EVENT
///
if(!initialized_)
{
Initialize();
}
if(!eventInitialized_)
{
runManager_.InitializeRun();
eventInitialized_ = true;
}
}
void G4Interface::InjectParticle(
const std::string& particleName, const G4ThreeVector& particlePosition,
const G4ThreeVector& particleDirection, const G4double particleEnergy
)
{
if(!eventInitialized_)
{
/* log_fatal("No event initialized. Cannot inject particle!"); */
G4cout << "No event initialized. Cannot inject particle!" << G4endl;
return;
}
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition* particleDef = NULL;
particleDef = particleTable->FindParticle(particleName);
// Transform coordinates to world system
G4ThreeVector position = particlePosition - detector_->GetWorldOrigin();
G4ParticleGun gun(1);
gun.SetParticleDefinition(particleDef);
gun.SetParticleEnergy(particleEnergy);
gun.SetParticlePosition(position);
gun.SetParticleMomentumDirection(particleDirection);
G4cout << "Injecting %s: x=%.2f m, y=%.2f m, z=%.2f m, E=%.3f MeV",
particleName.c_str(),
position.x() / CLHEP::m,
position.y() / CLHEP::m,
position.z() / CLHEP::m,
gun.GetParticleEnergy() / CLHEP::MeV;
runManager_.InjectParticle(&gun);
}
void G4Interface::TerminateEvent()
{
///
/// An IceTray EVENT corresponds to a G4RUN
/// where each injected particle initiates an G4EVENT
///
if(eventInitialized_)
{
runManager_.TerminateRun();
eventInitialized_ = false;
}
}
void G4Interface::Initialize()
{
if(initialized_)
{
/* log_error("G4Interface has already been initialized. Ignoring this call!"); */
G4cout << "G4Interface has already been initialized. Ignoring this call!" << G4endl;
return;
}
/* log_debug("Init geometry ..."); */
G4cout << "Init geometry ..." << G4endl;
runManager_.SetUserInitialization(detector_);
/* log_debug("Init physics list ..."); */
G4cout << "Init physics list ..." << G4endl;
runManager_.SetUserInitialization(new G4BeamTestPhysicsList());
/* log_debug("Init UserTrackingAction ..."); */
G4cout << "Init UserTrackingAction ..." << G4endl;
runManager_.SetUserAction(new G4BeamTestUserTrackingAction());
/* log_debug("Init UserSteppingAction ..."); */
G4cout << "Init UserSteppingAction ..." << G4endl;
runManager_.SetUserAction(new G4BeamTestUserSteppingAction());
// Initialize G4 kernel
/* log_debug("Init run manager ..."); */
G4cout << "Init run manager ..." << G4endl;
runManager_.Initialize();
/* // Set verbosity */
/* int verboseLevel = 0; */
/* switch (GetIcetrayLogger()->LogLevelForUnit("G4Interface")) */
/* { */
/* case I3LOG_FATAL: */
/* case I3LOG_ERROR: */
/* case I3LOG_WARN: */
/* case I3LOG_INFO: */
/* case I3LOG_NOTICE: */
/* default: */
/* verboseLevel = 0; */
/* break; */
/* case I3LOG_DEBUG: */
/* verboseLevel = 1; */
/* break; */
/* case I3LOG_TRACE: */
/* verboseLevel = 2; */
/* break; */
/* } */
// TODO(shivesh): verbosity
/* runManager_.SetVerboseLevel(verboseLevel); */
/* G4EventManager::GetEventManager()->SetVerboseLevel(verboseLevel); */
/* G4EventManager::GetEventManager()->GetStackManager()->SetVerboseLevel(verboseLevel); */
/* G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(verboseLevel); */
/* #ifdef G4VIS_USE */
/* if(visManager_) visManager_->SetVerboseLevel(verboseLevel); */
/* #endif */
// Execute visualization macro (if specified)
/* if(!visMacro_.empty()) */
/* { */
/* G4UImanager* uim = G4UImanager::GetUIpointer(); */
/* */
/* // Checking geometry */
/* uim->ApplyCommand("/geometry/test/grid_test"); */
/* */
/* // Execute visualization macro */
/* std::string visCmd = "/control/execute " + visMacro_; */
/* uim->ApplyCommand(visCmd.c_str()); */
/* } */
initialized_ = true;
}
|