Import Geant4 10.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 11:51:14 +02:00
parent e2d2f9810a
commit 286caacf06
12421 changed files with 730077 additions and 502383 deletions
+13 -6
View File
@@ -8,16 +8,23 @@
This directory includes example applications to demonstrate the usage of
different techniques for achieving event parallelism with Geant4.
- \link ExampleParN02 ParN02 \endlink and
\link ExampleParN04 ParN04 \endlink are modified versions of the novice examples N02 and N04
adapted to be run together with the TOP-C communication layer application
on either a cluster of systems or multi-processor machines.
- \link Examples_MPI MPI \endlink is a native interface with MPI libraries.
The directory contains
a Geant4 UI library and a couple of parallelized examples.
Using this interface, users applications can be parllelized with
different MPI compliant libraries, such as LAM/MPI, MPICH2, OpenMPI,
and so on.
and so on.
<br><br>
- \link Examples_tbb Examples TBB \endlink demonstrate how to
interface a simple application with the Intel Threading Building Blocks
library (TBB), and organise MT event-level parallelism as TBB tasks.
<br><br>
- TopC examples are Geant4 examples adapted to be run together with
the TOP-C communication layer application on either a cluster of systems
or multi-processor machines. They are based on N02 and N04 examples,
originally provided in novice examples (see more in \ref README_novice)
<br><br>
*/
+12
View File
@@ -2,6 +2,11 @@
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
find_package(Geant4)
include(${Geant4_USE_FILE})
#----------------------------------------------------------------------------
find_package(MPI QUIET)
if(MPI_CXX_FOUND)
add_subdirectory(MPI)
@@ -9,3 +14,10 @@ else()
message(STATUS "G4 Examples: MPI not installed --> MPI examples disabled")
endif()
find_package(TBB QUIET)
if(TBB_FOUND)
add_subdirectory(TBB)
else()
message(STATUS "G4 Examples: TBB not installed --> TBB example disabled")
endif()
+18
View File
@@ -10,5 +10,23 @@
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
03 December 2013, I. Hrivnacova (exparallel-V09-06-04)
- Fixed file descriptions (for Doxygen)
10 November 2013, I. Hrivnacova (exparallel-V09-06-03)
- Fixed README and CMake files
08 November 2013, I. Hrivnacova (exparallel-V09-06-02)
- Moved ParN02, ParN04 and info in a new TopC directory,
and removed ParN02tbb (its is still kept in the branch
ParN02tbb_08_11_2013)
27 August 2013, G. Cosmo (exparallel-V09-06-01)
- Added G4Ellipsoid among solids enabled for parameterisation
in examples ParN02, ParN02tbb, ParN04 and MPI/exMPI02.
25 June 2013, I. Hrivnacova (exparallel-V09-06-00)
- Added ParN02tbb example and updated CMakeLists.txt.
16 November 2012, I. Hrivnacova (exparallel-V09-05-00)
- Added CMakeLists.txt file in the top directory
+2 -2
View File
@@ -117,7 +117,7 @@ MPI runtime Environment
-----------------------
1. Make hosts/cluster configuration of your MPI environment.
2. Launch MPI runtime environment, typically executing
`lamboot` (LAM) / `mpdboot` (MPICH2).
`lamboot` (LAM) / `mpdboot` (MPICH2) / `mpd` (Inrel).
How to run
----------
@@ -188,7 +188,7 @@ A simple application.
- Geometry : chamber / calorimeter
- Primary : particle gun (200 MeV electron as default)
- Physics List : standard EM
- Physics List : FTFT_BERT
**Features:**
- Particles are transported in a geometry without any scoring.
+13
View File
@@ -9,6 +9,19 @@
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
10 Novembeer 2013 K. Murakami (MPI-V09-06-00)
[source]
- new coding guide line
- CMakeLists.txt, add BUILD_SHARED_LIBS flag for creating static lib
add check IntelMPI, mpiicpc
- MT migration : beamOn thread stacked to main for MT
use /run/beamOn command, instead of direct call of RM.BeamOn()
[examples]
- change coding guideling to the example guide
- MT migration
- PhysicsList is changed to FTFP_BERT
- add run.mac
20 November 2012, I. Hrivnacova (MPI-V09-05-06)
- Fixed .README files
+71 -62
View File
@@ -129,66 +129,75 @@ pre code {
.right {text-align:right}
</style><style type="text/css">
body{font-size:14px;line-height:1.6;font-family: Helvetica, arial, freesans, clean, sans-serif;padding: 20px;}
body>*:first-child{margin-top:0!important;}
body>*:last-child{margin-bottom:0!important;}
body a:active {outline: none;}
body a:hover {text-decoration: underline;}
body a {color: #4183C4;text-decoration: none;}
body a.absent{color:#c00;}
body h1, body h2, h3, h4, h5, h6{margin:20px 0 10px;padding:0;font-weight:bold;-webkit-font-smoothing:antialiased;}
body h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code{font-size:inherit;}
body h1{font-size:28px;color:#000;}
body h2{font-size:24px;border-bottom:1px solid #ccc;color:#000;}
body h3{font-size:18px;}
body h4{font-size:16px;}
body h5{font-size:14px;}
body h6{color:#777;font-size:14px;}
body p, blockquote, ul, ol, dl, li, table, pre{margin:15px 0;}
body hr{background:transparent url('../../images/modules/pulls/dirty-shade.png') repeat-x 0 0;border:0 none;color:#ccc;height:4px;padding:0;}
body>h2:first-child,>h1:first-child,>h1:first-child+h2,>h3:first-child,>h4:first-child,>h5:first-child,>h6:first-child{margin-top:0;padding-top:0;}
body h1+p, h2+p, h3+p, h4+p, h5+p, h6+p{margin-top:0;}
body li p.first{display:inline-block;}
body ul, ol{padding-left:30px;}
body ul li>:first-child, ol li>:first-child{margin-top:0;}
body ul li>:last-child, ol li>:last-child{margin-bottom:0;}
body dl{padding:0;}
body dl dt{font-size:14px;font-weight:bold;font-style:italic;padding:0;margin:15px 0 5px;}
body dl dt:first-child{padding:0;}
body dl dt>:first-child{margin-top:0;}
body dl dt>:last-child{margin-bottom:0;}
body dl dd{margin:0 0 15px;padding:0 15px;}
body dl dd>:first-child{margin-top:0;}
body dl dd>:last-child{margin-bottom:0;}
body blockquote{border-left:4px solid #DDD;padding:0 15px;color:#777;}
body blockquote>:first-child{margin-top:0;}
body blockquote>:last-child{margin-bottom:0;}
body table{padding:0;}
body table tr{border-top:1px solid #ccc;background-color:#fff;margin:0;padding:0;}
body table tr:nth-child(2n){background-color:#f8f8f8;}
body table tr th{font-weight:bold;}
body table tr th, table tr td{border:1px solid #ccc;text-align:left;margin:0;padding:6px 13px;}
body table tr th>:first-child, table tr td>:first-child{margin-top:0;}
body table tr th>:last-child, table tr td>:last-child{margin-bottom:0;}
body img{max-width:100%;}
body span.frame{display:block;overflow:hidden;}
body span.frame>span{border:1px solid #ddd;display:block;float:left;overflow:hidden;margin:13px 0 0;padding:7px;width:auto;}
body span.frame span img{display:block;float:left;}
body span.frame span span{clear:both;color:#333;display:block;padding:5px 0 0;}
body span.align-center{display:block;overflow:hidden;clear:both;}
body span.align-center>span{display:block;overflow:hidden;margin:13px auto 0;text-align:center;}
body span.align-center span img{margin:0 auto;text-align:center;}
body span.align-right{display:block;overflow:hidden;clear:both;}
body span.align-right>span{display:block;overflow:hidden;margin:13px 0 0;text-align:right;}
body span.align-right span img{margin:0;text-align:right;}
body span.float-left{display:block;margin-right:13px;overflow:hidden;float:left;}
body span.float-left span{margin:13px 0 0;}
body span.float-right{display:block;margin-left:13px;overflow:hidden;float:right;}
body span.float-right>span{display:block;overflow:hidden;margin:13px auto 0;text-align:right;}
body code, tt{margin:0 2px;padding:0 5px;white-space:nowrap;border:1px solid #eaeaea;background-color:#f8f8f8;border-radius:3px;}
body pre>code{margin:0;padding:0;white-space:pre;border:none;background:transparent;}
body .highlight pre, pre{background-color:#f8f8f8;border:1px solid #ccc;font-size:13px;line-height:19px;overflow:auto;padding:6px 10px;border-radius:3px;}
body pre code, pre tt{background-color:transparent;border:none;}
body {
font-family: "Geneva", Arial, sans-serif;
font-size: 13px;
margin: 10px;
}
a, a:visited {
color: #09c;
}
a:hover {
color: #336699;
text-decoration: none;
}
h1 {
margin: 0px 0px 10px;
font-weight: bold;
}
h2 {
border-bottom: 2px dotted #ccc;
margin: 5px 0px 15px;
}
h6 {
color: #09c;
}
blockquote {
font-family: "Georgia", Courier New, courier, sans-serif;
background: #efefef;
padding: 5px 10px;
border: solid 1px #ddd;
margin: 15px;
-webkit-border-radius:6px;
-moz-border-radius:6px;
border-radius:6px;
color: #333;
}
ul, ol {
margin-bottom: 15px;
}
li {
padding: 3px;
}
code {
background-color: #f1f1f1;
color: #336699;
}
pre {
background-color: #f1f1f1;
}
pre > code {
margin: 0px;
padding: 5px;
border: 0px;
background-color: #f1f1f1;
}
</style></head>
<body>
<h1>Geant4 MPI Interface</h1>
@@ -298,7 +307,7 @@ to the dynamic linker configuration using <code>ldconfig</code>.
<ol>
<li>Make hosts/cluster configuration of your MPI environment.</li>
<li>Launch MPI runtime environment, typically executing
<code>lamboot</code> (LAM) / <code>mpdboot</code> (MPICH2).</li>
<code>lamboot</code> (LAM) / <code>mpdboot</code> (MPICH2) / <code>mpd</code> (Intel).</li>
</ol>
<h2>How to run</h2>
@@ -373,7 +382,7 @@ for running examples:</p>
<ul>
<li>Geometry : chamber / calorimeter</li>
<li>Primary : particle gun (200 MeV electron as default)</li>
<li>Physics List : standard EM</li>
<li>Physics List : FTFP_BERT</li>
</ul>
<p><strong>Features:</strong></p>
+2 -2
View File
@@ -110,7 +110,7 @@ MPI runtime Environment
-----------------------
1. Make hosts/cluster configuration of your MPI environment.
2. Launch MPI runtime environment, typically executing
`lamboot` (LAM) / `mpdboot` (MPICH2).
`lamboot` (LAM) / `mpdboot` (MPICH2) / `mpd` (Intel).
How to run
----------
@@ -180,7 +180,7 @@ A simple application.
- Geometry : chamber / calorimeter
- Primary : particle gun (200 MeV electron as default)
- Physics List : standard EM
- Physics List : FTFP_BERT
**Features:**
- Particles are transported in a geometry without any scoring.
@@ -12,7 +12,7 @@ A simple application
- Geometry : chamber / calorimeter
- Primary : particle gun (200 MeV electron as default)
- Physics List : standard EM
- Physics List : FTFP_BERT
The environment variable *G4LEDATA* for low energy EM data is required.
@@ -8,8 +8,11 @@ project(exMPI01)
#----------------------------------------------------------------------------
# check MPI package...
find_package(MPI REQUIRED)
# modify these var. if needed
# modify these variables if needed
set(CMAKE_CXX_COMPILER mpicxx)
#set(CMAKE_CXX_COMPILER mpiicpc)
#set(CMAKE_CXX_INCLUDE_PATH )
#------------------------------------------------------------------------------
@@ -69,6 +72,7 @@ set_target_properties(exMPI01
# relies on these scripts being in the current working directory.
#
set(exMPI01_SCRIPTS
run.mac
v.mac
)
@@ -1,23 +0,0 @@
$Id: History,v 1.3 2010-06-06 05:07:23 perl Exp $
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
exMPI01 History
---------------
27 October 2012 K. Murakami
- migrated to CMake build
- updated documentations
4 June 2010 J.Perl
- Updated vis usage.
18 May 2010 K.Murakami
- use G4UIcsh instead of G4UItcsh because OpenMPI is now default.
- use G4eMultipleScattering instead of obsolete G4MultipleScattering.
16 Nov. 2007 K.Murakami
- commited to G4 CVS.
@@ -129,66 +129,75 @@ pre code {
.right {text-align:right}
</style><style type="text/css">
body{font-size:14px;line-height:1.6;font-family: Helvetica, arial, freesans, clean, sans-serif;padding: 20px;}
body>*:first-child{margin-top:0!important;}
body>*:last-child{margin-bottom:0!important;}
body a:active {outline: none;}
body a:hover {text-decoration: underline;}
body a {color: #4183C4;text-decoration: none;}
body a.absent{color:#c00;}
body h1, body h2, h3, h4, h5, h6{margin:20px 0 10px;padding:0;font-weight:bold;-webkit-font-smoothing:antialiased;}
body h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code{font-size:inherit;}
body h1{font-size:28px;color:#000;}
body h2{font-size:24px;border-bottom:1px solid #ccc;color:#000;}
body h3{font-size:18px;}
body h4{font-size:16px;}
body h5{font-size:14px;}
body h6{color:#777;font-size:14px;}
body p, blockquote, ul, ol, dl, li, table, pre{margin:15px 0;}
body hr{background:transparent url('../../images/modules/pulls/dirty-shade.png') repeat-x 0 0;border:0 none;color:#ccc;height:4px;padding:0;}
body>h2:first-child,>h1:first-child,>h1:first-child+h2,>h3:first-child,>h4:first-child,>h5:first-child,>h6:first-child{margin-top:0;padding-top:0;}
body h1+p, h2+p, h3+p, h4+p, h5+p, h6+p{margin-top:0;}
body li p.first{display:inline-block;}
body ul, ol{padding-left:30px;}
body ul li>:first-child, ol li>:first-child{margin-top:0;}
body ul li>:last-child, ol li>:last-child{margin-bottom:0;}
body dl{padding:0;}
body dl dt{font-size:14px;font-weight:bold;font-style:italic;padding:0;margin:15px 0 5px;}
body dl dt:first-child{padding:0;}
body dl dt>:first-child{margin-top:0;}
body dl dt>:last-child{margin-bottom:0;}
body dl dd{margin:0 0 15px;padding:0 15px;}
body dl dd>:first-child{margin-top:0;}
body dl dd>:last-child{margin-bottom:0;}
body blockquote{border-left:4px solid #DDD;padding:0 15px;color:#777;}
body blockquote>:first-child{margin-top:0;}
body blockquote>:last-child{margin-bottom:0;}
body table{padding:0;}
body table tr{border-top:1px solid #ccc;background-color:#fff;margin:0;padding:0;}
body table tr:nth-child(2n){background-color:#f8f8f8;}
body table tr th{font-weight:bold;}
body table tr th, table tr td{border:1px solid #ccc;text-align:left;margin:0;padding:6px 13px;}
body table tr th>:first-child, table tr td>:first-child{margin-top:0;}
body table tr th>:last-child, table tr td>:last-child{margin-bottom:0;}
body img{max-width:100%;}
body span.frame{display:block;overflow:hidden;}
body span.frame>span{border:1px solid #ddd;display:block;float:left;overflow:hidden;margin:13px 0 0;padding:7px;width:auto;}
body span.frame span img{display:block;float:left;}
body span.frame span span{clear:both;color:#333;display:block;padding:5px 0 0;}
body span.align-center{display:block;overflow:hidden;clear:both;}
body span.align-center>span{display:block;overflow:hidden;margin:13px auto 0;text-align:center;}
body span.align-center span img{margin:0 auto;text-align:center;}
body span.align-right{display:block;overflow:hidden;clear:both;}
body span.align-right>span{display:block;overflow:hidden;margin:13px 0 0;text-align:right;}
body span.align-right span img{margin:0;text-align:right;}
body span.float-left{display:block;margin-right:13px;overflow:hidden;float:left;}
body span.float-left span{margin:13px 0 0;}
body span.float-right{display:block;margin-left:13px;overflow:hidden;float:right;}
body span.float-right>span{display:block;overflow:hidden;margin:13px auto 0;text-align:right;}
body code, tt{margin:0 2px;padding:0 5px;white-space:nowrap;border:1px solid #eaeaea;background-color:#f8f8f8;border-radius:3px;}
body pre>code{margin:0;padding:0;white-space:pre;border:none;background:transparent;}
body .highlight pre, pre{background-color:#f8f8f8;border:1px solid #ccc;font-size:13px;line-height:19px;overflow:auto;padding:6px 10px;border-radius:3px;}
body pre code, pre tt{background-color:transparent;border:none;}
body {
font-family: "Geneva", Arial, sans-serif;
font-size: 13px;
margin: 10px;
}
a, a:visited {
color: #09c;
}
a:hover {
color: #336699;
text-decoration: none;
}
h1 {
margin: 0px 0px 10px;
font-weight: bold;
}
h2 {
border-bottom: 2px dotted #ccc;
margin: 5px 0px 15px;
}
h6 {
color: #09c;
}
blockquote {
font-family: "Georgia", Courier New, courier, sans-serif;
background: #efefef;
padding: 5px 10px;
border: solid 1px #ddd;
margin: 15px;
-webkit-border-radius:6px;
-moz-border-radius:6px;
border-radius:6px;
color: #333;
}
ul, ol {
margin-bottom: 15px;
}
li {
padding: 3px;
}
code {
background-color: #f1f1f1;
color: #336699;
}
pre {
background-color: #f1f1f1;
}
pre > code {
margin: 0px;
padding: 5px;
border: 0px;
background-color: #f1f1f1;
}
</style></head>
<body>
<h1>MPI/Examples : exMPI01</h1>
@@ -202,11 +211,9 @@ body pre code, pre tt{background-color:transparent;border:none;}
<ul>
<li>Geometry : chamber / calorimeter</li>
<li>Primary : particle gun (200 MeV electron as default)</li>
<li>Physics List : standard EM</li>
<li>Physics List : FTFP_BERT</li>
</ul>
<p>The environment variable <em>G4LEDATA</em> for low energy EM data is required.</p>
<h3>Features:</h3>
<ul>
@@ -9,9 +9,7 @@ A simple application
- Geometry : chamber / calorimeter
- Primary : particle gun (200 MeV electron as default)
- Physics List : standard EM
The environment variable *G4LEDATA* for low energy EM data is required.
- Physics List : FTFP_BERT
### Features:
@@ -23,30 +23,36 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file exMPI01.cc
// $Id: exMPI01.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @brief A MPI example code
#include "G4RunManager.hh"
#include "G4UImanager.hh"
// my application
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "PrimaryGeneratorAction.hh"
// MPI session
#include "G4MPImanager.hh"
#include "G4MPIsession.hh"
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "FTFP_BERT.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
int main(int argc, char** argv)
{
// random engine
//CLHEP::HepJamesRandom randomEngine;
CLHEP::Ranlux64Engine randomEngine;
CLHEP::HepRandom::setTheEngine(&randomEngine);
CLHEP::MTwistEngine randomEngine;
G4Random::setTheEngine(&randomEngine);
// --------------------------------------------------------------------
// MPI session
@@ -67,12 +73,17 @@ int main(int argc, char** argv)
// --------------------------------------------------------------------
// user application setting
// --------------------------------------------------------------------
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager();
runManager-> SetNumberOfThreads(4);
#else
G4RunManager* runManager = new G4RunManager();
#endif
// setup your application
runManager-> SetUserInitialization(new DetectorConstruction);
runManager-> SetUserInitialization(new PhysicsList);
runManager-> SetUserAction(new PrimaryGeneratorAction);
runManager-> SetUserInitialization(new FTFP_BERT);
runManager-> SetUserInitialization(new ActionInitialization);
runManager-> Initialize();
@@ -100,5 +111,5 @@ int main(int argc, char** argv)
delete runManager;
return 0;
return EXIT_SUCCESS;
}
@@ -22,21 +22,24 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file Particles.hh
/// @brief Define particles
//
// $Id: PrimaryGeneratorAction.hh 66587 2012-12-21 11:06:44Z ihrivnac $
//
/// @file PrimaryGeneratrorAction.hh
/// @brief Define primary generator action
#ifndef PARTICLES_H
#define PARTICLES_H
#ifndef ACTION_INITIALIZATION_H
#define ACTION_INITIALIZATION_H
#include "G4VPhysicsConstructor.hh"
#include "G4VUserActionInitialization.hh"
class Particles : public G4VPhysicsConstructor {
class ActionInitialization : public G4VUserActionInitialization {
public:
Particles();
~Particles();
ActionInitialization();
~ActionInitialization();
virtual void Build() const;
virtual void ConstructParticle();
virtual void ConstructProcess();
};
#endif
@@ -22,10 +22,12 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: DetectorConstruction.hh 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file DetectorConstruction.hh
/// @brief Define geometry
#ifndef DETECTOR_CONSTRUCTION_H
#define DETECTOR_CONSTRUCTION_H
@@ -34,9 +36,10 @@
class DetectorConstruction : public G4VUserDetectorConstruction {
public:
DetectorConstruction();
~DetectorConstruction();
~DetectorConstruction();
virtual G4VPhysicalVolume* Construct();
virtual G4VPhysicalVolume* Construct();
virtual void ConstructSDandField();
};
#endif
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: Materials.hh 71843 2013-06-25 16:58:09Z gcosmo $
//
/// @file Materials.hh
/// @brief Define materials
@@ -22,12 +22,15 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: PrimaryGeneratorAction.hh 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file PrimaryGeneratrorAction.hh
/// @brief Define primary generator action
#ifndef PRIMARY_GENERATOR_ACTION_H
#define PRIMARY_GENERATOR_ACTION_H
#include "G4VUserPrimaryGeneratorAction.hh"
class G4ParticleGun;
@@ -40,7 +43,7 @@ public:
virtual void GeneratePrimaries(G4Event* anEvent);
private:
G4ParticleGun* particleGun;
G4ParticleGun* fparticleGun;
};
#endif
@@ -0,0 +1,4 @@
/run/beamOn 40000
/mpi/status
@@ -22,36 +22,28 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file PhysicsList.cc
/// @brief Define physics list
//
// $Id: PrimaryGeneratorAction.cc 66587 2012-12-21 11:06:44Z ihrivnac $
//
/// @file PrimaryGeneratrorAction.cc
/// @brief Define primary generator action
#include "PhysicsList.hh"
#include "Particles.hh"
#include "PhysicsListEMstd.hh"
#include "G4SystemOfUnits.hh"
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
// --------------------------------------------------------------------------
PhysicsList::PhysicsList()
: G4VModularPhysicsList()
{
// default cut value (1.0mm)
defaultCutValue = 1.*mm;
SetVerboseLevel(1);
// particles
RegisterPhysics(new Particles);
// EM Physics
RegisterPhysics(new PhysicsListEMstd);
}
// --------------------------------------------------------------------------
PhysicsList::~PhysicsList()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization()
: G4VUserActionInitialization()
{
}
// --------------------------------------------------------------------------
void PhysicsList::SetCuts()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::~ActionInitialization()
{
SetCutsWithDefault();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::Build() const
{
SetUserAction(new PrimaryGeneratorAction);
}
@@ -22,34 +22,33 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: DetectorConstruction.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file DetectorConstruction.cc
/// @brief Define geometry
#include "DetectorConstruction.hh"
#include "Materials.hh"
#include "G4Material.hh"
#include "G4Tubs.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4PVPlacement.hh"
#include "G4VisAttributes.hh"
#include "G4SystemOfUnits.hh"
#include "G4Tubs.hh"
#include "G4VisAttributes.hh"
#include "DetectorConstruction.hh"
#include "Materials.hh"
// constants (detector parameters)
static const G4double DXYZ_AREA= 32.*cm;
static const G4double DW= 10.*cm;
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::Construct()
{
// material definition
@@ -60,18 +59,19 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
G4VisAttributes* va;
// world volume
G4Box* areaSolid = new G4Box("AREA",
DXYZ_AREA/2., DXYZ_AREA/2., DXYZ_AREA/2.);
const G4double DXYZ_AREA = 32.*cm;
G4Box* areaSolid = new G4Box("AREA", DXYZ_AREA/2., DXYZ_AREA/2.,
DXYZ_AREA/2.);
G4Material* vacuum = G4Material::GetMaterial("Vacuum");
G4Material* vacuum = G4Material::GetMaterial("Vacuum");
G4LogicalVolume* areaLV = new G4LogicalVolume(areaSolid, vacuum, "AREA_LV");
G4PVPlacement* area = new G4PVPlacement(0, G4ThreeVector(), "AREA_PV",
G4PVPlacement* area = new G4PVPlacement(0, G4ThreeVector(), "AREA_PV",
areaLV, 0, false, 0);
// vis. attributes
va = new G4VisAttributes(G4Color(1.,1.,1.));
va-> SetVisibility(false);
areaLV-> SetVisAttributes(va);
// detectors
// voxel
const G4double dvoxel = 10.*mm;
@@ -86,8 +86,8 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
G4int ix, iz;
G4int index = 0;
for (iz = 0; iz < 5; iz++) {
for (ix = -7; ix <= 7; ix++) {
for ( iz = 0; iz < 5; iz++ ) {
for ( ix = -7; ix <= 7; ix++ ) {
G4double x0 = (2.*ix) * cm;
G4double z0 = (-13.+2.*iz) * cm;
new G4PVPlacement(0, G4ThreeVector(x0, 0., z0),
@@ -97,8 +97,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
}
// tube
G4Tubs* stube = new G4Tubs("tube", 0.*mm, 19./2.*mm, dl,
0., 360.*deg);
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));
@@ -108,7 +107,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
rmtube-> rotateX(-90.*deg);
new G4PVPlacement(rmtube, G4ThreeVector(),
ltube, "tube", lvoxel, false, 0);
// cal
const G4double dxycal = 25.*mm;
const G4double dzcal = 3.*cm;
@@ -120,7 +119,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
lcal-> SetVisAttributes(va);
index = 0;
for (ix = -2; ix <= 2; ix++) {
for ( ix = -2; ix <= 2; ix++ ) {
G4double x0 = (5.*ix)*cm;
new G4PVPlacement(0, G4ThreeVector(x0, 0., 2.*cm),
lcal, "cal", areaLV, false, index);
@@ -129,3 +128,8 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
return area;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructSDandField()
{
}
@@ -22,25 +22,28 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: Materials.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file Materials.cc
/// @brief Define materials
#include "Materials.hh"
#include "G4Material.hh"
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
#include "Materials.hh"
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Materials::Materials()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Materials::~Materials()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Materials::Construct()
{
G4double A, Z;
@@ -57,7 +60,7 @@ void Materials::Construct()
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
// ------------------------------------------------------------------------
@@ -65,7 +68,7 @@ void Materials::Construct()
G4int natoms, nel;
// temperature of experimental hall is controlled at 20 degree.
const G4double expTemp = STP_Temperature+20.*kelvin;
const G4double expTemp = STP_Temperature+20.*kelvin;
// vacuum
density = universe_mean_density;
@@ -75,7 +78,7 @@ void Materials::Construct()
// air
density = 1.2929e-03 *g/cm3; // at 20 degree
G4Material* Air = new G4Material("Air", density, nel=3,
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);
@@ -98,7 +101,7 @@ void Materials::Construct()
// Ar(50%) + ethane(50%) mixture
density = (denAr+denEthane)/2.;
G4Material* ArEthane = new G4Material("ArEthane", density, nel=2,
kStateGas, expTemp);
kStateGas, expTemp);
ArEthane-> AddMaterial(Ar, massfraction= denAr/density/2.);
ArEthane-> AddMaterial(Ethane, massfraction= denEthane/density/2.);
@@ -1,101 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file PhysicsListEMstd.cc
/// @brief Define standard EM physics list
#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"
// --------------------------------------------------------------------------
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);
}
@@ -22,37 +22,40 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: PrimaryGeneratorAction.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file PrimaryGeneratrorAction.cc
/// @brief Define primary generator action
#include "PrimaryGeneratorAction.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4SystemOfUnits.hh"
#include "PrimaryGeneratorAction.hh"
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::PrimaryGeneratorAction()
{
particleGun = new G4ParticleGun;
fparticleGun = new G4ParticleGun;
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition* particle = particleTable-> FindParticle("e-");
particleGun-> SetParticleDefinition(particle);
particleGun-> SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
particleGun->SetParticlePosition(G4ThreeVector(0.,0.,-14.9*cm));
particleGun-> SetParticleEnergy(200.*MeV);
fparticleGun-> SetParticleDefinition(particle);
fparticleGun-> SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fparticleGun->SetParticlePosition(G4ThreeVector(0.,0.,-14.9*cm));
fparticleGun-> SetParticleEnergy(200.*MeV);
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::~PrimaryGeneratorAction()
{
delete particleGun;
delete fparticleGun;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
particleGun-> GeneratePrimaryVertex(anEvent);
fparticleGun-> GeneratePrimaryVertex(anEvent);
}
@@ -8,8 +8,11 @@ project(exMPI02)
#------------------------------------------------------------------------------
# check MPI package...
find_package(MPI REQUIRED)
# modify these var. if needed
# modify these variables if needed
set(CMAKE_CXX_COMPILER mpicxx)
#set(CMAKE_CXX_COMPILER mpiicpc)
#set(CMAKE_CXX_INCLUDE_PATH )
#----------------------------------------------------------------------------
@@ -37,7 +40,7 @@ include(${Geant4_USE_FILE})
#
find_package(ROOT QUIET)
if(NOT ROOT_FOUND)
message(STATUS "G4 Examples: ROOT package not found. --> exMPI02 example disabled")
message(STATUS "G4 Examples: ROOT package not found. --> exMPI02 example disabled")
return()
endif()
@@ -60,7 +63,7 @@ file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIR}
${ROOT_INCLUDE_DIR})
@@ -81,6 +84,7 @@ set_target_properties(exMPI02
# relies on these scripts being in the current working directory.
#
set(exMPI02_SCRIPTS
run.mac
v.mac
)
@@ -1,24 +0,0 @@
$Id: History,v 1.3 2010-06-06 05:07:23 perl Exp $
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
exMPI02 History
---------------
27 October 2012 K. Murakami
- migrated to CMake build
- Physis list is changed to FTFP_BERT
- updated documentations
4 June 2010 J.Perl
- Updated vis usage.
18 May 2010 K.Murakami
- use G4UIcsh instead of G4UItcsh because OpenMPI is now default.
16 Nov. 2007 K.Murakami
- commited to G4 CVS.
@@ -23,32 +23,31 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file exMPI02.cc
// $Id: exMPI02.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @brief A MPI example code
#include "G4RunManager.hh"
#include "G4UImanager.hh"
// my application
#include "DetectorConstruction.hh"
#include "MedicalBeam.hh"
#include "FTFP_BERT.hh"
#include "RunAction.hh"
#include "EventAction.hh"
// MPI session
#include "G4MPImanager.hh"
#include "G4MPIsession.hh"
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "FTFP_BERT.hh"
int main(int argc, char** argv)
{
// random engine
//CLHEP::Ranlux64Engine randomEngine;
//CLHEP::HepRandom::setTheEngine(&randomEngine);
// --------------------------------------------------------------------
// MPI session
// --------------------------------------------------------------------
@@ -68,14 +67,17 @@ int main(int argc, char** argv)
// --------------------------------------------------------------------
// user application setting
// --------------------------------------------------------------------
G4RunManager* runManager= new G4RunManager();
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager();
runManager-> SetNumberOfThreads(4);
#else
G4RunManager* runManager = new G4RunManager();
#endif
// setup your application
runManager-> SetUserInitialization(new DetectorConstruction);
runManager-> SetUserInitialization(new FTFP_BERT);
runManager-> SetUserAction(new MedicalBeam);
runManager-> SetUserAction(new RunAction);
runManager-> SetUserAction(new EventAction);
runManager-> SetUserInitialization(new ActionInitialization);
runManager-> Initialize();
@@ -92,8 +94,9 @@ int main(int argc, char** argv)
// --------------------------------------------------------------------
session-> SessionStart();
// --------------------------------------------------------------------
// termination
// --------------------------------------------------------------------
#ifdef G4VIS_USE
delete visManager;
#endif
@@ -102,5 +105,5 @@ int main(int argc, char** argv)
delete runManager;
return 0;
return EXIT_SUCCESS;
}
@@ -22,21 +22,24 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file PhysicsList.hh
/// @brief Define physics list
//
// $Id: PrimaryGeneratorAction.hh 66587 2012-12-21 11:06:44Z ihrivnac $
//
/// @file PrimaryGeneratrorAction.hh
/// @brief Define primary generator action
#ifndef PHYSICS_LIST_H
#define PHYSICS_LIST_H
#ifndef ACTION_INITIALIZATION_H
#define ACTION_INITIALIZATION_H
#include "G4VModularPhysicsList.hh"
#include "globals.hh"
#include "G4VUserActionInitialization.hh"
class PhysicsList: public G4VModularPhysicsList {
class ActionInitialization : public G4VUserActionInitialization {
public:
PhysicsList();
~PhysicsList();
virtual void SetCuts();
ActionInitialization();
~ActionInitialization();
virtual void BuildForMaster() const;
virtual void Build() const;
};
#endif
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: Analysis.hh 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file Analysis.hh
/// @brief Define histograms
@@ -30,6 +33,10 @@
#include "G4ThreeVector.hh"
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
class TH1D;
class TH2D;
@@ -49,21 +56,22 @@ public:
void ClearIncidentFlag();
private:
static Analysis* myanalysis;
Analysis();
DISALLOW_COPY_AND_ASSIGN(Analysis);
TH2D* incident_map;
TH1D* incident_x_hist;
TH2D* fincident_map;
TH1D* fincident_x_hist;
TH2D* dose_map;
TH1D* dose_hist;
TH2D* fdose_map;
TH1D* fdose_hist;
Analysis(); // protected
G4bool incidentFlag;
static G4ThreadLocal G4int fincidentFlag;
};
// ====================================================================
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void Analysis::ClearIncidentFlag()
{ incidentFlag= false; }
{
fincidentFlag = false;
}
#endif
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: DetectorConstruction.hh 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file DetectorConstruction.hh
/// @brief Define geometry
@@ -30,12 +33,19 @@
#include "G4VUserDetectorConstruction.hh"
class G4LogicalVolume;
class DetectorConstruction : public G4VUserDetectorConstruction {
public:
DetectorConstruction();
~DetectorConstruction();
~DetectorConstruction();
virtual G4VPhysicalVolume* Construct();
virtual void ConstructSDandField();
private:
G4LogicalVolume* flv_voxel;
virtual G4VPhysicalVolume* Construct();
};
#endif
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: EventAction.hh 71843 2013-06-25 16:58:09Z gcosmo $
//
/// @file EventAction.hh
/// @brief Describe event actions
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MedicalBeam.hh 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file MedicalBeam.hh
/// @brief Define beam profile as primary generator
@@ -36,7 +39,7 @@ class G4ParticleDefinition;
class MedicalBeam : public G4VUserPrimaryGeneratorAction {
public:
enum FieldShape{ SQUARE=0, CIRCLE };
enum FieldShape{ kSQUARE=0, kCIRCLE };
MedicalBeam();
~MedicalBeam();
@@ -60,72 +63,103 @@ public:
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);
protected:
G4ParticleDefinition* particle;
G4double kineticE;
G4ThreeVector sourcePosition;
G4double SSD; // (SSD= Source Skin Depth)
FieldShape fieldShape;
G4double fieldXY[2];
G4double fieldR;
private:
// local methods...
G4ThreeVector GenerateBeamDirection() const;
G4ParticleDefinition* fparticle;
G4double fkineticE;
G4ThreeVector fsourcePosition;
G4double fSSD; // (SSD= Source Skin Depth)
FieldShape ffieldShape;
G4double ffieldXY[2];
G4double ffieldR;
};
// ====================================================================
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void MedicalBeam::SetParticleDefinition(G4ParticleDefinition* pd)
{ particle= pd; }
{
fparticle = pd;
}
inline const G4ParticleDefinition* MedicalBeam::GetParticleDefinition() const
{ return particle; }
{
return fparticle;
}
inline void MedicalBeam::SetKineticE(G4double e)
{ kineticE= e; }
{
fkineticE = e;
}
inline G4double MedicalBeam::GetKineticE() const
{ return kineticE; }
{
return fkineticE;
}
inline void MedicalBeam::SetSourcePosition(const G4ThreeVector& pos)
{ sourcePosition= pos; }
{
fsourcePosition = pos;
}
inline G4ThreeVector MedicalBeam::GetSourcePosition() const
{ return sourcePosition; }
{
return fsourcePosition;
}
inline void MedicalBeam::SetFieldShape(MedicalBeam::FieldShape shape)
{ fieldShape= shape; }
{
ffieldShape = shape;
}
inline MedicalBeam::FieldShape MedicalBeam::GetFieldShape() const
{ return fieldShape; }
{
return ffieldShape;
}
inline void MedicalBeam::SetSSD(G4double ssd)
{ SSD= ssd; }
{
fSSD = ssd;
}
inline G4double MedicalBeam::GetSSD() const
{ return SSD; }
{
return fSSD;
}
inline void MedicalBeam::SetFieldXY(G4double fx, G4double fy)
{ fieldXY[0]= fx; fieldXY[1]= fy; }
{
ffieldXY[0] = fx;
ffieldXY[1] = fy;
}
inline G4double MedicalBeam::GetFieldX() const
{ return fieldXY[0]; }
{
return ffieldXY[0];
}
inline G4double MedicalBeam::GetFieldY() const
{ return fieldXY[1]; }
{
return ffieldXY[1];
}
inline void MedicalBeam::SetFieldR(G4double r)
{ fieldR= r; }
{
ffieldR = r;
}
inline G4double MedicalBeam::GetFieldR() const
{ return fieldR; }
{
return ffieldR;
}
#endif
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: RunAction.hh 71843 2013-06-25 16:58:09Z gcosmo $
//
/// @file RunAction.hh
/// @brief Describe run actions
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: VoxelParam.hh 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file VoxelParam.hh
/// @brief Define voxel parameterization
@@ -40,7 +43,7 @@ public:
virtual void ComputeDimensions(G4Box& box, const G4int id,
const G4VPhysicalVolume* vol) const;
virtual void ComputeDimensions
(G4Trd&,const G4int,const G4VPhysicalVolume*) const {}
@@ -52,26 +55,28 @@ public:
virtual void ComputeDimensions
(G4Sphere&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Orb&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Torus&,const G4int,const G4VPhysicalVolume*) const {}
(G4Ellipsoid&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Torus&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Para&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Hype&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Tubs&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Polycone&,const G4int,const G4VPhysicalVolume*) const {}
virtual void ComputeDimensions
(G4Polyhedra&,const G4int,const G4VPhysicalVolume*) const {}
@@ -22,6 +22,9 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: VoxelSD.hh 71843 2013-06-25 16:58:09Z gcosmo $
//
/// @file VoxelSD.hh
/// @brief Define detector sensitivity on voxels
@@ -0,0 +1,4 @@
/run/beamOn 40000
/mpi/status
@@ -0,0 +1,59 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: PrimaryGeneratorAction.cc 66587 2012-12-21 11:06:44Z ihrivnac $
//
/// @file PrimaryGeneratrorAction.cc
/// @brief Define primary generator action
#include "ActionInitialization.hh"
#include "EventAction.hh"
#include "MedicalBeam.hh"
#include "RunAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization()
: G4VUserActionInitialization()
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::~ActionInitialization()
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::BuildForMaster() const
{
SetUserAction(new RunAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::Build() const
{
SetUserAction(new MedicalBeam);
SetUserAction(new EventAction);
SetUserAction(new RunAction);
}
@@ -22,100 +22,92 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: Analysis.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file Analysis.cc
/// @brief Define histograms
#include "Analysis.hh"
#include "G4SystemOfUnits.hh"
// ROOT headers
#include "TROOT.h"
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TROOT.h"
#include "G4SystemOfUnits.hh"
#include "Analysis.hh"
Analysis* Analysis::myanalysis = NULL;
G4ThreadLocal G4int Analysis::fincidentFlag = false;
// --------------------------------------------------------------------------
Analysis::Analysis()
{
// ROOT style
gROOT-> Reset();
// define histograms
incident_map = new TH2D("incident map", "Incident Distributuon",
50, -5., 5.,
50, -5., 5.);
incident_map-> GetXaxis()-> SetTitle("X (cm)");
incident_map-> GetYaxis()-> SetTitle("Y (cm)");
incident_map-> SetStats(0);
incident_x_hist = new TH1D("incident x", "Incident X", 100, -5., 5.);
incident_x_hist-> GetXaxis()-> SetTitle("X (cm)");
incident_x_hist-> SetFillColor(kRed);
dose_map = new TH2D("dose map", "Dose Distribution",
500, 0., 50.,
200, -10., 10.);
dose_map-> GetXaxis()-> SetTitle("Z (cm)");
dose_map-> GetYaxis()-> SetTitle("X (cm)");
dose_map-> SetStats(0);
dose_hist = new TH1D("dose", "Dose Distribution", 500, 0., 50.);
dose_hist-> GetXaxis()-> SetTitle("Z (cm)");
dose_hist-> GetYaxis()-> SetTitle("Dose (GeV)");
dose_hist-> SetFillColor(kBlue);
dose_hist-> SetStats(0);
}
// --------------------------------------------------------------------------
Analysis::~Analysis()
{
delete incident_map;
delete incident_x_hist;
delete dose_map;
delete dose_hist;
myanalysis = NULL;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Analysis* Analysis::GetAnalysis()
{
if ( myanalysis == NULL ) {
myanalysis = new Analysis();
}
return myanalysis;
static Analysis the_analysis;
return &the_analysis;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Analysis::Analysis()
{
// define histograms
fincident_map = new TH2D("incident map", "Incident Distributuon",
50, -5., 5.,
50, -5., 5.);
fincident_map-> GetXaxis()-> SetTitle("X (cm)");
fincident_map-> GetYaxis()-> SetTitle("Y (cm)");
fincident_map-> SetStats(0);
fincident_x_hist = new TH1D("incident x", "Incident X", 100, -5., 5.);
fincident_x_hist-> GetXaxis()-> SetTitle("X (cm)");
fincident_x_hist-> SetFillColor(kRed);
fdose_map = new TH2D("dose map", "Dose Distribution",
500, 0., 50.,
200, -10., 10.);
fdose_map-> GetXaxis()-> SetTitle("Z (cm)");
fdose_map-> GetYaxis()-> SetTitle("X (cm)");
fdose_map-> SetStats(0);
fdose_hist = new TH1D("dose", "Dose Distribution", 500, 0., 50.);
fdose_hist-> GetXaxis()-> SetTitle("Z (cm)");
fdose_hist-> GetYaxis()-> SetTitle("Dose (GeV)");
fdose_hist-> SetFillColor(kBlue);
fdose_hist-> SetStats(0);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Analysis::~Analysis()
{
delete fincident_map;
delete fincident_x_hist;
delete fdose_map;
delete fdose_hist;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Analysis::Update()
{
return;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Analysis::Clear()
{
incident_map-> Reset();
incident_x_hist-> Reset();
dose_map-> Reset();
dose_hist-> Reset();
fincident_map-> Reset();
fincident_x_hist-> Reset();
fdose_map-> Reset();
fdose_hist-> Reset();
return;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Analysis::Save(const G4String& fname)
{
TFile* file = new TFile(fname.c_str(),
"RECREATE", "Geant4 ROOT analysis");
incident_map-> Write();
incident_x_hist-> Write();
dose_map-> Write();
dose_hist-> Write();
TFile* file = new TFile(fname.c_str(), "RECREATE", "Geant4 ROOT analysis");
fincident_map-> Write();
fincident_x_hist-> Write();
fdose_map-> Write();
fdose_hist-> Write();
file-> Close();
@@ -124,29 +116,28 @@ void Analysis::Save(const G4String& fname)
return;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Analysis::FillIncident(const G4ThreeVector& p)
{
if ( ! incidentFlag ) {
incident_map-> Fill(p.x()/cm, p.y()/cm);
incident_x_hist-> Fill(p.x()/cm);
if ( ! fincidentFlag ) {
fincident_map-> Fill(p.x()/cm, p.y()/cm);
fincident_x_hist-> Fill(p.x()/cm);
incidentFlag = true;
fincidentFlag = true;
}
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Analysis::FillDose(const G4ThreeVector& p, G4double dedx)
{
const G4double Z0 = 25.*cm;
const G4double dxy = 10.*mm;
if(std::abs(p.y()) < dxy ) {
dose_map-> Fill((p.z()+Z0)/cm, p.x()/cm, dedx/GeV);
if(std::abs(p.x()) < dxy) {
dose_hist-> Fill((p.z()+Z0)/cm, dedx/GeV);
if ( std::abs(p.y()) < dxy ) {
fdose_map-> Fill((p.z()+Z0)/cm, p.x()/cm, dedx/GeV);
if ( std::abs(p.x()) < dxy ) {
fdose_hist-> Fill((p.z()+Z0)/cm, dedx/GeV);
}
}
}
@@ -22,35 +22,39 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: DetectorConstruction.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file DetectorConstruction.hh
/// @brief Define geometry
#include "DetectorConstruction.hh"
#include "VoxelParam.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4NistManager.hh"
#include "G4PVParameterised.hh"
#include "VoxelSD.hh"
#include "G4VisAttributes.hh"
#include "G4PVPlacement.hh"
#include "G4SystemOfUnits.hh"
#include "G4VisAttributes.hh"
#include "DetectorConstruction.hh"
#include "VoxelParam.hh"
#include "VoxelSD.hh"
typedef G4LogicalVolume G4LV;
typedef G4PVPlacement G4PVP;
typedef G4VisAttributes G4VA;
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction()
: flv_voxel(NULL)
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::Construct()
{
G4NistManager* nistManager = G4NistManager::Instance();
@@ -58,32 +62,32 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
// world volume
const G4double DXYZ_WORLD = 200.*cm;
G4Box* sld_world = new G4Box("world",
G4Box* sld_world = new G4Box("world",
DXYZ_WORLD/2., DXYZ_WORLD/2., DXYZ_WORLD/2.);
G4Material* vacuum = nistManager-> FindOrBuildMaterial("G4_Galactic");
G4LV* lv_world = new G4LogicalVolume(sld_world, vacuum, "world");
G4PVP* world = new G4PVPlacement(0, G4ThreeVector(), "AREA",
G4PVP* world = new G4PVPlacement(0, G4ThreeVector(), "AREA",
lv_world, 0, false, 0);
// vis. attributes
va = new G4VA(G4Color(1.,1.,1.));
va-> SetVisibility(false);
lv_world-> SetVisAttributes(va);
// water phantom
const G4double DXY_PHANTOM = 20.*cm;
const G4double DZ_PHANTOM = 50.*cm;
G4Box* sld_phantom = new G4Box("phantom",
G4Box* sld_phantom = new G4Box("phantom",
DXY_PHANTOM/2., DXY_PHANTOM/2., DZ_PHANTOM/2.);
G4Material* water = nistManager-> FindOrBuildMaterial("G4_WATER");
G4LV* lv_phantom = new G4LogicalVolume(sld_phantom,
G4LV* lv_phantom = new G4LogicalVolume(sld_phantom,
water, "phantom");
va = new G4VA(G4Color(0.,1.,1.));
lv_phantom-> SetVisAttributes(va);
new G4PVP(0, G4ThreeVector(), lv_phantom, "phantom", lv_world, false, 0);
// voxel planes
@@ -99,23 +103,27 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
for (G4int iz =0; iz < 500; iz++) {
G4double z0 = -DZ_PHANTOM/2. + (iz+0.5)*DZ_VXP;
new G4PVP(0, G4ThreeVector(0.,0.,z0),
lv_vxp, "vxplane", lv_phantom,
false, 1000+iz);
new G4PVP(0, G4ThreeVector(0.,0.,z0),
lv_vxp, "vxplane", lv_phantom, false, 1000+iz);
}
// voxel parameterized
G4Box* sld_voxel = new G4Box("voxel",1.,1.,1.); // dummy
G4LV* lv_voxel = new G4LV(sld_voxel, water, "voxel");
lv_voxel-> SetSensitiveDetector(new VoxelSD("voxel"));
flv_voxel = new G4LV(sld_voxel, water, "voxel");
va = new G4VA(G4Color(0.,1.,1.));
va-> SetVisibility(false);
lv_voxel-> SetVisAttributes(va);
flv_voxel-> SetVisAttributes(va);
const G4int nvoxels = 100*100;
new G4PVParameterised("voxle", lv_voxel, lv_vxp,
kUndefined, nvoxels, new VoxelParam());
new G4PVParameterised("voxle", flv_voxel, lv_vxp, kUndefined, nvoxels,
new VoxelParam());
return world;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructSDandField()
{
flv_voxel-> SetSensitiveDetector(new VoxelSD("voxel"));
}
@@ -22,31 +22,34 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: EventAction.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file EventAction.cc
/// @brief Describe event actions
#include "EventAction.hh"
#include "G4Event.hh"
#include "Analysis.hh"
#include "EventAction.hh"
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
EventAction::EventAction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
EventAction::~EventAction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void EventAction::BeginOfEventAction(const G4Event*)
{
}
// --------------------------------------------------------------------------
void EventAction::EndOfEventAction(const G4Event*)
{
Analysis* myana = Analysis::GetAnalysis();
myana-> ClearIncidentFlag();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void EventAction::EndOfEventAction(const G4Event*)
{
}
@@ -22,51 +22,52 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MedicalBeam.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file MedicalBeam.cc
/// @brief Define beam profile as primary generator
#include "MedicalBeam.hh"
#include "Randomize.hh"
#include <cmath>
#include "G4Event.hh"
#include "G4ParticleTable.hh"
#include "G4PrimaryVertex.hh"
#include "Randomize.hh"
#include "MedicalBeam.hh"
using namespace CLHEP;
#include <cmath>
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
MedicalBeam::MedicalBeam()
: particle(0), kineticE(1.*MeV), sourcePosition(G4ThreeVector()),
SSD(1.*m), fieldShape(MedicalBeam::SQUARE), fieldR(10.*cm)
: fparticle(0), fkineticE(1.*MeV), fsourcePosition(G4ThreeVector()),
fSSD(1.*m), ffieldShape(MedicalBeam::kSQUARE), ffieldR(10.*cm)
{
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
particle = particleTable-> FindParticle("proton");
fparticle = particleTable-> FindParticle("proton");
kineticE = 200.*MeV;
sourcePosition = G4ThreeVector(0.,0.,-125.*cm);
SSD = 100.*cm;
fieldXY[0] = fieldXY[1] = 5.*cm;
fkineticE = 200.*MeV;
fsourcePosition = G4ThreeVector(0.,0.,-125.*cm);
fSSD = 100.*cm;
ffieldXY[0] = ffieldXY[1] = 5.*cm;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
MedicalBeam::~MedicalBeam()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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.));
if ( ffieldShape == MedicalBeam::kSQUARE ) {
dr = std::sqrt(sqr(ffieldXY[0]/2.) + sqr(ffieldXY[1]/2.));
} else {
dr = fieldR;
dr = ffieldR;
}
G4double sin0 = dr/SSD;
G4double sin0 = dr/fSSD;
G4double cos0 = std::sqrt(1.-sqr(sin0));
G4double dcos = 0.;
@@ -76,9 +77,9 @@ G4ThreeVector MedicalBeam::GenerateBeamDirection() const
G4double y = DBL_MAX;
G4double xmax, ymax;
if ( fieldShape == MedicalBeam::SQUARE ) {
xmax = fieldXY[0]/2./SSD;
ymax = fieldXY[1]/2./SSD;
if ( ffieldShape == MedicalBeam::kSQUARE ) {
xmax = ffieldXY[0]/2./fSSD;
ymax = ffieldXY[1]/2./fSSD;
} else {
xmax = ymax = DBL_MAX-1.;
}
@@ -96,20 +97,20 @@ G4ThreeVector MedicalBeam::GenerateBeamDirection() const
return G4ThreeVector(x,y,z);
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void MedicalBeam::GeneratePrimaries(G4Event* anEvent)
{
if ( particle == 0 ) return;
if ( fparticle == NULL ) return;
// create a new vertex
G4PrimaryVertex* vertex = new G4PrimaryVertex(sourcePosition, 0.*ns);
G4PrimaryVertex* vertex = new G4PrimaryVertex(fsourcePosition, 0.*ns);
// momentum
G4double mass = particle-> GetPDGMass();
G4double p = std::sqrt(sqr(mass+kineticE)-sqr(mass));
G4double mass = fparticle-> GetPDGMass();
G4double p = std::sqrt(sqr(mass+fkineticE)-sqr(mass));
G4ThreeVector pmon = p*GenerateBeamDirection();
G4PrimaryParticle* primary =
new G4PrimaryParticle(particle, pmon.x(), pmon.y(), pmon.z());
G4PrimaryParticle* primary =
new G4PrimaryParticle(fparticle, pmon.x(), pmon.y(), pmon.z());
// set primary to vertex
vertex-> SetPrimary(primary);
@@ -22,36 +22,43 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: RunAction.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file RunAction.cc
/// @brief Describe run actions
#include "RunAction.hh"
#include "Analysis.hh"
#include "G4MPImanager.hh"
#include <stdio.h>
#include "G4Threading.hh"
#include "Analysis.hh"
#include "RunAction.hh"
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::RunAction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::~RunAction()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::BeginOfRunAction(const G4Run*)
{
Analysis* myana = Analysis::GetAnalysis();
myana-> Clear();
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EndOfRunAction(const G4Run*)
{
G4bool is_worker = G4Threading::IsWorkerThread();
if ( is_worker ) return;
G4int rank = G4MPImanager::GetManager()-> GetRank();
char str[64];
sprintf(str, "dose-%03d.root", rank);
G4String fname(str);
@@ -22,25 +22,28 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: VoxelParam.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file VoxelParam.cc
/// @brief Define voxel parameterization
#include "VoxelParam.hh"
#include "G4VPhysicalVolume.hh"
#include "G4Box.hh"
#include "G4SystemOfUnits.hh"
#include "G4VPhysicalVolume.hh"
#include "VoxelParam.hh"
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VoxelParam::VoxelParam()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VoxelParam::~VoxelParam()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VoxelParam::ComputeTransformation(const G4int id,
G4VPhysicalVolume* vol) const
{
@@ -59,7 +62,7 @@ void VoxelParam::ComputeTransformation(const G4int id,
vol-> SetRotation(0);
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VoxelParam::ComputeDimensions(G4Box& box, const G4int,
const G4VPhysicalVolume*) const
{
@@ -22,37 +22,40 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: VoxelSD.cc 78126 2013-12-03 17:43:56Z gcosmo $
//
/// @file VoxelSD.cc
/// @brief Define detector sensitivity on voxels
#include "VoxelSD.hh"
//#include "G4MPImanager.hh"
#include "G4SDManager.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4VTouchable.hh"
#include "G4TouchableHistory.hh"
#include "G4Track.hh"
#include "G4VTouchable.hh"
#include "Randomize.hh"
#include "G4MPImanager.hh"
#include "Analysis.hh"
#include "VoxelSD.hh"
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VoxelSD::VoxelSD(const G4String& name)
: G4VSensitiveDetector(name)
{
G4SDManager::GetSDMpointer()-> AddNewDetector(this);
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VoxelSD::~VoxelSD()
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool VoxelSD::ProcessHits(G4Step* astep, G4TouchableHistory*)
{
G4ThreeVector x0 = astep-> GetPreStepPoint()-> GetPosition();
G4ThreeVector x1 = astep-> GetPostStepPoint()-> GetPosition();
G4int tid = astep-> GetTrack()-> GetTrackID();
G4int iz = astep-> GetPreStepPoint()-> GetTouchable()-> GetReplicaNumber(1);
@@ -62,21 +65,21 @@ G4bool VoxelSD::ProcessHits(G4Step* astep, G4TouchableHistory*)
if ( tid == 1 && iz == 1000 ) { // scored @ first layer
myana-> FillIncident(x0);
}
// energy deposit
G4ThreeVector p = G4UniformRand()*(x1-x0) + x0; // position sampling
G4double edep = astep-> GetTotalEnergyDeposit();
myana-> FillDose(p, edep);
myana-> FillDose(p, edep);
return true;
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VoxelSD::Initialize(G4HCofThisEvent*)
{
}
// --------------------------------------------------------------------------
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VoxelSD::EndOfEvent(G4HCofThisEvent*)
{
}
@@ -7,10 +7,16 @@ cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
# check MPI package...
find_package(MPI REQUIRED)
# modify these var. if needed
# modify these variables if needed
set(CMAKE_CXX_COMPILER mpicxx)
#set(CMAKE_CXX_COMPILER mpiicpc)
#set(CMAKE_CXX_INCLUDE_PATH )
set(BUILD_SHARED_LIBS TRUE CACHE BOOL "Build shared library")
message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
#------------------------------------------------------------------------------
find_package(Geant4 REQUIRED)
include(${Geant4_USE_FILE})
@@ -22,7 +28,7 @@ endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${Geant4_INCLUDE_DIR})
# sources
add_library(G4mpi SHARED
add_library(G4mpi
src/G4MPIbatch.cc
src/G4MPImanager.cc
src/G4MPImessenger.cc
@@ -48,6 +54,6 @@ set(HEADERS
)
# install
INSTALL(TARGETS G4mpi LIBRARY DESTINATION ${Geant4_DIR}/..)
INSTALL(TARGETS G4mpi DESTINATION ${Geant4_DIR}/..)
INSTALL(FILES ${HEADERS} DESTINATION ${Geant4_INCLUDE_DIR})
@@ -28,8 +28,8 @@
#ifndef G4MPI_BATCH_H
#define G4MPI_BATCH_H
#include "G4VMPIsession.hh"
#include <fstream>
#include "G4VMPIsession.hh"
class G4MPIbatch : public G4VMPIsession {
public:
@@ -39,9 +39,9 @@ public:
virtual G4UIsession* SessionStart();
protected:
std::ifstream batchStream;
G4bool isOpened;
G4bool isBatchMode;
std::ifstream batch_stream_;
G4bool is_opened_;
G4bool is_batch_mode_;
// get a command from a batch script file
G4String ReadCommand();
@@ -29,9 +29,13 @@
#define G4MPI_MANAGER_H
#include "mpi.h"
#include "globals.hh"
#include <pthread.h>
#include <fstream>
#include <pthread.h>
#include "globals.hh"
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
class G4MPImessenger;
class G4MPIsession;
@@ -41,13 +45,13 @@ class G4VMPIseedGenerator;
class G4MPImanager {
public:
// MPI master rank
enum { RANK_MASTER = 0 };
enum { kRANK_MASTER = 0 };
enum { // MPI tag
TAG_G4COMMAND = 100,
TAG_G4STATUS = 200,
TAG_G4SEED = 300,
TAG_DATA = 1000
kTAG_G4COMMAND = 100,
kTAG_G4STATUS = 200,
kTAG_G4SEED = 300,
kTAG_DATA = 1000
};
G4MPImanager();
@@ -101,127 +105,129 @@ public:
void ShowHelp() const;
private:
static G4MPImanager* theManager;
G4MPImessenger* messenger;
G4MPIsession* session;
G4int verbose;
G4MPIstatus* status; // status for each node
// MPI rank
G4bool isMaster;
G4bool isSlave;
G4int rank;
G4int size;
// MPI communicator
MPI::Intracomm COMM_G4COMMAND;
// cout/cerr control
G4bool qfcout;
std::ofstream fscout;
// init/macro file
G4bool qinitmacro;
G4String initFileName;
G4bool qbatchmode;
G4String macroFileName;
DISALLOW_COPY_AND_ASSIGN(G4MPImanager);
// internal use
void Initialize();
void ParseArguments(G4int argc, char** argv);
void Wait(G4int ausec) const;
void UpdateStatus();
// for beamOn
pthread_t threadID;
static G4MPImanager* g4mpi_;
G4MPImessenger* messenger_;
G4MPIsession* session_;
// seed generator
G4VMPIseedGenerator* seedGenerator;
G4VMPIseedGenerator* seed_generator_;
G4MPIstatus* status_; // status for each node
G4int verbose_;
// MPI rank
G4bool is_master_;
G4bool is_slave_;
G4int rank_;
G4int size_;
// MPI communicator
MPI::Intracomm COMM_G4COMMAND_;
// cout/cerr control
G4bool qfcout_;
std::ofstream fscout_;
// init/macro file
G4bool qinitmacro_;
G4String init_file_name_;
G4bool qbatchmode_;
G4String macro_file_name_;
// for beamOn
pthread_t thread_id_;
// parallel parameters
G4double masterWeight;
G4double master_weight_;
};
// ====================================================================
inline G4MPIsession* G4MPImanager::GetMPIsession() const
{
return session;
return session_;
}
inline G4int G4MPImanager::GetVerbose() const
{
return verbose;
return verbose_;
}
inline void G4MPImanager::SetVerbose(G4int iverbose)
{
G4int lv=iverbose;
if(iverbose>1) lv=1;
if(iverbose<0) lv=0;
G4int lv = iverbose;
if( iverbose > 1 ) lv = 1;
if( iverbose < 0 ) lv = 0;
verbose= lv;
verbose_ = lv;
return;
}
inline G4int G4MPImanager::GetRank() const
{
return rank;
return rank_;
}
inline G4int G4MPImanager::GetSize() const
{
return size;
return size_;
}
inline G4bool G4MPImanager::IsMaster() const
{
return isMaster;
return is_master_;
}
inline G4bool G4MPImanager::IsSlave() const
{
return isSlave;
return is_slave_;
}
inline G4bool G4MPImanager::IsInitMacro() const
{
return qinitmacro;
return qinitmacro_;
}
inline const G4String& G4MPImanager::GetInitFileName() const
{
return initFileName;
return init_file_name_;
}
inline G4bool G4MPImanager::IsBatchMode() const
{
return qbatchmode;
return qbatchmode_;
}
inline const G4String& G4MPImanager::GetMacroFileName() const
{
return macroFileName;
return macro_file_name_;
}
inline void G4MPImanager::SetMasterWeight(G4double aweight)
{
masterWeight= aweight;
master_weight_ = aweight;
if(aweight<0.) masterWeight= 0.;
if(aweight>1.) masterWeight= 1.;
if( aweight < 0. ) master_weight_ = 0.;
if( aweight > 1. ) master_weight_ = 1.;
}
inline G4double G4MPImanager::GetMasterWeight() const
{
return masterWeight;
return master_weight_;
}
inline G4VMPIseedGenerator* G4MPImanager::GetSeedGenerator() const
{
return seedGenerator;
return seed_generator_;
}
#endif
@@ -30,6 +30,10 @@
#include "G4UImessenger.hh"
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
class G4MPImanager;
class G4UIdirectory;
class G4UIcmdWithoutParameter;
@@ -40,30 +44,40 @@ class G4UIcommand;
class G4MPImessenger : public G4UImessenger {
public:
G4MPImessenger(G4MPImanager* manager);
G4MPImessenger();
~G4MPImessenger();
virtual void SetNewValue(G4UIcommand* command, G4String newValue);
virtual G4String GetCurrentValue(G4UIcommand* command);
void SetTargetObject(G4MPImanager* mpi_manager);
private:
G4MPImanager* g4MPI;
DISALLOW_COPY_AND_ASSIGN(G4MPImessenger);
G4MPImanager* g4mpi_;
// /mpi
G4UIdirectory* dir;
G4UIdirectory* dir_;
G4UIcmdWithAnInteger* verbose;
G4UIcmdWithoutParameter* status;
G4UIcmdWithAnInteger* verbose_;
G4UIcmdWithoutParameter* status_;
G4UIcmdWithAString* execute;
G4UIcmdWithAString* execute_;
G4UIcommand* beamOn;
G4UIcommand* dotbeamOn;
G4UIcmdWithADouble* masterWeight;
G4UIcommand* beam_on_;
G4UIcommand* dot_beam_on_;
G4UIcmdWithADouble* master_weight_;
G4UIcmdWithoutParameter* showSeeds;
G4UIcmdWithAnInteger* setMasterSeed;
G4UIcommand* setSeed;
G4UIcmdWithoutParameter* show_seeds_;
G4UIcmdWithAnInteger* set_master_seed_;
G4UIcommand* set_seed_;
};
// ====================================================================
inline void G4MPImessenger::SetTargetObject(G4MPImanager* mpi_manager)
{
g4mpi_ = mpi_manager;
}
#endif
@@ -40,8 +40,8 @@ public:
virtual G4UIsession* SessionStart();
protected:
G4VUIshell* shell;
private:
G4VUIshell* shell_;
// get command from user prompt of the master node
G4String GetCommand(const char* msg = 0);
@@ -36,8 +36,6 @@ class G4Timer;
class G4MPIstatus {
public:
enum { NSIZE = 10 };
G4MPIstatus();
~G4MPIstatus();
@@ -63,14 +61,16 @@ public:
void Print() const;
enum { kNSIZE = 10 };
private:
G4int rank;
G4int runID;
G4int nEventToBeProcessed;
G4int eventID;
G4double cputime;
G4ApplicationState g4state;
G4Timer* timer;
G4int rank_;
G4int run_id_;
G4int nevent_to_be_processed_;
G4int event_id_;
G4double cputime_;
G4ApplicationState g4state_;
G4Timer* timer_;
G4String GetStateString(G4ApplicationState astate) const;
};
@@ -78,47 +78,37 @@ private:
// ====================================================================
inline G4int G4MPIstatus::SizeOf() const
{
return NSIZE;
return kNSIZE;
}
inline G4int G4MPIstatus::GetRank() const
{
return rank;
return rank_;
}
inline G4int G4MPIstatus::GetRunID() const
{
return runID;
return run_id_;
}
inline G4int G4MPIstatus::GetNEventToBeProcessed() const
{
return nEventToBeProcessed;
return nevent_to_be_processed_;
}
inline G4int G4MPIstatus::GetEventID() const
{
return eventID;
return event_id_;
}
inline G4double G4MPIstatus::GetCPUTime() const
{
return cputime;
return cputime_;
}
inline G4ApplicationState G4MPIstatus::GetG4State() const
{
return g4state;
}
inline void G4MPIstatus::StartTimer()
{
timer-> Start();
}
inline void G4MPIstatus::StopTimer()
{
timer-> Stop();
return g4state_;
}
#endif
@@ -43,22 +43,22 @@ public:
const std::vector<G4long>& GetSeedList() const;
protected:
G4long masterSeed;
std::vector<G4long> seedList;
G4long master_seed_;
std::vector<G4long> seed_list_;
// generate seeds for MPI nodes
virtual void GenerateSeeds()=0;
virtual void GenerateSeeds() = 0;
};
// ====================================================================
inline G4long G4VMPIseedGenerator::GetMasterSeed() const
{
return masterSeed;
return master_seed_;
}
inline const std::vector<G4long>& G4VMPIseedGenerator::GetSeedList() const
inline const std::vector<G4long>& G4VMPIseedGenerator::GetSeedList() const
{
return seedList;
return seed_list_;
}
#endif
@@ -30,7 +30,7 @@
#include "G4VBasicShell.hh"
typedef void* (*Func_t)(void *); // for thead function
typedef void* (*Func_t)(void *); // for thread function
class G4MPImanager;
class G4VUIshell;
@@ -46,14 +46,14 @@ public:
virtual G4int ReceiveG4cerr(const G4String& cerrString);
protected:
G4MPImanager* g4MPI;
G4MPImanager* g4mpi_;
// MPI node info (cache)
G4bool isMaster;
G4bool isSlave;
G4int rank;
G4bool is_master_;
G4bool is_slave_;
G4int rank_;
G4int ExecCommand(G4String acommand);
G4int ExecCommand(const G4String& acommand);
G4String TruncateCommand(const G4String& command) const;
G4String BypassCommand(const G4String& command) const;
@@ -25,14 +25,17 @@
/// @file G4MPIbatch.cc
/// @brief MPI batch session
#include "mpi.h"
#include <vector>
#include "G4UIcommandStatus.hh"
#include "G4UImanager.hh"
#include "G4MPIbatch.hh"
#include "G4MPImanager.hh"
#include "G4UImanager.hh"
#include "G4UIcommandStatus.hh"
#include <vector>
// --------------------------------------------------------------------------
static void Tokenize(const G4String& str, std::vector<G4String>& tokens)
namespace {
void Tokenize(const G4String& str, std::vector<G4String>& tokens)
{
const char* delimiter = " ";
@@ -55,17 +58,19 @@ static void Tokenize(const G4String& str, std::vector<G4String>& tokens)
}
}
} // end of namespace
// --------------------------------------------------------------------------
G4MPIbatch::G4MPIbatch(const G4String& fname, G4bool qbatch)
: G4VMPIsession(), isOpened(false), isBatchMode(qbatch)
: G4VMPIsession(), is_opened_(false), is_batch_mode_(qbatch)
{
if(isMaster) {
batchStream.open(fname, std::ios::in);
if(batchStream.fail()) {
if( is_master_ ) {
batch_stream_.open(fname, std::ios::in);
if(batch_stream_.fail()) {
G4cerr << "cannot open a macro file(" << fname << ")."
<< G4endl;
} else {
isOpened = true;
is_opened_ = true;
}
}
}
@@ -73,7 +78,7 @@ G4MPIbatch::G4MPIbatch(const G4String& fname, G4bool qbatch)
// --------------------------------------------------------------------------
G4MPIbatch::~G4MPIbatch()
{
if(isOpened) batchStream.close();
if( is_opened_ ) batch_stream_.close();
}
// --------------------------------------------------------------------------
@@ -84,8 +89,8 @@ G4String G4MPIbatch::ReadCommand()
G4String cmdtotal = "";
G4bool qcontinued = false;
while(batchStream.good()) {
batchStream.getline(linebuf, BUFSIZE);
while( batch_stream_.good() ) {
batch_stream_.getline(linebuf, BUFSIZE);
G4String cmdline(linebuf);
@@ -99,24 +104,24 @@ G4String G4MPIbatch::ReadCommand()
cmdline = cmdline.strip(G4String::both);
// skip null line if single line
if(!qcontinued && cmdline.size() == 0) continue;
if( !qcontinued && cmdline.size() == 0 ) continue;
// '#' is treated as echoing something
if(cmdline(0) == '#') return cmdline;
if( cmdline(0) == '#' ) return cmdline;
// tokenize...
std::vector<G4String> tokens;
Tokenize(cmdline, tokens);
qcontinued = false;
for (G4int i = 0; i < G4int(tokens.size()); i++) {
for( G4int i = 0; i < G4int(tokens.size()); i++ ) {
// string after '#" is ignored
if(tokens[i](0) == '#' ) break;
if( tokens[i](0) == '#' ) break;
// '\' or '_' is treated as continued line.
if(tokens[i] == '\\' || tokens[i] == '_' ) {
if( tokens[i] == '\\' || tokens[i] == '_' ) {
qcontinued = true;
// check nothing after line continuation character
if( i != G4int(tokens.size())-1) {
G4Exception("G4MPIbatch::ReadCommand", "MPI002", JustWarning,
if( i != G4int(tokens.size())-1 ) {
G4Exception("G4MPIbatch::ReadCommand", "MPI004", JustWarning,
"unexpected character after line continuation character");
}
break; // stop parsing
@@ -125,10 +130,10 @@ G4String G4MPIbatch::ReadCommand()
cmdtotal += " ";
}
if(qcontinued) continue; // read the next line
if( qcontinued ) continue; // read the next line
if(cmdtotal.size() != 0) break;
if(batchStream.eof()) break;
if( cmdtotal.size() != 0 ) break;
if( batch_stream_.eof() ) break;
}
// strip again
@@ -138,7 +143,7 @@ G4String G4MPIbatch::ReadCommand()
cmdtotal = BypassCommand(cmdtotal);
// finally,
if(batchStream.eof() && cmdtotal.size()==0) {
if( batch_stream_.eof() && cmdtotal.size()==0 ) {
return "exit";
}
@@ -148,32 +153,32 @@ G4String G4MPIbatch::ReadCommand()
// --------------------------------------------------------------------------
G4UIsession* G4MPIbatch::SessionStart()
{
if( isMaster && !isOpened ){ // macro file is not found
g4MPI-> BcastCommand("exit");
if( is_master_ && !is_opened_ ) { // macro file is not found
g4mpi_-> BcastCommand("exit");
return NULL;
}
G4String newCommand = "", scommand; // newCommand is always "" in slaves
while(1) {
if (isMaster) newCommand = ReadCommand();
if( is_master_ ) newCommand = ReadCommand();
// broadcast a new G4 command
scommand = g4MPI-> BcastCommand(newCommand);
if(scommand == "exit") {
g4MPI-> WaitBeamOn();
scommand = g4mpi_-> BcastCommand(newCommand);
if( scommand == "exit" ) {
g4mpi_-> WaitBeamOn();
return 0;
}
// just echo something
if( scommand(0) == '#') {
if(G4UImanager::GetUIpointer()-> GetVerboseLevel() == 2) {
if( scommand(0) == '#' ) {
if( G4UImanager::GetUIpointer()-> GetVerboseLevel() == 2 ) {
G4cout << scommand << G4endl;
}
continue;
}
G4int rc = ExecCommand(scommand);
if (rc != fCommandSucceeded) {
if ( rc != fCommandSucceeded ) {
G4cerr << G4endl << "***** Batch is interupted!! *****" << G4endl;
break;
}
@@ -181,4 +186,3 @@ G4UIsession* G4MPIbatch::SessionStart()
return NULL;
}
@@ -25,34 +25,49 @@
/// @file G4MPImanager.cc
/// @brief MPI manager class
#include "G4MPImanager.hh"
#include "G4MPImessenger.hh"
#include "G4MPIsession.hh"
#include "G4MPIbatch.hh"
#include "G4MPIstatus.hh"
#include "G4MPIrandomSeedGenerator.hh"
#include "G4UImanager.hh"
#include "mpi.h"
#include <getopt.h>
#include <stdio.h>
#include <time.h>
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4StateManager.hh"
#include "G4Run.hh"
#include <time.h>
#include <stdio.h>
#include <getopt.h>
#include <assert.h>
#include "G4UIcommand.hh"
#include "G4UImanager.hh"
#include "G4MPIbatch.hh"
#include "G4MPImanager.hh"
#include "G4MPImessenger.hh"
#include "G4MPIrandomSeedGenerator.hh"
#include "G4MPIsession.hh"
#include "G4MPIstatus.hh"
G4MPImanager* G4MPImanager::theManager = 0;
G4MPImanager* G4MPImanager::g4mpi_ = NULL;
// --------------------------------------------------------------------------
namespace {
// wrappers for thread functions
static void thread_ExecuteThreadCommand(const G4String* command)
void thread_ExecuteThreadCommand(const G4String* command)
{
G4MPImanager::GetManager()-> ExecuteThreadCommand(*command);
}
// --------------------------------------------------------------------------
void Wait(G4int ausec)
{
struct timespec treq, trem;
treq.tv_sec = 0;
treq.tv_nsec = ausec*1000;
nanosleep(&treq, &trem);
}
} // end of namespace
// --------------------------------------------------------------------------
G4MPImanager::G4MPImanager()
: verbose(0), qfcout(false), qinitmacro(false), qbatchmode(false),
threadID(0), masterWeight(1.)
: verbose_(0), qfcout_(false), qinitmacro_(false), qbatchmode_(false),
thread_id_(0), master_weight_(1.)
{
//MPI::Init();
MPI::Init_thread(MPI::THREAD_SERIALIZED);
@@ -61,8 +76,8 @@ G4MPImanager::G4MPImanager()
// --------------------------------------------------------------------------
G4MPImanager::G4MPImanager(int argc, char** argv)
: verbose(0), qfcout(false), qinitmacro(false), qbatchmode(false),
threadID(0), masterWeight(1.)
: verbose_(0), qfcout_(false), qinitmacro_(false), qbatchmode_(false),
thread_id_(0), master_weight_(1.)
{
//MPI::Init(argc, argv);
MPI::Init_thread(argc, argv, MPI::THREAD_SERIALIZED);
@@ -73,49 +88,54 @@ G4MPImanager::G4MPImanager(int argc, char** argv)
// --------------------------------------------------------------------------
G4MPImanager::~G4MPImanager()
{
if(isSlave && qfcout) fscout.close();
if( is_slave_ && qfcout_ ) fscout_.close();
delete status;
delete messenger;
delete session;
delete status_;
delete messenger_;
delete session_;
COMM_G4COMMAND.Free();
COMM_G4COMMAND_.Free();
MPI::Finalize();
theManager = 0;
}
// --------------------------------------------------------------------------
G4MPImanager* G4MPImanager::GetManager()
{
assert( theManager != 0 );
return theManager;
if ( g4mpi_ == NULL ) {
G4Exception("G4MPImanager::GetManager()", "MPI001",
FatalException, "G4MPImanager is not instantiated.");
}
return g4mpi_;
}
// --------------------------------------------------------------------------
void G4MPImanager::Initialize()
{
assert( theManager == 0 );
if ( g4mpi_ != NULL ) {
G4Exception("G4MPImanager::Initialize()", "MPI002",
FatalException, "G4MPImanager is already instantiated.");
}
theManager= this;
g4mpi_ = this;
// get rank information
size = MPI::COMM_WORLD.Get_size();
rank = MPI::COMM_WORLD.Get_rank();
isMaster = (rank == RANK_MASTER);
isSlave = (rank != RANK_MASTER);
size_ = MPI::COMM_WORLD.Get_size();
rank_ = MPI::COMM_WORLD.Get_rank();
is_master_ = (rank_ == kRANK_MASTER);
is_slave_ = (rank_ != kRANK_MASTER);
// initialize MPI communicator
COMM_G4COMMAND = MPI::COMM_WORLD.Dup();
COMM_G4COMMAND_ = MPI::COMM_WORLD.Dup();
// new G4MPI stuffs
messenger = new G4MPImessenger(this);
session = new G4MPIsession;
status = new G4MPIstatus;
messenger_ = new G4MPImessenger();
messenger_-> SetTargetObject(this);
session_ = new G4MPIsession;
status_ = new G4MPIstatus;
// default seed generator is random generator.
seedGenerator = new G4MPIrandomSeedGenerator;
seed_generator_ = new G4MPIrandomSeedGenerator;
DistributeSeeds();
}
@@ -126,92 +146,67 @@ void G4MPImanager::ParseArguments(int argc, char** argv)
G4String ofprefix = "mpi";
G4int c;
while (1) {
G4int option_index= 0;
while ( 1 ) {
G4int option_index = 0;
static struct option long_options[] = {
{"help", 0, 0, 0},
{"verbose", 0, 0, 0},
{"init", 1, 0, 0},
{"ofile", 2, 0, 0},
{0, 0, 0, 0}
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{"init", required_argument, NULL, 'i'},
{"ofile", optional_argument, NULL, 'o'},
{NULL, 0, NULL, 0}
};
opterr = 0; // suppress message
c= getopt_long(argc, argv, "hvi:o", long_options, &option_index);
c = getopt_long(argc, argv, "hvi:o", long_options, &option_index);
opterr = 1;
if(c == -1) break;
if( c == -1 ) break;
switch (c) {
case 0:
switch(option_index) {
case 0 : // --help
qhelp = 1;
break;
case 1 : // --verbose
verbose = 1;
break;
case 2 : // --init
qinitmacro = true;
initFileName = optarg;
break;
case 3 : // --ofile
qfcout = true;
if(optarg) ofprefix = optarg;
break;
}
break;
case 'h' :
qhelp = 1;
break;
case 'v' :
verbose = 1;
verbose_ = 1;
break;
case 'i' :
qinitmacro = true;
initFileName = optarg;
qinitmacro_ = true;
init_file_name_ = optarg;
break;
case 'o' :
qfcout = true;
qfcout_ = true;
if ( optarg ) ofprefix = optarg;
break;
default:
G4cerr << "*** invalid options specified." << G4endl;
std::exit(EXIT_FAILURE);
break;
}
}
// show help
if(qhelp) {
if(isMaster) ShowHelp();
if ( qhelp ) {
if ( is_master_ ) ShowHelp();
MPI::Finalize();
exit(0);
std::exit(EXIT_SUCCESS);
}
// file output
if(isSlave && qfcout) {
if( is_slave_ && qfcout_ ) {
G4String prefix = ofprefix + ".%03d" + ".cout";
char str[1024];
sprintf(str, prefix.c_str(), rank);
sprintf(str, prefix.c_str(), rank_);
G4String fname(str);
fscout.open(fname.c_str(), std::ios::out);
fscout_.open(fname.c_str(), std::ios::out);
}
// non-option ARGV-elements ...
if (optind < argc ) {
qbatchmode = true;
macroFileName = argv[optind];
if ( optind < argc ) {
qbatchmode_ = true;
macro_file_name_ = argv[optind];
}
}
// --------------------------------------------------------------------------
void G4MPImanager::Wait(G4int ausec) const
{
struct timespec treq, trem;
treq.tv_sec = 0;
treq.tv_nsec = ausec*1000;
nanosleep(&treq, &trem);
}
// ====================================================================
void G4MPImanager::UpdateStatus()
{
@@ -223,12 +218,12 @@ void G4MPImanager::UpdateStatus()
G4StateManager* stateManager = G4StateManager::GetStateManager();
G4ApplicationState g4state = stateManager-> GetCurrentState();
if (run) {
if ( run ) {
runid = run-> GetRunID();
neventTBP = run -> GetNumberOfEventToBeProcessed();
eventid = run-> GetNumberOfEvent();
if(g4state == G4State_GeomClosed || g4state == G4State_EventProc) {
status-> StopTimer();
if( g4state == G4State_GeomClosed || g4state == G4State_EventProc ) {
status_-> StopTimer();
}
} else {
runid = 0;
@@ -236,39 +231,39 @@ void G4MPImanager::UpdateStatus()
neventTBP = 0;
}
status-> SetStatus(rank, runid, neventTBP, eventid, g4state);
status_-> SetStatus(rank_, runid, neventTBP, eventid, g4state);
}
// --------------------------------------------------------------------------
void G4MPImanager::ShowStatus()
{
G4int buff[G4MPIstatus::NSIZE];
G4int buff[G4MPIstatus::kNSIZE];
UpdateStatus();
G4bool gstatus = CheckThreadStatus();
if(isMaster) {
status-> Print(); // for maser itself
if ( is_master_ ) {
status_-> Print(); // for maser itself
G4int nev = status-> GetEventID();
G4int nevtp = status-> GetNEventToBeProcessed();
G4double cputime = status-> GetCPUTime();
G4int nev = status_-> GetEventID();
G4int nevtp = status_-> GetNEventToBeProcessed();
G4double cputime = status_-> GetCPUTime();
// receive from each slave
for (G4int islave = 1; islave < size; islave++) {
COMM_G4COMMAND.Recv(buff, G4MPIstatus::NSIZE, MPI::INT,
islave, TAG_G4STATUS);
status-> UnPack(buff);
status-> Print();
for ( G4int islave = 1; islave < size_; islave++ ) {
COMM_G4COMMAND_.Recv(buff, G4MPIstatus::kNSIZE, MPI::INT,
islave, kTAG_G4STATUS);
status_-> UnPack(buff);
status_-> Print();
// aggregation
nev += status-> GetEventID();
nevtp += status-> GetNEventToBeProcessed();
cputime += status-> GetCPUTime();
nev += status_-> GetEventID();
nevtp += status_-> GetNEventToBeProcessed();
cputime += status_-> GetCPUTime();
}
G4String strStatus;
if(gstatus) {
if ( gstatus ) {
strStatus = "Run";
} else {
strStatus = "Idle";
@@ -276,23 +271,23 @@ void G4MPImanager::ShowStatus()
G4cout << "-------------------------------------------------------"
<< G4endl
<< "* #ranks= " << size
<< "* #ranks= " << size_
<< " event= " << nev << "/" << nevtp
<< " state= " << strStatus
<< " time= " << cputime << "s"
<< G4endl;
} else {
status-> Pack(buff);
COMM_G4COMMAND.Send(buff, G4MPIstatus::NSIZE, MPI::INT,
RANK_MASTER, TAG_G4STATUS);
status_-> Pack(buff);
COMM_G4COMMAND_.Send(buff, G4MPIstatus::kNSIZE, MPI::INT,
kRANK_MASTER, kTAG_G4STATUS);
}
}
// ====================================================================
void G4MPImanager::DistributeSeeds()
{
std::vector<G4long> seedList = seedGenerator-> GetSeedList();
CLHEP::HepRandom::setTheSeed(seedList[rank]);
std::vector<G4long> seed_list = seed_generator_-> GetSeedList();
CLHEP::HepRandom::setTheSeed(seed_list[rank_]);
}
// --------------------------------------------------------------------------
@@ -300,28 +295,28 @@ void G4MPImanager::ShowSeeds()
{
G4long buff;
if(isMaster) {
if ( is_master_ ) {
// print master
G4cout << "* rank= " << rank
G4cout << "* rank= " << rank_
<< " seed= " << CLHEP::HepRandom::getTheSeed()
<< G4endl;
// receive from each slave
for (G4int islave = 1; islave < size; islave++) {
COMM_G4COMMAND.Recv(&buff, 1, MPI::LONG, islave, TAG_G4SEED);
for ( G4int islave = 1; islave < size_; islave++ ) {
COMM_G4COMMAND_.Recv(&buff, 1, MPI::LONG, islave, kTAG_G4SEED);
G4cout << "* rank= " << islave
<< " seed= " << buff
<< G4endl;
}
} else { // slaves
buff = CLHEP::HepRandom::getTheSeed();
COMM_G4COMMAND.Send(&buff, 1, MPI::LONG, RANK_MASTER, TAG_G4SEED);
COMM_G4COMMAND_.Send(&buff, 1, MPI::LONG, kRANK_MASTER, kTAG_G4SEED);
}
}
// --------------------------------------------------------------------------
void G4MPImanager::SetSeed(G4int inode, G4long seed)
{
if(rank == inode) {
if( rank_ == inode ) {
CLHEP::HepRandom::setTheSeed(seed);
}
}
@@ -330,31 +325,31 @@ void G4MPImanager::SetSeed(G4int inode, G4long seed)
G4bool G4MPImanager::CheckThreadStatus()
{
unsigned buff;
G4bool qstatus= false;
unsigned qstatus = 0;
if(isMaster) {
qstatus = threadID;
if( is_master_ ) {
qstatus = unsigned(thread_id_);
// get slave status
for (G4int islave = 1; islave < size; islave++) {
MPI::Request request = COMM_G4COMMAND.Irecv(&buff, 1, MPI::UNSIGNED,
islave, TAG_G4STATUS);
MPI::Status status;
while(! request.Test(status)) {
Wait(1000);
for ( G4int islave = 1; islave < size_; islave++ ) {
MPI::Request request = COMM_G4COMMAND_.Irecv(&buff, 1, MPI::UNSIGNED,
islave, kTAG_G4STATUS);
while( ! request.Test() ) {
::Wait(1000);
}
qstatus |= buff;
}
} else {
buff = unsigned(threadID);
COMM_G4COMMAND.Send(&buff, 1, MPI::UNSIGNED, RANK_MASTER, TAG_G4STATUS);
buff = unsigned(thread_id_);
COMM_G4COMMAND_.Send(&buff, 1, MPI::UNSIGNED, kRANK_MASTER, kTAG_G4STATUS);
}
// broadcast
buff = qstatus; // for master
COMM_G4COMMAND.Bcast(&buff, 1, MPI::UNSIGNED, RANK_MASTER);
COMM_G4COMMAND_.Bcast(&buff, 1, MPI::UNSIGNED, kRANK_MASTER);
qstatus = buff; // for slave
return qstatus;
if ( qstatus != 0 ) return true;
else return false;
}
// --------------------------------------------------------------------------
@@ -366,7 +361,7 @@ void G4MPImanager::ExecuteThreadCommand(const G4String& command)
G4int commandStatus = rc - (rc%100);
switch(commandStatus) {
switch( commandStatus ) {
case fCommandSucceeded:
break;
case fIllegalApplicationState:
@@ -378,9 +373,9 @@ void G4MPImanager::ExecuteThreadCommand(const G4String& command)
}
// thread is joined
if(threadID) {
pthread_join(threadID, 0);
threadID = 0;
if ( thread_id_ ) {
pthread_join(thread_id_, 0);
thread_id_ = 0;
}
return;
@@ -392,19 +387,18 @@ void G4MPImanager::ExecuteBeamOnThread(const G4String& command)
G4bool threadStatus = CheckThreadStatus();
if (threadStatus) {
if(isMaster) {
if ( is_master_ ) {
G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
}
} else { // ok
static G4String cmdstr;
cmdstr = command;
G4int rc = pthread_create(&threadID, 0,
G4int rc = pthread_create(&thread_id_, 0,
(Func_t)thread_ExecuteThreadCommand,
(void*)&cmdstr);
if (rc != 0)
G4Exception("G4MPImanager::ExecuteBeamOnThread()",
"MPI001",
FatalException,
"MPI003", FatalException,
"Failed to create a beamOn thread.");
}
}
@@ -412,39 +406,39 @@ void G4MPImanager::ExecuteBeamOnThread(const G4String& command)
// --------------------------------------------------------------------------
void G4MPImanager::JoinBeamOnThread()
{
if(threadID) {
pthread_join(threadID, 0);
threadID = 0;
if ( thread_id_ ) {
pthread_join(thread_id_, 0);
thread_id_ = 0;
}
}
// ====================================================================
G4String G4MPImanager::BcastCommand(const G4String& command)
{
enum { BUFF_SIZE = 512 };
static char sbuff[BUFF_SIZE];
command.copy(sbuff,BUFF_SIZE);
enum { kBUFF_SIZE = 512 };
static char sbuff[kBUFF_SIZE];
command.copy(sbuff, kBUFF_SIZE);
G4int len = command.size();
sbuff[len] ='\0'; // no boundary check
// "command" is not yet fixed in slaves at this time.
// waiting message exhausts CPU in LAM!
//COMM_G4COMMAND.Bcast(sbuff, ssize, MPI::CHAR, RANK_MASTER);
//COMM_G4COMMAND_.Bcast(sbuff, ssize, MPI::CHAR, RANK_MASTER);
// another implementation
if( isMaster ) {
for (G4int islave = 1; islave < size; islave++) {
COMM_G4COMMAND.Send(sbuff, BUFF_SIZE, MPI::CHAR, islave, TAG_G4COMMAND);
if( is_master_ ) {
for ( G4int islave = 1; islave < size_; islave++ ) {
COMM_G4COMMAND_.Send(sbuff, kBUFF_SIZE, MPI::CHAR,
islave, kTAG_G4COMMAND);
}
} else {
// try non-blocking receive
MPI::Request request= COMM_G4COMMAND.Irecv(sbuff, BUFF_SIZE, MPI::CHAR,
RANK_MASTER, TAG_G4COMMAND);
MPI::Request request= COMM_G4COMMAND_.Irecv(sbuff, kBUFF_SIZE, MPI::CHAR,
kRANK_MASTER, kTAG_G4COMMAND);
// polling...
MPI::Status status;
while(! request.Test(status)) {
Wait(1000);
while(! request.Test()) {
::Wait(1000);
}
}
@@ -454,42 +448,62 @@ G4String G4MPImanager::BcastCommand(const G4String& command)
// ====================================================================
void G4MPImanager::ExecuteMacroFile(const G4String& fname, G4bool qbatch)
{
G4bool currentmode = qbatchmode;
qbatchmode = true;
G4bool currentmode = qbatchmode_;
qbatchmode_ = true;
G4MPIbatch* batchSession = new G4MPIbatch(fname, qbatch);
batchSession-> SessionStart();
delete batchSession;
qbatchmode = currentmode;
qbatchmode_ = currentmode;
}
// --------------------------------------------------------------------------
void G4MPImanager::BeamOn(G4int nevent, G4bool qdivide)
{
#ifndef G4MULTITHREADED
G4RunManager* runManager = G4RunManager::GetRunManager();
#endif
if(qdivide) { // events are divided
G4double ntot = masterWeight+size-1.;
if ( qdivide ) { // events are divided
G4double ntot = master_weight_ + size_ - 1.;
G4int nproc = G4int(nevent/ntot);
G4int nproc0 = nevent-nproc*(size-1);
G4int nproc0 = nevent - nproc*(size_-1);
if(verbose>0 && isMaster) {
if ( verbose_ > 0 && is_master_ ) {
G4cout << "#events in master=" << nproc0 << " / "
<< "#events in slave=" << nproc << G4endl;
}
status-> StartTimer(); // start timer
if(isMaster) runManager-> BeamOn(nproc0);
status_-> StartTimer(); // start timer
#ifdef G4MULTITHREADED
G4String str_nevt;
if ( is_master_ ) str_nevt = G4UIcommand::ConvertToString(nproc0);
else str_nevt = G4UIcommand::ConvertToString(nproc);
G4UImanager* UI = G4UImanager::GetUIpointer();
UI-> ApplyCommand("/run/beamOn " + str_nevt);
#else
if ( is_master_ ) runManager-> BeamOn(nproc0);
else runManager-> BeamOn(nproc);
status-> StopTimer(); // stop timer
#endif
status_-> StopTimer(); // stop timer
} else { // same events are generated in each node (for test use)
if(verbose>0 && isMaster) {
if( verbose_ > 0 && is_master_ ) {
G4cout << "#events in master=" << nevent << " / "
<< "#events in slave=" << nevent << G4endl;
}
status-> StartTimer(); // start timer
status_-> StartTimer(); // start timer
#ifdef G4MULTITHREADED
G4String str_nevt = G4UIcommand::ConvertToString(nevent);
G4UImanager* UI = G4UImanager::GetUIpointer();
UI-> ApplyCommand("/run/beamOn " + str_nevt);
#else
runManager-> BeamOn(nevent);
status-> StopTimer(); // stop timer
#endif
status_-> StopTimer(); // stop timer
}
}
@@ -497,20 +511,19 @@ void G4MPImanager::BeamOn(G4int nevent, G4bool qdivide)
void G4MPImanager::WaitBeamOn()
{
G4int buff = 0;
if (qbatchmode) { // valid only in batch mode
if(isMaster) {
if ( qbatchmode_ ) { // valid only in batch mode
if ( is_master_ ) {
// receive from each slave
for (G4int islave = 1; islave < size; islave++) {
MPI::Request request = COMM_G4COMMAND.Irecv(&buff, 1, MPI::INT,
islave, TAG_G4STATUS);
MPI::Status status;
while(! request.Test(status)) {
Wait(1000);
for (G4int islave = 1; islave < size_; islave++) {
MPI::Request request = COMM_G4COMMAND_.Irecv(&buff, 1, MPI::INT,
islave, kTAG_G4STATUS);
while(! request.Test()) {
::Wait(1000);
}
}
} else {
buff = 1;
COMM_G4COMMAND.Send(&buff, 1, MPI::INT, RANK_MASTER, TAG_G4STATUS);
COMM_G4COMMAND_.Send(&buff, 1, MPI::INT, kRANK_MASTER, kTAG_G4STATUS);
}
}
}
@@ -518,13 +531,13 @@ void G4MPImanager::WaitBeamOn()
// --------------------------------------------------------------------------
void G4MPImanager::Print(const G4String& message)
{
if(isMaster){
if ( is_master_ ){
std::cout << message << std::flush;
} else {
if(qfcout) { // output to a file
fscout << message << std::flush;
if ( qfcout_ ) { // output to a file
fscout_ << message << std::flush;
} else { // output to stdout
std::cout << rank << ":" << message << std::flush;
std::cout << rank_ << ":" << message << std::flush;
}
}
}
@@ -532,7 +545,7 @@ void G4MPImanager::Print(const G4String& message)
// --------------------------------------------------------------------------
void G4MPImanager::ShowHelp() const
{
if(isSlave) return;
if (is_slave_ ) return;
G4cout << "Geant4 MPI interface" << G4endl;
G4cout << "usage:" << G4endl;
@@ -25,159 +25,160 @@
/// @file G4MPImessenger.cc
/// @brief Define MPI commands
#include "G4MPImessenger.hh"
#include "G4MPImanager.hh"
#include "G4VMPIseedGenerator.hh"
#include "G4UImanager.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "mpi.h"
#include <sstream>
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcommand.hh"
#include "G4UIdirectory.hh"
#include "G4UImanager.hh"
#include "G4UIparameter.hh"
#include <sstream>
#include "G4MPImanager.hh"
#include "G4MPImessenger.hh"
#include "G4VMPIseedGenerator.hh"
// --------------------------------------------------------------------------
G4MPImessenger::G4MPImessenger( G4MPImanager* manager)
: G4UImessenger(), g4MPI(manager)
G4MPImessenger::G4MPImessenger()
: G4UImessenger()
{
// /mpi
dir = new G4UIdirectory("/mpi/");
dir-> SetGuidance("MPI control commands");
dir_ = new G4UIdirectory("/mpi/");
dir_-> SetGuidance("MPI control commands");
// /mpi/verbose
verbose = new G4UIcmdWithAnInteger("/mpi/verbose", this);
verbose-> SetGuidance("Set verbose level.");
verbose-> SetParameterName("verbose", false, false);
verbose->SetRange("verbose>=0 && verbose<=1");
verbose_ = new G4UIcmdWithAnInteger("/mpi/verbose", this);
verbose_-> SetGuidance("Set verbose level.");
verbose_-> SetParameterName("verbose", false, false);
verbose_->SetRange("verbose>=0 && verbose<=1");
// /mpi/status
status = new G4UIcmdWithoutParameter("/mpi/status", this);
status-> SetGuidance( "Show mpi status.");
status_ = new G4UIcmdWithoutParameter("/mpi/status", this);
status_-> SetGuidance( "Show mpi status.");
// /mpi/execute
execute = new G4UIcmdWithAString("/mpi/execute", this);
execute-> SetGuidance("Execute a macro file. (=/control/execute)");
execute-> SetParameterName("fileName", false, false);
execute_ = new G4UIcmdWithAString("/mpi/execute", this);
execute_-> SetGuidance("Execute a macro file. (=/control/execute)");
execute_-> SetParameterName("fileName", false, false);
// /mpi/beamOn
beamOn = new G4UIcommand("/mpi/beamOn", this);
beamOn-> SetGuidance("Start a parallel run w/ thread.");
beam_on_ = new G4UIcommand("/mpi/beamOn", this);
beam_on_-> SetGuidance("Start a parallel run w/ thread.");
G4UIparameter* p1= new G4UIparameter("numberOfEvent", 'i', true);
p1-> SetDefaultValue(1);
p1-> SetParameterRange("numberOfEvent>=0");
beamOn-> SetParameter(p1);
beam_on_-> SetParameter(p1);
G4UIparameter* p2= new G4UIparameter("divide", 'b', true);
p2-> SetDefaultValue(true);
beamOn-> SetParameter(p2);
beam_on_-> SetParameter(p2);
// /mpi/.beamOn
dotbeamOn = new G4UIcommand("/mpi/.beamOn", this);
dotbeamOn-> SetGuidance("Start a parallel run w/o thread.");
dot_beam_on_ = new G4UIcommand("/mpi/.beamOn", this);
dot_beam_on_-> SetGuidance("Start a parallel run w/o thread.");
p1= new G4UIparameter("numberOfEvent", 'i', true);
p1-> SetDefaultValue(1);
p1-> SetParameterRange("numberOfEvent>=0");
dotbeamOn-> SetParameter(p1);
dot_beam_on_-> SetParameter(p1);
p2= new G4UIparameter("divide", 'b', true);
p2-> SetDefaultValue(true);
dotbeamOn-> SetParameter(p2);
dot_beam_on_-> SetParameter(p2);
// /mpi/weightForMaster
masterWeight = new G4UIcmdWithADouble("/mpi/masterWeight", this);
masterWeight-> SetGuidance("Set weight for master node.");
masterWeight-> SetParameterName("weight", false, false);
masterWeight-> SetRange("weight>=0. && weight<=1.");
master_weight_ = new G4UIcmdWithADouble("/mpi/masterWeight", this);
master_weight_-> SetGuidance("Set weight for master node.");
master_weight_-> SetParameterName("weight", false, false);
master_weight_-> SetRange("weight>=0. && weight<=1.");
// /mpi/showSeeds
showSeeds = new G4UIcmdWithoutParameter("/mpi/showSeeds", this);
showSeeds-> SetGuidance("Show seeds of MPI nodes.");
show_seeds_ = new G4UIcmdWithoutParameter("/mpi/showSeeds", this);
show_seeds_-> SetGuidance("Show seeds of MPI nodes.");
// /mpi/setMasterSeed
setMasterSeed = new G4UIcmdWithAnInteger("/mpi/setMasterSeed", this);
setMasterSeed-> SetGuidance("Set a master seed for the seed generator.");
setMasterSeed-> SetParameterName("seed", false, false);
set_master_seed_ = new G4UIcmdWithAnInteger("/mpi/setMasterSeed", this);
set_master_seed_-> SetGuidance("Set a master seed for the seed generator.");
set_master_seed_-> SetParameterName("seed", false, false);
// /mpi/setSeed
setSeed = new G4UIcommand("/mpi/setSeed", this);
setSeed-> SetGuidance("Set a seed for a specified node.");
set_seed_ = new G4UIcommand("/mpi/setSeed", this);
set_seed_-> SetGuidance("Set a seed for a specified node.");
p1 = new G4UIparameter("node", 'i', false);
p1-> SetParameterRange("node>=0");
setSeed-> SetParameter(p1);
set_seed_-> SetParameter(p1);
p2 = new G4UIparameter("seed", 'i', false);
setSeed-> SetParameter(p2);
set_seed_-> SetParameter(p2);
}
// --------------------------------------------------------------------------
G4MPImessenger::~G4MPImessenger()
{
delete verbose;
delete status;
delete execute;
delete beamOn;
delete dotbeamOn;
delete masterWeight;
delete showSeeds;
delete setMasterSeed;
delete setSeed;
delete verbose_;
delete status_;
delete execute_;
delete beam_on_;
delete dot_beam_on_;
delete master_weight_;
delete show_seeds_;
delete set_master_seed_;
delete set_seed_;
delete dir;
delete dir_;
}
// --------------------------------------------------------------------------
void G4MPImessenger::SetNewValue( G4UIcommand* command, G4String newValue)
void G4MPImessenger::SetNewValue(G4UIcommand* command, G4String newValue)
{
if (command == verbose) { // /mpi/verbose
G4int lv= verbose-> GetNewIntValue(newValue);
g4MPI-> SetVerbose(lv);
if ( command == verbose_ ) { // /mpi/verbose
G4int lv = verbose_-> GetNewIntValue(newValue);
g4mpi_-> SetVerbose(lv);
} else if (command == status){ // /mpi/status
g4MPI-> ShowStatus();
} else if ( command == status_ ) { // /mpi/status
g4mpi_-> ShowStatus();
} else if (command == execute){ // /mpi/execute
} else if ( command == execute_ ) { // /mpi/execute
G4UImanager* UI = G4UImanager::GetUIpointer();
g4MPI-> ExecuteMacroFile(UI-> FindMacroPath(newValue));
g4mpi_-> ExecuteMacroFile(UI-> FindMacroPath(newValue));
} else if (command == beamOn){ // /mpi/beamOn
} else if ( command == beam_on_ ) { // /mpi/beamOn
std::istringstream is(newValue);
G4int nevent;
G4bool qdivide;
is >> nevent >> qdivide;
g4MPI-> BeamOn(nevent, qdivide);
g4mpi_-> BeamOn(nevent, qdivide);
} else if (command == dotbeamOn){ // /mpi/.beamOn
} else if ( command == dot_beam_on_ ) { // /mpi/.beamOn
std::istringstream is(newValue);
G4int nevent;
G4bool qdivide;
is >> nevent >> qdivide;
g4MPI-> BeamOn(nevent, qdivide);
g4mpi_-> BeamOn(nevent, qdivide);
} else if (command == masterWeight){ // /mpi/masterWeight
G4double weight= masterWeight-> GetNewDoubleValue(newValue);
g4MPI-> SetMasterWeight(weight);
} else if ( command == master_weight_ ) { // /mpi/masterWeight
G4double weight= master_weight_-> GetNewDoubleValue(newValue);
g4mpi_-> SetMasterWeight(weight);
} else if (command == showSeeds){ // /mpi/showSeeds
g4MPI-> ShowSeeds();
} else if ( command == show_seeds_ ) { // /mpi/showSeeds
g4mpi_-> ShowSeeds();
} else if (command == setMasterSeed){ // /mpi/setMasterSeed
} else if ( command == set_master_seed_ ) { // /mpi/setMasterSeed
std::istringstream is(newValue);
G4long seed;
is >> seed;
g4MPI-> GetSeedGenerator()-> SetMasterSeed(seed);
g4MPI-> DistributeSeeds();
g4mpi_-> GetSeedGenerator()-> SetMasterSeed(seed);
g4mpi_-> DistributeSeeds();
} else if (command == setSeed){ // /mpi/setSeed
} else if ( command == set_seed_ ) { // /mpi/setSeed
std::istringstream is(newValue);
G4int inode;
G4long seed;
is >> inode >> seed;
g4MPI-> SetSeed(inode, seed);
g4mpi_-> SetSeed(inode, seed);
}
return;
@@ -188,12 +189,11 @@ G4String G4MPImessenger::GetCurrentValue(G4UIcommand* command)
{
G4String cv;
if (command == verbose) {
cv= verbose-> ConvertToString(g4MPI->GetVerbose());
} else if (command == masterWeight) {
cv= masterWeight-> ConvertToString(g4MPI->GetMasterWeight());
if ( command == verbose_ ) {
cv = verbose_-> ConvertToString(g4mpi_->GetVerbose());
} else if ( command == master_weight_ ) {
cv= master_weight_-> ConvertToString(g4mpi_->GetMasterWeight());
}
return cv;
}
@@ -25,9 +25,10 @@
/// @file G4MPIrandomSeedGenerator.cc
/// @brief An implementation of random number seed distribution
#include "G4MPIrandomSeedGenerator.hh"
#include "G4MPImanager.hh"
#include "mpi.h"
#include "Randomize.hh"
#include "G4MPImanager.hh"
#include "G4MPIrandomSeedGenerator.hh"
// --------------------------------------------------------------------------
G4MPIrandomSeedGenerator::G4MPIrandomSeedGenerator()
@@ -44,14 +45,15 @@ G4MPIrandomSeedGenerator::~G4MPIrandomSeedGenerator()
// --------------------------------------------------------------------------
G4bool G4MPIrandomSeedGenerator::CheckDoubleCount()
{
G4MPImanager* g4MPI = G4MPImanager::GetManager();
G4int nsize = g4MPI-> GetSize();
G4MPImanager* g4mpi = G4MPImanager::GetManager();
for (G4int i = 0; i < nsize; i++) {
for (G4int j = 0; j < nsize; j++) {
if((i != j) && (seedList[i] == seedList[j])) {
G4int nsize = g4mpi-> GetSize();
for ( G4int i = 0; i < nsize; i++ ) {
for ( G4int j = 0; j < nsize; j++ ) {
if( (i != j) && (seed_list_[i] == seed_list_[j]) ) {
G4double x = G4UniformRand();
seedList[j] = G4long(x*LONG_MAX);
seed_list_[j] = G4long(x*LONG_MAX);
return false;
}
}
@@ -63,14 +65,16 @@ G4bool G4MPIrandomSeedGenerator::CheckDoubleCount()
// --------------------------------------------------------------------------
void G4MPIrandomSeedGenerator::GenerateSeeds()
{
G4MPImanager* g4MPI = G4MPImanager::GetManager();
G4int nsize= g4MPI-> GetSize();
seedList.clear();
G4MPImanager* g4mpi = G4MPImanager::GetManager();
for (G4int i = 0; i < nsize; i++) {
G4int nsize = g4mpi-> GetSize();
seed_list_.clear();
for ( G4int i = 0; i < nsize; i++ ) {
G4double x = G4UniformRand();
G4int seed = G4long(x*LONG_MAX);
seedList.push_back(seed);
seed_list_.push_back(seed);
}
while(! CheckDoubleCount()) {
@@ -25,75 +25,80 @@
/// @file G4MPIsession.cc
/// @brief A terminal session for MPI application
#include "G4MPIsession.hh"
#include "G4MPImanager.hh"
#include "mpi.h"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIcommand.hh"
#include "G4UIcsh.hh"
#include "G4UItcsh.hh"
#include "G4UImanager.hh"
#include "G4UImpish.hh"
#include "G4UItcsh.hh"
#include "G4MPImanager.hh"
#include "G4MPIsession.hh"
// --------------------------------------------------------------------------
namespace {
G4UImanager* UI = G4UImanager::GetUIpointer();
#ifndef WIN32
static const G4bool tcsh_build = true;
const G4bool tcsh_build = true;
#else
static const G4bool tcsh_build = false;
const G4bool tcsh_build = false;
#endif
} // end of namespace
// --------------------------------------------------------------------------
G4MPIsession::G4MPIsession(G4VUIshell* ashell)
: G4VMPIsession()
{
G4UImanager* UI = G4UImanager::GetUIpointer();
UI-> SetSession(this);
UI-> SetCoutDestination(this);
::UI-> SetSession(this);
::UI-> SetCoutDestination(this);
// shell
if(isMaster) {
if(ashell) {
shell = ashell;
if( is_master_ ) {
if( ashell ) {
shell_ = ashell;
} else {
if ( g4MPI->GetSize() == 1 && tcsh_build ) shell = new G4UItcsh;
else shell = new G4UIcsh;
if ( g4mpi_-> GetSize() == 1 && ::tcsh_build ) shell_ = new G4UItcsh;
else shell_ = new G4UIcsh;
}
} else {
shell = new G4UImpish;
shell_ = new G4UImpish;
}
}
// --------------------------------------------------------------------------
G4MPIsession::~G4MPIsession()
{
delete shell;
delete shell_;
G4UImanager* UI = G4UImanager::GetUIpointer();
UI-> SetSession(0);
UI-> SetCoutDestination(0);
::UI = G4UImanager::GetUIpointer();
::UI-> SetSession(0);
::UI-> SetCoutDestination(0);
}
// --------------------------------------------------------------------------
void G4MPIsession::SetPrompt(const G4String& prompt)
{
shell-> SetPrompt(prompt);
shell_-> SetPrompt(prompt);
}
// --------------------------------------------------------------------------
void G4MPIsession::SetShell(G4VUIshell* ashell)
{
delete shell;
shell = ashell;
delete shell_;
shell_ = ashell;
}
// --------------------------------------------------------------------------
G4String G4MPIsession::GetCommand(const char* msg)
{
G4UImanager* UI = G4UImanager::GetUIpointer();
G4String newCommand;
const G4String nullString="";
const G4String nullString = "";
// get command from shell...
newCommand = shell-> GetCommandLineString(msg);
newCommand = shell_-> GetCommandLineString(msg);
G4String nC= newCommand.strip(G4String::leading);
if( nC.length() == 0 ) {
@@ -103,62 +108,62 @@ G4String G4MPIsession::GetCommand(const char* msg)
G4cout << nC << G4endl;
newCommand = nullString;
} else if(nC=="ls" || nC(0,3)=="ls " ) { // list commands
} else if( nC == "ls" || nC(0,3) == "ls " ) { // list commands
ListDirectory(nC);
newCommand = nullString;
} else if(nC=="lc" || nC(0,3)=="lc " ) { // ... by shell
shell-> ListCommand(nC.remove(0,2));
} else if( nC == "lc" || nC(0,3) == "lc " ) { // ... by shell
shell_-> ListCommand(nC.remove(0,2));
newCommand = nullString;
} else if(nC == "pwd") { // show current directory
} else if( nC == "pwd" ) { // show current directory
G4cout << "Current Command Directory : "
<< GetCurrentWorkingDirectory() << G4endl;
<< GetCurrentWorkingDirectory() << G4endl;
newCommand = nullString;
} else if(nC == "cwd") { // ... by shell
shell-> ShowCurrentDirectory();
} else if( nC == "cwd" ) { // ... by shell
shell_-> ShowCurrentDirectory();
newCommand = nullString;
} else if(nC == "cd" || nC(0,3) == "cd ") { // "cd"
} else if(nC == "cd" || nC(0,3) == "cd " ) { // "cd"
ChangeDirectoryCommand(nC);
shell-> SetCurrentDirectory(GetCurrentWorkingDirectory());
shell_-> SetCurrentDirectory(GetCurrentWorkingDirectory());
newCommand = nullString;
} else if(nC == "help" || nC(0,5) == "help ") { // "help"
} else if( nC == "help" || nC(0,5) == "help " ) { // "help"
TerminalHelp(nC);
newCommand = nullString;
} else if(nC(0) == '?') { // "show current value of a parameter"
} else if( nC(0) == '?' ) { // "show current value of a parameter"
ShowCurrent(nC);
newCommand = nullString;
} else if(nC == "hist" || nC == "history") { // "hist/history"
G4int nh= UI-> GetNumberOfHistory();
for (G4int i = 0; i<nh; i++) {
G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
} else if( nC == "hist" || nC == "history" ) { // "hist/history"
G4int nh= ::UI-> GetNumberOfHistory();
for( G4int i = 0; i<nh; i++ ) {
G4cout << i << ": " << ::UI-> GetPreviousCommand(i) << G4endl;
}
newCommand = nullString;
} else if(nC(0) == '!') { // "!"
G4String ss= nC(1, nC.length()-1);
} else if( nC(0) == '!' ) { // "!"
G4String ss = nC(1, nC.length()-1);
G4int vl;
const char* tt = ss;
std::istringstream is(tt);
is >> vl;
G4int nh= UI-> GetNumberOfHistory();
if(vl>=0 && vl<nh) {
newCommand = UI-> GetPreviousCommand(vl);
G4int nh = ::UI-> GetNumberOfHistory();
if( vl>=0 && vl<nh ) {
newCommand = ::UI-> GetPreviousCommand(vl);
G4cout << newCommand << G4endl;
} else {
G4cerr << "history " << vl << " is not found." << G4endl;
newCommand = nullString;
}
} else if( nC.empty() ){ // NULL command
} else if( nC.empty() ) { // NULL command
newCommand = nullString;
} else if( nC == "exit" ){ // "exit"
} else if( nC == "exit" ) { // "exit"
return "exit";
} else { // ...
@@ -173,13 +178,13 @@ G4String G4MPIsession::GetCommand(const char* msg)
G4UIsession* G4MPIsession::SessionStart()
{
// execute init macro
if( g4MPI-> IsInitMacro() ) {
g4MPI-> ExecuteMacroFile(g4MPI->GetInitFileName());
if( g4mpi_-> IsInitMacro() ) {
g4mpi_-> ExecuteMacroFile(g4mpi_->GetInitFileName());
}
// batch mode
if( g4MPI-> IsBatchMode() ) {
g4MPI-> ExecuteMacroFile(g4MPI->GetMacroFileName(), true);
if( g4mpi_-> IsBatchMode() ) {
g4mpi_-> ExecuteMacroFile(g4mpi_->GetMacroFileName(), true);
return NULL;
}
@@ -187,12 +192,12 @@ G4UIsession* G4MPIsession::SessionStart()
G4String newCommand = "", scommand; // newCommand is always "" in slaves
while(1) {
if(isMaster) newCommand = GetCommand();
if( is_master_ ) newCommand = GetCommand();
// broadcast a new G4 command
scommand = g4MPI-> BcastCommand(newCommand);
if(scommand == "exit") {
scommand = g4mpi_-> BcastCommand(newCommand);
if( scommand == "exit" ) {
G4bool qexit = TryForcedTerminate();
if(qexit) break;
if( qexit ) break;
else scommand = "";
}
ExecCommand(scommand);
@@ -204,14 +209,14 @@ G4UIsession* G4MPIsession::SessionStart()
// --------------------------------------------------------------------------
G4bool G4MPIsession::TryForcedTerminate()
{
if(! g4MPI-> CheckThreadStatus()) {
if(! g4mpi_-> CheckThreadStatus()) {
return true;
}
G4String xmessage;
// beamOn is still running
if(isMaster) {
if( is_master_ ) {
char c[1024];
while(1) {
G4cout << "Run is still running. Do you abort a run? [y/N]:"
@@ -225,16 +230,16 @@ G4bool G4MPIsession::TryForcedTerminate()
}
if(c[0] == 'y' || c[0] == 'Y') {
G4cout << "Aborting a run..." << G4endl;
xmessage = g4MPI-> BcastCommand("kill me");
xmessage = g4mpi_-> BcastCommand("kill me");
} else {
xmessage = g4MPI-> BcastCommand("alive");
xmessage = g4mpi_-> BcastCommand("alive");
}
} else {
xmessage = g4MPI-> BcastCommand("");
xmessage = g4mpi_-> BcastCommand("");
}
if(xmessage == "kill me") {
G4RunManager* runManager= G4RunManager::GetRunManager();
G4RunManager* runManager = G4RunManager::GetRunManager();
runManager-> AbortRun(true); // soft abort
}
@@ -25,71 +25,83 @@
/// @file G4MPIstatus.cc
/// @brief status of MPI application
#include "G4MPIstatus.hh"
#include "G4ApplicationState.hh"
#include "G4MPIstatus.hh"
// --------------------------------------------------------------------------
G4MPIstatus::G4MPIstatus()
: rank(0), runID(0), nEventToBeProcessed(0), eventID(0),
cputime(0.), g4state(G4State_Quit)
: rank_(0), run_id_(0), nevent_to_be_processed_(0), event_id_(0),
cputime_(0.), g4state_(G4State_Quit)
{
timer = new G4Timer;
timer_ = new G4Timer;
}
// --------------------------------------------------------------------------
G4MPIstatus::~G4MPIstatus()
{
delete timer;
delete timer_;
}
// --------------------------------------------------------------------------
void G4MPIstatus::StartTimer()
{
timer_-> Start();
}
// --------------------------------------------------------------------------
void G4MPIstatus::StopTimer()
{
timer_-> Stop();
}
// --------------------------------------------------------------------------
void G4MPIstatus::SetStatus(G4int arank, G4int runid, G4int noe, G4int evtid,
G4ApplicationState state)
{
rank = arank;
runID = runid;
nEventToBeProcessed = noe;
eventID = evtid;
g4state = state;
if (timer-> IsValid()) cputime = timer-> GetUserElapsed();
else cputime = 0.;
rank_ = arank;
run_id_ = runid;
nevent_to_be_processed_ = noe;
event_id_ = evtid;
g4state_ = state;
if ( timer_-> IsValid() ) cputime_= timer_-> GetUserElapsed();
else cputime_ = 0.;
}
// --------------------------------------------------------------------------
void G4MPIstatus::Pack(G4int* data) const
{
data[0] = rank;
data[1] = runID;
data[2] = nEventToBeProcessed;
data[3] = eventID;
data[4] = g4state;
data[0] = rank_;
data[1] = run_id_;
data[2] = nevent_to_be_processed_;
data[3] = event_id_;
data[4] = g4state_;
G4double* ddata = (G4double*)(data+5);
ddata[0] = cputime;
ddata[0] = cputime_;
}
// --------------------------------------------------------------------------
void G4MPIstatus::UnPack(G4int* data)
{
rank = data[0];
runID = data[1];
nEventToBeProcessed = data[2];
eventID = data[3];
g4state = (G4ApplicationState)data[4];
rank_ = data[0];
run_id_ = data[1];
nevent_to_be_processed_ = data[2];
event_id_ = data[3];
g4state_ = (G4ApplicationState)data[4];
G4double* ddata = (G4double*)(data+5);
cputime = ddata[0];
cputime_ = ddata[0];
}
// --------------------------------------------------------------------------
void G4MPIstatus::Print() const
{
// * rank= 001 run= 10002 event= 00001 / 100000 state= Idle"
G4cout << "* rank= " << rank
<< " run= " << runID
<< " event= " << eventID << " / " << nEventToBeProcessed
<< " state= " << GetStateString(g4state)
<< " time= " << cputime << "s"
G4cout << "* rank= " << rank_
<< " run= " << run_id_
<< " event= " << event_id_ << " / " << nevent_to_be_processed_
<< " state= " << GetStateString(g4state_)
<< " time= " << cputime_ << "s"
<< G4endl;
}
@@ -29,7 +29,7 @@
// --------------------------------------------------------------------------
G4VMPIseedGenerator::G4VMPIseedGenerator()
: masterSeed(123456789)
: master_seed_(123456789)
{
}
@@ -41,6 +41,6 @@ G4VMPIseedGenerator::~G4VMPIseedGenerator()
// --------------------------------------------------------------------------
void G4VMPIseedGenerator::SetMasterSeed(G4long aseed)
{
masterSeed = aseed;
master_seed_ = aseed;
GenerateSeeds();
}
@@ -25,21 +25,21 @@
/// @file G4VMPIsession.cc
/// @brief A base class for MPI sessions
#include "G4VMPIsession.hh"
#include "G4MPImanager.hh"
#include "G4UImanager.hh"
#include "mpi.h"
#include "G4UIcommand.hh"
#include "G4UImanager.hh"
#include "G4MPImanager.hh"
#include "G4VMPIsession.hh"
// --------------------------------------------------------------------------
G4VMPIsession::G4VMPIsession()
: G4VBasicShell()
{
// MPI
g4MPI = G4MPImanager::GetManager();
g4mpi_ = G4MPImanager::GetManager();
isMaster = g4MPI-> IsMaster();
isSlave = g4MPI-> IsSlave();
rank = g4MPI-> GetRank();
is_master_ = g4mpi_-> IsMaster();
is_slave_ = g4mpi_-> IsSlave();
rank_ = g4mpi_-> GetRank();
}
// --------------------------------------------------------------------------
@@ -51,7 +51,7 @@ G4VMPIsession::~G4VMPIsession()
G4bool G4VMPIsession::GetHelpChoice(G4int& aval)
{
G4cin >> aval;
if(!G4cin.good()){
if( !G4cin.good() ){
G4cin.clear();
G4cin.ignore(30,'\n');
return false;
@@ -72,7 +72,7 @@ void G4VMPIsession::PauseSessionStart(const G4String&)
}
// --------------------------------------------------------------------------
G4int G4VMPIsession::ExecCommand(G4String acommand)
G4int G4VMPIsession::ExecCommand(const G4String& acommand)
{
if( acommand.length() < 2 ) return fCommandSucceeded;
@@ -82,13 +82,13 @@ G4int G4VMPIsession::ExecCommand(G4String acommand)
G4String command = BypassCommand(acommand);
// "/mpi/beamOn is threaded out.
if(command(0,11) == "/mpi/beamOn") {
g4MPI-> ExecuteBeamOnThread(command);
if( command(0,11) == "/mpi/beamOn" ) {
g4mpi_-> ExecuteBeamOnThread(command);
returnVal = fCommandSucceeded;
} else if(command(0,12) == "/mpi/.beamOn") { // care for beamOn
G4bool threadStatus = g4MPI-> CheckThreadStatus();
if (threadStatus) { // still /run/beamOn is active
if(isMaster) {
} else if( command(0,12) == "/mpi/.beamOn" ) { // care for beamOn
G4bool threadStatus = g4mpi_-> CheckThreadStatus();
if ( threadStatus ) { // still /run/beamOn is active
if( is_master_ ) {
G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
}
returnVal = fCommandSucceeded;
@@ -105,11 +105,11 @@ G4int G4VMPIsession::ExecCommand(G4String acommand)
G4int commandStatus = returnVal - paramIndex;
G4UIcommand* cmd = 0;
if(commandStatus != fCommandSucceeded) {
if( commandStatus != fCommandSucceeded ) {
cmd = FindCommand(command);
}
switch(commandStatus) {
switch( commandStatus ) {
case fCommandSucceeded:
break;
case fCommandNotFound:
@@ -151,7 +151,7 @@ G4String G4VMPIsession::TruncateCommand(const G4String& command) const
G4String strarg;
str_size iarg = acommand.find(' ');
if(iarg != G4String::npos) {
if( iarg != G4String::npos ) {
strarg = acommand(iarg, acommand.size()-iarg);
acommand = acommand(0,iarg);
}
@@ -174,58 +174,75 @@ G4String G4VMPIsession::BypassCommand(const G4String& command) const
// bypass some commands
// * /mpi/beamOn
// -> /mpi/.beamOn (batch session)
// -> /mpi/.beamOn (MT mode)
//
// * /run/beamOn
// -> /mpi/.beamOn (batch session)
// -> /mpi/beamOn (interactive session)
// -> /mpi/.beamOn (MT mode)
//
// * /control/execute -> /mpi/execute
G4String acommand = command;
// /mpi/beamOn
if(acommand(0,11) == "/mpi/beamOn") {
if(g4MPI-> IsBatchMode()) {
if( acommand(0,11) == "/mpi/beamOn" ) {
#ifdef G4MULTITHREADED
acommand = "/mpi/.beamOn";
if(command.length() > 11) {
acommand += command.substr(11);
}
#else
if( g4mpi_-> IsBatchMode()) {
acommand = "/mpi/.beamOn";
if(command.length() > 11) {
acommand += command.substr(11);
}
}
#endif
}
// /run/beamOn
if(acommand(0,11) == "/run/beamOn") {
if( acommand(0,11) == "/run/beamOn" ) {
G4String strarg = "";
G4bool qget = false;
G4bool qdone = false;
for (str_size idx = 10; idx < command.size(); idx++) {
if(command[idx] == ' ' || command[idx] == '\011') {
for ( str_size idx = 10; idx < command.size(); idx++ ) {
if( command[idx] == ' ' || command[idx] == '\011' ) {
qget = true;
if(qdone) break;
continue;
}
if(qget) {
if( qget ) {
strarg += command[idx];
qdone = true;
}
}
if(g4MPI-> IsBatchMode()) { // batch session
if( g4mpi_-> IsBatchMode() ) { // batch session
acommand = "/mpi/.beamOn ";
if(command.length() > 11) acommand += strarg;
if( command.length() > 11 ) acommand += strarg;
} else { // interactive session
if(g4MPI-> GetVerbose()>0 && isMaster) {
#ifdef G4MULTITHREADED
if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
G4cout << "/run/beamOn is overridden by /mpi/.beamOn" << G4endl;
}
acommand = "/mpi/.beamOn ";
if( command.length() > 11 ) acommand += strarg;
#else
if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
G4cout << "/run/beamOn is overridden by /mpi/beamOn" << G4endl;
}
acommand = "/mpi/beamOn ";
if(command.length() > 11) acommand += strarg;
if( command.length() > 11 ) acommand += strarg;
#endif
}
}
// /control/execute
if(acommand(0,16) == "/control/execute") {
if(g4MPI-> GetVerbose()>0 && isMaster) {
if( acommand(0,16) == "/control/execute" ) {
if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
G4cout << "/control/execute is overridden by /mpi/execute"
<< G4endl;
}
@@ -238,14 +255,13 @@ G4String G4VMPIsession::BypassCommand(const G4String& command) const
// --------------------------------------------------------------------------
G4int G4VMPIsession::ReceiveG4cout(const G4String& coutString)
{
g4MPI-> Print(coutString);
g4mpi_-> Print(coutString);
return 0;
}
// --------------------------------------------------------------------------
G4int G4VMPIsession::ReceiveG4cerr(const G4String& cerrString)
{
g4MPI-> Print(cerrString);
g4mpi_-> Print(cerrString);
return 0;
}
@@ -1,125 +0,0 @@
//$Id$
///\file "parallel/ParN02/.README.N02"
///\brief Example N02 (in ParN02) README page
/*! \page ExampleN02InParN02 Example N02 in ParN02
This example simulates a simplified fixe target experiment.
Read \link ExampleParN02 Example ParN02 \endlink for a description
of how to run it in parallel.
\section ExampleN02InParN02_s1 GEOMETRY DEFINITION
The setup consists of a target followed by six chambers of increasing
transverse size. These chambers are located in a region called Tracker
region. Their shape are boxes, constructed as parametrised volumes
(ChamberParametrisation class).
The default geometry is constructed in DetectorConstruction class.
One can change the material of the target and of the chambers
interactively via the commands defined in the DetectorMessenger class.
In addition a transverse uniform magnetic field can be applied (see
N02MagneticField and DetectorMessenger classes).
\section ExampleN02InParN02_s2 PHYSICS LIST
The particle's type and the physic processes which will be available
in this example are set in PhysicsList class.
In this example, all the so called 'electromagnetic processes' are
introduced for gamma, charged leptons, and charged hadrons (see the
method PhysicsList::ConstructEM()).
An important data member of this class is the defaultCutValue which
defines the production threshold of secondary particles
(mainly Ionisation and Bremsstrahlung processes are concerned by this
CutValue).
Notice that the CutValue must be given in unit of length, corresponding
to the stopping range of the particle. It is automatically converted
in energy for each material, and a table is printed in the method
PhysicsList::SetCuts()
In addition the build-in interactive command:
\verbatim
/process/(in)activate processName
\endverbatim
allows to activate/inactivate the processes one by one.
\section ExampleN02InParN02_s3 RUNS and EVENTS
The primary kinematic consists of a single particle which hits the
target perpendicular to the input face. The type of the particle
and its energy are set in the PrimaryGeneratorAction class, and can
be changed via the G4 build-in commands of ParticleGun class.
A RUN is a set of events.
The user has control:
-at Begin and End of each run (class RunAction)
-at Begin and End of each event (class EventAction)
-at Begin and End of each track (class TrackingAction, not used here)
-at End of each step (class SteppingAction)
The class SteppingVerbose prints some informations step per step,
under the control of the command: /tracking/verbose 1
It inherits from G4SteppingVerbose, and has been setup here in order
to illustrate how to extract informations from the G4 kernel during
the tracking of a particle.
\section ExampleN02InParN02_s4 DETECTOR RESPONSE
A HIT is a record, track per track (even step per step), of all the
informations needed to simulate and analyse the detector response.
In this example the Tracker chambers are considered as the detector.
Therefore the chambers are declared 'sensitive detectors' (SD) in
the DetectorConstruction class.
Then, a Hit is defined as a set of 4 informations per step, inside
the chambers, namely:
- the track identifier (an integer),
- the chamber number,
- the total energy deposit in this step,
- the position of the deposit.
A given hit is an instance of the class TrackerHit which is created
during the tracking of a particle, step by step, in the method
TrackerSD::ProcessHits(). This hit is inserted in a HitsCollection.
The HitsCollection is printed at the end of event (via the method
TrackerSD::EndOfEvent()), under the control of the command: /hits/verbose 1
\section ExampleN02InParN02_s5 VISUALIZATION
The Visualization Manager is set in the main () (see exampleN02.cc).
The initialisation of the drawing is done via a set of /vis/ commands
in the macro vis.mac. This macro is automatically read from
the main when running in interactive mode.
The tracks are automatically drawn at the end of event and erased at
the beginning of the next run.
The visualization (with OpenGL driver) assumes two things:
1- the visualisation & interfaces categories have been compiled
with the environment variable G4VIS_BUILD_OPENGLX_DRIVER.
2- ParN02.cc has been compiled with G4VIS_USE_OPENGLX.
(The same with DAWNFILE instead of OPENGLX)
\section ExampleN02InParN02_s6 USER INTERFACES
The default command interface, called G4UIterminal, is done via
standart cin/G4cout.
On Linux and Sun-cc on can use a smarter command interface G4UItcsh.
It is enough to set the environment variable G4UI_USE_TCSH before
compiling ParN02.cc
*/
@@ -1,199 +0,0 @@
/**********************************************************************
* Include file with Base Class of Marshalgen *
**********************************************************************/
#ifndef MARSHALEDOBJ_H
#define MARSHALEDOBJ_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define MSH_ASSERT(X) {assert(X);}
#define MSH_HEADER_SIZE (sizeof(int)*2)
// the first field (first sizeof(int) bytes) contains the $TYPE_CHOICE
// the second field contains the size including the header
#define MSH_TOTALSIZE_OFFSET (sizeof(int))
#define MSH_TYPECHOICE_OFFSET 0
#define MSH_SET_TYPECHOICE(X) { memcpy(msh_buffer+MSH_TYPECHOICE_OFFSET,&(X),sizeof(int));}
#define MSH_SET_TOTALSIZE(X) { memcpy(msh_buffer+MSH_TOTALSIZE_OFFSET,&(X),sizeof(int));}
#define MSH_GET_TYPECHOICE(X,BUF) { memcpy(&(X), ((char*)BUF)+MSH_TYPECHOICE_OFFSET,sizeof(int));}
#define MSH_GET_TOTALSIZE(X,BUF) { memcpy(&(X), ((char*)BUF)+MSH_TOTALSIZE_OFFSET,sizeof(int));}
class MarshaledObj {
private:
// Make sure all marshaled objects are word aligned.
static const int WORD_SIZE = sizeof(long);
public:
static int ROUND_UP( int x ){
return (((x)+(WORD_SIZE-1)) / WORD_SIZE) * WORD_SIZE;
}
public:
// Constructs an empty MarshaledObj,
MarshaledObj(){
msh_extent = 128;
msh_size = MSH_HEADER_SIZE;
msh_isUnmarshalDone = false;
msh_buffer = (char *)malloc(msh_extent);
MSH_ASSERT(msh_buffer);
msh_cursor = msh_buffer + MSH_HEADER_SIZE;
msh_field_begin = msh_cursor;
msh_typechoice = 0;
int totalsize = msh_cursor-msh_buffer;
MSH_SET_TYPECHOICE(msh_typechoice);
MSH_SET_TOTALSIZE(totalsize);
}
//MarshaledObj(void *buf);
// This constructs a MarshledObj from a buffer (of type char*) for unmarshaling.
// buf is obtain from an already marshaled object.
// The first field of buf must be an int that contains the size of the buf
// NOT including itself.
// isUnmarshaling must be 'u' (for unmarshaling) .
MarshaledObj(void *buf, char isUnmarshaling) {
msh_isUnmarshalDone = false;
if(isUnmarshaling != 'u') {
printf("MarshaledObj(void*, char): wrong argument\n");
return;
}
//msh_extent = ROUND_UP(*(int *)buf + sizeof(int));
MSH_GET_TYPECHOICE(msh_typechoice,buf);
MSH_GET_TOTALSIZE(msh_size,buf);
msh_extent = ROUND_UP(msh_size);
msh_buffer = (char *)malloc(msh_extent);
MSH_ASSERT(msh_buffer);
memcpy(msh_buffer, (char *)buf, msh_extent);
msh_cursor = msh_buffer + MSH_HEADER_SIZE;
msh_field_begin = msh_cursor;
//MSH_SET_TYPECHOICE(msh_typechoice);
}
~MarshaledObj() {
if ( ! isUnmarshaling() )
free(msh_buffer);
}
inline bool isUnmarshaling() {
return (msh_extent <= 0);
}
private:
// Dont use copy constructor
const MarshaledObj& operator=(const MarshaledObj& right);
protected:
int msh_typechoice; // alias of $TYPE_CHOICE
// points to the buffer (header+body)
char *msh_buffer;
// msh_field_begin points to the size of the current field being marshaled
char* msh_field_begin;
// msh_size contains the total size of msh_buffer. i.e.,
size_t msh_size;
// msh_cursor points to the next field to be marshaled.
char *msh_cursor;
// msh_extent is the total allocated space for msh_buffer.
// msh_extent is always >= msh_size
size_t msh_extent;
bool msh_isUnmarshalDone; //Is unmarshaling done yet?
public:
inline void EXTEND_BUFFER(int size){
msh_size += size;
if(msh_size > msh_extent){
resizeBuffer(msh_size);
}
}
void resizeBuffer(size_t new_size ) {
int msh_displacement = msh_cursor - msh_buffer;
int field_displacement = msh_field_begin - msh_buffer;
while(new_size > msh_extent)
msh_extent *= 2;
msh_buffer = (char *)realloc( msh_buffer, msh_extent);
MSH_ASSERT(msh_buffer);
msh_cursor = msh_buffer + msh_displacement;
msh_field_begin = msh_buffer + field_displacement;
}
public:
// Returns the total size of buffer
inline int getBufferSize() {
return msh_size;
}
inline char *getBuffer() {
return msh_buffer;
}
/* p: pointer to the data field, size: size of that primitive data field */
void marshalPrimitive(void* p, int size) {
int msh_currentSize;
if (isUnmarshaling())
throw "Tried to marshal in object marked isUnmarshaling = true";
msh_currentSize = size;
EXTEND_BUFFER(msh_currentSize + sizeof(int));
// *(int *)msh_cursor = msh_currentSize;
memcpy(msh_cursor, &msh_currentSize, sizeof(int));
msh_cursor += sizeof(int);
memcpy(msh_cursor, p, size);
msh_cursor += msh_currentSize;
msh_size = msh_cursor - msh_buffer;
MSH_SET_TOTALSIZE(msh_size);
}
void unmarshalPrimitive(void* p, int size) {
int msh_currentSize;
//memcpy(&msh_currentSize, msh_cursor, sizeof(int));
/* in case *msh_cursor is invalid, use "size" not to crash the memory */
msh_currentSize = size;
msh_cursor += sizeof(int);
memcpy(p, msh_cursor, msh_currentSize);
msh_cursor += msh_currentSize;
//msh_size = msh_cursor - msh_buffer;
}
};
/* Used for distinguish the class types of the template parameter
vietha 2003.05.01 */
template <class T,class>
class MSH_IsSameClass
{
public:
enum {Is = 0};
};
template<class T>
class MSH_IsSameClass<T,T>
{
public:
enum {Is = 1};
};
#endif
@@ -1,199 +0,0 @@
/**********************************************************************
* Include file with Base Class of Marshalgen *
**********************************************************************/
#ifndef MARSHALEDOBJ_H
#define MARSHALEDOBJ_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define MSH_ASSERT(X) {assert(X);}
#define MSH_HEADER_SIZE (sizeof(int)*2)
// the first field (first sizeof(int) bytes) contains the $TYPE_CHOICE
// the second field contains the size including the header
#define MSH_TOTALSIZE_OFFSET (sizeof(int))
#define MSH_TYPECHOICE_OFFSET 0
#define MSH_SET_TYPECHOICE(X) { memcpy(msh_buffer+MSH_TYPECHOICE_OFFSET,&(X),sizeof(int));}
#define MSH_SET_TOTALSIZE(X) { memcpy(msh_buffer+MSH_TOTALSIZE_OFFSET,&(X),sizeof(int));}
#define MSH_GET_TYPECHOICE(X,BUF) { memcpy(&(X), ((char*)BUF)+MSH_TYPECHOICE_OFFSET,sizeof(int));}
#define MSH_GET_TOTALSIZE(X,BUF) { memcpy(&(X), ((char*)BUF)+MSH_TOTALSIZE_OFFSET,sizeof(int));}
class MarshaledObj {
private:
// Make sure all marshaled objects are word aligned.
static const int WORD_SIZE = sizeof(long);
public:
static int ROUND_UP( int x ){
return (((x)+(WORD_SIZE-1)) / WORD_SIZE) * WORD_SIZE;
}
public:
// Constructs an empty MarshaledObj,
MarshaledObj(){
msh_extent = 128;
msh_size = MSH_HEADER_SIZE;
msh_isUnmarshalDone = false;
msh_buffer = (char *)malloc(msh_extent);
MSH_ASSERT(msh_buffer);
msh_cursor = msh_buffer + MSH_HEADER_SIZE;
msh_field_begin = msh_cursor;
msh_typechoice = 0;
int totalsize = msh_cursor-msh_buffer;
MSH_SET_TYPECHOICE(msh_typechoice);
MSH_SET_TOTALSIZE(totalsize);
}
//MarshaledObj(void *buf);
// This constructs a MarshledObj from a buffer (of type char*) for unmarshaling.
// buf is obtain from an already marshaled object.
// The first field of buf must be an int that contains the size of the buf
// NOT including itself.
// isUnmarshaling must be 'u' (for unmarshaling) .
MarshaledObj(void *buf, char isUnmarshaling) {
msh_isUnmarshalDone = false;
if(isUnmarshaling != 'u') {
printf("MarshaledObj(void*, char): wrong argument\n");
return;
}
//msh_extent = ROUND_UP(*(int *)buf + sizeof(int));
MSH_GET_TYPECHOICE(msh_typechoice,buf);
MSH_GET_TOTALSIZE(msh_size,buf);
msh_extent = ROUND_UP(msh_size);
msh_buffer = (char *)malloc(msh_extent);
MSH_ASSERT(msh_buffer);
memcpy(msh_buffer, (char *)buf, msh_extent);
msh_cursor = msh_buffer + MSH_HEADER_SIZE;
msh_field_begin = msh_cursor;
//MSH_SET_TYPECHOICE(msh_typechoice);
}
~MarshaledObj() {
if ( ! isUnmarshaling() )
free(msh_buffer);
}
inline bool isUnmarshaling() {
return (msh_extent <= 0);
}
private:
// Dont use copy constructor
const MarshaledObj& operator=(const MarshaledObj& right);
protected:
int msh_typechoice; // alias of $TYPE_CHOICE
// points to the buffer (header+body)
char *msh_buffer;
// msh_field_begin points to the size of the current field being marshaled
char* msh_field_begin;
// msh_size contains the total size of msh_buffer. i.e.,
size_t msh_size;
// msh_cursor points to the next field to be marshaled.
char *msh_cursor;
// msh_extent is the total allocated space for msh_buffer.
// msh_extent is always >= msh_size
size_t msh_extent;
bool msh_isUnmarshalDone; //Is unmarshaling done yet?
public:
inline void EXTEND_BUFFER(int size){
msh_size += size;
if(msh_size > msh_extent){
resizeBuffer(msh_size);
}
}
void resizeBuffer(size_t new_size ) {
int msh_displacement = msh_cursor - msh_buffer;
int field_displacement = msh_field_begin - msh_buffer;
while(new_size > msh_extent)
msh_extent *= 2;
msh_buffer = (char *)realloc( msh_buffer, msh_extent);
MSH_ASSERT(msh_buffer);
msh_cursor = msh_buffer + msh_displacement;
msh_field_begin = msh_buffer + field_displacement;
}
public:
// Returns the total size of buffer
inline int getBufferSize() {
return msh_size;
}
inline char *getBuffer() {
return msh_buffer;
}
/* p: pointer to the data field, size: size of that primitive data field */
void marshalPrimitive(void* p, int size) {
int msh_currentSize;
if (isUnmarshaling())
throw "Tried to marshal in object marked isUnmarshaling = true";
msh_currentSize = size;
EXTEND_BUFFER(msh_currentSize + sizeof(int));
// *(int *)msh_cursor = msh_currentSize;
memcpy(msh_cursor, &msh_currentSize, sizeof(int));
msh_cursor += sizeof(int);
memcpy(msh_cursor, p, size);
msh_cursor += msh_currentSize;
msh_size = msh_cursor - msh_buffer;
MSH_SET_TOTALSIZE(msh_size);
}
void unmarshalPrimitive(void* p, int size) {
int msh_currentSize;
//memcpy(&msh_currentSize, msh_cursor, sizeof(int));
/* in case *msh_cursor is invalid, use "size" not to crash the memory */
msh_currentSize = size;
msh_cursor += sizeof(int);
memcpy(p, msh_cursor, msh_currentSize);
msh_cursor += msh_currentSize;
//msh_size = msh_cursor - msh_buffer;
}
};
/* Used for distinguish the class types of the template parameter
vietha 2003.05.01 */
template <class T,class>
class MSH_IsSameClass
{
public:
enum {Is = 0};
};
template<class T>
class MSH_IsSameClass<T,T>
{
public:
enum {Is = 1};
};
#endif
+8 -4
View File
@@ -5,13 +5,17 @@
This directory includes example applications to demonstrate the usage of
different techniques for achieving event parallelism with Geant4.
- ParN02 and ParN04 are modified versions of the novice examples N02 and N04
adapted to be run together with the TOP-C communication layer application
on either a cluster of systems or multi-processor machines.
- MPI is a native interface with MPI libraries. The directory contains
a Geant4 UI library and a couple of parallelized examples.
Using this interface, users applications can be parllelized with
different MPI compliant libraries, such as LAM/MPI, MPICH2, OpenMPI,
and so on.
- Example TBB is derived from original basic/B2 demonstrating how to
interface a simple application with the Intel Threading Building Blocks
library (TBB), and organise MT event-level parallelism as TBB tasks.
- TopC examples are Geant4 examples adapted to be run together with
the TOP-C communication layer application on either a cluster of systems
or multi-processor machines. They are based on N02 and N04 examples,
originally provided in novice examples (see more in example/README)
+27
View File
@@ -0,0 +1,27 @@
//$Id$
///\file "parallel/TBB/.README"
///\brief Examples TBB README page
/*! \page Examples_tbb Category "parallel/TBB"
TBB directory shows how to integrate Intel Threading Building Block and Geant4
to achieve event-level parallelism.
\link ExampleTBB_B2b TBB/B2b \endlink
Currently only a preliminary version of one example is provided: it replaces
the Geant4 Version 10.0 event-loop parallelism based on pthreads with TBB
task-based parallelism. <em> It should not be considered a feature-complete example
and it present some limitations (no merging of output, no correct clean-up of
heap). </em>
It will be substantially improved in 2014. If you have interest in TBB please
refer to Geant4 Multi-threading user-forum (reachable from Geant4 website)
where updates on TBB will be communicated or contact example author at:
adotti@slac.stanford.edu.
*/
@@ -0,0 +1,52 @@
//$Id$
///\file "parallel/TBB/B2b/.README"
///\brief Example TBB/B2b README page
/*! \page ExampleTBB_B2b Example TBB/B2b
This example shows how to integrate Intel Threading Building Block and Geant4
to achieve event-level parallelism.
<em>
Note that this is a preliminary version which should not be considered a
feature-complete example and which presents some limitations (no merging of
output, no correct clean-up of heap). It will be substantially improved
in 2014.
</em>
This example adds to B2b example, originally provided in basic example,
the TBB based classes:
\section TBB_B2b_s1 tbbMasterRunManager
tbbMasterRunManager class implements the master model run manager for TBB bases
application.
It is instantiated by user main (or equivalent function) instead
of G4[MT]RunManager. It controls the creation of tbb::tasks.
See G4MTRunManager for documentation of methods relative to base
class. Only class specific methods are documented here.
\section TBB_B2b_s2 tbbWorkerRunManager
tbbWorkerRunManager class implements the worker model run manager for TBB based
application.
It is instantiated by tbbUserWorkerInitialization and used by
tbbMasterRunManager.
See G4WorkerRunManager for documentation of methods relative to
base class. Only class specific methods are documented here.
\section TBB_B2b_s3 tbbUserWorkerInitialization
tbbUserWorkerInitialization class implements TBB specific worker initialization.
It is a sub-class of G4UserWorkerThreadInitialization.
Its role is to instantiate a tbbWorkerRunManager to be used by
tbb tasks.
\section TBB_B2b_s4 tbbTask
tbbTask class represents one TBB task.
*/
@@ -0,0 +1,79 @@
# $Id: CMakeLists.txt 68058 2013-03-13 14:47:43Z gcosmo $
#----------------------------------------------------------------------------
# Setup the project
#
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(B2bTBB)
#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
find_package(Geant4 REQUIRED ui_all vis_all multithreaded)
else()
find_package(Geant4 REQUIRED multithreaded)
endif()
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
#
include(${Geant4_USE_FILE})
#----------------------------------------------------------------------------
# Find TBB (required package)
#
find_package(TBB REQUIRED)
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
# Setup include directory for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include ${TBB_INCLUDE_DIRS})
#----------------------------------------------------------------------------
# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
#
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(exampleB2bTBB exampleB2b.cc ${sources} ${headers})
target_link_libraries(exampleB2bTBB ${Geant4_LIBRARIES} ${TBB_LIBRARIES})
#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build B2b. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.
#
set(EXAMPLEB2B_SCRIPTS
exampleB2b.out
exampleB2.in
icons.mac
gui.mac
run.png
init.mac
init_vis.mac
tbb.mac
vis.mac
)
foreach(_script ${EXAMPLEB2B_SCRIPTS})
configure_file(
${PROJECT_SOURCE_DIR}/${_script}
${PROJECT_BINARY_DIR}/${_script}
COPYONLY
)
endforeach()
#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS exampleB2bTBB DESTINATION bin)
@@ -0,0 +1,110 @@
.... Not yet finished .....
Status at Nov. 6th:
- Needs tag run-V09-06-115, for virtual keyword dded to barriers and new methods in base classes:
G4WorkerRunManager::MergePartialResults() re-factor reduction of local resutls into global
GMTRunManager::CreateAndStartWorkers() re-factor calls to create a worker threads.
- Tag is not yet in SVN, need some testing of the the above changes.
- With the above changes we reduce a lot the code differences in tbb examples
- Missing: reductions of run and scorers
- First macro tbb.mac created
========
Issues to be worked on that differentiate TBB from MT:
- SOLVED w/ run-V09-06-115: Barrier mechanism and synchornization of threads has no sense in TBB
- "Output" (run and scorer) cannot be anymore "thread-private". tbb::task should register (or reuse in
future version) output "containers" for master to use
- /run/beamOn command will create the list of tasks, but how to start them? From main?
- How to make more than one run? Maybe a new command /tbb/beamOn ???
- One RM per thread. In TBB master thread is "reused" and so crash because more than one RM is created on same thread.
Poor man solution: start work on a separate thread (e.g. explicit invokation of G4THREADCREATE for
tbb::task::spawn_root_and_wait
========
Bugs:
- Strangely it seems that two runs are exec, it appeared "Run 1 start" at the end of the job with no events processed
- No delete of objects...
==========
General design:
The experience of N02tbb of propototype showed that better design was needed with MT kernel classes.
The 10.beta design of relevant MT classes took into account this experience. The final goal is to have
only few classes that implement the TBB specific parallel execution model. These classes should be
independentent of both G4 kernel and of the specific example.
==========
Details:
I think We need only four TBB specific classes:
tbbTask (implements tbb::task)
: it's function is basically to replicate G4MTRunManagerKernel::StartThread, adding check if thread is
already intialized. Some issues are still present. See comments in text
tbbWorkerRunManager (implements G4WorkerRunManager)
: worker model, re-implements base class methods in order to:
- disable barrier mechanism
- different way of proceeding for RunTermination since there is no guarantee this is executed in thread
where it was started
tbbMasterRunManager (implements G4MTRunManager)
: master model, re-implements base class methods in order to:
- disable barrier mechanism
- instead of starting threads as in MT, created tbbTask objects, configure them (if needed) and creates
a tbb list of tasks
- Need to understnad how to reduce output from tasks
tbbUserWorkerInitialization (implements G4USerWorkerInitialization)
: used by tbbMaster it has the only responsibility to "new" a tbbWorkerRunManager
(the idea being to decouple master and worker, as in MT, so a user can re-implement only one of the two)
===========
Even more details:
List of virtual methods (and motivation) that are needed to implement for TBB:
tbbMasterRunManager::CreateAndStartWorkers => Create tbb::task instead of pthread. Actual creation of tasks is in ::CreateTask,
this method only calculates number of tasks.
tbbMasterRunManager::TerminateWorkers => Empty in TBB instead of joining pthreads
tbbMasterRunManager::All barriers => are empty in TBB.
tbbWorkerRunManager::ConstructScoringWolds => is protected in base class, but in tbb is called by tbb::execute, implement proxy here
tbbWorkerRunManager::MergePartialResults => in MT it's done by worker thread at the end of job, "pushing" to master. Needs to implement
the opposite in TBB
tbbUserWorkerInitialization::CrateWorkerRunManager => Needs to instantiate tbbWorkerRunManager
tbbTask::execute() => TBB specific method, MT "equivalent" is G4MTRunManagerKernel::StarThread, with the difference that
the same thread can execute more than one events and thus must re-use the "thread" private variables.
For the first example we assume all threads are used for simulation (e.g. no re-use of workspace).
If we get the design right, it will be enough to change this method to re-use workspaces (CMS requirement)
============
Some comments/notes:
1- We could change MT kernel design to make barriers optional, no need to re-implmente tbbWorkerRunManager::RunInitialization
2- tbb::task starts and it can be in a never used thread. In such a case setups the environment. In particular a G4Run object
is created (and scorers). We need to register these objects somewhere so the master can get them at the end and perform
reduction. Note these object cannot contain TLS variables because they will be reduced in a different thread (the master).
Anyway should be noted that since G4Run and scorers are thread private they should NEVER contain TLS variables. If they do
to me is a design flow.
3- How to "delete" stuff that is created in tbb::task? The problem is that in MT StarThread has scope of life-time of thread
so just before returning we can cleanup. tbb::task::execute has not such a concept.
Can we add a "callback" to threads that are executed at exit? (a thread "atexit" function?). Maybe could be useful.
Otherwise we need the master to clean up everything. In MT master has a list of worker run managers, but "delete" is done
in threads to correctly clean up "TLS" stuff.
Alternatively G4AutoDelete can help on that.
4- List of minor things: vector or workers and mutex to manipulate it are private data members in MT ; ConstructScoringWorld
is protected; G4UserWorkerThreadInitialization contains explicitly the word "Thread" , not a big deal but it gives the
wrong impression
5- If in G4MTRunManager we refactor the lines that start threads in a new virtual method in TBB we could re-implement only this
provided that barriers can be disabled
============
Current Status (Nov. 1, 2013):
CMakeLists.txt : prepared, application compiles if TBB is installed in the system
tbbTask : prototype done
tbbWorkerRunManager : prototype done
tbbUserWorkerInitialization : prototype done
tbbMasterRunManager : prototype done
See "TBB" string in comments in code.
@@ -0,0 +1,24 @@
# $Id: GNUmakefile 68058 2013-03-13 14:47:43Z gcosmo $
# --------------------------------------------------------------
# GNUmakefile for examples module. Gabriele Cosmo, 06/04/98.
# --------------------------------------------------------------
name := exampleB2b
G4TARGET := $(name)
G4EXLIB := true
ifndef G4INSTALL
G4INSTALL = ../../../..
endif
.PHONY: all
all: lib bin
include $(G4INSTALL)/config/architecture.gmk
include $(G4INSTALL)/config/binmake.gmk
visclean:
rm -f g4*.prim g4*.eps g4*.wrl
rm -f .DAWN_*
+48
View File
@@ -0,0 +1,48 @@
$Id$
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
TBB/B2b
--------
This example shows how to integrate Intel Threading Building Block and Geant4
to achieve event-level parallelism.
Note that this is a preliminary version which should not be considered a
feature-complete example and which presents some limitations (no merging of
output, no correct clean-up of heap). It will be substantially improved
in 2014.
This example adds to B2b example, originally provided in basic example,
the TBB based classes:
tbbMasterRunManager:
--------------------
This class implements the master model run manager for TBB bases
application.
It is instantiated by user main (or equivalent function) instead
of G4[MT]RunManager. It controls the creation of tbb::tasks.
See G4MTRunManager for documentation of methods relative to base
class. Only class specific methods are documented here.
tbbWorkerRunManager
--------------------
This class implements the worker model run manager for TBB based
application.
It is instantiated by tbbUserWorkerInitialization and used by
tbbMasterRunManager.
See G4WorkerRunManager for documentation of methods relative to
base class. Only class specific methods are documented here.
tbbUserWorkerInitialization
---------------------------
This class implements TBB specific worker initialization.
It is a sub-class of G4UserWorkerThreadInitialization.
Its role is to instantiate a tbbWorkerRunManager to be used by
tbb tasks.
tbbTask
---------------------------
This class represents one TBB task.
@@ -0,0 +1,25 @@
/tracking/verbose 1
# e+ 200MeV
/gun/energy 200 MeV
/gun/particle e+
/run/beamOn 1
# mu+ 1TeV
/gun/energy 1 TeV
/gun/particle mu+
/run/beamOn 1
/tracking/verbose 0
# e+ 200MeV
/gun/energy 200 MeV
/gun/particle e+
/run/beamOn 100
# mu+ 1TeV
/gun/energy 1 TeV
/gun/particle mu+
/run/beamOn 100
exit
@@ -0,0 +1,168 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
/// \file parallel/TBB/B2b/exampleB2b.cc
/// \brief Main program of the B2b example
#include "B2bDetectorConstruction.hh"
#include "B2ActionInitialization.hh"
//G4-TBB interfaces
#include "tbbUserWorkerInitialization.hh"
#include "tbbMasterRunManager.hh"
#include "G4Threading.hh"
#include "G4UImanager.hh"
#include "FTFP_BERT.hh"
#include "G4StepLimiterPhysics.hh"
#include "Randomize.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
//TBB includes
#include <tbb/task_scheduler_init.h>
#include <tbb/task.h>
//This function is very simple: it just start tbb work.
//This is done in a seperate thread, because for G4 the
//master cannot live in the same thread where workers are
//Starting tbb work in a thread guarantees that no workers
//are created where the master lives (the main thread)
//Clearly a separate solution is to create and configure master
//in a separate thread. But this is much simpler.
G4ThreadFunReturnType startWork(G4ThreadFunArgType arg)
{
tbb::task_list* tasks = static_cast<tbb::task_list*>(arg);
//We assume at least one /run/beamOn was executed, thus the tasklist is now filled,
//lets start TBB
try {
std::cout<<"Now spawn work and waiting"<<std::endl;
tbb::task::spawn_root_and_wait( *tasks );
} catch(std::exception& e) {
std::cerr<<"Error occurred. Error test is:\""<<e.what()<<"\""<<std::endl;
}
return static_cast<G4ThreadFunReturnType>(0);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
int main(int argc,char** argv)
{
// Choose the Random engine
G4Random::setTheEngine(new CLHEP::RanecuEngine);
//=== TBB engine initialization
tbb::task_scheduler_init init( G4Threading::G4GetNumberOfCores() );
tbb::task_list tasks;
tbbMasterRunManager* runManager = new tbbMasterRunManager;
//Set TBB specific data to run-manager, 1 event per tbb::task (e.g. Nevents == N tasks)
//Note that a /run/beamOn command will just create tasks and add them to tasks
runManager->SetNumberEventsPerTask(1); //Not needed since 1 is however default
runManager->SetTaskList(&tasks);
//Set user-initialization that specify threading model, in this case TBB.
//This overwrites default that uses pthreads
runManager->SetUserInitialization(new tbbUserWorkerInitialization );
//==== Geant4 specific stuff, from now up to END-G4 comment is copy from MT example
// Set mandatory initialization classes
runManager->SetUserInitialization(new B2bDetectorConstruction());
G4VModularPhysicsList* physicsList = new FTFP_BERT;
physicsList->RegisterPhysics(new G4StepLimiterPhysics());
runManager->SetUserInitialization(physicsList);
// Set user action classes
runManager->SetUserInitialization(new B2ActionInitialization());
// Initialize G4 kernel
runManager->Initialize();
#ifdef G4VIS_USE
// Initialize visualization
G4VisManager* visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
#endif
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
if (argc!=1) // batch mode
{
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);
}
else
{ // interactive mode : define UI session
#ifdef G4UI_USE
G4UIExecutive* ui = new G4UIExecutive(argc, argv);
#ifdef G4VIS_USE
UImanager->ApplyCommand("/control/execute init_vis.mac");
#else
UImanager->ApplyCommand("/control/execute init.mac");
#endif
if (ui->IsGUI())
UImanager->ApplyCommand("/control/execute gui.mac");
ui->SessionStart();
delete ui;
#endif
}
//END-G4
G4Thread aThread;
G4THREADCREATE(&aThread,startWork,static_cast<G4ThreadFunArgType>(&tasks));
//Wait for work to be finised
G4THREADJOIN(aThread);
#ifdef G4VIS_USE
delete visManager;
#endif
delete runManager;
return 0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,48 @@
#
# This file permits to customize, with commands,
# the menu bar of the G4UIXm, G4UIQt, G4UIWin32 sessions.
# It has no effect with G4UIterminal.
#
#
# Add icons of general interest
#
/control/execute icons.mac
#
# File menu :
/gui/addMenu file File
/gui/addButton file Quit exit
#
# Run menu :
/gui/addMenu run Run
/gui/addButton run "beamOn 1" "/run/beamOn 1"
/gui/addButton run run1 "/control/execute run1.mac"
/gui/addButton run run2 "/control/execute run2.mac"
#
# Gun menu :
/gui/addMenu gun Gun
/gui/addButton gun "50 MeV" "/gun/energy 50 MeV"
/gui/addButton gun "1 GeV" "/gun/energy 1 GeV"
/gui/addButton gun "10 GeV" "/gun/energy 10 GeV"
/gui/addButton gun "e-" "/gun/particle e-"
/gui/addButton gun "pi0" "/gun/particle pi0"
/gui/addButton gun "pi+" "/gun/particle pi+"
/gui/addButton gun "neutron" "/gun/particle neutron"
/gui/addButton gun "proton" "/gun/particle proton"
#
# Field menu :
/gui/addMenu field Field
/gui/addButton field "off" "/globalField/setValue 0 0 0 tesla"
/gui/addButton field "0.2 tesla" "/globalField/setValue 0.2 0 0 tesla"
/gui/addButton field "2.0 tesla" "/globalField/setValue 2.0 0 0 tesla"
#
# Viewer menu :
/gui/addMenu viewer Viewer
/gui/addButton viewer "Set style surface" "/vis/viewer/set/style surface"
/gui/addButton viewer "Set style wireframe" "/vis/viewer/set/style wire"
/gui/addButton viewer "Refresh viewer" "/vis/viewer/refresh"
/gui/addButton viewer "Update viewer (interaction or end-of-file)" "/vis/viewer/update"
/gui/addButton viewer "Flush viewer (= refresh + update)" "/vis/viewer/flush"
/gui/addButton viewer "Update scene" "/vis/scene/notifyHandlers"
#
# User defined icon :
/gui/addIcon "Run beam on" user_icon "/run/beamOn 1" run.png
@@ -0,0 +1,26 @@
#
# This file permits to customize, with commands,
# the icon menu bar of the G4UIQt sessions not yet implemented other UI drivers (geant4-09-05-ref-09)
# It has no effect with G4UIterminal.
# open/save icons
/gui/addIcon "Open macro file" open /control/execute
/gui/addIcon "Save viewer state" save /vis/viewer/save
# Cursors style icons
/gui/addIcon "Move" move
/gui/addIcon "Pick" pick
/gui/addIcon "Zoom out" zoom_out
/gui/addIcon "Zoom in" zoom_in
/gui/addIcon "Rotate" rotate
# Surface Style icons
# Surface Style icons
/gui/addIcon "Hidden line removal" hidden_line_removal
/gui/addIcon "Hidden line and hidden surface removal" hidden_line_and_surface_removal
/gui/addIcon "Surfaces" solid
/gui/addIcon "Wireframe" wireframe
# Perspective/Ortho icons
/gui/addIcon "Perspective" perspective
/gui/addIcon "Orthographic" ortho
@@ -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. *
// ********************************************************************
//
// $Id: B2ActionInitialization.hh 68058 2013-03-13 14:47:43Z gcosmo $
//
/// \file B2ActionInitialization.hh
/// \brief Definition of the B2ActionInitialization class
#ifndef B2ActionInitialization_h
#define B2ActionInitialization_h 1
#include "G4VUserActionInitialization.hh"
class B4DetectorConstruction;
/// Action initialization class.
///
class B2ActionInitialization : public G4VUserActionInitialization
{
public:
B2ActionInitialization();
virtual ~B2ActionInitialization();
virtual void BuildForMaster() const;
virtual void Build() const;
};
#endif
@@ -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. *
// ********************************************************************
//
// $Id: B2EventAction.hh 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2EventAction.hh
/// \brief Definition of the B2EventAction class
#ifndef B2EventAction_h
#define B2EventAction_h 1
#include "G4UserEventAction.hh"
#include "globals.hh"
/// Event action class
class B2EventAction : public G4UserEventAction
{
public:
B2EventAction();
virtual ~B2EventAction();
virtual void BeginOfEventAction(const G4Event* );
virtual void EndOfEventAction(const G4Event* );
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,66 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: B2PrimaryGeneratorAction.hh 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2PrimaryGeneratorAction.hh
/// \brief Definition of the B2PrimaryGeneratorAction class
#ifndef B2PrimaryGeneratorAction_h
#define B2PrimaryGeneratorAction_h 1
#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
class G4ParticleGun;
class G4Event;
/// The primary generator action class with particle gum.
///
/// It defines a single particle which hits the Tracker
/// perpendicular to the input face. The type of the particle
/// can be changed via the G4 build-in commands of G4ParticleGun class
/// (see the macros provided with this example).
class B2PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
public:
B2PrimaryGeneratorAction();
virtual ~B2PrimaryGeneratorAction();
virtual void GeneratePrimaries(G4Event* );
G4ParticleGun* GetParticleGun() {return fParticleGun;}
// Set methods
void SetRandomFlag(G4bool );
private:
G4ParticleGun* fParticleGun; // G4 particle gun
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,55 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: B2RunAction.hh 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2RunAction.hh
/// \brief Definition of the B2RunAction class
#ifndef B2RunAction_h
#define B2RunAction_h 1
#include "G4UserRunAction.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class G4Run;
/// Run action class
class B2RunAction : public G4UserRunAction
{
public:
B2RunAction();
virtual ~B2RunAction();
virtual void BeginOfRunAction(const G4Run* run);
virtual void EndOfRunAction(const G4Run* run);
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,108 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: B2TrackerHit.hh 69505 2013-05-07 01:57:27Z asaim $
//
/// \file B2TrackerHit.hh
/// \brief Definition of the B2TrackerHit class
#ifndef B2TrackerHit_h
#define B2TrackerHit_h 1
#include "G4VHit.hh"
#include "G4THitsCollection.hh"
#include "G4Allocator.hh"
#include "G4ThreeVector.hh"
#include "tls.hh"
/// Tracker hit class
///
/// It defines data members to store the trackID, chamberNb, energy deposit,
/// and position of charged particles in a selected volume:
/// - fTrackID, fChamberNB, fEdep, fPos
class B2TrackerHit : public G4VHit
{
public:
B2TrackerHit();
B2TrackerHit(const B2TrackerHit&);
virtual ~B2TrackerHit();
// operators
const B2TrackerHit& operator=(const B2TrackerHit&);
G4int operator==(const B2TrackerHit&) const;
inline void* operator new(size_t);
inline void operator delete(void*);
// methods from base class
virtual void Draw();
virtual void Print();
// Set methods
void SetTrackID (G4int track) { fTrackID = track; };
void SetChamberNb(G4int chamb) { fChamberNb = chamb; };
void SetEdep (G4double de) { fEdep = de; };
void SetPos (G4ThreeVector xyz){ fPos = xyz; };
// Get methods
G4int GetTrackID() const { return fTrackID; };
G4int GetChamberNb() const { return fChamberNb; };
G4double GetEdep() const { return fEdep; };
G4ThreeVector GetPos() const { return fPos; };
private:
G4int fTrackID;
G4int fChamberNb;
G4double fEdep;
G4ThreeVector fPos;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
typedef G4THitsCollection<B2TrackerHit> B2TrackerHitsCollection;
extern G4ThreadLocal G4Allocator<B2TrackerHit>* B2TrackerHitAllocator;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void* B2TrackerHit::operator new(size_t)
{
if(!B2TrackerHitAllocator)
B2TrackerHitAllocator = new G4Allocator<B2TrackerHit>;
return (void *) B2TrackerHitAllocator->MallocSingle();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void B2TrackerHit::operator delete(void *hit)
{
B2TrackerHitAllocator->FreeSingle((B2TrackerHit*) hit);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,69 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: B2TrackerSD.hh 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2TrackerSD.hh
/// \brief Definition of the B2TrackerSD class
#ifndef B2TrackerSD_h
#define B2TrackerSD_h 1
#include "G4VSensitiveDetector.hh"
#include "B2TrackerHit.hh"
#include <vector>
class G4Step;
class G4HCofThisEvent;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
/// B2Tracker sensitive detector class
///
/// The hits are accounted in hits in ProcessHits() function which is called
/// by Geant4 kernel at each step. A hit is created with each step with non zero
/// energy deposit.
class B2TrackerSD : public G4VSensitiveDetector
{
public:
B2TrackerSD(const G4String& name,
const G4String& hitsCollectionName);
virtual ~B2TrackerSD();
// methods from base class
virtual void Initialize(G4HCofThisEvent* hitCollection);
virtual G4bool ProcessHits(G4Step* step, G4TouchableHistory* history);
virtual void EndOfEvent(G4HCofThisEvent* hitCollection);
private:
B2TrackerHitsCollection* fHitsCollection;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,117 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
/// \file B2bChamberParameterisation.hh
/// \brief Definition of the B2bChamberParameterisation class
#ifndef B2bChamberParameterisation_h
#define B2bChamberParameterisation_h 1
#include "globals.hh"
#include "G4VPVParameterisation.hh"
class G4VPhysicalVolume;
class G4Box;
// Dummy declarations to get rid of warnings ...
class G4Trd;
class G4Trap;
class G4Cons;
class G4Orb;
class G4Sphere;
class G4Ellipsoid;
class G4Torus;
class G4Para;
class G4Hype;
class G4Tubs;
class G4Polycone;
class G4Polyhedra;
/// A parameterisation that describes a series of boxes along Z.
///
/// The boxes have equal width, & their lengths are a linear equation.
/// They are spaced an equal distance apart, starting from given location.
class B2bChamberParameterisation : public G4VPVParameterisation
{
public:
B2bChamberParameterisation(G4int noChambers,
G4double startZ,
G4double spacing,
G4double widthChamber,
G4double lengthInitial,
G4double lengthFinal );
virtual ~B2bChamberParameterisation();
void ComputeTransformation (const G4int copyNo,
G4VPhysicalVolume* physVol) const;
void ComputeDimensions (G4Tubs & trackerLayer, const G4int copyNo,
const G4VPhysicalVolume* physVol) const;
private: // Dummy declarations to get rid of warnings ...
void ComputeDimensions (G4Box&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Trd&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Trap&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Cons&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Sphere&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Orb&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Ellipsoid&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Torus&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Para&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Hype&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Polycone&,const G4int,
const G4VPhysicalVolume*) const {}
void ComputeDimensions (G4Polyhedra&,const G4int,
const G4VPhysicalVolume*) const {}
private:
G4int fNoChambers;
G4double fStartZ;
G4double fHalfWidth; // The half-width of each tracker chamber
G4double fSpacing; // The distance between the chambers' center
G4double fRmaxFirst; // The first half-length
G4double fRmaxIncr; // The Increment for the half-length
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#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. *
// ********************************************************************
//
// $Id$
//
/// \file B2bDetectorConstruction.hh
/// \brief Definition of the B2bDetectorConstruction class
#ifndef B2bDetectorConstruction_h
#define B2bDetectorConstruction_h 1
#include "globals.hh"
#include "G4VUserDetectorConstruction.hh"
#include "tls.hh"
class G4VPhysicalVolume;
class G4LogicalVolume;
class G4Material;
class G4UserLimits;
class G4GlobalMagFieldMessenger;
class B2bDetectorMessenger;
/// Detector construction class to define materials, geometry
/// and global uniform magnetic field.
class B2bDetectorConstruction : public G4VUserDetectorConstruction
{
public:
B2bDetectorConstruction();
virtual ~B2bDetectorConstruction();
public:
virtual G4VPhysicalVolume* Construct();
virtual void ConstructSDandField();
// Set methods
void SetTargetMaterial (G4String );
void SetChamberMaterial(G4String );
void SetMaxStep (G4double );
void SetCheckOverlaps(G4bool );
private:
// methods
void DefineMaterials();
G4VPhysicalVolume* DefineVolumes();
// data members
G4LogicalVolume* fLogicTarget; // pointer to the logical Target
G4LogicalVolume* fLogicChamber; // pointer to the logical Chamber
G4Material* fTargetMaterial; // pointer to the target material
G4Material* fChamberMaterial; // pointer to the chamber material
G4UserLimits* fStepLimit; // pointer to user step limits
B2bDetectorMessenger* fMessenger; // detector messenger
static G4ThreadLocal G4GlobalMagFieldMessenger* fMagFieldMessenger;
// magnetic field messenger
G4bool fCheckOverlaps; // option to activate checking of volumes overlaps
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#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. *
// ********************************************************************
//
// $Id$
//
/// \file B2bDetectorMessenger.hh
/// \brief Definition of the B2bDetectorMessenger class
#ifndef B2bDetectorMessenger_h
#define B2bDetectorMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class B2bDetectorConstruction;
class G4UIdirectory;
class G4UIcmdWithAString;
class G4UIcmdWithADoubleAndUnit;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
/// Messenger class that defines commands for B2bDetectorConstruction.
///
/// It implements commands:
/// - /B2/det/setTargetMaterial name
/// - /B2/det/setChamberMaterial name
/// - /B2/det/stepMax value unit
class B2bDetectorMessenger: public G4UImessenger
{
public:
B2bDetectorMessenger(B2bDetectorConstruction* );
virtual ~B2bDetectorMessenger();
virtual void SetNewValue(G4UIcommand*, G4String);
private:
B2bDetectorConstruction* fDetectorConstruction;
G4UIdirectory* fB2Directory;
G4UIdirectory* fDetDirectory;
G4UIcmdWithAString* fTargMatCmd;
G4UIcmdWithAString* fChamMatCmd;
G4UIcmdWithADoubleAndUnit* fStepMaxCmd;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -0,0 +1,82 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// Class description:
//
// This class implements the master model run manager for TBB bases
// application.
// It is instantiated by user main (or equivalent function) instead
// of G4[MT]RunManager. It controls the creation of tbb::tasks.
// See G4MTRunManager for documentation of methods relative to base
// class. Only class specific methods are documented here.
//
// Equivalent in traditional MT:
// G4MTRunManager
//
// History:
// Nov 4th, 2013 A. Dotti - First Implementation
#ifndef TBBMASTERRUNMANAGER_HH
#define TBBMASTERRUNMANAGER_HH
#include "G4MTRunManager.hh"
#include <tbb/task.h>
class tbbMasterRunManager : public G4MTRunManager {
public:
tbbMasterRunManager();
//Default construct, tasklist is the tbb::task_list
//where the created tasks will be added to
//nEvents is the number of events each tbb::task is
//responsible for
virtual ~tbbMasterRunManager();
virtual void RunTermination();
void SetTaskList( tbb::task_list* tl ) { theTasks = tl; }
//Set a reference to the output task list where new tasks will
//be added to
void SetNumberEventsPerTask( G4int nt ) { nEvtsPerTask = nt; }
//Specify number of events that each simulation task is responsible
//for
protected:
virtual void CreateAndStartWorkers();
virtual void TerminateWorkers();
virtual void CreateTask(G4int id,G4int evts);
//Creates a concrete tbb::task with index id
//responsible for evts events
protected:
//Barriers mechanism for TBB is non existing
virtual void WaitForReadyWorkers() {}
virtual void WaitForEndEventLoopWorkers() {}
virtual void ThisWorkerReady() {}
virtual void ThisWorkerEndEventLoop() {}
virtual WorkerActionRequest ThisWorkerWaitForNextAction() { return UNDEFINED; }
virtual void NewActionRequest( WorkerActionRequest /*newRequest*/ ) {}
private:
tbb::task_list* theTasks;
G4int nEvtsPerTask;
};
#endif //TBBMASTERRUNMANAGER_HH
@@ -22,21 +22,27 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file PhysicsListEMstd.hh
/// @brief Define standard EM physics list
//
#ifndef TBBTASK_HH
#define TBBTASK_HH
#ifndef PHYSICS_LIST_EM_STD_H
#define PHYSICS_LIST_EM_STD_H
#include <tbb/task.h>
#include <tbb/concurrent_queue.h>
#include "G4Types.hh"
#include "G4VPhysicsConstructor.hh"
class G4Run;
class PhysicsListEMstd : public G4VPhysicsConstructor {
class tbbTask : public tbb::task {
public:
PhysicsListEMstd();
~PhysicsListEMstd();
virtual void ConstructParticle();
virtual void ConstructProcess();
tbbTask(G4int anId, tbb::concurrent_queue<const G4Run*>* output=0 , G4int nEvts = 1 );
virtual ~tbbTask();
tbb::task* execute();
private:
G4int nEvents;
G4int thisID;
tbb::concurrent_queue<const G4Run*>* output;
G4bool beamOnCondition;
};
#endif
#endif //TBBTASK_HH
@@ -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. *
// ********************************************************************
//
// Class Descrition:
// This class implements TBB specific worker initialization.
// It is a sub-class of G4UserWorkerThreadInitialization.
// Its role is to instantiate a tbbWorkerRunManager to be used by
// tbb tasks.
//
// Equivalent in traditional MT:
// G4UserWorkerThreadInitialization
//
// History:
// Oct 31st, 2013 A. Dotti - First Implementation
#ifndef TBBUSERWORKERINITIALIZATION_HH
#define TBBUSERWORKERINITIALIZATION_HH
#include "G4UserWorkerThreadInitialization.hh"
class tbbUserWorkerInitialization : public G4UserWorkerThreadInitialization {
public:
virtual ~tbbUserWorkerInitialization();
virtual G4WorkerRunManager* CreateWorkerRunManager() const;
virtual void JoinWorker(G4Thread*);
virtual G4Thread* CreateAndStartWorker(G4WorkerThread*);
};
#endif //TBBUSERWORKERINITIALIZATION_HH
@@ -0,0 +1,54 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// Class description:
//
// This class implements the worker model run manager for TBB based
// application.
// It is instantiated by tbbUserWorkerInitialization and used by
// tbbMasterRunManager.
// See G4WorkerRunManager for documentation of methods relative to
// base class. Only class specific methods are documented here.
//
// Equivalent in traditional MT:
// G4WorkerRunManager
//
// History:
// Oct 31st, 2013 A. Dotti - First Implementation
#ifndef TBBWORKERRUNMANAGER_HH
#define TBBWORKERRUNMANAGER_HH
#include "G4WorkerRunManager.hh"
class tbbWorkerRunManager : public G4WorkerRunManager {
public:
tbbWorkerRunManager();
virtual ~tbbWorkerRunManager();
virtual void ConstructScoringWorlds();
virtual void MergePartialResults();
};
#endif
@@ -0,0 +1,9 @@
# Macro file for the initialization phase of "exampleN03.cc"
# when running in interactive mode without visualization
#
# Set some default verbose
#
/control/verbose 2
/control/saveHistory
/run/verbose 2
#
@@ -0,0 +1,12 @@
# Macro file for the initialization phase of "exampleB2.cc"
# when running in interactive mode with visualization
#
# Set some default verbose
#
/control/verbose 2
/control/saveHistory
/run/verbose 2
#
# Visualization setting
/control/execute vis.mac
#
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

@@ -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. *
// ********************************************************************
//
// $Id: B2ActionInitialization.cc 68058 2013-03-13 14:47:43Z gcosmo $
//
/// \file B2ActionInitialization.cc
/// \brief Implementation of the B2ActionInitialization class
#include "B2ActionInitialization.hh"
#include "B2PrimaryGeneratorAction.hh"
#include "B2RunAction.hh"
#include "B2EventAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2ActionInitialization::B2ActionInitialization()
: G4VUserActionInitialization()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2ActionInitialization::~B2ActionInitialization()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2ActionInitialization::BuildForMaster() const
{
SetUserAction(new B2RunAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2ActionInitialization::Build() const
{
SetUserAction(new B2PrimaryGeneratorAction);
SetUserAction(new B2RunAction);
SetUserAction(new B2EventAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -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. *
// ********************************************************************
//
// $Id: B2EventAction.cc 69652 2013-05-10 09:05:11Z ihrivnac $
//
/// \file B2EventAction.cc
/// \brief Implementation of the B2EventAction class
#include "B2EventAction.hh"
#include "G4Event.hh"
#include "G4EventManager.hh"
#include "G4TrajectoryContainer.hh"
#include "G4Trajectory.hh"
#include "G4ios.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2EventAction::B2EventAction()
: G4UserEventAction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2EventAction::~B2EventAction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2EventAction::BeginOfEventAction(const G4Event*)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2EventAction::EndOfEventAction(const G4Event* event)
{
// get number of stored trajectories
G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
G4int n_trajectories = 0;
if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
// periodic printing
G4int eventID = event->GetEventID();
if ( eventID < 100 || eventID % 100 == 0) {
G4cout << ">>> Event: " << eventID << G4endl;
if ( trajectoryContainer ) {
G4cout << " " << n_trajectories
<< " trajectories stored in this event." << G4endl;
}
G4VHitsCollection* hc = event->GetHCofThisEvent()->GetHC(0);
G4cout << " "
<< hc->GetSize() << " hits stored in this event" << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,96 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: B2PrimaryGeneratorAction.cc 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2PrimaryGeneratorAction.cc
/// \brief Implementation of the B2PrimaryGeneratorAction class
#include "B2PrimaryGeneratorAction.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4SystemOfUnits.hh"
#include "Randomize.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2PrimaryGeneratorAction::B2PrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction()
{
G4int nofParticles = 1;
fParticleGun = new G4ParticleGun(nofParticles);
// default particle kinematic
G4ParticleDefinition* particleDefinition
= G4ParticleTable::GetParticleTable()->FindParticle("proton");
fParticleGun->SetParticleDefinition(particleDefinition);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fParticleGun->SetParticleEnergy(3.0*GeV);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2PrimaryGeneratorAction::~B2PrimaryGeneratorAction()
{
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
// This function is called at the begining of event
// In order to avoid dependence of PrimaryGeneratorAction
// on DetectorConstruction class we get world volume
// from G4LogicalVolumeStore.
G4double worldZHalfLength = 0;
G4LogicalVolume* worldLV
= G4LogicalVolumeStore::GetInstance()->GetVolume("World");
G4Box* worldBox = NULL;
if ( worldLV ) worldBox = dynamic_cast<G4Box*>(worldLV->GetSolid());
if ( worldBox ) worldZHalfLength = worldBox->GetZHalfLength();
else {
G4cerr << "World volume of box not found." << G4endl;
G4cerr << "Perhaps you have changed geometry." << G4endl;
G4cerr << "The gun will be place in the center." << G4endl;
}
fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength));
fParticleGun->GeneratePrimaryVertex(anEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -22,42 +22,42 @@
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
/// @file Particles.cc
/// @brief Define particles
//
// $Id: B2RunAction.cc 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2RunAction.cc
/// \brief Implementation of the B2RunAction class
#include "Particles.hh"
#include "B2RunAction.hh"
#include "G4LeptonConstructor.hh"
#include "G4BosonConstructor.hh"
#include "G4MesonConstructor.hh"
#include "G4BaryonConstructor.hh"
#include "G4ShortLivedConstructor.hh"
#include "G4IonConstructor.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
// --------------------------------------------------------------------------
Particles::Particles()
: G4VPhysicsConstructor("Particles")
{
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2RunAction::B2RunAction()
: G4UserRunAction()
{
// set printing event number per each 100 events
G4RunManager::GetRunManager()->SetPrintProgress(1000);
}
// --------------------------------------------------------------------------
Particles::~Particles()
{
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2RunAction::~B2RunAction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2RunAction::BeginOfRunAction(const G4Run*)
{
//inform the runManager to save random number seed
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
}
// --------------------------------------------------------------------------
void Particles::ConstructParticle()
{
G4LeptonConstructor::ConstructParticle();
G4BosonConstructor::ConstructParticle();
G4MesonConstructor::ConstructParticle();
G4BaryonConstructor::ConstructParticle();
G4ShortLivedConstructor::ConstructParticle();
G4IonConstructor::ConstructParticle();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
// --------------------------------------------------------------------------
void Particles::ConstructProcess()
{
}
void B2RunAction::EndOfRunAction(const G4Run* )
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,116 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: B2TrackerHit.cc 69505 2013-05-07 01:57:27Z asaim $
//
/// \file B2TrackerHit.cc
/// \brief Implementation of the B2TrackerHit class
#include "B2TrackerHit.hh"
#include "G4UnitsTable.hh"
#include "G4VVisManager.hh"
#include "G4Circle.hh"
#include "G4Colour.hh"
#include "G4VisAttributes.hh"
#include <iomanip>
G4ThreadLocal G4Allocator<B2TrackerHit>* B2TrackerHitAllocator=0;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2TrackerHit::B2TrackerHit()
: G4VHit(),
fTrackID(-1),
fChamberNb(-1),
fEdep(0.),
fPos(G4ThreeVector())
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2TrackerHit::~B2TrackerHit() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2TrackerHit::B2TrackerHit(const B2TrackerHit& right)
: G4VHit()
{
fTrackID = right.fTrackID;
fChamberNb = right.fChamberNb;
fEdep = right.fEdep;
fPos = right.fPos;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
const B2TrackerHit& B2TrackerHit::operator=(const B2TrackerHit& right)
{
fTrackID = right.fTrackID;
fChamberNb = right.fChamberNb;
fEdep = right.fEdep;
fPos = right.fPos;
return *this;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4int B2TrackerHit::operator==(const B2TrackerHit& right) const
{
return ( this == &right ) ? 1 : 0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2TrackerHit::Draw()
{
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
if(pVVisManager)
{
G4Circle circle(fPos);
circle.SetScreenSize(4.);
circle.SetFillStyle(G4Circle::filled);
G4Colour colour(1.,0.,0.);
G4VisAttributes attribs(colour);
circle.SetVisAttributes(attribs);
pVVisManager->Draw(circle);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2TrackerHit::Print()
{
G4cout
<< " trackID: " << fTrackID << " chamberNb: " << fChamberNb
<< "Edep: "
<< std::setw(7) << G4BestUnit(fEdep,"Energy")
<< " Position: "
<< std::setw(7) << G4BestUnit( fPos,"Length")
<< G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,106 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id: B2TrackerSD.cc 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2TrackerSD.cc
/// \brief Implementation of the B2TrackerSD class
#include "B2TrackerSD.hh"
#include "G4HCofThisEvent.hh"
#include "G4Step.hh"
#include "G4ThreeVector.hh"
#include "G4SDManager.hh"
#include "G4ios.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2TrackerSD::B2TrackerSD(const G4String& name,
const G4String& hitsCollectionName)
: G4VSensitiveDetector(name),
fHitsCollection(NULL)
{
collectionName.insert(hitsCollectionName);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2TrackerSD::~B2TrackerSD()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2TrackerSD::Initialize(G4HCofThisEvent* hce)
{
// Create hits collection
fHitsCollection
= new B2TrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
// Add this collection in hce
G4int hcID
= G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
hce->AddHitsCollection( hcID, fHitsCollection );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool B2TrackerSD::ProcessHits(G4Step* aStep,
G4TouchableHistory*)
{
// energy deposit
G4double edep = aStep->GetTotalEnergyDeposit();
if (edep==0.) return false;
B2TrackerHit* newHit = new B2TrackerHit();
newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle()
->GetCopyNumber());
newHit->SetEdep(edep);
newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
fHitsCollection->insert( newHit );
//newHit->Print();
return true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2TrackerSD::EndOfEvent(G4HCofThisEvent*)
{
if ( verboseLevel>1 ) {
G4int nofHits = fHitsCollection->entries();
G4cout << "\n-------->Hits Collection: in this event they are " << nofHits
<< " hits in the tracker chambers: " << G4endl;
for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,95 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
/// \file B2bChamberParameterisation.cc
/// \brief Implementation of the B2bChamberParameterisation class
#include "B2bChamberParameterisation.hh"
#include "G4VPhysicalVolume.hh"
#include "G4ThreeVector.hh"
#include "G4Tubs.hh"
#include "G4SystemOfUnits.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2bChamberParameterisation::B2bChamberParameterisation(
G4int noChambers,
G4double startZ, // Z of center of first
G4double spacingZ, // Z spacing of centers
G4double widthChamber,
G4double lengthInitial,
G4double lengthFinal )
: G4VPVParameterisation()
{
fNoChambers = noChambers;
fStartZ = startZ;
fHalfWidth = 0.5*widthChamber;
fSpacing = spacingZ;
fRmaxFirst = 0.5 * lengthInitial;
if( noChambers > 0 ){
fRmaxIncr = 0.5 * (lengthFinal-lengthInitial)/(noChambers-1);
if (spacingZ < widthChamber) {
G4Exception("B2bChamberParameterisation::B2bChamberParameterisation()",
"InvalidSetup", FatalException,
"Width>Spacing");
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2bChamberParameterisation::~B2bChamberParameterisation()
{ }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bChamberParameterisation::ComputeTransformation
(const G4int copyNo, G4VPhysicalVolume* physVol) const
{
// Note: copyNo will start with zero!
G4double Zposition = fStartZ + copyNo * fSpacing;
G4ThreeVector origin(0,0,Zposition);
physVol->SetTranslation(origin);
physVol->SetRotation(0);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bChamberParameterisation::ComputeDimensions
(G4Tubs& trackerChamber, const G4int copyNo, const G4VPhysicalVolume*) const
{
// Note: copyNo will start with zero!
G4double rmax = fRmaxFirst + copyNo * fRmaxIncr;
trackerChamber.SetInnerRadius(0);
trackerChamber.SetOuterRadius(rmax);
trackerChamber.SetZHalfLength(fHalfWidth);
trackerChamber.SetStartPhiAngle(0.*deg);
trackerChamber.SetDeltaPhiAngle(360.*deg);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,346 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
/// \file B2bDetectorConstruction.cc
/// \brief Implementation of the B2bDetectorConstruction class
#include "B2bDetectorConstruction.hh"
#include "B2bDetectorMessenger.hh"
#include "B2bChamberParameterisation.hh"
#include "B2TrackerSD.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4Tubs.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4PVParameterised.hh"
#include "G4GlobalMagFieldMessenger.hh"
#include "G4GeometryTolerance.hh"
#include "G4GeometryManager.hh"
#include "G4UserLimits.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4SystemOfUnits.hh"
//#include "G4ios.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ThreadLocal
G4GlobalMagFieldMessenger* B2bDetectorConstruction::fMagFieldMessenger = 0;
B2bDetectorConstruction::B2bDetectorConstruction()
:G4VUserDetectorConstruction(),
fLogicTarget(NULL), fLogicChamber(NULL),
fTargetMaterial(NULL), fChamberMaterial(NULL),
fStepLimit(NULL),
fCheckOverlaps(true)
{
fMessenger = new B2bDetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2bDetectorConstruction::~B2bDetectorConstruction()
{
delete fStepLimit;
delete fMessenger;
delete fMagFieldMessenger;
fMagFieldMessenger = 0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* B2bDetectorConstruction::Construct()
{
// Define materials
DefineMaterials();
// Define volumes
return DefineVolumes();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bDetectorConstruction::DefineMaterials()
{
// Material definition
G4NistManager* nistManager = G4NistManager::Instance();
// Air defined using NIST Manager
nistManager->FindOrBuildMaterial("G4_AIR");
// Lead defined using NIST Manager
fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
// Xenon gas defined using NIST Manager
fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
// Print materials
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* B2bDetectorConstruction::DefineVolumes()
{
G4Material* air = G4Material::GetMaterial("G4_AIR");
// Sizes of the principal geometrical components (solids)
G4int NbOfChambers = 5;
G4double chamberSpacing = 80*cm; // from chamber center to center!
G4double chamberWidth = 20.0*cm; // width of the chambers
G4double targetLength = 5.0*cm; // full length of Target
G4double trackerLength = (NbOfChambers+1)*chamberSpacing;
G4double worldLength = 1.2 * (2*targetLength + trackerLength);
G4double targetRadius = 0.5*targetLength; // Radius of Target
targetLength = 0.5*targetLength; // Half length of the Target
G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
// Definitions of Solids, Logical Volumes, Physical Volumes
// World
G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
G4cout << "Computed tolerance = "
<< G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm
<< " mm" << G4endl;
G4Box* worldS
= new G4Box("world", //its name
worldLength/2,worldLength/2,worldLength/2); //its size
G4LogicalVolume* worldLV
= new G4LogicalVolume(
worldS, //its solid
air, //its material
"World"); //its name
// Must place the World Physical volume unrotated at (0,0,0).
//
G4VPhysicalVolume* worldPV
= new G4PVPlacement(
0, // no rotation
G4ThreeVector(), // at (0,0,0)
worldLV, // its logical volume
"World", // its name
0, // its mother volume
false, // no boolean operations
0, // copy number
fCheckOverlaps); // checking overlaps
// Target
G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
G4Tubs* targetS
= new G4Tubs("target",0.,targetRadius,targetLength,0.*deg,360.*deg);
fLogicTarget
= new G4LogicalVolume(targetS, fTargetMaterial,"Target",0,0,0);
new G4PVPlacement(0, // no rotation
positionTarget, // at (x,y,z)
fLogicTarget, // its logical volume
"Target", // its name
worldLV, // its mother volume
false, // no boolean operations
0, // copy number
fCheckOverlaps); // checking overlaps
G4cout << "Target is " << 2*targetLength/cm << " cm of "
<< fTargetMaterial->GetName() << G4endl;
// Tracker
G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
G4Tubs* trackerS
= new G4Tubs("tracker",0,trackerSize,trackerSize, 0.*deg, 360.*deg);
G4LogicalVolume* trackerLV
= new G4LogicalVolume(trackerS, air, "Tracker",0,0,0);
new G4PVPlacement(0, // no rotation
positionTracker, // at (x,y,z)
trackerLV, // its logical volume
"Tracker", // its name
worldLV, // its mother volume
false, // no boolean operations
0, // copy number
fCheckOverlaps); // checking overlaps
// Tracker segments
// An example of Parameterised volumes
// Dummy values for G4Tubs -- modified by parameterised volume
G4Tubs* chamberS
= new G4Tubs("tracker",0, 100*cm, 100*cm, 0.*deg, 360.*deg);
fLogicChamber
= new G4LogicalVolume(chamberS,fChamberMaterial,"Chamber",0,0,0);
G4double firstPosition = -trackerSize + chamberSpacing;
G4double firstLength = trackerLength/10;
G4double lastLength = trackerLength;
G4VPVParameterisation* chamberParam =
new B2bChamberParameterisation(
NbOfChambers, // NoChambers
firstPosition, // Z of center of first
chamberSpacing, // Z spacing of centers
chamberWidth, // chamber width
firstLength, // initial length
lastLength); // final length
// dummy value : kZAxis -- modified by parameterised volume
new G4PVParameterised("Chamber", // their name
fLogicChamber, // their logical volume
trackerLV, // Mother logical volume
kZAxis, // Are placed along this axis
NbOfChambers, // Number of chambers
chamberParam, // The parametrisation
fCheckOverlaps); // checking overlaps
G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
<< "\nThe chambers are " << chamberWidth/cm << " cm of "
<< fChamberMaterial->GetName() << "\nThe distance between chamber is "
<< chamberSpacing/cm << " cm" << G4endl;
// Visualization attributes
G4VisAttributes* boxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
worldLV ->SetVisAttributes(boxVisAtt);
fLogicTarget ->SetVisAttributes(boxVisAtt);
trackerLV ->SetVisAttributes(boxVisAtt);
G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
fLogicChamber->SetVisAttributes(chamberVisAtt);
// Example of User Limits
//
// Below is an example of how to set tracking constraints in a given
// logical volume
//
// Sets a max step length in the tracker region, with G4StepLimiter
G4double maxStep = 0.5*chamberWidth;
fStepLimit = new G4UserLimits(maxStep);
trackerLV->SetUserLimits(fStepLimit);
/// Set additional contraints on the track, with G4UserSpecialCuts
///
/// G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
/// trackerLV->SetUserLimits(new G4UserLimits(maxStep,
/// maxLength,
/// maxTime,
/// minEkin));
// Always return the physical world
return worldPV;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bDetectorConstruction::ConstructSDandField()
{
// Sensitive detectors
G4String trackerChamberSDname = "B2/TrackerChamberSD";
B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname,
"TrackerHitsCollection");
SetSensitiveDetector( fLogicChamber, aTrackerSD );
// Create global magnetic field messenger.
// Uniform magnetic field is then created automatically if
// the field value is not zero.
G4ThreeVector fieldValue = G4ThreeVector();
fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
fMagFieldMessenger->SetVerboseLevel(1);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bDetectorConstruction::SetTargetMaterial(G4String materialName)
{
G4NistManager* nistManager = G4NistManager::Instance();
G4Material* pttoMaterial =
nistManager->FindOrBuildMaterial(materialName);
if (fTargetMaterial != pttoMaterial) {
if ( pttoMaterial ) {
fTargetMaterial = pttoMaterial;
if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
G4cout << "\n----> The target is made of " << materialName << G4endl;
} else {
G4cout << "\n--> WARNING from SetTargetMaterial : "
<< materialName << " not found" << G4endl;
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bDetectorConstruction::SetChamberMaterial(G4String materialName)
{
G4NistManager* nistManager = G4NistManager::Instance();
G4Material* pttoMaterial =
nistManager->FindOrBuildMaterial(materialName);
if (fChamberMaterial != pttoMaterial) {
if ( pttoMaterial ) {
fChamberMaterial = pttoMaterial;
if (fLogicChamber) fLogicChamber->SetMaterial(fChamberMaterial);
G4cout << "\n----> The chambers are made of " << materialName << G4endl;
} else {
G4cout << "\n--> WARNING from SetChamberMaterial : "
<< materialName << " not found" << G4endl;
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bDetectorConstruction::SetMaxStep(G4double maxStep)
{
if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,94 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
//
/// \file B2bDetectorMessenger.cc
/// \brief Implementation of the B2bDetectorMessenger class
#include "B2bDetectorMessenger.hh"
#include "B2bDetectorConstruction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2bDetectorMessenger::B2bDetectorMessenger(B2bDetectorConstruction* Det)
: G4UImessenger(),
fDetectorConstruction(Det)
{
fB2Directory = new G4UIdirectory("/B2/");
fB2Directory->SetGuidance("UI commands specific to this example.");
fDetDirectory = new G4UIdirectory("/B2/det/");
fDetDirectory->SetGuidance("Detector construction control");
fTargMatCmd = new G4UIcmdWithAString("/B2/det/setTargetMaterial",this);
fTargMatCmd->SetGuidance("Select Material of the Target.");
fTargMatCmd->SetParameterName("choice",false);
fTargMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fChamMatCmd = new G4UIcmdWithAString("/B2/det/setChamberMaterial",this);
fChamMatCmd->SetGuidance("Select Material of the Chamber.");
fChamMatCmd->SetParameterName("choice",false);
fChamMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fStepMaxCmd = new G4UIcmdWithADoubleAndUnit("/B2/det/stepMax",this);
fStepMaxCmd->SetGuidance("Define a step max");
fStepMaxCmd->SetParameterName("stepMax",false);
fStepMaxCmd->SetUnitCategory("Length");
fStepMaxCmd->AvailableForStates(G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2bDetectorMessenger::~B2bDetectorMessenger()
{
delete fTargMatCmd;
delete fChamMatCmd;
delete fStepMaxCmd;
delete fB2Directory;
delete fDetDirectory;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B2bDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
if( command == fTargMatCmd )
{ fDetectorConstruction->SetTargetMaterial(newValue);}
if( command == fChamMatCmd )
{ fDetectorConstruction->SetChamberMaterial(newValue);}
if( command == fStepMaxCmd ) {
fDetectorConstruction
->SetMaxStep(fStepMaxCmd->GetNewDoubleValue(newValue));
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,86 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// Class description:
//
// This class implements the worker model run manager for TBB based
// application.
// It is instantiated by tbbUserWorkerInitialization and used by
// tbbMasterRunManager.
// See G4WorkerRunManager for documentation of methods relative to
// base class. Only class specific methods are documented here.
//
// Equivalent in traditional MT:
// G4WorkerRunManager
//
// History:
// Oct 31st, 2013 A. Dotti - First Implementation
#include "tbbMasterRunManager.hh"
#include "tbbTask.hh"
tbbMasterRunManager::tbbMasterRunManager() :
G4MTRunManager(),
theTasks(static_cast<tbb::task_list*>(0)),
nEvtsPerTask(1)
{
}
tbbMasterRunManager::~tbbMasterRunManager()
{
}
void tbbMasterRunManager::TerminateWorkers()
{
//For TBB based example this should be empty
}
void tbbMasterRunManager::CreateAndStartWorkers()
{
//Instead of pthread based workers, create tbbTask
G4int ntasks = numberOfEventToBeProcessed/nEvtsPerTask;
G4int remn = numberOfEventToBeProcessed % nEvtsPerTask;
for ( G4int nt = 0 ; nt < ntasks ; ++nt )
{
G4int evts= nEvtsPerTask;
if ( nt == ntasks - 1 ) evts+=remn;
CreateTask(nt,evts);
}
}
void tbbMasterRunManager::CreateTask(G4int id,G4int evts)
{
tbbTask& task = * new(tbb::task::allocate_root())
tbbTask( id , NULL , evts ); //Add output for merging
theTasks->push_back( task );
}
void tbbMasterRunManager::RunTermination()
{
// Reduce results ....
G4MTRunManager::RunTermination();
}

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