Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TransportationParameters.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// Author: J. Apostolakis Nov 2022
27
29
30#include "G4ApplicationState.hh"
31#include "G4StateManager.hh"
32#include "G4Threading.hh"
33#include "G4AutoLock.hh"
34
35#include "G4SystemOfUnits.hh"
36
37G4TransportationParameters* G4TransportationParameters::theInstance = nullptr;
38
39#ifdef G4MULTITHREADED
40namespace
41{
42 G4Mutex transportParamsMutex = G4MUTEX_INITIALIZER;
43}
44#endif
45
46//------------------------------------------------------------------------------
47
48G4TransportationParameters::G4TransportationParameters()
49{
51}
52
53//------------------------------------------------------------------------------
54
56{
57 if(theInstance == nullptr) {
58 G4MUTEXLOCK(&transportParamsMutex);
59 if(theInstance == nullptr) {
60 static G4TransportationParameters manager;
61 theInstance = &manager;
62 }
63 G4MUTEXUNLOCK(&transportParamsMutex);
64 }
65 return theInstance;
66}
67
68//------------------------------------------------------------------------------
69
70G4bool G4TransportationParameters::IsLocked() const
71{
72 auto fStateManager = G4StateManager::GetStateManager();
73
74 auto state = fStateManager->GetCurrentState();
75 bool goodState = state == G4State_PreInit
76 || state == G4State_Init
77 || state == G4State_Idle ;
78 return ( !G4Threading::IsMasterThread() || !goodState );
79}
80
81//------------------------------------------------------------------------------
82
84{
85 if(IsLocked()) { return false; }
86 fNumberOfTrials = val;
87 return true;
88}
89
90//------------------------------------------------------------------------------
91
93{
94 if(IsLocked()) { return false; }
95 fWarningEnergy = val;
96
97 // Consistency check -- and trial fix
98 if( fWarningEnergy > fImportantEnergy )
99 fImportantEnergy = fWarningEnergy;
100
101 return true;
102}
103
104//------------------------------------------------------------------------------
105
107{
108 if(IsLocked()) { return false; }
109 fImportantEnergy = val;
110
111 // Consistency check -- and trial fix
112 if( fImportantEnergy < fWarningEnergy )
113 fWarningEnergy = fImportantEnergy;
114
115 return true;
116}
117
118//------------------------------------------------------------------------------
119
120void G4TransportationParameters::StreamInfo(std::ostream& os) const
121{
122 auto prec = os.precision(5);
123
124 os << "Transport Parameters: " << G4endl;
125 os << " Warning energy = " << GetWarningEnergy() / CLHEP::MeV << " MeV " << G4endl;
126 os << " Important energy = " << GetImportantEnergy() / CLHEP::MeV << " MeV " << G4endl;
127 os << " Number of trials = " << GetNumberOfTrials() << G4endl;
128 os.precision(prec);
129}
130
131//------------------------------------------------------------------------------
132
134{
135 G4MUTEXLOCK(&transportParamsMutex);
137 G4MUTEXUNLOCK(&transportParamsMutex);
138}
139
140//------------------------------------------------------------------------------
141
143{
144 if(IsLocked()) { return false; }
145
146 // Restores the old high values -- potentially appropriate for energy-frontier
147 // HEP experiments.
148 // Caution: All tracks with E < 100 MeV that are found to loop are
149 SetWarningEnergy( 100.0 * CLHEP::MeV ); // Warn above this energy
150 SetImportantEnergy( 250.0 * CLHEP::MeV ); // Extra trial above this En
151
152 G4int maxTrials = 10;
153 SetNumberOfTrials( maxTrials );
154
155 return true;
156}
157
158//------------------------------------------------------------------------------
159
161{
162 if(IsLocked()) { return false; } // Currently must not change during loop - may relax
163
164 // Medium values -- reasonable default for an unknown application
165 fWarningEnergy= 1.0 * CLHEP::MeV; // Warn above this energy
166 fImportantEnergy= 10.0 * CLHEP::MeV; // Extra trial above this En
167 fNumberOfTrials= 10;
168 return true;
169}
170
171//------------------------------------------------------------------------------
172
174{
175 if(IsLocked()) { return false; }
176
177 // These values were the default in Geant4 10.5 - beta
178 SetWarningEnergy( 1.0 * CLHEP::keV ); // Warn above this En
179 SetImportantEnergy( 1.0 * CLHEP::MeV ); // Extra trials above it
180
181 G4int maxTrials = 30;
182 SetNumberOfTrials( maxTrials );
183
184 return true;
185}
186
187//------------------------------------------------------------------------------
188
190{
191 if(IsLocked()) { return false; }
192 fUseMagneticMoment= useMoment;
193 return true;
194}
195
196//------------------------------------------------------------------------------
197
198
200{
201 if(IsLocked()) { return false; }
202 fSilenceLooperWarnings= val;
203 return true;
204}
@ G4State_Init
@ G4State_Idle
@ G4State_PreInit
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
std::mutex G4Mutex
Definition: G4Threading.hh:81
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4StateManager * GetStateManager()
G4bool SetSilenceAllLooperWarnings(G4bool val=true)
static G4TransportationParameters * Instance()
G4bool EnableUseOfMagneticMoment(G4bool useMoment=true)
void StreamInfo(std::ostream &os) const
G4bool IsMasterThread()
Definition: G4Threading.cc:124