Import Geant4 10.5.0 source tree
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
|
||||
/*! \page ExampleB4dScoreWriter Example B4dScoreWriter
|
||||
|
||||
This example demonstrates saving the Geant4 scorers hits in form of ntuples in a Root
|
||||
file using Geant4 analysis tools.
|
||||
|
||||
The example is completely based on basic B4d example, the storing hits is activated
|
||||
in the main () function with instantiating G4ScoreNtupleWriter.
|
||||
In difference from the B3aScoreWriter example, the G4AnalysisManager is explicitly used
|
||||
in this example and the ntuples with scorers hits are saved in addition to the histograms
|
||||
and ntuples created in B4RunAction.
|
||||
|
||||
The G4ScoreNtupleWriter and G4ScoreNtupleWriterMessenger classses are provided in
|
||||
the 'scoreWriter' directory in this example. These classes are fully independent from
|
||||
the example classes and they can be reused in any Geant4 application.
|
||||
|
||||
The Geant4 UI command defined in G4ScoreNtupleWriterMessenger can be used to choose
|
||||
the output file type, the file name and the level of verbosity:
|
||||
|
||||
\verbatim
|
||||
/score/writerType root
|
||||
/score/fileName name
|
||||
/score/writerVerbose 1
|
||||
\endverbatim
|
||||
|
||||
\section B4dScoreWriter_s1 How to build
|
||||
|
||||
An additional step is needed when building the example with GNUmake
|
||||
due to using the extra 'scoreWriter' directory:
|
||||
|
||||
\verbatim
|
||||
% cd path_to_B4dScoreWriter/B4dScoreWriter
|
||||
% gmake setup
|
||||
% gmake
|
||||
\endverbatim
|
||||
|
||||
This will copy the files from scoreWriter in the example include and src;
|
||||
to remove these files:
|
||||
|
||||
\verbatim
|
||||
% gmake clean_setup
|
||||
\endverbatim
|
||||
|
||||
\section B4dScoreWriter_s2 How to run
|
||||
|
||||
- Execute exampleB4dExt in the 'interactive mode' with visualization
|
||||
\verbatim
|
||||
% ./exampleB4dExt
|
||||
\endverbatim
|
||||
and type in the commands from run1.mac line by line:
|
||||
\verbatim
|
||||
Idle> /run/initialize
|
||||
Idle> /control/verbose 2
|
||||
Idle> /tracking/verbose 2
|
||||
Idle> /run/beamOn 1
|
||||
Idle> ...
|
||||
Idle> exit
|
||||
\endverbatim
|
||||
or
|
||||
\verbatim
|
||||
Idle> /control/execute run1.mac
|
||||
....
|
||||
Idle> exit
|
||||
\endverbatim
|
||||
|
||||
- Execute exampleB4dExt in the 'batch' mode from macro files
|
||||
(without visualization)
|
||||
\verbatim
|
||||
% ./exampleB4dExt -m run2.mac
|
||||
% ./exampleB4dExt -m exampleB4dExt.in > exampleB3.out
|
||||
\endverbatim
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,71 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Setup the project
|
||||
#
|
||||
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
||||
project(B4dScoreWriter)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Find Geant4 package, activating all available UI and Vis drivers by default
|
||||
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
|
||||
# to build a batch mode only executable
|
||||
#
|
||||
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
|
||||
if(WITH_GEANT4_UIVIS)
|
||||
find_package(Geant4 REQUIRED ui_all vis_all)
|
||||
else()
|
||||
find_package(Geant4 REQUIRED)
|
||||
endif()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Setup Geant4 include directories and compile definitions
|
||||
# Setup include directory for this project
|
||||
#
|
||||
include(${Geant4_USE_FILE})
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Locate sources and headers for this project
|
||||
#
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/scoreWriter/include
|
||||
${Geant4_INCLUDE_DIR})
|
||||
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
|
||||
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add scoreWriter subdirectory
|
||||
#
|
||||
add_subdirectory(scoreWriter)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add the executable, and link it to the Geant4 libraries
|
||||
#
|
||||
add_executable(exampleB4dExt exampleB4dExt.cc ${sources} ${headers})
|
||||
target_link_libraries(exampleB4dExt scoreWriter ${Geant4_LIBRARIES})
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Copy all scripts to the build directory, i.e. the directory in which we
|
||||
# build B4c. This is so that we can run the executable directly because it
|
||||
# relies on these scripts being in the current working directory.
|
||||
#
|
||||
set(EXAMPLEB4D_SCRIPTS
|
||||
exampleB4dExt.in
|
||||
gui.mac
|
||||
init_vis.mac
|
||||
plotHisto.C
|
||||
run1.mac
|
||||
run2.mac
|
||||
vis.mac
|
||||
)
|
||||
|
||||
foreach(_script ${EXAMPLEB4D_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 exampleB4dExt DESTINATION bin)
|
||||
@@ -0,0 +1,32 @@
|
||||
# --------------------------------------------------------------
|
||||
# GNUmakefile for examples module. Gabriele Cosmo, 06/04/98.
|
||||
# --------------------------------------------------------------
|
||||
|
||||
name := exampleB4dExt
|
||||
G4TARGET := $(name)
|
||||
G4EXLIB := true
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
.PHONY: setup clean_setup all
|
||||
all: lib bin
|
||||
|
||||
setup:
|
||||
@echo "Copying files from scoreWriter"
|
||||
@cp -rp scoreWriter/include/* include
|
||||
@cp -rp scoreWriter/src/* src
|
||||
|
||||
clean_setup:
|
||||
@echo "Removing files copied from scoreWriter"
|
||||
@rm -fr include/G4ScoreNtupleWriter*
|
||||
@rm -fr src/G4ScoreNtupleWriter*
|
||||
|
||||
include $(G4INSTALL)/config/binmake.gmk
|
||||
|
||||
CPPFLAGS += -I./scoreWriter/include
|
||||
|
||||
visclean:
|
||||
rm -f g4*.prim g4*.eps g4*.wrl
|
||||
rm -f .DAWN_*
|
||||
@@ -0,0 +1,18 @@
|
||||
--------------------------------------------------
|
||||
|
||||
=========================================================
|
||||
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
|
||||
=========================================================
|
||||
|
||||
Example B4dScoreWriter History file
|
||||
-----------------------------------
|
||||
This file should be used by the G4 example coordinator to briefly
|
||||
summarize all major modifications introduced in the code and keep
|
||||
track of all tags.
|
||||
|
||||
----------------------------------------------------------
|
||||
* Reverse chronological order (last date on top), please *
|
||||
----------------------------------------------------------
|
||||
|
||||
30 October 2018, Ivana Hrivnacova (B4dScoreWriter-V10-04-00)
|
||||
- First version
|
||||
@@ -0,0 +1,65 @@
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=========================================================
|
||||
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
|
||||
=========================================================
|
||||
|
||||
Example B4dScoreWriter
|
||||
----------------------
|
||||
|
||||
This example demonstrates saving the Geant4 scorers hits in form of ntuples in a Root
|
||||
file using Geant4 analysis tools.
|
||||
|
||||
The example is completely based on basic B4d example, the storing scorers hits is activated
|
||||
in the main () function with instantiating G4ScoreNtupleWriter.
|
||||
In difference from the B3aScoreWriter example, the G4AnalysisManager is explicitly used
|
||||
in this example and the ntuples with scorers hits are saved in addition to the histograms
|
||||
and ntuples created in B4RunAction.
|
||||
|
||||
The G4ScoreNtupleWriter and G4ScoreNtupleWriterMessenger classses are provided in
|
||||
the 'scoreWriter' directory in this example. These classes are fully independent from
|
||||
the example classes and they can be reused in any Geant4 application.
|
||||
|
||||
The Geant4 UI command defined in G4ScoreNtupleWriterMessenger can be used to choose
|
||||
the output file type, the file name and the level of verbosity:
|
||||
|
||||
/score/writerType root
|
||||
/score/fileName name
|
||||
/score/writerVerbose 1
|
||||
|
||||
How to build
|
||||
---------------
|
||||
|
||||
An additional step is needed when building the example with GNUmake
|
||||
due to using the extra 'scoreWriter' directory:
|
||||
|
||||
% cd path_to_B4dScoreWriter/B4dScoreWriter
|
||||
% gmake setup
|
||||
% gmake
|
||||
|
||||
This will copy the files from scoreWriter in the example include and src;
|
||||
to remove these files:
|
||||
% gmake clean_setup
|
||||
|
||||
How to run
|
||||
-------------
|
||||
|
||||
- Execute exampleB4dExt in the 'interactive mode' with visualization
|
||||
% ./exampleB4dExt
|
||||
and type in the commands from run1.mac line by line:
|
||||
Idle> /run/initialize
|
||||
Idle> /control/verbose 2
|
||||
Idle> /tracking/verbose 2
|
||||
Idle> /run/beamOn 1
|
||||
Idle> ...
|
||||
Idle> exit
|
||||
or
|
||||
Idle> /control/execute run1.mac
|
||||
....
|
||||
Idle> exit
|
||||
- Execute exampleB4dExt in the 'batch' mode from macro files
|
||||
(without visualization)
|
||||
% ./exampleB4dExt -m run2.mac
|
||||
% ./exampleB4dExt -m exampleB4dExt.in > exampleB3.out
|
||||
|
||||
See the B3 example README for the further documentation of the basic B3 example.
|
||||
@@ -0,0 +1,165 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file exampleB4d.cc
|
||||
/// \brief Main program of the B4d example
|
||||
|
||||
#include "B4dDetectorConstruction.hh"
|
||||
#include "B4dActionInitialization.hh"
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
#include "G4MTRunManager.hh"
|
||||
#else
|
||||
#include "G4RunManager.hh"
|
||||
#endif
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "FTFP_BERT.hh"
|
||||
#include "G4ScoreNtupleWriter.hh"
|
||||
|
||||
|
||||
#include "Randomize.hh"
|
||||
|
||||
#include "G4VisExecutive.hh"
|
||||
|
||||
#include "G4UIExecutive.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
namespace {
|
||||
void PrintUsage() {
|
||||
G4cerr << " Usage: " << G4endl;
|
||||
G4cerr << " exampleB4d [-m macro ] [-u UIsession] [-t nThreads]" << G4endl;
|
||||
G4cerr << " note: -t option is available only for multi-threaded mode."
|
||||
<< G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
// Evaluate arguments
|
||||
//
|
||||
if ( argc > 7 ) {
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
G4String macro;
|
||||
G4String session;
|
||||
#ifdef G4MULTITHREADED
|
||||
G4int nThreads = 0;
|
||||
#endif
|
||||
for ( G4int i=1; i<argc; i=i+2 ) {
|
||||
if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
|
||||
else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
|
||||
#ifdef G4MULTITHREADED
|
||||
else if ( G4String(argv[i]) == "-t" ) {
|
||||
nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Detect interactive mode (if no macro provided) and define UI session
|
||||
//
|
||||
G4UIExecutive* ui = nullptr;
|
||||
if ( ! macro.size() ) {
|
||||
ui = new G4UIExecutive(argc, argv, session);
|
||||
}
|
||||
|
||||
// Choose the Random engine
|
||||
//
|
||||
G4Random::setTheEngine(new CLHEP::RanecuEngine);
|
||||
|
||||
// Construct the MT run manager
|
||||
//
|
||||
#ifdef G4MULTITHREADED
|
||||
auto runManager = new G4MTRunManager;
|
||||
if ( nThreads > 0 ) {
|
||||
runManager->SetNumberOfThreads(nThreads);
|
||||
}
|
||||
#else
|
||||
auto runManager = new G4RunManager;
|
||||
#endif
|
||||
|
||||
// Set mandatory initialization classes
|
||||
//
|
||||
auto detConstruction = new B4dDetectorConstruction();
|
||||
runManager->SetUserInitialization(detConstruction);
|
||||
|
||||
auto physicsList = new FTFP_BERT;
|
||||
runManager->SetUserInitialization(physicsList);
|
||||
|
||||
auto actionInitialization = new B4dActionInitialization();
|
||||
runManager->SetUserInitialization(actionInitialization);
|
||||
|
||||
// Initialize visualization
|
||||
auto visManager = new G4VisExecutive;
|
||||
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
|
||||
// G4VisManager* visManager = new G4VisExecutive("Quiet");
|
||||
visManager->Initialize();
|
||||
|
||||
// Get the pointer to the User Interface manager
|
||||
auto UImanager = G4UImanager::GetUIpointer();
|
||||
|
||||
// Activate score ntuple writer
|
||||
// The output type and the verbose level can be also set via UI commands
|
||||
// /score/writerType csv|root|xml
|
||||
// /score/writerVerbose level
|
||||
G4ScoreNtupleWriter scoreNtupleWriter;
|
||||
|
||||
// Process macro or start UI session
|
||||
//
|
||||
if ( macro.size() ) {
|
||||
// batch mode
|
||||
G4String command = "/control/execute ";
|
||||
UImanager->ApplyCommand(command+macro);
|
||||
}
|
||||
else {
|
||||
// interactive mode : define UI session
|
||||
UImanager->ApplyCommand("/control/execute init_vis.mac");
|
||||
if (ui->IsGUI()) {
|
||||
UImanager->ApplyCommand("/control/execute gui.mac");
|
||||
}
|
||||
ui->SessionStart();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
// Job termination
|
||||
// Free the store: user actions, physics_list and detector_description are
|
||||
// owned and deleted by the run manager, so they should not be deleted
|
||||
// in the main() program !
|
||||
|
||||
delete visManager;
|
||||
delete runManager;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
|
||||
@@ -0,0 +1,26 @@
|
||||
# Macro file for example B4 test
|
||||
#
|
||||
/run/initialize
|
||||
#
|
||||
/score/writerType root
|
||||
/score/writerVerbose 1
|
||||
#
|
||||
# e+ 300MeV
|
||||
/gun/particle e+
|
||||
/gun/energy 300 MeV
|
||||
/run/beamOn 1
|
||||
#
|
||||
# list the existing physics processes
|
||||
/process/list
|
||||
#
|
||||
# switch off MultipleScattering
|
||||
/process/inactivate msc
|
||||
/run/beamOn 1
|
||||
#
|
||||
# switch on MultipleScattering
|
||||
/process/activate msc
|
||||
#
|
||||
# change detector parameter
|
||||
/gun/particle gamma
|
||||
/gun/energy 500 MeV
|
||||
/run/beamOn 1
|
||||
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# This file permits to customize, with commands,
|
||||
# the menu bar of the G4UIXm, G4UIQt, G4UIWin32 sessions.
|
||||
# It has no effect with G4UIterminal.
|
||||
#
|
||||
# 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"
|
||||
#
|
||||
# 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"
|
||||
#
|
||||
# Vis menu :
|
||||
/gui/addMenu vis Vis
|
||||
/gui/addButton vis DAWNFILE "/control/execute visTutor/exN03Vis0.mac"
|
||||
/gui/addButton vis OpenInventor "/control/execute visTutor/exN03Vis5.mac"
|
||||
/gui/addButton vis TimeSlicing "/control/execute visTutor/exN03Vis12.mac"
|
||||
/gui/addButton vis EmShower "/control/execute visTutor/exN03Vis13.mac"
|
||||
#
|
||||
# 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 wireframe"
|
||||
/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"
|
||||
#
|
||||
# To limit the output flow in the "dump" widget :
|
||||
/run/printProgress 100
|
||||
#
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4Analysis.hh
|
||||
/// \brief Selection of the analysis technology
|
||||
|
||||
#ifndef B4Analysis_h
|
||||
#define B4Analysis_h 1
|
||||
|
||||
#include "g4root.hh"
|
||||
//#include "g4cvs.hh"
|
||||
//#include "g4xml.hh"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4PrimaryGeneratorAction.hh
|
||||
/// \brief Definition of the B4PrimaryGeneratorAction class
|
||||
|
||||
#ifndef B4PrimaryGeneratorAction_h
|
||||
#define B4PrimaryGeneratorAction_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 calorimeter
|
||||
/// 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 B4PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
|
||||
{
|
||||
public:
|
||||
B4PrimaryGeneratorAction();
|
||||
virtual ~B4PrimaryGeneratorAction();
|
||||
|
||||
virtual void GeneratePrimaries(G4Event* event);
|
||||
|
||||
// set methods
|
||||
void SetRandomFlag(G4bool value);
|
||||
|
||||
private:
|
||||
G4ParticleGun* fParticleGun; // G4 particle gun
|
||||
};
|
||||
|
||||
//....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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4RunAction.hh
|
||||
/// \brief Definition of the B4RunAction class
|
||||
|
||||
#ifndef B4RunAction_h
|
||||
#define B4RunAction_h 1
|
||||
|
||||
#include "G4UserRunAction.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4Run;
|
||||
|
||||
/// Run action class
|
||||
///
|
||||
/// It accumulates statistic and computes dispersion of the energy deposit
|
||||
/// and track lengths of charged particles with use of analysis tools:
|
||||
/// H1D histograms are created in BeginOfRunAction() for the following
|
||||
/// physics quantities:
|
||||
/// - Edep in absorber
|
||||
/// - Edep in gap
|
||||
/// - Track length in absorber
|
||||
/// - Track length in gap
|
||||
/// The same values are also saved in the ntuple.
|
||||
/// The histograms and ntuple are saved in the output file in a format
|
||||
/// accoring to a selected technology in B4Analysis.hh.
|
||||
///
|
||||
/// In EndOfRunAction(), the accumulated statistic and computed
|
||||
/// dispersion is printed.
|
||||
///
|
||||
|
||||
class B4RunAction : public G4UserRunAction
|
||||
{
|
||||
public:
|
||||
B4RunAction();
|
||||
virtual ~B4RunAction();
|
||||
|
||||
virtual void BeginOfRunAction(const G4Run*);
|
||||
virtual void EndOfRunAction(const G4Run*);
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4dActionInitialization.hh
|
||||
/// \brief Definition of the B4dActionInitialization class
|
||||
|
||||
#ifndef B4dActionInitialization_h
|
||||
#define B4dActionInitialization_h 1
|
||||
|
||||
#include "G4VUserActionInitialization.hh"
|
||||
|
||||
/// Action initialization class.
|
||||
///
|
||||
|
||||
class B4dActionInitialization : public G4VUserActionInitialization
|
||||
{
|
||||
public:
|
||||
B4dActionInitialization();
|
||||
virtual ~B4dActionInitialization();
|
||||
|
||||
virtual void BuildForMaster() const;
|
||||
virtual void Build() const;
|
||||
};
|
||||
|
||||
#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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4dDetectorConstruction.hh
|
||||
/// \brief Definition of the B4dDetectorConstruction class
|
||||
|
||||
#ifndef B4dDetectorConstruction_h
|
||||
#define B4dDetectorConstruction_h 1
|
||||
|
||||
#include "G4VUserDetectorConstruction.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4VPhysicalVolume;
|
||||
class G4GlobalMagFieldMessenger;
|
||||
|
||||
/// Detector construction class to define materials and geometry.
|
||||
/// The calorimeter is a box made of a given number of layers. A layer consists
|
||||
/// of an absorber plate and of a detection gap. The layer is replicated.
|
||||
///
|
||||
/// Four parameters define the geometry of the calorimeter :
|
||||
///
|
||||
/// - the thickness of an absorber plate,
|
||||
/// - the thickness of a gap,
|
||||
/// - the number of layers,
|
||||
/// - the transverse size of the calorimeter (the input face is a square).
|
||||
///
|
||||
/// In ConstructSDandField() sensitive detectors of G4MultiFunctionalDetector
|
||||
/// type with primitive scorers are created and associated with the Absorber
|
||||
/// and Gap volumes. In addition a transverse uniform magnetic field is defined
|
||||
/// via G4GlobalMagFieldMessenger class.
|
||||
|
||||
class B4dDetectorConstruction : public G4VUserDetectorConstruction
|
||||
{
|
||||
public:
|
||||
B4dDetectorConstruction();
|
||||
virtual ~B4dDetectorConstruction();
|
||||
|
||||
public:
|
||||
virtual G4VPhysicalVolume* Construct();
|
||||
virtual void ConstructSDandField();
|
||||
|
||||
private:
|
||||
// methods
|
||||
//
|
||||
void DefineMaterials();
|
||||
G4VPhysicalVolume* DefineVolumes();
|
||||
|
||||
// data members
|
||||
//
|
||||
static G4ThreadLocal G4GlobalMagFieldMessenger* fMagFieldMessenger;
|
||||
// magnetic field messenger
|
||||
|
||||
G4bool fCheckOverlaps; // option to activate checking of volumes overlaps
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4dEventAction.hh
|
||||
/// \brief Definition of the B4dEventAction class
|
||||
|
||||
#ifndef B4dEventAction_h
|
||||
#define B4dEventAction_h 1
|
||||
|
||||
#include "G4UserEventAction.hh"
|
||||
|
||||
#include "G4THitsMap.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
/// Event action class
|
||||
///
|
||||
/// In EndOfEventAction(), it prints the accumulated quantities of the energy
|
||||
/// deposit and track lengths of charged particles in Absober and Gap layers
|
||||
/// stored in the hits collections.
|
||||
|
||||
class B4dEventAction : public G4UserEventAction
|
||||
{
|
||||
public:
|
||||
B4dEventAction();
|
||||
virtual ~B4dEventAction();
|
||||
|
||||
virtual void BeginOfEventAction(const G4Event* event);
|
||||
virtual void EndOfEventAction(const G4Event* event);
|
||||
|
||||
private:
|
||||
// methods
|
||||
G4THitsMap<G4double>* GetHitsCollection(G4int hcID,
|
||||
const G4Event* event) const;
|
||||
G4double GetSum(G4THitsMap<G4double>* hitsMap) const;
|
||||
void PrintEventStatistics(G4double absoEdep, G4double absoTrackLength,
|
||||
G4double gapEdep, G4double gapTrackLength) const;
|
||||
|
||||
// data members
|
||||
G4int fAbsoEdepHCID;
|
||||
G4int fGapEdepHCID;
|
||||
G4int fAbsoTrackLengthHCID;
|
||||
G4int fGapTrackLengthHCID;
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Macro file for the initialization of example B4
|
||||
# in interactive session
|
||||
#
|
||||
# Set some default verbose
|
||||
#
|
||||
/control/verbose 2
|
||||
/control/saveHistory
|
||||
/run/verbose 2
|
||||
#
|
||||
# Change the default number of threads (in multi-threaded mode)
|
||||
#/run/numberOfThreads 4
|
||||
#
|
||||
# Initialize kernel
|
||||
/run/initialize
|
||||
#
|
||||
# Visualization setting
|
||||
/control/execute vis.mac
|
||||
@@ -0,0 +1,43 @@
|
||||
// ROOT macro file for plotting example B4 histograms
|
||||
//
|
||||
// Can be run from ROOT session:
|
||||
// root[0] .x plotHisto.C
|
||||
|
||||
{
|
||||
gROOT->Reset();
|
||||
gROOT->SetStyle("Plain");
|
||||
|
||||
// Draw histos filled by Geant4 simulation
|
||||
//
|
||||
|
||||
// Open file filled by Geant4 simulation
|
||||
TFile f("B4.root");
|
||||
|
||||
// Create a canvas and divide it into 2x2 pads
|
||||
TCanvas* c1 = new TCanvas("c1", "", 20, 20, 1000, 1000);
|
||||
c1->Divide(2,2);
|
||||
|
||||
// Draw Eabs histogram in the pad 1
|
||||
c1->cd(1);
|
||||
TH1D* hist1 = (TH1D*)f.Get("Eabs");
|
||||
hist1->Draw("HIST");
|
||||
|
||||
// Draw Labs histogram in the pad 2
|
||||
c1->cd(2);
|
||||
TH1D* hist2 = (TH1D*)f.Get("Labs");
|
||||
hist2->Draw("HIST");
|
||||
|
||||
// Draw Egap histogram in the pad 3
|
||||
// with logaritmic scale for y
|
||||
TH1D* hist3 = (TH1D*)f.Get("Egap");
|
||||
c1->cd(3);
|
||||
gPad->SetLogy(1);
|
||||
hist3->Draw("HIST");
|
||||
|
||||
// Draw Lgap histogram in the pad 4
|
||||
// with logaritmic scale for y
|
||||
c1->cd(4);
|
||||
gPad->SetLogy(1);
|
||||
TH1D* hist4 = (TH1D*)f.Get("Lgap");
|
||||
hist4->Draw("HIST");
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// ROOT macro file for plotting example B4 ntuple
|
||||
//
|
||||
// Can be run from ROOT session:
|
||||
// root[0] .x plotNtuple.C
|
||||
|
||||
{
|
||||
gROOT->Reset();
|
||||
gROOT->SetStyle("Plain");
|
||||
|
||||
// Draw histos filled by Geant4 simulation
|
||||
//
|
||||
|
||||
// Open file filled by Geant4 simulation
|
||||
TFile f("B4.root");
|
||||
|
||||
// Create a canvas and divide it into 2x2 pads
|
||||
TCanvas* c1 = new TCanvas("c1", "", 20, 20, 1000, 1000);
|
||||
c1->Divide(2,2);
|
||||
|
||||
// Get ntuple
|
||||
TNtuple* ntuple = (TNtuple*)f.Get("B4");
|
||||
|
||||
// Draw Eabs histogram in the pad 1
|
||||
c1->cd(1);
|
||||
ntuple->Draw("Eabs");
|
||||
|
||||
// Draw Labs histogram in the pad 2
|
||||
c1->cd(2);
|
||||
ntuple->Draw("Labs");
|
||||
|
||||
// Draw Egap histogram in the pad 3
|
||||
// with logaritmic scale for y ?? how to do this?
|
||||
c1->cd(3);
|
||||
gPad->SetLogy(1);
|
||||
ntuple->Draw("Egap");
|
||||
|
||||
// Draw Lgap histogram in the pad 4
|
||||
// with logaritmic scale for y ?? how to do this?
|
||||
c1->cd(4);
|
||||
gPad->SetLogy(1);
|
||||
ntuple->Draw("Egap");
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# Macro file for example B4
|
||||
#
|
||||
# Can be run in batch, without graphic
|
||||
# or interactively: Idle> /control/execute run1.mac
|
||||
#
|
||||
# Change the default number of workers (in multi-threading mode)
|
||||
#/run/numberOfWorkers 4
|
||||
#
|
||||
# Initialize kernel
|
||||
/run/initialize
|
||||
#
|
||||
# Default kinematics:
|
||||
# electron 50 MeV in direction (0.,0.,1.)
|
||||
# 1 event with tracking/verbose
|
||||
#
|
||||
/tracking/verbose 1
|
||||
/run/beamOn 1
|
||||
#
|
||||
#
|
||||
# muon 300 MeV in direction (0.,0.,1.)
|
||||
# 3 events
|
||||
#
|
||||
/gun/particle mu+
|
||||
/gun/energy 3 MeV
|
||||
/run/beamOn 3
|
||||
#
|
||||
# 20 events
|
||||
#
|
||||
/tracking/verbose 0
|
||||
/run/printProgress 5
|
||||
/run/beamOn 20
|
||||
#
|
||||
# Magnetic field
|
||||
#
|
||||
/globalField/setValue 0.2 0 0 tesla
|
||||
/run/beamOn 3
|
||||
#
|
||||
# Activate/inactivate physics processes
|
||||
#
|
||||
/process/list
|
||||
/process/inactivate eBrem
|
||||
#
|
||||
/run/beamOn 20
|
||||
#
|
||||
@@ -0,0 +1,18 @@
|
||||
# Macro file for example B4
|
||||
#
|
||||
# To be run preferably in batch, without graphics:
|
||||
# % exampleB4[a,b,c,d] run2.mac
|
||||
#
|
||||
#/run/numberOfWorkers 4
|
||||
/run/initialize
|
||||
#
|
||||
# Default kinemtics:
|
||||
# electron 50 MeV in direction (0.,0.,1.)
|
||||
# 1000 events
|
||||
#
|
||||
/score/writerType root
|
||||
/score/writerVerbose 1
|
||||
#
|
||||
/run/printProgress 100
|
||||
/run/beamOn 1000
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Setup the project
|
||||
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
||||
project(scoreWriter)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Find Geant4 package, no UI and Vis drivers activated
|
||||
#
|
||||
find_package(Geant4 REQUIRED)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Setup Geant4 include directories and compile definitions
|
||||
#
|
||||
include(${Geant4_USE_FILE})
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Locate sources and headers for this project
|
||||
#
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include
|
||||
${Geant4_INCLUDE_DIR})
|
||||
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
|
||||
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add the library
|
||||
#
|
||||
add_library(scoreWriter ${sources} ${headers})
|
||||
target_link_libraries(scoreWriter ${Geant4_LIBRARIES} )
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
|
||||
# and the library to 'lib' directory under CMAKE_INSTALL_PREFIX
|
||||
#
|
||||
install(TARGETS scoreWriter DESTINATION lib)
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4ScoreNtupleWriter_h
|
||||
#define G4ScoreNtupleWriter_h 1
|
||||
|
||||
#include "G4VScoreNtupleWriter.hh"
|
||||
#include "G4HCofThisEvent.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class G4HCofThisEvent;
|
||||
class G4VAnalysisManager;
|
||||
class G4ScoreNtupleWriterMessenger;
|
||||
|
||||
// class description:
|
||||
//
|
||||
// This class implements storing hits collections of G4THitsMap<G4double>
|
||||
// type vith Geant4 analysis tools.
|
||||
//
|
||||
// An ntuple with three columns is created for each primitive scorer:
|
||||
// int column - eventNumber
|
||||
// int column - copyNumber
|
||||
// double column - scored value
|
||||
|
||||
class G4ScoreNtupleWriter : public G4VScoreNtupleWriter
|
||||
{
|
||||
public:
|
||||
G4ScoreNtupleWriter(const G4String& outputType = "none");
|
||||
virtual ~G4ScoreNtupleWriter();
|
||||
|
||||
// methods
|
||||
virtual G4bool Book(G4HCofThisEvent* hce);
|
||||
virtual void OpenFile();
|
||||
virtual void Fill(G4HCofThisEvent* hce, G4int eventNumber);
|
||||
virtual void Write();
|
||||
|
||||
// set methods
|
||||
void SetOutputType(const G4String& outputTypeName);
|
||||
void SetFileName(const G4String& fileName);
|
||||
void SetVerboseLevel(G4int value);
|
||||
|
||||
// get methods
|
||||
G4AnalysisOutput GetOutputType() const;
|
||||
G4String GetFileName() const { return fFileName; }
|
||||
G4int GetVerboseLevel() const { return fVerboseLevel; }
|
||||
|
||||
protected:
|
||||
// methods
|
||||
virtual G4VScoreNtupleWriter* CreateInstance() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
void CreateAnalysisManager();
|
||||
|
||||
// data members
|
||||
G4ScoreNtupleWriterMessenger* fMessenger;
|
||||
std::vector<G4int> fHCIds;
|
||||
G4VAnalysisManager* fAnalysisManager;
|
||||
G4String fOutputTypeName;
|
||||
G4String fFileName;
|
||||
G4int fVerboseLevel;
|
||||
G4bool fHasAnalysisManager;
|
||||
G4bool fHasAnalysisFile;
|
||||
G4bool fIsBooked;
|
||||
G4bool fIsInitialized;
|
||||
G4int fFirstNtupleId;
|
||||
};
|
||||
|
||||
#endif
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4ScoreNtupleWriterMessenger_h
|
||||
#define G4ScoreNtupleWriterMessenger_h 1
|
||||
|
||||
#include "G4UImessenger.hh"
|
||||
|
||||
class G4ScoreNtupleWriter;
|
||||
class G4UIdirectory;
|
||||
class G4UIcmdWithoutParameter;
|
||||
class G4UIcmdWithAString;
|
||||
class G4UIcmdWithAnInteger;
|
||||
|
||||
// class description:
|
||||
//
|
||||
// This is a concrete class of G4UImessenger which handles the commands for
|
||||
// G4ScoreNtupleWriter. This class has the following commands:
|
||||
// /score/writerFileName filename
|
||||
// /score/writerType csv|root|xml|none
|
||||
// /score/writerVerbose value
|
||||
//
|
||||
|
||||
class G4ScoreNtupleWriterMessenger: public G4UImessenger
|
||||
{
|
||||
public:
|
||||
G4ScoreNtupleWriterMessenger(G4ScoreNtupleWriter* scoreNtupleWriter);
|
||||
~G4ScoreNtupleWriterMessenger();
|
||||
void SetNewValue(G4UIcommand * command,G4String newValues);
|
||||
|
||||
private:
|
||||
G4ScoreNtupleWriter* fScoreNtupleWriter;
|
||||
// G4UIdirectory* fDirectory;
|
||||
G4UIcmdWithAString* fWriterTypeCmd;
|
||||
G4UIcmdWithAString* fWriterFileNameCmd;
|
||||
G4UIcmdWithAnInteger* fWriterVerboseCmd;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#include "G4ScoreNtupleWriter.hh"
|
||||
#include "G4ScoreNtupleWriterMessenger.hh"
|
||||
#include "G4THitsMap.hh"
|
||||
#include "g4csv.hh"
|
||||
#include "g4root.hh"
|
||||
#include "g4xml.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
//
|
||||
// ctor, dtor
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ScoreNtupleWriter::G4ScoreNtupleWriter(const G4String& outputType)
|
||||
: G4VScoreNtupleWriter(),
|
||||
fMessenger(nullptr),
|
||||
fHCIds(),
|
||||
fAnalysisManager(nullptr),
|
||||
fOutputTypeName(outputType),
|
||||
fFileName("scoring"),
|
||||
fVerboseLevel(1),
|
||||
fHasAnalysisManager(false),
|
||||
fHasAnalysisFile(false),
|
||||
fIsBooked(false),
|
||||
fIsInitialized(false),
|
||||
fFirstNtupleId(0)
|
||||
{
|
||||
// if ( G4Threading::IsMasterThread() ) {
|
||||
fMessenger = new G4ScoreNtupleWriterMessenger(this);
|
||||
// }
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ScoreNtupleWriter::~G4ScoreNtupleWriter()
|
||||
{
|
||||
if ( fHasAnalysisManager ) {
|
||||
delete fAnalysisManager;
|
||||
}
|
||||
|
||||
delete fMessenger;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::CreateAnalysisManager()
|
||||
{
|
||||
if ( fAnalysisManager ) return;
|
||||
|
||||
switch ( GetOutputType() ) {
|
||||
case G4AnalysisOutput::kCsv:
|
||||
// create Csv analysis manager
|
||||
if ( ! G4CsvAnalysisManager::IsInstance() ) fHasAnalysisManager = true;
|
||||
fAnalysisManager = G4CsvAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kRoot:
|
||||
// create Root analysis manager
|
||||
if ( ! G4RootAnalysisManager::IsInstance() ) fHasAnalysisManager = true;
|
||||
fAnalysisManager = G4RootAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kXml:
|
||||
// create Xml analysis manager
|
||||
if ( ! G4XmlAnalysisManager::IsInstance() ) fHasAnalysisManager = true;
|
||||
fAnalysisManager = G4XmlAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kNone:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
fAnalysisManager->SetVerboseLevel(fVerboseLevel);
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VScoreNtupleWriter* G4ScoreNtupleWriter::CreateInstance() const
|
||||
{
|
||||
auto instance = new G4ScoreNtupleWriter();
|
||||
instance->SetOutputType(fOutputTypeName);
|
||||
instance->SetFileName(fFileName);
|
||||
instance->SetVerboseLevel(fVerboseLevel);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ScoreNtupleWriter::Book(G4HCofThisEvent* hce)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- G4ScoreNtupleWriter::Book" << G4endl;
|
||||
}
|
||||
#endif
|
||||
if ( ! hce) return false;
|
||||
|
||||
// book collection ID if DoubleHitsMap
|
||||
if (fHCIds.size() == 0) {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- going to fill fHCIds " << G4endl;
|
||||
}
|
||||
#endif
|
||||
for (G4int i=0; i<hce->GetNumberOfCollections(); ++i) {
|
||||
auto hitsMap
|
||||
= dynamic_cast<G4THitsMap<G4double>*>(hce->GetHC(i));
|
||||
|
||||
if ( hitsMap ) {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- adding hcID = " << i << G4endl;
|
||||
}
|
||||
#endif
|
||||
fHCIds.push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create analysis manager
|
||||
if ( fHCIds.size() ) {
|
||||
CreateAnalysisManager();
|
||||
}
|
||||
|
||||
// Create ntuples (only once)
|
||||
if ( ! fIsInitialized ) {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "-- going to create ntuples " << G4endl;
|
||||
}
|
||||
#endif
|
||||
auto first = true;
|
||||
for (auto id : fHCIds) {
|
||||
auto hitsMap
|
||||
= static_cast<G4THitsMap<G4double>*>(hce->GetHC(id));
|
||||
|
||||
// Create ntuple for this primitive
|
||||
G4String ntupleName(hitsMap->GetSDname());
|
||||
ntupleName.append("_");
|
||||
ntupleName.append(hitsMap->GetName());
|
||||
|
||||
G4int ntupleId
|
||||
= fAnalysisManager->CreateNtuple(ntupleName, ntupleName);
|
||||
if ( first ) {
|
||||
fFirstNtupleId = ntupleId;
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "-- set first ntuple Id " << fFirstNtupleId << G4endl;
|
||||
}
|
||||
#endif
|
||||
first = false;
|
||||
}
|
||||
|
||||
G4String colName(ntupleName);
|
||||
colName.append("_eventId");
|
||||
fAnalysisManager->CreateNtupleIColumn(colName);
|
||||
colName = ntupleName;
|
||||
colName.append("_cell");
|
||||
fAnalysisManager->CreateNtupleIColumn(colName);
|
||||
colName = ntupleName;
|
||||
colName.append("_score");
|
||||
fAnalysisManager->CreateNtupleDColumn(colName);
|
||||
fAnalysisManager->FinishNtuple();
|
||||
fIsBooked = true;
|
||||
}
|
||||
fIsInitialized = true;
|
||||
}
|
||||
|
||||
return fIsBooked;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::OpenFile()
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- G4ScoreNtupleWriter::OpenFile" << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( fAnalysisManager->IsOpenFile() ) return;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- G4ScoreNtupleWriter::OpenFile executing" << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( fAnalysisManager->GetFileName() == "" ) {
|
||||
fAnalysisManager->SetFileName(fFileName);
|
||||
}
|
||||
fAnalysisManager->OpenFile();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- G4ScoreNtupleWriter::OpenFile isOpenFile: "
|
||||
<< fAnalysisManager->IsOpenFile() << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
fHasAnalysisFile = fAnalysisManager->IsOpenFile();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::Fill(G4HCofThisEvent* hce, G4int eventNumber)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- start G4ScoreNtupleWriter::Fill" << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto counter = 0;
|
||||
for (auto id : fHCIds) {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "in loop over fHCIds, counter " << counter << G4endl;
|
||||
}
|
||||
#endif
|
||||
auto hitsMap
|
||||
= static_cast<G4THitsMap<G4double>*>(hce->GetHC(id));
|
||||
|
||||
//G4cout << eventNumber << ".. go to fill ntuple " << counter + fFirstNtupleId << G4endl;
|
||||
|
||||
// fill hits in ntuple
|
||||
std::map<G4int, G4double*>::iterator it;
|
||||
for ( it = hitsMap->GetMap()->begin(); it != hitsMap->GetMap()->end(); it++ ) {
|
||||
fAnalysisManager->FillNtupleIColumn(counter + fFirstNtupleId, 0, eventNumber);
|
||||
fAnalysisManager->FillNtupleIColumn(counter + fFirstNtupleId, 1, it->first);
|
||||
fAnalysisManager->FillNtupleDColumn(counter + fFirstNtupleId, 2, *(it->second));
|
||||
fAnalysisManager->AddNtupleRow(counter + fFirstNtupleId);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- done G4ScoreNtupleWriter::Fill" << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::Write()
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- start G4ScoreNtupleWriter::Write" << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( fHasAnalysisFile ) {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- sG4ScoreNtupleWriter::Write - has file" << G4endl;
|
||||
}
|
||||
#endif
|
||||
fAnalysisManager->Write();
|
||||
fAnalysisManager->CloseFile();
|
||||
fAnalysisManager->SetFileName("");
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fVerboseLevel > 1 ) {
|
||||
G4cout << "--- done G4ScoreNtupleWriter::Write" << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::SetOutputType(const G4String& outputTypeName)
|
||||
{
|
||||
if ( fAnalysisManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot set output type. The analysis manager has not been created.";
|
||||
G4Exception("G4HitsNtupleWriter::SetOutputType", "", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
fOutputTypeName = outputTypeName;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::SetVerboseLevel(G4int value)
|
||||
{
|
||||
fVerboseLevel = value;
|
||||
if ( fAnalysisManager ) {
|
||||
fAnalysisManager->SetVerboseLevel(value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ScoreNtupleWriter::SetFileName(const G4String& fileName)
|
||||
{
|
||||
fFileName = fileName;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AnalysisOutput G4ScoreNtupleWriter::GetOutputType() const
|
||||
{
|
||||
return G4Analysis::GetOutput(fOutputTypeName);
|
||||
}
|
||||
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#include "G4ScoreNtupleWriterMessenger.hh"
|
||||
#include "G4ScoreNtupleWriter.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcmdWithAString.hh"
|
||||
#include "G4UIcmdWithAnInteger.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
|
||||
G4ScoreNtupleWriterMessenger::G4ScoreNtupleWriterMessenger(
|
||||
G4ScoreNtupleWriter* scoreNtupleWriter)
|
||||
: G4UImessenger(),
|
||||
fScoreNtupleWriter(scoreNtupleWriter),
|
||||
// fDirectory(nullptr),
|
||||
fWriterTypeCmd(nullptr),
|
||||
fWriterFileNameCmd(nullptr),
|
||||
fWriterVerboseCmd(nullptr)
|
||||
{
|
||||
// Create command directory and commands only if they do not exist.
|
||||
// To be improved: G4UImanager::FindDirectory cannot be used
|
||||
// as it is declared private.
|
||||
|
||||
// if ( ! G4UImanager::GetUIpointer()->FindDirectory("/score") ) {
|
||||
// fDirectory = new G4UIdirectory("/score/");
|
||||
// fDirectory->SetGuidance("Interactive scoring commands.");
|
||||
// }
|
||||
|
||||
fWriterTypeCmd = new G4UIcmdWithAString("/score/writerType",this);
|
||||
fWriterTypeCmd->SetGuidance( "Set the ntuple writer output file type.");
|
||||
fWriterTypeCmd->SetParameterName("outputType",false);
|
||||
G4String candidates;
|
||||
for ( auto candidate :
|
||||
{ G4AnalysisOutput::kCsv,
|
||||
G4AnalysisOutput::kRoot,
|
||||
G4AnalysisOutput::kXml,
|
||||
G4AnalysisOutput::kNone } ) {
|
||||
candidates += G4Analysis::GetOutputName(candidate);
|
||||
candidates += " ";
|
||||
}
|
||||
fWriterTypeCmd->SetCandidates(candidates);
|
||||
fWriterTypeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
|
||||
fWriterFileNameCmd = new G4UIcmdWithAString("/score/writerFileName",this);
|
||||
fWriterFileNameCmd->SetGuidance( "Set the ntuple writer output file name.");
|
||||
fWriterFileNameCmd->SetParameterName("outputFileName",false);
|
||||
fWriterFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
|
||||
fWriterVerboseCmd = new G4UIcmdWithAnInteger("/score/writerVerbose",this);
|
||||
fWriterVerboseCmd->SetGuidance("Set the ntuple writer verbose level.");
|
||||
fWriterVerboseCmd->SetParameterName("writerVerbose",false);
|
||||
fWriterTypeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
}
|
||||
|
||||
G4ScoreNtupleWriterMessenger::~G4ScoreNtupleWriterMessenger()
|
||||
{
|
||||
delete fWriterTypeCmd;
|
||||
delete fWriterFileNameCmd;
|
||||
delete fWriterVerboseCmd;
|
||||
// delete fDirectory;
|
||||
}
|
||||
|
||||
void G4ScoreNtupleWriterMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
|
||||
{
|
||||
if ( command==fWriterTypeCmd ) {
|
||||
fScoreNtupleWriter->SetOutputType(newVal);
|
||||
}
|
||||
else if ( command==fWriterFileNameCmd ) {
|
||||
fScoreNtupleWriter->SetFileName(newVal);
|
||||
}
|
||||
else if ( command==fWriterVerboseCmd ) {
|
||||
fScoreNtupleWriter->SetVerboseLevel(fWriterVerboseCmd->GetNewIntValue(newVal));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4PrimaryGeneratorAction.cc
|
||||
/// \brief Implementation of the B4PrimaryGeneratorAction class
|
||||
|
||||
#include "B4PrimaryGeneratorAction.hh"
|
||||
|
||||
#include "G4RunManager.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......
|
||||
|
||||
B4PrimaryGeneratorAction::B4PrimaryGeneratorAction()
|
||||
: G4VUserPrimaryGeneratorAction(),
|
||||
fParticleGun(nullptr)
|
||||
{
|
||||
G4int nofParticles = 1;
|
||||
fParticleGun = new G4ParticleGun(nofParticles);
|
||||
|
||||
// default particle kinematic
|
||||
//
|
||||
auto particleDefinition
|
||||
= G4ParticleTable::GetParticleTable()->FindParticle("e-");
|
||||
fParticleGun->SetParticleDefinition(particleDefinition);
|
||||
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
|
||||
fParticleGun->SetParticleEnergy(50.*MeV);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4PrimaryGeneratorAction::~B4PrimaryGeneratorAction()
|
||||
{
|
||||
delete fParticleGun;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4PrimaryGeneratorAction::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.;
|
||||
auto worldLV = G4LogicalVolumeStore::GetInstance()->GetVolume("World");
|
||||
|
||||
// Check that the world volume has box shape
|
||||
G4Box* worldBox = nullptr;
|
||||
if ( worldLV ) {
|
||||
worldBox = dynamic_cast<G4Box*>(worldLV->GetSolid());
|
||||
}
|
||||
|
||||
if ( worldBox ) {
|
||||
worldZHalfLength = worldBox->GetZHalfLength();
|
||||
}
|
||||
else {
|
||||
G4ExceptionDescription msg;
|
||||
msg << "World volume of box shape not found." << G4endl;
|
||||
msg << "Perhaps you have changed geometry." << G4endl;
|
||||
msg << "The gun will be place in the center.";
|
||||
G4Exception("B4PrimaryGeneratorAction::GeneratePrimaries()",
|
||||
"MyCode0002", JustWarning, msg);
|
||||
}
|
||||
|
||||
// Set gun position
|
||||
fParticleGun
|
||||
->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength));
|
||||
|
||||
fParticleGun->GeneratePrimaryVertex(anEvent);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4RunAction.cc
|
||||
/// \brief Implementation of the B4RunAction class
|
||||
|
||||
#include "B4RunAction.hh"
|
||||
#include "B4Analysis.hh"
|
||||
|
||||
#include "G4Run.hh"
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4RunAction::B4RunAction()
|
||||
: G4UserRunAction()
|
||||
{
|
||||
// set printing event number per each event
|
||||
G4RunManager::GetRunManager()->SetPrintProgress(1);
|
||||
|
||||
// Create analysis manager
|
||||
// The choice of analysis technology is done via selectin of a namespace
|
||||
// in B4Analysis.hh
|
||||
auto analysisManager = G4AnalysisManager::Instance();
|
||||
G4cout << "Using " << analysisManager->GetType() << G4endl;
|
||||
|
||||
// Create directories
|
||||
//analysisManager->SetHistoDirectoryName("histograms");
|
||||
//analysisManager->SetNtupleDirectoryName("ntuple");
|
||||
analysisManager->SetVerboseLevel(1);
|
||||
analysisManager->SetNtupleMerging(true);
|
||||
// Note: merging ntuples is available only with Root output
|
||||
|
||||
// Book histograms, ntuple
|
||||
//
|
||||
|
||||
// Creating histograms
|
||||
analysisManager->CreateH1("Eabs","Edep in absorber", 100, 0., 800*MeV);
|
||||
analysisManager->CreateH1("Egap","Edep in gap", 100, 0., 100*MeV);
|
||||
analysisManager->CreateH1("Labs","trackL in absorber", 100, 0., 1*m);
|
||||
analysisManager->CreateH1("Lgap","trackL in gap", 100, 0., 50*cm);
|
||||
|
||||
// Creating ntuple
|
||||
//
|
||||
analysisManager->CreateNtuple("B4", "Edep and TrackL");
|
||||
analysisManager->CreateNtupleDColumn("Eabs");
|
||||
analysisManager->CreateNtupleDColumn("Egap");
|
||||
analysisManager->CreateNtupleDColumn("Labs");
|
||||
analysisManager->CreateNtupleDColumn("Lgap");
|
||||
analysisManager->FinishNtuple();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4RunAction::~B4RunAction()
|
||||
{
|
||||
delete G4AnalysisManager::Instance();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4RunAction::BeginOfRunAction(const G4Run* /*run*/)
|
||||
{
|
||||
//inform the runManager to save random number seed
|
||||
//G4RunManager::GetRunManager()->SetRandomNumberStore(true);
|
||||
|
||||
// Get analysis manager
|
||||
auto analysisManager = G4AnalysisManager::Instance();
|
||||
|
||||
// Open an output file
|
||||
//
|
||||
G4String fileName = "B4";
|
||||
analysisManager->OpenFile(fileName);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4RunAction::EndOfRunAction(const G4Run* /*run*/)
|
||||
{
|
||||
// print histogram statistics
|
||||
//
|
||||
auto analysisManager = G4AnalysisManager::Instance();
|
||||
if ( analysisManager->GetH1(1) ) {
|
||||
G4cout << G4endl << " ----> print histograms statistic ";
|
||||
if(isMaster) {
|
||||
G4cout << "for the entire run " << G4endl << G4endl;
|
||||
}
|
||||
else {
|
||||
G4cout << "for the local thread " << G4endl << G4endl;
|
||||
}
|
||||
|
||||
G4cout << " EAbs : mean = "
|
||||
<< G4BestUnit(analysisManager->GetH1(0)->mean(), "Energy")
|
||||
<< " rms = "
|
||||
<< G4BestUnit(analysisManager->GetH1(0)->rms(), "Energy") << G4endl;
|
||||
|
||||
G4cout << " EGap : mean = "
|
||||
<< G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
|
||||
<< " rms = "
|
||||
<< G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
|
||||
|
||||
G4cout << " LAbs : mean = "
|
||||
<< G4BestUnit(analysisManager->GetH1(2)->mean(), "Length")
|
||||
<< " rms = "
|
||||
<< G4BestUnit(analysisManager->GetH1(2)->rms(), "Length") << G4endl;
|
||||
|
||||
G4cout << " LGap : mean = "
|
||||
<< G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
|
||||
<< " rms = "
|
||||
<< G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
|
||||
}
|
||||
|
||||
// save histograms & ntuple
|
||||
//
|
||||
analysisManager->Write();
|
||||
analysisManager->CloseFile();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4dActionInitialization.cc
|
||||
/// \brief Implementation of the B4dActionInitialization class
|
||||
|
||||
#include "B4dActionInitialization.hh"
|
||||
#include "B4PrimaryGeneratorAction.hh"
|
||||
#include "B4RunAction.hh"
|
||||
#include "B4dEventAction.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4dActionInitialization::B4dActionInitialization()
|
||||
: G4VUserActionInitialization()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4dActionInitialization::~B4dActionInitialization()
|
||||
{;}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dActionInitialization::BuildForMaster() const
|
||||
{
|
||||
SetUserAction(new B4RunAction);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dActionInitialization::Build() const
|
||||
{
|
||||
SetUserAction(new B4PrimaryGeneratorAction);
|
||||
SetUserAction(new B4RunAction);
|
||||
SetUserAction(new B4dEventAction);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,329 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4dDetectorConstruction.cc
|
||||
/// \brief Implementation of the B4dDetectorConstruction class
|
||||
|
||||
#include "B4dDetectorConstruction.hh"
|
||||
|
||||
#include "G4Material.hh"
|
||||
#include "G4NistManager.hh"
|
||||
|
||||
#include "G4Box.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4PVReplica.hh"
|
||||
#include "G4GlobalMagFieldMessenger.hh"
|
||||
#include "G4AutoDelete.hh"
|
||||
|
||||
#include "G4SDManager.hh"
|
||||
#include "G4SDChargedFilter.hh"
|
||||
#include "G4MultiFunctionalDetector.hh"
|
||||
#include "G4VPrimitiveScorer.hh"
|
||||
#include "G4PSEnergyDeposit.hh"
|
||||
#include "G4PSTrackLength.hh"
|
||||
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Colour.hh"
|
||||
|
||||
#include "G4PhysicalConstants.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4ThreadLocal
|
||||
G4GlobalMagFieldMessenger* B4dDetectorConstruction::fMagFieldMessenger = 0;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4dDetectorConstruction::B4dDetectorConstruction()
|
||||
: G4VUserDetectorConstruction(),
|
||||
fCheckOverlaps(true)
|
||||
{
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4dDetectorConstruction::~B4dDetectorConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4VPhysicalVolume* B4dDetectorConstruction::Construct()
|
||||
{
|
||||
// Define materials
|
||||
DefineMaterials();
|
||||
|
||||
// Define volumes
|
||||
return DefineVolumes();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dDetectorConstruction::DefineMaterials()
|
||||
{
|
||||
// Lead material defined using NIST Manager
|
||||
auto nistManager = G4NistManager::Instance();
|
||||
nistManager->FindOrBuildMaterial("G4_Pb");
|
||||
|
||||
// Liquid argon material
|
||||
G4double a; // mass of a mole;
|
||||
G4double z; // z=mean number of protons;
|
||||
G4double density;
|
||||
new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
|
||||
// The argon by NIST Manager is a gas with a different density
|
||||
|
||||
// Vacuum
|
||||
new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
|
||||
kStateGas, 2.73*kelvin, 3.e-18*pascal);
|
||||
|
||||
// Print materials
|
||||
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
|
||||
{
|
||||
// Geometry parameters
|
||||
G4int nofLayers = 10;
|
||||
G4double absoThickness = 10.*mm;
|
||||
G4double gapThickness = 5.*mm;
|
||||
G4double calorSizeXY = 10.*cm;
|
||||
|
||||
auto layerThickness = absoThickness + gapThickness;
|
||||
auto calorThickness = nofLayers * layerThickness;
|
||||
auto worldSizeXY = 1.2 * calorSizeXY;
|
||||
auto worldSizeZ = 1.2 * calorThickness;
|
||||
|
||||
// Get materials
|
||||
auto defaultMaterial = G4Material::GetMaterial("Galactic");
|
||||
auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
|
||||
auto gapMaterial = G4Material::GetMaterial("liquidArgon");
|
||||
|
||||
if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
|
||||
G4ExceptionDescription msg;
|
||||
msg << "Cannot retrieve materials already defined.";
|
||||
G4Exception("B4DetectorConstruction::DefineVolumes()",
|
||||
"MyCode0001", FatalException, msg);
|
||||
}
|
||||
|
||||
//
|
||||
// World
|
||||
//
|
||||
auto worldS
|
||||
= new G4Box("World", // its name
|
||||
worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
|
||||
|
||||
auto worldLV
|
||||
= new G4LogicalVolume(
|
||||
worldS, // its solid
|
||||
defaultMaterial, // its material
|
||||
"World"); // its name
|
||||
|
||||
auto 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 operation
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
//
|
||||
// Calorimeter
|
||||
//
|
||||
auto calorimeterS
|
||||
= new G4Box("Calorimeter", // its name
|
||||
calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
|
||||
|
||||
auto calorLV
|
||||
= new G4LogicalVolume(
|
||||
calorimeterS, // its solid
|
||||
defaultMaterial, // its material
|
||||
"Calorimeter"); // its name
|
||||
|
||||
new G4PVPlacement(
|
||||
0, // no rotation
|
||||
G4ThreeVector(), // at (0,0,0)
|
||||
calorLV, // its logical volume
|
||||
"Calorimeter", // its name
|
||||
worldLV, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
//
|
||||
// Layer
|
||||
//
|
||||
auto layerS
|
||||
= new G4Box("Layer", // its name
|
||||
calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
|
||||
|
||||
auto layerLV
|
||||
= new G4LogicalVolume(
|
||||
layerS, // its solid
|
||||
defaultMaterial, // its material
|
||||
"Layer"); // its name
|
||||
|
||||
new G4PVReplica(
|
||||
"Layer", // its name
|
||||
layerLV, // its logical volume
|
||||
calorLV, // its mother
|
||||
kZAxis, // axis of replication
|
||||
nofLayers, // number of replica
|
||||
layerThickness); // witdth of replica
|
||||
|
||||
//
|
||||
// Absorber
|
||||
//
|
||||
auto absorberS
|
||||
= new G4Box("Abso", // its name
|
||||
calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
|
||||
|
||||
auto absorberLV
|
||||
= new G4LogicalVolume(
|
||||
absorberS, // its solid
|
||||
absorberMaterial, // its material
|
||||
"AbsoLV"); // its name
|
||||
|
||||
new G4PVPlacement(
|
||||
0, // no rotation
|
||||
G4ThreeVector(0., 0., -gapThickness/2), // its position
|
||||
absorberLV, // its logical volume
|
||||
"Abso", // its name
|
||||
layerLV, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
//
|
||||
// Gap
|
||||
//
|
||||
auto gapS
|
||||
= new G4Box("Gap", // its name
|
||||
calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
|
||||
|
||||
auto gapLV
|
||||
= new G4LogicalVolume(
|
||||
gapS, // its solid
|
||||
gapMaterial, // its material
|
||||
"GapLV"); // its name
|
||||
|
||||
new G4PVPlacement(
|
||||
0, // no rotation
|
||||
G4ThreeVector(0., 0., absoThickness/2), // its position
|
||||
gapLV, // its logical volume
|
||||
"Gap", // its name
|
||||
layerLV, // its mother volume
|
||||
false, // no boolean operation
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
//
|
||||
// print parameters
|
||||
//
|
||||
G4cout
|
||||
<< G4endl
|
||||
<< "------------------------------------------------------------" << G4endl
|
||||
<< "---> The calorimeter is " << nofLayers << " layers of: [ "
|
||||
<< absoThickness/mm << "mm of " << absorberMaterial->GetName()
|
||||
<< " + "
|
||||
<< gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl
|
||||
<< "------------------------------------------------------------" << G4endl;
|
||||
|
||||
//
|
||||
// Visualization attributes
|
||||
//
|
||||
worldLV->SetVisAttributes (G4VisAttributes::GetInvisible());
|
||||
|
||||
auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
|
||||
simpleBoxVisAtt->SetVisibility(true);
|
||||
calorLV->SetVisAttributes(simpleBoxVisAtt);
|
||||
|
||||
//
|
||||
// Always return the physical World
|
||||
//
|
||||
return worldPV;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dDetectorConstruction::ConstructSDandField()
|
||||
{
|
||||
G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
|
||||
//
|
||||
// Scorers
|
||||
//
|
||||
|
||||
// declare Absorber as a MultiFunctionalDetector scorer
|
||||
//
|
||||
auto absDetector = new G4MultiFunctionalDetector("Absorber");
|
||||
G4SDManager::GetSDMpointer()->AddNewDetector(absDetector);
|
||||
|
||||
G4VPrimitiveScorer* primitive;
|
||||
primitive = new G4PSEnergyDeposit("Edep");
|
||||
absDetector->RegisterPrimitive(primitive);
|
||||
|
||||
primitive = new G4PSTrackLength("TrackLength");
|
||||
auto charged = new G4SDChargedFilter("chargedFilter");
|
||||
primitive ->SetFilter(charged);
|
||||
absDetector->RegisterPrimitive(primitive);
|
||||
|
||||
SetSensitiveDetector("AbsoLV",absDetector);
|
||||
|
||||
// declare Gap as a MultiFunctionalDetector scorer
|
||||
//
|
||||
auto gapDetector = new G4MultiFunctionalDetector("Gap");
|
||||
G4SDManager::GetSDMpointer()->AddNewDetector(gapDetector);
|
||||
|
||||
primitive = new G4PSEnergyDeposit("Edep");
|
||||
gapDetector->RegisterPrimitive(primitive);
|
||||
|
||||
primitive = new G4PSTrackLength("TrackLength");
|
||||
primitive ->SetFilter(charged);
|
||||
gapDetector->RegisterPrimitive(primitive);
|
||||
|
||||
SetSensitiveDetector("GapLV",gapDetector);
|
||||
|
||||
//
|
||||
// Magnetic field
|
||||
//
|
||||
// Create global magnetic field messenger.
|
||||
// Uniform magnetic field is then created automatically if
|
||||
// the field value is not zero.
|
||||
G4ThreeVector fieldValue;
|
||||
fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
|
||||
fMagFieldMessenger->SetVerboseLevel(1);
|
||||
|
||||
// Register the field messenger for deleting
|
||||
G4AutoDelete::Register(fMagFieldMessenger);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
/// \file B4dEventAction.cc
|
||||
/// \brief Implementation of the B4dEventAction class
|
||||
|
||||
#include "B4dEventAction.hh"
|
||||
#include "B4Analysis.hh"
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4Event.hh"
|
||||
#include "G4SDManager.hh"
|
||||
#include "G4HCofThisEvent.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
|
||||
#include "Randomize.hh"
|
||||
#include <iomanip>
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4dEventAction::B4dEventAction()
|
||||
: G4UserEventAction(),
|
||||
fAbsoEdepHCID(-1),
|
||||
fGapEdepHCID(-1),
|
||||
fAbsoTrackLengthHCID(-1),
|
||||
fGapTrackLengthHCID(-1)
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B4dEventAction::~B4dEventAction()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4THitsMap<G4double>*
|
||||
B4dEventAction::GetHitsCollection(G4int hcID,
|
||||
const G4Event* event) const
|
||||
{
|
||||
auto hitsCollection
|
||||
= static_cast<G4THitsMap<G4double>*>(
|
||||
event->GetHCofThisEvent()->GetHC(hcID));
|
||||
|
||||
if ( ! hitsCollection ) {
|
||||
G4ExceptionDescription msg;
|
||||
msg << "Cannot access hitsCollection ID " << hcID;
|
||||
G4Exception("B4dEventAction::GetHitsCollection()",
|
||||
"MyCode0003", FatalException, msg);
|
||||
}
|
||||
|
||||
return hitsCollection;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4double B4dEventAction::GetSum(G4THitsMap<G4double>* hitsMap) const
|
||||
{
|
||||
G4double sumValue = 0.;
|
||||
for ( auto it : *hitsMap->GetMap() ) {
|
||||
// hitsMap->GetMap() returns the map of std::map<G4int, G4double*>
|
||||
sumValue += *(it.second);
|
||||
}
|
||||
return sumValue;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dEventAction::PrintEventStatistics(
|
||||
G4double absoEdep, G4double absoTrackLength,
|
||||
G4double gapEdep, G4double gapTrackLength) const
|
||||
{
|
||||
// Print event statistics
|
||||
//
|
||||
G4cout
|
||||
<< " Absorber: total energy: "
|
||||
<< std::setw(7) << G4BestUnit(absoEdep, "Energy")
|
||||
<< " total track length: "
|
||||
<< std::setw(7) << G4BestUnit(absoTrackLength, "Length")
|
||||
<< G4endl
|
||||
<< " Gap: total energy: "
|
||||
<< std::setw(7) << G4BestUnit(gapEdep, "Energy")
|
||||
<< " total track length: "
|
||||
<< std::setw(7) << G4BestUnit(gapTrackLength, "Length")
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dEventAction::BeginOfEventAction(const G4Event* /*event*/)
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B4dEventAction::EndOfEventAction(const G4Event* event)
|
||||
{
|
||||
// Get hist collections IDs
|
||||
if ( fAbsoEdepHCID == -1 ) {
|
||||
fAbsoEdepHCID
|
||||
= G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
|
||||
fGapEdepHCID
|
||||
= G4SDManager::GetSDMpointer()->GetCollectionID("Gap/Edep");
|
||||
fAbsoTrackLengthHCID
|
||||
= G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
|
||||
fGapTrackLengthHCID
|
||||
= G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
|
||||
}
|
||||
|
||||
// Get sum values from hits collections
|
||||
//
|
||||
auto absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
|
||||
auto gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
|
||||
|
||||
auto absoTrackLength
|
||||
= GetSum(GetHitsCollection(fAbsoTrackLengthHCID, event));
|
||||
auto gapTrackLength
|
||||
= GetSum(GetHitsCollection(fGapTrackLengthHCID, event));
|
||||
|
||||
// get analysis manager
|
||||
auto analysisManager = G4AnalysisManager::Instance();
|
||||
|
||||
// fill histograms
|
||||
//
|
||||
analysisManager->FillH1(0, absoEdep);
|
||||
analysisManager->FillH1(1, gapEdep);
|
||||
analysisManager->FillH1(2, absoTrackLength);
|
||||
analysisManager->FillH1(3, gapTrackLength);
|
||||
|
||||
// fill ntuple
|
||||
//
|
||||
analysisManager->FillNtupleDColumn(0, absoEdep);
|
||||
analysisManager->FillNtupleDColumn(1, gapEdep);
|
||||
analysisManager->FillNtupleDColumn(2, absoTrackLength);
|
||||
analysisManager->FillNtupleDColumn(3, gapTrackLength);
|
||||
analysisManager->AddNtupleRow();
|
||||
|
||||
//print per event (modulo n)
|
||||
//
|
||||
auto eventID = event->GetEventID();
|
||||
auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
|
||||
if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
|
||||
G4cout << "---> End of event: " << eventID << G4endl;
|
||||
PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,82 @@
|
||||
# Macro file for the visualization setting for the initialization phase
|
||||
# of the B4 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 2.
|
||||
#
|
||||
# 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 1
|
||||
# (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
|
||||
Reference in New Issue
Block a user