ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4FastSimulationPhysics.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4FastSimulationPhysics.cc
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 // ClassName: G4FastSimulationPhysics
30 //
31 // Author: M. Verderi (Nov.03.2016)
32 //
33 //----------------------------------------------------------------------------
34 //
35 //
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 
40 
41 #include "G4ParticleDefinition.hh"
42 #include "G4ProcessManager.hh"
43 
46 
47 // factory
49 //
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55  : G4VPhysicsConstructor(name),
56  fVerbose(false)
57 {;}
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {;}
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  fParticlesUnderFastSimulation.push_back(particleName);
69  fGeometries .push_back("");
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 void G4FastSimulationPhysics::ActivateFastSimulation(const G4String& particleName, const G4String& parallelGeometryName)
75 {
76  fParticlesUnderFastSimulation.push_back(particleName);
77  fGeometries .push_back(parallelGeometryName);
78 }
79 
80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81 
83 {;}
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
88 {
89 
90  auto myParticleIterator = GetParticleIterator();
91  myParticleIterator->reset();
92 
93  while ( (*myParticleIterator)() )
94  {
95  G4ParticleDefinition* particle = myParticleIterator->value();
96  G4String particleName = particle->GetParticleName();
97  G4ProcessManager* pmanager = particle->GetProcessManager();
98 
99  // -- include fast simulation manager process interface:
100  auto itr = std::find( fParticlesUnderFastSimulation.begin(),
102  particleName );
103 
104  if ( itr != fParticlesUnderFastSimulation.end() )
105  {
106  size_t ipos = itr - fParticlesUnderFastSimulation.begin();
107  G4String geometry = fGeometries[ipos];
108  if ( geometry == "" ) G4FastSimulationHelper::ActivateFastSimulation(pmanager);
109  else G4FastSimulationHelper::ActivateFastSimulation(pmanager, geometry);
110  }
111  }
112 
113  // -- tells what is done:
114  if ( fVerbose )
115  {
116  // -- print:
117  myParticleIterator->reset();
118 
119  while ( (*myParticleIterator)() )
120  {
121  G4ParticleDefinition* particle = myParticleIterator->value();
122  G4String particleName = particle->GetParticleName();
123  G4ProcessManager* pmanager = particle->GetProcessManager();
124 
125  G4bool isUnderFastSimulation(false);
126  G4String processAndGeometryNames;
127  G4int icount(0);
128 
129  G4ProcessVector* vprocess = pmanager->GetProcessList();
130  for (size_t ip = 0 ; ip < vprocess->size() ; ++ip)
131  {
132  G4VProcess* process = (*vprocess)[ip];
133  G4FastSimulationManagerProcess* pb = dynamic_cast< G4FastSimulationManagerProcess* >(process);
134  if ( pb != nullptr )
135  {
136  isUnderFastSimulation = true;
137  if ( icount < 3 )
138  {
139  processAndGeometryNames += pb->GetProcessName();
140  processAndGeometryNames += "[geom:";
141  processAndGeometryNames += pb->GetWorldVolume()->GetName();
142  processAndGeometryNames += "] ";
143  }
144  else
145  {
146  processAndGeometryNames += "\n ";
147  processAndGeometryNames += pb->GetProcessName();
148  processAndGeometryNames += "[geom:";
149  processAndGeometryNames += pb->GetWorldVolume()->GetName();
150  processAndGeometryNames += "] ";
151  icount = 0;
152  }
153  }
154  }
155  if ( isUnderFastSimulation ) G4cout << std::setw(14) << particleName << " : " << processAndGeometryNames << G4endl;
156  }
157  }
158 }