Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-17 08:07:04

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