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
+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
@@ -0,0 +1,48 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#ifndef TBBTASK_HH
#define TBBTASK_HH
#include <tbb/task.h>
#include <tbb/concurrent_queue.h>
#include "G4Types.hh"
class G4Run;
class tbbTask : public tbb::task {
public:
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 //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......
@@ -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: B2RunAction.cc 66536 2012-12-19 14:32:36Z ihrivnac $
//
/// \file B2RunAction.cc
/// \brief Implementation of the B2RunAction class
#include "B2RunAction.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B2RunAction::B2RunAction()
: G4UserRunAction()
{
// set printing event number per each 100 events
G4RunManager::GetRunManager()->SetPrintProgress(1000);
}
//....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);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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();
}
@@ -0,0 +1,233 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "tbbTask.hh"
#include "tbbWorkerRunManager.hh"
#include "G4Threading.hh"
#include "G4String.hh"
#include "G4WorkerRunManager.hh"
#include "G4MTRunManager.hh"
#include "G4UImanager.hh"
#include "G4UserWorkerThreadInitialization.hh"
#include "G4WorkerThread.hh"
#include "G4MTRunManagerKernel.hh"
#include "G4AutoLock.hh"
#include "G4UserWorkerInitialization.hh"
#include "G4VUserActionInitialization.hh"
//Equivalent to G4MTRunManagerKernel::StartThread
tbbTask::tbbTask(G4int anId,
tbb::concurrent_queue<const G4Run*>* out,
G4int nevts)
: nEvents(nevts),
thisID(anId),
output(out),
beamOnCondition(false)
{
}
tbbTask::~tbbTask()
{
}
#include <tbb/atomic.h>
namespace {
tbb::atomic<int> counter;
}
tbb::task* tbbTask::execute()
{
// In tbb we do not have anymore the concept of thread:
// tasks run "somewhere"; but there is no control over where.
// This somewhere is a thread, created, controlled and 'switched'
// to our task by the TBB runtime system.
//
// The "pedantic" way to proceed is: recreate the "context"
// from scratch every time (context=local run manager,
// geometry, etc)
// This would be a clear waste of resources: there is no
// need to initialize multiple times, when the same thread
// is used several times, ie for several tasks.
// In the current version to avoid this we initialize only
// i) the first time we run on each thread, and
// ii) at the start of a new run on each thread (reinitialization).
// We are confident that this works because TBB co-works with TLS.
// In addition this ensures that minimal changes needed to G4 code base.
//
// Note 1: that this "thread" is responsible for 1 or more TBB task,
// e.g. at least one event.
// Note 2: In this first example, we do not care about memory usage:
// The resources required depend only on the total number of
// threads used for at least one event during the simulation.
// Note 3: It is possible to do better - this is left for another example.
// Here is a sketch how:
// If there is a set maximum <N> threads which will be doing
// simulation at any point, and that this is smaller than the
// number of TBB tasks which can run simulataneously.
// What would need to be done is to "acquire" a resource (workspace)
// which holds all the memory required for a running task/thread,
// and release it at the end of the task to be re-used by other tasks
// possibly on different threads. This is demonstrated in another
// example.
static G4ThreadLocal tbbWorkerRunManager* localRM = 0;
//Is this task running for the first time?
//How to re-initialize between runs????
if (! localRM ) {
//It's a new thread, basically repeat what is being done in
//G4MTRunManagerKernel::StarThread with an
//important difference, do not process data or wait for master to
//communicate what to do, it will
//not happen!
G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
//============================
//Step-0: Thread ID
//============================
//Initliazie per-thread stream-output
//The following line is needed before we actually do I/O initialization
//because the constructor of UI manager resets the I/O destination.
G4int thisId = counter.fetch_and_increment();
G4Threading::G4SetThreadId( thisId );
G4UImanager::GetUIpointer()->SetUpForAThread( thisId );
//============================
//Step-1: Random number engine
//============================
//RNG Engine needs to be initialized by "cloning" the master one.
const CLHEP::HepRandomEngine* masterEngine =
masterRM->getMasterRandomEngine();
masterRM->GetUserWorkerThreadInitialization()->SetupRNGEngine(masterEngine);
//============================
//Step-2: Initialize worker thread
//============================
if(masterRM->GetUserWorkerInitialization())
masterRM->GetUserWorkerInitialization()->WorkerInitialize();
if(masterRM->GetUserActionInitialization()) {
G4VSteppingVerbose* sv =
masterRM->GetUserActionInitialization()->InitializeSteppingVerbose();
if (sv) G4VSteppingVerbose::SetInstance(sv);
}
//Now initialize worker part of shared objects (geometry/physics)
G4WorkerThread::BuildGeometryAndPhysicsVector();
localRM = static_cast<tbbWorkerRunManager*>(
masterRM->GetUserWorkerThreadInitialization()->CreateWorkerRunManager()
);
G4cout<<localRM<<G4endl;
//localRM->SetWorkerThread(wThreadContext);
// G4AutoLock wrmm(&workerRMMutex);
// G4MTRunManagerKernel::workerRMvector->push_back(localRM); //<<<<?????? ANDREA TBB
// wrmm.unlock();
//================================
//Step-3: Setup worker run manager
//================================
// Set the detector and physics list to the worker thread. Share with master
const G4VUserDetectorConstruction* detector =
masterRM->GetUserDetectorConstruction();
localRM->G4RunManager::SetUserInitialization(
const_cast<G4VUserDetectorConstruction*>(detector));
const G4VUserPhysicsList* physicslist = masterRM->GetUserPhysicsList();
localRM->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
//================================
//Step-4: Initialize worker run manager
//================================
if(masterRM->GetUserActionInitialization())
{ masterRM->GetNonConstUserActionInitialization()->Build(); }
if(masterRM->GetUserWorkerInitialization())
{ masterRM->GetUserWorkerInitialization()->WorkerStart(); }
localRM->Initialize();
//Problem at this point is if there is more than one run...
// Execute UI commands stored in the masther UI manager
std::vector<G4String> cmds = masterRM->GetCommandStack();
G4UImanager* uimgr = G4UImanager::GetUIpointer(); //TLS instance
std::vector<G4String>::const_iterator it = cmds.begin();
for(;it!=cmds.end();it++)
{ uimgr->ApplyCommand(*it); }
//Start this run
G4String macroFile = masterRM->GetSelectMacro();
G4int numSelect = masterRM->GetNumberOfSelectEvents();
if ( macroFile == "" || macroFile == " " )
{
localRM->BeamOn(nEvents,0,numSelect);
}
else
{
localRM->BeamOn(nEvents,macroFile,numSelect);
}
//======= NEW TBB SPECIFIC ===========
//Step-5: Initialize and start run
//====================================
// bla-bla-bla-bla
// This is basically BeamOn
beamOnCondition = localRM->ConfirmBeamOnCondition();
if (beamOnCondition) {
localRM->SetNumberOfEventsToBeProcessed( nEvents );
localRM->ConstructScoringWorlds();
localRM->RunInitialization();
//Register this G4Run in output
//Note: the idea is that we are going to accumulate everything in
//G4Run or derived class. We let the kernel know this is the object
//where the output is accumulated for the tbb::tasks that run on
//this thread.
if ( output ) {}
}
}
assert(localRM!=0);
if ( beamOnCondition ) {
localRM->DoEventLoop( nEvents );
//localRM->RunTermination(); //<<<< How to call this??? ANDREA TBB
}
//Cannot be done here since thread can be re-used by other task
//===============================
//Step-6: Terminate worker thread
//===============================
// if(masterRM->GetUserWorkerInitialization())
// { masterRM->GetUserWorkerInitialization()->WorkerStop(); }
// wrmm.lock();
// std::vector<G4WorkerRunManager*>::iterator itrWrm = workerRMvector->begin();
// for(;itrWrm!=workerRMvector->end();itrWrm++)
// {
// if((*itrWrm)==wrm)
// {
// workerRMvector->erase(itrWrm);
// break;
// }
// }
// wrmm.unlock();
// wThreadContext->DestroyGeometryAndPhysicsVector();
// wThreadContext = 0;
return static_cast<tbb::task*>(NULL);
}
@@ -0,0 +1,48 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "tbbUserWorkerInitialization.hh"
#include "G4Threading.hh"
#include "tbbWorkerRunManager.hh"
tbbUserWorkerInitialization::~tbbUserWorkerInitialization()
{}
void tbbUserWorkerInitialization::JoinWorker(G4Thread*)
{
//Not needed for TBB
}
G4Thread* tbbUserWorkerInitialization::CreateAndStartWorker(G4WorkerThread*)
{
//Not needed for TBB
return static_cast<G4Thread*>(0);
}
G4WorkerRunManager* tbbUserWorkerInitialization::CreateWorkerRunManager() const
{
return new tbbWorkerRunManager();
}
@@ -0,0 +1,49 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
#include "tbbWorkerRunManager.hh"
#include "G4Run.hh"
#include "G4MTRunManager.hh"
#include "G4UserWorkerInitialization.hh"
#include "G4UserRunAction.hh"
#include "G4SDManager.hh"
tbbWorkerRunManager::tbbWorkerRunManager() :
G4WorkerRunManager()
{}
tbbWorkerRunManager::~tbbWorkerRunManager()
{}
void tbbWorkerRunManager::MergePartialResults()
{
//TBB ??????
}
void tbbWorkerRunManager::ConstructScoringWorlds()
{
//Forward call to protected method, that's all
G4WorkerRunManager::ConstructScoringWorlds();
}
@@ -0,0 +1,16 @@
# Macro file for example B2
#
# Can be run in batch, without graphic
# or interactively: Idle> /control/execute run1.mac
#
# Default kinematics:
# proton 3 GeV in direction (0.,0.,1.)
#
#
# set target and chamber material
#
/B2/det/setTargetMaterial G4_WATER
/B2/det/setChamberMaterial G4_Ar
/globalField/verbose 1
/globalField/setValue 0.2 0 0 tesla
/run/beamOn 10000
@@ -0,0 +1,82 @@
# Macro file for the visualization setting for the initialization phase
# of the B2 example when running in interactive mode
#
# Use these open statements to open selected visualization
#
# Use this open statement to create an OpenGL view:
/vis/open OGL 600x600-0+0
#
# Use this open statement to create an OpenInventor view:
#/vis/open OIX
#
# Use this open statement to create a .prim file suitable for
# viewing in DAWN:
#/vis/open DAWNFILE
#
# Use this open statement to create a .heprep file suitable for
# viewing in HepRApp:
#/vis/open HepRepFile
#
# Use this open statement to create a .wrl file suitable for
# viewing in a VRML viewer:
#/vis/open VRML2FILE
#
# Disable auto refresh and quieten vis messages whilst scene and
# trajectories are established:
/vis/viewer/set/autoRefresh false
/vis/verbose errors
#
# Draw geometry:
/vis/drawVolume
#
# Specify view angle:
/vis/viewer/set/viewpointThetaPhi 90. 180.
#
# Specify zoom value:
/vis/viewer/zoom 1.4
#
# Specify style (surface, wireframe, auxiliary edges,...)
#/vis/viewer/set/style wireframe
#/vis/viewer/set/auxiliaryEdge true
#/vis/viewer/set/lineSegmentsPerCircle 100
#
# Draw coordinate axes:
#/vis/scene/add/axes 0 0 0 1 m
#
# Draw smooth trajectories at end of event, showing trajectory points
# as markers 2 pixels wide:
/vis/scene/add/trajectories smooth
/vis/modeling/trajectories/create/drawByCharge
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2
# (if too many tracks cause core dump => /tracking/storeTrajectory 0)
#
# Draw hits at end of event:
/vis/scene/add/hits
#
# To draw only gammas:
#/vis/filtering/trajectories/create/particleFilter
#/vis/filtering/trajectories/particleFilter-0/add gamma
#
# To invert the above, drawing all particles except gammas,
# keep the above two lines but also add:
#/vis/filtering/trajectories/particleFilter-0/invert true
#
# Many other options are available with /vis/modeling and /vis/filtering.
# For example, to select colour by particle ID:
#/vis/modeling/trajectories/create/drawByParticleID
#/vis/modeling/trajectories/drawByParticleID-0/default/setDrawStepPts true
# To select or override default colours (note: e+ is blue by default):
#/vis/modeling/trajectories/list
#/vis/modeling/trajectories/drawByParticleID-0/set e+ yellow
#
# To superimpose all of the events from a given run:
/vis/scene/endOfEventAction accumulate
#
# Re-establish auto refreshing and verbosity:
/vis/viewer/set/autoRefresh true
/vis/verbose warnings
#
# For file-based drivers, use this to create an empty detector view:
#/vis/viewer/flush
@@ -0,0 +1,8 @@
#---Adding examples subdirectories explicitly
# and a custom target to for building all basic examples -------------
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
add_subdirectory(B2b)
add_custom_target(tbb DEPENDS B2bTBB)
+30
View File
@@ -0,0 +1,30 @@
d: History 68751 2013-04-05 10:21:24Z gcosmo $
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
extended/parllel/tbb History file
---------------------------------
his 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 *
----------------------------------------------------------
10th November 2013 I. Hrivnacova (tbbex-V09-06-02)
- Added README files (and moved previous README in DevelopmentStatus.txt)
- Fixed CMake build
- Updated B2b classes for changes in B2b in basic
7th November 2013 A. Dotti (tbbex-V09-06-01)
- Bug fix for G4VSteppingVerbose
- Remove unused macros
6th November 2013 A. Dotti (tbbex-V09-06-00)
- First import of new TBB based examples
- Not ready yet for production or inclusion in release
+21
View File
@@ -0,0 +1,21 @@
Geant4 extended examples - TBB
--------------------------------
TBB directory shows how to integrate Intel Threading Building Block and Geant4
to achieve event-level parallelism.
TBB/B2b
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. It should not be considered a feature-complete example
and it present some limitations (no merging of output, no correct clean-up of
heap).
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.