Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4FastSimulationPhysics.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 // $Id$
27 //
28 //---------------------------------------------------------------------------
29 //
30 // ClassName: G4FastSimulationPhysics
31 //
32 // Author: M. Verderi (Nov.03.2016)
33 //
34 //----------------------------------------------------------------------------
35 //
36 //
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
41 
42 #include "G4ParticleDefinition.hh"
43 #include "G4ProcessManager.hh"
44 
47 
48 // factory
50 //
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56  : G4VPhysicsConstructor(name),
57  fVerbose(false)
58 {;}
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {;}
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  fParticlesUnderFastSimulation.push_back(particleName);
70  fGeometries .push_back("");
71 }
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
75 void G4FastSimulationPhysics::ActivateFastSimulation(const G4String& particleName, const G4String& parallelGeometryName)
76 {
77  fParticlesUnderFastSimulation.push_back(particleName);
78  fGeometries .push_back(parallelGeometryName);
79 }
80 
81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
82 
84 {;}
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 {
90 
91  auto myParticleIterator = GetParticleIterator();
92  myParticleIterator->reset();
93 
94  while ( (*myParticleIterator)() )
95  {
96  G4ParticleDefinition* particle = myParticleIterator->value();
97  G4String particleName = particle->GetParticleName();
98  G4ProcessManager* pmanager = particle->GetProcessManager();
99 
100  // -- include fast simulation manager process interface:
101  auto itr = std::find( fParticlesUnderFastSimulation.begin(),
102  fParticlesUnderFastSimulation.end(),
103  particleName );
104 
105  if ( itr != fParticlesUnderFastSimulation.end() )
106  {
107  size_t ipos = itr - fParticlesUnderFastSimulation.begin();
108  G4String geometry = fGeometries[ipos];
109  if ( geometry == "" ) G4FastSimulationHelper::ActivateFastSimulation(pmanager);
110  else G4FastSimulationHelper::ActivateFastSimulation(pmanager, geometry);
111  }
112  }
113 
114  // -- tells what is done:
115  if ( fVerbose )
116  {
117  // -- print:
118  myParticleIterator->reset();
119 
120  while ( (*myParticleIterator)() )
121  {
122  G4ParticleDefinition* particle = myParticleIterator->value();
123  G4String particleName = particle->GetParticleName();
124  G4ProcessManager* pmanager = particle->GetProcessManager();
125 
126  G4bool isUnderFastSimulation(false);
127  G4String processAndGeometryNames;
128  G4int icount(0);
129 
130  G4ProcessVector* vprocess = pmanager->GetProcessList();
131  for (G4int ip = 0 ; ip < vprocess->size() ; ip++)
132  {
133  G4VProcess* process = (*vprocess)[ip];
134  G4FastSimulationManagerProcess* pb = dynamic_cast< G4FastSimulationManagerProcess* >(process);
135  if ( pb != nullptr )
136  {
137  isUnderFastSimulation = true;
138  if ( icount < 3 )
139  {
140  processAndGeometryNames += pb->GetProcessName();
141  processAndGeometryNames += "[geom:";
142  processAndGeometryNames += pb->GetWorldVolume()->GetName();
143  processAndGeometryNames += "] ";
144  }
145  else
146  {
147  processAndGeometryNames += "\n ";
148  processAndGeometryNames += pb->GetProcessName();
149  processAndGeometryNames += "[geom:";
150  processAndGeometryNames += pb->GetWorldVolume()->GetName();
151  processAndGeometryNames += "] ";
152  icount = 0;
153  }
154  }
155  }
156  if ( isUnderFastSimulation ) G4cout << std::setw(14) << particleName << " : " << processAndGeometryNames << G4endl;
157  }
158  }
159 }
G4FastSimulationPhysics(const G4String &name="FastSimP")
const XML_Char * name
Definition: expat.h:151
void ActivateFastSimulation(const G4String &particleName)
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static void ActivateFastSimulation(G4ProcessManager *pmanager)
G4ParticleTable::G4PTblDicIterator * GetParticleIterator() const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
bool G4bool
Definition: G4Types.hh:79
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4int size() const
G4ProcessManager * GetProcessManager() const
#define G4endl
Definition: G4ios.hh:61
G4ProcessVector * GetProcessList() const
#define G4_DECLARE_PHYSCONSTR_FACTORY(physics_constructor)