Import Geant4 11.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2021-12-12 17:16:06 +01:00
parent 80e2389dd8
commit 84f33a068c
593 changed files with 68589 additions and 1 deletions
+10
View File
@@ -0,0 +1,10 @@
# - add tests components
add_subdirectory(g4pytest)
add_subdirectory(gtest01)
add_subdirectory(gtest02)
add_subdirectory(gtest03)
add_subdirectory(gtest04)
add_subdirectory(gtest05)
add_subdirectory(gtest06)
add_subdirectory(gtest07)
add_subdirectory(gtest08)
+57
View File
@@ -0,0 +1,57 @@
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
Category History file
---------------------
A set of tests for python wrapping of C++ elements.
----------------------------------------------------------
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
Nov.30, 2008 K.Murakami
- gtest01-07: modified with g4py namespace
Aug.07, 2007 K.Murakami
- gtest06 is added.
- gtest07 is added.
Jul.10, 2007 K.Murakami
- gtest05 is added.
Aug.07, 2006 K.Murakami
- gtest04 is added.
Oct.05, 2005 K.Murakami
- test13 is added.
Aug.31, 2005 K.Murakami
- gtest03 is added.
Aug.28, 2005 K.Murakami
- gtest02 is added.
Aug.24, 2005 K.Murakami
- test12 is added.
Aug.09, 2005 K.Murakami
- test11 is added.
Jun.22, 2005 K.Murakami
- gtest00 is removed
Jun.15, 2005 K.Murakami
- test10 is added.
Jun.14, 2005 K.Murakami
- test00- test09 are finished.
- gtest00 is closed.
- gtest01 is launched for Geant4Py basic tests
May 18, 2005 K.Murakami
- just created.
+45
View File
@@ -0,0 +1,45 @@
Test Modules
============
This module collects a set of tests for python wrapping of C++ elements.
>**Notes:** <br>
"*testXX*" directories contain tests without Geant4 package. <br>
"*gtestXX*" directories contain tests with Geant4 package.
Basic tests
-----------
| Test | Description |
|:------:|-------------
|test00 | hallo world
|test01 | simple class wrapping
|test02 | simple inheritance
|test03 | singleton w/o public constructor <br> can NOT be compiled.
|test04 | call policies
|test05 | function overloading & default arguments
|test06 | python inheritance from base class
|test07 | enums
|test08 | static member function
|test09 | operators
|test10 | call by-reference
|test11 | no_init
|test12 | indexing a STL vector
|test13 | test for a list argument/return
Function tests
--------------
| Test | Description |
|:------:|-------------
|gtest01 | user application
|gtest02 | test for using site-module packages
|gtest03 | test for EZsim package
|gtest04 | test for getting command tree and command information
|gtest05 | test for constructing CSG geometries in Python
|gtest06 | test for constructing/visualizing boolean geoemtries
|gtest07 | test for checking overlapped geometries
@@ -0,0 +1,35 @@
# - Function to build the C++ modules
function(g4pytest_add_module _TARGET)
g4py_add_module(${_TARGET} ${ARGN})
# Filthy temp hack for submodule paths....
string(REGEX REPLACE "^_" "" _SUBMODULE "${_TARGET}")
set_property(TARGET ${_TARGET} APPEND_STRING PROPERTY LIBRARY_OUTPUT_DIRECTORY "/g4pytest/${_SUBMODULE}")
foreach(_conftype ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${_conftype} _conftype_uppercase)
set_property(TARGET ${_TARGET} APPEND_STRING PROPERTY LIBRARY_OUTPUT_DIRECTORY_${_conftype_uppercase} "/g4pytest/${_SUBMODULE}")
endforeach()
endfunction()
# - add libs components
add_subdirectory(ExN01geom)
add_subdirectory(ExN03geom)
add_subdirectory(Qgeom)
add_subdirectory(ezgeom)
add_subdirectory(NISTmaterials)
add_subdirectory(Qmaterials)
add_subdirectory(EMSTDpl)
add_subdirectory(ExN01pl)
add_subdirectory(MedicalBeam)
add_subdirectory(ParticleGun)
# Remainder are pure python
# Copy/configure pure python components
file(GLOB_RECURSE PY_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py)
foreach(_pyfile ${PY_FILES})
file(GENERATE
OUTPUT ${GEANT4_PYTHON_OUTPUT_DIR}/g4pytest/${_pyfile}
INPUT ${CMAKE_CURRENT_SOURCE_DIR}/${_pyfile}
)
endforeach()
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _EMSTDpl)
g4pytest_add_module(${_TARGET} PhysicsListEMstd.cc pyEMSTDpl.cc)
target_link_libraries(${_TARGET} PRIVATE G4particles G4processes G4run)
@@ -0,0 +1,133 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// PhysicsListEMstd.cc
//
// 2006 Q
// ====================================================================
#include "PhysicsListEMstd.hh"
#include "G4SystemOfUnits.hh"
#include "G4ProcessManager.hh"
#include "G4ParticleDefinition.hh"
#include "G4Gamma.hh"
#include "G4Electron.hh"
#include "G4Positron.hh"
#include "G4ComptonScattering.hh"
#include "G4GammaConversion.hh"
#include "G4PhotoElectricEffect.hh"
#include "G4eMultipleScattering.hh"
#include "G4eIonisation.hh"
#include "G4eBremsstrahlung.hh"
#include "G4eplusAnnihilation.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////
PhysicsListEMstd::PhysicsListEMstd()
////////////////////////////////////
{
SetVerboseLevel(1);
defaultCutValue = 1.*mm; // default cut value (1.0mm)
}
/////////////////////////////////////
PhysicsListEMstd::~PhysicsListEMstd()
/////////////////////////////////////
{
}
//////////////////////////////////////////
void PhysicsListEMstd::ConstructParticle()
//////////////////////////////////////////
{
G4Gamma::GammaDefinition();
G4Electron::ElectronDefinition();
G4Positron::PositronDefinition();
}
/////////////////////////////////////////
void PhysicsListEMstd::ConstructProcess()
/////////////////////////////////////////
{
AddTransportation();
G4ProcessManager* pm;
// ----------------------------------------------------------
// gamma physics
// ----------------------------------------------------------
pm= G4Gamma::Gamma()-> GetProcessManager();
pm-> AddDiscreteProcess(new G4PhotoElectricEffect);
pm-> AddDiscreteProcess(new G4ComptonScattering);
pm-> AddDiscreteProcess(new G4GammaConversion);
// ----------------------------------------------------------
// electron physics
// ----------------------------------------------------------
G4eMultipleScattering* msc= new G4eMultipleScattering;
G4eIonisation* eion= new G4eIonisation;
G4eBremsstrahlung* ebrems= new G4eBremsstrahlung;
pm= G4Electron::Electron()->GetProcessManager();
pm-> AddProcess(msc, ordInActive, 1, 1);
pm-> AddProcess(eion, ordInActive, 2, 2);
pm-> AddProcess(ebrems, ordInActive, ordInActive, 3);
// ----------------------------------------------------------
// positron physics
// ----------------------------------------------------------
msc= new G4eMultipleScattering;
eion= new G4eIonisation;
ebrems= new G4eBremsstrahlung;
G4eplusAnnihilation* annihilation= new G4eplusAnnihilation;
pm= G4Positron::Positron()-> GetProcessManager();
pm-> AddProcess(msc, ordInActive, 1, 1);
pm-> AddProcess(eion, ordInActive, 2, 2);
pm-> AddProcess(ebrems, ordInActive, ordInActive, 3);
pm-> AddProcess(annihilation, 0, ordInActive, 4);
}
////////////////////////////////
void PhysicsListEMstd::SetCuts()
////////////////////////////////
{
SetCutsWithDefault();
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// PhysicsListEMstd.hh
//
// Physics list for electron/positron/gamma
// EM-standard package
//
// 2006 Q
// ====================================================================
#ifndef PHYSICS_LIST_EMSTD_H
#define PHYSICS_LIST_EMSTD_H
#include "G4VUserPhysicsList.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class PhysicsListEMstd: public G4VUserPhysicsList {
public:
PhysicsListEMstd();
~PhysicsListEMstd();
virtual void ConstructParticle();
virtual void ConstructProcess();
virtual void SetCuts();
};
#endif
@@ -0,0 +1 @@
from ._EMSTDpl import *
@@ -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. *
// ********************************************************************
//
// ====================================================================
// pyEMSTDpl.cc
//
// [Qgeom]
// a site-module of Geant4Py
//
// Electron/Gamma EM-standard physics list
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "G4RunManager.hh"
#include "PhysicsListEMstd.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyEMSTDpl {
PhysicsListEMstd* Construct()
{
PhysicsListEMstd* pl= new PhysicsListEMstd;
G4RunManager* runMgr= G4RunManager::GetRunManager();
runMgr-> SetUserInitialization(pl);
return pl;
}
}
using namespace pyEMSTDpl;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_EMSTDpl) {
class_<PhysicsListEMstd, PhysicsListEMstd*, bases<G4VUserPhysicsList> >
("PhysicsListEMstd", "Electron/Gamma EM-standard physics list")
;
// ---
def("Construct", Construct,
return_value_policy<reference_existing_object>());
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _ExN01geom)
g4pytest_add_module(${_TARGET} ExN01DetectorConstruction.cc pyExN01geom.cc)
target_link_libraries(${_TARGET} PRIVATE G4materials G4geometry G4run)
@@ -0,0 +1,155 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// ExN01DetectorConstruction.cc
//
// 2005 Q
// ====================================================================
#include "ExN01DetectorConstruction.hh"
#include "G4Material.hh"
#include "G4Box.hh"
#include "G4Tubs.hh"
#include "G4LogicalVolume.hh"
#include "G4ThreeVector.hh"
#include "G4PVPlacement.hh"
#include "G4SystemOfUnits.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////////////////////
ExN01DetectorConstruction::ExN01DetectorConstruction()
: experimentalHall_log(0), tracker_log(0),
calorimeterBlock_log(0), calorimeterLayer_log(0),
experimentalHall_phys(0), calorimeterLayer_phys(0),
calorimeterBlock_phys(0), tracker_phys(0)
//////////////////////////////////////////////////////
{
}
///////////////////////////////////////////////////////
ExN01DetectorConstruction::~ExN01DetectorConstruction()
///////////////////////////////////////////////////////
{
}
/////////////////////////////////////////////////////////
G4VPhysicalVolume* ExN01DetectorConstruction::Construct()
/////////////////////////////////////////////////////////
{
//------------------------------------------------------ materials
G4double a; // atomic mass
G4double z; // atomic number
G4double density;
G4Material* Ar =
new G4Material("ArgonGas", z= 18., a= 39.95*g/mole, density= 1.782*mg/cm3);
G4Material* Al =
new G4Material("Aluminum", z= 13., a= 26.98*g/mole, density= 2.7*g/cm3);
G4Material* Pb =
new G4Material("Lead", z= 82., a= 207.19*g/mole, density= 11.35*g/cm3);
//------------------------------------------------------ volumes
//------------------------------ experimental hall (world volume)
//------------------------------ beam line along x axis
G4double expHall_x = 3.0*m;
G4double expHall_y = 1.0*m;
G4double expHall_z = 1.0*m;
G4Box* experimentalHall_box
= new G4Box("expHall_box",expHall_x,expHall_y,expHall_z);
experimentalHall_log = new G4LogicalVolume(experimentalHall_box,
Ar,"expHall_log",0,0,0);
experimentalHall_phys = new G4PVPlacement(0,G4ThreeVector(),
experimentalHall_log,
"expHall",0,false,0);
//------------------------------ a tracker tube
G4double innerRadiusOfTheTube = 0.*cm;
G4double outerRadiusOfTheTube = 60.*cm;
G4double hightOfTheTube = 50.*cm;
G4double startAngleOfTheTube = 0.*deg;
G4double spanningAngleOfTheTube = 360.*deg;
G4Tubs* tracker_tube = new G4Tubs("tracker_tube",innerRadiusOfTheTube,
outerRadiusOfTheTube,hightOfTheTube,
startAngleOfTheTube,
spanningAngleOfTheTube);
tracker_log = new G4LogicalVolume(tracker_tube,Al,"tracker_log",0,0,0);
G4double trackerPos_x = -1.0*m;
G4double trackerPos_y = 0.*m;
G4double trackerPos_z = 0.*m;
tracker_phys = new G4PVPlacement(0,
G4ThreeVector(trackerPos_x,trackerPos_y,trackerPos_z),
tracker_log,"tracker",experimentalHall_log,false,0);
//------------------------------ a calorimeter block
G4double block_x = 1.0*m;
G4double block_y = 50.0*cm;
G4double block_z = 50.0*cm;
G4Box* calorimeterBlock_box = new G4Box("calBlock_box",block_x,
block_y,block_z);
calorimeterBlock_log = new G4LogicalVolume(calorimeterBlock_box,
Pb,"caloBlock_log",0,0,0);
G4double blockPos_x = 1.0*m;
G4double blockPos_y = 0.0*m;
G4double blockPos_z = 0.0*m;
calorimeterBlock_phys = new G4PVPlacement(0,
G4ThreeVector(blockPos_x,blockPos_y,blockPos_z),
calorimeterBlock_log,"caloBlock",experimentalHall_log,false,0);
//------------------------------ calorimeter layers
G4double calo_x = 1.*cm;
G4double calo_y = 40.*cm;
G4double calo_z = 40.*cm;
G4Box* calorimeterLayer_box = new G4Box("caloLayer_box",
calo_x,calo_y,calo_z);
calorimeterLayer_log = new G4LogicalVolume(calorimeterLayer_box,
Al,"caloLayer_log",0,0,0);
for(G4int i=0;i<19;i++) // loop for 19 layers
{
G4double caloPos_x = (i-9)*10.*cm;
G4double caloPos_y = 0.0*m;
G4double caloPos_z = 0.0*m;
calorimeterLayer_phys = new G4PVPlacement(0,
G4ThreeVector(caloPos_x,caloPos_y,caloPos_z),
calorimeterLayer_log,"caloLayer",calorimeterBlock_log,false,i);
}
//------------------------------------------------------------------
return experimentalHall_phys;
}
@@ -0,0 +1,73 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// ExN01DetectorConstruction.hh
//
// 2005 Q
// ====================================================================
#ifndef EXN01_DETECTOR_CONSTRUCTION_H
#define EXN01_DETECTOR_CONSTRUCTION_H
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4LogicalVolume;
class G4VPhysicalVolume;
#include "G4VUserDetectorConstruction.hh"
class ExN01DetectorConstruction : public G4VUserDetectorConstruction {
public:
ExN01DetectorConstruction();
~ExN01DetectorConstruction();
G4VPhysicalVolume* Construct();
private:
// Logical volumes
//
G4LogicalVolume* experimentalHall_log;
G4LogicalVolume* tracker_log;
G4LogicalVolume* calorimeterBlock_log;
G4LogicalVolume* calorimeterLayer_log;
// Physical volumes
//
G4VPhysicalVolume* experimentalHall_phys;
G4VPhysicalVolume* calorimeterLayer_phys;
G4VPhysicalVolume* calorimeterBlock_phys;
G4VPhysicalVolume* tracker_phys;
};
#endif
@@ -0,0 +1 @@
from ._ExN01geom import *
@@ -0,0 +1,71 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyExN01geom.cc
//
// [Qgeom]
// a site-module of Geant4Py
//
// geometry presented in ExN01 of Geant4 example
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "G4RunManager.hh"
#include "ExN01DetectorConstruction.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyExN03geom {
void Construct()
{
G4RunManager* runMgr= G4RunManager::GetRunManager();
runMgr-> SetUserInitialization(new ExN01DetectorConstruction);
}
}
using namespace pyExN03geom;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_ExN01geom) {
class_<ExN01DetectorConstruction, ExN01DetectorConstruction*,
bases<G4VUserDetectorConstruction> >
("ExN01DetectorConstruction", "ExN01 detector")
;
// ---
def("Construct", Construct);
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _ExN01pl)
g4pytest_add_module(${_TARGET} ExN01PhysicsList.cc pyExN01pl.cc)
target_link_libraries(${_TARGET} PRIVATE G4particles G4processes G4run)
@@ -0,0 +1,77 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// ExN01PhysicsList.cc
//
// 2005 Q
// ====================================================================
#include "ExN01PhysicsList.hh"
#include "G4ParticleTypes.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////
ExN01PhysicsList::ExN01PhysicsList()
////////////////////////////////////
{
}
/////////////////////////////////////
ExN01PhysicsList::~ExN01PhysicsList()
/////////////////////////////////////
{
}
//////////////////////////////////////////
void ExN01PhysicsList::ConstructParticle()
//////////////////////////////////////////
{
G4Geantino::GeantinoDefinition();
}
/////////////////////////////////////////
void ExN01PhysicsList::ConstructProcess()
/////////////////////////////////////////
{
AddTransportation();
}
////////////////////////////////
void ExN01PhysicsList::SetCuts()
////////////////////////////////
{
G4int temp = GetVerboseLevel();
SetVerboseLevel(0);
SetCutsWithDefault();
SetVerboseLevel(temp);
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// ExN01PhysicsList.hh
//
// 2005 Q
// ====================================================================
#ifndef EXN01_PHYSICS_LIST_H
#define EXN01_PHYSICS_LIST_H
#include "G4VUserPhysicsList.hh"
#include "globals.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class ExN01PhysicsList: public G4VUserPhysicsList {
public:
ExN01PhysicsList();
~ExN01PhysicsList();
protected:
// Construct particle and physics process
void ConstructParticle();
void ConstructProcess();
void SetCuts();
};
#endif
@@ -0,0 +1 @@
from ._ExN01pl import *
@@ -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. *
// ********************************************************************
//
// ====================================================================
// pyExN01pl.cc
//
// [ExN01pl]
// a site-module of Geant4Py
//
// minimal physics list, which is presnted in ExN01 of Geant4 example
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "G4RunManager.hh"
#include "ExN01PhysicsList.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyExN01pl {
ExN01PhysicsList* Construct()
{
ExN01PhysicsList* pl= new ExN01PhysicsList;
G4RunManager* runMgr= G4RunManager::GetRunManager();
runMgr-> SetUserInitialization(pl);
return pl;
}
}
using namespace pyExN01pl;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_ExN01pl) {
class_<ExN01PhysicsList, ExN01PhysicsList*, bases<G4VUserPhysicsList> >
("ExN01PhysicsList", "ExN01 physics list")
;
// ---
def("Construct", Construct,
return_value_policy<reference_existing_object>());
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _ExN03geom)
g4pytest_add_module(${_TARGET} ExN03DetectorConstruction.cc ExN03DetectorMessenger.cc pyExN03geom.cc)
target_link_libraries(${_TARGET} PRIVATE G4materials G4geometry G4run)
@@ -0,0 +1,473 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03DetectorConstruction.hh"
#include "ExN03DetectorMessenger.hh"
#include "G4Material.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4UniformMagField.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4SolidStore.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorConstruction::ExN03DetectorConstruction()
:AbsorberMaterial(0),GapMaterial(0),defaultMaterial(0),
solidWorld(0),logicWorld(0),physiWorld(0),
solidCalor(0),logicCalor(0),physiCalor(0),
solidLayer(0),logicLayer(0),physiLayer(0),
solidAbsorber(0),logicAbsorber(0),physiAbsorber(0),
solidGap (0),logicGap (0),physiGap (0),
magField(0)
{
// default parameter values of the calorimeter
AbsorberThickness = 10.*mm;
GapThickness = 5.*mm;
NbOfLayers = 10;
CalorSizeYZ = 10.*cm;
ComputeCalorParameters();
// materials
DefineMaterials();
SetAbsorberMaterial("Lead");
SetGapMaterial("liquidArgon");
// create commands for interactive definition of the calorimeter
detectorMessenger = new ExN03DetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorConstruction::~ExN03DetectorConstruction()
{ delete detectorMessenger;}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* ExN03DetectorConstruction::Construct()
{
return ConstructCalorimeter();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::DefineMaterials()
{
//This function illustrates the possible ways to define materials
G4String symbol; //a=mass of a mole;
G4double a, z, density; //z=mean number of protons;
G4int iz, n; //iz=number of protons in an isotope;
// n=number of nucleons in an isotope;
G4int ncomponents, natoms;
G4double abundance, fractionmass;
//
// define Elements
//
G4Element* H = new G4Element("Hydrogen",symbol="H" , z= 1., a= 1.01*g/mole);
G4Element* C = new G4Element("Carbon" ,symbol="C" , z= 6., a= 12.01*g/mole);
G4Element* N = new G4Element("Nitrogen",symbol="N" , z= 7., a= 14.01*g/mole);
G4Element* O = new G4Element("Oxygen" ,symbol="O" , z= 8., a= 16.00*g/mole);
G4Element* Si = new G4Element("Silicon",symbol="Si" , z= 14., a= 28.09*g/mole);
//
// define an Element from isotopes, by relative abundance
//
G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
G4Element* U = new G4Element("enriched Uranium",symbol="U",ncomponents=2);
U->AddIsotope(U5, abundance= 90.*perCent);
U->AddIsotope(U8, abundance= 10.*perCent);
//
// define simple materials
//
new G4Material("Aluminium", z=13., a=26.98*g/mole, density=2.700*g/cm3);
new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
new G4Material("Lead" , z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
//
// define a material from elements. case 1: chemical molecule
//
G4Material* H2O =
new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
H2O->AddElement(H, natoms=2);
H2O->AddElement(O, natoms=1);
// overwrite computed meanExcitationEnergy with ICRU recommended value
H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
G4Material* Sci =
new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
Sci->AddElement(C, natoms=9);
Sci->AddElement(H, natoms=10);
G4Material* Myl =
new G4Material("Mylar", density= 1.397*g/cm3, ncomponents=3);
Myl->AddElement(C, natoms=10);
Myl->AddElement(H, natoms= 8);
Myl->AddElement(O, natoms= 4);
G4Material* SiO2 =
new G4Material("quartz",density= 2.200*g/cm3, ncomponents=2);
SiO2->AddElement(Si, natoms=1);
SiO2->AddElement(O , natoms=2);
//
// define a material from elements. case 2: mixture by fractional mass
//
G4Material* Air =
new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
Air->AddElement(N, fractionmass=0.7);
Air->AddElement(O, fractionmass=0.3);
//
// define a material from elements and/or others materials (mixture of mixtures)
//
G4Material* Aerog =
new G4Material("Aerogel", density= 0.200*g/cm3, ncomponents=3);
Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
Aerog->AddElement (C , fractionmass= 0.1*perCent);
//
// examples of gas in non STP conditions
//
G4Material* CO2 =
new G4Material("CarbonicGas", density= 27.*mg/cm3, ncomponents=2,
kStateGas, 325.*kelvin, 50.*atmosphere);
CO2->AddElement(C, natoms=1);
CO2->AddElement(O, natoms=2);
G4Material* steam =
new G4Material("WaterSteam", density= 0.3*mg/cm3, ncomponents=1,
kStateGas, 500.*kelvin, 2.*atmosphere);
steam->AddMaterial(H2O, fractionmass=1.);
//
// examples of vacuum
//
G4Material* Vacuum =
new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
kStateGas, 2.73*kelvin, 3.e-18*pascal);
G4Material* beam =
new G4Material("Beam", density= 1.e-5*g/cm3, ncomponents=1,
kStateGas, STP_Temperature, 2.e-2*bar);
beam->AddMaterial(Air, fractionmass=1.);
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
//default materials of the World
defaultMaterial = Vacuum;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* ExN03DetectorConstruction::ConstructCalorimeter()
{
// Clean old geometry, if any
//
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
// complete the Calor parameters definition
ComputeCalorParameters();
//
// World
//
solidWorld = new G4Box("World", //its name
WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size
logicWorld = new G4LogicalVolume(solidWorld, //its solid
defaultMaterial, //its material
"World"); //its name
physiWorld = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
logicWorld, //its logical volume
"World", //its name
0, //its mother volume
false, //no boolean operation
0); //copy number
//
// Calorimeter
//
solidCalor=0; logicCalor=0; physiCalor=0;
solidLayer=0; logicLayer=0; physiLayer=0;
if (CalorThickness > 0.)
{ solidCalor = new G4Box("Calorimeter", //its name
CalorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);//size
logicCalor = new G4LogicalVolume(solidCalor, //its solid
defaultMaterial, //its material
"Calorimeter"); //its name
physiCalor = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
logicCalor, //its logical volume
"Calorimeter", //its name
logicWorld, //its mother volume
false, //no boolean operation
0); //copy number
//
// Layer
//
solidLayer = new G4Box("Layer", //its name
LayerThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size
logicLayer = new G4LogicalVolume(solidLayer, //its solid
defaultMaterial, //its material
"Layer"); //its name
if (NbOfLayers > 1)
physiLayer = new G4PVReplica("Layer", //its name
logicLayer, //its logical volume
logicCalor, //its mother
kXAxis, //axis of replication
NbOfLayers, //number of replica
LayerThickness); //witdth of replica
else
physiLayer = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
logicLayer, //its logical volume
"Layer", //its name
logicCalor, //its mother volume
false, //no boolean operation
0); //copy number
}
//
// Absorber
//
solidAbsorber=0; logicAbsorber=0; physiAbsorber=0;
if (AbsorberThickness > 0.)
{ solidAbsorber = new G4Box("Absorber", //its name
AbsorberThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
logicAbsorber = new G4LogicalVolume(solidAbsorber, //its solid
AbsorberMaterial, //its material
AbsorberMaterial->GetName()); //name
physiAbsorber = new G4PVPlacement(0, //no rotation
G4ThreeVector(-GapThickness/2,0.,0.), //its position
logicAbsorber, //its logical volume
AbsorberMaterial->GetName(), //its name
logicLayer, //its mother
false, //no boulean operat
0); //copy number
}
//
// Gap
//
solidGap=0; logicGap=0; physiGap=0;
if (GapThickness > 0.)
{ solidGap = new G4Box("Gap",
GapThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
logicGap = new G4LogicalVolume(solidGap,
GapMaterial,
GapMaterial->GetName());
physiGap = new G4PVPlacement(0, //no rotation
G4ThreeVector(AbsorberThickness/2,0.,0.), //its position
logicGap, //its logical volume
GapMaterial->GetName(), //its name
logicLayer, //its mother
false, //no boulean operat
0); //copy number
}
PrintCalorParameters();
//
// Visualization attributes
//
logicWorld->SetVisAttributes (G4VisAttributes::GetInvisible());
G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
simpleBoxVisAtt->SetVisibility(true);
logicCalor->SetVisAttributes(simpleBoxVisAtt);
/*
// Below are vis attributes that permits someone to test / play
// with the interactive expansion / contraction geometry system of the
// vis/OpenInventor driver :
{G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
simpleBoxVisAtt->SetVisibility(true);
delete logicCalor->GetVisAttributes();
logicCalor->SetVisAttributes(simpleBoxVisAtt);}
{G4VisAttributes* atb= new G4VisAttributes(G4Colour(1.0,0.0,0.0));
logicLayer->SetVisAttributes(atb);}
{G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,1.0,0.0));
atb->SetForceSolid(true);
logicAbsorber->SetVisAttributes(atb);}
{//Set opacity = 0.2 then transparency = 1 - 0.2 = 0.8
G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,0.0,1.0,0.2));
atb->SetForceSolid(true);
logicGap->SetVisAttributes(atb);}
*/
//
//always return the physical World
//
return physiWorld;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::PrintCalorParameters()
{
G4cout << "\n------------------------------------------------------------"
<< "\n---> The calorimeter is " << NbOfLayers << " layers of: [ "
<< AbsorberThickness/mm << "mm of " << AbsorberMaterial->GetName()
<< " + "
<< GapThickness/mm << "mm of " << GapMaterial->GetName() << " ] "
<< "\n------------------------------------------------------------\n";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
{
// search the material by its name
G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
if (pttoMaterial) AbsorberMaterial = pttoMaterial;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetGapMaterial(G4String materialChoice)
{
// search the material by its name
G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
if (pttoMaterial) GapMaterial = pttoMaterial;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetAbsorberThickness(G4double val)
{
// change Absorber thickness and recompute the calorimeter parameters
AbsorberThickness = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetGapThickness(G4double val)
{
// change Gap thickness and recompute the calorimeter parameters
GapThickness = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetCalorSizeYZ(G4double val)
{
// change the transverse size and recompute the calorimeter parameters
CalorSizeYZ = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetNbOfLayers(G4int val)
{
NbOfLayers = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4FieldManager.hh"
#include "G4TransportationManager.hh"
void ExN03DetectorConstruction::SetMagField(G4double fieldValue)
{
//apply a global uniform magnetic field along Z axis
G4FieldManager* fieldMgr
= G4TransportationManager::GetTransportationManager()->GetFieldManager();
if(magField) delete magField; //delete the existing magn field
if(fieldValue!=0.) // create a new one if non nul
{ magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
fieldMgr->SetDetectorField(magField);
fieldMgr->CreateChordFinder(magField);
} else {
magField = 0;
fieldMgr->SetDetectorField(magField);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4RunManager.hh"
void ExN03DetectorConstruction::UpdateGeometry()
{
G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,157 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef ExN03DetectorConstruction_h
#define ExN03DetectorConstruction_h 1
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
class G4Box;
class G4LogicalVolume;
class G4VPhysicalVolume;
class G4Material;
class G4UniformMagField;
class ExN03DetectorMessenger;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class ExN03DetectorConstruction : public G4VUserDetectorConstruction
{
public:
ExN03DetectorConstruction();
~ExN03DetectorConstruction();
public:
void SetAbsorberMaterial (G4String);
void SetAbsorberThickness(G4double);
void SetGapMaterial (G4String);
void SetGapThickness(G4double);
void SetCalorSizeYZ(G4double);
void SetNbOfLayers (G4int);
void SetMagField(G4double);
G4VPhysicalVolume* Construct();
void UpdateGeometry();
public:
void PrintCalorParameters();
G4double GetWorldSizeX() {return WorldSizeX;};
G4double GetWorldSizeYZ() {return WorldSizeYZ;};
G4double GetCalorThickness() {return CalorThickness;};
G4double GetCalorSizeYZ() {return CalorSizeYZ;};
G4int GetNbOfLayers() {return NbOfLayers;};
G4Material* GetAbsorberMaterial() {return AbsorberMaterial;};
G4double GetAbsorberThickness() {return AbsorberThickness;};
G4Material* GetGapMaterial() {return GapMaterial;};
G4double GetGapThickness() {return GapThickness;};
const G4VPhysicalVolume* GetphysiWorld() {return physiWorld;};
const G4VPhysicalVolume* GetAbsorber() {return physiAbsorber;};
const G4VPhysicalVolume* GetGap() {return physiGap;};
private:
G4Material* AbsorberMaterial;
G4double AbsorberThickness;
G4Material* GapMaterial;
G4double GapThickness;
G4int NbOfLayers;
G4double LayerThickness;
G4double CalorSizeYZ;
G4double CalorThickness;
G4Material* defaultMaterial;
G4double WorldSizeYZ;
G4double WorldSizeX;
G4Box* solidWorld; //pointer to the solid World
G4LogicalVolume* logicWorld; //pointer to the logical World
G4VPhysicalVolume* physiWorld; //pointer to the physical World
G4Box* solidCalor; //pointer to the solid Calor
G4LogicalVolume* logicCalor; //pointer to the logical Calor
G4VPhysicalVolume* physiCalor; //pointer to the physical Calor
G4Box* solidLayer; //pointer to the solid Layer
G4LogicalVolume* logicLayer; //pointer to the logical Layer
G4VPhysicalVolume* physiLayer; //pointer to the physical Layer
G4Box* solidAbsorber; //pointer to the solid Absorber
G4LogicalVolume* logicAbsorber; //pointer to the logical Absorber
G4VPhysicalVolume* physiAbsorber; //pointer to the physical Absorber
G4Box* solidGap; //pointer to the solid Gap
G4LogicalVolume* logicGap; //pointer to the logical Gap
G4VPhysicalVolume* physiGap; //pointer to the physical Gap
G4UniformMagField* magField; //pointer to the magnetic field
ExN03DetectorMessenger* detectorMessenger; //pointer to the Messenger
private:
void DefineMaterials();
void ComputeCalorParameters();
G4VPhysicalVolume* ConstructCalorimeter();
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void ExN03DetectorConstruction::ComputeCalorParameters()
{
// Compute derived parameters of the calorimeter
LayerThickness = AbsorberThickness + GapThickness;
CalorThickness = NbOfLayers*LayerThickness;
WorldSizeX = 1.2*CalorThickness; WorldSizeYZ = 1.2*CalorSizeYZ;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,148 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03DetectorMessenger.hh"
#include "ExN03DetectorConstruction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithoutParameter.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorMessenger::ExN03DetectorMessenger(
ExN03DetectorConstruction* ExN03Det)
:ExN03Detector(ExN03Det)
{
N03Dir = new G4UIdirectory("/N03/");
N03Dir->SetGuidance("UI commands of this example");
detDir = new G4UIdirectory("/N03/det/");
detDir->SetGuidance("detector control");
AbsMaterCmd = new G4UIcmdWithAString("/N03/det/setAbsMat",this);
AbsMaterCmd->SetGuidance("Select Material of the Absorber.");
AbsMaterCmd->SetParameterName("choice",false);
AbsMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
GapMaterCmd = new G4UIcmdWithAString("/N03/det/setGapMat",this);
GapMaterCmd->SetGuidance("Select Material of the Gap.");
GapMaterCmd->SetParameterName("choice",false);
GapMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
AbsThickCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setAbsThick",this);
AbsThickCmd->SetGuidance("Set Thickness of the Absorber");
AbsThickCmd->SetParameterName("Size",false);
AbsThickCmd->SetRange("Size>=0.");
AbsThickCmd->SetUnitCategory("Length");
AbsThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
GapThickCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setGapThick",this);
GapThickCmd->SetGuidance("Set Thickness of the Gap");
GapThickCmd->SetParameterName("Size",false);
GapThickCmd->SetRange("Size>=0.");
GapThickCmd->SetUnitCategory("Length");
GapThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
SizeYZCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setSizeYZ",this);
SizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
SizeYZCmd->SetParameterName("Size",false);
SizeYZCmd->SetRange("Size>0.");
SizeYZCmd->SetUnitCategory("Length");
SizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
NbLayersCmd = new G4UIcmdWithAnInteger("/N03/det/setNbOfLayers",this);
NbLayersCmd->SetGuidance("Set number of layers.");
NbLayersCmd->SetParameterName("NbLayers",false);
NbLayersCmd->SetRange("NbLayers>0 && NbLayers<500");
NbLayersCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
UpdateCmd = new G4UIcmdWithoutParameter("/N03/det/update",this);
UpdateCmd->SetGuidance("Update calorimeter geometry.");
UpdateCmd->SetGuidance("This command MUST be applied before \"beamOn\" ");
UpdateCmd->SetGuidance("if you changed geometrical value(s).");
UpdateCmd->AvailableForStates(G4State_Idle);
MagFieldCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setField",this);
MagFieldCmd->SetGuidance("Define magnetic field.");
MagFieldCmd->SetGuidance("Magnetic field will be in Z direction.");
MagFieldCmd->SetParameterName("Bz",false);
MagFieldCmd->SetUnitCategory("Magnetic flux density");
MagFieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorMessenger::~ExN03DetectorMessenger()
{
delete NbLayersCmd;
delete AbsMaterCmd; delete GapMaterCmd;
delete AbsThickCmd; delete GapThickCmd;
delete SizeYZCmd; delete UpdateCmd;
delete MagFieldCmd;
delete detDir;
delete N03Dir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
if( command == AbsMaterCmd )
{ ExN03Detector->SetAbsorberMaterial(newValue);}
if( command == GapMaterCmd )
{ ExN03Detector->SetGapMaterial(newValue);}
if( command == AbsThickCmd )
{ ExN03Detector->SetAbsorberThickness(AbsThickCmd
->GetNewDoubleValue(newValue));}
if( command == GapThickCmd )
{ ExN03Detector->SetGapThickness(GapThickCmd->GetNewDoubleValue(newValue));}
if( command == SizeYZCmd )
{ ExN03Detector->SetCalorSizeYZ(SizeYZCmd->GetNewDoubleValue(newValue));}
if( command == NbLayersCmd )
{ ExN03Detector->SetNbOfLayers(NbLayersCmd->GetNewIntValue(newValue));}
if( command == UpdateCmd )
{ ExN03Detector->UpdateGeometry(); }
if( command == MagFieldCmd )
{ ExN03Detector->SetMagField(MagFieldCmd->GetNewDoubleValue(newValue));}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,74 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef ExN03DetectorMessenger_h
#define ExN03DetectorMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class ExN03DetectorConstruction;
class G4UIdirectory;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithoutParameter;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class ExN03DetectorMessenger: public G4UImessenger
{
public:
ExN03DetectorMessenger(ExN03DetectorConstruction* );
~ExN03DetectorMessenger();
void SetNewValue(G4UIcommand*, G4String);
private:
ExN03DetectorConstruction* ExN03Detector;
G4UIdirectory* N03Dir;
G4UIdirectory* detDir;
G4UIcmdWithAString* AbsMaterCmd;
G4UIcmdWithAString* GapMaterCmd;
G4UIcmdWithADoubleAndUnit* AbsThickCmd;
G4UIcmdWithADoubleAndUnit* GapThickCmd;
G4UIcmdWithADoubleAndUnit* SizeYZCmd;
G4UIcmdWithAnInteger* NbLayersCmd;
G4UIcmdWithADoubleAndUnit* MagFieldCmd;
G4UIcmdWithoutParameter* UpdateCmd;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1 @@
from ._ExN03geom import *
@@ -0,0 +1,101 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyExN03geom.cc
//
// [ExN03geom]
// a site-module of Geant4Py
//
// geometry presented in ExN03 of Geant4 example
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "G4RunManager.hh"
#include "ExN03DetectorConstruction.hh"
using namespace boost::python;
typedef ExN03DetectorConstruction XXX;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyExN03geom {
void Construct()
{
G4RunManager* runMgr= G4RunManager::GetRunManager();
runMgr-> SetUserInitialization(new ExN03DetectorConstruction);
}
}
using namespace pyExN03geom;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_ExN03geom) {
class_<ExN03DetectorConstruction, ExN03DetectorConstruction*,
bases<G4VUserDetectorConstruction> >
("ExN03DetectorConstruction", "ExN03 detector")
// ---
.def("SetAbsorberMaterial", &XXX::SetAbsorberMaterial)
.def("SetAbsorberThickness", &XXX::SetAbsorberThickness)
.def("SetGapMaterial", &XXX::SetGapMaterial)
.def("SetGapThickness", &XXX::SetGapThickness)
.def("SetCalorSizeYZ", &XXX::SetCalorSizeYZ)
.def("SetNbOfLayers", &XXX::SetNbOfLayers)
.def("SetMagField", &XXX::SetMagField)
// ---
.def("GetWorldSizeX", &XXX::GetWorldSizeX)
.def("GetWorldSizeYZ", &XXX::GetWorldSizeYZ)
.def("GetCalorThickness", &XXX::GetCalorThickness)
.def("GetCalorSizeYZ", &XXX::GetCalorSizeYZ)
.def("GetNbOfLayers", &XXX::GetNbOfLayers)
.def("GetAbsorberMaterial", &XXX::GetAbsorberMaterial,
return_value_policy<reference_existing_object>())
.def("GetAbsorberThickness", &XXX::GetAbsorberThickness)
.def("GetGapMaterial", &XXX::GetGapMaterial,
return_value_policy<reference_existing_object>())
.def("GetGapThickness", &XXX::GetGapThickness)
.def("GetphysiWorld", &XXX::GetphysiWorld,
return_value_policy<reference_existing_object>())
.def("GetAbsorber", &XXX::GetAbsorber,
return_value_policy<reference_existing_object>())
.def("GetGap", &XXX::GetGap,
return_value_policy<reference_existing_object>())
// ---
.def("UpdateGeometry", &XXX::UpdateGeometry)
.def("PrintCalorParameters", &XXX::PrintCalorParameters)
;
// ---
def("Construct", Construct);
}
@@ -0,0 +1,136 @@
"""
Python module (Python3)
This module provides classes and functions for scoring reactions
[C] MCVertex:
[C] MCParticle:
[f] read_next_vertex(stream):
Q, 2006
"""
import string
from Geant4.hepunit import *
# ==================================================================
# public symbols
# ==================================================================
__all__ = [ 'MCParticle', 'MCVertex', 'read_next_vertex' ]
# ==================================================================
# class definition
# ==================================================================
# ------------------------------------------------------------------
# MCParticle
# ------------------------------------------------------------------
class MCParticle:
"MC particle"
def __init__(self, aname, aZ, aA, akE, apx, apy, apz):
self.name = aname
self.Z = aZ
self.A = aA
self.kineticE = akE
self.px = apx
self.py = apy
self.pz = apz
def printout(self):
print("--- particle: %s, Z=%2d, A=%2d, kE=%g" % \
(self.name, self.Z, self.A, self.kineticE/MeV))
# ------------------------------------------------------------------
# MCVertex
# ------------------------------------------------------------------
class MCVertex :
"MC vertex"
def __init__(self, ax, ay, az):
self.x = ax
self.y = ay
self.z = az
self.nparticle = 0
self.particle_list = []
def append_particle(self, aparticle):
self.particle_list.append(aparticle)
self.nparticle= self.nparticle+1
def printout(self):
print("@@@ vertex: x=(%g,%g,%g) Nsec=%3d" % \
(self.x/cm, self.y/cm, self.z/cm, self.nparticle))
for p in self.particle_list:
p.printout()
def dump_vertex(self, stream):
aline = "%g %g %g %d\n" % \
(self.x/m, self.y/m, self.z/m, self.nparticle)
stream.write(aline)
for p in self.particle_list:
aline = " %s %d %d %g %g %g %g\n" % \
(p.name, p.Z, p.A, p.kineticE/MeV, p.px/MeV, p.py/MeV, p.pz/MeV)
stream.write(aline)
def __del__(self):
np = len(self.particle_list)
del self.particle_list[0:np]
# ==================================================================
# I/O interface
# ==================================================================
def read_next_vertex(stream):
"read next vertex from a file stream"
line= stream.readline()
if line == "": # EOF
return 0
# reading vertex
data = line.split()
x = string.atof(data[0]) * m
y = string.atof(data[1]) * m
z = string.atof(data[2]) * m
nsec = string.atoi(data[3])
vertex = MCVertex(x,y,z)
# reading particles
for p in range(0, nsec):
data = stream.readline().split()
pname = data[0]
Z = string.atoi(data[1])
A = string.atoi(data[2])
kE = string.atof(data[3]) * MeV
px = string.atof(data[4]) * MeV
py = string.atof(data[5]) * MeV
pz = string.atof(data[6]) * MeV
particle = MCParticle(pname, Z, A, kE, px, py, pz)
vertex.append_particle(particle)
return vertex
# ==================================================================
# test
# ==================================================================
def test():
f = open("reaction.dat")
f.seek(0)
while(1):
vertex = read_next_vertex(f)
if vertex == 0:
break
vertex.printout()
del vertex
f.close()
print(">>> EOF")
# ==================================================================
# main
# ==================================================================
if __name__ == "__main__":
test()
@@ -0,0 +1,189 @@
"""
Python module
This module provides ROOT IO interface for MCScore data
[C] MCScoreROOTIO
[f] loop_tree(tfile, analyze_vertex):
Q, 2006
"""
from array import array
import string
from Geant4.hepunit import *
import mcscore
import ROOT
# ==================================================================
# public symbols
# ==================================================================
__all__ = [ 'MCScoreROOTIO', 'loop_tree' ]
# ==================================================================
# class definition
# ==================================================================
# ------------------------------------------------------------------
# MCScoreROOTIO
# ------------------------------------------------------------------
class MCScoreROOTIO:
"ROOT IO interface for MCScore"
def __init__(self, bsize=250):
self.maxparticle = bsize # buffer size for #particles/vertex
# ------------------------------------------------------------------
def define_tree(self):
"define ROOT tree"
# defining tree header...
self.vtree = ROOT.TTree('vertex', 'mc vertex')
self.ptree = ROOT.TTree('particle', 'mc particle')
# vertex...
self.a_x = array('d', [0.]); self.vtree.Branch('x', self.a_x, 'x/d')
self.a_y = array('d', [0.]); self.vtree.Branch('y', self.a_y, 'y/d')
self.a_z = array('d', [0.]); self.vtree.Branch('z', self.a_z, 'z/d')
#global a_np, a_namelist, a_Z, a_A, a_ke, a_px, a_py, a_pz
self.a_np = array('i', [0]); self.ptree.Branch('np', self.a_np, 'np/i')
self.a_namelist = array('c', self.maxparticle*10*['\0'])
# 10 characters/particle
self.ptree.Branch('namelist', self.a_namelist, 'namelist/C')
self.a_Z = array('i', self.maxparticle*[0])
self.ptree.Branch('Z', self.a_Z, 'Z[np]/I')
self.a_A = array('i', self.maxparticle*[0])
self.ptree.Branch('A', self.a_A, 'A[np]/i')
self.a_ke = array('d', self.maxparticle*[0.])
self.ptree.Branch('kE', self.a_ke, 'kE[np]/d')
self.a_px = array('d', self.maxparticle*[0.])
self.ptree.Branch('px', self.a_px, 'px[np]/d')
self.a_py = array('d', self.maxparticle*[0.])
self.ptree.Branch('py', self.a_py, 'py[np]/d')
self.a_pz = array('d', self.maxparticle*[0.])
self.ptree.Branch('pz', self.a_pz, 'pz[np]/d')
# ------------------------------------------------------------------
def fill_tree(self, vertex):
"fill vertex information to ROOT tree"
# ------------------------------------------------------------------
def push_pname(i0, pname): # local function
n = len(pname)
for i in xrange(n):
self.a_namelist[i0+i] = pname[i]
self.a_namelist[i0+n] = ' '
self.a_x[0] = vertex.x
self.a_y[0] = vertex.y
self.a_z[0] = vertex.z
self.vtree.Fill()
if vertex.nparticle > self.maxparticle:
raise """
*** buffer overflow in #particles/vertex.
*** please increment buffersize in MCScoreROOTIO(bsize).
""", self.maxparticle
idx_namelist = 0
self.a_np[0] = vertex.nparticle
for ip in range(vertex.nparticle):
particle = vertex.particle_list[ip]
push_pname(idx_namelist, particle.name)
idx_namelist += (len(particle.name)+1)
self.a_Z[ip] = particle.Z
self.a_A[ip] = particle.A
self.a_ke[ip] = particle.kineticE
self.a_px[ip] = particle.px
self.a_py[ip] = particle.py
self.a_pz[ip] = particle.pz
self.a_namelist[idx_namelist] = '\0'
self.ptree.Fill()
# ==================================================================
# functions
# ==================================================================
def loop_tree(tfile, analyze_vertex):
"""
loop ROOT tree in a ROOT file.
* analyze_vertex: user function : analyze_vertex(MCVertex)
"""
avtree = tfile.Get("vertex")
aptree = tfile.Get("particle")
# reading vertex...
n_vertex = avtree.GetEntries()
for ivtx in xrange(n_vertex):
avtree.GetEntry(ivtx)
aptree.GetEntry(ivtx)
# vertex
vertex = MCScore.MCVertex(avtree.x, avtree.y, avtree.z)
# reading secondary particles...
nsec = aptree.np
namelist = aptree.namelist
pname = namelist.split()
for ip in xrange(nsec):
particle = MCScore.MCParticle(pname[ip], aptree.Z[ip], aptree.A[ip],
aptree.kE[ip], aptree.px[ip],
aptree.py[ip], aptree.pz[ip])
vertex.append_particle(particle)
analyze_vertex(vertex)
return n_vertex
# ==================================================================
# test
# ==================================================================
def test_t2root():
g = ROOT.TFile("reaction.root", 'recreate')
rootio = MCScoreROOTIO()
rootio.define_tree()
f = open("reaction.dat")
f.seek(0)
while(1):
vertex = MCScore.read_next_vertex(f)
if vertex == 0:
break
# filling ...
rootio.fill_tree(vertex)
del vertex
print ">>> EOF"
f.close()
# closing ROOT file
g.Write()
g.Close()
# ------------------------------------------------------------------
def test_loop():
def my_analysis(vertex):
vertex.printout()
f = ROOT.TFile("reaction.root", 'read')
nv = loop_tree(f, my_analysis)
print "*** # of vertex= ", nv
# ==================================================================
# main
# ==================================================================
if __name__ == "__main__":
test_t2root()
test_loop()
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _MedicalBeam)
g4pytest_add_module(${_TARGET} MedicalBeam.cc pyMedicalBeam.cc)
target_link_libraries(${_TARGET} PRIVATE G4run G4particles)
@@ -0,0 +1,136 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// MedicalBeam.cc
//
// 2005 Q
// ====================================================================
#include "MedicalBeam.hh"
#include "Randomize.hh"
#include "G4Event.hh"
#include "G4ParticleTable.hh"
#include "G4PrimaryVertex.hh"
using namespace CLHEP;
#include <cmath>
// ====================================================================
//
// class description
//
// ====================================================================
///////////////////////////////////
MedicalBeam::MedicalBeam()
: particle(0),
kineticE(1.*MeV),
sourcePosition(G4ThreeVector()),
SSD(1.*m),
fieldShape(MedicalBeam::SQUARE),
fieldR(10.*cm)
///////////////////////////////////
{
fieldXY[0]= fieldXY[1]= 10.*cm;
}
///////////////////////////
MedicalBeam::~MedicalBeam()
///////////////////////////
{
}
////////////////////////////////////////////////////////
G4ThreeVector MedicalBeam::GenerateBeamDirection() const
////////////////////////////////////////////////////////
{
// uniform distribution in a limitted solid angle
G4double dr;
if(fieldShape == MedicalBeam::SQUARE) {
dr= std::sqrt(sqr(fieldXY[0]/2.)+sqr(fieldXY[1]/2.));
} else {
dr= fieldR;
}
G4double sin0= dr/SSD;
G4double cos0= std::sqrt(1.-sqr(sin0));
G4double x= DBL_MAX;
G4double y= DBL_MAX;
G4double xmax, ymax;
if(fieldShape == MedicalBeam::SQUARE) {
xmax= fieldXY[0]/2./SSD;
ymax= fieldXY[1]/2./SSD;
} else {
xmax= ymax= DBL_MAX-1.;
}
G4double dcos{0.0};
G4double dsin{0.0};
G4double dphi{0.0};
while(! (std::abs(x)< xmax && std::abs(y)< ymax) ) {
dcos= RandFlat::shoot(cos0, 1.);
dsin= std::sqrt(1.-sqr(dcos));
dphi= RandFlat::shoot(0., twopi);
x= std::cos(dphi)*dsin*dcos;
y= std::sin(dphi)*dsin*dcos;
}
G4double z= dcos;
return G4ThreeVector(x,y,z);
}
/////////////////////////////////////////////////////
void MedicalBeam::GeneratePrimaries(G4Event* anEvent)
/////////////////////////////////////////////////////
{
if(particle==0) return;
// create a new vertex
G4PrimaryVertex* vertex= new G4PrimaryVertex(sourcePosition, 0.*ns);
// momentum
G4double mass= particle-> GetPDGMass();
G4double p= std::sqrt(sqr(mass+kineticE)-sqr(mass));
G4ThreeVector pmon= p*GenerateBeamDirection();
G4PrimaryParticle* primary= new G4PrimaryParticle(particle,
pmon.x(),
pmon.y(),
pmon.z());
// set primary to vertex
vertex-> SetPrimary(primary);
// set vertex to event
anEvent-> AddPrimaryVertex(vertex);
}
@@ -0,0 +1,143 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// MedicalBeam.hh
//
// 2005 Q
// ====================================================================
#ifndef MEDICAL_BEAM_H
#define MEDICAL_BEAM_H
#include "globals.hh"
#include "G4ThreeVector.hh"
#include "G4VUserPrimaryGeneratorAction.hh"
class G4ParticleDefinition;
// ====================================================================
//
// class definition
//
// ====================================================================
class MedicalBeam : public G4VUserPrimaryGeneratorAction {
public:
enum FieldShape{ SQUARE=0, CIRCLE };
protected:
G4ParticleDefinition* particle;
G4double kineticE;
G4ThreeVector sourcePosition;
G4double SSD; // (SSD= Source Skin Depth)
FieldShape fieldShape;
G4double fieldXY[2];
G4double fieldR;
// local methods...
G4ThreeVector GenerateBeamDirection() const;
public:
MedicalBeam();
~MedicalBeam();
// set/get functions...
void SetParticleDefinition(G4ParticleDefinition* pd);
const G4ParticleDefinition* GetParticleDefinition() const;
void SetKineticE(G4double e);
G4double GetKineticE() const;
void SetSourcePosition(const G4ThreeVector& pos);
G4ThreeVector GetSourcePosition() const;
void SetFieldShape(FieldShape shape);
FieldShape GetFieldShape() const;
void SetSSD(G4double ssd);
G4double GetSSD() const;
void SetFieldXY(G4double fx, G4double fy);
G4double GetFieldX() const;
G4double GetFieldY() const;
void SetFieldR(G4double r);
G4double GetFieldR() const;
// methods...
virtual void GeneratePrimaries(G4Event* anEvent);
};
// ====================================================================
// inline functions
// ====================================================================
inline void MedicalBeam::SetParticleDefinition(G4ParticleDefinition* pd)
{ particle= pd; }
inline const G4ParticleDefinition* MedicalBeam::GetParticleDefinition() const
{ return particle; }
inline void MedicalBeam::SetKineticE(G4double e)
{ kineticE= e; }
inline G4double MedicalBeam::GetKineticE() const
{ return kineticE; }
inline void MedicalBeam::SetSourcePosition(const G4ThreeVector& pos)
{ sourcePosition= pos; }
inline G4ThreeVector MedicalBeam::GetSourcePosition() const
{ return sourcePosition; }
inline void MedicalBeam::SetFieldShape(MedicalBeam::FieldShape shape)
{ fieldShape= shape; }
inline MedicalBeam::FieldShape MedicalBeam::GetFieldShape() const
{ return fieldShape; }
inline void MedicalBeam::SetSSD(G4double ssd)
{ SSD= ssd; }
inline G4double MedicalBeam::GetSSD() const
{ return SSD; }
inline void MedicalBeam::SetFieldXY(G4double fx, G4double fy)
{ fieldXY[0]= fx; fieldXY[1]= fy; }
inline G4double MedicalBeam::GetFieldX() const
{ return fieldXY[0]; }
inline G4double MedicalBeam::GetFieldY() const
{ return fieldXY[1]; }
inline void MedicalBeam::SetFieldR(G4double r)
{ fieldR= r; }
inline G4double MedicalBeam::GetFieldR() const
{ return fieldR; }
#endif
@@ -0,0 +1 @@
from ._MedicalBeam import *
@@ -0,0 +1,162 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyMedicalBeam.cc
//
// [MedicalBeam]
// a site-module of Geant4Py
//
// primary generator action for medical beam
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "MedicalBeam.hh"
#include "G4ParticleTable.hh"
#include "G4RunManager.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyMedicalBeam {
MedicalBeam* Construct()
{
G4RunManager* runMgr= G4RunManager::GetRunManager();
MedicalBeam* medicalbeam= new MedicalBeam();
runMgr-> SetUserAction(medicalbeam);
return medicalbeam;
}
///////////////////////////////////////////////////////////////////
void SetParticleByName(MedicalBeam* beam, const std::string& pname)
///////////////////////////////////////////////////////////////////
{
G4ParticleTable* particleTable= G4ParticleTable::GetParticleTable();
G4ParticleDefinition* pd= particleTable-> FindParticle(pname);
if (pd != 0) {
beam-> SetParticleDefinition(pd);
} else {
G4cout << "*** \"" << pname << "\" is not registered "
<< "in available particle list" << G4endl;
}
}
////////////////////////////////////////////////
std::string GetParticleByName(MedicalBeam* beam)
////////////////////////////////////////////////
{
const G4ParticleDefinition* pd= beam-> GetParticleDefinition();
if(pd==0) return std::string("None");
else return (pd-> GetParticleName()).c_str();
}
////////////////////////////////////////////////////////
void f_SetFieldXY(MedicalBeam* beam, const list& listXY)
////////////////////////////////////////////////////////
{
G4double fx= extract<double>(listXY[0]);
G4double fy= extract<double>(listXY[1]);
beam-> SetFieldXY(fx, fy);
}
////////////////////////////////////
list f_GetFieldXY(MedicalBeam* beam)
////////////////////////////////////
{
list listFieldXY;
listFieldXY.append(beam-> GetFieldX());
listFieldXY.append(beam-> GetFieldY());
return listFieldXY;
}
}
using namespace pyMedicalBeam;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_MedicalBeam) {
class_<MedicalBeam, MedicalBeam*,
bases<G4VUserPrimaryGeneratorAction> >
("MedicalBeam", "primary generator action with medical beam")
// ---
.add_property("particle", GetParticleByName, SetParticleByName)
.def("SetParticleByName", SetParticleByName)
.def("GetParticleByName", GetParticleByName)
// ---
.add_property("kineticE", &MedicalBeam::GetKineticE,
&MedicalBeam::SetKineticE)
.def("SetKineticE", &MedicalBeam::SetKineticE)
.def("GetKineticE", &MedicalBeam::GetKineticE)
// ---
.add_property("sourcePosition", &MedicalBeam::GetSourcePosition,
&MedicalBeam::SetSourcePosition)
.def("SetSourcePosition", &MedicalBeam::SetSourcePosition)
.def("GetSourcePosition", &MedicalBeam::GetSourcePosition)
// ---
.add_property("fieldShape", &MedicalBeam::GetFieldShape,
&MedicalBeam::SetFieldShape)
.def("SetFieldShape", &MedicalBeam::SetFieldShape)
.def("GetFieldShape", &MedicalBeam::GetFieldShape)
// ---
.add_property("SSD", &MedicalBeam::GetSSD, &MedicalBeam::SetSSD)
.def("SetSSD", &MedicalBeam::SetSSD)
.def("GetSSD", &MedicalBeam::GetSSD)
// ----
.add_property("fieldXY", f_GetFieldXY, f_SetFieldXY)
.def("SetFieldXY", f_SetFieldXY)
.def("GetFieldXY", f_GetFieldXY)
.def("GetFieldX", &MedicalBeam::GetFieldX)
.def("GetFieldY", &MedicalBeam::GetFieldY)
// ---
.add_property("fieldR", &MedicalBeam::GetFieldR, &MedicalBeam::SetFieldR)
.def("SetFieldR", &MedicalBeam::SetFieldR)
.def("GetFieldR", &MedicalBeam::GetFieldR)
;
// enums...
enum_<MedicalBeam::FieldShape>("FieldShape")
.value("SQUARE", MedicalBeam::SQUARE)
.value("CIRCLE", MedicalBeam::CIRCLE)
;
// ---
def("Construct", Construct,
return_value_policy<reference_existing_object>());
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _NISTmaterials)
g4pytest_add_module(${_TARGET} NISTmaterials.cc pyNISTmaterials.cc)
target_link_libraries(${_TARGET} PRIVATE G4materials)
@@ -0,0 +1,61 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// NISTmaterials.cc
//
// 2005 Q
// ====================================================================
#include "G4NistManager.hh"
////////////////
void Construct()
////////////////
{
G4NistManager* NistMgr = G4NistManager::Instance();
// define typically used materials
NistMgr-> FindOrBuildMaterial("G4_Al");
NistMgr-> FindOrBuildMaterial("G4_Si");
NistMgr-> FindOrBuildMaterial("G4_Ar");
NistMgr-> FindOrBuildMaterial("G4_Cu");
NistMgr-> FindOrBuildMaterial("G4_Fe");
NistMgr-> FindOrBuildMaterial("G4_Ge");
NistMgr-> FindOrBuildMaterial("G4_Ag");
NistMgr-> FindOrBuildMaterial("G4_W");
NistMgr-> FindOrBuildMaterial("G4_Au");
NistMgr-> FindOrBuildMaterial("G4_Pb");
NistMgr-> FindOrBuildMaterial("G4_AIR");
NistMgr-> FindOrBuildMaterial("G4_Galactic");
NistMgr-> FindOrBuildMaterial("G4_WATER");
NistMgr-> FindOrBuildMaterial("G4_CESIUM_IODIDE");
NistMgr-> FindOrBuildMaterial("G4_SODIUM_IODIDE");
NistMgr-> FindOrBuildMaterial("G4_PLASTIC_SC_VINYLTOLUENE");
NistMgr-> FindOrBuildMaterial("G4_MYLAR");
//NistMgr-> FindOrBuildMaterial("G4_GRAPHITE");
// bug in G4 (element isnot defined. should be fixed.)
}
@@ -0,0 +1 @@
from ._NISTmaterials import *
@@ -0,0 +1,49 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyNISTmaterials.cc
//
// [NISTmaterials]
// a site-module of Geant4Py
//
// NIST materials
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
using namespace boost::python;
void Construct();
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_NISTmaterials) {
def("Construct", Construct);
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _ParticleGun)
g4pytest_add_module(${_TARGET} ParticleGunAction.cc pyParticleGun.cc)
target_link_libraries(${_TARGET} PRIVATE G4run G4particles)
@@ -0,0 +1,60 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// ParticleGunAction.cc
//
// 2005 Q
// ====================================================================
#include "ParticleGunAction.hh"
#include "G4ParticleGun.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////
ParticleGunAction::ParticleGunAction()
//////////////////////////////////////
{
particleGun= new G4ParticleGun;
}
///////////////////////////////////////
ParticleGunAction::~ParticleGunAction()
///////////////////////////////////////
{
delete particleGun;
}
///////////////////////////////////////////////////////////
void ParticleGunAction::GeneratePrimaries(G4Event* anEvent)
///////////////////////////////////////////////////////////
{
particleGun-> GeneratePrimaryVertex(anEvent);
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// ParticleGunAction.hh
//
// 2005 Q
// ====================================================================
#ifndef PARTICLE_GUN_ACTION_H
#define PARTICLE_GUN_ACTION_H
#include "G4VUserPrimaryGeneratorAction.hh"
class G4ParticleGun;
// ====================================================================
//
// class definition
//
// ====================================================================
class ParticleGunAction : public G4VUserPrimaryGeneratorAction {
private:
// use G4 particle gun
G4ParticleGun* particleGun;
public:
ParticleGunAction();
~ParticleGunAction();
G4ParticleGun* GetParticleGun() const;
virtual void GeneratePrimaries(G4Event* anEvent);
};
// ====================================================================
// inline functions
// ====================================================================
inline G4ParticleGun* ParticleGunAction::GetParticleGun() const
{ return particleGun; }
#endif
@@ -0,0 +1 @@
from ._ParticleGun import *
@@ -0,0 +1,79 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyParticleGun.cc
//
// [ParticleGun]
// a site-module of Geant4Py
//
// primary generator action with particle gun
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "ParticleGunAction.hh"
#include "G4ParticleGun.hh"
#include "G4RunManager.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyParticleGun {
G4ParticleGun* Construct()
{
G4RunManager* runMgr= G4RunManager::GetRunManager();
ParticleGunAction* pga= new ParticleGunAction;
runMgr-> SetUserAction(pga);
return pga-> GetParticleGun();
}
}
using namespace pyParticleGun;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_ParticleGun) {
class_<ParticleGunAction, ParticleGunAction*,
bases<G4VUserPrimaryGeneratorAction> >
("ParticleGunAction", "primary generator action with particle gun")
.def("GetParticleGun", &ParticleGunAction::GetParticleGun,
return_internal_reference<>())
;
// ---
def("Construct", Construct,
return_value_policy<reference_existing_object>());
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _Qgeom)
g4pytest_add_module(${_TARGET} QDetectorConstruction.cc pyQgeom.cc)
target_link_libraries(${_TARGET} PRIVATE G4materials G4geometry G4run)
@@ -0,0 +1,144 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QDetectorConstruction.cc
//
// 2005 Q
// ====================================================================
#include "QDetectorConstruction.hh"
#include "G4Material.hh"
#include "G4Tubs.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4VisAttributes.hh"
#include "G4SystemOfUnits.hh"
// ====================================================================
//
// class description
//
// ====================================================================
// constants (detector parameters)
static const G4double DXYZ_AREA= 30.*cm;
//////////////////////////////////////////////
QDetectorConstruction::QDetectorConstruction()
//////////////////////////////////////////////
{
}
///////////////////////////////////////////////
QDetectorConstruction::~QDetectorConstruction()
///////////////////////////////////////////////
{
}
/////////////////////////////////////////////////////
G4VPhysicalVolume* QDetectorConstruction::Construct()
/////////////////////////////////////////////////////
{
G4Material* mate;
G4VisAttributes* va;
// ==============================================================
// world volume
// ==============================================================
G4Box* areaSolid= new G4Box("AREA",
DXYZ_AREA/2., DXYZ_AREA/2., DXYZ_AREA/2.);
G4Material* vacuum= G4Material::GetMaterial("Vacuum");
G4LogicalVolume* areaLV= new G4LogicalVolume(areaSolid, vacuum, "AREA_LV");
G4PVPlacement* area= new G4PVPlacement(0, G4ThreeVector(), "AREA_PV",
areaLV, 0, false, 0);
// vis. attributes
va= new G4VisAttributes(G4Color(1.,1.,1.));
va-> SetForceWireframe(true);
areaLV-> SetVisAttributes(va);
// ==============================================================
// detectors
// ==============================================================
// voxel
const G4double dvoxel= 10.*mm;
const G4double dl= 10.*cm;
G4Box* svoxel= new G4Box("voxel", dvoxel, dl, dvoxel);
mate= G4Material::GetMaterial("Vacuum");
G4LogicalVolume* lvoxel= new G4LogicalVolume(svoxel, mate, "voxel");
va= new G4VisAttributes(G4Color(0.,0.8,0.8));
va-> SetVisibility(false);
lvoxel-> SetVisAttributes(va);
G4int ix, iz;
G4int index=0;
for (iz=0; iz<5; iz++) {
for (ix=-7; ix<=7; ix++) {
G4double x0= (2.*ix)*cm;
G4double z0= (-13.+2.*iz)*cm;
/*G4PVPlacement* pvoxel=*/ new G4PVPlacement(0, G4ThreeVector(x0, 0., z0),
lvoxel, "voxel", areaLV, false, index);
index++;
}
}
// tube
//G4Tubs* stube= new G4Tubs("tube", 15./2.*mm, 19./2.*mm, dl,
G4Tubs* stube= new G4Tubs("tube", 0.*mm, 19./2.*mm, dl,
0., 360.*deg);
mate= G4Material::GetMaterial("Al");
G4LogicalVolume* ltube= new G4LogicalVolume(stube, mate, "tube");
va= new G4VisAttributes(G4Color(0.,0.8,0.8));
ltube-> SetVisAttributes(va);
G4RotationMatrix* rmtube= new G4RotationMatrix;
rmtube-> rotateX(-90.*deg);
/*G4PVPlacement* ptube=*/ new G4PVPlacement(rmtube, G4ThreeVector(),
ltube, "tube", lvoxel, false, 0);
// cal
const G4double dxycal= 25.*mm;
const G4double dzcal= 3.*cm;
G4Box* scal= new G4Box("cal", dxycal, dxycal, dzcal);
mate= G4Material::GetMaterial("CsI");
G4LogicalVolume* lcal= new G4LogicalVolume(scal, mate, "cal");
va= new G4VisAttributes(G4Color(0.5,0.5,0.));
lcal-> SetVisAttributes(va);
index= 0;
for (ix=-2; ix<=2; ix++) {
G4double x0= (5.*ix)*cm;
/*G4PVPlacement* pcal=*/ new G4PVPlacement(0, G4ThreeVector(x0, 0., 2.*cm),
lcal, "cal", areaLV, false, index);
index++;
}
return area;
}
@@ -0,0 +1,52 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QDetectorConstruction.hh
//
// 2005 Q
// ====================================================================
#ifndef Q_DETECTOR_CONSTRUCTION_H
#define Q_DETECTOR_CONSTRUCTION_H
#include "G4VUserDetectorConstruction.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class QDetectorConstruction : public G4VUserDetectorConstruction {
public:
QDetectorConstruction();
~QDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
};
#endif
@@ -0,0 +1 @@
from ._Qgeom import *
@@ -0,0 +1,71 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyQgeom.cc
//
// [Qgeom]
// a site-module of Geant4Py
//
// A sample geometry
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "G4RunManager.hh"
#include "QDetectorConstruction.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyQgeom {
void Construct()
{
G4RunManager* runMgr= G4RunManager::GetRunManager();
runMgr-> SetUserInitialization(new QDetectorConstruction);
}
}
using namespace pyQgeom;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_Qgeom) {
class_<QDetectorConstruction, QDetectorConstruction*,
bases<G4VUserDetectorConstruction> >
("QDetectorConstruction", "my detector")
;
// ---
def("Construct", Construct);
}
@@ -0,0 +1,4 @@
# - build library
set(_TARGET _Qmaterials)
g4pytest_add_module(${_TARGET} Qmaterials.cc pyQmaterials.cc)
target_link_libraries(${_TARGET} PRIVATE G4materials)
@@ -0,0 +1,142 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// Qmaterials.cc
//
// 2005 Q
// ====================================================================
#include "G4Material.hh"
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
////////////////
void Construct()
////////////////
{
G4double A, Z;
// ------------------------------------------------------------------------
// Elements
// ------------------------------------------------------------------------
G4Element* elH = new G4Element("Hydrogen","H", Z=1., A=1.00794*g/mole);
G4Element* elC = new G4Element("Carbon", "C", Z=6., A= 12.011 *g/mole);
G4Element* elN = new G4Element("Nitrogen","N", Z=7., A= 14.00674*g/mole);
G4Element* elO = new G4Element("Oxygen", "O", Z=8., A= 15.9994*g/mole);
G4Element* elNa = new G4Element("Sodium", "Na", Z=11., A= 22.989768*g/mole);
G4Element* elSi = new G4Element("Silicon", "Si", Z=14., A= 28.0855*g/mole);
G4Element* elAr = new G4Element("Argon", "Ar", Z=18., A= 39.948*g/mole);
G4Element* elI = new G4Element("Iodine", "I", Z=53., A= 126.90447*g/mole);
G4Element* elCs = new G4Element("Cesium", "Cs", Z=55., A= 132.90543*g/mole);
// ------------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------------
G4double density, massfraction;
G4int natoms, nel;
// temperature of experimental hall is controlled at 20 degree.
const G4double expTemp= STP_Temperature+20.*kelvin;
// vacuum
density= universe_mean_density;
G4Material* Vacuum= new G4Material("Vacuum", density, nel=2);
Vacuum-> AddElement(elN, .7);
Vacuum-> AddElement(elO, .3);
// air
density= 1.2929e-03 *g/cm3; // at 20 degree
G4Material* Air= new G4Material("Air", density, nel=3,
kStateGas, expTemp);
G4double ttt= 75.47+23.20+1.28;
Air-> AddElement(elN, massfraction= 75.47/ttt);
Air-> AddElement(elO, massfraction= 23.20/ttt);
Air-> AddElement(elAr, massfraction= 1.28/ttt);
// Ar gas
A= 39.948 *g/mole;
const G4double denAr= 1.782e-03 *g/cm3 * STP_Temperature/expTemp;
G4Material* Ar= new G4Material("ArgonGas", Z=18., A, denAr,
kStateGas, expTemp);
// ethane (C2H6)
const G4double denEthane= 1.356e-3 *g/cm3 * STP_Temperature/expTemp;
G4Material* Ethane= new G4Material("Ethane", denEthane, nel=2,
kStateGas, expTemp);
Ethane-> AddElement(elC, natoms=2);
Ethane-> AddElement(elH, natoms=6);
// Ar(50%) + ethane(50%) mixture
density= (denAr+denEthane)/2.;
G4Material* ArEthane= new G4Material("ArEthane", density, nel=2,
kStateGas, expTemp);
ArEthane-> AddMaterial(Ar, massfraction= denAr/density/2.);
ArEthane-> AddMaterial(Ethane, massfraction= denEthane/density/2.);
// silicon
A= 28.0855 *g/mole;
density= 2.33 *g/cm3;
/*G4Material* Si=*/ new G4Material("SiliconWafer", Z=14., A, density);
// alminium
A= 26.98 *g/mole;
density= 2.70 *g/cm3;
/*G4Material* Al=*/ new G4Material("Al", Z=13., A, density);
// iron
A= 55.847 *g/mole;
density= 7.87 *g/cm3;
/*G4Material* Fe=*/ new G4Material("Iron", Z=26., A, density);
// lead
A= 207.2 *g/mole;
density= 11.35 *g/cm3;
/*G4Material* Pb=*/ new G4Material("Lead", Z=82., A, density);
// scintillator (Polystyene(C6H5CH=CH2))
density= 1.032 *g/cm3;
G4Material* Scinti= new G4Material("Scinti", density, nel=2);
Scinti-> AddElement(elC, natoms=8);
Scinti-> AddElement(elH, natoms=8);
// quartz (SiO2, crystalline)
density= 2.64 *g/cm3;
G4Material* Quartz= new G4Material("Quartz", density, nel= 2);
Quartz-> AddElement(elSi, natoms=1);
Quartz-> AddElement(elO, natoms=2);
// NaI crystal
density= 3.67 *g/cm3;
G4Material* NaI= new G4Material("NaI", density, nel= 2);
NaI-> AddElement(elNa, natoms=1);
NaI-> AddElement(elI, natoms=1);
// CsI crystal
density= 4.51 *g/cm3;
G4Material* CsI= new G4Material("CsI", density, nel= 2);
CsI-> AddElement(elCs, natoms=1);
CsI-> AddElement(elI, natoms=1);
}
@@ -0,0 +1 @@
from ._Qmaterials import *
@@ -0,0 +1,49 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyQmaterials.cc
//
// [Qmaterials]
// a site-module of Geant4Py
//
// A sample set of materials
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
using namespace boost::python;
void Construct();
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_Qmaterials) {
def("Construct", Construct);
}
@@ -0,0 +1,3 @@
# Geant4Py site-modules
@@ -0,0 +1,149 @@
"""
# ==================================================================
# Python module (Python3)
#
# Calculation of photon cross section and stopping power for
# chared particles
#
# Q, 2005
# ==================================================================
"""
from Geant4 import *
# ==================================================================
# public symbols
# ==================================================================
__all__ = [ 'CalculatePhotonCrossSection', 'CalculateDEDX' ]
# ==================================================================
# Photon Cross Section
# ==================================================================
def CalculatePhotonCrossSection(mat, elist, verbose=0,
plist=["compt", "", "phot", "conv"]):
"""
Calculate photon cross section for a given material and
a list of energy, returing a list of cross sections for
the components of "Copmton scattering", "rayleigh scattering",
"photoelectric effect", "pair creation" and total one.
Arguments:
mat: material name
elist: list of energy
verbose: verbose level [0]
plist: list of process name
(compton/rayleigh/photoelectic/conversion) [StandardEM set]
Keys of index:
"compt": Compton Scattering
"rayleigh": Rayleigh Scattering
"phot" : photoelectric effect
"conv" : pair Creation
"tot" : total
Example:
xsec_list= CalculatePhotonCrossSection(...)
value= xsec_list[energy_index]["compt"]
"""
if(verbose>0):
print("-------------------------------------------------------------------")
print(" Photon Cross Section (", mat, ")")
print("Energy Compton Raleigh Photo- Pair Total")
print(" Scattering Scattering electric Creation")
print("(MeV) (cm2/g) (cm2/g) (cm2/g) (cm2/g) (cm2/g)")
print("-------------------------------------------------------------------")
xsection_list= []
for ekin in elist:
xsec= {}
xsec["compt"] \
= gEmCalculator.ComputeCrossSectionPerVolume(ekin, "gamma", plist[0],
mat) * cm2/g
xsec["rayleigh"] \
= gEmCalculator.ComputeCrossSectionPerVolume(ekin, "gamma", plist[1],
mat) * cm2/g
xsec["phot"] \
= gEmCalculator.ComputeCrossSectionPerVolume(ekin, "gamma", plist[2],
mat) * cm2/g
xsec["conv"] \
= gEmCalculator.ComputeCrossSectionPerVolume(ekin, "gamma", plist[3],
mat) * cm2/g
xsec["tot"]= xsec["compt"] + xsec["rayleigh"] + xsec["phot"] + xsec["conv"]
xsection_list.append((ekin, xsec))
if(verbose>0):
print(" %8.3e %8.3e %8.3e %8.3e %8.3e %8.3e" \
% (ekin/MeV, xsec["compt"]/(cm2/g), xsec["rayleigh"]/(cm2/g),
xsec["phot"]/(cm2/g), xsec["conv"]/(cm2/g), xsec["tot"]/(cm2/g)))
return xsection_list
# ==================================================================
# Stopping Power
# ==================================================================
def CalculateDEDX(part, mat, elist, verbose=0,
plist=["eIoni", "eBrem", "muIoni", "muBrems", "hIoni"]):
"""
Calculate stopping powers for a give particle, material and
a list of energy, returing stopping power for the components of
"Ionization", "Radiation" and total one.
Arguments:
part: particle name
mat: material name
elist: list of energy
verbose: verbose level [0]
plist: list of process name
(electron ionization/electron brems/
muon ionization/muon brems/hadron ionization) [StandardEM set]
Keys of index:
"ioni": ionization
"brems": Bremsstrahlung
"tot": total
Example:
dedx_list= CalculateDEDX(...)
value= dedx_list[energy_index]["ioni"]
"""
if(verbose>0):
print("------------------------------------------------------")
print(" Stopping Power (", part, ",", mat, ")")
print(" Energy Ionization Radiation Total")
print(" (MeV) (MeVcm2/g) (MeVcm2/g) (MeVcm2/g)")
print("------------------------------------------------------")
procname_brems= ""
procname_ioni= ""
if ( part=="e+" or part=="e-" ):
procname_ioni= plist[0]
procname_brems= plist[1]
elif ( part=="mu+" or part=="mu-"):
procname_ioni= plist[2]
procname_brems= plist[3]
else:
procname_ioni= plist[4]
procname_brems= ""
dedx_list= []
for ekin in elist:
dedx= {}
dedx["ioni"] \
= gEmCalculator.ComputeDEDX(ekin, part, procname_ioni, mat) * MeV*cm2/g
dedx["brems"] \
= gEmCalculator.ComputeDEDX(ekin, part, procname_brems, mat) * MeV*cm2/g
dedx["tot"]= dedx["ioni"]+ dedx["brems"]
if(verbose>0):
print(" %8.3e %8.3e %8.3e %8.3e" \
% (ekin/MeV, dedx["ioni"]/(MeV*cm2/g),
dedx["brems"]/(MeV*cm2/g), dedx["tot"]/(MeV*cm2/g) ))
dedx_list.append((ekin, dedx))
return dedx_list
@@ -0,0 +1,10 @@
# - build library
set(_TARGET _ezgeom)
g4pytest_add_module(${_TARGET}
EzDetectorConstruction.cc
G4EzVolume.cc
G4EzVoxelParameterization.cc
G4EzWorld.cc
pyEzgeom.cc
)
target_link_libraries(${_TARGET} PRIVATE G4materials G4geometry G4run)
@@ -0,0 +1,58 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// EzDetectorConstruction.cc
//
// 2005 Q
// ====================================================================
#include "EzDetectorConstruction.hh"
#include "G4EzWorld.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////////////////
EzDetectorConstruction::EzDetectorConstruction()
////////////////////////////////////////////////
{
}
/////////////////////////////////////////////////
EzDetectorConstruction::~EzDetectorConstruction()
/////////////////////////////////////////////////
{
}
//////////////////////////////////////////////////////
G4VPhysicalVolume* EzDetectorConstruction::Construct()
//////////////////////////////////////////////////////
{
return G4EzWorld::GetWorldVolume();
}
@@ -0,0 +1,52 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// EzDetectorConstruction.hh
//
// 2005 Q
// ====================================================================
#ifndef EZ_DETECTOR_CONSTRUCTION_H
#define EZ_DETECTOR_CONSTRUCTION_H
#include "G4VUserDetectorConstruction.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class EzDetectorConstruction : public G4VUserDetectorConstruction {
public:
EzDetectorConstruction();
~EzDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
};
#endif
@@ -0,0 +1,311 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// G4EzVolume.cc
//
// 2005 Q
// ====================================================================
#include "G4Material.hh"
#include "G4Box.hh"
#include "G4Tubs.hh"
#include "G4Cons.hh"
#include "G4Sphere.hh"
#include "G4Orb.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4PVParameterised.hh"
#include "G4VisAttributes.hh"
#include "G4EzWorld.hh"
#include "G4EzVolume.hh"
#include "G4EzVoxelParameterization.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////
G4EzVolume::G4EzVolume()
: name("MyVolume"),
solid(0),
lv(0), lvsub(0),
nplacement(0)
////////////////////////
{
}
/////////////////////////////////////////////
G4EzVolume::G4EzVolume(const G4String& aname)
: name(aname), solid(0), lv(0), lvsub(0),
nplacement(0)
/////////////////////////////////////////////
{
}
/////////////////////////
G4EzVolume::~G4EzVolume()
/////////////////////////
{
}
///////////////////////////////////////////////////////////////////////
void G4EzVolume::CreateBoxVolume(G4Material* amaterial,
G4double dx, G4double dy, G4double dz)
///////////////////////////////////////////////////////////////////////
{
if(lv !=0 ) {
G4cout << "%%% Warning (G4EzVolume): volume is already created."
<< G4endl;
return;
}
solid= new G4Box(name, dx/2., dy/2., dz/2.);
lv= new G4LogicalVolume(solid, amaterial, name);
// vis. attributes
va= new G4VisAttributes();
lv-> SetVisAttributes(va);
}
////////////////////////////////////////////////////////////////////////////
void G4EzVolume::CreateTubeVolume(G4Material* amaterial,
G4double rmin, G4double rmax, G4double dz,
G4double phi0, G4double dphi)
////////////////////////////////////////////////////////////////////////////
{
if(lv !=0 ) {
G4cout << "%%% Warning (G4EzVolume): volume is already created."
<< G4endl;
return;
}
solid= new G4Tubs(name, rmin, rmax, dz, phi0, dphi);
lv= new G4LogicalVolume(solid, amaterial, name);
// vis. attributes
va= new G4VisAttributes();
lv-> SetVisAttributes(va);
}
/////////////////////////////////////////////////////////////////
void G4EzVolume::CreateConeVolume(G4Material* amaterial,
G4double rmin1, G4double rmax1,
G4double rmin2, G4double rmax2,
G4double dz,
G4double phi0, G4double dphi)
/////////////////////////////////////////////////////////////////
{
if(lv !=0 ) {
G4cout << "%%% Warning (G4EzVolume): volume is already created."
<< G4endl;
return;
}
solid= new G4Cons(name, rmin1, rmax1, rmin2, rmax2,
dz, phi0, dphi);
lv= new G4LogicalVolume(solid, amaterial, name);
// vis. attributes
va= new G4VisAttributes();
lv-> SetVisAttributes(va);
}
/////////////////////////////////////////////////////////////////////
void G4EzVolume::CreateSphereVolume(G4Material* amaterial,
G4double rmin, G4double rmax,
G4double phi0, G4double dphi,
G4double theta0, G4double dtheta)
/////////////////////////////////////////////////////////////////////
{
if(lv !=0 ) {
G4cout << "%%% Warning (G4EzVolume): volume is already created."
<< G4endl;
return;
}
solid= new G4Sphere(name, rmin, rmax, phi0, dphi, theta0, dtheta);
lv= new G4LogicalVolume(solid, amaterial, name);
// vis. attributes
va= new G4VisAttributes();
lv-> SetVisAttributes(va);
}
//////////////////////////////////////////////////////////////////////
void G4EzVolume::CreateOrbVolume(G4Material* amaterial, G4double rmax)
//////////////////////////////////////////////////////////////////////
{
if(lv !=0 ) {
G4cout << "%%% Warning (G4EzVolume): volume is already created."
<< G4endl;
return;
}
solid= new G4Orb(name, rmax);
lv= new G4LogicalVolume(solid, amaterial, name);
// vis. attributes
va= new G4VisAttributes();
lv-> SetVisAttributes(va);
}
////////////////////////////////////////////////////////////////
G4VPhysicalVolume* G4EzVolume::PlaceIt(const G4ThreeVector& pos,
G4int ncopy,
G4EzVolume* parent)
////////////////////////////////////////////////////////////////
{
if(lv==0) {
G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
<< G4endl;
return 0;
}
G4PVPlacement* pv;
if(parent==0) { // place it in the world
G4VPhysicalVolume* world= G4EzWorld::GetWorldVolume();
pv= new G4PVPlacement(0, pos, name, lv, world, false, ncopy);
} else {
pv= new G4PVPlacement(0, pos, lv, name, parent->lv, false, ncopy);
}
nplacement++;
return pv;
}
//////////////////////////////////////////////////////////////////////
G4VPhysicalVolume* G4EzVolume::PlaceIt(const G4Transform3D& transform,
G4int ncopy,
G4EzVolume* parent)
//////////////////////////////////////////////////////////////////////
{
if(lv==0) {
G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
<< G4endl;
return 0;
}
G4PVPlacement* pv;
if(parent==0) { // place it in the world
G4VPhysicalVolume* world= G4EzWorld::GetWorldVolume();
pv= new G4PVPlacement(transform, name, lv, world, false, ncopy);
} else {
pv= new G4PVPlacement(transform, lv, name, parent->lv, false, ncopy);
}
nplacement++;
return pv;
}
///////////////////////////////////////////////////////////////////////////
G4VPhysicalVolume* G4EzVolume::ReplicateIt(G4EzVolume* parent,
EAxis pAxis, G4int nReplicas,
G4double width, G4double offset)
///////////////////////////////////////////////////////////////////////////
{
if(lv==0) {
G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
<< G4endl;
return 0;
}
G4PVReplica* pv=
new G4PVReplica(name, lv, parent->lv, pAxis, nReplicas, width, offset);
nplacement += nReplicas;
return pv;
}
//////////////////////////////////////////////////////////////////
G4ThreeVector G4EzVolume::VoxelizeIt(G4int nx, G4int ny, G4int nz)
//////////////////////////////////////////////////////////////////
{
// creating voxel volume...
G4Box* avolume= dynamic_cast<G4Box*>(solid);
if(avolume ==0 ) {
G4cout << "%%% Error (G4EzVolume): voxelization is valid "
<< "only for Box geometry." << G4endl;
return G4ThreeVector();
}
if(lvsub !=0) {
G4cout << "%%% Error (G4EzVolume): already voxelized." << G4endl;
return G4ThreeVector();
}
G4double dx= (avolume-> GetXHalfLength())*2.;
G4double dy= (avolume-> GetYHalfLength())*2.;
G4double dz= (avolume-> GetZHalfLength())*2.;
// voxel size
G4double ddx= dx/nx;
G4double ddy= dy/ny;
G4double ddz= dz/nz;
G4Box* voxel= new G4Box("voxel", ddx/2., ddy/2., ddz/2.);
G4Material* voxelMaterial= lv-> GetMaterial();
lvsub= new G4LogicalVolume(voxel, voxelMaterial, "voxel");
G4VisAttributes* vavoxel= new G4VisAttributes(G4Color(1.,0.,0.));
lvsub-> SetVisAttributes(vavoxel);
G4EzVoxelParameterization* voxelParam=
new G4EzVoxelParameterization(ddx, ddy, ddz, nx, ny, nz);
G4int nvoxel= nx*ny*nz;
new G4PVParameterised(name+"_voxel", lvsub, lv, kXAxis,
nvoxel, voxelParam);
return G4ThreeVector(ddx, ddy, ddz);
}
////////////////////////////////////////////////////////////////
void G4EzVolume::SetSensitiveDetector(G4VSensitiveDetector* asd)
////////////////////////////////////////////////////////////////
{
if(lvsub!=0) {
lvsub-> SetSensitiveDetector(asd);
return;
}
if(lv!=0) lv-> SetSensitiveDetector(asd);
}
@@ -0,0 +1,165 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// G4EzVolume.hh
//
// Utility class for supporting creating user geometry
//
// * wrapper of logical volume
//
// 2005 Q
// ====================================================================
#ifndef G4_EZ_VOLUME_H
#define G4_EZ_VOLUME_H
#include "G4LogicalVolume.hh"
#include "G4VisAttributes.hh"
#include "G4Transform3D.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4Material;
class G4VSolid;
class G4VPhysicalVolume;
class G4EzVolume {
protected:
// volume information
G4String name;
G4VSolid* solid;
G4LogicalVolume* lv;
G4LogicalVolume* lvsub; // logical volume for voxels
G4VisAttributes* va;
G4int nplacement; // # of placements
public:
G4EzVolume();
G4EzVolume(const G4String& aname);
~G4EzVolume();
// createing volume
void CreateBoxVolume(G4Material* amaterial,
G4double dx, G4double dy, G4double dz);
void CreateTubeVolume(G4Material* amaterial,
G4double rmin, G4double rmax,
G4double dz,
G4double phi0=0., G4double dphi=360*deg);
void CreateConeVolume(G4Material* amaterial,
G4double rmin1, G4double rmax1,
G4double rmin2, G4double rmax2,
G4double dz,
G4double phi0=0., G4double dphi=360.*deg);
void CreateSphereVolume(G4Material* amaterial,
G4double rmin, G4double rmax,
G4double phi0=0., G4double dphi=360.*deg,
G4double theta0=0., G4double dtheta=180.*deg);
void CreateOrbVolume(G4Material* amaterial, G4double rmax);
// placement
G4VPhysicalVolume* PlaceIt(const G4ThreeVector& pos, G4int ncopy=0,
G4EzVolume* parent=0);
G4VPhysicalVolume* PlaceIt(const G4Transform3D& transform, G4int ncopy=0,
G4EzVolume* parent=0);
// replica
// parent volume should be exactly filled with replicated volumes.
G4VPhysicalVolume* ReplicateIt(G4EzVolume* parent,
EAxis pAxis, G4int nReplicas,
G4double width, G4double offset=0);
// voxelize
// volume should be "BOX". otherwise, error.
// returning voxel size in each dimension
G4ThreeVector VoxelizeIt(G4int nx, G4int ny, G4int nz);
// sensitivity
// in the case of voxelized, SD will be set to a voxel.
void SetSensitiveDetector(G4VSensitiveDetector* asd);
// direct access to properties
const G4String& GetName() const;
void SetSolid(G4VSolid* asolid);
const G4VSolid* GetSolid() const;
void SetMaterial(G4Material* amaterial);
G4Material* GetMaterial() const;
G4int GetNofPlacements() const;
void SetVisibility(G4bool qvisible);
void SetColor(const G4Color& color);
void SetColor(G4double red, G4double green, G4double blue);
};
// ====================================================================
// inline functions
// ====================================================================
inline const G4String& G4EzVolume::GetName() const { return name; }
inline void G4EzVolume::SetSolid(G4VSolid* asolid) { solid= asolid; }
inline const G4VSolid* G4EzVolume::GetSolid() const { return solid; }
inline void G4EzVolume::SetMaterial(G4Material* amaterial)
{
if(lv!= 0) lv-> SetMaterial(amaterial);
if(lvsub!= 0) lvsub-> SetMaterial(amaterial);
}
inline G4Material* G4EzVolume::GetMaterial() const
{
if(lv!=0) return lv-> GetMaterial();
else return 0;
}
inline G4int G4EzVolume::GetNofPlacements() const { return nplacement; }
inline void G4EzVolume::SetVisibility(G4bool qvisible)
{
if(va!=0) va-> SetVisibility(qvisible);
}
inline void G4EzVolume::SetColor(const G4Color& color)
{
if(va!=0) va-> SetColor(color);
}
inline void G4EzVolume::SetColor(G4double red, G4double green, G4double blue)
{
if(va!=0) va-> SetColor(red, green, blue);
}
#endif
@@ -0,0 +1,89 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// G4EzVoxelParameterization.cc
//
// 2005 Q
// ====================================================================
#include "G4EzVoxelParameterization.hh"
#include "G4Box.hh"
#include "G4VPhysicalVolume.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////////////////////////////////////////
G4EzVoxelParameterization::G4EzVoxelParameterization
(G4double ddx, G4double ddy, G4double ddz, G4int nx, G4int ny, G4int nz)
: voxelSize(ddx, ddy, ddz), motherSize(ddx*nx, ddy*ny, ddz*nz)
//////////////////////////////////////////////////////////////////////////
{
nvoxels[0]= nx;
nvoxels[1]= ny;
nvoxels[2]= nz;
}
///////////////////////////////////////////////////////
G4EzVoxelParameterization::~G4EzVoxelParameterization()
///////////////////////////////////////////////////////
{
}
///////////////////////////////////////////////////////////
void G4EzVoxelParameterization::ComputeTransformation
(const G4int copyNo, G4VPhysicalVolume* physVol) const
///////////////////////////////////////////////////////////
{
// copyNo-> index
G4int nxy= nvoxels[0]*nvoxels[1];
G4int iz= copyNo/nxy;
G4int ixy= copyNo - iz*nxy;
G4int iy= ixy/nvoxels[0];
G4int ix= ixy-iy*nvoxels[0];
// voxel position
G4double px= voxelSize[0]*(ix+0.5) - motherSize[0]/2.;
G4double py= voxelSize[1]*(iy+0.5) - motherSize[1]/2.;
G4double pz= voxelSize[2]*(iz+0.5) - motherSize[2]/2.;
physVol-> SetTranslation(G4ThreeVector(px, py, pz));
}
//////////////////////////////////////////////////////////////////////////////
void G4EzVoxelParameterization::ComputeDimensions
(G4Box& /*aBox*/, const G4int /*copyNo*/, const G4VPhysicalVolume* /*physVol*/) const
//////////////////////////////////////////////////////////////////////////////
{
return;
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// G4EzVoxelParameterization.hh
//
// 2005 Q
// ====================================================================
#ifndef G4EZ_VOXEL_PARAMETERIZATION_H
#define G4EZ_VOXEL_PARAMETERIZATION_H
#include "G4VPVParameterisation.hh"
#include "G4ThreeVector.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4EzVoxelParameterization : public G4VPVParameterisation {
protected:
G4ThreeVector voxelSize;
G4ThreeVector motherSize;
G4int nvoxels[3];
public:
G4EzVoxelParameterization(G4double ddx, G4double ddy, G4double ddz,
G4int nx, G4int ny, G4int nz);
~G4EzVoxelParameterization();
virtual void ComputeTransformation(const G4int copyNo,
G4VPhysicalVolume* physVol) const;
using G4VPVParameterisation::ComputeDimensions;
virtual void ComputeDimensions(G4Box& aBox, const G4int copyNo,
const G4VPhysicalVolume* physVol) const;
};
#endif
@@ -0,0 +1,137 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// G4EzWorld.cc
//
// 2005 Q
// ====================================================================
#include "G4EzWorld.hh"
#include "G4Element.hh"
#include "G4Material.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4VisAttributes.hh"
#include "G4RunManager.hh"
#include "G4PhysicalConstants.hh"
G4VPhysicalVolume* G4EzWorld::world= G4EzWorld::CreateWorld();
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////
G4EzWorld::G4EzWorld()
//////////////////////
{
}
///////////////////////
G4EzWorld::~G4EzWorld()
///////////////////////
{
world= 0;
}
//////////////////////////////////////////////////////////
G4VPhysicalVolume* G4EzWorld::CreateWorld
(G4double dx, G4double dy, G4double dz)
//////////////////////////////////////////////////////////
{
// default matetial is "vacuum"
G4Material* vacuum= G4Material::GetMaterial("_Vacuum", false);
if(vacuum==0) {
G4Element* elN= new G4Element("_N", "", 7., 14.00674*g/mole);
G4Element* elO= new G4Element("_O", "", 8., 15.9994*g/mole);
vacuum= new G4Material("_Vacuum", universe_mean_density, 2);
vacuum-> AddElement(elN, 0.7);
vacuum-> AddElement(elO, 0.3);
}
G4Box* sdworld= new G4Box("world", dx/2., dy/2., dz/2.);
G4LogicalVolume* lvworld= new G4LogicalVolume(sdworld, vacuum, "word");
G4PVPlacement* aworld= new G4PVPlacement(0, G4ThreeVector(), "world",
lvworld, 0, false, 0);
// vis. attributes
G4VisAttributes* vaworld= new G4VisAttributes(G4Color(1.,1.,1.));
vaworld-> SetForceWireframe(true);
lvworld-> SetVisAttributes(vaworld);
return aworld;
}
////////////////////////////////////////////////////////////
void G4EzWorld::Reset(G4double dx, G4double dy, G4double dz)
////////////////////////////////////////////////////////////
{
delete world;
world= CreateWorld(dx, dy, dz);
G4RunManager* runManager= G4RunManager::GetRunManager();
runManager-> DefineWorldVolume(world);
}
/////////////////////////////////////////////////////////////
void G4EzWorld::Resize(G4double dx, G4double dy, G4double dz)
/////////////////////////////////////////////////////////////
{
G4Box* box= dynamic_cast<G4Box*>(world-> GetLogicalVolume()-> GetSolid());
box-> SetXHalfLength(dx/2.);
box-> SetYHalfLength(dy/2.);
box-> SetZHalfLength(dz/2.);
G4RunManager* runManager= G4RunManager::GetRunManager();
runManager-> GeometryHasBeenModified();
}
//////////////////////////////////////////////////
void G4EzWorld::SetMaterial(G4Material* amaterial)
//////////////////////////////////////////////////
{
world-> GetLogicalVolume()-> SetMaterial(amaterial);
}
//////////////////////////////////////////
void G4EzWorld::SetVisibility(G4bool qvis)
//////////////////////////////////////////
{
G4VisAttributes* vaworld= const_cast<G4VisAttributes*>(
world-> GetLogicalVolume()-> GetVisAttributes());
vaworld-> SetVisibility(qvis);
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// G4EzWorld.hh
//
// Utility class for supporting creating user geometry
//
// management of a world volume
//
// 2005 Q
// ====================================================================
#ifndef G4_EZ_WORLD_H
#define G4_EZ_WORLD_H
#include "globals.hh"
#include "G4SystemOfUnits.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4Material;
class G4VPhysicalVolume;
class G4EzWorld {
protected:
// world volume is automatically presented.
static G4VPhysicalVolume* world;
static G4VPhysicalVolume* CreateWorld(G4double dx=1.*m,
G4double dy=1.*m,
G4double dz=1.*m);
public:
G4EzWorld();
~G4EzWorld();
static G4VPhysicalVolume* GetWorldVolume();
static void Reset(G4double dx, G4double dy, G4double dz);
static void Resize(G4double dx, G4double dy, G4double dz);
static void SetMaterial(G4Material* amaterial);
static void SetVisibility(G4bool qvis);
};
// ====================================================================
// inline functions
// ====================================================================
inline G4VPhysicalVolume* G4EzWorld::GetWorldVolume() { return world; }
#endif
@@ -0,0 +1 @@
from ._ezgeom import *
@@ -0,0 +1,158 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// pyEZgeom.cc
//
// [ezgeom]
// a site-module of Geant4Py
//
// An easy way to build geometry
//
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "EzDetectorConstruction.hh"
#include "G4EzWorld.hh"
#include "G4EzVolume.hh"
#include "G4RunManager.hh"
#include "G4VSensitiveDetector.hh"
using namespace boost::python;
// ====================================================================
// thin wrappers
// ====================================================================
namespace pyEZgeom {
// methods in global namespace
void Construct()
{
G4RunManager* runMgr= G4RunManager::GetRunManager();
runMgr-> SetUserInitialization(new EzDetectorConstruction);
}
void ResetWorld(G4double dx, G4double dy, G4double dz)
{
G4EzWorld::Reset(dx, dy, dz);
}
void ResizeWorld(G4double dx, G4double dy, G4double dz)
{
G4EzWorld::Resize(dx, dy, dz);
}
void SetWorldMaterial(G4Material* amaterial)
{
G4EzWorld::SetMaterial(amaterial);
}
void SetWorldVisibility(G4bool qvis)
{
G4EzWorld::SetVisibility(qvis);
}
// CreateTubeVolume
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_CreateTubeVolume,
CreateTubeVolume, 4, 6)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_CreateConeVolume,
CreateConeVolume, 6, 8)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_CreateSphereVolume,
CreateSphereVolume, 3, 7)
// PlaceIt
G4VPhysicalVolume*(G4EzVolume::*f1_PlaceIt)
(const G4ThreeVector&, G4int, G4EzVolume*) = &G4EzVolume::PlaceIt;
G4VPhysicalVolume*(G4EzVolume::*f2_PlaceIt)
(const G4Transform3D&, G4int, G4EzVolume*) = &G4EzVolume::PlaceIt;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_PlaceIt, PlaceIt, 1, 3)
// ReplicateIt
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_ReplicateIt, ReplicateIt, 4, 5)
// SetColor
void (G4EzVolume::*f1_SetColor)(const G4Color&) = &G4EzVolume::SetColor;
void (G4EzVolume::*f2_SetColor)(G4double, G4double, G4double)
= &G4EzVolume::SetColor;
}
using namespace pyEZgeom;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(_ezgeom) {
class_<G4EzVolume>("G4EzVolume", "an easy way of geometry configuration")
.def(init<const G4String&>())
// ---
.def("CreateBoxVolume", &G4EzVolume::CreateBoxVolume)
.def("CreateTubeVolume", &G4EzVolume::CreateTubeVolume,
f_CreateTubeVolume())
.def("CreateConeVolume", &G4EzVolume::CreateConeVolume,
f_CreateConeVolume())
.def("CreateShpereVolume", &G4EzVolume::CreateSphereVolume,
f_CreateSphereVolume())
.def("CreateOrbVolume", &G4EzVolume::CreateOrbVolume)
// ---
.def("SetSold", &G4EzVolume::SetSolid)
.def("GetSold", &G4EzVolume::GetSolid,
return_value_policy<reference_existing_object>())
.def("SetMaterial", &G4EzVolume::SetMaterial)
.def("GetMaterial", &G4EzVolume::GetMaterial,
return_value_policy<reference_existing_object>())
// ---
.def("PlaceIt", f1_PlaceIt,
f_PlaceIt()[return_value_policy<reference_existing_object>()])
.def("PlaceIt", f2_PlaceIt,
f_PlaceIt()[return_value_policy<reference_existing_object>()])
.def("ReplicateIt", &G4EzVolume::ReplicateIt,
f_ReplicateIt()[return_value_policy<reference_existing_object>()])
.def("VoxelizeIt", &G4EzVolume::VoxelizeIt)
// ---
.def("SetSensitiveDetector", &G4EzVolume::SetSensitiveDetector)
// ---
.def("SetColor", f1_SetColor)
.def("SetColor", f2_SetColor)
.def("SetVisibility", &G4EzVolume::SetVisibility)
;
// -------------------------------------------------------------------
def("Construct", Construct);
def("ResetWorld", ResetWorld);
def("ResizeWorld", ResizeWorld);
def("SetWorldMaterial", SetWorldMaterial);
def("SetWorldVisibility", SetWorldVisibility);
}
@@ -0,0 +1,4 @@
add_subdirectory(module)
configure_file(test.py test.py)
add_test(NAME geant4py-test01 COMMAND ${PYTHON_EXECUTABLE} test.py)
set_tests_properties(geant4py-test01 PROPERTIES ENVIRONMENT "PYTHONPATH=${GEANT4_PYTHON_OUTPUT_DIR};${GEANT4_TEST_ENVIRONMENT}")
+8
View File
@@ -0,0 +1,8 @@
# gun.mac
/gun/number 1
/gun/particle e-
/gun/energy 200 MeV
/gun/direction 0.2 0. 1.
/gun/position 0. 0. -14.9 cm
@@ -0,0 +1,16 @@
# - build test library
# library
set(_TARGET gtest01)
g4py_add_module(${_TARGET}
Particles.cc
PhysicsListEMstd.cc
QDetectorConstruction.cc
QEventAction.cc
QMaterials.cc
QPhysicsList.cc
QPrimaryGeneratorAction.cc
gtest01.cc
)
target_link_libraries(${_TARGET} PRIVATE G4particles G4processes G4run)
@@ -0,0 +1,80 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// Particles.cc
//
// Physics list for defining particles
//
// ====================================================================
#include "Particles.hh"
#include "G4LeptonConstructor.hh"
#include "G4BosonConstructor.hh"
#include "G4MesonConstructor.hh"
#include "G4BaryonConstructor.hh"
#include "G4ShortLivedConstructor.hh"
#include "G4IonConstructor.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////
Particles::Particles()
: G4VPhysicsConstructor("Particles")
//////////////////////////////////////
{
}
///////////////////////
Particles::~Particles()
///////////////////////
{
}
///////////////////////////////////
void Particles::ConstructParticle()
///////////////////////////////////
{
G4LeptonConstructor::ConstructParticle();
G4BosonConstructor::ConstructParticle();
G4MesonConstructor::ConstructParticle();
G4BaryonConstructor::ConstructParticle();
G4ShortLivedConstructor::ConstructParticle();
G4IonConstructor::ConstructParticle();
}
//////////////////////////////////
void Particles::ConstructProcess()
//////////////////////////////////
{
}
@@ -0,0 +1,53 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// Particles.hh
//
// 2004 Q
// ====================================================================
#ifndef PARTICLES_H
#define PARTICLES_H
#include "G4VPhysicsConstructor.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class Particles : public G4VPhysicsConstructor {
public:
Particles();
~Particles();
virtual void ConstructParticle();
virtual void ConstructProcess();
};
#endif
@@ -0,0 +1,121 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// PhysicsListEMstd.cc
//
// Physics list for electron/positron/gamma
// EM-standard package w/ default parameters
//
// ====================================================================
#include "PhysicsListEMstd.hh"
#include "G4ProcessManager.hh"
#include "G4ParticleDefinition.hh"
#include "G4Gamma.hh"
#include "G4Electron.hh"
#include "G4Positron.hh"
#include "G4NeutrinoE.hh"
#include "G4AntiNeutrinoE.hh"
#include "G4ComptonScattering.hh"
#include "G4GammaConversion.hh"
#include "G4PhotoElectricEffect.hh"
#include "G4eMultipleScattering.hh"
#include "G4eIonisation.hh"
#include "G4eBremsstrahlung.hh"
#include "G4eplusAnnihilation.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////
PhysicsListEMstd::PhysicsListEMstd()
: G4VPhysicsConstructor("EM-std")
////////////////////////////////////
{
}
/////////////////////////////////////
PhysicsListEMstd::~PhysicsListEMstd()
/////////////////////////////////////
{
}
//////////////////////////////////////////
void PhysicsListEMstd::ConstructParticle()
//////////////////////////////////////////
{
}
/////////////////////////////////////////
void PhysicsListEMstd::ConstructProcess()
/////////////////////////////////////////
{
G4ProcessManager* pm;
// ----------------------------------------------------------
// gamma physics
// ----------------------------------------------------------
pm= G4Gamma::Gamma()-> GetProcessManager();
pm-> AddDiscreteProcess(new G4PhotoElectricEffect);
pm-> AddDiscreteProcess(new G4ComptonScattering);
pm-> AddDiscreteProcess(new G4GammaConversion);
// ----------------------------------------------------------
// electron physics
// ----------------------------------------------------------
G4eMultipleScattering* msc= new G4eMultipleScattering;
G4eIonisation* eion= new G4eIonisation;
G4eBremsstrahlung* ebrems= new G4eBremsstrahlung;
pm= G4Electron::Electron()->GetProcessManager();
pm-> AddProcess(msc, ordInActive, 1, 1);
pm-> AddProcess(eion, ordInActive, 2, 2);
pm-> AddProcess(ebrems, ordInActive, ordInActive, 3);
// ----------------------------------------------------------
// positron physics
// ----------------------------------------------------------
msc= new G4eMultipleScattering;
eion= new G4eIonisation;
ebrems= new G4eBremsstrahlung;
G4eplusAnnihilation* annihilation= new G4eplusAnnihilation;
pm= G4Positron::Positron()-> GetProcessManager();
pm-> AddProcess(msc, ordInActive, 1, 1);
pm-> AddProcess(eion, ordInActive, 2, 2);
pm-> AddProcess(ebrems, ordInActive, ordInActive, 3);
pm-> AddProcess(annihilation, 0, ordInActive, 4);
}
@@ -0,0 +1,53 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// PhysicsListEMstd.hh
//
// 2004 Q
// ====================================================================
#ifndef PHYSICS_LIST_EM_STD_H
#define PHYSICS_LIST_EM_STD_H
#include "G4VPhysicsConstructor.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class PhysicsListEMstd : public G4VPhysicsConstructor {
public:
PhysicsListEMstd();
~PhysicsListEMstd();
virtual void ConstructParticle();
virtual void ConstructProcess();
};
#endif
@@ -0,0 +1,144 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QDetectorConstruction.cc
//
// 2005 Q
// ====================================================================
#include "QDetectorConstruction.hh"
#include "G4Material.hh"
#include "G4Tubs.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4VisAttributes.hh"
#include "G4SystemOfUnits.hh"
// ====================================================================
//
// class description
//
// ====================================================================
// constants (detector parameters)
static const G4double DXYZ_AREA= 30.*cm;
//////////////////////////////////////////////
QDetectorConstruction::QDetectorConstruction()
//////////////////////////////////////////////
{
}
///////////////////////////////////////////////
QDetectorConstruction::~QDetectorConstruction()
///////////////////////////////////////////////
{
}
/////////////////////////////////////////////////////
G4VPhysicalVolume* QDetectorConstruction::Construct()
/////////////////////////////////////////////////////
{
G4Material* mate;
G4VisAttributes* va;
// ==============================================================
// world volume
// ==============================================================
G4Box* areaSolid= new G4Box("AREA",
DXYZ_AREA/2., DXYZ_AREA/2., DXYZ_AREA/2.);
G4Material* vacuum= G4Material::GetMaterial("Vacuum");
G4LogicalVolume* areaLV= new G4LogicalVolume(areaSolid, vacuum, "AREA_LV");
G4PVPlacement* area= new G4PVPlacement(0, G4ThreeVector(), "AREA_PV",
areaLV, 0, false, 0);
// vis. attributes
va= new G4VisAttributes(G4Color(1.,1.,1.));
va-> SetForceWireframe(true);
areaLV-> SetVisAttributes(va);
// ==============================================================
// detectors
// ==============================================================
// voxel
const G4double dvoxel= 10.*mm;
const G4double dl= 10.*cm;
G4Box* svoxel= new G4Box("voxel", dvoxel, dl, dvoxel);
mate= G4Material::GetMaterial("Vacuum");
G4LogicalVolume* lvoxel= new G4LogicalVolume(svoxel, mate, "voxel");
va= new G4VisAttributes(G4Color(0.,0.8,0.8));
va-> SetVisibility(false);
lvoxel-> SetVisAttributes(va);
G4int ix, iz;
G4int index=0;
for (iz=0; iz<5; iz++) {
for (ix=-7; ix<=7; ix++) {
G4double x0= (2.*ix)*cm;
G4double z0= (-13.+2.*iz)*cm;
/*G4PVPlacement* pvoxel=*/ new G4PVPlacement(0, G4ThreeVector(x0, 0., z0),
lvoxel, "voxel", areaLV, false, index);
index++;
}
}
// tube
//G4Tubs* stube= new G4Tubs("tube", 15./2.*mm, 19./2.*mm, dl,
G4Tubs* stube= new G4Tubs("tube", 0.*mm, 19./2.*mm, dl,
0., 360.*deg);
mate= G4Material::GetMaterial("Al");
G4LogicalVolume* ltube= new G4LogicalVolume(stube, mate, "tube");
va= new G4VisAttributes(G4Color(0.,0.8,0.8));
ltube-> SetVisAttributes(va);
G4RotationMatrix* rmtube= new G4RotationMatrix;
rmtube-> rotateX(-90.*deg);
/*G4PVPlacement* ptube=*/ new G4PVPlacement(rmtube, G4ThreeVector(),
ltube, "tube", lvoxel, false, 0);
// cal
const G4double dxycal= 25.*mm;
const G4double dzcal= 3.*cm;
G4Box* scal= new G4Box("cal", dxycal, dxycal, dzcal);
mate= G4Material::GetMaterial("CsI");
G4LogicalVolume* lcal= new G4LogicalVolume(scal, mate, "cal");
va= new G4VisAttributes(G4Color(0.5,0.5,0.));
lcal-> SetVisAttributes(va);
index= 0;
for (ix=-2; ix<=2; ix++) {
G4double x0= (5.*ix)*cm;
/*G4PVPlacement* pcal=*/ new G4PVPlacement(0, G4ThreeVector(x0, 0., 2.*cm),
lcal, "cal", areaLV, false, index);
index++;
}
return area;
}
@@ -0,0 +1,52 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QDetectorConstruction.hh
//
// 2005 Q
// ====================================================================
#ifndef Q_DETECTOR_CONSTRUCTION_H
#define Q_DETECTOR_CONSTRUCTION_H
#include "G4VUserDetectorConstruction.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class QDetectorConstruction : public G4VUserDetectorConstruction {
public:
QDetectorConstruction();
~QDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
};
#endif
@@ -0,0 +1,68 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QEventAction.cc
//
// 2005 Q
// ====================================================================
#include "QEventAction.hh"
#include "globals.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////
QEventAction::QEventAction()
////////////////////////////
{
}
/////////////////////////////
QEventAction::~QEventAction()
/////////////////////////////
{
}
////////////////////////////////////////////////////////////
void QEventAction::BeginOfEventAction(const G4Event* /*aevent*/)
////////////////////////////////////////////////////////////
{
G4cout << "QEventAction::BofEA is called." << G4endl;
}
//////////////////////////////////////////////////////////
void QEventAction::EndOfEventAction(const G4Event* /*aevent*/)
//////////////////////////////////////////////////////////
{
G4cout << "QEventAction::EofEA is called." << G4endl;
}
@@ -0,0 +1,52 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QEventAction.hh
//
// 2005 Q
// ====================================================================
#ifndef Q_EVENT_ACTION_H
#define Q_EVENT_ACTION_H
#include "G4UserEventAction.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class QEventAction : public G4UserEventAction {
public:
QEventAction();
~QEventAction();
virtual void BeginOfEventAction(const G4Event* aevent);
virtual void EndOfEventAction(const G4Event* aevent);
};
#endif
@@ -0,0 +1,163 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QMaterials.cc
//
// 2005 Q
// ====================================================================
#include "QMaterials.hh"
#include "G4Material.hh"
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////
QMaterials::QMaterials()
////////////////////////
{
}
/////////////////////////
QMaterials::~QMaterials()
/////////////////////////
{
}
////////////////////////////
void QMaterials::Construct()
////////////////////////////
{
G4double A, Z;
// ------------------------------------------------------------------------
// Elements
// ------------------------------------------------------------------------
G4Element* elH = new G4Element("Hydrogen","H", Z=1., A=1.00794*g/mole);
G4Element* elC = new G4Element("Carbon", "C", Z=6., A= 12.011 *g/mole);
G4Element* elN = new G4Element("Nitrogen","N", Z=7., A= 14.00674*g/mole);
G4Element* elO = new G4Element("Oxygen", "O", Z=8., A= 15.9994*g/mole);
G4Element* elNa = new G4Element("Sodium", "Na", Z=11., A= 22.989768*g/mole);
G4Element* elSi = new G4Element("Silicon", "Si", Z=14., A= 28.0855*g/mole);
G4Element* elAr = new G4Element("Argon", "Ar", Z=18., A= 39.948*g/mole);
G4Element* elI = new G4Element("Iodine", "I", Z=53., A= 126.90447*g/mole);
G4Element* elCs = new G4Element("Cesium", "Cs", Z=55., A= 132.90543*g/mole);
// ------------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------------
G4double density, massfraction;
G4int natoms, nel;
// temperature of experimental hall is controlled at 20 degree.
const G4double expTemp= STP_Temperature+20.*kelvin;
// vacuum
density= universe_mean_density;
G4Material* Vacuum= new G4Material("Vacuum", density, nel=2);
Vacuum-> AddElement(elN, .7);
Vacuum-> AddElement(elO, .3);
// air
density= 1.2929e-03 *g/cm3; // at 20 degree
G4Material* Air= new G4Material("Air", density, nel=3,
kStateGas, expTemp);
G4double ttt= 75.47+23.20+1.28;
Air-> AddElement(elN, massfraction= 75.47/ttt);
Air-> AddElement(elO, massfraction= 23.20/ttt);
Air-> AddElement(elAr, massfraction= 1.28/ttt);
// Ar gas
A= 39.948 *g/mole;
const G4double denAr= 1.782e-03 *g/cm3 * STP_Temperature/expTemp;
G4Material* Ar= new G4Material("ArgonGas", Z=18., A, denAr,
kStateGas, expTemp);
// ethane (C2H6)
const G4double denEthane= 1.356e-3 *g/cm3 * STP_Temperature/expTemp;
G4Material* Ethane= new G4Material("Ethane", denEthane, nel=2,
kStateGas, expTemp);
Ethane-> AddElement(elC, natoms=2);
Ethane-> AddElement(elH, natoms=6);
// Ar(50%) + ethane(50%) mixture
density= (denAr+denEthane)/2.;
G4Material* ArEthane= new G4Material("ArEthane", density, nel=2,
kStateGas, expTemp);
ArEthane-> AddMaterial(Ar, massfraction= denAr/density/2.);
ArEthane-> AddMaterial(Ethane, massfraction= denEthane/density/2.);
// silicon
A= 28.0855 *g/mole;
density= 2.33 *g/cm3;
/*G4Material* Si=*/ new G4Material("SiliconWafer", Z=14., A, density);
// alminium
A= 26.98 *g/mole;
density= 2.70 *g/cm3;
/*G4Material* Al=*/ new G4Material("Al", Z=13., A, density);
// iron
A= 55.847 *g/mole;
density= 7.87 *g/cm3;
/*G4Material* Fe=*/ new G4Material("Iron", Z=26., A, density);
// lead
A= 207.2 *g/mole;
density= 11.35 *g/cm3;
/*G4Material* Pb=*/ new G4Material("Lead", Z=82., A, density);
// scintillator (Polystyene(C6H5CH=CH2))
density= 1.032 *g/cm3;
G4Material* Scinti= new G4Material("Scinti", density, nel=2);
Scinti-> AddElement(elC, natoms=8);
Scinti-> AddElement(elH, natoms=8);
// quartz (SiO2, crystalline)
density= 2.64 *g/cm3;
G4Material* Quartz= new G4Material("Quartz", density, nel= 2);
Quartz-> AddElement(elSi, natoms=1);
Quartz-> AddElement(elO, natoms=2);
// NaI crystal
density= 3.67 *g/cm3;
G4Material* NaI= new G4Material("NaI", density, nel= 2);
NaI-> AddElement(elNa, natoms=1);
NaI-> AddElement(elI, natoms=1);
// CsI crystal
density= 4.51 *g/cm3;
G4Material* CsI= new G4Material("CsI", density, nel= 2);
CsI-> AddElement(elCs, natoms=1);
CsI-> AddElement(elI, natoms=1);
}
@@ -0,0 +1,50 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QMaterials.hh
//
// 2005 Q
// ====================================================================
#ifndef Q_MATERIALS_H
#define Q_MATERIALS_H
#include "globals.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class QMaterials {
public:
QMaterials();
~QMaterials();
void Construct();
};
#endif
@@ -0,0 +1,72 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QPhysicsList.cc
//
// 2005 Q
// ====================================================================
#include "QPhysicsList.hh"
#include "Particles.hh"
#include "PhysicsListEMstd.hh"
#include "G4SystemOfUnits.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////
QPhysicsList::QPhysicsList()
: G4VModularPhysicsList()
////////////////////////////
{
// default cut value (1.0mm)
defaultCutValue = 1.*mm;
SetVerboseLevel(1);
// particles
RegisterPhysics(new Particles);
// EM Physics
RegisterPhysics(new PhysicsListEMstd);
}
/////////////////////////////
QPhysicsList::~QPhysicsList()
/////////////////////////////
{
}
////////////////////////////
void QPhysicsList::SetCuts()
////////////////////////////
{
// " G4VUserPhysicsList::SetCutsWithDefault" method sets
// the default cut value for all particle types
SetCutsWithDefault();
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// QPhysicsList.hh
//
// 2005 Q
// ====================================================================
#ifndef Q_PHYSICS_LIST_H
#define Q_PHYSICS_LIST_H
#include "G4VModularPhysicsList.hh"
#include "globals.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class QPhysicsList: public G4VModularPhysicsList {
public:
QPhysicsList();
~QPhysicsList();
virtual void SetCuts();
};
#endif
@@ -0,0 +1,60 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// QPrimaryGeneratorAction.cc
//
// 2005 Q
// ====================================================================
#include "QPrimaryGeneratorAction.hh"
#include "G4ParticleGun.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////////////////
QPrimaryGeneratorAction::QPrimaryGeneratorAction()
//////////////////////////////////////////////////
{
particleGun= new G4ParticleGun;
}
///////////////////////////////////////////////////
QPrimaryGeneratorAction::~QPrimaryGeneratorAction()
///////////////////////////////////////////////////
{
delete particleGun;
}
/////////////////////////////////////////////////////////////////
void QPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
/////////////////////////////////////////////////////////////////
{
particleGun-> GeneratePrimaryVertex(anEvent);
}
@@ -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. *
// ********************************************************************
//
// ====================================================================
// QPrimaryGeneratorAction.hh
//
// 2005 Q
// ====================================================================
#ifndef Q_PRIMARY_GENERATOR_ACTION_H
#define Q_PRIMARY_GENERATOR_ACTION_H
#include "G4VUserPrimaryGeneratorAction.hh"
class G4ParticleGun;
// ====================================================================
//
// class definition
//
// ====================================================================
class QPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
private:
// use G4 particle gun
G4ParticleGun* particleGun;
public:
QPrimaryGeneratorAction();
~QPrimaryGeneratorAction();
G4ParticleGun* GetParticleGun() const;
virtual void GeneratePrimaries(G4Event* anEvent);
};
// ====================================================================
// inline functions
// ====================================================================
inline G4ParticleGun* QPrimaryGeneratorAction::GetParticleGun() const
{ return particleGun; }
#endif
@@ -0,0 +1,73 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// ====================================================================
// gtest01.cc
//
// python wrapper for user application
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "QMaterials.hh"
#include "QDetectorConstruction.hh"
#include "QPhysicsList.hh"
#include "QPrimaryGeneratorAction.hh"
#include "G4ParticleGun.hh"
#include "QEventAction.hh"
using namespace boost::python;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(gtest01) {
class_<QMaterials>("QMaterials", "my material")
.def("Construct", &QMaterials::Construct)
;
class_<QDetectorConstruction, QDetectorConstruction*,
bases<G4VUserDetectorConstruction> >
("QDetectorConstruction", "my detector")
;
class_<QPhysicsList, QPhysicsList*,
bases<G4VUserPhysicsList> >
("QPhysicsList", "my physics list")
;
class_<QPrimaryGeneratorAction, QPrimaryGeneratorAction*,
bases<G4VUserPrimaryGeneratorAction> >
("QPrimaryGeneratorAction", "my primary generator action")
.def("GetParticleGun", &QPrimaryGeneratorAction::GetParticleGun,
return_internal_reference<>())
;
class_<QEventAction, QEventAction*,
bases<G4UserEventAction> >
("QEventAction", "my event action")
;
}
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest01
# - check basic control flow
# ==================================================================
from Geant4 import *
import gtest01
import ROOT
# ==================================================================
# ROOT PART #
# ==================================================================
# ------------------------------------------------------------------
def init_root():
# ------------------------------------------------------------------
ROOT.gROOT.Reset()
# plot style
ROOT.gStyle.SetTextFont(82)
ROOT.gStyle.SetTitleFont(82, "X")
ROOT.gStyle.SetLabelFont(82, "X")
ROOT.gStyle.SetTitleFont(82, "Y")
ROOT.gStyle.SetLabelFont(82, "Y")
#ROOT.gStyle.SetOptTitle(0)
ROOT.gStyle.SetErrorX(0)
canvas= ROOT.TCanvas("g4py_plots",
"Geant4Py Sample Plots",
620, 30, 600, 400)
#canvas.Divide(2,2);
#canvas.SetFillColor(29)
canvas.SetGrid()
return canvas
# ------------------------------------------------------------------
def hini():
# ------------------------------------------------------------------
global hist1
hist1= ROOT.TH1D("dE/dx/step", "dE/dx", 100, 0., 2000.)
hist1.SetXTitle("(keV)")
# ------------------------------------------------------------------
def hshow():
# ------------------------------------------------------------------
hist1.Draw()
# ==================================================================
# Geant4 PART #
# ==================================================================
# ==================================================================
# user actions in python
# ==================================================================
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
"My Primary Generator Action"
def __init__(self):
G4VUserPrimaryGeneratorAction.__init__(self)
self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event):
self.particleGun.GeneratePrimaryVertex(event)
# ------------------------------------------------------------------
class MyRunAction(G4UserRunAction):
"My Run Action"
def BeginOfRunAction(self, run):
print "*** #event to be processed (BRA)=",
run.numberOfEventToBeProcessed
def EndOfRunAction(self, run):
print "*** run end run(ERA)=", run.runID
# ------------------------------------------------------------------
class MyEventAction(G4UserEventAction):
"My Event Action"
def BeginOfEventAction(self, event):
print "*** current event (BEA)=", event.eventID
def EndOfEventAction(self, event):
print "*** current event (EEA)=", event.eventID
# ------------------------------------------------------------------
class MySteppingAction(G4UserSteppingAction):
"My Stepping Action"
def UserSteppingAction(self, step):
#print "*** dE/dx in current step=", step.GetTotalEnergyDeposit()
dedx= step.GetTotalEnergyDeposit()
if(dedx>0):
hist1.Fill(dedx/HEPUnit.keV)
# ==================================================================
# main
# ==================================================================
g4pyCanvas= init_root()
hini()
app= gtest01.MyApplication()
app.Configure()
# set user actions...
myPGA= MyPrimaryGeneratorAction()
gRunManager.SetUserAction(myPGA)
myRA= MyRunAction()
gRunManager.SetUserAction(myRA)
#myEA= MyEventAction()
#gRunManager.SetUserAction(myEA)
mySA= MySteppingAction()
gRunManager.SetUserAction(mySA)
# set particle gun
#ApplyUICommand("/control/execute gun.mac")
pg= myPGA.particleGun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(200.*HEPUnit.MeV)
pg.SetParticleMomentumDirection(G4ThreeVector(0.2, 0., 1.))
pg.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*HEPUnit.cm)
# visualization
ApplyUICommand("/control/execute vis.mac")
# beamOn
gRunManager.BeamOn(1000)
#
hshow()
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest01
# - check basic control flow
# ==================================================================
from Geant4 import *
import gtest01
import random
#import thread
# ==================================================================
# user actions in python
# ==================================================================
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
"My Primary Generator Action"
def __init__(self):
G4VUserPrimaryGeneratorAction.__init__(self)
self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event):
#dx= random.gauss(0., 0.1)
dx=0.
self.particleGun.SetParticleMomentumDirection(G4ThreeVector(dx, 0., 1.))
self.particleGun.GeneratePrimaryVertex(event)
# ------------------------------------------------------------------
class MyRunAction(G4UserRunAction):
"My Run Action"
def BeginOfRunAction(self, run):
print "*** #event to be processed (BRA)=",
run.GetNumberOfEventToBeProcessed()
def EndOfRunAction(self, run):
print "*** run end run(ERA)=", run.GetRunID()
# ------------------------------------------------------------------
class MyEventAction(G4UserEventAction):
"My Event Action"
#def BeginOfEventAction(self, event):
#print "*** current event (BEA)=", event.GetEventID()
# pass
#def EndOfEventAction(self, event):
# print "*** current event (EEA)=", event.GetEventID()
# ------------------------------------------------------------------
class MySteppingAction(G4UserSteppingAction):
"My Stepping Action"
def UserSteppingAction(self, step):
#print "*** dE/dx in current step=", step.GetTotalEnergyDeposit()
track= step.GetTrack()
touchable= track.GetTouchable()
pv= touchable.GetVolume()
#print pv.GetCopyNo()
#print touchable.GetReplicaNumber(0)
# ------------------------------------------------------------------
class MyField(G4MagneticField):
"My Magnetic Field"
def GetFieldValue(self, pos, time):
bfield= G4ThreeVector()
bfield.x= 0.
bfield.y= 5.*tesla
bfield.z= 0.
return bfield
# ==================================================================
# main
# ==================================================================
qMaterials= gtest01.QMaterials()
qMaterials.Construct()
qDC= gtest01.QDetectorConstruction()
gRunManager.SetUserInitialization(qDC)
qPL= gtest01.QPhysicsList()
gRunManager.SetUserInitialization(qPL)
# set user actions...
#qPGA= gtest01.QPrimaryGeneratorAction()
myPGA= MyPrimaryGeneratorAction()
gRunManager.SetUserAction(myPGA)
#myRA= MyRunAction()
#gRunManager.SetUserAction(myRA)
myEA= MyEventAction()
gRunManager.SetUserAction(myEA)
mySA= MySteppingAction()
gRunManager.SetUserAction(mySA)
# set particle gun
#ApplyUICommand("/control/execute gun.mac")
#pg= qPGA.GetParticleGun()
pg= myPGA.particleGun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(200.*MeV)
pg.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*cm)
# magnetic field
fieldMgr= gTransportationManager.GetFieldManager()
myField= G4UniformMagField(G4ThreeVector(0.,10.*tesla,0.))
#myField= MyField()
fieldMgr.SetDetectorField(myField)
fieldMgr.CreateChordFinder(myField)
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
gRunManager.BeamOn(10)
#thread.start_new_thread(gRunManager.BeamOn, (100000))
+118
View File
@@ -0,0 +1,118 @@
#!/usr/bin/python3
# ==================================================================
# python script for Geant4Py test
#
# gtest01
# - check basic control flow
# ==================================================================
from Geant4 import *
import gtest01
import random
# ==================================================================
# user actions in python
# ==================================================================
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
"My Primary Generator Action"
def __init__(self):
G4VUserPrimaryGeneratorAction.__init__(self)
self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event):
#dx= random.gauss(0., 0.1)
dx=0.
self.particleGun.SetParticleMomentumDirection(G4ThreeVector(dx, 0., 1.))
self.particleGun.GeneratePrimaryVertex(event)
# ------------------------------------------------------------------
class MyRunAction(G4UserRunAction):
"My Run Action"
def BeginOfRunAction(self, run):
print("*** #event to be processed (BRA)=",
run.GetNumberOfEventToBeProcessed())
def EndOfRunAction(self, run):
print("*** run end run(ERA)=", run.GetRunID())
# ------------------------------------------------------------------
class MyEventAction(G4UserEventAction):
"My Event Action"
#def BeginOfEventAction(self, event):
#print("*** current event (BEA)=", event.GetEventID())
# pass
#def EndOfEventAction(self, event):
#print("*** current event (EEA)=", event.GetEventID())
# ------------------------------------------------------------------
class MySteppingAction(G4UserSteppingAction):
"My Stepping Action"
def UserSteppingAction(self, step):
#print("*** dE/dx in current step=", step.GetTotalEnergyDeposit())
track= step.GetTrack()
touchable= track.GetTouchable()
pv= touchable.GetVolume()
#print(pv.GetCopyNo())
#print(touchable.GetReplicaNumber(0))
# ------------------------------------------------------------------
class MyField(G4MagneticField):
"My Magnetic Field"
def GetFieldValue(self, pos, time):
bfield= G4ThreeVector()
bfield.x= 0.
bfield.y= 5.*tesla
bfield.z= 0.
return bfield
# ==================================================================
# main
# ==================================================================
qMaterials= gtest01.QMaterials()
qMaterials.Construct()
qDC= gtest01.QDetectorConstruction()
gRunManager.SetUserInitialization(qDC)
qPL= gtest01.QPhysicsList()
gRunManager.SetUserInitialization(qPL)
# set user actions...
#qPGA= gtest01.QPrimaryGeneratorAction()
myPGA= MyPrimaryGeneratorAction()
gRunManager.SetUserAction(myPGA)
#myRA= MyRunAction()
#gRunManager.SetUserAction(myRA)
myEA= MyEventAction()
gRunManager.SetUserAction(myEA)
mySA= MySteppingAction()
gRunManager.SetUserAction(mySA)
# set particle gun
#ApplyUICommand("/control/execute gun.mac")
#pg= qPGA.GetParticleGun()
pg= myPGA.particleGun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(200.*MeV)
pg.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*cm)
# magnetic field
fieldMgr= gTransportationManager.GetFieldManager()
myField= G4UniformMagField(G4ThreeVector(0.,10.*tesla,0.))
#myField= MyField()
fieldMgr.SetDetectorField(myField)
fieldMgr.CreateChordFinder(myField)
gRunManager.Initialize()
# beamOn
gRunManager.BeamOn(10)
gTerminate()
+16
View File
@@ -0,0 +1,16 @@
# vis.mac
/vis/open OGLSX
/vis/scene/create
/vis/scene/add/volume
#/vis/scene/add/volume cal 3
/vis/sceneHandler/attach
/vis/viewer/set/viewpointThetaPhi 90. -90.
/tracking/storeTrajectory 1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
+11
View File
@@ -0,0 +1,11 @@
/vis/scene/create
/vis/scene/add/volume
/vis/sceneHandler/create VRML2FILE
/vis/viewer/create
/tracking/storeTrajectory 1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
@@ -0,0 +1,3 @@
configure_file(test.py test.py)
add_test(NAME geant4py-test02 COMMAND ${PYTHON_EXECUTABLE} test.py)
set_tests_properties(geant4py-test02 PROPERTIES ENVIRONMENT "PYTHONPATH=${GEANT4_PYTHON_OUTPUT_DIR};${GEANT4_TEST_ENVIRONMENT}")
+8
View File
@@ -0,0 +1,8 @@
# gun.mac
/gun/number 1
/gun/particle e-
/gun/energy 200 MeV
/gun/direction 0.2 0. 1.
/gun/position 0. 0. -14.9 cm
+133
View File
@@ -0,0 +1,133 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4py.Qmaterials, g4py.NISTmaterials
import g4py.Qgeom, g4py.ExN01geom, g4py.ExN03geom
import g4py.ExN01pl, g4py.EMSTDpl
import g4py.ParticleGun, g4py.MedicalBeam
# ==================================================================
# user setup
# ==================================================================
# ------------------------------------------------------------------
# Setup-0 (Q)
# ------------------------------------------------------------------
def Setup0():
# simple materials for Qgeom
g4py.Qmaterials.Construct()
# NIST materials
#g4py.NISTmaterials.Construct()
# normal way for constructing user geometry
#qDC= g4py.Qgeom.QDetectorConstruction()
#gRunManager.SetUserInitialization(qDC)
# 2nd way, short-cut way
g4py.Qgeom.Construct()
# primary
global primary_position, primary_direction
primary_position= G4ThreeVector(0.,0., -14.9*cm)
primary_direction= G4ThreeVector(0.2, 0., 1.)
# ------------------------------------------------------------------
# Setup-1 (ExampleN01)
# ------------------------------------------------------------------
def Setup1():
g4py.ExN01geom.Construct()
global primary_position, primary_direction
primary_position= G4ThreeVector(-2.5*m, 0., 0.)
primary_direction= G4ThreeVector(1., 0., 0.)
# ------------------------------------------------------------------
# Setup-3 (ExampleN03)
# ------------------------------------------------------------------
def Setup3():
#exN03geom= g4py.ExN03geom.ExN03DetectorConstruction()
#gRunManager.SetUserInitialization(exN03geom)
g4py.ExN03geom.Construct()
global primary_position, primary_direction
primary_position= G4ThreeVector(-1.*m, 0., 0.)
primary_direction= G4ThreeVector(1., 0., 0.)
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# ------------------------------------------------------------------
# user setup
# ------------------------------------------------------------------
Setup0()
#Setup1()
#Setup3()
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
# normal way for constructing user physics list
#exN01PL= ExN01PhysicsList.ExN01PhysicsList()
#gRunManager.SetUserInitialization(exN01PL)
# 2nd way, short-cut way
# geantino + transportation
#g4py.ExN01pl.Construct()
# electron/gamma standard EM
g4py.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
# ------------
# Particle Gun
# ------------
# normal way for constructing user physics list
#pgPGA= g4py.ParticleGun.ParticleGunAction()
#gRunManager.SetUserAction(pgPGA)
#pg= pgPGA.GetParticleGun()
# 2nd way, short-cut way
pg= g4py.ParticleGun.Construct()
# set parameters of particle gun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(300.*MeV)
pg.SetParticlePosition(primary_position)
pg.SetParticleMomentumDirection(primary_direction)
# ------------
# Medical Beam
# ------------
#beam= g4py.MedicalBeam.Construct()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gApplyUICommand("/control/execute vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+133
View File
@@ -0,0 +1,133 @@
#!/usr/bin/python3
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4pytest.Qmaterials, g4pytest.NISTmaterials
import g4pytest.Qgeom, g4pytest.ExN01geom, g4pytest.ExN03geom
import g4pytest.ExN01pl, g4pytest.EMSTDpl
import g4pytest.ParticleGun, g4pytest.MedicalBeam
# ==================================================================
# user setup
# ==================================================================
# ------------------------------------------------------------------
# Setup-0 (Q)
# ------------------------------------------------------------------
def Setup0():
# simple materials for Qgeom
g4pytest.Qmaterials.Construct()
# NIST materials
#g4pytest.NISTmaterials.Construct()
# normal way for constructing user geometry
#qDC= g4pytest.Qgeom.QDetectorConstruction()
#gRunManager.SetUserInitialization(qDC)
# 2nd way, short-cut way
g4pytest.Qgeom.Construct()
# primary
global primary_position, primary_direction
primary_position= G4ThreeVector(0.,0., -14.9*cm)
primary_direction= G4ThreeVector(0.2, 0., 1.)
# ------------------------------------------------------------------
# Setup-1 (ExampleN01)
# ------------------------------------------------------------------
def Setup1():
g4pytest.ExN01geom.Construct()
global primary_position, primary_direction
primary_position= G4ThreeVector(-2.5*m, 0., 0.)
primary_direction= G4ThreeVector(1., 0., 0.)
# ------------------------------------------------------------------
# Setup-3 (ExampleN03)
# ------------------------------------------------------------------
def Setup3():
#exN03geom= g4pytest.ExN03geom.ExN03DetectorConstruction()
#gRunManager.SetUserInitialization(exN03geom)
g4pytest.ExN03geom.Construct()
global primary_position, primary_direction
primary_position= G4ThreeVector(-1.*m, 0., 0.)
primary_direction= G4ThreeVector(1., 0., 0.)
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830)
# ------------------------------------------------------------------
# user setup
# ------------------------------------------------------------------
Setup0()
#Setup1()
#Setup3()
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
# normal way for constructing user physics list
#exN01PL= ExN01PhysicsList.ExN01PhysicsList()
#gRunManager.SetUserInitialization(exN01PL)
# 2nd way, short-cut way
# geantino + transportation
#g4pytest.ExN01pl.Construct()
# electron/gamma standard EM
g4pytest.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
# ------------
# Particle Gun
# ------------
# normal way for constructing user physics list
#pgPGA= g4pytest.ParticleGun.ParticleGunAction()
#gRunManager.SetUserAction(pgPGA)
#pg= pgPGA.GetParticleGun()
# 2nd way, short-cut way
pg= g4pytest.ParticleGun.Construct()
# set parameters of particle gun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(300.*MeV)
pg.SetParticlePosition(primary_position)
pg.SetParticleMomentumDirection(primary_direction)
# ------------
# Medical Beam
# ------------
#beam= g4pytest.MedicalBeam.Construct()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gApplyUICommand("/control/execute vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+16
View File
@@ -0,0 +1,16 @@
# vis.mac
/vis/open OGLSX
/vis/scene/create
/vis/scene/add/volume
/vis/sceneHandler/attach
#/vis/viewer/set/viewpointThetaPhi 180. 0.
/vis/viewer/set/viewpointThetaPhi 90. -90.
/tracking/storeTrajectory 1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
@@ -0,0 +1,3 @@
configure_file(test.py test.py)
add_test(NAME geant4py-test03 COMMAND ${PYTHON_EXECUTABLE} test.py)
set_tests_properties(geant4py-test03 PROPERTIES ENVIRONMENT "PYTHONPATH=${GEANT4_PYTHON_OUTPUT_DIR};${GEANT4_TEST_ENVIRONMENT}")
+8
View File
@@ -0,0 +1,8 @@
# gun.mac
/gun/number 1
/gun/particle gamma
/gun/energy 1 MeV
/gun/direction 0. 0. 1.
/gun/position 0. 0. -20. cm
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4py.NISTmaterials
import g4py.ezgeom
from g4py.ezgeom import G4EzVolume
import g4py.EMSTDpl
import g4py.ParticleGun
# ==================================================================
# intialize
# ==================================================================
def Configure():
# ------------------------------------------------------------------
# setup for materials
# ------------------------------------------------------------------
# simple materials for Qgeom
g4py.NISTmaterials.Construct()
# ------------------------------------------------------------------
# setup for geometry
# ------------------------------------------------------------------
#g4py.Qgeom.Construct()
g4py.ezgeom.Construct() # initialize
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
g4py.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
g4py.ParticleGun.Construct()
gControlExecute("gun.mac")
# ==================================================================
# constructing geometry
# ==================================================================
def ConstructGeom():
print "* Constructing geometry..."
# reset world material
air= G4Material.GetMaterial("G4_AIR")
g4py.ezgeom.SetWorldMaterial(air)
# target
global target
target= G4EzVolume("Target")
au= G4Material.GetMaterial("G4_Au")
target.CreateTubeVolume(au, 0., 1.*cm, 1.*mm)
target.PlaceIt(G4ThreeVector(0.,0.,-10.*cm))
# dummy box
global detector_box, detector_box_pv
detector_box= G4EzVolume("DetectorBox")
detector_box.CreateBoxVolume(air, 20.*cm, 20.*cm, 40.*cm)
detector_box_pv= detector_box.PlaceIt(G4ThreeVector(0.,0.,20.*cm))
# calorimeter
global cal
cal= G4EzVolume("Calorimeter")
nai= G4Material.GetMaterial("G4_SODIUM_IODIDE")
cal.CreateBoxVolume(nai, 5.*cm, 5.*cm, 30.*cm)
dd= 5.*cm
for ical in range(-1, 2):
calPos= G4ThreeVector(dd*ical, 0., 0.)
print calPos
cal.PlaceIt(calPos, ical+1, detector_box)
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# setup...
Configure()
ConstructGeom()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/python3
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4pytest.NISTmaterials
import g4pytest.ezgeom
from g4pytest.ezgeom import G4EzVolume
import g4pytest.EMSTDpl
import g4pytest.ParticleGun
# ==================================================================
# intialize
# ==================================================================
def Configure():
# ------------------------------------------------------------------
# setup for materials
# ------------------------------------------------------------------
# simple materials for Qgeom
g4pytest.NISTmaterials.Construct()
# ------------------------------------------------------------------
# setup for geometry
# ------------------------------------------------------------------
#g4pytest.Qgeom.Construct()
g4pytest.ezgeom.Construct() # initialize
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
g4pytest.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
g4pytest.ParticleGun.Construct()
gControlExecute("gun.mac")
# ==================================================================
# constructing geometry
# ==================================================================
def ConstructGeom():
print("* Constructing geometry...")
# reset world material
air= G4Material.GetMaterial("G4_AIR")
g4pytest.ezgeom.SetWorldMaterial(air)
# target
global target
target= G4EzVolume("Target")
au= G4Material.GetMaterial("G4_Au")
target.CreateTubeVolume(au, 0., 1.*cm, 1.*mm)
target.PlaceIt(G4ThreeVector(0.,0.,-10.*cm))
# dummy box
global detector_box, detector_box_pv
detector_box= G4EzVolume("DetectorBox")
detector_box.CreateBoxVolume(air, 20.*cm, 20.*cm, 40.*cm)
detector_box_pv= detector_box.PlaceIt(G4ThreeVector(0.,0.,20.*cm))
# calorimeter
global cal
cal= G4EzVolume("Calorimeter")
nai= G4Material.GetMaterial("G4_SODIUM_IODIDE")
cal.CreateBoxVolume(nai, 5.*cm, 5.*cm, 30.*cm)
dd= 5.*cm
for ical in range(-1, 2):
calPos= G4ThreeVector(dd*ical, 0., 0.)
print(calPos)
cal.PlaceIt(calPos, ical+1, detector_box)
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830)
# setup...
Configure()
ConstructGeom()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4py.NISTmaterials
import g4py.ezgeom
from g4py.ezgeom import G4EzVolume
import g4py.EMSTDpl
import g4py.ParticleGun
# ==================================================================
# intialize
# ==================================================================
def Configure():
# ------------------------------------------------------------------
# setup for materials
# ------------------------------------------------------------------
# simple materials for Qgeom
g4py.NISTmaterials.Construct()
# ------------------------------------------------------------------
# setup for geometry
# ------------------------------------------------------------------
#g4py.Qgeom.Construct()
g4py.ezgeom.Construct() # initialize
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
g4py.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
g4py.ParticleGun.Construct()
gControlExecute("gun.mac")
# ==================================================================
# constructing geometry
# ==================================================================
def ConstructGeom():
print "* Constructing geometry..."
# reset world material
air= G4Material.GetMaterial("G4_AIR")
g4py.ezgeom.SetWorldMaterial(air)
# phantom
global phantom
phantom= G4EzVolume("DetectorBox")
water= G4Material.GetMaterial("G4_WATER")
phantom.CreateBoxVolume(water, 40.*cm, 40.*cm, 50.*cm)
phantom.PlaceIt(G4ThreeVector(0.,0.,20.*cm))
vsize=phantom.VoxelizeIt(100, 100, 100)
print "voxel size=", vsize
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# setup...
Configure()
ConstructGeom()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+15
View File
@@ -0,0 +1,15 @@
# vis.mac
/vis/open OGLSX
/vis/scene/create
/vis/scene/add/volume
/vis/sceneHandler/attach
/vis/viewer/set/viewpointThetaPhi 270. 90.
/tracking/storeTrajectory 1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
@@ -0,0 +1,3 @@
configure_file(test.py test.py)
add_test(NAME geant4py-test04 COMMAND ${PYTHON_EXECUTABLE} test.py)
set_tests_properties(geant4py-test04 PROPERTIES ENVIRONMENT "PYTHONPATH=${GEANT4_PYTHON_OUTPUT_DIR};${GEANT4_TEST_ENVIRONMENT}")

Some files were not shown because too many files have changed in this diff Show More