diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index d0745f3ce188694dd735f3b86d0ee6717365bd5c..11b76216322f99486a8848b0379a3ae071f9b7c2 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -72,7 +72,6 @@ install(FILES python/DD4hep.py python/DDG4.py python/DDG4Dict.C - python/DDG4Dict.h DESTINATION python) install(TARGETS DD4hepG4 DD4hepG4Plugins DD4hepG4Legacy g4gdmlDisplay diff --git a/DDG4/examples/CLICSidSimu.py b/DDG4/examples/CLICSidSimu.py index 2be162aebb71568408a9b57f9436e1ea7d451981..37b259bc86dcf506a6a5780b7f2fd625df1cb526 100644 --- a/DDG4/examples/CLICSidSimu.py +++ b/DDG4/examples/CLICSidSimu.py @@ -154,8 +154,8 @@ def run(): part.SaveProcesses = ['Decay'] part.OutputLevel = 4 # generator_output_level part.enableUI() - user = DDG4.Action(kernel,"Geant4UserParticleHandler/UserParticleHandler") - part.adopt(user) + #user = DDG4.Action(kernel,"Geant4UserParticleHandler/UserParticleHandler") + #part.adopt(user) """ rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader") diff --git a/DDG4/include/DDG4/DDG4Dict.h b/DDG4/include/DDG4/DDG4Dict.h new file mode 100644 index 0000000000000000000000000000000000000000..1ad0e8a530056e8e70bb1109f3d42df5bec3a2a1 --- /dev/null +++ b/DDG4/include/DDG4/DDG4Dict.h @@ -0,0 +1,129 @@ +// $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 +// +//==================================================================== +#ifndef DD4HEP_DDG4_DDG4DICT_H +#define DD4HEP_DDG4_DDG4DICT_H + +// FRamework include files +#include "DDG4/Geant4Data.h" +#include "DDG4/Geant4Particle.h" +namespace DD4hep { + namespace DDSegmentation { } + namespace Simulation { } + namespace Geometry { } +} + +// CINT configuration +#if defined(__MAKECINT__) +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +/// Define namespaces +#pragma link C++ namespace DD4hep; +#pragma link C++ namespace DD4hep::Geometry; +#pragma link C++ namespace DD4hep::Simulation; + +/// Simple stuff +#pragma link C++ class DD4hep::Simulation::SimpleRun+; +#pragma link C++ class DD4hep::Simulation::SimpleEvent+; +#pragma link C++ class DD4hep::Simulation::DataExtension+; + +#pragma link C++ class std::auto_ptr<DD4hep::Simulation::DataExtension>+; + +/// Dictionaires for Geant4 particles +#pragma link C++ class DD4hep::Simulation::ParticleExtension+; +#pragma link C++ class std::auto_ptr<DD4hep::Simulation::ParticleExtension>+; +#pragma link C++ class DD4hep::Simulation::Geant4Particle+; +#pragma link C++ class std::vector<DD4hep::Simulation::Geant4Particle*>+; +#pragma link C++ class std::map<int,DD4hep::Simulation::Geant4Particle*>+; + +/// Dictionaires for basic Hit data structures +#pragma link C++ class DD4hep::Simulation::Geant4HitData+; +#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+; + +/// Dictionaires for Tracker Hit data structures +#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*>+; + +/// Dictionaires for Calorimeter Hit data structures +#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*>+; + +#endif + +#ifdef __DDG4_STANDALONE_DICTIONARIES__ +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + /* + * Simulation namespace declaration + */ + namespace Simulation { +#define NO_CALL { throw "This function shoule never ever be called!"; } + /// Default constructor + inline SimpleRun::SimpleRun() { } + /// Default destructor + inline SimpleRun::~SimpleRun() { } + /// Default constructor + inline SimpleEvent::SimpleEvent() { } + /// Default destructor + inline SimpleEvent::~SimpleEvent() { } + + /// Default destructor + inline DataExtension::~DataExtension() { } + /// Default destructor + inline ParticleExtension::~ParticleExtension() { } + /// Default constructor + inline Geant4Particle::Geant4Particle() { } + /// Copy constructor + inline Geant4Particle::Geant4Particle(const Geant4Particle&) { NO_CALL } + /// Default destructor + inline Geant4Particle::~Geant4Particle() { } + /// Remove daughter from set + inline void Geant4Particle::removeDaughter(int) { NO_CALL } + /// Default constructor + inline Geant4HitData::Geant4HitData() { } + /// Default destructor + inline Geant4HitData::~Geant4HitData() { } + /// Extract the MC contribution for a given hit from the step information + inline Geant4HitData::Contribution Geant4HitData::extractContribution(G4Step*) { return Contribution(); } + /// Default constructor + inline Geant4Tracker::Hit::Hit() { } + /// Initializing constructor + inline Geant4Tracker::Hit::Hit(int, int, double, double) {} + /// Default destructor + inline Geant4Tracker::Hit::~Hit() { } + /// Assignment operator + inline Geant4Tracker::Hit& Geant4Tracker::Hit::operator=(const Hit&) { return *this; } + /// Clear hit content + inline Geant4Tracker::Hit& Geant4Tracker::Hit::clear() { return *this; } + /// Store Geant4 point and step information into tracker hit structure. + inline Geant4Tracker::Hit& Geant4Tracker::Hit::storePoint(G4Step*, G4StepPoint*) { return *this;} + /// Default constructor + inline Geant4Calorimeter::Hit::Hit() { } + /// Initializing constructor + inline Geant4Calorimeter::Hit::Hit(const Position&) {} + /// Default destructor + inline Geant4Calorimeter::Hit::~Hit() { } + } +} +#undef NO_CALL + +#endif // __DDG4_STANDALONE_DICTIONARIES__ + +#endif /* DD4HEP_DDG4_DDG4DICT_H */ diff --git a/DDG4/include/DDG4/Geant4Data.h b/DDG4/include/DDG4/Geant4Data.h index 3d51abafe72ad332bdd06a4ffa0d3cdc83dcecc7..c5cf525cb06e3566bc38bcb903d117f4955a5d1c 100644 --- a/DDG4/include/DDG4/Geant4Data.h +++ b/DDG4/include/DDG4/Geant4Data.h @@ -10,19 +10,16 @@ #define DD4HEP_GEANT4DATA_H // Framework include files -#ifndef __DD4HEP_DDEVE_EXCLUSIVE__ -#include "DD4hep/Objects.h" -#include "G4Step.hh" -class G4PrimaryParticle; -#else -typedef void* G4Step; -typedef void* G4StepPoint; -typedef void* G4PrimaryParticle; -#endif +#include "Math/Vector3D.h" // C/C++ include files #include <set> #include <memory> +#include <vector> + +// Forward declarations +class G4Step; +class G4StepPoint; /* * DD4hep namespace declaration @@ -35,13 +32,8 @@ namespace DD4hep { namespace Simulation { // Forward type definitions - typedef Geometry::Position Position; - typedef Geometry::Position Direction; - - // Forward declarations - class Geant4Particle; - class Geant4Vertex; - + typedef ROOT::Math::XYZVector Position; + typedef ROOT::Math::XYZVector Direction; /** @class HitCompare Geant4Data.h DDG4/Geant4Data.h * @@ -132,7 +124,7 @@ namespace DD4hep { * @version 1.0 */ struct Geant4HitData { - // cellID + /// cellID long long int cellID; /// User data extension if required std::auto_ptr<DataExtension> extension; @@ -148,21 +140,33 @@ namespace DD4hep { double deposit; /// Timestamp when this energy was deposited double time; + /// Proper position of the hit contribution + float x,y,z; + /// Default constructor MonteCarloContrib() - : trackID(-1), pdgID(-1), deposit(0.0), time(0.0) { + : trackID(-1), pdgID(-1), deposit(0.0), time(0.0), x(0), y(0), z(0) { } /// Initializing constructor - MonteCarloContrib(int track_id, double dep, double time_stamp) - : trackID(track_id), pdgID(-1), deposit(dep), time(time_stamp) { + MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp) + : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), x(0), y(0), z(0) { } /// Initializing constructor - MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp) - : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp) { + MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, float* pos) + : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), + x(pos[0]), y(pos[1]), z(pos[2]) + { + } + /// Initializing constructor + MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double* pos) + : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), + x(pos[0]), y(pos[1]), z(pos[2]) + { } /// Copy constructor MonteCarloContrib(const MonteCarloContrib& c) - : trackID(c.trackID), pdgID(c.pdgID), deposit(c.deposit), time(c.time) { + : trackID(c.trackID), pdgID(c.pdgID), deposit(c.deposit), time(c.time), + x(c.x), y(c.y), z(c.z) { } /// Assignment operator MonteCarloContrib& operator=(const MonteCarloContrib& c) { @@ -171,11 +175,15 @@ namespace DD4hep { pdgID = c.pdgID; deposit = c.deposit; time = c.time; + x = c.x; + y = c.y; + z = c.z; } return *this; } /// Clear data content void clear() { + x = y = z = 0.0; time = deposit = 0.0; pdgID = trackID = -1; } diff --git a/DDG4/include/DDG4/Geant4HitCollection.h b/DDG4/include/DDG4/Geant4HitCollection.h index 1d13183e96db7b005a901e488a3c7677d58979c4..3978dbd59db56880c656275282e633ba61a9155c 100644 --- a/DDG4/include/DDG4/Geant4HitCollection.h +++ b/DDG4/include/DDG4/Geant4HitCollection.h @@ -26,15 +26,13 @@ */ namespace DD4hep { - /// Forward declarations - namespace Geometry { class SensitiveDetectorObject; } - /* * Simulation namespace declaration */ namespace Simulation { // Forward declarations + class Geant4Sensitive; class Geant4HitCollection; class Geant4HitWrapper; @@ -176,8 +174,6 @@ namespace DD4hep { typedef std::vector<Geant4HitWrapper> WrappedHits; /// Hit manipulator typedef Geant4HitWrapper::HitManipulator Manip; - /// Sensitive detector - typedef Geometry::Handle<Geometry::SensitiveDetectorObject> SensitiveDetector; /** @class Compare Geant4HitCollection.h DDG4/Geant4HitCollection.h * @@ -197,7 +193,7 @@ namespace DD4hep { /// The collection of hit pointers in the wrapped format WrappedHits m_hits; /// Handle to the sensitive detector - SensitiveDetector m_detector; + Geant4Sensitive* m_detector; /// The type of the objects in this collection. Set by the constructor Manip* m_manipulator; @@ -214,7 +210,7 @@ namespace DD4hep { public: /// Initializing constructor (C++ version) template <typename TYPE> - Geant4HitCollection(const std::string& det, const std::string& coll, SensitiveDetector sd) + Geant4HitCollection(const std::string& det, const std::string& coll, Geant4Sensitive* sd) : G4VHitsCollection(det, coll), m_detector(sd), m_manipulator(Geant4HitWrapper::manipulator<TYPE>()) { newInstance(); @@ -222,7 +218,7 @@ namespace DD4hep { } /// Initializing constructor template <typename TYPE> - Geant4HitCollection(const std::string& det, const std::string& coll, SensitiveDetector sd, const TYPE*) + Geant4HitCollection(const std::string& det, const std::string& coll, Geant4Sensitive* sd, const TYPE*) : G4VHitsCollection(det, coll), m_detector(sd), m_manipulator(Geant4HitWrapper::manipulator<TYPE>()) { newInstance(); @@ -230,16 +226,20 @@ namespace DD4hep { } /// Default destructor virtual ~Geant4HitCollection(); - /// Set the sensitive detector - void setSensitiveDetector(SensitiveDetector detector); - /// Access the sensitive detector - SensitiveDetector sensitiveDetector() const; /// Type information of the object stored const ComponentCast& type() const; /// Type information of the vector type for extracting data const ComponentCast& vector_type() const; /// Clear the collection (Deletes all valid references to real hits) virtual void clear(); + /// Set the sensitive detector + void setSensitive(Geant4Sensitive* detector) { + m_detector = detector; + } + /// Access the sensitive detector + Geant4Sensitive* sensitive() const { + return m_detector; + } /// Access individual hits virtual G4VHit* GetHit(size_t which) const { return (G4VHit*) &m_hits.at(which); diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h index 5382f8ceff1a4bd470fd9a8df40d01270d2cea02..f79faa0e283c2d9c7f448410048b67e94733900b 100644 --- a/DDG4/include/DDG4/Geant4Particle.h +++ b/DDG4/include/DDG4/Geant4Particle.h @@ -133,7 +133,8 @@ namespace DD4hep { void removeDaughter(int id_daughter); }; -#ifndef __DD4HEP_DDEVE_EXCLUSIVE__ +#ifndef __DDG4_STANDALONE_DICTIONARIES__ + /// Data structure to access MC particle information /** * @author M.Frank diff --git a/DDG4/include/DDG4/Geant4SensDetAction.h b/DDG4/include/DDG4/Geant4SensDetAction.h index 9b720a68aaee25230e7fb65eabf55d16e9ac1fcb..2ec461117ac90d5e18eebbdcbdcb6f1ac6509a62 100644 --- a/DDG4/include/DDG4/Geant4SensDetAction.h +++ b/DDG4/include/DDG4/Geant4SensDetAction.h @@ -88,7 +88,8 @@ namespace DD4hep { * @author M.Frank * @version 1.0 */ - struct Geant4Sensitive: public Geant4Action { + class Geant4Sensitive: public Geant4Action { + public: typedef Geometry::LCDD LCDD; typedef Geometry::Readout Readout; typedef Geometry::DetElement DetElement; @@ -97,6 +98,12 @@ namespace DD4hep { typedef Geant4StepHandler StepHandler; typedef Geant4HitCollection HitCollection; + enum HitCreationFlags { + SIMPLE_MODE = 0, + MEDIUM_MODE = 1<<0, + DETAILED_MODE = 1<<1 + }; + private: /// Reference to G4 sensitive detector Geant4ActionSD* m_sensitiveDetector; @@ -104,6 +111,8 @@ namespace DD4hep { Geant4SensDetActionSequence* m_sequence; protected: + /// Property: Hit creation mode. Maybe one of the enum HitCreationFlags + int m_hitCreationMode; /// Reference to the detector description object LCDD& m_lcdd; /// Reference to the detector element describing this sensitive element @@ -130,6 +139,11 @@ namespace DD4hep { /// Access to the sensitive detector object void setDetector(Geant4ActionSD* sens_det); + /// Property access to the hit creation mode + int hitCreationMode() const { + return m_hitCreationMode; + } + /// G4VSensitiveDetector internals: Access to the detector name std::string detectorName() const { return detector().name(); @@ -150,6 +164,11 @@ namespace DD4hep { return detector().isActive(); } + /// Access the DD4hep sensitive detector + SensitiveDetector sensitiveDetector() const { + return m_sensitive; + } + /// Access to the readout geometry of the sensitive detector G4VReadOutGeometry* readoutGeometry() const { return detector().readoutGeometry(); @@ -233,8 +252,9 @@ namespace DD4hep { public: typedef Geometry::SensitiveDetector SensitiveDetector; - typedef Geant4HitCollection* (*create_t)(const std::string&, const std::string&, SensitiveDetector); - typedef std::vector<std::pair<std::string, create_t> > HitCollections; + typedef Geant4HitCollection* (*create_t)(const std::string&, const std::string&, Geant4Sensitive*); + typedef std::pair<std::string, std::pair<Geant4Sensitive*,create_t> > HitCollection; + typedef std::vector<HitCollection> HitCollections; protected: /// Geant4 hit collection context @@ -260,7 +280,7 @@ namespace DD4hep { Geant4ActionSD* m_detector; /// Create a new typed hit collection - template <typename TYPE> static Geant4HitCollection* _create(const std::string& det, const std::string& coll, SensitiveDetector sd) { + template <typename TYPE> static Geant4HitCollection* _create(const std::string& det, const std::string& coll, Geant4Sensitive* sd) { return new Geant4HitCollection(det, coll, sd, (TYPE*) 0); } @@ -275,11 +295,11 @@ namespace DD4hep { size_t defineCollections(Geant4ActionSD* sens_det); /// Initialize the usage of a hit collection. Returns the collection identifier - size_t defineCollection(const std::string& name, create_t func); + size_t defineCollection(Geant4Sensitive* owner, const std::string& name, create_t func); /// Define a named collection containing hist of a specified type - template <typename TYPE> size_t defineCollection(const std::string& coll_name) { - return defineCollection(coll_name, Geant4SensDetActionSequence::_create<TYPE>); + template <typename TYPE> size_t defineCollection(Geant4Sensitive* owner, const std::string& coll_name) { + return defineCollection(owner, coll_name, Geant4SensDetActionSequence::_create<TYPE>); } /// Access HitCollection container names @@ -382,7 +402,7 @@ namespace DD4hep { /// Initialize the usage of a single hit collection. Returns the collection ID template <typename TYPE> inline size_t Geant4Sensitive::defineCollection(const std::string& coll_name) { - return sequence().defineCollection<TYPE>(coll_name); + return sequence().defineCollection<TYPE>(this, coll_name); } } // End namespace Simulation diff --git a/DDG4/include/DDG4/Geant4StepHandler.h b/DDG4/include/DDG4/Geant4StepHandler.h index 57faa0354fb2b461397d85a8af7ed5cef1d046d1..9539f3018413e4b72d6944573761bf96d9b4f433 100644 --- a/DDG4/include/DDG4/Geant4StepHandler.h +++ b/DDG4/include/DDG4/Geant4StepHandler.h @@ -57,20 +57,31 @@ namespace DD4hep { int trkPdgID() const { return track->GetDefinition()->GetPDGEncoding(); } + /// Returns the step status (argument) in form of a string static const char* stepStatus(G4StepStatus status); + /// Returns the pre-step status in form of a string const char* preStepStatus() const; + /// Returns the post-step status in form of a string const char* postStepStatus() const; + /// Returns total energy deposit + double totalEnergy() const { + return step->GetTotalEnergyDeposit(); + } + /// Returns the pre-step position Position prePos() const { const G4ThreeVector& p = pre->GetPosition(); return Position(p.x(), p.y(), p.z()); } + /// Returns the pre-step position as a G4ThreeVector const G4ThreeVector& prePosG4() const { return pre->GetPosition(); } + /// Returns the post-step position Position postPos() const { const G4ThreeVector& p = post->GetPosition(); return Position(p.x(), p.y(), p.z()); } + /// Returns the post-step position as a G4ThreeVector const G4ThreeVector& postPosG4() const { return post->GetPosition(); } @@ -92,6 +103,9 @@ namespace DD4hep { int trkID() const { return track->GetTrackID(); } + double trkTime() const { + return track->GetGlobalTime(); + } double trkEnergy() const { return track->GetTotalEnergy(); } @@ -153,6 +167,16 @@ namespace DD4hep { bool lastInVolume() const { return step->IsLastStepInVolume(); } + /// Coordinate transformation to global coordinates. + /** Note: Positions are in units of MM! */ + Position localToGlobal(const Position& local) const; + /// Coordinate transformation to global coordinates. + /** Note: DDSegmentation points are units in CM! Conversion done inside! */ + Position localToGlobal(const DDSegmentation::Vector3D& local) const; + /// Coordinate transformation to global coordinates in MM + Position localToGlobal(const G4ThreeVector& local) const; + /// Coordinate transformation to global coordinates in MM + Position localToGlobal(double x, double y, double z) const; }; } // End namespace Simulation diff --git a/DDG4/lcio/Geant4Output2LCIO.cpp b/DDG4/lcio/Geant4Output2LCIO.cpp index ebad8b6a9f382797d95272fc1c4c6c940d9d8faa..19159214cb346993683806ed6a936b20193d01d8 100644 --- a/DDG4/lcio/Geant4Output2LCIO.cpp +++ b/DDG4/lcio/Geant4Output2LCIO.cpp @@ -172,7 +172,7 @@ void Geant4Output2LCIO::saveEvent(OutputContext<G4Event>& ctxt) { typedef Geant4Conversion<lcio::LCCollectionVec,_Args> _C; const _C& cnv = _C::converter(typeid(Geant4ParticleMap)); lcio::LCCollectionVec* col = cnv(_Args(context(),part_map)); - evt->addCollection(col,"McParticles"); + evt->addCollection(col,lcio::LCIO::MCPARTICLE); } } } diff --git a/DDG4/lcio/LCIOConversions.cpp b/DDG4/lcio/LCIOConversions.cpp index 0e3a6515eab13f12e7b36935957d3fa8e9d26fac..0f703c26f135289866279c29889710207da34b96 100644 --- a/DDG4/lcio/LCIOConversions.cpp +++ b/DDG4/lcio/LCIOConversions.cpp @@ -13,6 +13,7 @@ #include "DD4hep/Printout.h" #include "DDG4/Geant4HitCollection.h" #include "DDG4/Geant4DataConversion.h" +#include "DDG4/Geant4SensDetAction.h" #include "DDG4/Geant4Context.h" #include "DDG4/Geant4Primary.h" #include "DDG4/Geant4Data.h" @@ -30,6 +31,22 @@ #include "UTIL/ILDConf.h" using namespace std; +//================================================================================== +// +// SimCalorimeterHit: +// ------------------ +// LCIO::CHBIT_STEP If detailed mode set | YES if detailed +// LCIO::CHBIT_LONG: Position is stored | YES +// LCIO::CHBIT_ID1: CellID1 is stored | YES +// +// +// SimTrackerHit: +// -------------- +// LCIO::THBIT_ID1: CellID1 is stored (TrackerHit) | YES +// LCIO::THBIT_MOMENTUM: Momentum is stored | YES if detailed +// +//================================================================================== + /* * DD4hep namespace declaration */ @@ -79,14 +96,22 @@ namespace DD4hep { pair<const Geant4Context*,Geant4HitCollection*>, Geant4Tracker::Hit>::operator()(const arg_t& args) const { - Geant4HitCollection* coll = args.second; - size_t nhits = coll->GetSize(); - string dsc = encoding(coll->sensitiveDetector()); - Geant4ParticleMap* pm = args.first->event().extension<Geant4ParticleMap>(); - lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>(); - EVENT::LCCollection* lc_part = lc_evt->getCollection("McParticles"); + Geant4HitCollection* coll = args.second; + Geant4Sensitive* sd = coll->sensitive(); + size_t nhits = coll->GetSize(); + string dsc = encoding(sd->sensitiveDetector()); + Geant4ParticleMap* pm = args.first->event().extension<Geant4ParticleMap>(); + lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>(); + EVENT::LCCollection* lc_part = lc_evt->getCollection(lcio::LCIO::MCPARTICLE); lcio::LCCollectionVec* lc_coll = new lcio::LCCollectionVec(lcio::LCIO::SIMTRACKERHIT); UTIL::CellIDEncoder<SimTrackerHit> decoder(dsc,lc_coll); + int hit_creation_mode = sd->hitCreationMode(); + + if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) + lc_coll->setFlag(UTIL::make_bitset32(LCIO::THBIT_MOMENTUM,LCIO::THBIT_ID1)); + else + lc_coll->setFlag(LCIO::THBIT_ID1); + lc_coll->reserve(nhits); for(size_t i=0; i<nhits; ++i) { const Geant4Tracker::Hit* hit = coll->hit(i); @@ -94,16 +119,15 @@ namespace DD4hep { int trackID = pm->particleID(t.trackID); EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*)lc_part->getElementAt(trackID); double pos[3] = {hit->position.x(), hit->position.y(), hit->position.z()}; - float mom[3] = {hit->momentum.x(), hit->momentum.y(), hit->momentum.z()}; lcio::SimTrackerHitImpl* lc_hit = new lcio::SimTrackerHitImpl; - lc_hit->setCellID0( (hit->cellID >> 0 ) & 0xFFFFFFFF); - lc_hit->setCellID1( (hit->cellID >> sizeof( int ) ) & 0xFFFFFFFF); + lc_hit->setCellID0((hit->cellID >> 0 ) & 0xFFFFFFFF); + lc_hit->setCellID1((hit->cellID >> sizeof(int)) & 0xFFFFFFFF); lc_hit->setEDep(hit->energyDeposit); lc_hit->setPathLength(hit->length); lc_hit->setTime(hit->truth.time); lc_hit->setMCParticle(lc_mcp); lc_hit->setPosition(pos); - lc_hit->setMomentum(mom); + lc_hit->setMomentum(hit->momentum.x(),hit->momentum.y(),hit->momentum.z()); lc_coll->addElement(lc_hit); } return lc_coll; @@ -124,31 +148,45 @@ namespace DD4hep { pair<const Geant4Context*,Geant4HitCollection*>, Geant4Calorimeter::Hit>::operator()(const arg_t& args) const { typedef Geant4HitData::Contributions Contributions; - Geant4HitCollection* coll = args.second; - size_t nhits = coll->GetSize(); - string dsc = encoding(coll->sensitiveDetector()); - Geant4ParticleMap* pm = args.first->event().extension<Geant4ParticleMap>(); - lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>(); - EVENT::LCCollection* lc_parts = lc_evt->getCollection("McParticles"); - lcio::LCCollectionVec* lc_coll = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT); + Geant4HitCollection* coll = args.second; + Geant4Sensitive* sd = coll->sensitive(); + size_t nhits = coll->GetSize(); + string dsc = encoding(sd->sensitiveDetector()); + Geant4ParticleMap* pm = args.first->event().extension<Geant4ParticleMap>(); + lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>(); + EVENT::LCCollection* lc_parts = lc_evt->getCollection(lcio::LCIO::MCPARTICLE); + lcio::LCCollectionVec* lc_coll = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT); UTIL::CellIDEncoder<SimCalorimeterHit> decoder(dsc,lc_coll); - lc_coll->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1)); + int hit_creation_mode = sd->hitCreationMode(); + + if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) + lc_coll->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1)); + else + lc_coll->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1)); + lc_coll->reserve(nhits); + if ( sd->hasProperty("HitCreationMode") ) { + hit_creation_mode = sd->property("HitCreationMode").value<int>(); + } for(size_t i=0; i<nhits; ++i) { const Geant4Calorimeter::Hit* hit = coll->hit(i); float pos[3] = {hit->position.x(), hit->position.y(), hit->position.z()}; lcio::SimCalorimeterHitImpl* lc_hit = new lcio::SimCalorimeterHitImpl; - lc_hit->setCellID0(( hit->cellID >> 0 ) & 0xFFFFFFFF); - lc_hit->setCellID1(( hit->cellID >> sizeof(int)) & 0xFFFFFFFF); // ???? + lc_hit->setCellID0((hit->cellID >> 0 ) & 0xFFFFFFFF); + lc_hit->setCellID1((hit->cellID >> sizeof(int)) & 0xFFFFFFFF); // ???? lc_hit->setPosition(pos); - lc_hit->setEnergy( hit->energyDeposit ); + ///No! Done when adding particle contrbutions: lc_hit->setEnergy( hit->energyDeposit ); lc_coll->addElement(lc_hit); /// Now add the individual track contributions to the LCIO hit structure for(Contributions::const_iterator j=hit->truth.begin(); j!=hit->truth.end(); ++j) { const Geant4HitData::Contribution& c = *j; int trackID = pm->particleID(c.trackID); + float pos[] = {c.x, c.y, c.z}; EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*)lc_parts->getElementAt(trackID); - lc_hit->addMCParticleContribution(lc_mcp,c.deposit,c.time); + if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) + lc_hit->addMCParticleContribution(lc_mcp, c.deposit, c.time, c.pdgID, pos); + else + lc_hit->addMCParticleContribution(lc_mcp, c.deposit, c.time); } } return lc_coll; @@ -188,8 +226,15 @@ namespace DD4hep { pair<const Geant4Context*,Geant4HitCollection*>, lcio::SimTrackerHitImpl>::operator()(const arg_t& args) const { - string dsc = encoding(args.second->sensitiveDetector()); - output_t* lc = new lcio::LCCollectionVec(lcio::LCIO::SIMTRACKERHIT); + Geant4Sensitive* sd = args.second->sensitive(); + string dsc = encoding(sd->sensitiveDetector()); + output_t* lc = new lcio::LCCollectionVec(lcio::LCIO::SIMTRACKERHIT); + int hit_creation_mode = sd->hitCreationMode(); + + if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) + lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1)); + else + lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1)); UTIL::CellIDEncoder<SimTrackerHit> decoder(dsc,lc); return moveEntries<lcio::SimTrackerHitImpl>(args.second,lc); } @@ -212,10 +257,15 @@ namespace DD4hep { pair<const Geant4Context*,Geant4HitCollection*>, lcio::SimCalorimeterHitImpl>::operator()(const arg_t& args) const { - string dsc = encoding(args.second->sensitiveDetector()); - output_t* lc = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT); - UTIL::CellIDEncoder<SimCalorimeterHit> decoder(dsc,lc); - lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1)); + Geant4Sensitive* sd = args.second->sensitive(); + string dsc = encoding(args.second->sensitive()->sensitiveDetector()); + output_t* lc = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT); + int hit_creation_mode = sd->hitCreationMode(); + + if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) + lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1)); + else + lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1)); return moveEntries<tag_t>(args.second,lc); } diff --git a/DDG4/lcio/LCIOEventReader.h b/DDG4/lcio/LCIOEventReader.h index b7b2a5eaf2bab6344b3ab3492eb150ad43a4297e..ffb6587c18d531e13d25b5515898754499f87bb5 100644 --- a/DDG4/lcio/LCIOEventReader.h +++ b/DDG4/lcio/LCIOEventReader.h @@ -11,14 +11,7 @@ #include <string> // Forward declarations -class G4Event; -namespace IO { class LCReader; } -namespace UTIL { class LCStdHepRdr; } -namespace EVENT { class MCParticle; } namespace EVENT { class LCCollection; } -namespace IMPL { class MCParticleImpl; } -namespace IMPL { class LCCollectionVec; } - /* * DD4hep namespace declaration @@ -63,6 +56,7 @@ namespace DD4hep { } /* End namespace Simulation */ } /* End namespace DD4hep */ + #include "DD4hep/Plugins.h" namespace { /// Factory to create Geant4 physics constructions diff --git a/DDG4/lcio/LCIOFileReader.cpp b/DDG4/lcio/LCIOFileReader.cpp index dfa955cfbc65157493a17f9d90f4dfb0635002ed..433506fef379ffba2f1be71d590a153872651bf0 100644 --- a/DDG4/lcio/LCIOFileReader.cpp +++ b/DDG4/lcio/LCIOFileReader.cpp @@ -4,10 +4,15 @@ //-------------------------------------------------------------------- // //==================================================================== +#ifndef DD4HEP_DDG4_LCIOFILEREADER_H +#define DD4HEP_DDG4_LCIOFILEREADER_H // Framework include files #include "LCIOEventReader.h" +// Forward declarations +namespace IO { class LCReader; } + /* * DD4hep namespace declaration */ @@ -39,6 +44,7 @@ namespace DD4hep { }; } } +#endif // DD4HEP_DDG4_LCIOFILEREADER_H #include "DD4hep/Printout.h" #include "DD4hep/Primitives.h" diff --git a/DDG4/lcio/LCIOStdHepReader.cpp b/DDG4/lcio/LCIOStdHepReader.cpp index 8da479885285f63e4d62d0ade47c1b8021208d56..a9641b9cad84aa43397783b3a05453f05e1c9009 100644 --- a/DDG4/lcio/LCIOStdHepReader.cpp +++ b/DDG4/lcio/LCIOStdHepReader.cpp @@ -4,10 +4,14 @@ //-------------------------------------------------------------------- // //==================================================================== - +#ifndef DD4HEP_DDG4_LCIOSTDHEPREADER_H +#define DD4HEP_DDG4_LCIOSTDHEPREADER_H // Framework include files #include "LCIOEventReader.h" +// Forward declarations +namespace UTIL { class LCStdHepRdr; } + /* * DD4hep namespace declaration */ @@ -39,7 +43,7 @@ namespace DD4hep { }; } /* End namespace lcio */ } /* End namespace DD4hep */ - +#endif /* DD4HEP_DDG4_LCIOSTDHEPREADER_H */ #include "lcio.h" #include "EVENT/LCIO.h" diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index 0a4dfe0a3ff31df98668fac1667820b52a8aba88..608c6ca48c27ee7cae059a3e2ad0cbb68a985d35 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -128,16 +128,16 @@ namespace DD4hep { }; /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - /// Geant4SensitiveAction<SimpleTracker> + /// Geant4SensitiveAction<Geant4Tracker> /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// Define collections created by this sensitivie action object - template <> void Geant4SensitiveAction<SimpleTracker>::defineCollections() { - m_collectionID = defineCollection<SimpleTracker::Hit>(m_sensitive.readout().name()); + template <> void Geant4SensitiveAction<Geant4Tracker>::defineCollections() { + m_collectionID = defineCollection<Geant4Tracker::Hit>(m_sensitive.readout().name()); } /// Method for generating hit(s) using the information of G4Step object. - template <> bool Geant4SensitiveAction<SimpleTracker>::process(G4Step* step,G4TouchableHistory* /*hist*/ ) { - typedef SimpleTracker::Hit Hit; + template <> bool Geant4SensitiveAction<Geant4Tracker>::process(G4Step* step,G4TouchableHistory* /*hist*/ ) { + typedef Geant4Tracker::Hit Hit; StepHandler h(step); Position prePos = h.prePos(); Position postPos = h.postPos(); @@ -151,7 +151,7 @@ namespace DD4hep { double new_len = mean_length(h.preMom(),h.postMom())/hit_len; direction *= new_len/hit_len; } - print("SimpleTracker","%s> Add hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f", + print("Geant4Tracker","%s> Add hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f", c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z()); Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime()); if ( hit ) { @@ -167,67 +167,67 @@ namespace DD4hep { hit->cellID = volumeID( step ) ; throw runtime_error("Invalid CELL ID for hit!"); } - print("SimpleTracker","%s> Hit with deposit:%f Pos:%f %f %f ID=%016X", + print("Geant4Tracker","%s> Hit with deposit:%f Pos:%f %f %f ID=%016X", c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(), (void*)hit->cellID); Geant4TouchableHandler handler(step); - print("SimpleTracker","%s> Geant4 path:%s",c_name(),handler.path().c_str()); + print("Geant4Tracker","%s> Geant4 path:%s",c_name(),handler.path().c_str()); return true; } throw runtime_error("new() failed: Cannot allocate hit object"); } - typedef Geant4SensitiveAction<SimpleTracker> Geant4SimpleTrackerAction; + typedef Geant4SensitiveAction<Geant4Tracker> Geant4TrackerAction; /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// Geant4SensitiveAction<Calorimeter> /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// Define collections created by this sensitivie action object - template <> void Geant4SensitiveAction<SimpleCalorimeter>::defineCollections() { - m_collectionID = defineCollection<SimpleCalorimeter::Hit>(m_sensitive.readout().name()); + template <> void Geant4SensitiveAction<Geant4Calorimeter>::defineCollections() { + m_collectionID = defineCollection<Geant4Calorimeter::Hit>(m_sensitive.readout().name()); } /// Method for generating hit(s) using the information of G4Step object. - template <> bool Geant4SensitiveAction<SimpleCalorimeter>::process(G4Step* step,G4TouchableHistory*) { - typedef SimpleCalorimeter::Hit Hit; - StepHandler h(step); - Position pos = 0.5 * (h.prePos() + h.postPos()); + template <> bool Geant4SensitiveAction<Geant4Calorimeter>::process(G4Step* step,G4TouchableHistory*) { + typedef Geant4Calorimeter::Hit Hit; + StepHandler h(step); HitContribution contrib = Hit::extractContribution(step); HitCollection* coll = collection(m_collectionID); long long int cell = cellID(step); + Hit* hit = coll->find<Hit>(CellIDCompare<Hit>(cell)); - if ( step->GetTotalEnergyDeposit() < 1e-5 ) return true; - if ( !hit ) { + if ( h.totalEnergy() < numeric_limits<double>::epsilon() ) { + return true; + } + else if ( !hit ) { Geant4TouchableHandler handler(step); - hit = new Hit(h.prePos()); + DDSegmentation::Vector3D pos = m_segmentation.position(cell); + Position global = h.localToGlobal(pos); + hit = new Hit(global); hit->cellID = cell; coll->add(hit); - print("SimpleCalorimeter","%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s", - c_name(),contrib.deposit,pos.X(),pos.Y(),pos.Z(),handler.path().c_str()); - if ( 0 == hit->cellID ) { + printM2("Geant4Calorimeter","%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s", + c_name(),contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str()); + if ( 0 == hit->cellID ) { // for debugging only! hit->cellID = cellID(step); throw runtime_error("Invalid CELL ID for hit!"); } } - else { - print("SimpleCalorimeter","%s> UPDATE hit with deposit:%7.3f MeV Pos:%8.2f %8.2f %8.2f id:%016llX cell:%016llX", - c_name(),contrib.deposit,pos.X(),pos.Y(),pos.Z(),cell,hit->cellID); - } hit->truth.push_back(contrib); hit->energyDeposit += contrib.deposit; - mark(h.track); + mark(step); return true; } - typedef Geant4SensitiveAction<SimpleCalorimeter> Geant4SimpleCalorimeterAction; + typedef Geant4SensitiveAction<Geant4Calorimeter> Geant4CalorimeterAction; /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// Geant4SensitiveAction<OpticalCalorimeter> /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - struct SimpleOpticalCalorimeter {}; + struct Geant4OpticalCalorimeter {}; /// Define collections created by this sensitivie action object - template <> void Geant4SensitiveAction<SimpleOpticalCalorimeter>::defineCollections() { - m_collectionID = defineCollection<SimpleCalorimeter::Hit>(m_sensitive.readout().name()); + template <> void Geant4SensitiveAction<Geant4OpticalCalorimeter>::defineCollections() { + m_collectionID = defineCollection<Geant4Calorimeter::Hit>(m_sensitive.readout().name()); } /// Method for generating hit(s) using the information of G4Step object. - template <> bool Geant4SensitiveAction<SimpleOpticalCalorimeter>::process(G4Step* step,G4TouchableHistory*) { + template <> bool Geant4SensitiveAction<Geant4OpticalCalorimeter>::process(G4Step* step,G4TouchableHistory*) { G4Track * track = step->GetTrack(); // check that particle is optical photon: if( track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() ) { @@ -238,7 +238,7 @@ namespace DD4hep { return false; } else { - typedef SimpleCalorimeter::Hit Hit; + typedef Geant4Calorimeter::Hit Hit; StepHandler h(step); HitCollection* coll = collection(m_collectionID); HitContribution contrib = Hit::extractContribution(step); @@ -260,7 +260,7 @@ namespace DD4hep { return true; } } - typedef Geant4SensitiveAction<SimpleOpticalCalorimeter> Geant4SimpleOpticalCalorimeterAction; + typedef Geant4SensitiveAction<Geant4OpticalCalorimeter> Geant4OpticalCalorimeterAction; #if 0 /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -358,12 +358,21 @@ namespace DD4hep { typedef Geant4SensitiveAction<TrackerCombine> Geant4TrackerCombine; #endif + + typedef Geant4TrackerAction Geant4SimpleTrackerAction; + typedef Geant4CalorimeterAction Geant4SimpleCalorimeterAction; + typedef Geant4OpticalCalorimeterAction Geant4SimpleOpticalCalorimeterAction; } } using namespace DD4hep::Simulation; #include "DDG4/Factories.h" +DECLARE_GEANT4SENSITIVE(Geant4TrackerAction) +DECLARE_GEANT4SENSITIVE(Geant4CalorimeterAction) +DECLARE_GEANT4SENSITIVE(Geant4OpticalCalorimeterAction) + +// Need these factories for backwards compatibility DECLARE_GEANT4SENSITIVE(Geant4SimpleTrackerAction) DECLARE_GEANT4SENSITIVE(Geant4SimpleCalorimeterAction) DECLARE_GEANT4SENSITIVE(Geant4SimpleOpticalCalorimeterAction) diff --git a/DDG4/python/DDG4Dict.C b/DDG4/python/DDG4Dict.C index b670433078d8c59b769bcabd702fce2cf4ee225a..0221e930f83c8fd2b3cfb9a464eac320485055fb 100644 --- a/DDG4/python/DDG4Dict.C +++ b/DDG4/python/DDG4Dict.C @@ -11,24 +11,26 @@ //==================================================================== // FRamework include files #include "DDG4/Geant4Primary.h" -#include "DDG4/Geant4Data.h" -#include "DDG4Dict.h" +#include "DDG4/DDG4Dict.h" // CINT configuration #if defined(__MAKECINT__) #pragma link C++ namespace DD4hep::DDSegmentation; + +/// Geant4 Vertex dictionaries #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::vector<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::PrimaryExtension+; #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; diff --git a/DDG4/python/DDG4Dict.h b/DDG4/python/DDG4Dict.h deleted file mode 100644 index ecfbfe1dddc385bc67f984dc6e93bce74b746e37..0000000000000000000000000000000000000000 --- a/DDG4/python/DDG4Dict.h +++ /dev/null @@ -1,53 +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 "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/Geant4Data.cpp b/DDG4/src/Geant4Data.cpp index 79f54cd37f08af395b319ccd97a0ab5913d36d20..a4a114bfdc7b818ae14ae537f1284b470003b25b 100644 --- a/DDG4/src/Geant4Data.cpp +++ b/DDG4/src/Geant4Data.cpp @@ -11,6 +11,7 @@ #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" #include "DDG4/Geant4Data.h" +#include "DDG4/Geant4StepHandler.h" // Geant4 include files #include "G4Step.hh" @@ -60,11 +61,14 @@ Geant4HitData::~Geant4HitData() { /// Extract the MC contribution for a given hit from the step information Geant4HitData::Contribution Geant4HitData::extractContribution(G4Step* step) { + Geant4StepHandler h(step); G4Track* trk = step->GetTrack(); - double energy_deposit = - (trk->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) ? - trk->GetTotalEnergy() : step->GetTotalEnergyDeposit(); - Contribution contrib(trk->GetTrackID(), trk->GetDefinition()->GetPDGEncoding(), energy_deposit, trk->GetGlobalTime()); + double deposit = + (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy(); + const G4ThreeVector& pre = h.prePosG4(); + const G4ThreeVector& post = h.postPosG4(); + float pos[] = { (pre.x()+post.x())/2.0, (pre.y()+post.y())/2.0, (pre.z()+post.z())/2.0 }; + Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),pos); return contrib; } diff --git a/DDG4/src/Geant4HitCollection.cpp b/DDG4/src/Geant4HitCollection.cpp index b8e110c0705a9dd2878fdf51325d3621d32151ea..b1a1b4604b598f61e8d61ac139c7404a18a39e97 100644 --- a/DDG4/src/Geant4HitCollection.cpp +++ b/DDG4/src/Geant4HitCollection.cpp @@ -75,16 +75,6 @@ Geant4HitCollection::~Geant4HitCollection() { InstanceCount::decrement(this); } -/// Set the sensitive detector -void Geant4HitCollection::setSensitiveDetector(SensitiveDetector detector) { - m_detector = detector; -} - -/// Access the sensitive detector -Geant4HitCollection::SensitiveDetector Geant4HitCollection::sensitiveDetector() const { - return m_detector; -} - /// Type information of the object stored const ComponentCast& Geant4HitCollection::type() const { return m_manipulator->cast; diff --git a/DDG4/src/Geant4ParticlePrint.cpp b/DDG4/src/Geant4ParticlePrint.cpp index c81c0dcbddde3af3f8057f032e15836f2d3f186b..3c7e9dc6bc69264fba08abf6816fe84719e95ab0 100644 --- a/DDG4/src/Geant4ParticlePrint.cpp +++ b/DDG4/src/Geant4ParticlePrint.cpp @@ -12,6 +12,7 @@ #include "DD4hep/InstanceCount.h" #include "DDG4/Geant4ParticlePrint.h" #include "DDG4/Geant4Data.h" +#include <cstring> using namespace std; using namespace DD4hep; diff --git a/DDG4/src/Geant4SensDetAction.cpp b/DDG4/src/Geant4SensDetAction.cpp index 287d7978ae18d3e70e5afc602d745699bb0ac66b..46a3918ae0b74d88c0137defced4de1751c45e22 100644 --- a/DDG4/src/Geant4SensDetAction.cpp +++ b/DDG4/src/Geant4SensDetAction.cpp @@ -79,13 +79,14 @@ bool Geant4Filter::operator()(const G4Step*) const { /// Constructor. The detector element is identified by the name Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const string& name, DetElement det, LCDD& lcdd) - : Geant4Action(ctxt, name), m_sensitiveDetector(0), m_sequence(0), m_lcdd(lcdd), - m_detector(det), m_sensitive(), m_readout(), m_segmentation() + : Geant4Action(ctxt, name), m_sensitiveDetector(0), m_sequence(0), + m_lcdd(lcdd), m_detector(det), m_sensitive(), m_readout(), m_segmentation() { InstanceCount::increment(this); if (!det.isValid()) { throw runtime_error(format("Geant4Sensitive", "DDG4: Detector elemnt for %s is invalid.", name.c_str())); } + declareProperty("HitCreationMode", m_hitCreationMode = SIMPLE_MODE); m_sequence = ctxt->kernel().sensitiveAction(m_detector.name()); m_sensitive = lcdd.sensitiveDetector(det.name()); m_readout = m_sensitive.readout(); @@ -258,8 +259,8 @@ void Geant4SensDetActionSequence::adopt(Geant4Filter* filter) { } /// Initialize the usage of a hit collection. Returns the collection identifier -size_t Geant4SensDetActionSequence::defineCollection(const std::string& name, create_t func) { - m_collections.push_back(make_pair(name, func)); +size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& name, create_t func) { + m_collections.push_back(make_pair(name, make_pair(owner,func))); return m_collections.size() - 1; } @@ -333,8 +334,8 @@ void Geant4SensDetActionSequence::begin(G4HCofThisEvent* hce) { m_hce = hce; m_actors(ContextUpdate(context())); for (size_t count = 0; count < m_collections.size(); ++count) { - const std::pair<string, create_t>& cr = m_collections[count]; - Geant4HitCollection* c = (*cr.second)(name(), cr.first, m_sensitive); + const HitCollection& cr = m_collections[count]; + Geant4HitCollection* c = (*cr.second.second)(name(), cr.first, cr.second.first); int id = m_detector->GetCollectionID(count); m_hce->AddHitsCollection(id, c); } diff --git a/DDG4/src/Geant4StepHandler.cpp b/DDG4/src/Geant4StepHandler.cpp index 9dd4f61bd5de013629d28b6121447d21b50429a9..3fe9cdd5e72e74a4b3e112637a695623097359fe 100644 --- a/DDG4/src/Geant4StepHandler.cpp +++ b/DDG4/src/Geant4StepHandler.cpp @@ -9,8 +9,12 @@ // Framework include files #include "DDG4/Geant4StepHandler.h" +#include "DDSegmentation/Segmentation.h" +#include "DD4hep/DD4hepUnits.h" + using namespace DD4hep::Simulation; +/// Returns the step status in form of a string const char* Geant4StepHandler::stepStatus(G4StepStatus status) { switch (status) { // Step reached the world boundary @@ -41,10 +45,35 @@ const char* Geant4StepHandler::stepStatus(G4StepStatus status) { }; } +/// Returns the pre-step status in form of a string const char* Geant4StepHandler::preStepStatus() const { return stepStatus(pre ? pre->GetStepStatus() : fUndefined); } +/// Returns the post-step status in form of a string const char* Geant4StepHandler::postStepStatus() const { return stepStatus(post ? post->GetStepStatus() : fUndefined); } + +/// Coordinate transformation to global coordinate. +Position Geant4StepHandler::localToGlobal(const DDSegmentation::Vector3D& local) const { + return localToGlobal(G4ThreeVector(local.X / dd4hep::mm,local.Y / dd4hep::mm,local.Z / dd4hep::mm)); +} + +/// Coordinate transformation to global coordinates. +Position Geant4StepHandler::localToGlobal(const Position& local) const { + return localToGlobal(G4ThreeVector(local.X(),local.Y(),local.Z())); +} + +/// Coordinate transformation to global coordinates +Position Geant4StepHandler::localToGlobal(double x, double y, double z) const { + return localToGlobal(G4ThreeVector(x,y,z)); +} + +/// Coordinate transformation to global coordinates +Position Geant4StepHandler::localToGlobal(const G4ThreeVector& loc) const { + G4StepPoint* sp = step->GetPreStepPoint(); + G4TouchableHandle t = sp->GetTouchableHandle(); + G4ThreeVector p = t->GetHistory()->GetTopTransform().Inverse().TransformPoint(loc); + return Position(p.x(),p.y(),p.z()); +} diff --git a/examples/CLICSiD/CMakeLists.txt b/examples/CLICSiD/CMakeLists.txt index 136f50ac11864990bcce282bf68895c3330d391b..b6ccf8c92257229a53b44de018349b2a9f83b346 100644 --- a/examples/CLICSiD/CMakeLists.txt +++ b/examples/CLICSiD/CMakeLists.txt @@ -47,7 +47,7 @@ set( ROOT_COMPONENT_LIBRARIES Geom Reflex) #------------------------------------------------------------- include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include - include + include ${DD4hep_INCLUDE_DIRS} ${ROOT_INCLUDE_DIR} ) diff --git a/examples/CLICSiD/eve/CLICSiD_Events.root b/examples/CLICSiD/eve/CLICSiD_Events.root index d23e246a59f9cc2bfcb5fc4af8374c0a4672f899..ff43b5d2077efb0134fe9c99e99fab4270ab5428 100644 Binary files a/examples/CLICSiD/eve/CLICSiD_Events.root and b/examples/CLICSiD/eve/CLICSiD_Events.root differ diff --git a/examples/CLICSiD/eve/CLICSiD_Events.slcio b/examples/CLICSiD/eve/CLICSiD_Events.slcio index 84e1fa6b3c62c341ffc65a76a78ef4f5cee92b83..45aaeee5115de55e4b8f390e2689f36d2bee393a 100644 Binary files a/examples/CLICSiD/eve/CLICSiD_Events.slcio and b/examples/CLICSiD/eve/CLICSiD_Events.slcio differ