Geant4  10.01.p01
G4GenericBiasingPhysics.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: G4GenericBiasingPhysics
31 //
32 // Author: M. Verderi (Sept.10.2013)
33 // Modified:
34 // 07/11/2014, M. Verderi : fix bug of PhysicsBias(...) which was not taking
35 // into account the vector of processes passed, but biasing all.
36 //
37 //----------------------------------------------------------------------------
38 //
39 //
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
44 
45 #include "G4ParticleDefinition.hh"
46 #include "G4ProcessManager.hh"
47 
48 #include "G4BiasingHelper.hh"
49 
50 // factory
52 //
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58  : G4VPhysicsConstructor(name)
59 {;}
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {;}
65 
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
70 {
71  fBiasedParticles.push_back(particleName);
72  std::vector< G4String > dummy;
73  fBiasedProcesses.push_back(dummy);
74  fBiasAllProcesses.push_back(true);
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
79 void G4GenericBiasingPhysics::PhysicsBias(const G4String& particleName, const std::vector< G4String >& processNames)
80 {
81  fBiasedParticles.push_back(particleName);
82  fBiasedProcesses.push_back(processNames);
83  fBiasAllProcesses.push_back(false);
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 {
90  fNonPhysBiasedParticles.push_back(particleName);
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94 
95 void G4GenericBiasingPhysics::Bias(const G4String& particleName)
96 {
97  PhysicsBias(particleName);
98  NonPhysicsBias(particleName);
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
103 void G4GenericBiasingPhysics::Bias(const G4String& particleName, const std::vector< G4String >& processNames)
104 {
105  PhysicsBias(particleName, processNames);
106  NonPhysicsBias(particleName);
107 }
108 
109 
110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
111 
113 {;}
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
118 {
119  aParticleIterator->reset();
120 
121  while( (*aParticleIterator)() )
122  {
123  G4ParticleDefinition* particle = aParticleIterator->value();
124  G4String particleName = particle->GetParticleName();
125  G4ProcessManager* pmanager = particle->GetProcessManager();
126 
127  // -- include non physics process interface for biasing:
128  if ( std::find(fNonPhysBiasedParticles.begin(),
130  particleName ) != fNonPhysBiasedParticles.end() )
131  {
133  }
134 
135  // -- wrap biased physics processes, all processes or only user selected:
136  std::vector< G4String >::const_iterator particleIt =
137  std::find(fBiasedParticles.begin(),
138  fBiasedParticles.end(),
139  particleName );
140  if ( particleIt == fBiasedParticles.end() ) continue;
141 
142  std::vector < G4String >& biasedProcesses = fBiasedProcesses [ particleIt - fBiasedParticles.begin() ];
143  G4bool biasAll = fBiasAllProcesses[ particleIt - fBiasedParticles.begin() ];
144 
145  if ( biasAll )
146  {
147  G4ProcessVector* vprocess = pmanager->GetProcessList();
148  for (G4int ip = 0 ; ip < vprocess->size() ; ip++)
149  {
150  G4VProcess* process = (*vprocess)[ip];
151  biasedProcesses.push_back( process->GetProcessName() );
152  }
153  }
154 
155  G4bool restartLoop(true);
156  while ( restartLoop )
157  {
158  for (std::size_t ip = 0 ; ip < biasedProcesses.size() ; ip++)
159  {
160  G4bool activ = G4BiasingHelper::ActivatePhysicsBiasing(pmanager, biasedProcesses[ip] );
161  restartLoop = activ;
162  if ( restartLoop ) break;
163  }
164  }
165 
166  }
167 }
168 
std::vector< std::vector< G4String > > fBiasedProcesses
G4String name
Definition: TRTMaterials.hh:40
void PhysicsBias(const G4String &particleName)
static void ActivateNonPhysicsBiasing(G4ProcessManager *pmanager, G4String nonPhysicsProcessName="")
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4GenericBiasingPhysics(const G4String &name="BiasingP")
bool G4bool
Definition: G4Types.hh:79
#define aParticleIterator
G4_DECLARE_PHYSCONSTR_FACTORY(G4GenericBiasingPhysics)
static G4bool ActivatePhysicsBiasing(G4ProcessManager *pmanager, G4String physicsProcessToBias, G4String wrappedName="")
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4int size() const
std::vector< G4String > fBiasedParticles
std::vector< G4String > fNonPhysBiasedParticles
std::vector< G4bool > fBiasAllProcesses
void NonPhysicsBias(const G4String &particleName)
G4ProcessVector * GetProcessList() const
void Bias(const G4String &particleName)