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 // 26 // 27 // Author: Mathieu Karamitros (kara@cenbg.in2p 27 // Author: Mathieu Karamitros (kara@cenbg.in2p3.fr) 28 // 28 // 29 // WARNING : This class is released as a proto 29 // WARNING : This class is released as a prototype. 30 // It might strongly evolve or even disappear 30 // It might strongly evolve or even disappear in the next releases. 31 // 31 // 32 // History: 32 // History: 33 // ----------- 33 // ----------- 34 // 10 Oct 2011 M.Karamitros created 34 // 10 Oct 2011 M.Karamitros created 35 // 35 // 36 // ------------------------------------------- 36 // ------------------------------------------------------------------- 37 37 38 #include "G4DNAChemistryManager.hh" 38 #include "G4DNAChemistryManager.hh" 39 39 40 #include "G4AutoLock.hh" << 40 #include "G4Scheduler.hh" >> 41 #include "G4SystemOfUnits.hh" >> 42 #include "G4Molecule.hh" >> 43 #include "G4VITTrackHolder.hh" >> 44 #include "G4H2O.hh" 41 #include "G4DNAMolecularReactionTable.hh" 45 #include "G4DNAMolecularReactionTable.hh" 42 #include "G4DNAWaterExcitationStructure.hh" 46 #include "G4DNAWaterExcitationStructure.hh" 43 #include "G4DNAWaterIonisationStructure.hh" 47 #include "G4DNAWaterIonisationStructure.hh" 44 #include "G4Electron_aq.hh" 48 #include "G4Electron_aq.hh" 45 #include "G4GeometryManager.hh" << 46 #include "G4H2O.hh" << 47 #include "G4MolecularConfiguration.hh" 49 #include "G4MolecularConfiguration.hh" 48 #include "G4Molecule.hh" << 50 #include "G4VMoleculeCounter.hh" 49 #include "G4MoleculeFinder.hh" << 51 #include "G4VUserChemistryList.hh" 50 #include "G4MoleculeTable.hh" << 52 #include "G4AutoLock.hh" 51 #include "G4PhysChemIO.hh" << 52 #include "G4Scheduler.hh" << 53 #include "G4StateManager.hh" << 54 #include "G4SystemOfUnits.hh" << 55 #include "G4UIcmdWithABool.hh" 53 #include "G4UIcmdWithABool.hh" 56 #include "G4UIcmdWithADoubleAndUnit.hh" 54 #include "G4UIcmdWithADoubleAndUnit.hh" 57 #include "G4UIcmdWithAnInteger.hh" << 58 #include "G4UIcmdWithoutParameter.hh" 55 #include "G4UIcmdWithoutParameter.hh" 59 #include "G4VITTrackHolder.hh" << 56 #include "G4UIcmdWithAnInteger.hh" 60 #include "G4VMoleculeCounter.hh" << 57 #include "G4GeometryManager.hh" 61 #include "G4VUserChemistryList.hh" << 58 #include "G4StateManager.hh" 62 #include "G4VUserPulseInfo.hh" << 59 #include "G4MoleculeFinder.hh" >> 60 #include "G4MoleculeTable.hh" >> 61 #include "G4PhysChemIO.hh" 63 62 64 #include <memory> << 65 63 66 G4DNAChemistryManager* G4DNAChemistryManager:: 64 G4DNAChemistryManager* G4DNAChemistryManager::fgInstance = nullptr; 67 65 68 G4ThreadLocal G4DNAChemistryManager::ThreadLoc 66 G4ThreadLocal G4DNAChemistryManager::ThreadLocalData* 69 G4DNAChemistryManager::fpThreadData = null 67 G4DNAChemistryManager::fpThreadData = nullptr; 70 68 71 G4Mutex chemManExistence; 69 G4Mutex chemManExistence; 72 70 73 //-------------------------------------------- 71 //------------------------------------------------------------------------------ 74 72 75 G4DNAChemistryManager::ThreadLocalData::Thread 73 G4DNAChemistryManager::ThreadLocalData::ThreadLocalData() 76 { 74 { 77 fpPhysChemIO = nullptr; 75 fpPhysChemIO = nullptr; 78 fThreadInitialized = false; 76 fThreadInitialized = false; 79 } 77 } 80 78 81 //-------------------------------------------- 79 //------------------------------------------------------------------------------ 82 80 83 G4DNAChemistryManager::ThreadLocalData::~Threa 81 G4DNAChemistryManager::ThreadLocalData::~ThreadLocalData() 84 { 82 { 85 fpThreadData = nullptr; 83 fpThreadData = nullptr; 86 } 84 } 87 85 88 //-------------------------------------------- 86 //------------------------------------------------------------------------------ 89 87 90 void G4DNAChemistryManager::SetPhysChemIO(std: 88 void G4DNAChemistryManager::SetPhysChemIO(std::unique_ptr<G4VPhysChemIO> pPhysChemIO) 91 { 89 { 92 fpThreadData->fpPhysChemIO = std::move(pPh 90 fpThreadData->fpPhysChemIO = std::move(pPhysChemIO); 93 } 91 } 94 92 95 //-------------------------------------------- 93 //------------------------------------------------------------------------------ 96 94 97 //-------------------------------------------- 95 //------------------------------------------------------------------------------ 98 /* 96 /* 99 * The chemistry manager is shared between thr 97 * The chemistry manager is shared between threads 100 * It is initialized both on the master thread 98 * It is initialized both on the master thread and on the worker threads 101 */ 99 */ 102 //-------------------------------------------- 100 //------------------------------------------------------------------------------ 103 G4DNAChemistryManager::G4DNAChemistryManager() 101 G4DNAChemistryManager::G4DNAChemistryManager() 104 : << 102 : G4UImessenger() 105 fpChemDNADirectory(new G4UIdirectory( << 103 , G4VStateDependent() >> 104 , fpChemDNADirectory(new G4UIdirectory("/chem/")) 106 , fpActivateChem(new G4UIcmdWithABool( 105 , fpActivateChem(new G4UIcmdWithABool("/chem/activate", this)) 107 , fpRunChem(new G4UIcmdWithAnInteger(" 106 , fpRunChem(new G4UIcmdWithAnInteger("/chem/run", this)) 108 , fpSkipReactionsFromChemList(new G4UI 107 , fpSkipReactionsFromChemList(new G4UIcmdWithoutParameter("/chem/skipReactionsFromChemList", this)) 109 , fpScaleForNewTemperature(new G4UIcmd 108 , fpScaleForNewTemperature(new G4UIcmdWithADoubleAndUnit("/chem/temperature", this)) 110 , fpInitChem(new G4UIcmdWithoutParamet 109 , fpInitChem(new G4UIcmdWithoutParameter("/chem/init", this)) 111 , << 110 , fActiveChemistry(false) 112 fpExcitationLevel(nullptr) << 111 , fMasterInitialized(false) >> 112 , fForceThreadReinitialization(false) >> 113 , fpExcitationLevel(nullptr) 113 , fpIonisationLevel(nullptr) 114 , fpIonisationLevel(nullptr) 114 , fpUserChemistryList(nullptr) 115 , fpUserChemistryList(nullptr) >> 116 , fOwnChemistryList(false) >> 117 , fUseInStandalone(false) >> 118 , fPhysicsTableBuilt(false) >> 119 , fSkipReactions(false) >> 120 , fGeometryClosed(false) >> 121 , fVerbose(0) >> 122 , fResetCounterWhenRunEnds(true) 115 { 123 { 116 fpRunChem->SetParameterName("Number of run 124 fpRunChem->SetParameterName("Number of runs to execute for the chemistry module" 117 "(this works w 125 "(this works when used in standalone", true, true); 118 fpRunChem->SetDefaultValue(1); 126 fpRunChem->SetDefaultValue(1); 119 fpScaleForNewTemperature->SetUnitCategory( 127 fpScaleForNewTemperature->SetUnitCategory("Temperature"); 120 } 128 } 121 129 122 //-------------------------------------------- 130 //------------------------------------------------------------------------------ 123 131 124 G4DNAChemistryManager* G4DNAChemistryManager:: 132 G4DNAChemistryManager* G4DNAChemistryManager::Instance() 125 { 133 { 126 if (fgInstance == nullptr) 134 if (fgInstance == nullptr) 127 { 135 { 128 G4AutoLock lock(&chemManExistence); 136 G4AutoLock lock(&chemManExistence); 129 if (fgInstance == nullptr) // MT : dou 137 if (fgInstance == nullptr) // MT : double check at initialisation 130 { 138 { 131 fgInstance = new G4DNAChemistryMan 139 fgInstance = new G4DNAChemistryManager(); 132 } 140 } 133 lock.unlock(); 141 lock.unlock(); 134 } 142 } 135 143 136 // make sure thread local data is initiali 144 // make sure thread local data is initialized for all threads 137 if (fpThreadData == nullptr) 145 if (fpThreadData == nullptr) 138 { 146 { 139 fpThreadData = new ThreadLocalData(); 147 fpThreadData = new ThreadLocalData(); 140 } 148 } 141 149 142 assert(fpThreadData != nullptr); 150 assert(fpThreadData != nullptr); 143 151 144 return fgInstance; 152 return fgInstance; 145 } 153 } 146 154 147 //-------------------------------------------- 155 //------------------------------------------------------------------------------ 148 156 149 G4DNAChemistryManager* G4DNAChemistryManager:: 157 G4DNAChemistryManager* G4DNAChemistryManager::GetInstanceIfExists() 150 { 158 { 151 return fgInstance; 159 return fgInstance; 152 } 160 } 153 161 154 //-------------------------------------------- 162 //------------------------------------------------------------------------------ 155 163 156 G4DNAChemistryManager::~G4DNAChemistryManager( 164 G4DNAChemistryManager::~G4DNAChemistryManager() 157 { 165 { 158 Clear(); 166 Clear(); 159 fgInstance = nullptr; 167 fgInstance = nullptr; 160 } 168 } 161 169 162 //-------------------------------------------- 170 //------------------------------------------------------------------------------ 163 171 164 void G4DNAChemistryManager::Clear() 172 void G4DNAChemistryManager::Clear() 165 { 173 { 166 fpIonisationLevel.reset(); 174 fpIonisationLevel.reset(); 167 fpExcitationLevel.reset(); 175 fpExcitationLevel.reset(); 168 176 169 if (fpUserChemistryList) 177 if (fpUserChemistryList) 170 { 178 { 171 Deregister(*fpUserChemistryList); 179 Deregister(*fpUserChemistryList); 172 } 180 } 173 181 174 fpChemDNADirectory.reset(); 182 fpChemDNADirectory.reset(); 175 fpActivateChem.reset(); 183 fpActivateChem.reset(); 176 fpRunChem.reset(); 184 fpRunChem.reset(); 177 185 178 fpSkipReactionsFromChemList.reset(); 186 fpSkipReactionsFromChemList.reset(); 179 fpInitChem.reset(); 187 fpInitChem.reset(); 180 188 181 if (fpThreadData != nullptr) 189 if (fpThreadData != nullptr) 182 { 190 { 183 delete fpThreadData; 191 delete fpThreadData; 184 fpThreadData = nullptr; 192 fpThreadData = nullptr; 185 } 193 } 186 194 187 G4DNAMolecularReactionTable::DeleteInstanc 195 G4DNAMolecularReactionTable::DeleteInstance(); 188 G4MolecularConfiguration::DeleteManager(); 196 G4MolecularConfiguration::DeleteManager(); 189 G4VMoleculeCounter::DeleteInstance(); 197 G4VMoleculeCounter::DeleteInstance(); 190 } 198 } 191 199 192 //-------------------------------------------- 200 //------------------------------------------------------------------------------ 193 201 194 void G4DNAChemistryManager::DeleteInstance() 202 void G4DNAChemistryManager::DeleteInstance() 195 { 203 { 196 G4AutoLock lock(&chemManExistence); 204 G4AutoLock lock(&chemManExistence); 197 205 198 if (fgInstance != nullptr) 206 if (fgInstance != nullptr) 199 { 207 { 200 G4DNAChemistryManager* pDeleteMe = fgI 208 G4DNAChemistryManager* pDeleteMe = fgInstance; 201 fgInstance = nullptr; 209 fgInstance = nullptr; 202 lock.unlock(); 210 lock.unlock(); 203 delete pDeleteMe; 211 delete pDeleteMe; 204 } 212 } 205 else 213 else 206 { 214 { 207 G4cerr << "G4DNAChemistryManager alrea 215 G4cerr << "G4DNAChemistryManager already deleted" << G4endl; 208 } 216 } 209 lock.unlock(); 217 lock.unlock(); 210 } 218 } 211 219 212 //-------------------------------------------- 220 //------------------------------------------------------------------------------ 213 221 214 G4bool G4DNAChemistryManager::Notify(G4Applica 222 G4bool G4DNAChemistryManager::Notify(G4ApplicationState requestedState) 215 { 223 { 216 if (requestedState == G4State_Quit) 224 if (requestedState == G4State_Quit) 217 { 225 { 218 if (fVerbose != 0) << 226 if (fVerbose) 219 { 227 { 220 G4cout << "G4DNAChemistryManager:: 228 G4cout << "G4DNAChemistryManager::Notify ---> received G4State_Quit" 221 << G4endl; 229 << G4endl; 222 } 230 } 223 Clear(); 231 Clear(); 224 } 232 } 225 else if (requestedState == G4State_GeomClo 233 else if (requestedState == G4State_GeomClosed) 226 { 234 { 227 fGeometryClosed = true; 235 fGeometryClosed = true; 228 } 236 } 229 else if (requestedState == G4State_Idle) 237 else if (requestedState == G4State_Idle) 230 { 238 { 231 InitializeThreadSharedData(); 239 InitializeThreadSharedData(); 232 } 240 } 233 241 234 return true; 242 return true; 235 } 243 } 236 244 237 //-------------------------------------------- 245 //------------------------------------------------------------------------------ 238 246 239 void G4DNAChemistryManager::SetNewValue(G4UIco 247 void G4DNAChemistryManager::SetNewValue(G4UIcommand* pCommand, G4String value) 240 { 248 { 241 if (pCommand == fpActivateChem.get()) 249 if (pCommand == fpActivateChem.get()) 242 { 250 { 243 SetChemistryActivation(G4UIcmdWithABoo 251 SetChemistryActivation(G4UIcmdWithABool::GetNewBoolValue(value)); 244 } 252 } 245 else if (pCommand == fpRunChem.get()) 253 else if (pCommand == fpRunChem.get()) 246 { 254 { 247 int nbExec = value.empty() ? 1 : G4UIc 255 int nbExec = value.empty() ? 1 : G4UIcommand::ConvertToInt(value); 248 for (int i = 0 ; i < nbExec ; ++i) 256 for (int i = 0 ; i < nbExec ; ++i) 249 { 257 { 250 Run(); 258 Run(); 251 } 259 } 252 } 260 } 253 else if (pCommand == fpSkipReactionsFromCh 261 else if (pCommand == fpSkipReactionsFromChemList.get()) 254 { 262 { 255 fSkipReactions = true; 263 fSkipReactions = true; 256 } 264 } 257 else if (pCommand == fpScaleForNewTemperat 265 else if (pCommand == fpScaleForNewTemperature.get()) 258 { 266 { 259 SetGlobalTemperature(fpScaleForNewTemp 267 SetGlobalTemperature(fpScaleForNewTemperature->ConvertToDimensionedDouble(value)); 260 } 268 } 261 else if (pCommand == fpInitChem.get()) 269 else if (pCommand == fpInitChem.get()) 262 { 270 { 263 Initialize(); 271 Initialize(); 264 InitializeThread(); 272 InitializeThread(); 265 } 273 } 266 } 274 } 267 275 268 //-------------------------------------------- 276 //------------------------------------------------------------------------------ 269 277 270 G4String G4DNAChemistryManager::GetCurrentValu 278 G4String G4DNAChemistryManager::GetCurrentValue(G4UIcommand* pCommand) 271 { 279 { 272 if (pCommand == fpActivateChem.get()) 280 if (pCommand == fpActivateChem.get()) 273 { 281 { 274 return G4UIcmdWithABool::ConvertToStri 282 return G4UIcmdWithABool::ConvertToString(fActiveChemistry); 275 } 283 } 276 if (pCommand == fpScaleForNewTemperature.g << 284 else if (pCommand == fpScaleForNewTemperature.get()) 277 { 285 { 278 return fpScaleForNewTemperature->Conve 286 return fpScaleForNewTemperature->ConvertToStringWithBestUnit(G4MolecularConfiguration::GetGlobalTemperature()); 279 } 287 } 280 if (pCommand == fpSkipReactionsFromChemLis << 288 else if (pCommand == fpSkipReactionsFromChemList.get()) 281 { 289 { 282 return G4UIcmdWithABool::ConvertToStri 290 return G4UIcmdWithABool::ConvertToString(fSkipReactions); 283 } 291 } 284 292 285 return ""; 293 return ""; 286 } 294 } 287 295 288 //-------------------------------------------- 296 //------------------------------------------------------------------------------ 289 297 290 void G4DNAChemistryManager::InitializeThreadSh 298 void G4DNAChemistryManager::InitializeThreadSharedData() 291 { 299 { 292 if (!G4Threading::IsMasterThread()) 300 if (!G4Threading::IsMasterThread()) 293 { 301 { 294 return; 302 return; 295 } 303 } 296 304 297 G4MoleculeTable::Instance()->PrepareMolecu 305 G4MoleculeTable::Instance()->PrepareMolecularConfiguration(); 298 G4MoleculeTable::Instance()->Finalize(); 306 G4MoleculeTable::Instance()->Finalize(); 299 } 307 } 300 308 301 //-------------------------------------------- 309 //------------------------------------------------------------------------------ 302 void G4DNAChemistryManager::Run() 310 void G4DNAChemistryManager::Run() 303 { 311 { 304 if (!fActiveChemistry) 312 if (!fActiveChemistry) 305 { 313 { 306 return; 314 return; 307 } 315 } 308 316 309 InitializeThread(); 317 InitializeThread(); 310 318 311 if (!fMasterInitialized) 319 if (!fMasterInitialized) 312 { 320 { 313 G4ExceptionDescription description; 321 G4ExceptionDescription description; 314 description << "Global components were 322 description << "Global components were not initialized."; 315 G4Exception("G4DNAChemistryManager::Ru 323 G4Exception("G4DNAChemistryManager::Run", "MASTER_INIT", FatalException, 316 description); 324 description); 317 } 325 } 318 326 319 if (!fpThreadData->fThreadInitialized) 327 if (!fpThreadData->fThreadInitialized) 320 { 328 { 321 G4ExceptionDescription description; 329 G4ExceptionDescription description; 322 description << "Thread local component 330 description << "Thread local components were not initialized."; 323 G4Exception("G4DNAChemistryManager::Ru 331 G4Exception("G4DNAChemistryManager::Run", "THREAD_INIT", FatalException, 324 description); 332 description); 325 } 333 } 326 334 327 G4MoleculeTable::Instance()->Finalize(); 335 G4MoleculeTable::Instance()->Finalize(); 328 G4Scheduler::Instance()->Process(); 336 G4Scheduler::Instance()->Process(); 329 if (fResetCounterWhenRunEnds) 337 if (fResetCounterWhenRunEnds) 330 { 338 { 331 G4VMoleculeCounter::Instance()->ResetC 339 G4VMoleculeCounter::Instance()->ResetCounter(); 332 } 340 } 333 CloseFile(); 341 CloseFile(); 334 } 342 } 335 343 336 //-------------------------------------------- 344 //------------------------------------------------------------------------------ 337 345 338 void G4DNAChemistryManager::UseAsStandalone(G4 346 void G4DNAChemistryManager::UseAsStandalone(G4bool flag) 339 { 347 { 340 fUseInStandalone = flag; 348 fUseInStandalone = flag; 341 } 349 } 342 350 343 //-------------------------------------------- 351 //------------------------------------------------------------------------------ 344 352 345 void G4DNAChemistryManager::SetGun(G4ITGun* pC 353 void G4DNAChemistryManager::SetGun(G4ITGun* pChemGun) 346 { 354 { 347 G4Scheduler::Instance()->SetGun(pChemGun); 355 G4Scheduler::Instance()->SetGun(pChemGun); 348 } 356 } 349 357 350 //-------------------------------------------- 358 //------------------------------------------------------------------------------ 351 359 352 void G4DNAChemistryManager::Initialize() 360 void G4DNAChemistryManager::Initialize() 353 { 361 { 354 //======================================== 362 //=========================================================================== 355 // MT MODE 363 // MT MODE 356 //======================================== 364 //=========================================================================== 357 if (G4Threading::IsMultithreadedApplicatio 365 if (G4Threading::IsMultithreadedApplication()) 358 { 366 { 359 //==================================== 367 //========================================================================== 360 // ON WORKER THREAD 368 // ON WORKER THREAD 361 //==================================== 369 //========================================================================== 362 if (G4Threading::IsWorkerThread()) 370 if (G4Threading::IsWorkerThread()) 363 { 371 { 364 InitializeThread(); // Will create 372 InitializeThread(); // Will create and initialize G4Scheduler 365 return; 373 return; 366 } 374 } 367 //==================================== 375 //========================================================================== 368 // ON MASTER THREAD 376 // ON MASTER THREAD 369 //==================================== 377 //========================================================================== 370 << 378 else 371 InitializeMaster(); << 379 { 372 InitializeThreadSharedData(); << 380 InitializeMaster(); 373 return; << 381 InitializeThreadSharedData(); >> 382 return; >> 383 } 374 } 384 } 375 //======================================== 385 //=========================================================================== 376 // IS NOT IN MT MODE 386 // IS NOT IN MT MODE 377 //======================================== 387 //=========================================================================== 378 << 388 else 379 InitializeMaster(); << 389 { 380 InitializeThreadSharedData(); << 390 InitializeMaster(); 381 // In this case: InitializeThread is calle << 391 InitializeThreadSharedData(); 382 return; << 392 // In this case: InitializeThread is called when Run() is called >> 393 return; >> 394 } 383 } 395 } 384 396 385 //-------------------------------------------- 397 //------------------------------------------------------------------------------ 386 398 387 void G4DNAChemistryManager::InitializeMaster() 399 void G4DNAChemistryManager::InitializeMaster() 388 { 400 { 389 if (fMasterInitialized) 401 if (fMasterInitialized) 390 { 402 { 391 return; 403 return; 392 } 404 } 393 405 394 if (fVerbose != 0) << 406 if (fVerbose) 395 { 407 { 396 G4cout << "G4DNAChemistryManager::Init 408 G4cout << "G4DNAChemistryManager::InitializeMaster() is called" << G4endl; 397 } 409 } 398 410 399 411 400 if (fpUserChemistryList == nullptr) 412 if (fpUserChemistryList == nullptr) 401 { 413 { 402 G4ExceptionDescription description; 414 G4ExceptionDescription description; 403 description << "No user chemistry list 415 description << "No user chemistry list has been provided."; 404 G4Exception("G4DNAChemistryManager::In 416 G4Exception("G4DNAChemistryManager::InitializeMaster", "NO_CHEM_LIST", 405 FatalException, descriptio 417 FatalException, description); 406 }else 418 }else 407 { 419 { 408 fpUserChemistryList->ConstructDissociati 420 fpUserChemistryList->ConstructDissociationChannels(); 409 if (!fSkipReactions) 421 if (!fSkipReactions) 410 { 422 { 411 fpUserChemistryList->ConstructReacti 423 fpUserChemistryList->ConstructReactionTable(G4DNAMolecularReactionTable::GetReactionTable()); 412 } 424 } 413 else 425 else 414 { 426 { 415 G4DNAMolecularReactionTable::GetReac 427 G4DNAMolecularReactionTable::GetReactionTable(); // init pointer 416 } 428 } 417 } 429 } 418 430 419 G4Scheduler::Instance(); 431 G4Scheduler::Instance(); 420 // creates a concrete object of the schedu 432 // creates a concrete object of the scheduler 421 fMasterInitialized = true; 433 fMasterInitialized = true; 422 } 434 } 423 435 424 //-------------------------------------------- 436 //------------------------------------------------------------------------------ 425 437 426 void G4DNAChemistryManager::HandleStandaloneIn 438 void G4DNAChemistryManager::HandleStandaloneInitialization() 427 { 439 { 428 if (!fUseInStandalone || fPhysicsTableBuil 440 if (!fUseInStandalone || fPhysicsTableBuilt) 429 { 441 { 430 return; 442 return; 431 } 443 } 432 444 433 if (fVerbose != 0) << 445 if (fVerbose) 434 { 446 { 435 G4cout << "G4DNAChemistryManager: Buil 447 G4cout << "G4DNAChemistryManager: Build the physics tables for " 436 "molecule definition only." 448 "molecule definition only." 437 << G4endl; 449 << G4endl; 438 } 450 } 439 451 440 fpUserChemistryList->BuildPhysicsTable(); 452 fpUserChemistryList->BuildPhysicsTable(); 441 453 442 if (!fGeometryClosed) 454 if (!fGeometryClosed) 443 { 455 { 444 if (fVerbose != 0) << 456 if (fVerbose) 445 { 457 { 446 G4cout << "G4DNAChemistryManager: 458 G4cout << "G4DNAChemistryManager: Close geometry" << G4endl; 447 } 459 } 448 460 449 G4GeometryManager* pGeomManager = G4Ge 461 G4GeometryManager* pGeomManager = G4GeometryManager::GetInstance(); 450 pGeomManager->OpenGeometry(); 462 pGeomManager->OpenGeometry(); 451 pGeomManager->CloseGeometry(true, true 463 pGeomManager->CloseGeometry(true, true); 452 fGeometryClosed = true; 464 fGeometryClosed = true; 453 } 465 } 454 466 455 fPhysicsTableBuilt = true; 467 fPhysicsTableBuilt = true; 456 } 468 } 457 469 458 //-------------------------------------------- 470 //------------------------------------------------------------------------------ 459 471 460 void G4DNAChemistryManager::InitializeThread() 472 void G4DNAChemistryManager::InitializeThread() 461 { 473 { 462 if (fpThreadData->fThreadInitialized && !f 474 if (fpThreadData->fThreadInitialized && !fForceThreadReinitialization) 463 { 475 { 464 return; 476 return; 465 } 477 } 466 478 467 if (fpUserChemistryList == nullptr) 479 if (fpUserChemistryList == nullptr) 468 { 480 { 469 G4ExceptionDescription description; 481 G4ExceptionDescription description; 470 description << "No user chemistry list 482 description << "No user chemistry list has been provided."; 471 G4Exception("G4DNAChemistryManager::In 483 G4Exception("G4DNAChemistryManager::InitializeThread", "NO_CHEM_LIST", 472 FatalException, descriptio 484 FatalException, description); 473 }else 485 }else 474 { 486 { 475 HandleStandaloneInitialization();// To 487 HandleStandaloneInitialization();// To make coverty happy 476 fpUserChemistryList->ConstructTimeStep 488 fpUserChemistryList->ConstructTimeStepModel(G4DNAMolecularReactionTable::GetReactionTable()); 477 } 489 } 478 490 479 if (fVerbose != 0) << 491 if (fVerbose) 480 { 492 { 481 G4cout << "G4DNAChemistryManager::Init 493 G4cout << "G4DNAChemistryManager::InitializeThread() is called" 482 << G4endl; 494 << G4endl; 483 } 495 } 484 496 485 G4Scheduler::Instance()->Initialize(); 497 G4Scheduler::Instance()->Initialize(); 486 498 487 fpThreadData->fThreadInitialized = true; 499 fpThreadData->fThreadInitialized = true; 488 500 489 G4VMoleculeCounter::InitializeInstance(); 501 G4VMoleculeCounter::InitializeInstance(); 490 502 491 InitializeFile(); 503 InitializeFile(); 492 } 504 } 493 505 494 //-------------------------------------------- 506 //------------------------------------------------------------------------------ 495 507 496 void G4DNAChemistryManager::InitializeFile() 508 void G4DNAChemistryManager::InitializeFile() 497 { 509 { 498 if (fVerbose != 0) << 510 if (fVerbose) 499 { 511 { 500 G4cout << "G4DNAChemistryManager::Init 512 G4cout << "G4DNAChemistryManager::InitializeFile() is called" 501 << G4endl; 513 << G4endl; 502 } 514 } 503 515 504 if (fpThreadData->fpPhysChemIO) 516 if (fpThreadData->fpPhysChemIO) 505 { 517 { 506 fpThreadData->fpPhysChemIO->Initialize 518 fpThreadData->fpPhysChemIO->InitializeFile(); 507 } 519 } 508 } 520 } 509 521 510 //-------------------------------------------- 522 //------------------------------------------------------------------------------ 511 523 512 G4bool G4DNAChemistryManager::IsActivated() 524 G4bool G4DNAChemistryManager::IsActivated() 513 { 525 { 514 return fgInstance != nullptr ? fgInstance- << 526 return fgInstance ? fgInstance->IsChemistryActivated() : false; 515 } 527 } 516 528 517 //-------------------------------------------- 529 //------------------------------------------------------------------------------ 518 530 519 G4bool G4DNAChemistryManager::IsChemistryActiv 531 G4bool G4DNAChemistryManager::IsChemistryActivated() 520 { 532 { 521 return fActiveChemistry; 533 return fActiveChemistry; 522 } 534 } 523 535 524 //-------------------------------------------- 536 //------------------------------------------------------------------------------ 525 537 526 void G4DNAChemistryManager::SetChemistryActiva 538 void G4DNAChemistryManager::SetChemistryActivation(G4bool flag) 527 { 539 { 528 fActiveChemistry = flag; 540 fActiveChemistry = flag; 529 } 541 } 530 542 531 //-------------------------------------------- 543 //------------------------------------------------------------------------------ 532 544 533 void G4DNAChemistryManager::WriteInto(const G4 545 void G4DNAChemistryManager::WriteInto(const G4String& output, 534 std::ios 546 std::ios_base::openmode mode) 535 { 547 { 536 if (fVerbose != 0) << 548 if (fVerbose) 537 { 549 { 538 G4cout << "G4DNAChemistryManager: Writ 550 G4cout << "G4DNAChemistryManager: Write chemical stage into " 539 << output.data() << G4endl; 551 << output.data() << G4endl; 540 } 552 } 541 553 542 if (!fpThreadData->fpPhysChemIO) 554 if (!fpThreadData->fpPhysChemIO) 543 { 555 { 544 fpThreadData->fpPhysChemIO = std::make << 556 fpThreadData->fpPhysChemIO.reset(new G4PhysChemIO::FormattedText()); 545 } 557 } 546 558 547 fpThreadData->fpPhysChemIO->WriteInto(outp 559 fpThreadData->fpPhysChemIO->WriteInto(output, mode); 548 560 549 } 561 } 550 562 551 //-------------------------------------------- 563 //------------------------------------------------------------------------------ 552 564 553 void G4DNAChemistryManager::AddEmptyLineInOutp 565 void G4DNAChemistryManager::AddEmptyLineInOutputFile() 554 { 566 { 555 if (fpThreadData->fpPhysChemIO) 567 if (fpThreadData->fpPhysChemIO) 556 { 568 { 557 fpThreadData->fpPhysChemIO->AddEmptyLi 569 fpThreadData->fpPhysChemIO->AddEmptyLineInOutputFile(); 558 } 570 } 559 } 571 } 560 572 561 //-------------------------------------------- 573 //------------------------------------------------------------------------------ 562 574 563 void G4DNAChemistryManager::CloseFile() 575 void G4DNAChemistryManager::CloseFile() 564 { 576 { 565 if (fpThreadData->fpPhysChemIO) 577 if (fpThreadData->fpPhysChemIO) 566 { 578 { 567 fpThreadData->fpPhysChemIO->CloseFile( 579 fpThreadData->fpPhysChemIO->CloseFile(); 568 } 580 } 569 } 581 } 570 582 571 //-------------------------------------------- 583 //------------------------------------------------------------------------------ 572 584 573 G4DNAWaterExcitationStructure* G4DNAChemistryM 585 G4DNAWaterExcitationStructure* G4DNAChemistryManager::GetExcitationLevel() 574 { 586 { 575 if (!fpExcitationLevel) 587 if (!fpExcitationLevel) 576 { 588 { 577 fpExcitationLevel = std::make_unique<G << 589 fpExcitationLevel.reset(new G4DNAWaterExcitationStructure); 578 } 590 } 579 return fpExcitationLevel.get(); 591 return fpExcitationLevel.get(); 580 } 592 } 581 593 582 //-------------------------------------------- 594 //------------------------------------------------------------------------------ 583 595 584 G4DNAWaterIonisationStructure* G4DNAChemistryM 596 G4DNAWaterIonisationStructure* G4DNAChemistryManager::GetIonisationLevel() 585 { 597 { 586 if (!fpIonisationLevel) 598 if (!fpIonisationLevel) 587 { 599 { 588 fpIonisationLevel = std::make_unique<G << 600 fpIonisationLevel.reset(new G4DNAWaterIonisationStructure); 589 } 601 } 590 return fpIonisationLevel.get(); 602 return fpIonisationLevel.get(); 591 } 603 } 592 604 593 //-------------------------------------------- 605 //------------------------------------------------------------------------------ 594 606 595 void G4DNAChemistryManager::CreateWaterMolecul 607 void G4DNAChemistryManager::CreateWaterMolecule(ElectronicModification modification, 596 608 G4int electronicLevel, 597 609 const G4Track* pIncomingTrack) 598 { 610 { 599 if (fpThreadData->fpPhysChemIO) 611 if (fpThreadData->fpPhysChemIO) 600 { 612 { 601 G4double energy = -1.; 613 G4double energy = -1.; 602 614 603 switch (modification) 615 switch (modification) 604 { 616 { 605 case eDissociativeAttachment: 617 case eDissociativeAttachment: 606 energy = 0.; 618 energy = 0.; 607 break; 619 break; 608 case eExcitedMolecule: 620 case eExcitedMolecule: 609 energy = GetExcitationLevel()->Exc 621 energy = GetExcitationLevel()->ExcitationEnergy(electronicLevel); 610 break; 622 break; 611 case eIonizedMolecule: 623 case eIonizedMolecule: 612 energy = GetIonisationLevel()->Ion 624 energy = GetIonisationLevel()->IonisationEnergy(electronicLevel); 613 break; 625 break; 614 } 626 } 615 627 616 fpThreadData->fpPhysChemIO->CreateWate 628 fpThreadData->fpPhysChemIO->CreateWaterMolecule(modification, 617 629 4 - electronicLevel, 618 630 energy, 619 631 pIncomingTrack); 620 } 632 } 621 633 622 if (fActiveChemistry) 634 if (fActiveChemistry) 623 { 635 { 624 auto pH2OMolecule = new G4Molecule(G4 << 636 G4Molecule* pH2OMolecule = new G4Molecule(G4H2O::Definition()); 625 637 626 switch (modification) 638 switch (modification) 627 { 639 { 628 case eDissociativeAttachment: 640 case eDissociativeAttachment: 629 pH2OMolecule->AddElectron(5, 1); 641 pH2OMolecule->AddElectron(5, 1); 630 break; 642 break; 631 case eExcitedMolecule: 643 case eExcitedMolecule: 632 pH2OMolecule->ExciteMolecule(4 - e 644 pH2OMolecule->ExciteMolecule(4 - electronicLevel); 633 break; 645 break; 634 case eIonizedMolecule: 646 case eIonizedMolecule: 635 pH2OMolecule->IonizeMolecule(4 - e 647 pH2OMolecule->IonizeMolecule(4 - electronicLevel); 636 break; 648 break; 637 } 649 } 638 650 639 G4double delayedTime = 0.; << 651 G4Track* pH2OTrack = pH2OMolecule->BuildTrack(picosecond, 640 if(pIncomingTrack->GetUserInformation( << 641 { << 642 auto pPulseInfo = dynamic_cast<G4V << 643 (pIncomingTrack->GetUserInformat << 644 if(pPulseInfo != nullptr) << 645 { << 646 delayedTime = pPulseInfo->GetD << 647 } << 648 } << 649 << 650 G4Track* pH2OTrack = pH2OMolecule->Bui << 651 652 pIncomingTrack->GetPosition()); 652 653 653 pH2OTrack->SetParentID(pIncomingTrack- 654 pH2OTrack->SetParentID(pIncomingTrack->GetTrackID()); 654 pH2OTrack->SetTrackStatus(fStopButAliv 655 pH2OTrack->SetTrackStatus(fStopButAlive); 655 pH2OTrack->SetKineticEnergy(0.); 656 pH2OTrack->SetKineticEnergy(0.); 656 PushTrack(pH2OTrack); 657 PushTrack(pH2OTrack); 657 } 658 } 658 } 659 } 659 660 660 //-------------------------------------------- 661 //------------------------------------------------------------------------------ 661 // pFinalPosition is optional 662 // pFinalPosition is optional 662 void G4DNAChemistryManager::CreateSolvatedElec 663 void G4DNAChemistryManager::CreateSolvatedElectron(const G4Track* pIncomingTrack, 663 664 G4ThreeVector* pFinalPosition) 664 { 665 { 665 if (fpThreadData->fpPhysChemIO) 666 if (fpThreadData->fpPhysChemIO) 666 { 667 { 667 fpThreadData->fpPhysChemIO->CreateSolv 668 fpThreadData->fpPhysChemIO->CreateSolvatedElectron(pIncomingTrack, 668 669 pFinalPosition); 669 } 670 } 670 671 671 if (fActiveChemistry) 672 if (fActiveChemistry) 672 { 673 { 673 G4double delayedTime = 0.; << 674 PushMolecule(std::unique_ptr<G4Molecule>(new G4Molecule(G4Electron_aq::Definition())), 674 if(pIncomingTrack->GetUserInformation( << 675 picosecond, 675 { << 676 pFinalPosition ? *pFinalPosition : pIncomingTrack->GetPosition(), 676 auto pPulseInfo = dynamic_cast<G4V << 677 (pIncomingTrack->GetUserInformat << 678 if(pPulseInfo != nullptr) << 679 { << 680 delayedTime = pPulseInfo->GetD << 681 } << 682 } << 683 << 684 PushMolecule(std::make_unique<G4Molecu << 685 picosecond + delayedTime, << 686 pFinalPosition != nullptr << 687 pIncomingTrack->GetTrackI 677 pIncomingTrack->GetTrackID()); 688 } 678 } 689 } 679 } 690 680 691 //-------------------------------------------- 681 //------------------------------------------------------------------------------ 692 682 693 void G4DNAChemistryManager::PushMolecule(std:: 683 void G4DNAChemistryManager::PushMolecule(std::unique_ptr<G4Molecule> pMolecule, 694 doubl 684 double time, 695 const 685 const G4ThreeVector& position, 696 int p 686 int parentID) 697 { 687 { 698 assert(fActiveChemistry 688 assert(fActiveChemistry 699 && "To inject chemical species, the 689 && "To inject chemical species, the chemistry must be activated. " 700 "Check chemistry activation befo 690 "Check chemistry activation before injecting species."); 701 G4Track* pTrack = pMolecule->BuildTrack(ti 691 G4Track* pTrack = pMolecule->BuildTrack(time, position); 702 pTrack->SetTrackStatus(fAlive); 692 pTrack->SetTrackStatus(fAlive); 703 pTrack->SetParentID(parentID); 693 pTrack->SetParentID(parentID); 704 pMolecule.release(); 694 pMolecule.release(); 705 PushTrack(pTrack); 695 PushTrack(pTrack); 706 } 696 } 707 697 708 //-------------------------------------------- 698 //------------------------------------------------------------------------------ 709 699 710 void G4DNAChemistryManager::SetGlobalTemperatu 700 void G4DNAChemistryManager::SetGlobalTemperature(G4double temp_K) 711 { 701 { 712 G4MolecularConfiguration::SetGlobalTempera 702 G4MolecularConfiguration::SetGlobalTemperature(temp_K); 713 G4DNAMolecularReactionTable::Instance()->S 703 G4DNAMolecularReactionTable::Instance()->ScaleReactionRateForNewTemperature(temp_K); 714 } 704 } 715 705 716 //-------------------------------------------- 706 //------------------------------------------------------------------------------ 717 // [[deprecated]] : chemistry list should neve 707 // [[deprecated]] : chemistry list should never be nullptr 718 void G4DNAChemistryManager::SetChemistryList(G 708 void G4DNAChemistryManager::SetChemistryList(G4VUserChemistryList* pChemistryList) 719 { 709 { 720 fpUserChemistryList.reset(pChemistryList); 710 fpUserChemistryList.reset(pChemistryList); 721 fOwnChemistryList = false; 711 fOwnChemistryList = false; 722 SetChemistryActivation(true); 712 SetChemistryActivation(true); 723 } 713 } 724 714 725 void G4DNAChemistryManager::SetChemistryList(G 715 void G4DNAChemistryManager::SetChemistryList(G4VUserChemistryList& chemistryList) 726 { 716 { 727 fpUserChemistryList.reset(&chemistryList); 717 fpUserChemistryList.reset(&chemistryList); 728 fOwnChemistryList = false; 718 fOwnChemistryList = false; 729 SetChemistryActivation(true); 719 SetChemistryActivation(true); 730 } 720 } 731 721 732 void G4DNAChemistryManager::SetChemistryList(s 722 void G4DNAChemistryManager::SetChemistryList(std::unique_ptr<G4VUserChemistryList> pChemistryList) 733 { 723 { 734 fpUserChemistryList = std::move(pChemistry 724 fpUserChemistryList = std::move(pChemistryList); 735 fOwnChemistryList = true; 725 fOwnChemistryList = true; 736 SetChemistryActivation(true); 726 SetChemistryActivation(true); 737 } 727 } 738 728 739 //-------------------------------------------- 729 //------------------------------------------------------------------------------ 740 730 741 void G4DNAChemistryManager::Deregister(G4VUser 731 void G4DNAChemistryManager::Deregister(G4VUserChemistryList& chemistryList) 742 { 732 { 743 if (fpUserChemistryList.get() == &chemistr 733 if (fpUserChemistryList.get() == &chemistryList) 744 { 734 { 745 if (!fpUserChemistryList->IsPhysicsCon 735 if (!fpUserChemistryList->IsPhysicsConstructor() || fOwnChemistryList) 746 { 736 { 747 fpUserChemistryList.reset(); 737 fpUserChemistryList.reset(); 748 } 738 } 749 739 750 fpUserChemistryList.release(); 740 fpUserChemistryList.release(); 751 } 741 } 752 } 742 } 753 743 754 //-------------------------------------------- 744 //------------------------------------------------------------------------------ 755 745 756 void G4DNAChemistryManager::PushTrack(G4Track* 746 void G4DNAChemistryManager::PushTrack(G4Track* pTrack) 757 { 747 { 758 G4ITTrackHolder::Instance()->Push(pTrack); 748 G4ITTrackHolder::Instance()->Push(pTrack); 759 } 749 } 760 750 761 //-------------------------------------------- 751 //------------------------------------------------------------------------------ 762 752 763 void G4DNAChemistryManager::SetVerbose(G4int v 753 void G4DNAChemistryManager::SetVerbose(G4int verbose) 764 { 754 { 765 fVerbose = verbose; 755 fVerbose = verbose; 766 } 756 } 767 757 768 //-------------------------------------------- 758 //------------------------------------------------------------------------------ 769 759 770 G4bool G4DNAChemistryManager::IsCounterResetWh 760 G4bool G4DNAChemistryManager::IsCounterResetWhenRunEnds() const 771 { 761 { 772 return fResetCounterWhenRunEnds; 762 return fResetCounterWhenRunEnds; 773 } 763 } 774 764 775 //-------------------------------------------- 765 //------------------------------------------------------------------------------ 776 766 777 void G4DNAChemistryManager::ResetCounterWhenRu 767 void G4DNAChemistryManager::ResetCounterWhenRunEnds(G4bool resetCounterWhenRunEnds) 778 { 768 { 779 fResetCounterWhenRunEnds = resetCounterWhe 769 fResetCounterWhenRunEnds = resetCounterWhenRunEnds; 780 } 770 } 781 771 782 //-------------------------------------------- 772 //------------------------------------------------------------------------------ 783 773 784 void G4DNAChemistryManager::ForceRebuildingPhy 774 void G4DNAChemistryManager::ForceRebuildingPhysicsTable() 785 { 775 { 786 fPhysicsTableBuilt = false; 776 fPhysicsTableBuilt = false; 787 } 777 } 788 778 789 //-------------------------------------------- 779 //------------------------------------------------------------------------------ 790 780 791 void G4DNAChemistryManager::ForceMasterReiniti 781 void G4DNAChemistryManager::ForceMasterReinitialization() 792 { 782 { 793 fMasterInitialized = false; 783 fMasterInitialized = false; 794 InitializeMaster(); 784 InitializeMaster(); 795 } 785 } 796 786 797 //-------------------------------------------- 787 //------------------------------------------------------------------------------ 798 788 799 void G4DNAChemistryManager::ForceThreadReiniti 789 void G4DNAChemistryManager::ForceThreadReinitialization() 800 { 790 { 801 fForceThreadReinitialization = true; 791 fForceThreadReinitialization = true; 802 } 792 } 803 793 804 //-------------------------------------------- 794 //------------------------------------------------------------------------------ 805 795 806 void G4DNAChemistryManager::TagThreadForReinit 796 void G4DNAChemistryManager::TagThreadForReinitialization() 807 { 797 { 808 fpThreadData->fThreadInitialized = false; 798 fpThreadData->fThreadInitialized = false; 809 } 799 } 810 800