Import Geant4 11.1.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2022-07-01 10:44:02 +02:00
parent b3bf75a2a1
commit c07cea1fe0
2172 changed files with 183300 additions and 123938 deletions
@@ -0,0 +1,62 @@
///\file "hadronic/ParticleFluence/Sphere/.README.txt"
///\brief Example ParticleFluence/Sphere README page
/*! \page ExampeParticleFluenceSphere Example Sphere
In this example, the particle fluence is evaluated for a very simple
set-up, consisting of one target solid sphere, at the center of which
a particle is shot (by default along the z-axis).
The particle fluence is computed in two places: "forward" and "backward",
defined as the positions immediately after and before, respectively, of
the target with respect to the direction of the primary particle.
The particle fluence is estimated by summing the track length in a
"scoring volume" - i.e. a thin hemisphere shell filled up with G4_Galactic
(very low density gas) material, immediately outside the target sphere -
and then dividing for the cubic volume of such scoring volume.
The particle fluence is evaluated for the following 11 particle types:
- all
- electron + positron
- gamma
- muon- + muon+
- neutrino (any flavour and including anti-neutrino)
- charged pions
- neutron + anti_neutron
- proton + anti_proton
- ion (and anti-ions)
- otherMeson (e.g. kaons, etc.)
- otherBaryon (e.g. hyperons, etc.)
The particle fluence is evaluated for the following 3 kinematical ranges:
- any kinetic energy
- kinetic energy < 20 MeV
- kinetic energy > 20 MeV
Look for the string "***LOOKHERE***" for those parameters/options that
are either hardwired in the code (i.e. not available via UI command),
or default values of UI commands.
This example uses the physics list factory, therefore you can specify
the reference physics list you want to use via the PHYSLIST
environmental variable (by default, if you don't set it, the FTFP_BERT
physics list is used).
To build this example:
mkdir Build; cd Build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DGeant4_DIR=/path-to-geant4-libraries ../.
make
To run it:
./Sphere all_together.g4
which shoots 50 GeV pion- on different target materials, 100 events
in each run, and print out some information on the particle fluence
at the end of each run.
Other macros exist for specific materials.
*/
@@ -0,0 +1,65 @@
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 3.16...3.21)
project(Sphere)
#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
find_package(Geant4 REQUIRED ui_all vis_all)
else()
find_package(Geant4 REQUIRED)
endif()
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
#
include(${Geant4_USE_FILE})
#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIR})
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(Sphere Sphere.cc ${sources} ${headers})
target_link_libraries(Sphere ${Geant4_LIBRARIES} )
#----------------------------------------------------------------------------
# Copy all scripts to the build directory, so that we can run the executable
# directly there.
#
set(Sphere_SCRIPTS
all_together.g4
polystyrene.g4
graphite.g4
si.g4
lar.g4
fe.g4
cu.g4
w.g4
pb.g4
pbwo4.g4
)
foreach(_script ${Sphere_SCRIPTS})
configure_file(
${PROJECT_SOURCE_DIR}/${_script}
${PROJECT_BINARY_DIR}/${_script}
COPYONLY
)
endforeach()
#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS Sphere DESTINATION bin)
@@ -0,0 +1,11 @@
name := Sphere
G4TARGET := $(name)
G4EXLIB := true
include $(G4INSTALL)/config/architecture.gmk
.PHONY: all
all: lib bin
include $(G4INSTALL)/config/binmake.gmk
@@ -0,0 +1,10 @@
# Example ParticleFluence History
See `CONTRIBUTING.rst` for details of **required** info/format for each entry,
which **must** added in reverse chronological order (newest at the top). It must **not**
be used as a substitute for writing good git commit messages!
## 2021-06-10 Alberto Ribon (exhadrParticleFluenceSphere-V11-00-00)
- Created the Sphere variant of the ParticleFluence example.
@@ -0,0 +1,55 @@
In this example, the particle fluence is evaluated for a very simple
set-up, consisting of one target solid sphere, at the center of which
a particle is shot (by default along the z-axis).
The particle fluence is computed in two places: "forward" and "backward",
defined as the positions immediately after and before, respectively, of
the target with respect to the direction of the primary particle.
The particle fluence is estimated by summing the track length in a
"scoring volume" - i.e. a thin hemisphere shell filled up with G4_Galactic
(very low density gas) material, immediately outside the target sphere -
and then dividing for the cubic volume of such scoring volume.
The particle fluence is evaluated for the following 11 particle types:
- all
- electron + positron
- gamma
- muon- + muon+
- neutrino (any flavour and including anti-neutrino)
- charged pions
- neutron + anti_neutron
- proton + anti_proton
- ion (and anti-ions)
- otherMeson (e.g. kaons, etc.)
- otherBaryon (e.g. hyperons, etc.)
The particle fluence is evaluated for the following 3 kinematical ranges:
- any kinetic energy
- kinetic energy < 20 MeV
- kinetic energy > 20 MeV
Look for the string "***LOOKHERE***" for those parameters/options that
are either hardwired in the code (i.e. not available via UI command),
or default values of UI commands.
This example uses the physics list factory, therefore you can specify
the reference physics list you want to use via the PHYSLIST
environmental variable (by default, if you don't set it, the FTFP_BERT
physics list is used).
To build this example:
mkdir Build; cd Build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DGeant4_DIR=/path-to-geant4-libraries ../.
make
To run it:
./Sphere all_together.g4
which shoots 50 GeV pion- on different target materials, 100 events
in each run, and print out some information on the particle fluence
at the end of each run.
Other macros exist for specific materials.
@@ -0,0 +1,70 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file Sphere.cc
/// \brief Main program of the hadronic/ParticleFluence/Sphere example
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4Threading.hh"
#include "G4RunManagerFactory.hh"
#include "G4UImanager.hh"
#include "G4PhysListFactory.hh"
#include "DetectorConstruction.hh"
#include "ActionInitialization.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
int main(int argc,char** argv) {
auto* runManager = G4RunManagerFactory::CreateRunManager();
DetectorConstruction* pDetectorInstance = new DetectorConstruction;
runManager->SetUserInitialization( pDetectorInstance );
// Physics list factory: use the PHYSLIST environmental variable.
G4PhysListFactory factory;
G4VModularPhysicsList* thePL = factory.ReferencePhysList();
runManager->SetUserInitialization( thePL );
runManager->SetUserInitialization( new ActionInitialization );
G4UImanager* UI = G4UImanager::GetUIpointer();
if ( argc==1 ) { // Define UI session for interactive mode.
} else { // Batch mode
G4String command = "/control/execute ";
G4String fileName = argv[1];
UI->ApplyCommand(command+fileName);
}
// job termination
delete runManager;
return 0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,53 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
#
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
#
/mydet/material G4_POLYSTYRENE
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_GRAPHITE
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_Si
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_lAr
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_Fe
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_Cu
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_W
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_Pb
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
#
/mydet/material G4_PbWO4
/mydet/radius 100.0 cm
/mydet/update
/run/beamOn 100
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_Cu
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_Fe
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_GRAPHITE
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
@@ -0,0 +1,51 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file ActionInitialization.hh
/// \brief Definition of the ActionInitialization class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef ActionInitialization_h
#define ActionInitialization_h 1
#include "G4VUserActionInitialization.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class ActionInitialization : public G4VUserActionInitialization {
public:
ActionInitialization();
virtual ~ActionInitialization();
virtual void BuildForMaster() const override;
virtual void Build() const override;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,87 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file DetectorConstruction.hh
/// \brief Definition of the DetectorConstruction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef DetectorConstruction_H
#define DetectorConstruction_H 1
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
class G4LogicalVolume;
class G4VPhysicalVolume;
class G4Material;
class DetectorMessenger;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class DetectorConstruction : public G4VUserDetectorConstruction {
public:
DetectorConstruction();
~DetectorConstruction();
G4VPhysicalVolume* Construct();
void SetMaterial( const G4String name );
inline G4Material* GetMaterial() const;
inline void SetRadius( const G4double value );
inline G4double GetRadius() const;
void UpdateGeometry();
private:
G4VPhysicalVolume* ConstructSphere(); // To be invoked each time the geometry needs
// to be updated
void PrintParameters();
G4Material* fMaterial;
G4LogicalVolume* fExperimentalHall_log;
G4VPhysicalVolume* fExperimentalHall_phys;
G4LogicalVolume* fLogicSphere;
G4VPhysicalVolume* fPhysiSphere;
G4LogicalVolume* fLogicScoringShell;
G4VPhysicalVolume* fPhysiScoringShell;
DetectorMessenger* fDetectorMessenger;
G4double fRadius;
const G4double fScoringThickness = 10.0; //***LOOKHERE*** thickness of the scoring shell
};
inline G4Material* DetectorConstruction::GetMaterial() const {
return fMaterial;
}
inline void DetectorConstruction::SetRadius( const G4double value ) {
fRadius = value;
}
inline G4double DetectorConstruction::GetRadius() const {
return fRadius;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,63 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file DetectorMessenger.hh
/// \brief Definition of the DetectorMessenger class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef DetectorMessenger_h
#define DetectorMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class DetectorConstruction;
class G4UIdirectory;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAString;
class G4UIcmdWithoutParameter;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class DetectorMessenger: public G4UImessenger {
public:
DetectorMessenger( DetectorConstruction* );
~DetectorMessenger();
void SetNewValue( G4UIcommand*, G4String ) override;
private:
DetectorConstruction* fDetector;
G4UIdirectory* fDetectorDir;
G4UIcmdWithAString* fMaterial;
G4UIcmdWithADoubleAndUnit* fRadius;
G4UIcmdWithoutParameter* fUpdateCommand;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,56 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file PrimaryGeneratorAction.hh
/// \brief Definition of the PrimaryGeneratorAction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef PrimaryGeneratorAction_h
#define PrimaryGeneratorAction_h 1
#include "G4VUserPrimaryGeneratorAction.hh"
class G4ParticleGun;
class G4Event;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
public:
PrimaryGeneratorAction();
~PrimaryGeneratorAction();
void GeneratePrimaries( G4Event* anEvent ) override;
void SetGunPosition() const;
private:
G4ParticleGun* fParticleGun;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,104 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file Run.hh
/// \brief Definition of the Run class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef Run_h
#define Run_h 1
#include "G4Run.hh"
#include "G4ThreeVector.hh"
#include "SteppingAction.hh"
#include <array>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class Run : public G4Run {
// This class accumulates relevant quantities related to particle fluence collected during
// the run.
// ( Note: these information are provided via calls of accessor methods of this Run class
// made by SteppingAction::UserSteppingAction. )
// At the end of a run, the printInfo method is called by the run-action to print out
// some summary information about these quantities.
// In multithreaded (MT) mode, an object of this class is filled up for each working thread,
// and then merged (automatically by the Geant4 kernel) into another object (of this class)
// owned by the master class; the printInfo method is then called only for the latter run
// object.
// Note that, for simplicity and brevity, we avoid histograms and print-out instead some
// statistics (compute by ourself) at the end of the run.
public:
Run();
~Run();
virtual void RecordEvent( const G4Event* anEvent ) override;
// This method is called automatically by the Geant4 kernel (not by the user!) at the end
// of each event. In the case of multithreaded mode, it is called only for the working thread
// that handled that event.
virtual void Merge( const G4Run* aRun ) override;
// This method is called automatically by the Geant4 kernel (not by the user!) only in the
// case of multithreaded mode and only for working threads.
void printInfo() const;
// This method is called by RunAction::EndOfRunAction : in the case of multithreaded mode,
// only the master thread calls it.
void setPrimaryParticleId( const G4int inputValue ) { fPrimaryParticleId = inputValue; }
void setPrimaryParticleEnergy( const G4double inputValue )
{ fPrimaryParticleEnergy = inputValue; }
void setPrimaryParticleDirection( const G4ThreeVector &inputValue )
{ fPrimaryParticleDirection = inputValue; }
void setTargetMaterialName( const G4String &inputValue ) { fTargetMaterialName = inputValue; }
void setCubicVolumeScoringShell( const G4double inputValue )
{ fCubicVolumeScoringShell = inputValue; }
G4int getPrimaryParticleId() const { return fPrimaryParticleId; }
G4double getPrimaryParticleEnergy() const { return fPrimaryParticleEnergy; }
G4ThreeVector getPrimaryParticleDirection() const { return fPrimaryParticleDirection; }
G4String getTargetMaterialName() const { return fTargetMaterialName; }
G4double getCubicVolumeScoringShell() const { return fCubicVolumeScoringShell; }
void setArray( const std::array< G4double, SteppingAction::numberCombinations >& inputArray );
std::array< G4double, SteppingAction::numberCombinations > getArray() const { return fArray; }
// Accessor methods useful to transfer information collected by the stepping-action
// into this Run class
private:
G4int fNumEvents;
G4int fPrimaryParticleId;
G4double fPrimaryParticleEnergy;
G4ThreeVector fPrimaryParticleDirection;
G4String fTargetMaterialName;
G4double fCubicVolumeScoringShell;
std::array< G4double, SteppingAction::numberCombinations > fArray;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,57 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file RunAction.hh
/// \brief Definition of the RunAction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef RunAction_h
#define RunAction_h
#include "G4UserRunAction.hh"
class G4Run;
class SteppingAction;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class RunAction: public G4UserRunAction {
public:
RunAction( SteppingAction* steppingAction = nullptr );
virtual ~RunAction();
virtual void BeginOfRunAction( const G4Run* aRun ) override;
virtual void EndOfRunAction( const G4Run* aRun ) override;
virtual G4Run* GenerateRun() override;
private:
SteppingAction* fSteppingAction;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,108 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file SteppingAction.hh
/// \brief Definition of the SteppingAction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef SteppingAction_H
#define SteppingAction_H 1
#include "globals.hh"
#include "G4UserSteppingAction.hh"
#include "G4ThreeVector.hh"
#include <array>
class Run;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class SteppingAction : public G4UserSteppingAction {
public:
SteppingAction();
virtual ~SteppingAction();
virtual void UserSteppingAction( const G4Step* ) override;
// This is the main method where the step lengths of particles inside
// the scoring shell are collected, and then the corresponding fluences
// are filled up in the Run object where they are stored (and then
// printed out at the end of the Run).
// (For simplicity and brevity, we avoid histograms and compute instead
// some statistics ourself, which will be print-out at the end of the run.)
void initialize();
// This method is called by RunAction::BeginOfRunAction for the
// initialization of the stepping-action at the beginning of each Run.
// This is necessary because different runs can have different primary particle
// types, kinetic energies, and detector configurations.
void setRunPointer( Run* inputValue = nullptr ) { fRunPtr = inputValue; }
// This method is called by RunAction::BeginOfRunAction for providing to the
// stepping-action the pointer to the run object at the beginning of each Run.
// This pointer is then used to pass the information collected by the stepping-action
// to the run object.
G4double getCubicVolumeScoringShell() const { return fCubicVolumeScoringShell; }
// The cubic-volume of the scoring shell is needed to get the fluence from the
// sum of step lengths inside that scoring shell.
static const G4int numberKinematicRegions = 3; // all, below 20 MeV, above 20 MeV
static const G4int numberScoringPositions = 2; // forward, backward (hemisphere with
// respect to the primary particle direction)
static const G4int numberParticleTypes = 11; // all, e, gamma, mu, nu, pi, n, p, ions,
// other-mesons, other-baryons
static const G4int numberCombinations =
numberKinematicRegions*numberScoringPositions*numberParticleTypes;
static const std::array< G4String, numberKinematicRegions > arrayKinematicRegionNames;
static const std::array< G4String, numberScoringPositions > arrayScoringPositionNames;
static const std::array< G4String, numberParticleTypes > arrayParticleTypeNames;
static G4int getIndex( const G4int iKinematicRegion, const G4int iScoringPosition,
const G4int iParticleType );
private:
Run* fRunPtr; // Pointer to the Run object
G4int fPrimaryParticleId;
G4double fPrimaryParticleEnergy;
G4ThreeVector fPrimaryParticleDirection;
G4String fTargetMaterialName;
G4bool fIsFirstStepOfTheEvent;
G4bool fIsFirstStepInTarget;
G4bool fIsFirstStepInScoringShell;
G4double fCubicVolumeScoringShell;
std::array< G4double, numberCombinations > fArraySumStepLengths;
// Array to collect the sum of step lengths in the scoring shell for the whole run,
// according to the various cases (kinematical region, scoring position and particle type).
// Note that the fluence in a scoring volume is defined as sum of step lengths
// in that scoring volume divided by the cubic-volume of that scoring volume.
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_lAr
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_Pb
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_PbWO4
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_POLYSTYRENE
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_Si
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100
@@ -0,0 +1,65 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file ActionInitialization.cc
/// \brief Implementation of the ActionInitialization class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
#include "SteppingAction.hh"
#include "Run.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization() : G4VUserActionInitialization() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::~ActionInitialization() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::BuildForMaster() const {
// This is NOT called in SEQ-mode, while in the MT-mode is called only for the Master thread.
SetUserAction( new RunAction );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::Build() const {
// This is called in the SEQ-mode and in the MT-mode only for Worker threads.
SetUserAction( new PrimaryGeneratorAction );
SteppingAction* steppingAction = new SteppingAction;
SetUserAction( steppingAction );
SetUserAction( new RunAction( steppingAction ) );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,219 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file DetectorConstruction.cc
/// \brief Implementation of the DetectorConstruction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "DetectorConstruction.hh"
#include "DetectorMessenger.hh"
#include "PrimaryGeneratorAction.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4Orb.hh"
#include "G4Sphere.hh"
#include "G4LogicalVolume.hh"
#include "G4ThreeVector.hh"
#include "G4PVPlacement.hh"
#include "globals.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4SolidStore.hh"
#include "G4RunManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction() :
fMaterial( nullptr ),
fExperimentalHall_log( nullptr ), fExperimentalHall_phys( nullptr ),
fLogicSphere( nullptr ), fPhysiSphere( nullptr ),
fLogicScoringShell( nullptr ), fPhysiScoringShell( nullptr ),
fDetectorMessenger( nullptr ),
fRadius( 1.0*CLHEP::m ) //***LOOKHERE*** Default values
{
//G4cout << " BEGIN DetectorConstruction::DetectorConstruction()" << G4endl;
fMaterial = G4NistManager::Instance()->FindOrBuildMaterial( "G4_Fe" ); //***LOOKHERE***
// Default material
fDetectorMessenger = new DetectorMessenger( this );
//G4cout << " END DetectorConstruction::DetectorConstruction()" << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction() {
delete fDetectorMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::Construct() {
//G4cout << " BEGIN DetectorConstruction::Construct()" << G4endl;
return ConstructSphere();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::ConstructSphere() {
//G4cout << " BEGIN DetectorConstruction::ConstructSphere()" << G4endl;
// Clean old geometry, if any.
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
// The target is a full solid sphere (G4Orb), positioned at the center, (0.0, 0.0, 0.0).
// The world volume (experimental hall) is a box 10% bigger than the sphere
// and it is filled of "G4_Galactic" material.
G4double expHall_x = 1.1*fRadius; // half dimension along x
G4double expHall_y = 1.1*fRadius; // half dimension along y
G4double expHall_z = 1.1*fRadius; // half dimension along z
G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial( "G4_Galactic" );
// Experimental hall
G4Box* experimentalHall_box = new G4Box( "expHall_box", expHall_x, expHall_y, expHall_z );
fExperimentalHall_log = new G4LogicalVolume( experimentalHall_box, // solid
vacuum, // material
"expHall_log", // name
0, // field manager
0, // sensitive detector
0 ); // user limits
fExperimentalHall_phys = new G4PVPlacement( 0, // rotation
G4ThreeVector(), // translation
"expHall", // name
fExperimentalHall_log, // logical volume
0, // mother physical volume
false, // boolean operation
0 ); // copy number
// Target sphere
G4Orb* solidSphere = new G4Orb( "solidSphere", // name
fRadius ); // outer radius
fLogicSphere = new G4LogicalVolume( solidSphere, // solid
fMaterial, // material
"logicSphere", // name
0, // field manager
0, // sensitive detector
0 ); // user limits
fPhysiSphere = new G4PVPlacement( 0, // rotation
G4ThreeVector(), // translation
"physiSphere", // name
fLogicSphere, // logical volume
fExperimentalHall_phys, // mother physical volume
false, // boolean operation
0 ); // copy number
// Scoring shell (a thin vacuum layer, immediately outside the target sphere)
G4Sphere* solidScoringShell = new G4Sphere( "solidScoringShell", // name
fRadius, // Inner radius (the radius
// of the target sphere)
fRadius + fScoringThickness, // Outer radius
0.0, // Starting Phi angle of the
// segment in radians
2.0*CLHEP::pi, // Delta Phi angle of the
// segment in radians
0.0, // Starting Theta angle of
// the segment in radians
CLHEP::pi ); // Delta Theta angle of the
// segment in radians
fLogicScoringShell = new G4LogicalVolume( solidScoringShell, // solid
vacuum, // material
"logicScoringShell", // name
0, // field manager
0, // sensitive detector
0 ); // user limits
fPhysiScoringShell = new G4PVPlacement( 0, // rotation
G4ThreeVector(), // translation
"physiScoringShell", // name
fLogicScoringShell, // logical volume
fExperimentalHall_phys, // mother physical volume
false, // boolean operation
0 ); // copy number
G4cout << G4endl
<< "DetectorConstruction::ConstructSphere() : " << G4endl
<< "\t World (box) size: " << G4endl
<< "\t \t x : -/+ " << expHall_x << " mm ;"
<< "\t y : -/+ " << expHall_y << " mm ;"
<< "\t z : -/+ " << expHall_z << " mm ;" << G4endl
<< G4endl << G4endl;
//G4cout << " END DetectorConstruction::ConstructSphere()
return fExperimentalHall_phys;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetMaterial( const G4String name ) {
fMaterial = G4NistManager::Instance()->FindOrBuildMaterial( name );
if ( fMaterial == nullptr ) {
G4cout << G4endl << G4endl
<< "WARNING: the name of the material has not been recognized!" << G4endl
<< " ===> the default * G4_Fe * will be used."
<< G4endl << G4endl;
fMaterial = G4NistManager::Instance()->FindOrBuildMaterial( "G4_Fe" );
}
if ( fLogicSphere ) fLogicSphere->SetMaterial( fMaterial );
//G4cout << " Absorber Material = " << logicSphere->GetMaterial()->GetName() << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::UpdateGeometry() {
//G4cout << " BEGIN DetectorConstruction::UpdateGeometry" << G4endl;
G4RunManager::GetRunManager()->ReinitializeGeometry();
PrintParameters();
// Update also the position of the gun
const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast< const PrimaryGeneratorAction* >
( G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction() );
if ( pPrimaryAction ) pPrimaryAction->SetGunPosition();
//G4cout << " END DetectorConstruction::UpdateGeometry" << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::PrintParameters() {
G4cout << G4endl << G4endl
<< " ------ DetectorConstruction::PrintParameters() ------ " << G4endl
<< " Material = " << fMaterial->GetName() << G4endl
<< " Radius = " << fRadius << " mm" << G4endl
<< " ScoringThickness = " << fScoringThickness << " mm" << G4endl
<< " -------------------------------------------------------- "
<< G4endl << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,91 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file DetectorMessenger.cc
/// \brief Implementation of the DetectorMessenger class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "DetectorMessenger.hh"
#include "DetectorConstruction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorMessenger::DetectorMessenger( DetectorConstruction* myDet ) : fDetector( myDet ) {
fDetectorDir = new G4UIdirectory( "/mydet/" );
fDetectorDir->SetGuidance( "Detector control." );
fMaterial = new G4UIcmdWithAString( "/mydet/material", this );
fMaterial->SetGuidance( "Choice of the material:" );
fMaterial->SetGuidance( " a Geant4 NIST material, e.g. G4_Fe " );
fMaterial->SetParameterName( "choiceMaterial", true );
fMaterial->SetDefaultValue( "G4_Fe" );
fMaterial->AvailableForStates( G4State_PreInit, G4State_Idle );
fRadius = new G4UIcmdWithADoubleAndUnit( "/mydet/radius", this );
fRadius->SetParameterName( "choiceRadius", true );
fRadius->SetGuidance( "Target sphere radius" );
fRadius->SetDefaultValue( 1000.0 ); // default: 1 meter.
fRadius->AvailableForStates( G4State_PreInit, G4State_Idle );
fUpdateCommand = new G4UIcmdWithoutParameter( "/mydet/update", this);
fUpdateCommand->SetGuidance( "Update geometry." );
fUpdateCommand->SetGuidance( "This command MUST be applied before \"beamOn\" " );
fUpdateCommand->SetGuidance( "if you changed geometrical value(s)." );
fUpdateCommand->AvailableForStates( G4State_Idle );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorMessenger::~DetectorMessenger() {
delete fDetectorDir;
delete fMaterial;
delete fRadius;
delete fUpdateCommand;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorMessenger::SetNewValue( G4UIcommand* command, G4String newValue ) {
if ( command == fMaterial ) {
fDetector->SetMaterial( newValue );
}
if ( command == fRadius ) {
fDetector->SetRadius( fRadius->GetNewDoubleValue( newValue ) );
}
if ( command == fUpdateCommand ) {
fDetector->UpdateGeometry();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,76 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file PrimaryGeneratorAction.cc
/// \brief Implementation of the PrimaryGeneratorAction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "PrimaryGeneratorAction.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "globals.hh"
#include "G4SystemOfUnits.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction(),
fParticleGun( nullptr ) {
G4int n_particle = 1;
fParticleGun = new G4ParticleGun( n_particle );
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
//***LOOKHERE*** Default particle and energy
fParticleGun->SetParticleDefinition( particleTable->FindParticle( "geantino" ) );
fParticleGun->SetParticleEnergy( 10.0*GeV );
SetGunPosition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::~PrimaryGeneratorAction() {
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorAction::SetGunPosition() const {
// Shoot the particle from the center of the sphere
fParticleGun->SetParticlePosition( G4ThreeVector( 0.0, 0.0, 0.0 ) );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorAction::GeneratePrimaries( G4Event* anEvent ) {
G4ThreeVector v( 0.0, 0.0, 1.0 ); //***LOOKHERE*** default shoot along the z-axis
fParticleGun->SetParticleMomentumDirection( v );
fParticleGun->GeneratePrimaryVertex( anEvent );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,130 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file Run.cc
/// \brief Implementation of the Run class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "Run.hh"
#include "G4SystemOfUnits.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Run::Run() : G4Run(), fNumEvents( 0 ),
fPrimaryParticleId( 0 ), fPrimaryParticleEnergy( 0.0 ),
fPrimaryParticleDirection( G4ThreeVector( 0.0, 0.0, 0.0 ) ),
fTargetMaterialName( "" ), fCubicVolumeScoringShell( 1.0 )
{
for ( G4int i = 0; i < SteppingAction::numberCombinations; ++i ) fArray[i] = 0.0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Run::~Run() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Run::RecordEvent( const G4Event* anEvent ) {
// This method is called automatically by the Geant4 kernel (not by the user!) at the end
// of each event : in MT-mode, it is called only for the working thread that handled the event.
G4int nEvt = anEvent->GetEventID();
if ( nEvt % 10 == 0 ) G4cout << " Event#=" << nEvt << G4endl;
G4Run::RecordEvent( anEvent );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Run::Merge( const G4Run* aRun ) {
// This method is called automatically by the Geant4 kernel (not by the user!) only in the case
// of multithreaded mode and only for working threads.
const Run* localRun = static_cast< const Run* >( aRun );
fPrimaryParticleId = localRun->getPrimaryParticleId();
fPrimaryParticleEnergy = localRun->getPrimaryParticleEnergy();
fPrimaryParticleDirection = localRun->getPrimaryParticleDirection();
fTargetMaterialName = localRun->getTargetMaterialName();
fCubicVolumeScoringShell = localRun->getCubicVolumeScoringShell();
fNumEvents += localRun->GetNumberOfEvent();
for ( G4int i = 0; i < SteppingAction::numberCombinations; ++i ) {
fArray[i] += localRun->getArray()[i];
}
G4Run::Merge( aRun );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Run::printInfo() const {
// This method is called by RunAction::EndOfRunAction. In MT-mode, only the master thread
// calls it.
const G4double floatingNumberOfEvents =
std::max( 1.0, fNumEvents > 0 ? fNumEvents*1.0 : GetNumberOfEvent()*1.0 );
// The fluence in the scoring shell is defined as sum of step lengths in that shell
// divided by the cubic-volume of that scoring shell.
const G4double conversionFactor = CLHEP::cm * CLHEP::cm; // From mm^-2 to cm^-2
const G4double factor =
conversionFactor / ( 0.5*fCubicVolumeScoringShell*floatingNumberOfEvents );
G4cout << std::setprecision(6) << G4endl << G4endl
<< " =============== Run::printInfo() =============== \t RunID = " << GetRunID()
<< G4endl
<< " Primary particle PDG code = " << fPrimaryParticleId << G4endl
<< " Primary particle kinetic energy = " << fPrimaryParticleEnergy / CLHEP::GeV
<< " GeV" << G4endl
<< " Primary particle direction = " << fPrimaryParticleDirection << G4endl
<< " Target material = " << fTargetMaterialName << G4endl
<< " Cubic-volume scoring shell = " << fCubicVolumeScoringShell << " mm^3" << G4endl
<< " Number of events = " << floatingNumberOfEvents << G4endl
<< " Conversion factor: fluence from mm^-2 to cm^-2 = " << conversionFactor << G4endl
<< " Particle fluence in unit of cm^-2 :" << G4endl;
for ( G4int i = 0; i < SteppingAction::numberKinematicRegions; ++i ) {
for ( G4int j = 0; j < SteppingAction::numberScoringPositions; ++j ) {
for ( G4int k = 0; k < SteppingAction::numberParticleTypes; ++k ) {
G4int index = SteppingAction::getIndex( i, j, k );
//G4cout << "(i, j, k )=(" << i << ", " << j << ", " << k << ") ->" << index;
G4cout << " case=" << std::setw(3) << index
<< " " << std::setw(12) << SteppingAction::arrayKinematicRegionNames[i]
<< " " << std::setw(12) << SteppingAction::arrayScoringPositionNames[j]
<< " " << std::setw(12) << SteppingAction::arrayParticleTypeNames[k]
<< " " << factor*fArray[index] << G4endl;
}
}
}
G4cout << " ============================================================= " << G4endl << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Run::setArray( const std::array< G4double,
SteppingAction::numberCombinations >& inputArray ) {
for ( G4int i = 0; i < SteppingAction::numberCombinations; ++i ) {
fArray[i] = inputArray[i];
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,75 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file RunAction.cc
/// \brief Implementation of the RunAction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "RunAction.hh"
#include "globals.hh"
#include "G4Run.hh"
#include "Run.hh"
#include "SteppingAction.hh"
#include "G4RunManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::RunAction( SteppingAction* steppingAction ) :
G4UserRunAction(), fSteppingAction( steppingAction ) {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::~RunAction() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4Run* RunAction::GenerateRun() {
return new Run;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::BeginOfRunAction( const G4Run* aRun ) {
G4cout << "### Run " << aRun->GetRunID() << " starts." << G4endl;
if ( fSteppingAction ) {
fSteppingAction->initialize();
Run* run = const_cast< Run* >( static_cast< const Run* >( aRun ) );
if ( run != nullptr ) fSteppingAction->setRunPointer( run );
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EndOfRunAction( const G4Run* aRun ) {
const Run* run = static_cast< const Run* >( aRun );
if ( run == nullptr || run->GetNumberOfEvent() == 0 ) return;
if ( IsMaster() ) run->printInfo();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,203 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file SteppingAction.cc
/// \brief Implementation of the SteppingAction class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "SteppingAction.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleTypes.hh"
#include "G4IonTable.hh"
#include "G4StepPoint.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VTouchable.hh"
#include "G4TouchableHistory.hh"
#include "G4VSolid.hh"
#include "G4LossTableManager.hh"
#include "G4SystemOfUnits.hh"
#include "Run.hh"
const std::array< G4String, SteppingAction::numberKinematicRegions >
SteppingAction::arrayKinematicRegionNames = { "", "below 20 MeV", "above 20 MeV" };
const std::array< G4String, SteppingAction::numberScoringPositions >
SteppingAction::arrayScoringPositionNames = { "forward", "backward" };
const std::array< G4String, SteppingAction::numberParticleTypes >
SteppingAction::arrayParticleTypeNames = { "all", "electron", "gamma", "muon", "neutrino",
"pion", "neutron", "proton", "ion", "otherMeson",
"otherBaryon" };
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4int SteppingAction::getIndex( const G4int iKinematicRegion, const G4int iScoringPosition,
const G4int iParticleType ) {
G4int index = -1;
if ( iKinematicRegion >= 0 && iKinematicRegion < numberKinematicRegions &&
iScoringPosition >= 0 && iScoringPosition < numberScoringPositions &&
iParticleType >= 0 && iParticleType < numberParticleTypes ) {
index = iKinematicRegion * numberScoringPositions * numberParticleTypes +
iScoringPosition * numberParticleTypes +
iParticleType;
}
return index;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SteppingAction::SteppingAction() :G4UserSteppingAction() {
initialize();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SteppingAction::~SteppingAction() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SteppingAction::initialize() {
// Initialization needed at the beginning of each Run
fPrimaryParticleId = 0;
fPrimaryParticleEnergy = 0.0;
fPrimaryParticleDirection = G4ThreeVector( 0.0, 0.0, 1.0 );
fTargetMaterialName = "";
fIsFirstStepOfTheEvent = true;
fIsFirstStepInTarget = true;
fIsFirstStepInScoringShell = true;
fCubicVolumeScoringShell = 1.0;
for ( G4int i = 0; i < numberCombinations; ++i ) {
fArraySumStepLengths[i] = 0.0;
}
/*
for ( G4int i = 0; i < numberCombinations; ++i ) fArraySumStepLengths[i] = 999.9;
G4cout << " numberCombinations=" << numberCombinations << G4endl;
for ( G4int i = 0; i < numberKinematicRegions; ++i ) {
for ( G4int j = 0; j < numberScoringPositions; ++j ) {
for ( G4int k = 0; k < numberParticleTypes; ++k ) {
G4int index = getIndex( i, j, k );
G4cout << "(i, j, k)=(" << i << ", " << j << ", " << k << ") ->" << index;
if ( fArraySumStepLengths[ index ] < 1.0 ) G4cout << " <=== REPEATED!";
else fArraySumStepLengths[ index ] = 0.0;
G4cout << G4endl;
}
}
}
for ( G4int i = 0; i < numberCombinations; ++i ) {
if ( fArraySumStepLengths[i] > 999.0 ) G4cout << " i=" << i << " NOT COVERED !" << G4endl;
}
*/
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SteppingAction::UserSteppingAction( const G4Step* theStep ) {
// Get information on the primary particle
if ( fIsFirstStepOfTheEvent ) {
if ( theStep->GetTrack()->GetParentID() == 0 ) {
fPrimaryParticleId = theStep->GetTrack()->GetDefinition()->GetPDGEncoding();
fPrimaryParticleEnergy = theStep->GetPreStepPoint()->GetKineticEnergy();
fPrimaryParticleDirection = theStep->GetPreStepPoint()->GetMomentumDirection();
if ( fRunPtr ) {
fRunPtr->setPrimaryParticleId( fPrimaryParticleId );
fRunPtr->setPrimaryParticleEnergy( fPrimaryParticleEnergy );
fRunPtr->setPrimaryParticleDirection( fPrimaryParticleDirection );
}
fIsFirstStepOfTheEvent = false;
}
}
// Get information on the target material
if ( fIsFirstStepInTarget &&
theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "physiSphere" ) {
fTargetMaterialName = theStep->GetPreStepPoint()->GetMaterial()->GetName();
if ( fRunPtr ) fRunPtr->setTargetMaterialName( fTargetMaterialName );
fIsFirstStepInTarget = false;
}
// Get information on step lengths in the scoring shell
if ( theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "physiScoringShell" ) {
if ( fIsFirstStepInScoringShell ) {
fCubicVolumeScoringShell =
theStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume();
if ( fRunPtr ) fRunPtr->setCubicVolumeScoringShell( fCubicVolumeScoringShell );
fIsFirstStepInScoringShell = false;
}
G4double stepLength = theStep->GetTrack()->GetStepLength() * theStep->GetTrack()->GetWeight();
G4int absPdg = theStep->GetTrack()->GetDefinition() == nullptr ? 0 :
std::abs( theStep->GetTrack()->GetDefinition()->GetPDGEncoding() );
/*
G4cout << theStep->GetTrack()->GetDefinition()->GetParticleName() << " absPdg=" << absPdg
<< " Ekin[MeV]=" << theStep->GetPreStepPoint()->GetKineticEnergy()
<< " r[mm]=" << theStep->GetTrack()->GetPosition().mag()
<< " z[mm]=" << theStep->GetTrack()->GetPosition().z()
<< " " << theStep->GetTrack()->GetVolume()->GetName()
<< " " << theStep->GetTrack()->GetMaterial()->GetName()
<< " L[mm]=" << stepLength << " "
<< ( fPrimaryParticleDirection.dot( theStep->GetTrack()->GetPosition().unit() ) > 0.0
? "forward" : "backward" ) << G4endl;
*/
// Three kinematical regions: [0] : any value ; [1] : below 20 MeV ; [2] : above 20 MeV
G4int iKinematicRegion = theStep->GetPreStepPoint()->GetKineticEnergy() < 20.0 ? 1 : 2;
// Two scoring positions: [0] : forward hemisphere ; [1] : backward hemisphere
// (with respect to the primary particle initial direction)
G4int iScoringPosition =
fPrimaryParticleDirection.dot( theStep->GetTrack()->GetPosition().unit() ) > 0.0 ? 0 : 1;
G4int iParticleType = -1;
if ( absPdg == 11 ) iParticleType = 1; // electron (and positron)
else if ( absPdg == 22 ) iParticleType = 2; // gamma
else if ( absPdg == 13 ) iParticleType = 3; // muons (mu- and mu+)
else if ( absPdg == 12 || absPdg == 14 || absPdg == 16 ) iParticleType = 4; // neutrinos (and
// anti-neutrinos), all flavors
else if ( absPdg == 111 || absPdg == 211 ) iParticleType = 5; // (charged) pions
else if ( absPdg == 2112 ) iParticleType = 6; // neutron (and anti-neutron)
else if ( absPdg == 2212 ) iParticleType = 7; // proton (and anti-proton)
else if ( G4IonTable::IsIon( theStep->GetTrack()->GetDefinition() ) || // ions (and anti-ions)
G4IonTable::IsAntiIon( theStep->GetTrack()->GetDefinition() ) ) iParticleType = 8;
else if ( absPdg < 1000 ) iParticleType = 9; // other mesons (e.g. kaons) (Note: this works
// in most cases, but not always!)
else if ( absPdg > 1000 ) iParticleType = 10; // other baryons (e.g. hyperons, anti-hyperons,
// etc.)
// Consider the specific case : kinematic region, scoring position, and particle type
G4int index = getIndex( iKinematicRegion, iScoringPosition, iParticleType );
fArraySumStepLengths[index] += stepLength;
// Consider the "all" particle case, with the same kinematic region and scoring position
index = getIndex( iKinematicRegion, iScoringPosition, 0 );
fArraySumStepLengths[index] += stepLength;
// Consider the "any" kinematic region case, with the same scoring position and particle type
index = getIndex( 0, iScoringPosition, iParticleType );
fArraySumStepLengths[index] += stepLength;
// Consider the "any" kinematic region and "all" particle, with the same scoring position
index = getIndex( 0, iScoringPosition, 0 );
fArraySumStepLengths[index] += stepLength;
if ( fRunPtr ) fRunPtr->setArray( fArraySumStepLengths );
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+10
View File
@@ -0,0 +1,10 @@
/random/setSavingFlag 1
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mydet/material G4_W
/mydet/radius 100.0 cm
/run/initialize
/gun/particle pi-
/gun/energy 50 GeV
/run/beamOn 100