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 | // $Id: G4GlobalFastSimulationManager.cc,v 1.20 2007/05/11 13:50:20 mverderi Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-02 $ |
---|
29 | // |
---|
30 | // |
---|
31 | //--------------------------------------------------------------- |
---|
32 | // |
---|
33 | // G4GlobalFastSimulationManager.cc |
---|
34 | // |
---|
35 | // Description: |
---|
36 | // A singleton class which manages the Fast Simulation managers |
---|
37 | // attached to envelopes. Implementation. |
---|
38 | // |
---|
39 | // History: |
---|
40 | // June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes |
---|
41 | // "G4FlavoredParallelWorld"; some method name changes; |
---|
42 | // GetFlavoredWorldForThis now returns a |
---|
43 | // G4FlavoredParallelWorld pointer. |
---|
44 | // Feb 98: Verderi && MoraDeFreitas - First Implementation. |
---|
45 | // March 98: correction to instanciate dynamically the manager |
---|
46 | // May 07: Move to parallel world scheme |
---|
47 | // |
---|
48 | //--------------------------------------------------------------- |
---|
49 | |
---|
50 | #include "G4GlobalFastSimulationManager.hh" |
---|
51 | #include "G4ParticleTable.hh" |
---|
52 | #include "G4ParticleDefinition.hh" |
---|
53 | #include "G4Material.hh" |
---|
54 | #include "G4ThreeVector.hh" |
---|
55 | #include "G4PVPlacement.hh" |
---|
56 | #include "G4TransportationManager.hh" |
---|
57 | #include "G4FastSimulationMessenger.hh" |
---|
58 | #include "G4RegionStore.hh" |
---|
59 | #include "G4ProcessVector.hh" |
---|
60 | #include "G4ProcessManager.hh" |
---|
61 | #include "G4PhysicalVolumeStore.hh" |
---|
62 | |
---|
63 | |
---|
64 | // ------------------------------------------ |
---|
65 | // -- static instance pointer initialisation: |
---|
66 | // ------------------------------------------ |
---|
67 | G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::fGlobalFastSimulationManager = 0; |
---|
68 | |
---|
69 | // -------------------------------------------------- |
---|
70 | // -- static methods to retrieve the manager pointer: |
---|
71 | // -------------------------------------------------- |
---|
72 | G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetGlobalFastSimulationManager() |
---|
73 | { |
---|
74 | if(!fGlobalFastSimulationManager) |
---|
75 | fGlobalFastSimulationManager = new G4GlobalFastSimulationManager; |
---|
76 | |
---|
77 | return fGlobalFastSimulationManager; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetInstance() |
---|
82 | { |
---|
83 | return G4GlobalFastSimulationManager::GetGlobalFastSimulationManager(); |
---|
84 | } |
---|
85 | |
---|
86 | // --------------- |
---|
87 | // -- constructor |
---|
88 | // --------------- |
---|
89 | G4GlobalFastSimulationManager::G4GlobalFastSimulationManager() |
---|
90 | { |
---|
91 | fTheFastSimulationMessenger = new G4FastSimulationMessenger(this); |
---|
92 | } |
---|
93 | |
---|
94 | // ------------- |
---|
95 | // -- destructor |
---|
96 | // ------------- |
---|
97 | G4GlobalFastSimulationManager::~G4GlobalFastSimulationManager() |
---|
98 | { |
---|
99 | delete fTheFastSimulationMessenger; |
---|
100 | fTheFastSimulationMessenger = 0; |
---|
101 | } |
---|
102 | |
---|
103 | // ---------------------- |
---|
104 | // -- management methods: |
---|
105 | // ---------------------- |
---|
106 | void G4GlobalFastSimulationManager:: |
---|
107 | AddFastSimulationManager(G4FastSimulationManager* fsmanager) |
---|
108 | { |
---|
109 | ManagedManagers.push_back(fsmanager); |
---|
110 | } |
---|
111 | |
---|
112 | void G4GlobalFastSimulationManager:: |
---|
113 | RemoveFastSimulationManager(G4FastSimulationManager* fsmanager) |
---|
114 | { |
---|
115 | ManagedManagers.remove(fsmanager); |
---|
116 | } |
---|
117 | |
---|
118 | void G4GlobalFastSimulationManager::AddFSMP(G4FastSimulationManagerProcess* fp) |
---|
119 | { |
---|
120 | fFSMPVector.push_back(fp); |
---|
121 | } |
---|
122 | |
---|
123 | void G4GlobalFastSimulationManager::RemoveFSMP(G4FastSimulationManagerProcess* fp) |
---|
124 | { |
---|
125 | fFSMPVector.remove(fp); |
---|
126 | } |
---|
127 | |
---|
128 | void G4GlobalFastSimulationManager::ActivateFastSimulationModel(const G4String& aName) |
---|
129 | { |
---|
130 | G4bool result = false; |
---|
131 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
132 | result = result || ManagedManagers[ifsm]-> |
---|
133 | ActivateFastSimulationModel(aName); |
---|
134 | if(result) |
---|
135 | G4cout << "Model " << aName << " activated."; |
---|
136 | else |
---|
137 | G4cout << "Model " << aName << " not found."; |
---|
138 | G4cout << G4endl; |
---|
139 | } |
---|
140 | |
---|
141 | void G4GlobalFastSimulationManager::InActivateFastSimulationModel(const G4String& aName) |
---|
142 | { |
---|
143 | G4bool result = false; |
---|
144 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
145 | result = result || ManagedManagers[ifsm]-> |
---|
146 | InActivateFastSimulationModel(aName); |
---|
147 | if(result) |
---|
148 | G4cout << "Model " << aName << " inactivated."; |
---|
149 | else |
---|
150 | G4cout << "Model " << aName << " not found."; |
---|
151 | G4cout << G4endl; |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | // --------------------------------- |
---|
156 | // -- display fast simulation setup: |
---|
157 | // --------------------------------- |
---|
158 | void G4GlobalFastSimulationManager::ShowSetup() |
---|
159 | { |
---|
160 | std::vector<G4VPhysicalVolume*> worldDone; |
---|
161 | G4VPhysicalVolume* world; |
---|
162 | G4RegionStore* regions = G4RegionStore::GetInstance(); |
---|
163 | // ---------------------------------------------------- |
---|
164 | // -- loop on regions to get the list of world volumes: |
---|
165 | // ---------------------------------------------------- |
---|
166 | G4cout << "\nFast simulation setup:" << G4endl; |
---|
167 | for (size_t i=0; i<regions->size(); i++) |
---|
168 | { |
---|
169 | world = (*regions)[i]->GetWorldPhysical(); |
---|
170 | G4bool newWorld = true; |
---|
171 | for (size_t ii=0; ii<worldDone.size(); ii++) if (worldDone[ii] == world) {newWorld = false; break;} |
---|
172 | if (newWorld) |
---|
173 | { |
---|
174 | worldDone.push_back(world); |
---|
175 | G4Region* worldRegion = world->GetLogicalVolume()->GetRegion(); |
---|
176 | // -- preambule: print physical volume and region names... |
---|
177 | if (world == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()) |
---|
178 | G4cout << "\n * Mass Geometry with "; |
---|
179 | else |
---|
180 | G4cout << "\n * Parallel Geometry with "; |
---|
181 | G4cout << "world volume: `" << world->GetName() << "' [region : `" << worldRegion->GetName() << "']" << G4endl; |
---|
182 | // -- ... and print G4FSMP(s) attached to this world volume: |
---|
183 | G4bool findG4FSMP(false); |
---|
184 | // -- show to what particles this G4FSMP is attached to: |
---|
185 | std::vector<G4ParticleDefinition*> particlesKnown; |
---|
186 | for (size_t ip=0; ip<fFSMPVector.size(); ip++) |
---|
187 | if (fFSMPVector[ip]->GetWorldVolume() == world) |
---|
188 | { |
---|
189 | G4cout << " o G4FastSimulationProcess: '" << fFSMPVector[ip]->GetProcessName() << "'" << G4endl; |
---|
190 | G4cout << " Attached to:"; |
---|
191 | G4ParticleTable* particles = G4ParticleTable::GetParticleTable(); |
---|
192 | for (G4int iParticle=0; iParticle<particles->entries(); iParticle++) |
---|
193 | { |
---|
194 | G4ParticleDefinition* particle = particles->GetParticle(iParticle); |
---|
195 | G4ProcessVector* processes = particle->GetProcessManager()->GetProcessList(); |
---|
196 | if (processes->contains(fFSMPVector[ip])) {G4cout << " " << particle->GetParticleName(); findG4FSMP = true; particlesKnown.push_back(particle);} |
---|
197 | } |
---|
198 | G4cout << G4endl; |
---|
199 | } |
---|
200 | if (!findG4FSMP) G4cout << " o G4FastSimulationProcess: (none)" << G4endl; |
---|
201 | // -- now display the regions in this world volume, with mother<->daughter link shown by indentation: |
---|
202 | G4cout << " o Region(s) and model(s) setup:" << G4endl; |
---|
203 | DisplayRegion(worldRegion, 1, particlesKnown); |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | void G4GlobalFastSimulationManager::DisplayRegion(G4Region* region, G4int depth, std::vector<G4ParticleDefinition*>& particlesKnown) const |
---|
210 | { |
---|
211 | G4String indent = " "; |
---|
212 | for (G4int I=0; I<depth; I++) indent += " "; |
---|
213 | G4cout << indent << "Region: `" << region->GetName() <<"'" << G4endl; |
---|
214 | G4FastSimulationManager* fastSimManager = region->GetFastSimulationManager(); |
---|
215 | if (fastSimManager) |
---|
216 | { |
---|
217 | indent += " "; |
---|
218 | G4cout << indent << "Model(s):" << G4endl; |
---|
219 | indent += " "; |
---|
220 | for (size_t im=0; im<fastSimManager->GetFastSimulationModelList().size(); im++) |
---|
221 | { |
---|
222 | G4cout << indent << "`" << (fastSimManager->GetFastSimulationModelList())[im]->GetName() << "'"; |
---|
223 | G4cout << " ; applicable to:"; |
---|
224 | G4ParticleTable* particles = G4ParticleTable::GetParticleTable(); |
---|
225 | for (G4int iParticle=0; iParticle<particles->entries(); iParticle++) |
---|
226 | { |
---|
227 | if ((fastSimManager->GetFastSimulationModelList())[im]->IsApplicable(*(particles->GetParticle(iParticle)))) |
---|
228 | { |
---|
229 | G4cout << " " << particles->GetParticle(iParticle)->GetParticleName(); |
---|
230 | G4bool known(false); |
---|
231 | for (size_t l=0; l<particlesKnown.size();l++) if(particlesKnown[l] == particles->GetParticle(iParticle)) {known = true; break;} |
---|
232 | if (!known) G4cout << "[!!]"; |
---|
233 | } |
---|
234 | } |
---|
235 | G4cout << G4endl; |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | // -- all that to check mothership of "region" |
---|
240 | G4PhysicalVolumeStore* physVolStore = G4PhysicalVolumeStore::GetInstance(); |
---|
241 | for (size_t ip=0; ip<physVolStore->size(); ip++) |
---|
242 | { |
---|
243 | G4VPhysicalVolume* physVol = (*physVolStore)[ip]; |
---|
244 | if (physVol->GetLogicalVolume()->IsRootRegion()) |
---|
245 | if (physVol->GetMotherLogical()) |
---|
246 | { |
---|
247 | G4Region* thisVolMotherRegion = physVol->GetMotherLogical()->GetRegion(); |
---|
248 | if (thisVolMotherRegion == region) |
---|
249 | DisplayRegion(physVol->GetLogicalVolume()->GetRegion(), depth+1, particlesKnown); |
---|
250 | } |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | // ---------------------------- |
---|
256 | // -- management methods : list |
---|
257 | // ---------------------------- |
---|
258 | |
---|
259 | void G4GlobalFastSimulationManager::ListEnvelopes(const G4String& aName, |
---|
260 | listType theType) |
---|
261 | { |
---|
262 | if (theType == ISAPPLICABLE) |
---|
263 | { |
---|
264 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
265 | ManagedManagers[ifsm]->ListModels(aName); |
---|
266 | return; |
---|
267 | } |
---|
268 | |
---|
269 | if(aName == "all") |
---|
270 | { |
---|
271 | G4int titled = 0; |
---|
272 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
273 | { |
---|
274 | if(theType == NAMES_ONLY) |
---|
275 | { |
---|
276 | if(!(titled++)) |
---|
277 | G4cout << "Current Envelopes for Fast Simulation:\n"; |
---|
278 | G4cout << " "; |
---|
279 | ManagedManagers[ifsm]->ListTitle(); |
---|
280 | G4cout << G4endl; |
---|
281 | } |
---|
282 | else ManagedManagers[ifsm]->ListModels(); |
---|
283 | } |
---|
284 | } |
---|
285 | else |
---|
286 | { |
---|
287 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
288 | if(aName == ManagedManagers[ifsm]-> GetEnvelope()->GetName()) |
---|
289 | { |
---|
290 | ManagedManagers[ifsm]->ListModels(); |
---|
291 | break; |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | void G4GlobalFastSimulationManager::ListEnvelopes(const G4ParticleDefinition* aPD) |
---|
297 | { |
---|
298 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
299 | ManagedManagers[ifsm]->ListModels(aPD); |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | G4VFastSimulationModel* G4GlobalFastSimulationManager::GetFastSimulationModel(const G4String& modelName, |
---|
304 | const G4VFastSimulationModel* previousFound) const |
---|
305 | { |
---|
306 | G4VFastSimulationModel* model = 0; |
---|
307 | // -- flag used to navigate accross the various managers; |
---|
308 | bool foundPrevious(false); |
---|
309 | for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) |
---|
310 | { |
---|
311 | model = ManagedManagers[ifsm]-> |
---|
312 | GetFastSimulationModel(modelName, previousFound, foundPrevious); |
---|
313 | if (model) break; |
---|
314 | } |
---|
315 | return model; |
---|
316 | } |
---|