Geant4 VMC Version 6.7
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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//_____________________________________________________________________________
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
186 // Get or create fast simulation process
187 G4FastSimulationManagerProcess* fastSimulationProcess =
189
190 // Add fast simulation process to selected particles
191 auto aParticleIterator = GetParticleIterator();
192 aParticleIterator->reset();
193 while ((*aParticleIterator)()) {
194 G4ParticleDefinition* particle = aParticleIterator->value();
195 G4String particleName = particle->GetParticleName();
196
197 // skip particles which are not in the model configuration selection
198 if (! (*it)->HasParticle(particleName) ) continue;
199
200 // skip particles which do not have process manager
201 if (!particle->GetProcessManager()) continue;
202
203 if (VerboseLevel() > 2) {
204 G4cout << "Adding model " << modelName << " to particle "
205 << particle->GetParticleName() << G4endl;
206 }
207
208 // Set the process to the particle process manager
209 particle->GetProcessManager()->AddDiscreteProcess(fastSimulationProcess);
210 }
211 }
212}
213
214//
215// protected methods
216//
217
218//_____________________________________________________________________________
223
224//_____________________________________________________________________________
226{
227 if (VerboseLevel() > 1) {
228 G4cout << "TG4FastSimulationPhysics::ConstructProcess " << G4endl;
229 }
230
231 // Get model configurations vector from geometry manager
232 TG4ModelConfigurationManager* fastModelsManager =
234
235 const std::vector<TG4ModelConfiguration*>& models =
236 fastModelsManager->GetVector();
237
238 // Do nothing if no models were set
239 if (models.size() == 0) {
240 if (VerboseLevel() > 1) {
241 G4cout << "No fast simulation models are defined." << G4endl;
242 }
243 return;
244 }
245
246 // Construct user models
248 fUserFastSimulation->Construct();
249 }
250
251 // Update regions
252 UpdateRegions(models);
253
254 // Add fast simulation process to particles
256
257 if (VerboseLevel() > 0) {
258 G4cout << "### Fast simulation models added to physics processes" << G4endl;
259 }
260}
261
262//
263// public methods
264//
265
266//_____________________________________________________________________________
268 TG4VUserFastSimulation* fastSimulation)
269{
273
275 TG4Globals::Warning("TG4FastSimulationPhysics", "SetUserFastSimulation",
276 "Fast simulation was already defined, setting is ignored.");
277 return;
278 }
279
280 fUserFastSimulation = fastSimulation;
281}
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
std::map< G4String, G4FastSimulationManagerProcess * > ProcessMap
void AddFastSimulationProcess(const std::vector< TG4ModelConfiguration * > &models)
virtual void ConstructProcess()
Construct physics processes.
virtual void ConstructParticle()
Construct particles.
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
TG4VPhysicsConstructor(const G4String &name)
virtual G4int VerboseLevel() const
The abstract base class which is used to build fast simulation models.