Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4FastSimulationPhysics.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2015 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
16#include "TG4GeometryManager.h"
17#include "TG4Globals.h"
21
22#include <G4FastSimulationManagerProcess.hh>
23#include <G4ParticleDefinition.hh>
24#include <G4ProcessManager.hh>
25#include <G4Region.hh>
26#include <G4RegionStore.hh>
27
28//_____________________________________________________________________________
31
32//_____________________________________________________________________________
34 : TG4VPhysicsConstructor(name), fUserFastSimulation(0)
35{
37}
38
39//_____________________________________________________________________________
41 G4int theVerboseLevel, const G4String& name)
42 : TG4VPhysicsConstructor(name, theVerboseLevel), fUserFastSimulation(0)
43{
45}
46
47//_____________________________________________________________________________
49{
51
52 if (fgProcessMap) {
53 ProcessMap::iterator it;
54 for (it = fgProcessMap->begin(); it != fgProcessMap->end(); it++) {
55 delete it->second;
56 }
57 delete fgProcessMap;
58 fgProcessMap = 0;
59 }
60}
61
62//
63// private methods
64//
65
66//_____________________________________________________________________________
68 const std::vector<TG4ModelConfiguration*>& models)
69{
70
71 if (VerboseLevel() > 1) {
72 G4cout << "TG4FastSimulationPhysics::UpdateRegions" << G4endl;
73 }
74
75 // Process fast models configurations
76 std::vector<TG4ModelConfiguration*>::const_iterator it;
77 for (it = models.begin(); it != models.end(); it++) {
78
79 // Get model configuration
80 G4String modelName = (*it)->GetModelName();
81 const std::vector<G4String>& regions = (*it)->GetRegions();
82 G4VFastSimulationModel* fastSimulationModel =
83 (*it)->GetFastSimulationModel();
84
85 if (VerboseLevel() > 1) {
86 G4cout << "Adding fast simulation model " << modelName << " to regions ";
87 std::vector<G4String>::const_iterator itm;
88 for (itm = regions.begin(); itm != regions.end(); itm++) {
89 G4cout << (*itm) << " ";
90 }
91 G4cout << G4endl;
92 }
93
94 if (!fastSimulationModel) {
95 TString text = "The fast simulation model ";
96 text += modelName.data();
97 text += " was not found.";
98 TG4Globals::Warning("TG4FastSimulationPhysics", "UpdateRegions", text);
99 continue;
100 }
101
102 if (!regions.size()) {
103 TString text = "The fast simulation model ";
104 text += modelName.data();
105 text += " has no associated region.";
106 TG4Globals::Warning("TG4FastSimulationPhysics", "UpdateRegions", text);
107 continue;
108 }
109
110 for (G4int j = 0; j < G4int(regions.size()); ++j) {
111
112 // Get region
113 G4Region* region = G4RegionStore::GetInstance()->GetRegion(regions[j]);
114
115 if (!region) {
116 TString text = "The region ";
117 text += regions[j].data();
118 text += " was not found.";
119 TG4Globals::Warning("TG4FastSimulationPhysics", "UpdateRegions", text);
120 continue;
121 }
122
123 // Retrieve fast simulation manager ou create one if needed.
124 G4FastSimulationManager* fastSimulationManager =
125 region->GetFastSimulationManager();
126 if (!fastSimulationManager) {
127 if (VerboseLevel() > 1) {
128 G4cout << "creating G4FastSimulationManager for the region" << G4endl;
129 }
130 // TO DO: CHECK THIS
131 G4bool isUnique = false;
132 fastSimulationManager = new G4FastSimulationManager(region, isUnique);
133 }
134 fastSimulationManager->AddFastSimulationModel(fastSimulationModel);
135 }
136 }
137}
138
139//_____________________________________________________________________________
140G4FastSimulationManagerProcess*
142 const G4String& modelName)
143{
146
147 // Create fast simulation process map if it does not yet exist
148 if (!fgProcessMap) {
149 fgProcessMap = new ProcessMap();
150 }
151
152 // Create one thread-local fast simulation process per model
153 G4FastSimulationManagerProcess* fastSimulationProcess = 0;
154 ProcessMap::iterator it = fgProcessMap->find(modelName);
155 if (it != fgProcessMap->end()) {
156 fastSimulationProcess = it->second;
157 }
158 else {
159 // fastSimulationProcess = new G4FastSimulationManagerProcess(modelName);
160 fastSimulationProcess = new G4FastSimulationManagerProcess();
161 (*fgProcessMap)[modelName] = fastSimulationProcess;
162 G4cout << "... created fastSimulationProcess" << G4endl;
163 }
164
165 return fastSimulationProcess;
166}
167
168//_____________________________________________________________________________
170 const std::vector<TG4ModelConfiguration*>& models)
171{
174
175 if (VerboseLevel() > 1) {
176 G4cout << "TG4FastSimulationPhysics::AddFastSimulationProcess" << G4endl;
177 }
178
179 // Process fast models configurations
180 std::vector<TG4ModelConfiguration*>::const_iterator it;
181 for (it = models.begin(); it != models.end(); it++) {
182
183 // Get model name
184 G4String modelName = (*it)->GetModelName();
185 G4String particles = (*it)->GetParticles();
186
187 // Get or create fast simulation process
188 G4FastSimulationManagerProcess* fastSimulationProcess =
190
191 // Add fast simulation process to selected particles
192 auto aParticleIterator = GetParticleIterator();
193 aParticleIterator->reset();
194 while ((*aParticleIterator)()) {
195 G4ParticleDefinition* particle = aParticleIterator->value();
196 G4String particleName = particle->GetParticleName();
197
198 // skip particles which are not in selection
199 if (particles != "all" && (!(*it)->HasParticle(particleName))) {
200 continue;
201 }
202
203 // skip particles which do not have process manager
204 if (!particle->GetProcessManager()) continue;
205
206 if (VerboseLevel() > 2) {
207 G4cout << "Adding model " << modelName << " to particle "
208 << particle->GetParticleName() << G4endl;
209 }
210
211 // Set the process to the particle process manager
212 particle->GetProcessManager()->AddDiscreteProcess(fastSimulationProcess);
213 }
214 }
215}
216
217//
218// protected methods
219//
220
221//_____________________________________________________________________________
226
227//_____________________________________________________________________________
229{
230 if (VerboseLevel() > 1) {
231 G4cout << "TG4FastSimulationPhysics::ConstructProcess " << G4endl;
232 }
233
234 // Get model configurations vector from geometry manager
235 TG4ModelConfigurationManager* fastModelsManager =
237
238 const std::vector<TG4ModelConfiguration*>& models =
239 fastModelsManager->GetVector();
240
241 // Do nothing if no models were set
242 if (models.size() == 0) {
243 if (VerboseLevel() > 1) {
244 G4cout << "No fast simulation models are defined." << G4endl;
245 }
246 return;
247 }
248
249 // Construct user models
252 }
253
254 // Update regions
255 UpdateRegions(models);
256
257 // Add fast simulation process to particles
259
260 if (VerboseLevel() > 0) {
261 G4cout << "### Fast simulation models added to physics processes" << G4endl;
262 }
263}
264
265//
266// public methods
267//
268
269//_____________________________________________________________________________
271 TG4VUserFastSimulation* fastSimulation)
272{
276
278 TG4Globals::Warning("TG4FastSimulationPhysics", "SetUserFastSimulation",
279 "Fast simulation was already defined, setting is ignored.");
280 return;
281 }
282
283 fUserFastSimulation = fastSimulation;
284}
Definition of the TG4FastSimulationPhysics class.
Definition of the TG4GeometryManager class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4ModelConfigurationManager class.
Definition of the TG4ModelConfiguration class.
Definition of the TG4VUserFastSimulation class.
void SetUserFastSimulation(TG4VUserFastSimulation *userFastSimulation)
static G4ThreadLocal ProcessMap * fgProcessMap
fast simulation processes map
void UpdateRegions(const std::vector< TG4ModelConfiguration * > &models)
TG4FastSimulationPhysics(const G4String &name="FastSimulation")
TG4VUserFastSimulation * fUserFastSimulation
the user fast simulation
void AddFastSimulationProcess(const std::vector< TG4ModelConfiguration * > &models)
virtual void ConstructProcess()
Construct physics processes.
virtual void ConstructParticle()
Construct particles.
std::map< G4String, G4FastSimulationManagerProcess * > ProcessMap
G4FastSimulationManagerProcess * GetOrCreateFastSimulationProcess(const G4String &modelName)
TG4ModelConfigurationManager * GetFastModelsManager() const
static TG4GeometryManager * Instance()
static void Warning(const TString &className, const TString &methodName, const TString &text)
The model configuration vector with suitable setters and a messenger.
const ModelConfigurationVector & GetVector() const
Abstract base class for physics constructors with verbose.
virtual G4int VerboseLevel() const
The abstract base class which is used to build fast simulation models.
virtual void Construct()=0
Method to be overriden by user.