Skip to content
Open
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
34 changes: 7 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(OpenCMSG4ver1)
cmake_minimum_required(VERSION 3.16...3.27)
project(OpenCMSG4)

list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})

#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
Expand Down Expand Up @@ -37,31 +36,11 @@ if(ROOT_FOUND)
endif()
include(${ROOT_USE_FILE})

#----------------------------------------------------------------------------
# Find Pythia6 (optional package)
#
find_package(Pythia6 QUIET)
if(PYTHIA6_FOUND)
message(STATUS "G4 Examples: Pythia6 found. --> HepMCEx01 example with Pythia6 enabled.")
add_definitions(-DG4LIB_USE_PYTHIA)
else()
set(PYTHIA6_LIBRARIES "")
endif()

#----------------------------------------------------------------------------
# GCC COMPILER FLAGS
#
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

SET(GCC_COMPILE_FLAGS "-Wshadow")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}")

#----------------------------------------------------------------------------
# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
#
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
include_directories(${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIR}
${HEPMC_INCLUDE_DIR})
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
Expand All @@ -72,8 +51,9 @@ file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
#
add_executable(OpenCMSG4 OpenCMSG4.cc ${sources} ${headers})
target_link_libraries(OpenCMSG4 ${Geant4_LIBRARIES}
${HEPMC_LIBRARIES} ${HEPMC_FIO_LIBRARIES}
${PYTHIA6_LIBRARIES} ${ROOT_LIBRARIES} gfortran)
${HEPMC_LIBRARIES}
${ROOT_LIBRARIES})


#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
Expand Down Expand Up @@ -110,7 +90,7 @@ endforeach()
# Add program to the project targets
# (this avoids the need of typing the program name after make)
#
add_custom_target(OpenCMSG4ver1 DEPENDS OpenCMSG4)
# add_custom_target(OpenCMSG4ver1 DEPENDS OpenCMSG4)

#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
Expand Down
25 changes: 22 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@ G4TARGET := $(name)
G4EXLIB := true

ifndef G4INSTALL
G4INSTALL = ../../..
G4INSTALL = ../../../../..
endif


.PHONY: all
all: lib bin

include $(G4INSTALL)/config/binmake.gmk

ifdef HEPMC_DIR
all : lib bin

include $(G4INSTALL)/config/binmake.gmk

INCFLAGS += -I$(HEPMC_DIR)/include

LDLIBS1 += -L$(HEPMC_DIR)/lib -lHepMC

FCFLAGS += -c


else

all:
@echo 'ERROR - HEPMC_DIR not defined in the environment !'
@echo ' Requires HepMC release 1.27.'
endif


visclean:
rm -f g4*.prim g4*.eps g4*.wrl
Expand Down
6 changes: 4 additions & 2 deletions exampleRun_hepmc.mac
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#/vis/ogl/set/displayListLimit 10000000000
#/vis/viewer/set/viewpointThetaPhi 65 315 deg

/detector/sensitiveMaterialOnly false
/run/numberOfThreads 1

#/detector/sensitiveMaterialOnly false
/detector/trackerMode 111111
/detector/ecalMode 111

Expand All @@ -10,6 +12,6 @@
/generator hepmc
/hepmcAscii/verbose 0
/hepmcAscii/open example_MyPythia.dat
/analysis/setFileName OpenCMSG4_hepmc.root
/root/setFileName OpenCMSG4_particle.root

/run/beamOn 10
4 changes: 3 additions & 1 deletion exampleRun_particle.mac
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#/vis/ogl/set/displayListLimit 10000000000
#/vis/viewer/set/viewpointThetaPhi 65 315 deg

/run/numberOfThreads 1

/detector/trackerSensitiveMaterialOnly false
/detector/trackerMode 111111
/detector/ecalMode 111
Expand All @@ -20,4 +22,4 @@
/generator/particle/sigmaEta 0
/root/setFileName OpenCMSG4_particle.root

/run/beamOn 100
/run/beamOn 10
3 changes: 2 additions & 1 deletion include/Analysis.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef Analysis_h
#define Analysis_h 1

#include "g4root.hh"
#include "G4AnalysisManager.hh"
// #include "g4root.hh"
//#include "g4xml.hh"
//#include "g4csv.hh"

Expand Down
4 changes: 2 additions & 2 deletions include/CustomParticleFactory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class CustomParticleFactory
{
private:
static bool loaded;
static std::set<G4ParticleDefinition *> m_particles;
static thread_local bool loaded;
static thread_local std::set<G4ParticleDefinition *> m_particles;

public:
static void loadCustomParticles();
Expand Down
4 changes: 2 additions & 2 deletions include/FullModelHadronicProcess.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private:

G4double GetMeanFreePath(const G4Track& aTrack, G4double, G4ForceCondition*);

void CalculateMomenta( G4FastVector<G4ReactionProduct,256> &vec,
void CalculateMomenta( std::vector<G4ReactionProduct*> &vec,
G4int &vecLen,
const G4HadProjectile *originalIncident,
const G4DynamicParticle *originalTarget,
Expand All @@ -58,7 +58,7 @@ private:
const G4ReactionProduct &targetParticle,
G4ReactionProduct &leadParticle );

void Rotate(G4FastVector<G4ReactionProduct,256> &vec, G4int &vecLen);
void Rotate(std::vector<G4ReactionProduct*> &vec, G4int &vecLen);

const G4DynamicParticle* FindRhadron(G4ParticleChange*);

Expand Down
51 changes: 22 additions & 29 deletions include/HepMCAsciiReader.hh
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
#ifndef _HEPMC_ASCII_READER_H
#define _HEPMC_ASCII_READER_H
#ifndef HEPMC_ASCII_READER_H
#define HEPMC_ASCII_READER_H

#include "G4VPrimaryGenerator.hh"
#include "HepMC/IO_GenEvent.h"
#include "HepMCG4Interface.hh"

class HepMCAsciiReaderMessenger;

class HepMCAsciiReader : public G4VPrimaryGenerator
class HepMCAsciiReader : public HepMCG4Interface
{
public:
HepMCAsciiReader();
~HepMCAsciiReader();
protected:
G4String filename;
HepMC::IO_GenEvent* asciiInput;

protected:
G4String filename;
G4int verbose;
HepMCAsciiReaderMessenger* messenger;
G4int verbose;
HepMCAsciiReaderMessenger* messenger;

HepMC::IO_GenEvent* asciiInput;
HepMC::GenEvent* hepmcevt;
virtual G4bool CheckVertexInsideWorld(const G4ThreeVector& pos) const;
virtual HepMC::GenEvent* GenerateHepMCEvent();
void HepMC2G4(const HepMC::GenEvent* hepmcevt, G4Event* event);
virtual HepMC::GenEvent* GenerateHepMCEvent();

public:
virtual void GeneratePrimaryVertex(G4Event * event);
public:
HepMCAsciiReader();
~HepMCAsciiReader();

// set/get methods
void SetFileName(G4String name);
G4String GetFileName() const;
// set/get methods
void SetFileName(G4String name);
G4String GetFileName() const;

void SetVerboseLevel(G4int i);
G4int GetVerboseLevel() const;

// methods...
void Initialize();
void SetVerboseLevel(G4int i);
G4int GetVerboseLevel() const;

// methods...
void Initialize();
};


// ====================================================================
// inline functions
// ====================================================================

inline void HepMCAsciiReader::SetFileName(G4String name)
{
filename= name;
filename = name;
}

inline G4String HepMCAsciiReader::GetFileName() const
Expand All @@ -55,7 +48,7 @@ inline G4String HepMCAsciiReader::GetFileName() const

inline void HepMCAsciiReader::SetVerboseLevel(G4int i)
{
verbose= i;
verbose = i;
}

inline G4int HepMCAsciiReader::GetVerboseLevel() const
Expand Down
28 changes: 14 additions & 14 deletions include/HepMCAsciiReaderMessenger.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef HEPMC_G4_ASCII_READER_MESSENGER_H
#define HEPMC_G4_ASCII_READER_MESSENGER_H
#ifndef HEPMC_ASCII_READER_MESSENGER_H
#define HEPMC_ASCII_READER_MESSENGER_H

#include "G4UImessenger.hh"

Expand All @@ -9,21 +9,21 @@ class G4UIcmdWithoutParameter;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;

class HepMCAsciiReaderMessenger : public G4UImessenger {
public:
HepMCAsciiReaderMessenger(HepMCAsciiReader* agen);
~HepMCAsciiReaderMessenger();
class HepMCAsciiReaderMessenger : public G4UImessenger
{
public:
HepMCAsciiReaderMessenger(HepMCAsciiReader* agen);
~HepMCAsciiReaderMessenger();

void SetNewValue(G4UIcommand* command, G4String newValues);
G4String GetCurrentValue(G4UIcommand* command);
void SetNewValue(G4UIcommand* command, G4String newValues);
G4String GetCurrentValue(G4UIcommand* command);

private:
HepMCAsciiReader* gen;

G4UIdirectory* dir;
G4UIcmdWithAnInteger* verbose;
G4UIcmdWithAString* open;
private:
HepMCAsciiReader* gen;

G4UIdirectory* dir;
G4UIcmdWithAnInteger* verbose;
G4UIcmdWithAString* open;
};

#endif
50 changes: 50 additions & 0 deletions include/HepMCG4Interface.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef HEPMC_G4_INTERFACE_H
#define HEPMC_G4_INTERFACE_H

#include "HepMC/GenEvent.h"

#include "G4VPrimaryGenerator.hh"

/// A base class for primary generation via HepMC object.
/// This class is derived from G4VPrimaryGenerator.

class HepMCG4Interface : public G4VPrimaryGenerator
{
protected:
// Note that the life of HepMC event object must be handled by users.
// In the default implementation, a current HepMC event will be
// deleted at GeneratePrimaryVertex() in the next event.
HepMC::GenEvent* hepmcEvent; // (care for single event case only)

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

// service method for conversion from HepMC::GenEvent to G4Event
void HepMC2G4(const HepMC::GenEvent* hepmcevt, G4Event* g4event);

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

public:
HepMCG4Interface();
virtual ~HepMCG4Interface();

// set/get methods
HepMC::GenEvent* GetHepMCGenEvent() const;

// The default behavior is that a single HepMC event generated by
// GenerateHepMCEvent() will be converted to G4Event through HepMC2G4().
virtual void GeneratePrimaryVertex(G4Event* anEvent);
};

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline HepMC::GenEvent* HepMCG4Interface::GetHepMCGenEvent() const
{
return hepmcEvent;
}

#endif
Loading