Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GlobalFastSimulationManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29//---------------------------------------------------------------
30//
31// G4GlobalFastSimulationManager.cc
32//
33// Description:
34// A singleton class which manages the Fast Simulation managers
35// attached to envelopes. Implementation.
36//
37// History:
38// June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes
39// "G4FlavoredParallelWorld"; some method name changes;
40// GetFlavoredWorldForThis now returns a
41// G4FlavoredParallelWorld pointer.
42// Feb 98: Verderi && MoraDeFreitas - First Implementation.
43// March 98: correction to instanciate dynamically the manager
44// May 07: Move to parallel world scheme
45//
46//---------------------------------------------------------------
47
49
51#include "G4Material.hh"
52#include "G4PVPlacement.hh"
54#include "G4ParticleTable.hh"
56#include "G4ProcessManager.hh"
57#include "G4ProcessVector.hh"
58#include "G4RegionStore.hh"
60#include "G4ThreeVector.hh"
62
63// --------------------------------------------------
64// -- static methods to retrieve the manager pointer:
65// --------------------------------------------------
71
76
77// ---------------
78// -- constructor
79// ---------------
80G4GlobalFastSimulationManager::G4GlobalFastSimulationManager()
81{
82 fTheFastSimulationMessenger = new G4FastSimulationMessenger(this);
83}
84
85// -------------
86// -- destructor
87// -------------
89{
90 delete fTheFastSimulationMessenger;
91}
92
93// ----------------------
94// -- management methods:
95// ----------------------
97{
98 ManagedManagers.push_back(fsmanager);
99}
100
102{
103 ManagedManagers.remove(fsmanager);
104}
105
107{
108 fFSMPVector.push_back(fp);
109}
110
115
117{
118 G4bool result = false;
119 for (auto& ManagedManager : ManagedManagers)
120 result = result || ManagedManager->ActivateFastSimulationModel(aName);
121
122 G4cout << "Model " << aName << (result ? " activated." : " not found.") << G4endl;
123}
124
126{
127 G4bool result = false;
128 for (auto& ManagedManager : ManagedManagers)
129 result = result || ManagedManager->InActivateFastSimulationModel(aName);
130
131 G4cout << "Model " << aName << (result ? " inactivated." : " not found.") << G4endl;
132}
133
135{
136 // loop over all models (that need flushing?) and flush
137 for (auto& ManagedManager : ManagedManagers)
138 ManagedManager->FlushModels();
139}
140
141// ---------------------------------
142// -- display fast simulation setup:
143// ---------------------------------
145{
146 std::vector<G4VPhysicalVolume*> worldDone;
147 G4VPhysicalVolume* world;
149 // ----------------------------------------------------
150 // -- loop on regions to get the list of world volumes:
151 // ----------------------------------------------------
152 G4cout << "\nFast simulation setup:" << G4endl;
153 for (auto& region : *regions) {
154 world = region->GetWorldPhysical();
155 if (world == nullptr) // region does not belong to any (existing) world
156 {
157 continue;
158 }
159 G4bool newWorld = true;
160 for (auto& ii : worldDone)
161 if (ii == world) {
162 newWorld = false;
163 break;
164 }
165 if (newWorld) {
166 worldDone.push_back(world);
167 G4Region* worldRegion = world->GetLogicalVolume()->GetRegion();
168 // -- preambule: print physical volume and region names...
169 if (world
171 ->GetNavigatorForTracking()
172 ->GetWorldVolume())
173 G4cout << "\n * Mass Geometry with ";
174 else
175 G4cout << "\n * Parallel Geometry with ";
176 G4cout << "world volume: `" << world->GetName() << "' [region : `" << worldRegion->GetName()
177 << "']" << G4endl;
178 // -- ... and print G4FSMP(s) attached to this world volume:
179 G4bool findG4FSMP(false);
180 // -- show to what particles this G4FSMP is attached to:
181 std::vector<G4ParticleDefinition*> particlesKnown;
182 for (auto& ip : fFSMPVector)
183 if (ip->GetWorldVolume() == world) {
184 G4cout << " o G4FastSimulationProcess: '" << ip->GetProcessName() << "'" << G4endl;
185 G4cout << " Attached to:";
187 for (G4int iParticle = 0; iParticle < particles->entries(); iParticle++) {
188 G4ParticleDefinition* particle = particles->GetParticle(iParticle);
189 G4ProcessVector* processes = particle->GetProcessManager()->GetProcessList();
190 if (processes->contains(ip)) {
191 G4cout << " " << particle->GetParticleName();
192 findG4FSMP = true;
193 particlesKnown.push_back(particle);
194 }
195 }
196 G4cout << G4endl;
197 }
198 if (!findG4FSMP) G4cout << " o G4FastSimulationProcess: (none)" << G4endl;
199 // -- now display the regions in this world volume, with mother<->daughter link shown by
200 // indentation:
201 G4cout << " o Region(s) and model(s) setup:" << G4endl;
202 DisplayRegion(worldRegion, 1, particlesKnown);
203 }
204 }
205}
206
207void G4GlobalFastSimulationManager::DisplayRegion(
208 G4Region* region, G4int depth, std::vector<G4ParticleDefinition*>& particlesKnown) const
209{
210 G4String indent = " ";
211 for (G4int I = 0; I < depth; I++)
212 indent += " ";
213 G4cout << indent << "Region: `" << region->GetName() << "'" << G4endl;
214 G4FastSimulationManager* fastSimManager = region->GetFastSimulationManager();
215 if (fastSimManager != nullptr) {
216 indent += " ";
217 G4cout << indent << "Model(s):" << G4endl;
218 indent += " ";
219 for (auto im : fastSimManager->GetFastSimulationModelList()) {
220 G4cout << indent << "`" << im->GetName() << "'";
221 G4cout << " ; applicable to:";
223 for (G4int iParticle = 0; iParticle < particles->entries(); iParticle++) {
224 if (im->IsApplicable(*(particles->GetParticle(iParticle)))) {
225 G4cout << " " << particles->GetParticle(iParticle)->GetParticleName();
226 G4bool known(false);
227 for (auto& l : particlesKnown)
228 if (l == particles->GetParticle(iParticle)) {
229 known = true;
230 break;
231 }
232 if (!known) G4cout << "[!!]";
233 }
234 }
235 G4cout << G4endl;
236 }
237 }
238
239 // -- all that to check mothership of "region"
241 for (auto physVol : *physVolStore) {
242 if (physVol->GetLogicalVolume()->IsRootRegion())
243 if (physVol->GetMotherLogical() != nullptr) {
244 G4Region* thisVolMotherRegion = physVol->GetMotherLogical()->GetRegion();
245 if (thisVolMotherRegion == region)
246 DisplayRegion(physVol->GetLogicalVolume()->GetRegion(), depth + 1, particlesKnown);
247 }
248 }
249}
250
251// ----------------------------
252// -- management methods : list
253// ----------------------------
254
256{
257 if (theType == ISAPPLICABLE) {
258 for (auto& ManagedManager : ManagedManagers)
259 ManagedManager->ListModels(aName);
260 return;
261 }
262
263 if (aName == "all") {
264 G4int titled = 0;
265 for (auto& ManagedManager : ManagedManagers) {
266 if (theType == NAMES_ONLY) {
267 if ((titled++) == 0) G4cout << "Current Envelopes for Fast Simulation:\n";
268 G4cout << " ";
269 ManagedManager->ListTitle();
270 G4cout << G4endl;
271 }
272 else
273 ManagedManager->ListModels();
274 }
275 }
276 else {
277 for (auto& ManagedManager : ManagedManagers)
278 if (aName == ManagedManager->GetEnvelope()->GetName()) {
279 ManagedManager->ListModels();
280 break;
281 }
282 }
283}
284
286{
287 for (auto& ManagedManager : ManagedManagers)
288 ManagedManager->ListModels(aPD);
289}
290
292 const G4String& modelName, const G4VFastSimulationModel* previousFound) const
293{
294 G4VFastSimulationModel* model = nullptr;
295 // -- flag used to navigate accross the various managers;
296 bool foundPrevious(false);
297 for (auto ManagedManager : ManagedManagers) {
298 model = ManagedManager->GetFastSimulationModel(modelName, previousFound, foundPrevious);
299 if (model != nullptr) break;
300 }
301 return model;
302}
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
const std::vector< G4VFastSimulationModel * > & GetFastSimulationModelList() const
T * remove(const T *)
void RemoveFSMP(G4FastSimulationManagerProcess *)
void ListEnvelopes(const G4String &aName="all", listType aListType=NAMES_ONLY)
G4VFastSimulationModel * GetFastSimulationModel(const G4String &modelName, const G4VFastSimulationModel *previousFound=nullptr) const
void AddFSMP(G4FastSimulationManagerProcess *)
void RemoveFastSimulationManager(G4FastSimulationManager *)
static G4GlobalFastSimulationManager * GetGlobalFastSimulationManager()
static G4GlobalFastSimulationManager * GetInstance()
void AddFastSimulationManager(G4FastSimulationManager *)
G4Region * GetRegion() const
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
G4ParticleDefinition * GetParticle(G4int index) const
G4int entries() const
static G4ParticleTable * GetParticleTable()
static G4PhysicalVolumeStore * GetInstance()
G4ProcessVector * GetProcessList() const
G4bool contains(G4VProcess *aProcess) const
static G4RegionStore * GetInstance()
G4FastSimulationManager * GetFastSimulationManager() const
Definition G4Region.cc:140
const G4String & GetName() const
static G4TransportationManager * GetTransportationManager()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const