Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Streamline simulation in preparation for new features #191

Closed
Closed
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ option(FALAISE_WITH_DOCS "Build documentation for Falaise" ON)
# - ROOT
# - Geant4
set(FALAISE_BAYEUX_MIN_VERSION 3.4.1)
find_package(Bayeux ${FALAISE_BAYEUX_MIN_VERSION} REQUIRED geant4)
find_package(Bayeux ${FALAISE_BAYEUX_MIN_VERSION}) #REQUIRED geant4)

#-----------------------------------------------------------------------
# Build the subdirectories as required
Expand Down
1 change: 1 addition & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ add_subdirectory(ChargedParticleTracking)
add_subdirectory(GammaTracking)
add_subdirectory(GammaClustering)
add_subdirectory(things2root)
add_subdirectory(SNSimulation)

102 changes: 102 additions & 0 deletions modules/SNSimulation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
cmake_minimum_required(VERSION 3.3)
project(SNSimulation)

find_package(Geant4 REQUIRED gdml)
find_package(Boost REQUIRED thread)
if(Geant4_DATASETS)
set(MCTOOLS_G4_DATA_ASSIGNMENTS)
foreach(_ds ${Geant4_DATASETS})
list(APPEND MCTOOLS_G4_DATA_ASSIGNMENTS "(\"${Geant4_DATASET_${_ds}_ENVVAR}\", \"${Geant4_DATASET_${_ds}_PATH}\")")
endforeach()
string(REPLACE ";" "" MCTOOLS_G4_DATA_ASSIGNMENTS ${MCTOOLS_G4_DATA_ASSIGNMENTS})
endif()

configure_file(snsim/data_libraries.h.in snsim/data_libraries.h @ONLY)

add_library(SNSimulation SHARED
snsim/base_physics_constructor.h
snsim/biasing_manager.h
snsim/detector_construction.h
snsim/electromagnetic_field.h
snsim/em_field_equation_of_motion.h
snsim/em_field_g4_stuff.h
snsim/em_field_g4_utils.h
snsim/em_physics_constructor.h
snsim/event_action.h
snsim/g4_prng.h
snsim/loggable_support.h
snsim/magnetic_field.h
snsim/manager.h
snsim/manager_parameters.h
snsim/neutrons_physics_constructor.h
snsim/particles_physics_constructor.h
snsim/physics_list.h
snsim/physics_list_utils.h
snsim/primary_generator.h
snsim/region_tools.h
snsim/run_action.h
snsim/sensitive_detector.h
snsim/sensitive_hit.h
snsim/sensitive_hit_collection.h
snsim/simulation_ctrl.h
snsim/simulation_module.h
snsim/stacking_action.h
snsim/stepping_action.h
snsim/stepping_verbose.h
snsim/track_history.h
snsim/tracking_action.h
snsim/processes/em_extra_models.h
snsim/processes/em_model_factory.h
snsim/processes/utils.h

src/base_physics_constructor.cc
src/biasing_manager.cc
src/detector_construction.cc
src/electromagnetic_field.cc
src/em_field_equation_of_motion.cc
src/em_field_g4_stuff.cc
src/em_physics_constructor.cc
src/event_action.cc
src/g4_prng.cc
src/loggable_support.cc
src/magnetic_field.cc
src/manager.cc
src/manager_parameters.cc
src/neutrons_physics_constructor.cc
src/particles_physics_constructor.cc
src/physics_list.cc
src/physics_list_utils.cc
src/primary_generator.cc
src/region_tools.cc
src/run_action.cc
src/sensitive_detector.cc
src/sensitive_hit.cc
src/sensitive_hit_collection.cc
src/simulation_ctrl.cc
src/simulation_module.cc
src/stacking_action.cc
src/stepping_action.cc
src/stepping_verbose.cc
src/track_history.cc
src/tracking_action.cc
src/processes/em_extra_models.cc
src/processes/em_model_factory.cc
src/processes/utils.cc)

add_library(SNSimulation::SNSimulation ALIAS SNSimulation)

target_include_directories(SNSimulation PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
${Geant4_INCLUDE_DIRS})

# Hack - strip "-D" flag as we should only supply the def names
set(SNSimulation_DEFINITIONS)
foreach(_def ${Geant4_DEFINITIONS})
string(REGEX REPLACE "^-D" "" _bxdef ${_def})
list(APPEND SNSimulation_DEFINITIONS ${_bxdef})
endforeach()

set_target_properties(SNSimulation PROPERTIES COMPILE_DEFINITIONS "${SNSimulation_DEFINITIONS}")
target_link_libraries(SNSimulation PUBLIC Falaise Bayeux::Bayeux ${Geant4_LIBRARIES} Boost::thread)
target_clang_format(SNSimulation)
125 changes: 125 additions & 0 deletions modules/SNSimulation/snsim/base_physics_constructor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/// \file snsim/base_physics_constructor.h
/* Author(s) : Francois Mauger <[email protected]>
* Creation date: 2013-07-03
* Last modified: 2015-04-30
*
* License: GPL3
*
* Description:
*
* Base class for physics constructors
*
*/

#ifndef SNSIM_BASE_PHYSICS_CONSTRUCTOR_H
#define SNSIM_BASE_PHYSICS_CONSTRUCTOR_H 1

// Standard library:
#include <map>
#include <string>

// Third party:
// - Bayeux/datatools :
#include <bayeux/datatools/factory_macros.h>
#include <bayeux/datatools/i_tree_dump.h>
// - Geant4
#include <G4VPhysicsConstructor.hh>
#include <globals.hh>

// This project:
#include <snsim/loggable_support.h>
#include <snsim/physics_list_utils.h>

namespace snsim {

// Forward class declaration:
class physics_list;

std::string g4_builder_type_to_label(int);

int label_to_g4_builder_type(const std::string &label_);

/// \brief Base class for G4-based physics constructor with factory registration support
class base_physics_constructor : public G4VPhysicsConstructor,
public datatools::i_tree_dumpable,
public loggable_support {
public:
/// Check initialization status
bool is_initialized() const;

/// Set the name of the physics constructor
void set_name(const std::string &name_);

/// Return the name of the physics constructor
const std::string &get_name() const;

/// Set the class unique identifier of the physics constructor
void set_class_id(const std::string &class_id_);

/// Return the class unique identifier of the physics constructor
const std::string &get_class_id() const;

/// Default constructor
base_physics_constructor();

/// Desctructor
virtual ~base_physics_constructor();

/// Initialization from a set of configuration properties and a dictionary of physics constructors
virtual void initialize(const datatools::properties &config_,
physics_constructor_dict_type &dict_) = 0;

/// Initialization from a set of configuration properties
void initialize_standalone(const datatools::properties &config_);

/// Reset
virtual void reset() = 0;

// G4 mandatory interface: construct particle and physics

/// Construct the Geant4 particle list
virtual void ConstructParticle(); // Default empty implementation

/// Construct the Geant4 processes list
virtual void ConstructProcess(); // Default empty implementation

/// Check if the constructor has a mother physics list
bool has_mother_physics_list() const;

/// Return a const reference to the mother physics list (if any)
const physics_list &get_mother_physics_list() const;

/// Smart print
virtual void tree_dump(std::ostream &out_ = std::clog, const std::string &title_ = "",
const std::string &indent_ = "", bool inherit_ = false) const;

protected:
void _set_initialized(bool);

void _set_mother_physics_list(physics_list &);

void _reset();

private:
std::string _name_; //!< Name of the physics constructor
std::string _class_id_; //!< Class ID of the physics constructor
bool _initialized_; //!< Initialization flag
physics_list *_mother_physics_list_ = nullptr; //!< Reference to the mother physics list

// Factory registration system :
DATATOOLS_FACTORY_SYSTEM_REGISTER_INTERFACE(base_physics_constructor)

friend class physics_list;
};

} // namespace snsim

#endif // SNSIM_BASE_PHYSICS_CONSTRUCTOR_H

/*
** Local Variables: --
** mode: c++ --
** c-file-style: "gnu" --
** tab-width: 2 --
** End: --
*/
78 changes: 78 additions & 0 deletions modules/SNSimulation/snsim/biasing_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/// \file snsim/biasing_manager.h
/* Author(s) : Arnaud Chapon <[email protected]>
* François Mauger <[email protected]>
* Creation date: 2014-11-20
* Last modified: 2014-11-20
*
* License:
*
* Description:
*
* GEANT 4 biasing manager
*
* History:
*
*/

#ifndef SNSIM_BIASING_MANAGER_H
#define SNSIM_BIASING_MANAGER_H 1

// Standard library:
#include <string>
// #include <map>
// #include <vector>

// Third party:
// - Bayeux/datatools :
#include <bayeux/datatools/logger.h>

namespace datatools {
// Forward declaration:
class properties;
} // namespace datatools

namespace snsim {

// Forward declaration:
class detector_construction;

/// \brief Manager for Geant4 biasing algorithm associated to elements of the geometry
class biasing_manager {
public:
/// Default constructor
biasing_manager();

/// Destructor
virtual ~biasing_manager();

/// Set the reference to the parent detector construction
void set_detector_construction(detector_construction &dc_);

/// Check initialization flag
bool is_initialized() const;

/// Initialize from a container of properties
void initialize(const datatools::properties &);

// Reset
void reset();

protected:
void _set_default();

private:
bool _initialized_; //!< Initialization flag
detector_construction *_dc_; //!< Handle to the parent detector construction
};

} // namespace snsim

#endif // SNSIM_BIASING_MANAGER_H

/*
** Local Variables: --
** mode: c++ --
** c-file-style: "gnu" --
** tab-width: 2 --
** End: --
*/
75 changes: 75 additions & 0 deletions modules/SNSimulation/snsim/data_libraries.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! \file mctools/g4/data_libraries.h
//! \brief Configure the Geant4 data libraries
//! \details Geant4 physics models use several architecture independent
//! data files for cross-sections and other process dependent
//! information. Geant4 determines the root location of each
//! data source via environment variables whose value is
//! the absolute path to the resource.
//! We can generally determine the path to these files at
//! MCTools configure time, so provide an interface that can be
//! used to set up the environment inside the application,
//! unless it is already set.
//! NB: This file is not part of the public interface
//
// This file is part of MCTools.
//
// MCTools is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MCTools is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MCTools. If not, see <http://www.gnu.org/licenses/>.

#ifndef MCTOOLS_G4_DATA_LIBRARIES_H
#define MCTOOLS_G4_DATA_LIBRARIES_H

// Standard Library
#include <cstdlib>

// Third Party
// - Boost
#include <boost/assign/list_inserter.hpp>

// This Project

namespace {
class geant4_data_library {
public:

public:
geant4_data_library() : map_() {
boost::assign::insert(map_)@MCTOOLS_G4_DATA_ASSIGNMENTS@;
}

~geant4_data_library() {}

void configure_data() const {
DLMap::const_iterator iter(map_.begin());
DLMap::const_iterator end(map_.end());

for(; iter!=end; ++iter) {
setenv((*iter).first.c_str(),(*iter).second.c_str(),0);
}
}

private:
typedef std::map<std::string,std::string> DLMap;
DLMap map_;
};
}

#endif // MCTOOLS_G4_DATA_LIBRARIES_H

/*
** Local Variables: --
** mode: c++ --
** c-file-style: "gnu" --
** tab-width: 2 --
** End: --
*/
Loading