Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // Author: J. Apostolakis Nov 2022 27 28 #include "G4TransportationParameters.hh" 29 30 #include "G4ApplicationState.hh" 31 #include "G4StateManager.hh" 32 #include "G4Threading.hh" 33 #include "G4AutoLock.hh" 34 35 #include "G4SystemOfUnits.hh" 36 37 G4TransportationParameters* G4TransportationPa 38 39 #ifdef G4MULTITHREADED 40 namespace 41 { 42 G4Mutex transportParamsMutex = G4MUTEX_INIT 43 } 44 #endif 45 46 //-------------------------------------------- 47 48 G4TransportationParameters::G4TransportationPa 49 { 50 SetIntermediateLooperThresholds(); 51 } 52 53 //-------------------------------------------- 54 55 G4TransportationParameters* G4TransportationPa 56 { 57 if(theInstance == nullptr) { 58 G4MUTEXLOCK(&transportParamsMutex); 59 if(theInstance == nullptr) { 60 static G4TransportationParameters manage 61 theInstance = &manager; 62 } 63 G4MUTEXUNLOCK(&transportParamsMutex); 64 } 65 return theInstance; 66 } 67 68 //-------------------------------------------- 69 70 G4bool G4TransportationParameters::IsLocked() 71 { 72 auto stateManager = G4StateManager::GetState 73 74 auto state = stateManager->GetCurrentState() 75 bool goodState = state == G4State_PreInit 76 || state == G4State_Init 77 || state == G4State_Idle ; 78 return ( !G4Threading::IsMasterThread() || ! 79 } 80 81 //-------------------------------------------- 82 83 G4bool G4TransportationParameters::SetNumberO 84 { 85 if(IsLocked()) { ReportLockError(__func__); 86 fNumberOfTrials = val; 87 return true; 88 } 89 90 //-------------------------------------------- 91 92 G4bool G4TransportationParameters::SetWarning 93 { 94 if(IsLocked()) { ReportLockError(__func__); 95 fWarningEnergy = val; 96 97 // Consistency check -- and trial fix 98 if( fWarningEnergy > fImportantEnergy ) { 99 G4cerr << "G4TransportationParameters::G 100 << " resetting important energy 101 << " to " << val << G4endl; 102 // "Enforcing Important Energy >= Warnin 103 fImportantEnergy = fWarningEnergy; 104 } 105 return true; 106 } 107 108 //-------------------------------------------- 109 110 G4bool G4TransportationParameters::SetImporta 111 { 112 if(IsLocked()) { ReportLockError(__func__); 113 fImportantEnergy = val; 114 115 // Consistency check -- and trial fix 116 if( fImportantEnergy < fWarningEnergy ) { 117 G4String mthd= G4String("G4Transportatio 118 G4ExceptionDescription ed; 119 ed<<"enforcing hierarchy (warning-E <= i 120 <<" energy from " << fImportantEnergy 121 G4Exception( mthd, "Enforcing Warning En 122 JustWarning, ed ); 123 124 fWarningEnergy = fImportantEnergy; 125 } 126 return true; 127 } 128 129 //-------------------------------------------- 130 131 G4bool G4TransportationParameters::SetWarningA 132 133 { 134 if(IsLocked()) { 135 ReportLockError(__func__); 136 return false; 137 } 138 139 if( warnE <= importE ) 140 { 141 fWarningEnergy = warnE; 142 fImportantEnergy = importE; 143 } 144 else 145 { 146 fWarningEnergy = importE; 147 fImportantEnergy = warnE; 148 149 G4String mthd= G4String("G4Transportation 150 G4ExceptionDescription ed; 151 ed << "To enforce hierarchy (warning-E <= 152 << " using smaller value= " << import 153 << " and larger value= " << warnE << 154 G4Exception( mthd, "Enforcing Warning En 155 JustWarning, ed ); 156 } 157 return true; 158 } 159 160 //-------------------------------------------- 161 162 void G4TransportationParameters::ReportLockErr 163 { 164 // Report Incompatible States: GeomClosed , 165 G4String namesMethodClass= G4String("G4Trans 166 167 auto stateManager = G4StateManager::GetState 168 auto state = stateManager->GetCurrentStat 169 170 G4ExceptionDescription ed; 171 ed << "Cannot change values of G4Transportat 172 << stateManager->GetStateString(state) << 173 ed << "Only the following Geant4 state are c 174 if( verbose ) { 175 ed << G4endl << "Values remain as follows 176 StreamInfo( ed ); 177 } 178 G4Exception( namesMethodClass, 179 "Locked, due to incompatible G4 180 JustWarning, ed ); 181 } 182 183 //-------------------------------------------- 184 185 void G4TransportationParameters::StreamInfo(st 186 { 187 auto prec = os.precision(5); 188 189 os << "Transport Parameters: " << G4endl; 190 os << " Warning energy = " << GetWarning 191 os << " Important energy = " << GetImporta 192 os << " Number of trials = " << GetNumberO 193 os.precision(prec); 194 } 195 196 //-------------------------------------------- 197 198 void G4TransportationParameters::Dump() const 199 { 200 G4MUTEXLOCK(&transportParamsMutex); 201 StreamInfo(G4cout); 202 G4MUTEXUNLOCK(&transportParamsMutex); 203 } 204 205 //-------------------------------------------- 206 207 G4bool G4TransportationParameters::SetHighLoop 208 { 209 if(IsLocked()) { return false; } 210 211 // Restores the old high values -- potential 212 // HEP experiments. 213 // Caution: All tracks with E < 100 MeV tha 214 SetWarningEnergy( 100.0 * CLHEP::MeV ); / 215 SetImportantEnergy( 250.0 * CLHEP::MeV ); / 216 217 G4int maxTrials = 10; 218 SetNumberOfTrials( maxTrials ); 219 220 return true; 221 } 222 223 //-------------------------------------------- 224 225 G4bool G4TransportationParameters::SetIntermed 226 { 227 if(IsLocked()) { return false; } // Currentl 228 229 // Medium values -- reasonable default for a 230 fWarningEnergy= 1.0 * CLHEP::MeV; // War 231 fImportantEnergy= 10.0 * CLHEP::MeV; // Ext 232 fNumberOfTrials= 10; 233 return true; 234 } 235 236 //-------------------------------------------- 237 238 G4bool G4TransportationParameters::SetLowLoope 239 { 240 if(IsLocked()) { return false; } 241 242 // These values were the default in Geant4 1 243 SetWarningEnergy( 1.0 * CLHEP::keV ); // 244 SetImportantEnergy( 1.0 * CLHEP::MeV ); // 245 246 G4int maxTrials = 30; 247 SetNumberOfTrials( maxTrials ); 248 249 return true; 250 } 251 252 //-------------------------------------------- 253 254 G4bool G4TransportationParameters::EnableUseOf 255 { 256 if(IsLocked()) { return false; } 257 fUseMagneticMoment= useMoment; 258 return true; 259 } 260 261 //-------------------------------------------- 262 263 264 G4bool G4TransportationParameters::SetSilenceA 265 { 266 if(IsLocked()) { return false; } 267 fSilenceLooperWarnings= val; 268 return true; 269 } 270