diff --git a/Simulation/DetSimAna/CMakeLists.txt b/Simulation/DetSimAna/CMakeLists.txt index ba4ee82a13957e67bb85463d6403010a8ed7f44c..7bf795e6d4b3d1536cd9276ee57fabd08e59a5b2 100644 --- a/Simulation/DetSimAna/CMakeLists.txt +++ b/Simulation/DetSimAna/CMakeLists.txt @@ -7,12 +7,13 @@ gaudi_depends_on_subdirs( find_package(Geant4 REQUIRED ui_all vis_all) include(${Geant4_USE_FILE}) +find_package(DD4hep COMPONENTS DDG4 REQUIRED) set(DetSimAna_srcs src/ExampleAnaElemTool.cpp ) gaudi_add_module(DetSimAna ${DetSimAna_srcs} - INCLUDE_DIRS DetSimInterface GaudiKernel Geant4 - LINK_LIBRARIES DetSimInterface GaudiKernel Geant4 + INCLUDE_DIRS DetSimInterface DD4hep GaudiKernel Geant4 + LINK_LIBRARIES DetSimInterface DD4hep ${DD4hep_COMPONENT_LIBRARIES} GaudiKernel Geant4 ) diff --git a/Simulation/DetSimAna/src/ExampleAnaElemTool.cpp b/Simulation/DetSimAna/src/ExampleAnaElemTool.cpp index 569c968c247760189886993da50211acaf9acfc0..f9f54489e8e4f2ff15c4a841674a278255ab8e27 100644 --- a/Simulation/DetSimAna/src/ExampleAnaElemTool.cpp +++ b/Simulation/DetSimAna/src/ExampleAnaElemTool.cpp @@ -2,6 +2,12 @@ #include "G4Event.hh" +#include "DD4hep/Detector.h" +#include "DD4hep/Plugins.h" +#include "DDG4/Geant4Converter.h" +#include "DDG4/Geant4Mapping.h" + + DECLARE_COMPONENT(ExampleAnaElemTool) void @@ -20,8 +26,33 @@ ExampleAnaElemTool::BeginOfEventAction(const G4Event* anEvent) { } void -ExampleAnaElemTool::EndOfEventAction(const G4Event*) { - +ExampleAnaElemTool::EndOfEventAction(const G4Event* anEvent) { + + // save all data + + // readout defined in DD4hep + auto lcdd = &(dd4hep::Detector::getInstance()); + auto allReadouts = lcdd->readouts(); + + for (auto& readout : allReadouts) { + info() << "Readout " << readout.first << endmsg; + } + + // retrieve the hit collections + G4HCofThisEvent* collections = anEvent->GetHCofThisEvent(); + if (!collections) { + warning() << "No collections found. " << endmsg; + return; + } + int Ncol = collections->GetNumberOfCollections(); + for (int icol = 0; icol < Ncol; ++icol) { + G4VHitsCollection* collect = collections->GetHC(icol); + if (!collect) { + warning() << "Collection iCol " << icol << " is missing" << endmsg; + continue; + } + info() << "Collection " << collect->GetName() << endmsg; + } } void