Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:07

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 
0028 // Author: Mathieu Karamitros
0029 //
0030 // The code is developed in the framework of the ESA AO7146
0031 //
0032 // We would be very happy hearing from you, send us your feedback! :)
0033 //
0034 // In order for Geant4-DNA to be maintained and still open-source,
0035 // article citations are crucial. 
0036 // If you use Geant4-DNA chemistry and you publish papers about your software, 
0037 // in addition to the general paper on Geant4-DNA:
0038 //
0039 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0040 //
0041 // we would be very happy if you could please also cite the following
0042 // reference papers on chemistry:
0043 //
0044 // J. Comput. Phys. 274 (2014) 841-882
0045 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
0046 
0047 #pragma once
0048 
0049 #include "globals.hh"
0050 #include "G4ThreeVector.hh"
0051 #include <fstream>
0052 #include <memory>
0053 #include "G4UImessenger.hh"
0054 #include "G4VStateDependent.hh"
0055 
0056 class G4Track;
0057 class G4DNAWaterExcitationStructure;
0058 class G4DNAWaterIonisationStructure;
0059 class G4Molecule;
0060 class G4VUserChemistryList;
0061 class G4UIcmdWithABool;
0062 class G4UIcmdWithADoubleAndUnit;
0063 class G4UIcmdWithoutParameter;
0064 class G4UIcmdWithAnInteger;
0065 class G4ITGun;
0066 class G4VPhysChemIO;
0067 
0068 enum ElectronicModification
0069 {
0070     eIonizedMolecule,
0071     eExcitedMolecule,
0072     eDissociativeAttachment
0073 };
0074 
0075 /**
0076  * WARNING: THIS CLASS IS A PROTOTYPE
0077  * G4DNAChemistryManager is called from the physics models.
0078  * It creates the water molecules and the solvated electrons and
0079  * and send them to G4ITStepManager to be treated in the chemistry stage.
0080  * For this, the fActiveChemistry flag needs to be on.
0081  * It is also possible to give already molecule's pointers already built.
0082  * G4DNAChemistryManager will then be in charge of creating the track and loading
0083  * it to the IT system.
0084  * The user can also ask to create a file containing a information about the
0085  * creation of water molecules and solvated electrons.
0086  */
0087 class G4DNAChemistryManager: public G4UImessenger,
0088                              public G4VStateDependent
0089 {
0090 protected:
0091     ~G4DNAChemistryManager() override;
0092 
0093 public:
0094     //============================================================================
0095     // STATIC METHODS
0096     //============================================================================
0097     static G4DNAChemistryManager* Instance();
0098     static G4DNAChemistryManager* GetInstanceIfExists();
0099 
0100     static void DeleteInstance();
0101     static G4bool IsActivated();
0102 
0103     //============================================================================
0104     // VIRTUAL METHODS
0105     //============================================================================
0106     // G4VStateDependent
0107     G4bool Notify(G4ApplicationState requestedState) override;
0108     // G4UImessenger
0109     void SetNewValue(G4UIcommand*, G4String) override;
0110     G4String GetCurrentValue(G4UIcommand* pCommand) override;
0111 
0112     //============================================================================
0113     // INITIALIZATION AND FINALIZATION METHODS
0114     //============================================================================
0115     G4bool IsChemistryActivated();
0116     void SetChemistryActivation(G4bool);
0117 
0118     /** Chemistry list is managed outside the chemistry manager (eg. constructor). */
0119     void SetChemistryList(G4VUserChemistryList&);
0120 
0121     /** Not a constructor or when used in standalone? Prefer this method. */
0122     void SetChemistryList(std::unique_ptr<G4VUserChemistryList>);
0123 
0124     // [[deprecated]] : chemistry list should never be nullptr
0125     void SetChemistryList(G4VUserChemistryList*);
0126 
0127     void Deregister(G4VUserChemistryList&);
0128 
0129     void Initialize();
0130     void Run();
0131     void Clear();
0132 
0133     /**
0134      * @brief Inject custom species to the simulation
0135      * @details This method should be called per thread, possibly from
0136      * ActionInitialisation::Build.
0137      * One can decide to set the same gun for all threads.
0138      * It is the user responsibility to handle the pointer deletion.
0139      */
0140     void SetGun(G4ITGun* pChemSpeciesGun);
0141 
0142     void SetPhysChemIO(std::unique_ptr<G4VPhysChemIO> pPhysChemIO);
0143 
0144     void SetVerbose(G4int verbose);
0145 
0146     /**
0147      * If the chemistry module is used in standalone (ie. without running the physics
0148      * stage beforehand), the physics table still needs to be built.
0149      * It is therefore necessary to flag the chemistry module as being run
0150      * in standalone.
0151      */
0152     void UseAsStandalone(G4bool flag);
0153     G4bool IsCounterResetWhenRunEnds() const;
0154 
0155     void ResetCounterWhenRunEnds(G4bool resetCounterWhenRunEnds);
0156 
0157     void ForceMasterReinitialization();
0158     void TagThreadForReinitialization();
0159     void ForceThreadReinitialization();
0160     void ForceRebuildingPhysicsTable();
0161 
0162     //============================================================================
0163     // FILE OPERATIONS
0164     //============================================================================
0165     /**
0166      * Tells the chemMan to write into a file
0167      * the position and electronic state of the water molecule
0168      * and the position thermalized or not of the solvated electron
0169      */
0170     void WriteInto(const G4String&, std::ios_base::openmode mode =
0171                    std::ios_base::out);
0172     void AddEmptyLineInOutputFile();
0173 
0174     /**
0175      * Close the file specified with WriteInto
0176      */
0177     void CloseFile();
0178 
0179     //============================================================================
0180     // PUSH MOLECULES
0181     //============================================================================
0182     /**
0183      * Method used by DNA physics model to create a water molecule.
0184      * The ElectronicModification is a flag telling whether the molecule
0185      * is ionized or excited, the electronic level is calculated by the
0186      * model and the IncomingTrack is the track responsible for the creation
0187      * of this molecule (electron, proton...).
0188      */
0189     void CreateWaterMolecule(ElectronicModification,
0190                              G4int /*electronicLevel*/,
0191                              const G4Track* /*pIncomingTrack*/);
0192 
0193     /**
0194      * This method should be used by the physics model of the ElectronSolvatation
0195      * process.
0196      */
0197     void CreateSolvatedElectron(const G4Track* /*pIncomingTrack*/,
0198                                 G4ThreeVector* pFinalPosition = nullptr);
0199 
0200     void PushMolecule(std::unique_ptr<G4Molecule> pMolecule,
0201                       G4double time,
0202                       const G4ThreeVector& position,
0203                       G4int parentID);
0204 
0205 protected:
0206     void HandleStandaloneInitialization();
0207     void PushTrack(G4Track*);
0208     void SetGlobalTemperature(G4double temperatureKelvin);
0209 
0210     G4DNAWaterExcitationStructure* GetExcitationLevel();
0211     G4DNAWaterIonisationStructure* GetIonisationLevel();
0212     void InitializeFile();
0213     void InitializeMaster();
0214     void InitializeThread();
0215     void InitializeThreadSharedData();
0216 
0217     G4DNAChemistryManager();
0218 
0219 private:
0220     std::unique_ptr<G4UIdirectory> fpChemDNADirectory;
0221     std::unique_ptr<G4UIcmdWithABool> fpActivateChem;
0222     std::unique_ptr<G4UIcmdWithAnInteger> fpRunChem;
0223     std::unique_ptr<G4UIcmdWithoutParameter> fpSkipReactionsFromChemList;
0224     std::unique_ptr<G4UIcmdWithADoubleAndUnit> fpScaleForNewTemperature;
0225     std::unique_ptr<G4UIcmdWithoutParameter> fpInitChem;
0226 
0227     static G4DNAChemistryManager* fgInstance;
0228     G4bool fActiveChemistry{false};
0229 
0230     struct ThreadLocalData{
0231         ThreadLocalData();
0232         ~ThreadLocalData();
0233         std::unique_ptr<G4VPhysChemIO> fpPhysChemIO;
0234         G4bool fThreadInitialized = false;
0235     };
0236 
0237     static G4ThreadLocal ThreadLocalData* fpThreadData;
0238 
0239     G4bool fMasterInitialized{false};
0240     G4bool fForceThreadReinitialization{false};
0241 
0242     std::unique_ptr<G4DNAWaterExcitationStructure> fpExcitationLevel;
0243     std::unique_ptr<G4DNAWaterIonisationStructure> fpIonisationLevel;
0244 
0245     std::unique_ptr<G4VUserChemistryList> fpUserChemistryList;
0246     G4bool fOwnChemistryList{false};
0247     G4bool fUseInStandalone{false};
0248     G4bool fPhysicsTableBuilt{false};
0249     G4bool fSkipReactions{false};
0250 
0251     G4bool fGeometryClosed{false};
0252 
0253     G4int fVerbose{0};
0254     G4bool fResetCounterWhenRunEnds{true};
0255 };