Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4VModularPhysicsList implementation << 27 // 26 // 28 // Original author: H.Kurashige (Kobe Universi << 27 // $Id: G4VModularPhysicsList.cc,v 1.3 2006/06/29 21:14:00 gunter Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-08-01-patch-01 $ >> 29 // >> 30 // >> 31 // ------------------------------------------------------------ >> 32 // GEANT 4 class implementation file >> 33 // ------------------------------------------------------------ 30 34 31 #include "G4VModularPhysicsList.hh" 35 #include "G4VModularPhysicsList.hh" 32 36 33 #include "G4StateManager.hh" << 34 << 35 #include <algorithm> << 36 << 37 // This macros change the references to fields << 38 // in the class G4VMPLData. << 39 #define G4MT_physicsVector ((G4VMPLsubInstance << 40 << 41 G4VMPLManager G4VModularPhysicsList::G4VMPLsub << 42 << 43 // ------------------------------------------- << 44 void G4VMPLData::initialize() << 45 { << 46 physicsVector = new G4PhysConstVectorData(); << 47 } << 48 << 49 // ------------------------------------------- << 50 G4VModularPhysicsList::G4VModularPhysicsList() 37 G4VModularPhysicsList::G4VModularPhysicsList() >> 38 : G4VUserPhysicsList() 51 { 39 { 52 g4vmplInstanceID = G4VMPLsubInstanceManager. << 40 physicsVector = new G4PhysConstVector(); 53 } 41 } 54 42 55 // ------------------------------------------- << 56 G4VModularPhysicsList::~G4VModularPhysicsList( 43 G4VModularPhysicsList::~G4VModularPhysicsList() 57 { 44 { 58 if (G4MT_physicsVector != nullptr) { << 45 G4PhysConstVector::iterator itr; 59 for (auto& ptr : *G4MT_physicsVector) { << 46 for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) { 60 delete ptr; << 47 delete (*itr); 61 } << 62 delete G4MT_physicsVector; << 63 G4MT_physicsVector = nullptr; << 64 } << 65 } << 66 << 67 // ------------------------------------------- << 68 G4VModularPhysicsList::G4VModularPhysicsList(c << 69 : G4VUserPhysicsList(right) << 70 { << 71 g4vmplInstanceID = G4VMPLsubInstanceManager. << 72 G4MT_physicsVector = nullptr; << 73 } << 74 << 75 // ------------------------------------------- << 76 G4VModularPhysicsList& G4VModularPhysicsList:: << 77 { << 78 if (this != &right) { << 79 defaultCutValue = right.defaultCutValue; << 80 isSetDefaultCutValue = right.isSetDefaultC << 81 fRetrievePhysicsTable = right.fRetrievePhy << 82 fStoredInAscii = right.fStoredInAscii; << 83 fIsCheckedForRetrievePhysicsTable = right. << 84 fIsRestoredCutValues = right.fIsRestoredCu << 85 directoryPhysicsTable = right.directoryPhy << 86 (this->subInstanceManager.offset[this->g4v << 87 static_cast<const G4VUserPhysicsList&>(r << 88 .GetSubInstanceManager() << 89 .offset[right.GetInstanceID()] << 90 ._fDisplayThreshold; << 91 (this->subInstanceManager.offset[this->g4v << 92 static_cast<G4int>(static_cast<const G4V << 93 .GetSubInstanceMana << 94 .offset[right.GetIn << 95 ._fIsPhysicsTableBu << 96 fDisableCheckParticleList = right.fDisable << 97 verboseLevel = right.verboseLevel; << 98 << 99 if (G4MT_physicsVector != nullptr) { << 100 for (auto& ptr : *G4MT_physicsVector) { << 101 delete ptr; << 102 } << 103 delete G4MT_physicsVector; << 104 G4MT_physicsVector = nullptr; << 105 } << 106 g4vmplInstanceID = G4VMPLsubInstanceManage << 107 } 48 } 108 return *this; << 49 physicsVector->clear(); 109 } 50 } 110 51 111 // ------------------------------------------- << 112 void G4VModularPhysicsList::ConstructParticle( 52 void G4VModularPhysicsList::ConstructParticle() 113 { 53 { 114 // create particles 54 // create particles 115 for (auto itr = G4MT_physicsVector->cbegin() << 55 G4PhysConstVector::iterator itr; 116 (*itr)->ConstructParticle(); << 56 for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) { >> 57 (*itr)->ConstructParticle();; 117 } 58 } 118 } 59 } 119 60 120 // ------------------------------------------- << 121 // Andrea Dotti: May 6 2013 << 122 // Current limitation being debugged: Construc << 123 // needs to be sequential (there is at least o << 124 // problems). This is not yet understood and n << 125 // want this part to be sequential (imagine wh << 126 // TODO: Remove this lock << 127 #include "G4AutoLock.hh" << 128 namespace << 129 { << 130 G4Mutex constructProcessMutex = G4MUTEX_INITIA << 131 } << 132 61 133 // ------------------------------------------- << 134 void G4VModularPhysicsList::ConstructProcess() 62 void G4VModularPhysicsList::ConstructProcess() 135 { 63 { 136 G4AutoLock l(&constructProcessMutex); // Pr << 137 AddTransportation(); 64 AddTransportation(); 138 65 139 for (auto itr = G4MT_physicsVector->cbegin() << 66 G4PhysConstVector::iterator itr; >> 67 for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) { 140 (*itr)->ConstructProcess(); 68 (*itr)->ConstructProcess(); 141 } 69 } 142 } 70 } 143 71 144 // ------------------------------------------- << 145 void G4VModularPhysicsList::RegisterPhysics(G4 << 146 { << 147 G4StateManager* stateManager = G4StateManage << 148 G4ApplicationState currentState = stateManag << 149 if (!(currentState == G4State_PreInit)) { << 150 G4Exception("G4VModularPhysicsList::Regist << 151 "Geant4 kernel is not PreInit << 152 return; << 153 } << 154 << 155 G4String pName = fPhysics->GetPhysicsName(); << 156 G4int pType = fPhysics->GetPhysicsType(); << 157 // If physics_type is equal to 0, << 158 // following duplication check is omitted << 159 // This is TEMPORAL treatment. << 160 if (pType == 0) { << 161 G4MT_physicsVector->push_back(fPhysics); << 162 #ifdef G4VERBOSE << 163 if (verboseLevel > 1) { << 164 G4cout << "G4VModularPhysicsList::Regist << 165 << " is added" << G4endl; << 166 } << 167 #endif << 168 return; << 169 } << 170 << 171 // Check if physics with the physics_type sa << 172 auto itr = G4MT_physicsVector->cbegin(); << 173 for (; itr != G4MT_physicsVector->cend(); ++ << 174 if (pType == (*itr)->GetPhysicsType()) bre << 175 } << 176 if (itr != G4MT_physicsVector->cend()) { << 177 #ifdef G4VERBOSE << 178 if (verboseLevel > 0) { << 179 G4cout << "G4VModularPhysicsList::Regist << 180 << "a physics with given type alr << 181 G4cout << " Type = " << pType << " : " << 182 << " existing physics is " << (* << 183 G4cout << " New " << pName << " can not << 184 } << 185 #endif << 186 G4String comment = "Duplicate type for "; << 187 comment += pName; << 188 G4Exception("G4VModularPhysicsList::Regist << 189 return; << 190 } << 191 << 192 // register << 193 G4MT_physicsVector->push_back(fPhysics); << 194 } << 195 << 196 // ------------------------------------------- << 197 void G4VModularPhysicsList::ReplacePhysics(G4V << 198 { << 199 G4StateManager* stateManager = G4StateManage << 200 G4ApplicationState currentState = stateManag << 201 if (!(currentState == G4State_PreInit)) { << 202 G4Exception("G4VModularPhysicsList::Replac << 203 "Geant4 kernel is not PreInit << 204 return; << 205 } << 206 << 207 G4String pName = fPhysics->GetPhysicsName(); << 208 G4int pType = fPhysics->GetPhysicsType(); << 209 // If physics_type is equal to 0, << 210 // duplication check is omitted and just add << 211 // This is TEMPORAL treatment. << 212 if (pType == 0) { << 213 // register << 214 G4MT_physicsVector->push_back(fPhysics); << 215 #ifdef G4VERBOSE << 216 if (verboseLevel > 0) { << 217 G4cout << "G4VModularPhysicsList::Replac << 218 << " is added" << G4endl; << 219 } << 220 #endif << 221 return; << 222 } << 223 << 224 // Check if physics with the physics_type sa << 225 auto itr = G4MT_physicsVector->begin(); << 226 for (; itr != G4MT_physicsVector->end(); ++i << 227 if (pType == (*itr)->GetPhysicsType()) bre << 228 } << 229 if (itr == G4MT_physicsVector->end()) { << 230 // register << 231 G4MT_physicsVector->push_back(fPhysics); << 232 } << 233 else { << 234 #ifdef G4VERBOSE << 235 if (verboseLevel > 0) { << 236 G4cout << "G4VModularPhysicsList::Replac << 237 << " with type : " << pType << " << 238 } << 239 #endif << 240 << 241 // delete exsiting one << 242 delete (*itr); << 243 // replace with given one << 244 (*itr) = fPhysics; << 245 } << 246 return; << 247 } << 248 << 249 // ------------------------------------------- << 250 void G4VModularPhysicsList::RemovePhysics(G4in << 251 { << 252 G4StateManager* stateManager = G4StateManage << 253 G4ApplicationState currentState = stateManag << 254 if (!(currentState == G4State_PreInit)) { << 255 G4Exception("G4VModularPhysicsList::Remove << 256 "Geant4 kernel is not PreInit << 257 return; << 258 } << 259 << 260 for (auto itr = G4MT_physicsVector->cbegin() << 261 if (pType == (*itr)->GetPhysicsType()) { << 262 G4String pName = (*itr)->GetPhysicsName( << 263 #ifdef G4VERBOSE << 264 if (verboseLevel > 0) { << 265 G4cout << "G4VModularPhysicsList::Remo << 266 } << 267 #endif << 268 G4MT_physicsVector->erase(itr); << 269 break; << 270 } << 271 << 272 ++itr; << 273 } << 274 } << 275 << 276 // ------------------------------------------- << 277 void G4VModularPhysicsList::RemovePhysics(G4VP << 278 { << 279 G4StateManager* stateManager = G4StateManage << 280 G4ApplicationState currentState = stateManag << 281 if (!(currentState == G4State_PreInit)) { << 282 G4Exception("G4VModularPhysicsList::Remove << 283 "Geant4 kernel is not PreInit << 284 return; << 285 } << 286 << 287 for (auto itr = G4MT_physicsVector->cbegin() << 288 if (fPhysics == (*itr)) { << 289 G4String pName = (*itr)->GetPhysicsName( << 290 #ifdef G4VERBOSE << 291 if (verboseLevel > 0) { << 292 G4cout << "G4VModularPhysicsList::Remo << 293 } << 294 #endif << 295 G4MT_physicsVector->erase(itr); << 296 break; << 297 } << 298 << 299 ++itr; << 300 } << 301 } << 302 << 303 // ------------------------------------------- << 304 void G4VModularPhysicsList::RemovePhysics(cons << 305 { << 306 G4StateManager* stateManager = G4StateManage << 307 G4ApplicationState currentState = stateManag << 308 if (!(currentState == G4State_PreInit)) { << 309 G4Exception("G4VModularPhysicsList::Remove << 310 "Geant4 kernel is not PreInit << 311 return; << 312 } << 313 << 314 for (auto itr = G4MT_physicsVector->cbegin() << 315 G4String pName = (*itr)->GetPhysicsName(); << 316 if (name == pName) { << 317 #ifdef G4VERBOSE << 318 if (verboseLevel > 0) { << 319 G4cout << "G4VModularPhysicsList::Remo << 320 } << 321 #endif << 322 G4MT_physicsVector->erase(itr); << 323 break; << 324 } << 325 << 326 ++itr; << 327 } << 328 } << 329 << 330 // ------------------------------------------- << 331 const G4VPhysicsConstructor* G4VModularPhysics << 332 { << 333 auto itr = G4MT_physicsVector->cbegin(); << 334 for (G4int i = 0; i < idx && itr != G4MT_phy << 335 ++itr; << 336 if (itr != G4MT_physicsVector->cend()) retur << 337 return nullptr; << 338 } << 339 << 340 // ------------------------------------------- << 341 const G4VPhysicsConstructor* G4VModularPhysics << 342 { << 343 auto itr = G4MT_physicsVector->cbegin(); << 344 for (; itr != G4MT_physicsVector->cend(); ++ << 345 if (name == (*itr)->GetPhysicsName()) brea << 346 } << 347 if (itr != G4MT_physicsVector->cend()) retur << 348 return nullptr; << 349 } << 350 << 351 // ------------------------------------------- << 352 const G4VPhysicsConstructor* G4VModularPhysics << 353 { << 354 auto itr = G4MT_physicsVector->cbegin(); << 355 for (; itr != G4MT_physicsVector->cend(); ++ << 356 if (pType == (*itr)->GetPhysicsType()) bre << 357 } << 358 if (itr != G4MT_physicsVector->cend()) retur << 359 return nullptr; << 360 } << 361 << 362 // ------------------------------------------- << 363 void G4VModularPhysicsList::SetVerboseLevel(G4 << 364 { << 365 verboseLevel = value; << 366 // Loop over constructors << 367 for (auto itr = G4MT_physicsVector->cbegin() << 368 (*itr)->SetVerboseLevel(verboseLevel); << 369 } << 370 } << 371 << 372 // ------------------------------------------- << 373 void G4VModularPhysicsList::TerminateWorker() << 374 { << 375 // See https://jira-geant4.kek.jp/browse/DEV << 376 std::for_each(G4MT_physicsVector->cbegin(), << 377 [](G4PhysConstVector::value_ty << 378 G4VUserPhysicsList::TerminateWorker(); << 379 } << 380 72