diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index df2085011e43f86acf78ec0a10c809865752fe59..8adabae3dc9b242b0fb5505d697c3710843667e8 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -98,6 +98,16 @@ install(DIRECTORY include/DDG4 DESTINATION include PATTERN ".svn" EXCLUDE ) +install(DIRECTORY examples + DESTINATION examples/DDG4 + PATTERN ".svn" EXCLUDE ) + +install(DIRECTORY python + DESTINATION python/DDG4 + PATTERN ".d" EXCLUDE + PATTERN ".so" EXCLUDE + PATTERN ".svn" EXCLUDE ) + install(TARGETS DD4hepG4 DD4hepG4Plugins DD4hepG4Legacy g4gdmlDisplay RUNTIME DESTINATION bin LIBRARY DESTINATION lib diff --git a/DDG4/examples/exampleAClick.C b/DDG4/examples/CLICSidAClick.C similarity index 74% rename from DDG4/examples/exampleAClick.C rename to DDG4/examples/CLICSidAClick.C index cf8d6ecab3cbfcc237b8fa35a2ff3bdcf8773df2..4c5e67487149211c436d1fa56d22faf406c4ab4a 100644 --- a/DDG4/examples/exampleAClick.C +++ b/DDG4/examples/CLICSidAClick.C @@ -1,6 +1,7 @@ +#include "DDG4/Geant4Data.h" #include "DDG4/Geant4Config.h" #include "DDG4/Geant4TestActions.h" -#include "DDG4/Geant4TrackHandler.h" + #include <iostream> using namespace std; @@ -17,6 +18,21 @@ using namespace DD4hep::Simulation::Setup; #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) { @@ -29,11 +45,13 @@ SensitiveSeq::handled_type* setupDetector(Kernel& kernel, const std::string& nam } void setupG4_CINT() { - Kernel kernel(); - + Geant4Kernel kernel(Geometry::LCDD::getInstance()); + string install_dir = getenv("DD4hepINSTALL"); + string ddg4_examples = install_dir+"/examples/DDG4/examples"; Phase p; - kernel.loadGeometry("file:../DD4hep.trunk/DDExamples/CLICSiD/compact/compact.xml"); - kernel.loadXML("DDG4_field.xml"); + + kernel.loadGeometry(("file:"+install_dir+"/examples/CLICSiD/compact/compact.xml").c_str()); + kernel.loadXML(("file:"+ddg4_examples+"/DDG4_field.xml").c_str()); GenAction gun(kernel,"Geant4ParticleGun/Gun"); gun["energy"] = 0.5*GeV; @@ -87,4 +105,3 @@ void setupG4_CINT() { void exampleAClick() { setupG4_CINT(); } - diff --git a/DDG4/examples/CLICSidSimu.py b/DDG4/examples/CLICSidSimu.py index 9cfb759830ca869f53e3e0eec25b668c9fa6a78a..1fc88a9f8d33ec9172590010bf14d4c965b190f9 100644 --- a/DDG4/examples/CLICSidSimu.py +++ b/DDG4/examples/CLICSidSimu.py @@ -1,6 +1,6 @@ # # -import DDG4 +import os, DDG4 from SystemOfUnits import * # # @@ -13,10 +13,12 @@ from SystemOfUnits import * """ def run(): + install_dir = os.environ['DD4hepINSTALL'] + example_dir = install_dir+'/examples/DDG4/examples'; kernel = DDG4.Kernel() kernel.UI = "UI" - kernel.loadGeometry("file:../DD4hep.trunk/DDExamples/CLICSiD/compact/compact.xml") - kernel.loadXML("file:../DD4hep.trunk/DDG4/examples/DDG4_field.xml") + kernel.loadGeometry("file:"+install_dir+"/examples/CLICSiD/compact/compact.xml") + kernel.loadXML("file:"+example_dir+"/DDG4_field.xml") lcdd = kernel.lcdd() print '+++ List of sensitive detectors:' @@ -73,13 +75,12 @@ def run(): evt_root.Control = True evt_root.Output = "simple.root" evt_root.enableUI() - - evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput') - evt_lcio.Output = "simple_lcio" - evt_lcio.enableUI() - kernel.eventAction().add(evt_root) - kernel.eventAction().add(evt_lcio) + + #evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput') + #evt_lcio.Output = "simple_lcio" + #evt_lcio.enableUI() + #kernel.eventAction().add(evt_lcio) # Setup particle gun gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/Gun") diff --git a/DDG4/examples/initAClick.C b/DDG4/examples/initAClick.C index 56f0df96e97d82e7600791643d4fe3381097966f..a17ae34ae3c09b70f669eb28670751945c645bb4 100644 --- a/DDG4/examples/initAClick.C +++ b/DDG4/examples/initAClick.C @@ -1,3 +1,4 @@ +#include "TInterpreter.h" #include "TSystem.h" #include <iostream> #include <string> @@ -9,12 +10,10 @@ string make_str(const char* data) { return string(data); } -void initAClick() { - string cwd = gSystem->WorkingDirectory(); - cout << "CWD:" << cwd << endl; +void initAClick(const char* command=0) { string rootsys = make_str(gSystem->Getenv("ROOTSYS")); - string g4_base = make_str(gSystem->Getenv("Geant4_DIR")); - string dd4hep = make_str(gSystem->Getenv("DD4hep_DIR")); + string g4_base = make_str(gSystem->Getenv("G4INSTALL")); + string dd4hep = make_str(gSystem->Getenv("DD4hepINSTALL")); string inc = " -I"+dd4hep+"/include -I"+g4_base+"/include/Geant4 -Wno-shadow -g -O0"; string libs = (" -L"+rootsys+"/lib"); libs += " -lCore -lCint -lMathCore -L"+dd4hep+"/lib -lDD4hepCore -lDD4hepG4 -lDDSegmentation"; @@ -23,4 +22,13 @@ void initAClick() { 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()); + } } diff --git a/DDG4/include/DDG4/Geant4Action.h b/DDG4/include/DDG4/Geant4Action.h index 1f358dafb945cc5792a5e6b81db13f9741e25dd4..1372fbf49b1b7f5613d8868bb64716c11536caf0 100644 --- a/DDG4/include/DDG4/Geant4Action.h +++ b/DDG4/include/DDG4/Geant4Action.h @@ -14,8 +14,6 @@ #include "DDG4/Geant4Callback.h" #include "DDG4/ComponentProperties.h" -#include "G4VUserTrackInformation.hh" - // Geant4 forward declarations class G4Run; class G4Event; @@ -68,29 +66,8 @@ namespace DD4hep { static TypeName split(const std::string& type_name, const std::string& delim); }; - /** @class Geant4TrackInformation Geant4Action.h DDG4/Geant4Action.h - * - * @author M.Frank - * @version 1.0 - */ - struct Geant4TrackInformation : public G4VUserTrackInformation { - enum { - STORE = 1 << 0, LAST = 1 << 31 - }; - int m_flags; - /// Default constructor - Geant4TrackInformation(); - /// Standard destructor - virtual ~Geant4TrackInformation(); - /// Access flag if track should be stored - bool storeTrack() const { - return (m_flags & STORE) != 0; - } - /// Access flag if track should be stored - Geant4TrackInformation& storeTrack(bool value); - }; - #if 0 + /** @class Geant4UserTrajectory Geant4Action.h DDG4/Geant4Action.h * * @author M.Frank diff --git a/DDG4/include/DDG4/Geant4Handle.h b/DDG4/include/DDG4/Geant4Handle.h index 6560224cc072c3ba5f6593b346e4f97814103608..0b51905d4a49107782a09381431b0ab3e0557801 100644 --- a/DDG4/include/DDG4/Geant4Handle.h +++ b/DDG4/include/DDG4/Geant4Handle.h @@ -51,6 +51,7 @@ namespace DD4hep { checked_assign(dynamic_cast<handled_type*>(typ)); } Geant4Handle(const Geant4Handle& handle); + Geant4Handle(const Geant4Kernel&, const char* type_name); Geant4Handle(const Geant4Kernel&, const std::string& type_name); /// Constructor only implemented for sensitive objects Geant4Handle(const Geant4Kernel& ctxt, const std::string& type_name, const std::string& detector); diff --git a/DDG4/include/DDG4/Geant4TrackInformation.h b/DDG4/include/DDG4/Geant4TrackInformation.h new file mode 100644 index 0000000000000000000000000000000000000000..cb3f47d34fc454d056a2040f7a574e4ed24df199 --- /dev/null +++ b/DDG4/include/DDG4/Geant4TrackInformation.h @@ -0,0 +1,51 @@ +// $Id: Geant4Hits.h 513 2013-04-05 14:31:53Z gaede $ +//==================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#ifndef DD4HEP_DDG4_GEANT4TRACKINFORMATION_H +#define DD4HEP_DDG4_GEANT4TRACKINFORMATION_H + +// Framework include files +#include "G4VUserTrackInformation.hh" + +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + /* + * Simulation namespace declaration + */ + namespace Simulation { + + /** @class Geant4TrackInformation Geant4Action.h DDG4/Geant4Action.h + * + * @author M.Frank + * @version 1.0 + */ + struct Geant4TrackInformation : public G4VUserTrackInformation { + enum { + STORE = 1 << 0, LAST = 1 << 31 + }; + int m_flags; + /// Default constructor + Geant4TrackInformation(); + /// Standard destructor + virtual ~Geant4TrackInformation(); + /// Access flag if track should be stored + bool storeTrack() const { + return (m_flags & STORE) != 0; + } + /// Access flag if track should be stored + Geant4TrackInformation& storeTrack(bool value); + }; + + + } // End namespace Simulation +} // End namespace DD4hep + +#endif // DD4HEP_DDG4_GEANT4TRACKINFORMATION_H diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index 79e41c61db0ad6ad271d29f6c42c0590ca9a091b..f8e3e35810e2e1fd0cc856da84a9e4a991daa311 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -7,11 +7,11 @@ import ROOT def compileAClick(dictionary,g4=True): from ROOT import gInterpreter, gSystem import os.path - dd4hep = os.environ['DD4hep_DIR'] + dd4hep = os.environ['DD4hepINSTALL'] inc = ' -I'+os.environ['ROOTSYS']+'/include -I'+dd4hep+'/include ' lib = ' -L'+dd4hep+'/lib -lDD4hepCore -lDD4hepG4 -lDDSegmentation ' if g4: - geant4 = os.environ['Geant4_DIR'] + geant4 = os.environ['G4INSTALL'] inc = inc + ' -I'+geant4+'/include/Geant4 -Wno-shadow -g -O0 ' lib = lib + ' -L'+geant4+'/lib -L'+geant4+'/lib64 -lG4event -lG4tracking -lG4particles ' diff --git a/DDG4/src/Geant4Action.cpp b/DDG4/src/Geant4Action.cpp index ebcf23464ada782359f5c5e53be96c63fe656a14..f5289888c30abe2891ecfd2e002886ec0256863c 100644 --- a/DDG4/src/Geant4Action.cpp +++ b/DDG4/src/Geant4Action.cpp @@ -35,21 +35,6 @@ TypeName TypeName::split(const string& type_name) { return split(type_name,"/"); } -/// Default constructor -Geant4TrackInformation::Geant4TrackInformation() - : G4VUserTrackInformation(), m_flags(0) { -} - -/// Standard destructor -Geant4TrackInformation::~Geant4TrackInformation() { -} - -/// Access flag if track should be stored -Geant4TrackInformation& Geant4TrackInformation::storeTrack(bool value) { - value ? m_flags |= STORE : m_flags &= ~STORE; - return *this; -} - /// Standard constructor Geant4Action::Geant4Action(Geant4Context* context, const string& nam) : m_context(context), m_control(0), m_outputLevel(INFO), m_needsControl(false), m_name(nam), m_refCount(1) { diff --git a/DDG4/src/Geant4Handle.cpp b/DDG4/src/Geant4Handle.cpp index 69bb7c98356991d01bafc8aa77a1b1969bcf3779..e12c4a5b241acc9d1b7dbe0dd1fb8d72f3647979 100644 --- a/DDG4/src/Geant4Handle.cpp +++ b/DDG4/src/Geant4Handle.cpp @@ -87,6 +87,38 @@ template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(const Geant4Kernel& ke throw runtime_error(format("Geant4Handle", "Failed to create object of type %s!", type_name.c_str())); } +template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(const Geant4Kernel& kernel, const char* type_name_char) + : value(0) { + string type_name = type_name_char; + TypeName typ = TypeName::split(type_name); + Geant4Context* ctxt = kernel.context(); + Geant4Action* object = PluginService::Create<Geant4Action*>(typ.first, ctxt, typ.second); + if (!object && typ.first == typ.second) { + typ.first = typeinfoName(typeid(TYPE)); + printout(DEBUG, "Geant4Handle<Geant4Sensitive>", "Object factory for %s not found. Try out %s", typ.second.c_str(), + typ.first.c_str()); + object = PluginService::Create<Geant4Action*>(typ.first, ctxt, typ.second); + if (!object) { + size_t idx = typ.first.rfind(':'); + if (idx != string::npos) + typ.first = string(typ.first.substr(idx + 1)); + printout(DEBUG, "Geant4Handle<Geant4Sensitive>", "Try out object factory for %s", typ.first.c_str()); + object = PluginService::Create<Geant4Action*>(typ.first, ctxt, typ.second); + } + } + if (object) { + TYPE* ptr = dynamic_cast<TYPE*>(object); + if (ptr) { + value = ptr; + return; + } + throw runtime_error( + format("Geant4Handle", "Failed to convert object of type %s to handle of type %s!", type_name.c_str(), + typeinfoName(typeid(TYPE)).c_str())); + } + throw runtime_error(format("Geant4Handle", "Failed to create object of type %s!", type_name.c_str())); +} + template <typename TYPE> Geant4Handle<TYPE>::~Geant4Handle() { if (value) value->release(); diff --git a/DDG4/src/Geant4TrackInformation.cpp b/DDG4/src/Geant4TrackInformation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..449dcaf5a696d19b464242b47d7cf4cc1ed1a59d --- /dev/null +++ b/DDG4/src/Geant4TrackInformation.cpp @@ -0,0 +1,28 @@ +// $Id: Geant4Converter.cpp 603 2013-06-13 21:15:14Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#include "DDG4/Geant4TrackInformation.h" + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Simulation; + +/// Default constructor +Geant4TrackInformation::Geant4TrackInformation() + : G4VUserTrackInformation(), m_flags(0) { +} + +/// Standard destructor +Geant4TrackInformation::~Geant4TrackInformation() { +} + +/// Access flag if track should be stored +Geant4TrackInformation& Geant4TrackInformation::storeTrack(bool value) { + value ? m_flags |= STORE : m_flags &= ~STORE; + return *this; +} diff --git a/DDG4/src/Geant4TrackingAction.cpp b/DDG4/src/Geant4TrackingAction.cpp index ec703b5a63d653bf40c552b14983fd7707a99053..71004543326e683f73e6b257d2e5a3ac70765c96 100644 --- a/DDG4/src/Geant4TrackingAction.cpp +++ b/DDG4/src/Geant4TrackingAction.cpp @@ -11,6 +11,7 @@ #include "DD4hep/InstanceCount.h" #include "DDG4/Geant4TrackingAction.h" #include "DDG4/Geant4MonteCarloTruth.h" +#include "DDG4/Geant4TrackInformation.h" // Geant4 include files #include "G4Track.hh" diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index 87af8af44913fba8fe2aea2e1dc39302e795950d..45ea049e5213a9d07c8a837d54c4c407cf509179 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -117,7 +117,7 @@ namespace { printout(ERROR, "Geant4VolumeManager", "populate: Severe error: Duplicated Geant4 path!!!! %s", " [THIS SHOULD NEVER HAPPEN]"); - for(Geant4Mapping::PlacementPath::const_iterator j=path.begin(); j!=path.end(); ++j) { + for(Geant4Mapping::PlacementPath::const_reverse_iterator j=path.rbegin(); j!=path.rend(); ++j) { log << "/" << (*j)->GetName(); } printout(ERROR, "Geant4VolumeManager", " Geant4 path has >= 2 instances: %s", log.str().c_str()); @@ -139,7 +139,7 @@ namespace { code, " [THIS SHOULD NEVER HAPPEN]"); const Geant4Mapping::PlacementPath& path = (*i).second; - for(Geant4Mapping::PlacementPath::const_iterator j=path.begin(); j!=path.end(); ++j) { + for(Geant4Mapping::PlacementPath::const_reverse_iterator j=path.rbegin(); j!=path.rend(); ++j) { log << "/" << (*j)->GetName(); } printout(ERROR, "Geant4VolumeManager", " Geant4 path: %s", log.str().c_str());