Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BiasingHelper.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#include "G4BiasingHelper.hh"
27
28#include "G4ProcessManager.hh"
31
33 G4String physicsProcessToBias,
34 G4String wrappedName)
35{
36 G4VProcess* physicsProcess(0);
37
38 G4ProcessVector* vprocess = pmanager->GetProcessList();
39 for (G4int ip = 0 ; ip < (G4int)vprocess->size() ; ++ip)
40 {
41 if ( (*vprocess)[ip]->GetProcessName() == physicsProcessToBias )
42 {
43 physicsProcess = (*vprocess)[ip];
44 break;
45 }
46 }
47
48 // -- process not found, return "false" to tell about failure
49 if ( physicsProcess == 0 ) return false;
50
51 // -- process is not a physics one, return "false" to tell about failure
52 G4int processType = physicsProcess->GetProcessType();
53 if ( ( processType != 2 ) && // EM
54 ( processType != 3 ) && // Optical
55 ( processType != 4 ) && // Hadronic
56 ( processType != 6 ) ) // Decay
57 return false;
58
59 // -- prevent wrapper of wrapper...
60 if ( dynamic_cast< G4BiasingProcessInterface* >( physicsProcess ) ) return false;
61
62 // -- remember process indeces:
63 G4int atRestIndex = pmanager->GetProcessOrdering(physicsProcess, idxAtRest );
64 G4int alongStepIndex = pmanager->GetProcessOrdering(physicsProcess, idxAlongStep);
65 G4int postStepIndex = pmanager->GetProcessOrdering(physicsProcess, idxPostStep );
66
67 // -- now remove the physic process, that will be replaced by a wrapped version:
68 G4VProcess* removed = pmanager->RemoveProcess(physicsProcess);
69 if ( removed != physicsProcess )
70 {
72 ed << "Internal inconsistency in processes handling. Please report !" << G4endl;
73 G4Exception("G4BiasingHelper::ActivatePhysicsBiasing(...)",
74 "BIAS.GEN.01",
76 ed);
77 }
78
79 G4BiasingProcessInterface* biasingWrapper = new G4BiasingProcessInterface( physicsProcess,
80 atRestIndex != ordInActive,
81 alongStepIndex != ordInActive,
82 postStepIndex != ordInActive,
83 wrappedName);
84
85 if ( alongStepIndex == -1 ) alongStepIndex = ordDefault;
86
87 pmanager->AddProcess( biasingWrapper,
88 atRestIndex,
89 alongStepIndex,
90 postStepIndex);
91
92 return true;
93}
94
96 G4String nonPhysicsProcessName )
97{
98 G4BiasingProcessInterface* biasingNonPhys(nullptr);
99 if ( nonPhysicsProcessName == "" ) biasingNonPhys = new G4BiasingProcessInterface();
100 else biasingNonPhys = new G4BiasingProcessInterface(nonPhysicsProcessName );
101 pmanager->AddProcess( biasingNonPhys,
104 ordDefault);
105}
106
108{
109 G4ParallelGeometriesLimiterProcess* toReturn = nullptr;
110
111 G4ProcessVector* processList = pmanager->GetProcessList();
112 G4bool noInstance = true;
113 for (G4int i = 0 ; i < (G4int)processList->size() ; ++i)
114 {
115 G4VProcess* process = (*processList)[i];
116 if ( dynamic_cast< G4ParallelGeometriesLimiterProcess* >( process ) )
117 {
118 noInstance = false;
119
121 ed << "Trying to re-add a G4ParallelGeometriesLimiterProcess process to the process manager for '"<<
122 pmanager->GetParticleType()->GetParticleName() << " (PDG : " << pmanager->GetParticleType()->GetPDGEncoding() << " )"
123 << " while one is already present." << G4endl;
124 G4Exception("G4BiasingHelper::AddBiasingProcessLimiter(G4ProcessManager* pmanager)",
125 "BIAS.GEN.28",
126 JustWarning, ed,
127 "Call ignored.");
128 break;
129 }
130 }
131
132 if ( noInstance )
133 {
135 pmanager->AddProcess ( biasingLimiter );
136 pmanager->SetProcessOrderingToSecond( biasingLimiter, idxAlongStep );
137 pmanager->SetProcessOrderingToLast ( biasingLimiter, idxPostStep );
138
139 toReturn = biasingLimiter;
140 }
141
142 return toReturn;
143}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
@ ordInActive
@ ordDefault
@ idxPostStep
@ idxAtRest
@ idxAlongStep
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
static void ActivateNonPhysicsBiasing(G4ProcessManager *pmanager, G4String nonPhysicsProcessName="")
static G4ParallelGeometriesLimiterProcess * AddLimiterProcess(G4ProcessManager *pmanager, const G4String &processName="biasLimiter")
static G4bool ActivatePhysicsBiasing(G4ProcessManager *pmanager, G4String physicsProcessToBias, G4String wrappedName="")
const G4String & GetParticleName() const
G4ParticleDefinition * GetParticleType() const
G4int GetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4ProcessVector * GetProcessList() const
G4VProcess * RemoveProcess(G4VProcess *aProcess)
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
void SetProcessOrderingToLast(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
std::size_t size() const
G4ProcessType GetProcessType() const
Definition: G4VProcess.hh:392