Skip to content

Hepmc3 examples #18

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/extended/eventgenerator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ else()
message(STATUS "G4 Examples: HepMC package not found. --> HepMC examples disabled.")
endif()

#----------------------------------------------------------------------------
# HepMC3 examples require HepMC3
#
find_package(HepMC3 QUIET)
if(HEPMC3_FOUND)
add_subdirectory(HepMC3)
else()
message(STATUS "G4 Examples: HepMC3 package not found. --> HepMC3 examples disabled.")
endif()

#----------------------------------------------------------------------------
# decayer6 example requires Pythia6
#
Expand Down
120 changes: 120 additions & 0 deletions examples/extended/eventgenerator/HepMC3/.README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

///\file "eventgenerator/HepMC/.README.txt"
///\brief Examples HepMC README page

/*! \page Examples_HepMC Category "eventgenerator/HepMC"

This directory contains examples for using HepMC as an interface with
various Monte Carlo event generators, such as PYTHIA.
It also include an example for demonstrating MC truth handling with HepMC.

\section HepMC_s1 Requirements for external software packages

\subsection HepMC_sub_s11 HepMC
- Tested version : 2.06.09
- http://lcgapp.cern.ch/project/simu/HepMC/

Note: examples were tested only on Linux with gcc.

\subsection HepMC_sub_s12 PYTHIA
- Tested version 6.4.26
- URL: http://www.thep.lu.se/~torbjorn/Pythia.html


\section HepMC_s2 Examples HepMCEx01 and HepMCEx02

\subsection HepMC_sub_s21 class HepMCG4Interface
This class is derived from G4VPrimaryGenerator, and is a base class
for primary generation via HepMC object.

protected members:

- virtual HepMC::GenEvent* GenerateHepMCEvent() \n
Implement this method in his/her own concrete class.
An empty event will be created in default.

- void HepMC2G4(const HepMC::GenEvent* hepmcevt, G4Event* g4event) \n
service method for conversion from HepMC::GenEvent to G4Event

- virtual G4bool CheckVertexInsideWorld(const G4ThreeVector& pos) const \n
We have to take care for the position of primaries because
primary vertices outside the world volume give rise to G4Exception.
If the default implementation is not adequate, an alternative
can be implemented in your own class.

public members:
- virtual void GeneratePrimaryVertex(G4Event* anEvent) \n
The default behavior is that a single HepMC event generated by
GenerateHepMCEvent() will be converted to G4Event through HepMC2G4().

\subsection HepMC_sub_s22 class HepMCG4AsciiReader / HepMCG4AsciiReaderMessenger (derived from HepMCG4Interface)
This derived class is for reading primary information from
an Ascii file generated by HepMC.

\subsection HepMC_sub_s23 class HepMCG4PythiaInterface / HepMCG4AsciiReaderMessenger (derived from HepMCG4Interface)
This derived class is for directly calling PYTHIA functions.
Users can set parameters, initialize, generate, and terminate
by command line operation.

\subsection HepMC_sub_s24 Macros in examples

- hepmc_pygen.in \n
process PYTHIA events(H->4mu) generated at every event.

- hepmc_ascii.in \n
read pregenerated events from HepMC Ascii file (data/example_MyPythia.dat).

\subsection HepMC_sub_s25 Installation

- 1. Download and install HepMC from: \n
http://lcgapp.cern.ch/project/simu/HepMC/ \n
and define the environment variable:
\verbatim
HEPMC_DIR the path to HepMC installation.
\endverbatim

- 2. Download the PYTHIA6 source file from the PYTHIA6 download site:\n
http://www.hepforge.org/downloads/pythia6

- 2A. With CMake: Build pythia6 library

For a convenience a CMake file for building Pythia6 library from
the source is provided in
examples/extended/eventgenerator/CMakeLists.txt.pythia6.
Build the pythia6 library following the instructions in this file
and then define the environment variables:
\verbatim
PYTHIA6 the path where pythia6 library is installed
PYTHIA6_VERSION the pythia version
\endverbatim

- 2B. With GNUmake: Define the environment variables: \n
\verbatim
PYTHIA6 the path to pythia-versionX.f source code
PYTHIA6_VERSION the pythia version
\endverbatim

e.g. If you download pythia-6.4.26.f.gz and unzip it in $HOME,
then you have to set:
export PYTHIA6=$HOME
export PYTHIA6_VERSION="6.4.26"

pythia6 will be then compiled together with example code.

- 3. Compilation:\n
Then the examples are compiled in a standard way, see \ref README_HowToRun.

\subsection HepMC_sub_s26 Examples

See more details in \ref ExampleHepMCEx01 and \ref ExampleHepMCEx02.

\subsection HepMC_sub_s27 Notes

We attached a sample HepMC Ascii data file, "data/example_MyPythia.dat",
which contains 10 PYTHIA events created by "data/example_MyPythia.cxx".

\section HepMC_s3 Example MCTruth

Application \link ExampleMCTruth MCTruth \endlink demonstrating handling of Monte-Carlo truth information through the HepMC3 package.

*/
19 changes: 19 additions & 0 deletions examples/extended/eventgenerator/HepMC3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#---Adding all HepMC3 examples subdirectories explicitly

cmake_minimum_required(VERSION 3.8...3.18)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
find_package(Geant4)
include(${Geant4_USE_FILE})

#----------------------------------------------------------------------------
# HepMC examples require HepMC
#
find_package(HepMC3 REQUIRED)

add_subdirectory(HepMCEx01)
add_subdirectory(HepMCEx02)
add_subdirectory(MCTruth)
56 changes: 56 additions & 0 deletions examples/extended/eventgenerator/HepMC3/HepMCEx01/.README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

///\file "eventgenerator/HepMC/HepMCEx01/.README.txt"
///\brief Example HepMCEx01 README page

/*! \page ExampleHepMCEx01 Example HepMCEx01

HepMCEx01 is based on Example N04, which has a simplified collider detector
geometry. Only part of the primary generator action is replaced with new one.
This example demonstrates the following features.

\section ExampleHepMCEx01_s1 HepMC interface

ExN04PrimaryGeneratorAction has HepMCG4Interface as the generator.
There are two types of generators provided as samples. One generator reads
primary information from a HepMC Ascii file (data/example_MyPythia.dat).
The other one generates primaries directly invoking PYTHIA routines
in every event.

\section ExampleHepMCEx01_s2 Readout geometry

ExN04DetectorConstruction defines a simplified collider detecor
geometry, tracker made of cylindrical tubes, calorimeter made of
cylindrical tubes, and muon trackers made of planes.
Cylindrical calorimeter is made of tubes of lead and scintirator
without cut in phi nor z direction. Energy deposition in scintirator
is accumulated by ExN04CalorimeterSD sensitive detector, which has
a readout geometry to find the phi-z cell.

\section ExampleHepMCEx01_s3 Full set of "ordinary" physics processes

FTFP_BERT physics list defines almost all of leptons and hadrons which
Geant4 has dedicated classes for. Also almost all physics processes
Geant4 has are defined.

\section ExampleHepMCEx01_s4 Event filtering by the stacking mechanism.

Higgs events in "pythia_event.data" have two lepton pairs produced
by the Higgs decay via Z0. At the first stage of each event, only the
primary muons are tracked without tracking secondaries. then the number
of hits on the muon trackers are examined. At the next stage, only
the primary charged particles are tracked only inside the barrel
tracking area and the isolation of the primary muons are examined.
At the third stage, all particles in the RoI (Region of Interest) along
the isolated muons are tracked. All these examinations are applied in
ExN04StackingAction.

\section ExampleHepMCEx01_s5 Installation

See \ref Examples_HepMC how to build this example.

\section ExampleHepMCEx01_s6 Execution
\verbatim
% HepMCEx01 hepmc_pygen.in
\endverbatim

*/
162 changes: 162 additions & 0 deletions examples/extended/eventgenerator/HepMC3/HepMCEx01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 3.8...3.18)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
project(HepMCEx01)

#----------------------------------------------------------------------------
# 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
#
include(${Geant4_USE_FILE})

#----------------------------------------------------------------------------
# Find HepMC3 (required package)
#

add_definitions(-DG4LIB_USE_HEPMC3)
find_package(HepMC3 REQUIRED)
set (EVENT_RECORD_INCLUDE_DIR ${HEPMC3_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/external)
set (EVENT_RECORD_LIBRARIES ${HEPMC3_LIB})
set (interface_sources
${PROJECT_SOURCE_DIR}/src/HepMC3G4AsciiReader.cc
${PROJECT_SOURCE_DIR}/src/HepMC3G4AsciiReaderMessenger.cc
${PROJECT_SOURCE_DIR}/src/HepMC3G4Interface.cc
${PROJECT_SOURCE_DIR}/src/HepMC3G4PythiaInterface.cc
${PROJECT_SOURCE_DIR}/src/HepMC3G4PythiaMessenger.cc
)

#----------------------------------------------------------------------------
# Find Pythia6 (optional package)
#
find_package(Pythia6)
include(CheckLanguage)
check_language(Fortran)
if(PYTHIA6_FOUND AND CMAKE_Fortran_COMPILER)
message(STATUS "G4 Examples: Pythia6 found. --> HepMCEx01 example with Pythia6 enabled.")
add_definitions(-DG4LIB_USE_PYTHIA)
enable_language(Fortran)
message(STATUS "Fortran compiler found Pythia6 were found ${Fortran_COMPILER_NAME} ")
set( GENERATOR_LIBRARIES ${PYTHIA6_LIBRARIES} LHAPDF gfortran)
set (generator_sources
#${PROJECT_SOURCE_DIR}/external/upevnt.F
#${PROJECT_SOURCE_DIR}/external/upinit.F
#${PROJECT_SOURCE_DIR}/external/upveto.F
)

else()
set(GENERATOR_LIBRARIES "")
set (generator_sources "")
endif()

#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIR}
${EVENT_RECORD_INCLUDE_DIR})
set(sources
${PROJECT_SOURCE_DIR}/src/ExN04CalorimeterHit.cc
${PROJECT_SOURCE_DIR}/src/ExN04CalorimeterParametrisation.cc
${PROJECT_SOURCE_DIR}/src/ExN04CalorimeterROGeometry.cc
${PROJECT_SOURCE_DIR}/src/ExN04CalorimeterSD.cc
${PROJECT_SOURCE_DIR}/src/ExN04DetectorConstruction.cc
${PROJECT_SOURCE_DIR}/src/ExN04DetectorParameterDef.icc
${PROJECT_SOURCE_DIR}/src/ExN04EventAction.cc
${PROJECT_SOURCE_DIR}/src/ExN04Field.cc
${PROJECT_SOURCE_DIR}/src/ExN04MuonHit.cc
${PROJECT_SOURCE_DIR}/src/ExN04MuonSD.cc
${PROJECT_SOURCE_DIR}/src/ExN04PrimaryGeneratorAction.cc
${PROJECT_SOURCE_DIR}/src/ExN04PrimaryGeneratorMessenger.cc
${PROJECT_SOURCE_DIR}/src/ExN04RunAction.cc
${PROJECT_SOURCE_DIR}/src/ExN04StackingAction.cc
${PROJECT_SOURCE_DIR}/src/ExN04StackingActionMessenger.cc
${PROJECT_SOURCE_DIR}/src/ExN04SteppingAction.cc
${PROJECT_SOURCE_DIR}/src/ExN04SteppingVerbose.cc
${PROJECT_SOURCE_DIR}/src/ExN04TrackerHit.cc
${PROJECT_SOURCE_DIR}/src/ExN04TrackerParametrisation.cc
${PROJECT_SOURCE_DIR}/src/ExN04TrackerSD.cc
${PROJECT_SOURCE_DIR}/src/ExN04TrackingAction.cc
)


set( headers
${PROJECT_SOURCE_DIR}/include/ExN04CalorimeterHit.hh
${PROJECT_SOURCE_DIR}/include/ExN04Field.hh
${PROJECT_SOURCE_DIR}/include/ExN04SteppingAction.hh
${PROJECT_SOURCE_DIR}/include/ExN04CalorimeterParametrisation.hh
${PROJECT_SOURCE_DIR}/include/ExN04MuonHit.hh
${PROJECT_SOURCE_DIR}/include/ExN04SteppingVerbose.hh
${PROJECT_SOURCE_DIR}/include/ExN04CalorimeterROGeometry.hh
${PROJECT_SOURCE_DIR}/include/ExN04MuonSD.hh
${PROJECT_SOURCE_DIR}/include/ExN04TrackerHit.hh
${PROJECT_SOURCE_DIR}/include/ExN04CalorimeterSD.hh
${PROJECT_SOURCE_DIR}/include/ExN04PrimaryGeneratorAction.hh
${PROJECT_SOURCE_DIR}/include/ExN04TrackerParametrisation.hh
${PROJECT_SOURCE_DIR}/include/ExN04DetectorConstruction.hh
${PROJECT_SOURCE_DIR}/include/ExN04PrimaryGeneratorMessenger.hh
${PROJECT_SOURCE_DIR}/include/ExN04TrackerSD.hh
${PROJECT_SOURCE_DIR}/include/ExN04DetectorParameterDef.hh
${PROJECT_SOURCE_DIR}/include/ExN04RunAction.hh
${PROJECT_SOURCE_DIR}/include/ExN04TrackingAction.hh
${PROJECT_SOURCE_DIR}/include/ExN04DummySD.hh
${PROJECT_SOURCE_DIR}/include/ExN04StackingAction.hh
${PROJECT_SOURCE_DIR}/include/ExN04EventAction.hh
${PROJECT_SOURCE_DIR}/include/ExN04StackingActionMessenger.hh

${PROJECT_SOURCE_DIR}/include/HepMCG4Interface.hh
${PROJECT_SOURCE_DIR}/include/HepMCG4AsciiReaderMessenger.hh
${PROJECT_SOURCE_DIR}/include/HepMC3G4AsciiReader.hh
${PROJECT_SOURCE_DIR}/include/HepMCG4PythiaInterface.hh
${PROJECT_SOURCE_DIR}/include/HepMC3G4AsciiReaderMessenger.hh
${PROJECT_SOURCE_DIR}/include/HepMCG4PythiaMessenger.hh
${PROJECT_SOURCE_DIR}/include/HepMCG4AsciiReader.hh
${PROJECT_SOURCE_DIR}/include/HepMC3G4PythiaMessenger.hh
${PROJECT_SOURCE_DIR}/include/HepMC3G4PythiaInterface.hh
${PROJECT_SOURCE_DIR}/include/HepMC3G4Interface.hh
)

#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(HepMCEx01 HepMCEx01.cc ${sources} ${generator_sources} ${interface_sources} ${headers})
target_link_libraries(HepMCEx01 ${Geant4_LIBRARIES}
${EVENT_RECORD_LIBRARIES}
${GENERATOR_LIBRARIES})

#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build HepMCEx01. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.
#
set(HepMCEx01_SCRIPTS
hepmc_ascii.in hepmc_ascii.out hepmc_pygen.in hepmc_pygen.out pyh4mu.mac pyset.mac vis.mac
data/example_MyPythia.dat
)

foreach(_script ${HepMCEx01_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 HepMCEx01 DESTINATION bin)

Loading