Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4ModelConfigurationManager.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 "TG4G3ControlVector.h"
17#include "TG4GeometryServices.h"
18#include "TG4Limits.h"
19#include "TG4Medium.h"
20#include "TG4MediumMap.h"
23#include "TG4PhysicsManager.h"
24
25#include <G4LogicalVolume.hh>
26#include <G4LogicalVolumeStore.hh>
27#include <G4Material.hh>
28#include <G4ProductionCuts.hh>
29#include <G4Region.hh>
30#include <G4RegionStore.hh>
31#include <G4TransportationManager.hh>
32
33#ifdef G4MULTITHREADED
34namespace
35{
36// Mutex to lock creating regions
37G4Mutex setRegionsNamesMutex = G4MUTEX_INITIALIZER;
38G4Mutex createRegionsMutex = G4MUTEX_INITIALIZER;
39} // namespace
40#endif
41
42//_____________________________________________________________________________
44 const G4String& name, const G4String& availableModels)
45 : TG4Verbose(G4String(name).append("ConfigurationManager")),
46 // make the verbose name unique
47 fMessenger(0),
48 fName(name),
49 fAvailableModels(availableModels),
50 fVector(),
51 fCreateRegionsDone(false)
52{
54
55 if (VerboseLevel() > 1) {
56 G4cout << "TG4ModelConfigurationManager::TG4ModelConfigurationManager"
57 << G4endl;
58 }
59
60 fMessenger = new TG4ModelConfigurationMessenger(this, availableModels);
61}
62
63//_____________________________________________________________________________
65{
67
68 delete fMessenger;
69
70 ModelConfigurationVector::iterator it;
71 for (it = fVector.begin(); it != fVector.end(); it++) {
72 delete *it;
73 }
74}
75
76//
77// private methods
78//
79
80//_____________________________________________________________________________
82{
86
87#ifdef G4MULTITHREADED
88 G4AutoLock lm(&setRegionsNamesMutex);
89#endif
91
92 ModelConfigurationVector::iterator it;
93 for (it = fVector.begin(); it != fVector.end(); it++) {
94
95 const std::vector<G4String>& mediaNames = (*it)->GetRegionsMedia();
96
97 // Process the vector and generate a new list with material names
98 std::vector<G4String>::const_iterator itr;
99 for (itr = mediaNames.begin(); itr != mediaNames.end(); itr++) {
100
101 std::vector<TG4Medium*> media;
102 G4bool isPattern = (*itr).find("*") != std::string::npos;
103 if (isPattern) {
104 // G4cout << "processing " << (*itr) << " as pattern." << G4endl;
105 mediumMap->GetMedia(*itr, media);
106 }
107 else {
108 // G4cout << "processing " << (*itr) << " as single medium." << G4endl;
109 TG4Medium* medium = mediumMap->GetMedium(*itr);
110 if (!medium) {
111 // Add warning
112 TString text = "Medium ";
113 text += (*itr).data();
114 text += " not found.";
115 text += TG4Globals::Endl();
116 text += "The special physics model will not be applied.";
118 "TG4ModelConfigurationManager", "SetRegionsNames", text);
119 continue;
120 }
121 media.push_back(medium);
122 }
123
124 std::vector<TG4Medium*>::const_iterator itrm;
125 for (itrm = media.begin(); itrm != media.end(); itrm++) {
126 G4String materialName = (*itrm)->GetMaterial()->GetName();
127 (*it)->SetOneRegion(materialName);
128 }
129 }
130
131 if (VerboseLevel() > 1) {
132 // Print the new regions names corresponding to materials
133 G4cout << "TG4ModelConfigurationManager::SetRegionsNames: ";
134 const std::vector<G4String>& regions = (*it)->GetRegions();
135 std::vector<G4String>::const_iterator itm;
136 for (itm = regions.begin(); itm != regions.end(); itm++) {
137 G4cout << "\'" << (*itm) << "\' ";
138 }
139 G4cout << G4endl;
140 }
141 }
142#ifdef G4MULTITHREADED
143 lm.unlock();
144#endif
145}
146
147//
148// public methods
149//
150
151//_____________________________________________________________________________
153{
155
156 if (VerboseLevel() > 1) {
157 G4cout << "TG4ModelConfigurationManager::CreateRegions" << G4endl;
158 }
159
160 // Return if no models are registered
161 if (!fVector.size()) return;
162
163 // Return if regions were already created
164 if (fCreateRegionsDone) return;
165
166 // Generate new regions names based on material names
168
169#ifdef G4MULTITHREADED
170 G4AutoLock lm(&createRegionsMutex);
171 if (!fCreateRegionsDone) {
172#endif
173 // Loop over logical volumes
174 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
175 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
176 G4LogicalVolume* lv = (*lvStore)[i];
177 G4String materialName = lv->GetMaterial()->GetName();
178
179 if (VerboseLevel() > 2) {
180 G4cout << "Processing volume " << lv->GetName() << ", material "
181 << materialName << G4endl;
182 }
183
184 // Skip volumes with materials which are not in the regions list
185 G4bool isModelRegion = false;
186 ModelConfigurationVector::const_iterator it;
187 for (it = fVector.begin(); it != fVector.end(); it++) {
188 if ((*it)->HasRegion(materialName)) isModelRegion = true;
189 }
190
191 if (!isModelRegion) {
192 if (VerboseLevel() > 2) {
193 G4cout << "Material " << materialName << " is not in selection"
194 << G4endl;
195 }
196 continue;
197 }
198
199 // If region already exists, only add the logical volume
200 // and continue the loop
201 G4Region* region =
202 G4RegionStore::GetInstance()->GetRegion(materialName, false);
203
204 if (!region) {
205 region = new G4Region(materialName);
206
207 if (VerboseLevel() > 1) {
208 G4cout << "Created region " << region->GetName() << region << G4endl;
209 }
210 }
211
212 if (VerboseLevel() > 1) {
213 G4cout << "Adding region " << region->GetName() << " to lv "
214 << lv->GetName() << G4endl;
215 }
216 region->AddRootLogicalVolume(lv);
217 lv->SetRegion(region);
218 }
219 fCreateRegionsDone = true;
220#ifdef G4MULTITHREADED
221 lm.unlock();
222 }
223#endif
224}
225
226//_____________________________________________________________________________
227void TG4ModelConfigurationManager::SetModel(const G4String& modelName)
228{
230
231 if (VerboseLevel() > 1) {
232 G4cout << "TG4ModelConfigurationManager::SetModel: " << modelName << G4endl;
233 }
234
235 if (!GetModelConfiguration(modelName, false)) {
236 fVector.push_back(new TG4ModelConfiguration(modelName));
237 }
238 else {
239 TString text = "Cannot create model ";
240 text += modelName.data();
241 text += " twice.";
242 TG4Globals::Warning("TG4ModelConfigurationManager", "SetModel", text);
243 }
244}
245
246//_____________________________________________________________________________
248 const G4String& modelName, const G4String& particles)
249{
251
252 TG4ModelConfiguration* modelConfiguration =
253 GetModelConfiguration(modelName, "SetModelParticles");
254
255 if (!modelConfiguration) {
256 TString text = "The model configuration ";
257 text += modelName.data();
258 text += " is not defined.";
259 TG4Globals::Warning("TG4ModelConfigurationManager", "SetModelParticles",
260 text + TG4Globals::Endl() + TString("Setting will be ignored."));
261 return;
262 }
263
264 modelConfiguration->SetParticles(particles);
265}
266
267//_____________________________________________________________________________
269 const G4String& modelName, const G4String& regionsMedia)
270{
272
273 TG4ModelConfiguration* modelConfiguration =
274 GetModelConfiguration(modelName, "SetModelRegions");
275
276 if (!modelConfiguration) {
277 TString text = "The model configuration ";
278 text += modelName.data();
279 text += " is not defined.";
280 TG4Globals::Warning("TG4ModelConfigurationManager", "SetModelRegions",
281 text + TG4Globals::Endl() + TString("Setting will be ignored."));
282 return;
283 }
284
285 modelConfiguration->SetRegionsMedia(regionsMedia);
286}
287
288//_____________________________________________________________________________
290 const G4String& modelName, const G4String& regionMedium)
291{
293
294 TG4ModelConfiguration* modelConfiguration =
295 GetModelConfiguration(modelName, "SetModelRegions");
296
297 if (!modelConfiguration) {
298 TString text = "The model configuration ";
299 text += modelName.data();
300 text += " is not defined.";
301 TG4Globals::Warning("TG4ModelConfigurationManager", "SetModelRegions",
302 text + TG4Globals::Endl() + TString("Setting will be ignored."));
303 return;
304 }
305 modelConfiguration->SetOneRegionMedium(regionMedium);
306}
307
308//_____________________________________________________________________________
310 const G4String& modelName, G4bool warn) const
311{
314
315 ModelConfigurationVector::const_iterator it;
316 for (it = fVector.begin(); it != fVector.end(); it++) {
317 if ((*it)->GetModelName() == modelName) return *it;
318 }
319
320 if (warn) {
321 TString text = "Model configuration ";
322 text += modelName.data();
323 text += " does not exist";
325 "TG4ModelConfigurationManager", "GetModelConfiguration", text);
326 }
327
328 return 0;
329}
Definition of the TG4G3ControlVector class.
Definition of the TG4GeometryServices class.
Definition of the TG4Limits class.
Definition of the TG4MediumMap class.
Definition of the TG4Medium class.
Definition of the TG4ModelConfigurationManager class.
Definition of the TG4ModelConfigurationMessenger class.
Definition of the TG4ModelConfiguration class.
Definition of the TG4PhysicsManager class.
static TG4GeometryServices * Instance()
TG4MediumMap * GetMediumMap() const
static void Warning(const TString &className, const TString &methodName, const TString &text)
static TString Endl()
Definition TG4Globals.h:100
The map of media to logical volumes.
TG4Medium * GetMedium(G4int mediumID, G4bool warn=true) const
void GetMedia(const G4String &namePattern, std::vector< TG4Medium * > &media, G4bool warn=true) const
Helper class to keep medium data.
Definition TG4Medium.h:29
void SetModelRegions(const G4String &modelName, const G4String &regionsMedia)
void SetModel(const G4String &modelName)
TG4ModelConfiguration * GetModelConfiguration(const G4String &modelName, G4bool warn=true) const
G4bool fCreateRegionsDone
Info whether regions were constructed.
void SetModelParticles(const G4String &modelName, const G4String &particles)
TG4ModelConfigurationMessenger * fMessenger
Messenger.
void SetOneModelRegion(const G4String &modelName, const G4String &regionMedium)
TG4ModelConfigurationManager(const G4String &name, const G4String &availableModels="")
ModelConfigurationVector fVector
Vector of registered model configurations.
Messenger class that defines commands for the special physica models.
A helper class to hold a configuration of a special physics model.
void SetParticles(const G4String &particles)
void SetOneRegionMedium(const G4String &regionMedium)
void SetRegionsMedia(const G4String &regionsMedia)
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78