diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index da5eedb165f0a1c2f552c4c72c6da4bb7f02bd14..d0745f3ce188694dd735f3b86d0ee6717365bd5c 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -16,10 +16,6 @@ if(NOT DD4HEP_USE_XERCESC) list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/src/Geant4XML.cpp) endif() SET( CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wno-long-long") - -#--------------------------- Main geant4 interface library (no plugins!)----------- -root_generate_dictionary( G__DDG4 ${CMAKE_CURRENT_SOURCE_DIR}/python/DDG4Dict.C LINKDEF ${CMAKE_SOURCE_DIR}/DDCore/include/ROOT/LinkDef.h) -list(APPEND sources G__DDG4.cxx) # add_library(DD4hepG4 SHARED ${sources}) target_link_libraries(DD4hepG4 DD4hepCore ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) @@ -34,8 +30,11 @@ target_link_libraries(DD4hepG4Legacy DD4hepCore DD4hepG4 ${ROOT_LIBRARIES} Refle SET_TARGET_PROPERTIES(DD4hepG4Legacy PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION}) dd4hep_generate_rootmap(DD4hepG4Legacy) +#--------------------------- Main geant4 interface library (no plugins!)----------- +root_generate_dictionary( G__DDG4 ${CMAKE_CURRENT_SOURCE_DIR}/python/DDG4Dict.C LINKDEF ${CMAKE_SOURCE_DIR}/DDCore/include/ROOT/LinkDef.h) #--------------------------- New Plugin library for new simulation framework ----- file(GLOB plugins_sources plugins/*.cpp) +list(APPEND plugins_sources G__DDG4.cxx) add_library(DD4hepG4Plugins SHARED ${plugins_sources}) target_link_libraries(DD4hepG4Plugins DD4hepCore DD4hepG4 ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) @@ -69,7 +68,12 @@ install(DIRECTORY examples DESTINATION examples/DDG4 PATTERN ".svn" EXCLUDE ) -install(FILES python/DD4hep.py python/DDG4.py python/DDG4Dict.C DESTINATION python) +install(FILES + python/DD4hep.py + python/DDG4.py + python/DDG4Dict.C + python/DDG4Dict.h + DESTINATION python) install(TARGETS DD4hepG4 DD4hepG4Plugins DD4hepG4Legacy g4gdmlDisplay RUNTIME DESTINATION bin diff --git a/DDG4/examples/CLICSidAClick.C b/DDG4/examples/CLICSidAClick.C index 2ee49266c9669d66ee69d2bcda3b2f3ae093e4e8..f2f26a3269bb87ba0eb0ffb8f6d671b90a5ca187 100644 --- a/DDG4/examples/CLICSidAClick.C +++ b/DDG4/examples/CLICSidAClick.C @@ -1,4 +1,3 @@ -#include "DDG4/Geant4Data.h" #include "DDG4/Geant4Config.h" #include "DDG4/Geant4TestActions.h" @@ -10,34 +9,10 @@ using namespace DD4hep::Simulation; using namespace DD4hep::Simulation::Test; using namespace DD4hep::Simulation::Setup; -#if defined(__MAKECINT__) -#pragma link C++ class Geant4RunActionSequence; -#pragma link C++ class Geant4EventActionSequence; -#pragma link C++ class Geant4SteppingActionSequence; -#pragma link C++ class Geant4StackingActionSequence; -#pragma link C++ class Geant4GeneratorActionSequence; -#pragma link C++ class Geant4Action; -#pragma link C++ class Geant4Kernel; -#pragma link C++ class KernelHandle; - -// Simple Event classes -#pragma link C++ class SimpleRun+; -#pragma link C++ class SimpleEvent+; -#pragma link C++ class SimpleHit+; -#pragma link C++ class std::vector<SimpleHit*>+; -#pragma link C++ class SimpleHit::Contribution+; -#pragma link C++ class SimpleHit::Contributions+; -#pragma link C++ class SimpleTracker+; -#pragma link C++ class SimpleTracker::Hit+; -#pragma link C++ class std::vector<SimpleTracker::Hit*>+; -#pragma link C++ class SimpleCalorimeter+; -#pragma link C++ class SimpleCalorimeter::Hit+; -#pragma link C++ class std::vector<SimpleCalorimeter::Hit*>+; -#endif - -SensitiveSeq::handled_type* setupDetector(Kernel& kernel, const std::string& name) { +SensitiveSeq::handled_type* setupDetector(Geant4Kernel& kernel, const std::string& name) { SensitiveSeq sd = SensitiveSeq(kernel,name); Sensitive sens = Sensitive(kernel,"Geant4TestSensitive/"+name+"Handler",name); + sens["OutputLevel"] = 4; sd->adopt(sens); sens = Sensitive(kernel,"Geant4TestSensitive/"+name+"Monitor",name); sd->adopt(sens); @@ -45,6 +20,7 @@ SensitiveSeq::handled_type* setupDetector(Kernel& kernel, const std::string& nam } void setupG4_CINT() { + //Geant4Kernel& kernel = Geant4Kernel::instance(Geometry::LCDD::getInstance()); Geant4Kernel kernel(Geometry::LCDD::getInstance()); string install_dir = getenv("DD4hepINSTALL"); string ddg4_examples = install_dir+"/examples/DDG4/examples"; @@ -53,21 +29,33 @@ void setupG4_CINT() { kernel.loadGeometry(("file:"+install_dir+"/examples/CLICSiD/compact/compact.xml").c_str()); kernel.loadXML(("file:"+ddg4_examples+"/DDG4_field.xml").c_str()); + kernel.property("UI") = "UI"; + setPrintLevel(DEBUG); + + Action ui(kernel,"Geant4UIManager/UI"); + ui["HaveVIS"] = true; + ui["HaveUI"] = true; + ui["SessionType"] = "csh"; + kernel.registerGlobalAction(ui); + GenAction gun(kernel,"Geant4ParticleGun/Gun"); - gun["energy"] = 0.5*GeV; + gun["energy"] = 25*GeV; gun["particle"] = "e-"; gun["multiplicity"] = 1; + gun["OutputLevel"] = 5; kernel.generatorAction().adopt(gun); - Action run_init(kernel,"Geant4TestRunAction/RunInit"); + RunAction run_init(kernel,"Geant4TestRunAction/RunInit"); run_init["Property_int"] = 12345; - kernel.runAction().callAtBegin (run_init.get(),&Geant4TestRunAction::begin); + kernel.runAction().adopt(run_init); kernel.eventAction().callAtBegin(run_init.get(),&Geant4TestRunAction::beginEvent); kernel.eventAction().callAtEnd (run_init.get(),&Geant4TestRunAction::endEvent); - Action evt_1(kernel,"Geant4TestEventAction/UserEvent_1"); + EventAction evt_1(kernel,"Geant4TestEventAction/UserEvent_1"); evt_1["Property_int"] = 12345; evt_1["Property_string"] = "Events"; + evt_1["OutputLevel"] = 5; + kernel.eventAction().adopt(evt_1); p = kernel.addPhase<const G4Run*>("BeginRun"); p->add(evt_1.get(),&Geant4TestEventAction::beginRun); diff --git a/DDG4/examples/CLICSidSimu.py b/DDG4/examples/CLICSidSimu.py index 24f690fb41837883d7fb4774d511df2a3b1095de..267958c7f4deb0117497b3e5be9ba044c81b2621 100644 --- a/DDG4/examples/CLICSidSimu.py +++ b/DDG4/examples/CLICSidSimu.py @@ -45,13 +45,27 @@ def run(): evt_root = simple.setupROOTOutput('RootOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M')) evt_lcio = simple.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M')) evt_lcio.OutputLevel = Output.ERROR - # Setup particle gun - #gun = simple.setupGun('Gun','pi-',energy=10*GeV,isotrop=True,multiplicity=3) + + + generator_output_level = Output.INFO gen = DDG4.GeneratorAction(kernel,"Geant4GeneratorActionInit/GenerationInit") kernel.generatorAction().adopt(gen) """ + Generation of isotrope tracks using the DDG4 partcle gun: + """ + # Setup particle gun + gun = simple.setupGun('Gun','pi-',energy=10*GeV,isotrop=True,multiplicity=3) + gun.OutputLevel = 5 # generator_output_level + + gen = DDG4.GeneratorAction(kernel,"Geant4PrimaryConverter/GunConverter"); + gen.OutputLevel = 5 # generator_output_level + kernel.generatorAction().adopt(gen) + + """ + Generation of isotrope tracks of a given multiplicity with overlay: + # First particle generator: pi+ gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropPi+"); gen.particle = 'pi+' @@ -81,7 +95,8 @@ def run(): kernel.generatorAction().adopt(gen) """ - generator_output_level = Output.INFO + """ + Generation of primary particles from LCIO input files # First particle file reader gen = DDG4.GeneratorAction(kernel,"LCIOInputAction/LCIO1"); @@ -122,6 +137,7 @@ def run(): gen = DDG4.GeneratorAction(kernel,"Geant4PrimaryHandler/PrimaryHandler") gen.OutputLevel = generator_output_level kernel.generatorAction().adopt(gen) + """ # And handle the simulation particles. part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler") diff --git a/DDG4/examples/dictionaries.C b/DDG4/examples/dictionaries.C deleted file mode 100644 index e559d62479a2a980f689baba5c443d1f03c0af5e..0000000000000000000000000000000000000000 --- a/DDG4/examples/dictionaries.C +++ /dev/null @@ -1,46 +0,0 @@ -// $Id: Geant4Data.h 513 2013-04-05 14:31:53Z gaede $ -//==================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------- -// -// Define the ROOT dictionaries for all data classes to be saved -// which are created by the DDG4 examples. -// -// Author : M.Frank -// -//==================================================================== -// Framework include files -#include "DDG4/Geant4Data.h" -#include <vector> -#include <set> - -using namespace std; -using namespace DD4hep; -using namespace DD4hep::Simulation; - -// CINT configuration -#if defined(__MAKECINT__) -#pragma link C++ class Position+; -//#pragma link C++ class Direction+; -#pragma link C++ class SimpleRun+; -#pragma link C++ class SimpleEvent+; -//#pragma link C++ class SimpleEvent::Seeds+; -#pragma link C++ class SimpleHit+; -#pragma link C++ class std::vector<SimpleHit*>+; -#pragma link C++ class SimpleHit::Contribution+; -#pragma link C++ class SimpleHit::Contributions+; -#pragma link C++ class SimpleTracker+; -#pragma link C++ class SimpleTracker::Hit+; -#pragma link C++ class std::vector<SimpleTracker::Hit*>+; -#pragma link C++ class SimpleCalorimeter+; -#pragma link C++ class SimpleCalorimeter::Hit+; -#pragma link C++ class std::vector<SimpleCalorimeter::Hit*>+; -#pragma link C++ class Particle+; -#pragma link C++ class std::vector<Particle*>+; -#pragma link C++ class std::set<int>+; -//#pragma link C++ class ; -#endif - -int dictionaries() { - return 0; -} diff --git a/DDG4/examples/initAClick.C b/DDG4/examples/initAClick.C index a17ae34ae3c09b70f669eb28670751945c645bb4..79873df28fd2313c846dbd2363fa5844f344645e 100644 --- a/DDG4/examples/initAClick.C +++ b/DDG4/examples/initAClick.C @@ -6,11 +6,14 @@ using namespace std; string make_str(const char* data) { - cout << "make_str: '" << (data ? data : "Bad-Pointer") << "'" << endl; + if ( !data ) { + cout << "make_str: '" << (data ? data : "Bad-Pointer") << "'" << endl; + return string(""); + } return string(data); } -void initAClick(const char* command=0) { +int initAClick(const char* command=0) { string rootsys = make_str(gSystem->Getenv("ROOTSYS")); string g4_base = make_str(gSystem->Getenv("G4INSTALL")); string dd4hep = make_str(gSystem->Getenv("DD4hepINSTALL")); @@ -22,13 +25,7 @@ void initAClick(const char* command=0) { gSystem->AddLinkedLibs(libs.c_str()); cout << "Includes: " << gSystem->GetIncludePath() << endl; cout << "Linked libs:" << gSystem->GetLinkedLibs() << endl; - - string ddg4_examples = string(getenv("DD4hepINSTALL"))+"/examples/DDG4/examples"; - string cmd = ".L "+ddg4_examples+"/dictionaries.C+"; - //gInterpreter->ProcessLine(cmd.c_str()); - if ( command ) { - string cmd = command; - cout << "Executing command:" << cmd << endl; - gInterpreter->ProcessLine(cmd.c_str()); - } + int ret = gSystem->Load("libDD4hepG4Plugins"); + return ret; } + diff --git a/DDG4/examples/run.C b/DDG4/examples/run.C index 39934fb51517990d4f87bd6282341fa8836e5145..b62089327843dc800296041ca4304102da723186 100644 --- a/DDG4/examples/run.C +++ b/DDG4/examples/run.C @@ -1,7 +1,6 @@ #include "TInterpreter.h" void run() { gInterpreter->ProcessLine(".X initAClick.C"); - //gInterpreter->ProcessLine(".L dictionaries.C+"); //gInterpreter->ProcessLine(".L exampleAClick.C+"); //gInterpreter->ProcessLine(".L xmlAClick.C+"); //gInterpreter->ProcessLine(".L TEve.C+"); diff --git a/DDG4/include/DDG4/Geant4Config.h b/DDG4/include/DDG4/Geant4Config.h index 4ca778ba85079efd1d0e7e4727a1331f0ae500ed..74e2cc1edd64d2539fa275728ea322d6983b88b2 100644 --- a/DDG4/include/DDG4/Geant4Config.h +++ b/DDG4/include/DDG4/Geant4Config.h @@ -51,7 +51,7 @@ namespace DD4hep { namespace Setup { // Basics typedef Geant4Kernel Kernel; - typedef Geant4Handle<Geant4Kernel> KernelH; + //typedef Geant4Handle<Geant4Kernel> KernelH; // Actions typedef Geant4Handle<Geant4Action> Action; typedef Geant4Handle<Geant4Filter> Filter; diff --git a/DDG4/include/DDG4/Geant4Kernel.h b/DDG4/include/DDG4/Geant4Kernel.h index 600027e5d4d1257c532a4b88fa5f91dc68e72d12..8fadb8b0d547604fb7ba3e335c8e8d621b207c1c 100644 --- a/DDG4/include/DDG4/Geant4Kernel.h +++ b/DDG4/include/DDG4/Geant4Kernel.h @@ -115,6 +115,9 @@ namespace DD4hep { /// Helper to register an action sequence template <typename C> bool registerSequence(C*& seq, const std::string& name); +#if defined(__CINT__) || defined(__MAKECINT__) +#endif + public: /// Standard constructor Geant4Kernel(LCDD& lcdd); public: diff --git a/DDG4/include/DDG4/Geant4MonteCarloTruth.h b/DDG4/include/DDG4/Geant4MonteCarloTruth.h index 7c9726b604fbe38eaf0be95920b69400827f57f5..860173ba4ad6b1d402c86c2be9c036f6cf71cf29 100644 --- a/DDG4/include/DDG4/Geant4MonteCarloTruth.h +++ b/DDG4/include/DDG4/Geant4MonteCarloTruth.h @@ -51,10 +51,12 @@ namespace DD4hep { public: /// Default destructor virtual ~Geant4MonteCarloTruth(); +#ifndef __MAKECINT__ /// Access the particle map virtual const ParticleMap& particles() const = 0; /// Access the map of track equivalents virtual const TrackEquivalents& equivalents() const = 0; +#endif /// Access the equivalent track id (shortcut to the usage of TrackEquivalents) virtual int particleID(int track, bool throw_if_not_found=true) const = 0; /// Mark a Geant4 track to be kept for later MC truth analysis @@ -87,10 +89,12 @@ namespace DD4hep { Geant4DummyTruthHandler(Geant4Context* ctxt,const std::string& nam); /// Default destructor virtual ~Geant4DummyTruthHandler(); +#ifndef __MAKECINT__ /// Access the particle map virtual const ParticleMap& particles() const { return m_particleMap; } /// Access the map of track equivalents virtual const TrackEquivalents& equivalents() const { return m_equivalentTracks; } +#endif /// Access the equivalent track id (shortcut to the usage of TrackEquivalents) virtual int particleID(int track, bool) const { return track; } /// Mark a Geant4 track to be kept for later MC truth analysis. Default flag: CREATED_HIT diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h index 6dd0d3e82e6517efe0e286a1cbb000bafb9f971b..0b023766c58f475729b6c7096430a3a4a09a8e02 100644 --- a/DDG4/include/DDG4/Geant4Particle.h +++ b/DDG4/include/DDG4/Geant4Particle.h @@ -139,6 +139,9 @@ namespace DD4hep { * @version 1.0 */ class Geant4ParticleHandle { + public: + typedef ROOT::Math::PxPyPzM4D<double> FourVector; + typedef ROOT::Math::Cartesian3D<double> ThreeVector; protected: /// Particle pointer Geant4Particle* particle; @@ -172,11 +175,11 @@ namespace DD4hep { /// Access to the creator process type name std::string processTypeName() const; /// Access patricle momentum, energy as 4 vector - ROOT::Math::PxPyPzM4D<double> pxPyPzM() const; + FourVector pxPyPzM() const; /// Access patricle momentum, energy as 4 vector - ROOT::Math::Cartesian3D<double> startVertex() const; + ThreeVector startVertex() const; /// Access patricle momentum, energy as 4 vector - ROOT::Math::Cartesian3D<double> endVertex() const; + ThreeVector endVertex() const; /// Various output formats: diff --git a/DDG4/include/DDG4/Geant4ParticleHandler.h b/DDG4/include/DDG4/Geant4ParticleHandler.h index bafcea19068a4a1c75a9dbe9f5f28e8a8c56d6d5..e3f390f224445436f89067efcbeb706ee3e15e27 100644 --- a/DDG4/include/DDG4/Geant4ParticleHandler.h +++ b/DDG4/include/DDG4/Geant4ParticleHandler.h @@ -43,6 +43,16 @@ namespace DD4hep { * @version 1.0 */ class Geant4ParticleHandler : public Geant4GeneratorAction, public Geant4MonteCarloTruth { +#ifdef __MAKECINT__ + public: +#else + private: +#endif + /// No default constructor + Geant4ParticleHandler(); + /// No assignment operator + Geant4ParticleHandler& operator=(const Geant4ParticleHandler& c); + public: typedef std::vector<std::string> Processes; struct FindParticleByID { @@ -113,11 +123,12 @@ namespace DD4hep { virtual void begin(const G4Track* track); /// Post-track action callback virtual void end(const G4Track* track); - +#ifndef __MAKECINT__ /// Access the particle map virtual const ParticleMap& particles() const { return m_particleMap; } /// Access the map of track equivalents virtual const TrackEquivalents& equivalents() const { return m_equivalentTracks; } +#endif /// Access the equivalent track id (shortcut to the usage of TrackEquivalents) virtual int particleID(int track, bool throw_if_not_found=true) const; diff --git a/DDG4/include/DDG4/Geant4Primary.h b/DDG4/include/DDG4/Geant4Primary.h index 3c3c39c55c09ae4b8821e8e2d3398d6fe12089e1..3bbf70131b28a0c5a16c228d4a011e4b37bd28e6 100644 --- a/DDG4/include/DDG4/Geant4Primary.h +++ b/DDG4/include/DDG4/Geant4Primary.h @@ -140,9 +140,9 @@ namespace DD4hep { /// Add a new interaction object to the event void add(int id, Geant4PrimaryInteraction* interaction); /// Retrieve an interaction by it's ID - Interaction* get(int id) const; + Geant4PrimaryInteraction* get(int id) const; /// Retrieve all intractions - std::vector<Interaction*> interactions() const; + std::vector<Geant4PrimaryInteraction*> interactions() const; }; } // End namespace Simulation diff --git a/DDG4/include/DDG4/Geant4PrimaryConverter.h b/DDG4/include/DDG4/Geant4PrimaryConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..9fea3351202b49a27523ce39749ed8816aaaeb69 --- /dev/null +++ b/DDG4/include/DDG4/Geant4PrimaryConverter.h @@ -0,0 +1,47 @@ +//==================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#ifndef DD4HEP_DDG4_GEANT4PRIMARYCONVERTER_H +#define DD4HEP_DDG4_GEANT4PRIMARYCONVERTER_H + +// Framework include files +#include "DDG4/Geant4GeneratorAction.h" +#include "Math/Vector3D.h" + +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + /* + * Simulation namespace declaration + */ + namespace Simulation { + + /** @class Geant4Primaryconverter Geant4Primaryconverter.h DDG4/Geant4Primaryconverter.h + * + * Convert G4PrimaryVertix and G4PrimaryParticle constructs into + * Geant4Primary records. Required for native G4 particle guns. + * + * @author M.Frank + * @version 1.0 + */ + class Geant4PrimaryConverter: public Geant4GeneratorAction { + protected: + /// Interaction mask + int m_mask; + public: + /// Standard constructor + Geant4PrimaryConverter(Geant4Context* context, const std::string& name); + /// Default destructor + virtual ~Geant4PrimaryConverter(); + /// Callback to generate primary particles + virtual void operator()(G4Event* event); + }; + } // End namespace Simulation +} // End namespace DD4hep +#endif /* DD4HEP_DDG4_GEANT4PRIMARYCONVERTER_H */ diff --git a/DDG4/lcio/LCIOInputAction.cpp b/DDG4/lcio/LCIOInputAction.cpp index 697a6f705401c6f4aa0d945173378049ca8a2656..45fb86588709bd071ac56229731d760e518646b0 100644 --- a/DDG4/lcio/LCIOInputAction.cpp +++ b/DDG4/lcio/LCIOInputAction.cpp @@ -147,6 +147,7 @@ void LCIOInputAction::operator()(G4Event* event) { p->reason = 0; p->usermask = 0; p->pdgID = mcp->getPDG(); + p->charge = int(mcp->getCharge()*3.0); p->psx = mom_scale*mom[0]*GeV; p->psy = mom_scale*mom[1]*GeV; p->psz = mom_scale*mom[2]*GeV; diff --git a/DDG4/plugins/Geant4Factories.cpp b/DDG4/plugins/Geant4Factories.cpp index e4cfc7fa9cb232f6537dbdd3ddc7012d914b2f44..899f3b1c37d57635641f200759f3ab213c03da91 100644 --- a/DDG4/plugins/Geant4Factories.cpp +++ b/DDG4/plugins/Geant4Factories.cpp @@ -91,6 +91,10 @@ DECLARE_GEANT4ACTION(Geant4InteractionMerger) #include "DDG4/Geant4PrimaryHandler.h" DECLARE_GEANT4ACTION(Geant4PrimaryHandler) +//============================= +#include "DDG4/Geant4PrimaryConverter.h" +DECLARE_GEANT4ACTION(Geant4PrimaryConverter) + //============================= #include "DDG4/Geant4TestActions.h" namespace DD4hep { namespace Simulation { diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index afb06232a117d741b1f43661fda5e0d7148bcf38..be43da09fb577a5fa2aff09789f2bbfdc4a60778 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -2,7 +2,7 @@ from DD4hep import * def loadDDG4(): from ROOT import gSystem - result = gSystem.Load("libDD4hepG4") + result = gSystem.Load("libDD4hepG4Plugins") if 0 != result: raise Exception('DDG4.py: Failed to load the Geant4 library libDD4hepG4: '+gSystem.GetErrorStr()) from ROOT import DD4hep as module @@ -213,6 +213,7 @@ class Simple: phys.enableUI() phys.dump() return phys + def setupGun(self, name, particle, energy, isotrop=True, multiplicity=1, position=(0.0,0.0,0.0)): gun = GeneratorAction(self.kernel,"Geant4ParticleGun/"+name) gun.energy = energy @@ -222,6 +223,8 @@ class Simple: gun.isotrop = isotrop gun.enableUI() self.kernel.generatorAction().add(gun) + return gun + def setupCshUI(self): # Configure UI ui = Action(self.kernel,"Geant4UIManager/UI") diff --git a/DDG4/python/DDG4Dict.C b/DDG4/python/DDG4Dict.C index 245d85783b7a3450a78cc7f72d8e57d9756ffa84..b670433078d8c59b769bcabd702fce2cf4ee225a 100644 --- a/DDG4/python/DDG4Dict.C +++ b/DDG4/python/DDG4Dict.C @@ -10,43 +10,31 @@ // //==================================================================== // FRamework include files -#include "DDG4/Geant4Particle.h" +#include "DDG4/Geant4Primary.h" #include "DDG4/Geant4Data.h" -#include <vector> - -using namespace std; -using namespace DD4hep; -using namespace DD4hep::Simulation; - +#include "DDG4Dict.h" // CINT configuration #if defined(__MAKECINT__) -//#pragma link C++ class Position+; -//#pragma link C++ class Direction+; -#pragma link C++ class SimpleRun+; -#pragma link C++ class SimpleEvent+; -//#pragma link C++ class SimpleEvent::Seeds+; -#pragma link C++ class DataExtension+; -#pragma link C++ class ParticleExtension+; -#pragma link C++ class auto_ptr<DataExtension>+; -#pragma link C++ class auto_ptr<ParticleExtension>+; - -#pragma link C++ class SimpleHit+; -#pragma link C++ class Geant4Particle+; -#pragma link C++ class std::vector<SimpleHit*>+; -#pragma link C++ class SimpleHit::Contribution+; -#pragma link C++ class SimpleHit::Contributions+; -#pragma link C++ class SimpleTracker+; -#pragma link C++ class SimpleTracker::Hit+; -#pragma link C++ class std::vector<SimpleTracker::Hit*>+; -#pragma link C++ class SimpleCalorimeter+; -#pragma link C++ class SimpleCalorimeter::Hit+; -#pragma link C++ class std::vector<SimpleCalorimeter::Hit*>+; -#pragma link C++ class std::vector<Geant4Particle*>+; +#pragma link C++ namespace DD4hep::DDSegmentation; +#pragma link C++ class DD4hep::Simulation::VertexExtension+; +#pragma link C++ class DD4hep::Simulation::PrimaryExtension+; +#pragma link C++ class std::auto_ptr<DD4hep::Simulation::VertexExtension>+; +#pragma link C++ class std::auto_ptr<DD4hep::Simulation::PrimaryExtension>+; +#pragma link C++ class DD4hep::Simulation::Geant4Vertex+; +#pragma link C++ class std::map<int,DD4hep::Simulation::Geant4Vertex*>+; +#pragma link C++ class DD4hep::Simulation::Geant4ParticleMap+; +#pragma link C++ class DD4hep::Simulation::Geant4PrimaryInteraction+; +#pragma link C++ class std::map<int,DD4hep::Simulation::Geant4PrimaryInteraction*>+; +#pragma link C++ class DD4hep::Simulation::Geant4PrimaryEvent+; //#pragma link C++ class ; #endif +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Simulation; + #include "DDG4/Geant4Config.h" #include "DDG4/Geant4DataDump.h" #include <iostream> @@ -256,6 +244,11 @@ typedef DD4hep::Simulation::Geant4ActionCreation Geant4ActionCreation; #pragma link C++ class Geant4SensDetActionSequence; #pragma link C++ class Geant4ActionPhase; +// Work around CINT bug: +// somehow the symbol Geometry moved into global namespace. Redeclare it here +namespace Geometry {} +#pragma link C++ namespace Geometry; + #endif int Geant4Dict() { diff --git a/DDG4/python/DDG4Dict.h b/DDG4/python/DDG4Dict.h new file mode 100644 index 0000000000000000000000000000000000000000..ecfbfe1dddc385bc67f984dc6e93bce74b746e37 --- /dev/null +++ b/DDG4/python/DDG4Dict.h @@ -0,0 +1,53 @@ +// $Id: Geant4Data.h 513 2013-04-05 14:31:53Z gaede $ +//==================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------- +// +// Define the ROOT dictionaries for all data classes to be saved +// which are created by the DDG4 examples. +// +// Author : M.Frank +// +//==================================================================== +// FRamework include files +#include "DDG4/Geant4Data.h" +#include "DDG4/Geant4Particle.h" + +// CINT configuration +#if defined(__MAKECINT__) +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ namespace DD4hep; +#pragma link C++ namespace DD4hep::Geometry; +#pragma link C++ namespace DD4hep::Simulation; + +#pragma link C++ class DD4hep::Simulation::SimpleRun+; +#pragma link C++ class DD4hep::Simulation::SimpleEvent+; +//#pragma link C++ class DD4hep::SimpleEvent::Seeds+; +#pragma link C++ class DD4hep::Simulation::DataExtension+; +#pragma link C++ class DD4hep::Simulation::ParticleExtension+; + +#pragma link C++ class std::auto_ptr<DD4hep::Simulation::DataExtension>+; +#pragma link C++ class std::auto_ptr<DD4hep::Simulation::ParticleExtension>+; + +#pragma link C++ class DD4hep::Simulation::Geant4HitData+; +#pragma link C++ class DD4hep::Simulation::Geant4Particle+; +//#pragma link C++ class DD4hep::Simulation::Geant4ParticleHandle; // No streamer here! +#pragma link C++ class std::vector<DD4hep::Simulation::Geant4HitData*>+; +#pragma link C++ class DD4hep::Simulation::Geant4HitData::Contribution+; +#pragma link C++ class DD4hep::Simulation::Geant4HitData::Contributions+; +#pragma link C++ class DD4hep::Simulation::Geant4Tracker+; +#pragma link C++ class DD4hep::Simulation::Geant4Tracker::Hit+; +#pragma link C++ class std::vector<DD4hep::Simulation::Geant4Tracker::Hit*>+; +#pragma link C++ class DD4hep::Simulation::Geant4Calorimeter+; +#pragma link C++ class DD4hep::Simulation::Geant4Calorimeter::Hit+; +#pragma link C++ class std::vector<DD4hep::Simulation::Geant4Calorimeter::Hit*>+; +#pragma link C++ class std::vector<DD4hep::Simulation::Geant4Vertex*>+; +#pragma link C++ class std::vector<DD4hep::Simulation::Geant4Particle*>+; +//#pragma link C++ class std::set<int>+; // Note: Link requested for already precompiled class +#pragma link C++ class std::map<int,DD4hep::Simulation::Geant4Particle*>+; + +//#pragma link C++ class ; +#endif diff --git a/DDG4/src/Geant4Exec.cpp b/DDG4/src/Geant4Exec.cpp index d3d160a48f90a0f17c30a226dadfba4ef30495db..69dc8e32c90b743aa53f56a6fb85e5a977612ba9 100644 --- a/DDG4/src/Geant4Exec.cpp +++ b/DDG4/src/Geant4Exec.cpp @@ -83,9 +83,6 @@ namespace DD4hep { void releaseContextFromClients() { Geant4Action::ContextUpdate(0)(m_sequence); } - void releaseContextFromClients2() { - Geant4Action::ContextUpdate(0)(m_sequence); - } void createClientContext(const G4Run* run) { Geant4Run* r = new Geant4Run(run); m_activeContext->setRun(r); @@ -114,6 +111,9 @@ namespace DD4hep { } }; + class Geant4UserRunAction; + class Geant4UserEventAction; + /** @class Geant4UserRunAction * * Concrete implementation of the Geant4 run action @@ -122,23 +122,18 @@ namespace DD4hep { * @version 1.0 */ struct Geant4UserRunAction : public G4UserRunAction, public SequenceHdl<Geant4RunActionSequence> { + Geant4UserEventAction* eventAction; /// Standard constructor Geant4UserRunAction(Geant4Context* context, Geant4RunActionSequence* seq) - : Base(context, seq) { + : Base(context, seq), eventAction(0) { } /// Default destructor virtual ~Geant4UserRunAction() { } - /// begin-of-run callback - virtual void BeginOfRunAction(const G4Run* run) { - createClientContext(run); - m_sequence->begin(run); - } + /// Begin-of-run callback + virtual void BeginOfRunAction(const G4Run* run); /// End-of-run callback - virtual void EndOfRunAction(const G4Run* run) { - m_sequence->end(run); - destroyClientContext(run); - } + virtual void EndOfRunAction(const G4Run* run); }; /** @class Geant4UserEventAction @@ -149,23 +144,18 @@ namespace DD4hep { * @version 1.0 */ struct Geant4UserEventAction : public G4UserEventAction, public SequenceHdl<Geant4EventActionSequence> { + Geant4UserRunAction* runAction; /// Standard constructor Geant4UserEventAction(Geant4Context* context, Geant4EventActionSequence* seq) - : Base(context, seq) { + : Base(context, seq), runAction(0) { } /// Default destructor virtual ~Geant4UserEventAction() { } - /// begin-of-event callback - virtual void BeginOfEventAction(const G4Event* evt) { - setContextToClients(); - m_sequence->begin(evt); - } + /// Begin-of-event callback + virtual void BeginOfEventAction(const G4Event* evt); /// End-of-event callback - virtual void EndOfEventAction(const G4Event* evt) { - m_sequence->end(evt); - destroyClientContext(evt); - } + virtual void EndOfEventAction(const G4Event* evt); }; /** @class Geant4UserTrackingAction @@ -193,7 +183,7 @@ namespace DD4hep { virtual void PostUserTrackingAction(const G4Track* trk) { m_sequence->end(trk); m_sequence->context()->kernel().setTrackMgr(0); - releaseContextFromClients2(); //Let's leave this out for now...Frank has dirty tricks. + releaseContextFromClients(); //Let's leave this out for now...Frank has dirty tricks. } }; @@ -216,13 +206,13 @@ namespace DD4hep { virtual void NewStage() { setContextToClients(); m_sequence->newStage(); - releaseContextFromClients2(); //Let's leave this out for now...Frank has dirty tricks. + releaseContextFromClients(); //Let's leave this out for now...Frank has dirty tricks. } /// Preparation callback virtual void PrepareNewEvent() { setContextToClients(); m_sequence->prepare(); - releaseContextFromClients2(); //Let's leave this out for now...Frank has dirty tricks. + releaseContextFromClients(); //Let's leave this out for now...Frank has dirty tricks. } }; @@ -245,7 +235,7 @@ namespace DD4hep { virtual void GeneratePrimaries(G4Event* event) { createClientContext(event); (*m_sequence)(event); - releaseContextFromClients2(); //Let's leave this out for now...Frank has dirty tricks. + releaseContextFromClients(); //Let's leave this out for now...Frank has dirty tricks. } }; @@ -268,10 +258,39 @@ namespace DD4hep { virtual void UserSteppingAction(const G4Step* s) { setContextToClients(); (*m_sequence)(s, fpSteppingManager); - releaseContextFromClients2(); //Let's leave this out for now...Frank has dirty tricks. + releaseContextFromClients(); //Let's leave this out for now...Frank has dirty tricks. } }; + /// Begin-of-run callback + void Geant4UserRunAction::BeginOfRunAction(const G4Run* run) { + createClientContext(run); + eventAction->setContextToClients(); + m_sequence->begin(run); + } + + /// End-of-run callback + void Geant4UserRunAction::EndOfRunAction(const G4Run* run) { + m_sequence->end(run); + eventAction->releaseContextFromClients(); + destroyClientContext(run); + } + + /// Begin-of-event callback + void Geant4UserEventAction::BeginOfEventAction(const G4Event* evt) { + runAction->setContextToClients(); + setContextToClients(); + m_sequence->begin(evt); + } + + /// End-of-event callback + void Geant4UserEventAction::EndOfEventAction(const G4Event* evt) { + m_sequence->end(evt); + runAction->releaseContextFromClients(); + destroyClientContext(evt); + } + + } } @@ -330,14 +349,14 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { runManager.SetUserAction(gen_action); // Set the run action sequence. Not optional, since run context is defined/destroyed inside - Geant4UserRunAction* run_action = - new Geant4UserRunAction(ctx,kernel.runAction(false)); + Geant4UserRunAction* run_action = new Geant4UserRunAction(ctx,kernel.runAction(false)); runManager.SetUserAction(run_action); // Set the event action sequence. Not optional, since event context is destroyed inside - Geant4UserEventAction* evt_action = - new Geant4UserEventAction(ctx,kernel.eventAction(false)); + Geant4UserEventAction* evt_action = new Geant4UserEventAction(ctx,kernel.eventAction(false)); runManager.SetUserAction(evt_action); + run_action->eventAction = evt_action; + evt_action->runAction = run_action; // Set the tracking action sequence if (kernel.trackingAction(false)) { diff --git a/DDG4/src/Geant4GeneratorActionInit.cpp b/DDG4/src/Geant4GeneratorActionInit.cpp index cb3560d83ae5f43d57a19be38e093d47a853f30e..5194dfb366f1581616535a6a17fd4665cfb880f7 100644 --- a/DDG4/src/Geant4GeneratorActionInit.cpp +++ b/DDG4/src/Geant4GeneratorActionInit.cpp @@ -40,7 +40,7 @@ void Geant4GeneratorActionInit::begin(const G4Run* run) { /// End-run action callback void Geant4GeneratorActionInit::end(const G4Run* /* run */) { - printP1("+++ Funished run %d after %d events (% events in total)",m_run,m_evtRun,m_evtTotal); + printP1("+++ Funished run %d after %d events (%d events in total)",m_run,m_evtRun,m_evtTotal); m_evtRun = 0; m_run = 0; } diff --git a/DDG4/src/Geant4ParticleHandler.cpp b/DDG4/src/Geant4ParticleHandler.cpp index c844cfac6e5a96219f6094435d48ddccb569f9fd..c647d2ba3d85c05de67b4b561cde229c49d22c5f 100644 --- a/DDG4/src/Geant4ParticleHandler.cpp +++ b/DDG4/src/Geant4ParticleHandler.cpp @@ -72,6 +72,10 @@ Geant4ParticleHandler::Geant4ParticleHandler(Geant4Context* context, const strin InstanceCount::increment(this); } +/// No default constructor +Geant4ParticleHandler::Geant4ParticleHandler() : Geant4GeneratorAction(0,"") { +} + /// Default destructor Geant4ParticleHandler::~Geant4ParticleHandler() { clear(); @@ -79,6 +83,11 @@ Geant4ParticleHandler::~Geant4ParticleHandler() { InstanceCount::decrement(this); } +/// No assignment operator +Geant4ParticleHandler& Geant4ParticleHandler::operator=(const Geant4ParticleHandler&) { + return *this; +} + /// Adopt the user particle handler bool Geant4ParticleHandler::adopt(Geant4UserParticleHandler* action) { if ( action ) { diff --git a/DDG4/src/Geant4PrimaryConverter.cpp b/DDG4/src/Geant4PrimaryConverter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4554a8fdf8e86db95b21ec53fdce51a9db35649a --- /dev/null +++ b/DDG4/src/Geant4PrimaryConverter.cpp @@ -0,0 +1,101 @@ +// $Id: Geant4Converter.cpp 603 2013-06-13 21:15:14Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== + +// Framework include files +#include "DD4hep/Printout.h" +#include "DD4hep/InstanceCount.h" +#include "DDG4/Geant4Primary.h" +#include "DDG4/Geant4Context.h" +#include "DDG4/Geant4PrimaryConverter.h" + +#include "G4Event.hh" +#include "G4PrimaryVertex.hh" +#include "G4PrimaryParticle.hh" + +// C/C++ include files +#include <limits> + +using namespace std; +using namespace DD4hep::Simulation; + +/// Standard constructor +Geant4PrimaryConverter::Geant4PrimaryConverter(Geant4Context* context, const string& name) + : Geant4GeneratorAction(context, name) +{ + InstanceCount::increment(this); + declareProperty("Mask", m_mask = 1); + m_needsControl = true; +} + +/// Default destructor +Geant4PrimaryConverter::~Geant4PrimaryConverter() { + InstanceCount::decrement(this); +} + +/// Callback to generate primary particles +void Geant4PrimaryConverter::operator()(G4Event* event) { + typedef DD4hep::ReferenceBitMask<int> PropertyMask; + Geant4Event& evt = context()->event(); + Geant4PrimaryMap* primaries = evt.extension<Geant4PrimaryMap>(); + Geant4PrimaryEvent* prim = evt.extension<Geant4PrimaryEvent>(); + Geant4PrimaryInteraction* inter = new Geant4PrimaryInteraction(); + Geant4PrimaryInteraction* output = evt.extension<Geant4PrimaryInteraction>(); + const G4Event& e = *event; + + prim->add(m_mask, inter); + print("+++ Particle interaction converted from Geant4 primaries:"); + + for(int cnt=0, i=0, ni=e.GetNumberOfPrimaryVertex(); i<ni; ++i) { + G4PrimaryVertex* v4 = e.GetPrimaryVertex(i); + Geant4Vertex* vtx = new Geant4Vertex(); + vtx->x = v4->GetX0()*mm; + vtx->y = v4->GetY0()*mm; + vtx->z = v4->GetZ0()*mm; + vtx->time = v4->GetT0()*ns; + inter->vertices.insert(make_pair(inter->vertices.size(),vtx)); + output->vertices.insert(make_pair(output->vertices.size(),vtx->addRef())); + for(int j=0, nj=v4->GetNumberOfParticle(); j<nj; ++j) { + const G4PrimaryParticle* p4 = v4->GetPrimary(j); + Geant4ParticleHandle p = new Geant4Particle(cnt); + p->reason = 0; + p->usermask = 0; + p->pdgID = p4->GetPDGcode(); + p->psx = p4->GetPx()*GeV; + p->psy = p4->GetPy()*GeV; + p->psz = p4->GetPz()*GeV; + p->time = v4->GetT0()*ns; + p->properTime = v4->GetT0()*ns; + p->vsx = v4->GetX0()*mm; + p->vsy = v4->GetY0()*mm; + p->vsz = v4->GetZ0()*mm; + p->vex = v4->GetX0()*mm; + p->vey = v4->GetY0()*mm; + p->vez = v4->GetZ0()*mm; + p->definition = p4->GetParticleDefinition(); + p->process = 0; + p->spin[0] = 0; + p->spin[1] = 0; + p->spin[2] = 0; + p->colorFlow[0] = 0; + p->colorFlow[0] = 0; + p->mass = p4->GetMass(); + p->charge = p4->GetCharge(); + PropertyMask status(p->status); + status.set(G4PARTICLE_GEN_CREATED); + status.set(G4PARTICLE_GEN_STABLE); + p.dump3(outputLevel()-1,name(),"+->"); + + vtx->out.insert(p->id); + inter->particles.insert(make_pair(p->id,p)); + output->particles.insert(make_pair(p->id,p->addRef())); + primaries->primaryMap.insert(make_pair(p4,p->addRef())); + cnt++; + } + } +} diff --git a/DDG4/src/Geant4TestActions.cpp b/DDG4/src/Geant4TestActions.cpp index ef0eaf0b0070aefd89809c5fdc8ef7f8adc1d227..ee5ad871d863ff37627ed5037fb615ffa3ada901 100644 --- a/DDG4/src/Geant4TestActions.cpp +++ b/DDG4/src/Geant4TestActions.cpp @@ -62,7 +62,7 @@ Geant4TestGeneratorAction::~Geant4TestGeneratorAction() { /// Callback to generate primary particles void Geant4TestGeneratorAction::operator()(G4Event* evt) { PRINT("%s> calling Geant4TestGeneratorAction(event_id=%d Context: run=%p evt=%p)", - m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event()); + m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr()); } /// Standard constructor with initializing arguments @@ -91,13 +91,13 @@ void Geant4TestRunAction::end(const G4Run* run) { /// begin-of-event callback void Geant4TestRunAction::beginEvent(const G4Event* evt) { PRINT("%s> calling beginEvent(event_id=%d Context: run=%p evt=%p)", - m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event()); + m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr()); } /// End-of-event callback void Geant4TestRunAction::endEvent(const G4Event* evt) { PRINT("%s> calling endEvent(event_id=%d Context: run=%p evt=%p)", - m_type.c_str(), evt->GetEventID(), &context()->run(), &context()->event()); + m_type.c_str(), evt->GetEventID(), context()->runPtr(), context()->eventPtr()); } /// Standard constructor with initializing arguments @@ -130,14 +130,14 @@ void Geant4TestEventAction::end(const G4Event* evt) { void Geant4TestEventAction::beginRun(const G4Run* run) { PRINT("%s> calling beginRun(run_id=%d,num_event=%d Context:%p)", m_type.c_str(), run->GetRunID(), - run->GetNumberOfEventToBeProcessed(), &context()->run()); + run->GetNumberOfEventToBeProcessed(), context()->runPtr()); } /// End-of-run callback void Geant4TestEventAction::endRun(const G4Run* run) { PRINT("%s> calling endRun(run_id=%d, num_event=%d Context:%p)", m_type.c_str(), run->GetRunID(), - run->GetNumberOfEvent(), &context()->run()); + run->GetNumberOfEvent(), context()->runPtr()); } /// Standard constructor with initializing arguments