Skip to content
Snippets Groups Projects
Commit 51bd6c03 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

Accessing hit collections.

parent a2e8ed16
No related branches found
No related tags found
No related merge requests found
...@@ -7,12 +7,13 @@ gaudi_depends_on_subdirs( ...@@ -7,12 +7,13 @@ gaudi_depends_on_subdirs(
find_package(Geant4 REQUIRED ui_all vis_all) find_package(Geant4 REQUIRED ui_all vis_all)
include(${Geant4_USE_FILE}) include(${Geant4_USE_FILE})
find_package(DD4hep COMPONENTS DDG4 REQUIRED)
set(DetSimAna_srcs set(DetSimAna_srcs
src/ExampleAnaElemTool.cpp src/ExampleAnaElemTool.cpp
) )
gaudi_add_module(DetSimAna ${DetSimAna_srcs} gaudi_add_module(DetSimAna ${DetSimAna_srcs}
INCLUDE_DIRS DetSimInterface GaudiKernel Geant4 INCLUDE_DIRS DetSimInterface DD4hep GaudiKernel Geant4
LINK_LIBRARIES DetSimInterface GaudiKernel Geant4 LINK_LIBRARIES DetSimInterface DD4hep ${DD4hep_COMPONENT_LIBRARIES} GaudiKernel Geant4
) )
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
#include "G4Event.hh" #include "G4Event.hh"
#include "DD4hep/Detector.h"
#include "DD4hep/Plugins.h"
#include "DDG4/Geant4Converter.h"
#include "DDG4/Geant4Mapping.h"
DECLARE_COMPONENT(ExampleAnaElemTool) DECLARE_COMPONENT(ExampleAnaElemTool)
void void
...@@ -20,8 +26,33 @@ ExampleAnaElemTool::BeginOfEventAction(const G4Event* anEvent) { ...@@ -20,8 +26,33 @@ ExampleAnaElemTool::BeginOfEventAction(const G4Event* anEvent) {
} }
void 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 void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment