70 G4DNAChemistryManager::fpThreadData =
nullptr;
76G4DNAChemistryManager::ThreadLocalData::ThreadLocalData()
78 fpPhysChemIO =
nullptr;
79 fThreadInitialized =
false;
84G4DNAChemistryManager::ThreadLocalData::~ThreadLocalData()
86 fpThreadData =
nullptr;
93 fpThreadData->fpPhysChemIO = std::move(pPhysChemIO);
113 fpExcitationLevel(nullptr)
114 , fpIonisationLevel(nullptr)
115 , fpUserChemistryList(nullptr)
117 fpRunChem->SetParameterName(
"Number of runs to execute for the chemistry module"
118 "(this works when used in standalone",
true,
true);
119 fpRunChem->SetDefaultValue(1);
120 fpScaleForNewTemperature->SetUnitCategory(
"Temperature");
127 if (fgInstance ==
nullptr)
130 if (fgInstance ==
nullptr)
138 if (fpThreadData ==
nullptr)
140 fpThreadData =
new ThreadLocalData();
143 assert(fpThreadData !=
nullptr);
160 fgInstance =
nullptr;
167 fpIonisationLevel.reset();
168 fpExcitationLevel.reset();
170 if (fpUserChemistryList)
175 fpChemDNADirectory.reset();
176 fpActivateChem.reset();
179 fpSkipReactionsFromChemList.reset();
182 if (fpThreadData !=
nullptr)
185 fpThreadData =
nullptr;
200 if (fgInstance !=
nullptr)
203 fgInstance =
nullptr;
209 G4cerr <<
"G4DNAChemistryManager already deleted" <<
G4endl;
222 G4cout <<
"G4DNAChemistryManager::Notify ---> received G4State_Quit"
229 fGeometryClosed =
true;
243 if (pCommand == fpActivateChem.get())
247 else if (pCommand == fpRunChem.get())
250 for (
int i = 0 ; i < nbExec ; ++i)
255 else if (pCommand == fpSkipReactionsFromChemList.get())
257 fSkipReactions =
true;
259 else if (pCommand == fpScaleForNewTemperature.get())
263 else if (pCommand == fpInitChem.get())
274 if (pCommand == fpActivateChem.get())
278 if (pCommand == fpScaleForNewTemperature.get())
282 if (pCommand == fpSkipReactionsFromChemList.get())
306 if (!fActiveChemistry)
313 if (!fMasterInitialized)
316 description <<
"Global components were not initialized.";
321 if (!fpThreadData->fThreadInitialized)
324 description <<
"Thread local components were not initialized.";
340 fUseInStandalone = flag;
389 if (fMasterInitialized)
396 G4cout <<
"G4DNAChemistryManager::InitializeMaster() is called" <<
G4endl;
400 if (fpUserChemistryList ==
nullptr)
403 description <<
"No user chemistry list has been provided.";
404 G4Exception(
"G4DNAChemistryManager::InitializeMaster",
"NO_CHEM_LIST",
408 fpUserChemistryList->ConstructDissociationChannels();
425 fMasterInitialized =
true;
432 if (!fUseInStandalone || fPhysicsTableBuilt)
439 G4cout <<
"G4DNAChemistryManager: Build the physics tables for "
440 "molecule definition only."
444 fpUserChemistryList->BuildPhysicsTable();
446 if (!fGeometryClosed)
450 G4cout <<
"G4DNAChemistryManager: Close geometry" <<
G4endl;
456 fGeometryClosed =
true;
459 fPhysicsTableBuilt =
true;
466 if (fpThreadData->fThreadInitialized && !fForceThreadReinitialization)
471 if (fpUserChemistryList ==
nullptr)
474 description <<
"No user chemistry list has been provided.";
475 G4Exception(
"G4DNAChemistryManager::InitializeThread",
"NO_CHEM_LIST",
485 G4cout <<
"G4DNAChemistryManager::InitializeThread() is called"
494 fpThreadData->fThreadInitialized =
true;
505 G4cout <<
"G4DNAChemistryManager::InitializeFile() is called"
509 if (fpThreadData->fpPhysChemIO)
511 fpThreadData->fpPhysChemIO->InitializeFile();
519 return fgInstance !=
nullptr ? fgInstance->IsChemistryActivated() :
false;
526 return fActiveChemistry;
533 fActiveChemistry = flag;
539 std::ios_base::openmode mode)
543 G4cout <<
"G4DNAChemistryManager: Write chemical stage into "
544 << output.data() <<
G4endl;
547 if (!fpThreadData->fpPhysChemIO)
549 fpThreadData->fpPhysChemIO = std::make_unique<G4PhysChemIO::FormattedText>();
552 fpThreadData->fpPhysChemIO->WriteInto(output, mode);
560 if (fpThreadData->fpPhysChemIO)
562 fpThreadData->fpPhysChemIO->AddEmptyLineInOutputFile();
570 if (fpThreadData->fpPhysChemIO)
572 fpThreadData->fpPhysChemIO->CloseFile();
580 if (!fpExcitationLevel)
582 fpExcitationLevel = std::make_unique<G4DNAWaterExcitationStructure>();
584 return fpExcitationLevel.get();
591 if (!fpIonisationLevel)
593 fpIonisationLevel = std::make_unique<G4DNAWaterIonisationStructure>();
595 return fpIonisationLevel.get();
601 G4int electronicLevel,
604 if (fpThreadData->fpPhysChemIO)
608 switch (modification)
621 fpThreadData->fpPhysChemIO->CreateWaterMolecule(modification,
627 if (fActiveChemistry)
631 switch (modification)
634 pH2OMolecule->AddElectron(5, 1);
637 pH2OMolecule->ExciteMolecule(4 - electronicLevel);
640 pH2OMolecule->IonizeMolecule(4 - electronicLevel);
649 if(pPulseInfo !=
nullptr)
651 delayedTime = pPulseInfo->GetDelayedTime();
655 G4Track *pH2OTrack = pH2OMolecule->BuildTrack(picosecond + delayedTime,
671 if (fpThreadData->fpPhysChemIO)
673 fpThreadData->fpPhysChemIO->CreateSolvatedElectron(pIncomingTrack,
677 if (fActiveChemistry)
684 if(pPulseInfo !=
nullptr)
686 delayedTime = pPulseInfo->GetDelayedTime();
691 picosecond + delayedTime,
692 pFinalPosition ? *pFinalPosition : pIncomingTrack->
GetPosition(),
706 assert(fActiveChemistry
707 &&
"To inject chemical species, the chemistry must be activated. "
708 "Check chemistry activation before injecting species.");
728 fpUserChemistryList.reset(pChemistryList);
729 fOwnChemistryList =
false;
735 fpUserChemistryList.reset(&chemistryList);
736 fOwnChemistryList =
false;
742 fpUserChemistryList = std::move(pChemistryList);
743 fOwnChemistryList =
true;
751 if (fpUserChemistryList.get() == &chemistryList)
753 if (!fpUserChemistryList->IsPhysicsConstructor() || fOwnChemistryList)
755 fpUserChemistryList.reset();
758 fpUserChemistryList.release();
808 fPhysicsTableBuilt =
false;
815 fMasterInitialized =
false;
823 fForceThreadReinitialization =
true;
830 fpThreadData->fThreadInitialized =
false;
G4TemplateAutoLock< G4Mutex > G4AutoLock
@ eDissociativeAttachment
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
void SetPhysChemIO(std::unique_ptr< G4VPhysChemIO > pPhysChemIO)
G4String GetCurrentValue(G4UIcommand *pCommand) override
void CreateSolvatedElectron(const G4Track *, G4ThreeVector *pFinalPosition=nullptr)
void EndOfEventAction(const G4Event *)
void InitializeThreadSharedData()
~G4DNAChemistryManager() override
G4bool IsChemistryActivated()
static G4DNAChemistryManager * GetInstanceIfExists()
void BeginOfEventAction(const G4Event *)
void HandleStandaloneInitialization()
static G4DNAChemistryManager * Instance()
void UseAsStandalone(G4bool flag)
void PushTrack(G4Track *)
void SetChemistryList(G4VUserChemistryList &)
void ForceThreadReinitialization()
void PushMolecule(std::unique_ptr< G4Molecule > pMolecule, G4double time, const G4ThreeVector &position, G4int parentID, const G4Track *parentTrack=nullptr)
void AddEmptyLineInOutputFile()
void ForceRebuildingPhysicsTable()
static G4bool IsActivated()
void SetGlobalTemperature(G4double temperatureKelvin)
void SetGun(G4ITGun *pChemSpeciesGun)
Inject custom species to the simulation.
G4DNAWaterIonisationStructure * GetIonisationLevel()
void Deregister(G4VUserChemistryList &)
G4DNAWaterExcitationStructure * GetExcitationLevel()
void EndOfRunAction(const G4Run *)
void SetNewValue(G4UIcommand *, G4String) override
G4bool Notify(G4ApplicationState requestedState) override
void ForceMasterReinitialization()
void SetChemistryActivation(G4bool)
static void DeleteInstance()
void SetVerbose(G4int verbose)
void TagThreadForReinitialization()
void BeginOfRunAction(const G4Run *)
void WriteInto(const G4String &, std::ios_base::openmode mode=std::ios_base::out)
void CreateWaterMolecule(ElectronicModification, G4int, const G4Track *)
static G4DNAMolecularReactionTable * GetReactionTable()
static G4DNAMolecularReactionTable * Instance()
static void DeleteInstance()
void ScaleReactionRateForNewTemperature(double temp_K)
G4double ExcitationEnergy(G4int level)
G4double IonisationEnergy(G4int level)
static G4Electron_aq * Definition()
G4GeometryManager is a singleton class responsible for high level geometrical functions,...
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
static G4H2O * Definition()
void Push(G4Track *) override
static G4ITTrackHolder * Instance()
static void DeleteManager()
static void SetGlobalTemperature(G4double)
static G4double GetGlobalTemperature()
void EndOfEventAction(const G4Event *)
void BeginOfRunAction(const G4Run *)
void EndOfRunAction(const G4Run *)
void BeginOfEventAction(const G4Event *)
static G4MoleculeCounterManager * GetInstanceIfExists()
static G4MoleculeCounterManager * Instance()
static void DeleteInstance()
void Finalize(G4MoleculeDefinition *)
void PrepareMolecularConfiguration()
static G4MoleculeTable * Instance()
void SetGun(G4ITGun *) override
static G4Scheduler * Instance()
void Initialize() override
void SetTrackStatus(const G4TrackStatus aTrackStatus)
const G4ThreeVector & GetPosition() const
G4VUserTrackInformation * GetUserInformation() const
void SetKineticEnergy(const G4double aValue)
void SetParentID(const G4int aValue)
static G4bool GetNewBoolValue(const char *paramString)
static G4String ConvertToString(G4bool boolVal)
static G4int ConvertToInt(const char *st)
G4bool IsMultithreadedApplication()