Commit 15047a5d authored by MARCOS ANTONIO DE OLIVEIRA DEROS's avatar MARCOS ANTONIO DE OLIVEIRA DEROS
Browse files

Initial commit

parents
///\file "B1/.README.txt"
///\brief Example B1 README page
/*! \page ExampleB1 Example B1
This example demonstrates a very simple application where an energy
deposit is accounted in user actions and their associated objects
and a dose in a selected volume is calculated.
\section B1_s1 GEOMETRY DEFINITION
The geometry is constructed in the B1DetectorConstruction class.
The setup consists of a an envelope of box shape containing two
volumes: a spherical cone and a trapezoid.
In this example we use some common materials materials for medical
applications. The envelope is made of water and the two inner volumes
are made from tissue and bone materials.
The materials are created with the help of the G4NistManager class,
which allows to build a material from the NIST database using their
names. Available materials and their compositions can be found in
<a href="http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides
/ForApplicationDeveloper/html/apas10.html">
the Geant4 User's Guide for Application Developers, Appendix 10:
Geant4 Materials Database
</a>.
\section B1_s2 PHYSICS LIST
The particle's type and the physic processes which will be available
in this example are set in the QBBC physics list. This physics list
requires data files for electromagnetic and hadronic processes.
See more on installation of the datasets in
<a href="http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides
/InstallationGuide/html/ch03s03.html">
Geant4 Installation Guide, Chapter 3.3: Note On Geant4 Datasets </a>.
The following datasets: G4LEDATA, G4LEVELGAMMADATA, G4NEUTRONXSDATA,
G4SAIDXSDATA and G4ENSDFSTATEDATA are mandatory for this example.
In addition the build-in interactive command:
\verbatim
/process/(in)activate processName
\endverbatim
allows to activate/inactivate the processes one by one.
\section B1_s3 ACTION INITALIZATION
A newly introduced class, B1ActionInitialization, instantiates and registers
to Geant4 kernel all user action classes.
While in sequential mode the action classes are instatiated just once,
via invoking the method:
B1ActionInitialization::Build()
in multi-threading mode the same method is invoked for each thread worker
and so all user action classes are defined thread-local.
A run action class is instantiated both thread-local
and global that's why its instance is created also in the method
B1ActionInitialization::BuildForMaster()
which is invoked only in multi-threading mode.
\section B1_s4 PRIMARY GENERATOR
The primary generator is defined in the B1PrimaryGeneratorAction class.
The default kinematics is a 6 MeV gamma, randomly distributed in front
of the envelope across 80% of the transverse (X,Y) envelope size.
This default setting can be changed via the Geant4 built-in commands
of the G4ParticleGun class.
\section B1_s5 DETECTOR RESPONSE
This example demonstrates a simple scoring implemented directly
in the user action classes. Alternative ways of scoring via Geant4 classes
can be found in the other examples.
The energy deposited is collected step by step for a selected volume
in B1SteppingAction and accumulated event by event in B1EventAction.
At end of event, the value acummulated in B1EventAction is added in B1RunAction
and summed over the whole run (see B1EventAction::EndOfevent()).
Total dose deposited is computed at B1RunAction::EndOfRunAction(),
and printed together with informations about the primary particle.
In multi-threading mode the energy accumulated in G4Accumulable objects per
workers is merged to the master in B1RunAction::EndOfRunAction() and the final
result is printed on the screen.
G4Accumulable<G4double> type instead of G4double type is used for the B1RunAction
data members in order to facilitate merging of the values accumulated on workers
to the master. Currently the accumulables have to be registered to G4AccumulablesManager
and G4AccumulablesManager::Merge() has to be called from the users code. This is planned
to be further simplified with a closer integration of G4Accumulable classes in
the Geant4 kernel next year.
An example of creating and computing new units (e.g., dose) is also shown
in the class constructor.
<hr>
The following paragraphs are common to all basic examples
\section B1_A VISUALISATION
The visualization manager is set via the G4VisExecutive class
in the main() function in exampleB1.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 function when the example is used in interactive running mode.
By default, vis.mac opens an OpenGL viewer (/vis/open OGL).
The user can change the initial viewer by commenting out this line
and instead uncommenting one of the other /vis/open statements, such as
HepRepFile or DAWNFILE (which produce files that can be viewed with the
HepRApp and DAWN viewers, respectively). Note that one can always
open new viewers at any time from the command line. For example, if
you already have a view in, say, an OpenGL window with a name
"viewer-0", then
\verbatim
/vis/open DAWNFILE
\endverbatim
then to get the same view
\verbatim
/vis/viewer/copyView viewer-0
\endverbatim
or to get the same view *plus* scene-modifications
\verbatim
/vis/viewer/set/all viewer-0
\endverbatim
then to see the result
\verbatim
/vis/viewer/flush
\endverbatim
The DAWNFILE, HepRepFile drivers are always available
(since they require no external libraries), but the OGL driver requires
that the Geant4 libraries have been built with the OpenGL option.
From Release 9.6 the vis.mac macro in example B1 has additional commands
that demonstrate additional functionality of the vis system, such as
displaying text, axes, scales, date, logo and shows how to change
viewpoint and style. Consider copying these to other examples or
your application. To see even more commands use help or
ls or browse the available UI commands in the Application
Developers Guide, Section 7.1.
For more information on visualization, including information on how to
install and run DAWN, OpenGL and HepRApp, see the visualization tutorials,
for example,\n
- <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4OpenGLTutorial/G4OpenGLTutorial.html">
OpenGL Tutorial </a>
- <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4DAWNTutorial/G4DAWNTutorial.html">
DAWN Tutorial </a>
- <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4HepRAppTutorial/G4HepRAppTutorial.html">
HepRApp Tutorial </a>
The tracks are automatically drawn at the end of each event, accumulated
for all events and erased at the beginning of the next run.
\section B1_B USER INTERFACES
The user command interface is set via the G4UIExecutive class
in the main() function in exampleB1.cc
The selection of the user command interface is then done automatically
according to the Geant4 configuration or it can be done explicitly via
the third argument of the G4UIExecutive constructor (see exampleB4a.cc).
\section B1_C HOW TO RUN
- Execute exampleB1 in the 'interactive mode' with visualization
\verbatim
% exampleB1
and type in the commands from run1.mac line by line:
Idle> /control/verbose 2
Idle> /tracking/verbose 1
Idle> /run/beamOn 10
Idle> ...
Idle> exit
\endverbatim
or
\verbatim
Idle> /control/execute run1.mac
....
Idle> exit
\endverbatim
- Execute exampleB1 in the 'batch' mode from macro files
(without visualization)
\verbatim
% exampleB1 run2.mac
% exampleB1 exampleB1.in > exampleB1.out
\endverbatim
*/
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(B1)
#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
find_package(Geant4 REQUIRED ui_all vis_all)
else()
find_package(Geant4 REQUIRED)
endif()
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
# Setup include directory for this project
#
include(${Geant4_USE_FILE})
include_directories(${PROJECT_SOURCE_DIR}/include)
#----------------------------------------------------------------------------
# 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(exampleB1 exampleB1.cc ${sources} ${headers})
target_link_libraries(exampleB1 ${Geant4_LIBRARIES})
#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build B1. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.
#
set(EXAMPLEB1_SCRIPTS
exampleB1.in
exampleB1.out
init_vis.mac
run1.mac
run2.mac
vis.mac
)
foreach(_script ${EXAMPLEB1_SCRIPTS})
configure_file(
${PROJECT_SOURCE_DIR}/${_script}
${PROJECT_BINARY_DIR}/${_script}
COPYONLY
)
endforeach()
#----------------------------------------------------------------------------
# For internal Geant4 use - but has no effect if you build this
# example standalone
#
add_custom_target(B1 DEPENDS exampleB1)
#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS exampleB1 DESTINATION bin)
# --------------------------------------------------------------
# GNUmakefile for examples module. Gabriele Cosmo, 06/04/98.
# --------------------------------------------------------------
name := exampleB1
G4TARGET := $(name)
G4EXLIB := true
ifndef G4INSTALL
G4INSTALL = ../../..
endif
.PHONY: all
all: lib bin
include $(G4INSTALL)/config/binmake.gmk
visclean:
rm -f g4*.prim g4*.eps g4*.wrl
rm -f .DAWN_*
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
Example B1 History file
-----------------------
This file should be used by the G4 example coordinator to briefly
summarize all major modifications introduced in the code and keep
track of all tags.
----------------------------------------------------------
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
26/09/16 I. Hrivnacova (exampleB1-V10-02-01)
- Updated for renaming G4Parameter in G4Accumulable
20/09/16 J. Allison (exampleB1-V10-02-00)
- vis.mac: Added this to make "Envelope" transparent blue:
# "Envelope" is transparent blue to represent water
/vis/geometry/set/colour Envelope 0 0 0 1 .3
02/11/15 I. Hrivnacova (exampleB1-V10-01-03)
- B1Run class replaced with a code based on G4Parameter
04/05/15 I. Hrivnacova (exampleB1-V10-01-02)
- Coding guidelines: removed empty lines
23/04/15 mma (exampleB1-V10-01-01)
- RunAction : come back to previous formula
21/04/15 mma (exampleB1-V10-01-00)
- RunAction : correct calculation of rmsEdep
29/11/14 I. Hrivnacova
- Use G4endl instead of \n in G4cout;
this makes each new line in the output on threads preceded with
G4WTN >
06/11/14 I. Hrivnacova
- Removed G4UI_USE/G4VIS_USE tests and init.mac macro (not needed)
- Moved G4UIExecutive at the beginning of main() in all examples
- Perform run initialization in macros instead of main()
28/10/13 I. Hrivnacova (exampleB1-V09-06-06)
- Removed SetNumberOfThreads(4) from main (use Geant4 default)
26/10/13 mma (exampleB1-V09-06-05)
- Use /run/printProgress. Cleanup in EventAction
08/10/13 I. Hrivnacova (exampleB1-V09-06-04)
- Removed B1EventInformation for keeping maximum simplicity
- Improved documentation (added paragraph on Run::Merge())
- Code clean-up
09/06/13 I. Hrivnacova (exampleB1-V09-06-03)
- clarify local names in user actions
05/06/13 mma (exampleB1-V09-06-02)
- add section about ACTION INITALIZATION to README and .README
- update section DETECTOR RESPONSE
05/05/13 I. Hrivnacova (exampleB1-V09-06-01)
- Migration for MT (by Makoto):
Added B1ActionInitialization, B1EventInformation and B1Run classes
and updated actions classes accordingly.
README files still need to be updated.
15/01/13 I. Hrivnacova (exampleB1-V09-06-00)
- Tag for a test only (g4svn update with svn 1.7.x)
13/11/12 I. Hrivnacova (exampleB1-V09-05-03)
- Use QBBC physics list instead of QGSP_BIC_EMY, which becomes
obsolete
02/11/12 J. Allison (exampleB1-V09-05-01 and 02)
- README: Improved.
02/11/12 J. Allison (exampleB1-V09-05-00)
- vis.mac: Improved view and added text, scale, logo etc. to scene.
14/11/11 I. Hrivnacova
- The first tagged version of the new B1 example
(tagged in basic)
31/10/11 I. Hrivnacova
- change volume names
- scoring in 1 volume only, with new scheme
05/09/11 M. Maire, P. Gueye
- Created.
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
Example B1
-----------
This example demonstrates a very simple application where an energy
deposit is accounted in user actions and their associated objects
and a dose in a selected volume is calculated.
1- GEOMETRY DEFINITION
The geometry is constructed in the B1DetectorConstruction class.
The setup consists of a an envelope of box shape containing two
volumes: a spherical cone and a trapezoid.
In this example we use some common materials materials for medical
applications. The envelope is made of water and the two inner volumes
are made from tissue and bone materials.
The materials are created with the help of the G4NistManager class,
which allows to build a material from the NIST database using their
names. All available materials can be found in the Geant4 User's Guide
for Application Developers, Appendix 10: Geant4 Materials Database.
2- PHYSICS LIST
The particle's type and the physic processes which will be available
in this example are set in the QBBC physics list. This physics list
requires data files for electromagnetic and hadronic processes.
See more on installation of the datasets in Geant4 Installation Guide,
Chapter 3.3: Note On Geant4 Datasets:
http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides
/InstallationGuide/html/ch03s03.html
The following datasets: G4LEDATA, G4LEVELGAMMADATA, G4NEUTRONXSDATA,
G4SAIDXSDATA and G4ENSDFSTATEDATA are mandatory for this example.
In addition the build-in interactive command:
/process/(in)activate processName
allows to activate/inactivate the processes one by one.
3- ACTION INITALIZATION
A newly introduced class, B1ActionInitialization, instantiates and registers
to Geant4 kernel all user action classes.
While in sequential mode the action classes are instatiated just once,
via invoking the method:
B1ActionInitialization::Build()
in multi-threading mode the same method is invoked for each thread worker
and so all user action classes are defined thread-local.
A run action class is instantiated both thread-local
and global that's why its instance is created also in the method
B1ActionInitialization::BuildForMaster()
which is invoked only in multi-threading mode.
4- PRIMARY GENERATOR
The primary generator is defined in the B1PrimaryGeneratorAction class.
The default kinematics is a 6 MeV gamma, randomly distributed in front
of the envelope across 80% of the transverse (X,Y) envelope size.
This default setting can be changed via the Geant4 built-in commands
of the G4ParticleGun class.
5- DETECTOR RESPONSE
This example demonstrates a simple scoring implemented directly
in the user action classes. Alternative ways of scoring via Geant4 classes
can be found in the other examples.
The energy deposited is collected step by step for a selected volume
in B1SteppingAction and accumulated event by event in B1EventAction.
At end of event, the value acummulated in B1EventAction is added in B1RunAction
and summed over the whole run (see B1EventAction::EndOfevent()).
Total dose deposited is computed at B1RunAction::EndOfRunAction(),
and printed together with informations about the primary particle.
In multi-threading mode the energy accumulated in G4Accumulable objects per
workers is merged to the master in B1RunAction::EndOfRunAction() and the final
result is printed on the screen.
G4Parameter<G4double> type instead of G4double type is used for the B1RunAction
data members in order to facilitate merging of the values accumulated on workers
to the master. Currently the accumulables have to be registered to G4AccumulablesManager
and G4AccumulablesManager::Merge() has to be called from the users code. This is planned
to be further simplified with a closer integration of G4Accumulable classes in
the Geant4 kernel next year.
An example of creating and computing new units (e.g., dose) is also shown
in the class constructor.
The following paragraphs are common to all basic examples
A- VISUALISATION
The visualization manager is set via the G4VisExecutive class
in the main() function in exampleB1.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 function when the example is used in interactive running mode.
By default, vis.mac opens an OpenGL viewer (/vis/open OGL).
The user can change the initial viewer by commenting out this line
and instead uncommenting one of the other /vis/open statements, such as
HepRepFile or DAWNFILE (which produce files that can be viewed with the
HepRApp and DAWN viewers, respectively). Note that one can always
open new viewers at any time from the command line. For example, if
you already have a view in, say, an OpenGL window with a name
"viewer-0", then
/vis/open DAWNFILE
then to get the same view
/vis/viewer/copyView viewer-0
or to get the same view *plus* scene-modifications
/vis/viewer/set/all viewer-0
then to see the result
/vis/viewer/flush
The DAWNFILE, HepRepFile drivers are always available
(since they require no external libraries), but the OGL driver requires
that the Geant4 libraries have been built with the OpenGL option.
From Release 9.6 the vis.mac macro in example B1 has additional commands
that demonstrate additional functionality of the vis system, such as
displaying text, axes, scales, date, logo and shows how to change
viewpoint and style. Consider copying these to other examples or
your application. To see even more commands use help or
ls or browse the available UI commands in the Application
Developers Guide, Section 7.1.
For more information on visualization, including information on how to
install and run DAWN, OpenGL and HepRApp, see the visualization tutorials,
for example,
http://geant4.slac.stanford.edu/Presentations/vis/G4[VIS]Tutorial/G4[VIS]Tutorial.html
(where [VIS] can be replaced by DAWN, OpenGL and HepRApp)
The tracks are automatically drawn at the end of each event, accumulated
for all events and erased at the beginning of the next run.
B- USER INTERFACES
The user command interface is set via the G4UIExecutive class
in the main() function in exampleB1.cc
The selection of the user command interface is then done automatically
according to the Geant4 configuration or it can be done explicitly via
the third argument of the G4UIExecutive constructor (see exampleB4a.cc).
C- HOW TO RUN
- Execute exampleB1 in the 'interactive mode' with visualization:
% ./exampleB1
and type in the commands from run1.mac line by line:
Idle> /control/verbose 2
Idle> /tracking/verbose 1
Idle> /run/beamOn 10
Idle> ...
Idle> exit
or
Idle> /control/execute run1.mac
....
Idle> exit
- Execute exampleB1 in the 'batch' mode from macro files
(without visualization)
% ./exampleB1 run2.mac
% ./exampleB1 exampleB1.in > exampleB1.out
//
// ********************************************************************
// * 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 exampleB1.cc
/// \brief Main program of the B1 example
#include "B1DetectorConstruction.hh"
#include "B1ActionInitialization.hh"
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
#include "QBBC.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "Randomize.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
int main(int argc,char** argv)
{
// Detect interactive mode (if no arguments) and define UI session
//
G4UIExecutive* ui = 0;
if ( argc == 1 ) {
ui = new G4UIExecutive(argc, argv);
}
// Choose the Random engine
G4Random::setTheEngine(new CLHEP::RanecuEngine);
// Construct the default run manager
//
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager;
#else
G4RunManager* runManager = new G4RunManager;
#endif
// Set mandatory initialization classes
//
// Detector construction
runManager->SetUserInitialization(new B1DetectorConstruction());
// Physics list
G4VModularPhysicsList* physicsList = new QBBC;
physicsList->SetVerboseLevel(1);
runManager->SetUserInitialization(physicsList);
// User action initialization
runManager->SetUserInitialization(new B1ActionInitialization());
// Initialize visualization
//
G4VisManager* visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
// Process macro or start UI session
//
if ( ! ui ) {
// batch mode
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);
}
else {
// interactive mode
UImanager->ApplyCommand("/control/execute init_vis.mac");
ui->SessionStart();
delete ui;
}
// Job termination