Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-18 07:54:51

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 /// \file ActionInitialization.cc
0027 /// \brief Implementation of the ActionInitialization class
0028 
0029 #include "ActionInitialization.hh"
0030 
0031 #include "ChemistryWorld.hh"
0032 #include "DetectorConstruction.hh"
0033 #include "InterPulseAction.hh"
0034 #include "PrimaryGeneratorAction.hh"
0035 #include "PulseAction.hh"
0036 #include "RunAction.hh"
0037 #include "StackingAction.hh"
0038 #include "TimeStepAction.hh"
0039 
0040 #include "G4DNAChemistryManager.hh"
0041 #include "G4DNAEventScheduler.hh"
0042 #include "G4DNAScavengerMaterial.hh"
0043 #include "G4H2O.hh"
0044 #include "G4Molecule.hh"
0045 #include "G4MoleculeGun.hh"
0046 #include "G4Scheduler.hh"
0047 #include "G4RunManager.hh"
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0049 
0050 ActionInitialization::ActionInitialization()
0051   : G4VUserActionInitialization()
0052 {
0053   DefineCommands();
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0057 
0058 void ActionInitialization::BuildForMaster() const
0059 {
0060   SetUserAction(new RunAction());
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0064 
0065 void ActionInitialization::Build() const
0066 {
0067   PulseAction* pPulseAction = nullptr;
0068   if (fActivePulse) {  // Le Tuan Anh: define if fActivePulse
0069     if (fUseInterPulse) {
0070       pPulseAction =
0071         new InterPulseAction(fPulseStructure, fUseHistoInput, fPulsePeriod, fNumberOfPulse);
0072     }
0073     else {
0074       pPulseAction = new PulseAction(fPulseStructure, fUseHistoInput);
0075     }
0076 
0077     pPulseAction->SetPulse(fActivePulse);
0078     SetUserAction(pPulseAction);
0079   }
0080 
0081   SetUserAction(new PrimaryGeneratorAction());
0082   auto pRunAction = new RunAction();
0083   SetUserAction(pRunAction);
0084 
0085   if (G4DNAChemistryManager::IsActivated()) {
0086     SetUserAction(new StackingAction());
0087     const auto* fpDetector = dynamic_cast<const DetectorConstruction*>(
0088     G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0089     auto pChemWorld = fpDetector->GetChemistryWorld();
0090     auto pScavenger = std::make_unique<G4DNAScavengerMaterial>(pChemWorld);
0091     // To counter Scavenger
0092     dynamic_cast<G4DNAScavengerMaterial*>(pScavenger.get())->SetCounterAgainstTime();
0093     G4Scheduler::Instance()->SetScavengerMaterial(std::move(pScavenger));
0094     auto timeStepAction = new TimeStepAction(pChemWorld, pPulseAction);
0095     auto eventScheduler = timeStepAction->GetEventScheduler();
0096     pRunAction->SetEventScheduler(eventScheduler);
0097     G4Scheduler::Instance()->SetUserAction(timeStepAction);
0098   }
0099 }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0102 
0103 void ActionInitialization::DefineCommands()
0104 {
0105   // Le Tuan Anh: add new commands:
0106   fMessenger = std::make_unique<G4GenericMessenger>(this, "/UHDR/pulse/", "Pulse control");
0107   auto& filenameCmd =
0108     fMessenger->DeclareMethod("pulseFile", &ActionInitialization::SetPulseStructureInput);
0109   filenameCmd.SetParameterName("filenamePulse", true);
0110   filenameCmd.SetDefaultValue("");
0111 
0112   auto& activePulseCmd = fMessenger->DeclareProperty("pulseOn", fActivePulse);
0113   activePulseCmd.SetParameterName("activatePulse", true);
0114   activePulseCmd.SetDefaultValue("false");
0115 
0116   auto& filenameCmdHisto =
0117     fMessenger->DeclareMethod("pulseInHisto", &ActionInitialization::SetPulseStructureHistoInput);
0118   filenameCmdHisto.SetParameterName("filenameInHisto", true);
0119   filenameCmdHisto.SetDefaultValue("");
0120 
0121   auto& interPulseCmd = fMessenger->DeclareProperty("multiPulse", fUseInterPulse);
0122   interPulseCmd.SetParameterName("activateInterPulse", true);
0123   interPulseCmd.SetDefaultValue("false");
0124 
0125   auto& pulsePeriodCmd =
0126     fMessenger->DeclareMethodWithUnit("pulsePeriod", "us", &ActionInitialization::SetPulsePeriod);
0127   pulsePeriodCmd.SetParameterName("pulsePeriod", true);
0128   pulsePeriodCmd.SetDefaultValue("0");
0129   pulsePeriodCmd.SetRange("pulsePeriod >= 0");
0130 
0131   auto& nPulseCmd =
0132     fMessenger->DeclareMethod("numberOfPulse", &ActionInitialization::SetNumberOfPulse);
0133   nPulseCmd.SetParameterName("numberOfPulse", true);
0134   nPulseCmd.SetDefaultValue("1");
0135   nPulseCmd.SetRange("numberOfPulse >= 1");
0136 }
0137 
0138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0139 void ActionInitialization::SetPulseStructureHistoInput(G4String fn)
0140 {
0141   // L.T. Anh: set histo input file & activate fUseHistoInput
0142   fPulseStructure = fn;
0143   fUseHistoInput = true;
0144 }
0145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0146 
0147 void ActionInitialization::SetPulseStructureInput(G4String fn)
0148 {
0149   // L.T. Anh: set input file & deactivate fUseHistoInput
0150   fPulseStructure = fn;
0151   fUseHistoInput = false;
0152 }