Skip to content
Snippets Groups Projects
Commit c2e8e984 authored by Leonhard Reichenbach's avatar Leonhard Reichenbach Committed by Andre Sailer
Browse files

add Geant4TVUserParticleHandler

parent 27d79bab
No related branches found
No related tags found
No related merge requests found
...@@ -14,18 +14,19 @@ ...@@ -14,18 +14,19 @@
/** \addtogroup Geant4Action /** \addtogroup Geant4Action
* *
@{ @{
\package Geant4TCUserParticleHandler \package Geant4TVUserParticleHandler
* \brief Rejects to keep particles, which are created outside a tracking cylinder. * \brief Rejects to keep particles, which are created outside a tracking cylinder.
* *
* *
@} @}
*/ */
#ifndef DD4HEP_DDG4_GEANT4TCUSERPARTICLEHANDLER_H #ifndef DD4HEP_DDG4_GEANT4TVUSERPARTICLEHANDLER_H
#define DD4HEP_DDG4_GEANT4TCUSERPARTICLEHANDLER_H #define DD4HEP_DDG4_GEANT4TVUSERPARTICLEHANDLER_H
// Framework include files // Framework include files
#include <DD4hep/Primitives.h> #include <DD4hep/Primitives.h>
#include <DD4hep/Volumes.h>
#include <DDG4/Geant4UserParticleHandler.h> #include <DDG4/Geant4UserParticleHandler.h>
/// Namespace for the AIDA detector description toolkit /// Namespace for the AIDA detector description toolkit
...@@ -34,22 +35,23 @@ namespace dd4hep { ...@@ -34,22 +35,23 @@ namespace dd4hep {
/// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
namespace sim { namespace sim {
/// Rejects to keep particles, which are created outside a tracking cylinder. /// Rejects to keep particles, which are created outside a tracking volume.
/** Geant4TCUserParticleHandler /** Geant4TVUserParticleHandler
* *
* TC stands for TrackingCylinder ;-) * TV stands for TrackingVolume ;-)
* *
* @author M.Frank * @author M.Frank
* @version 1.0 * @version 1.0
*/ */
class Geant4TCUserParticleHandler : public Geant4UserParticleHandler { class Geant4TVUserParticleHandler : public Geant4UserParticleHandler {
double m_zTrackerMin, m_zTrackerMax, m_rTracker; Volume m_trackingVolume;
public: public:
/// Standard constructor /// Standard constructor
Geant4TCUserParticleHandler(Geant4Context* context, const std::string& nam); Geant4TVUserParticleHandler(Geant4Context* context, const std::string& nam);
/// Default destructor /// Default destructor
virtual ~Geant4TCUserParticleHandler() {} virtual ~Geant4TVUserParticleHandler() {}
/// Post-track action callback /// Post-track action callback
/** Allow the user to force the particle handling in the post track action /** Allow the user to force the particle handling in the post track action
...@@ -69,7 +71,7 @@ namespace dd4hep { ...@@ -69,7 +71,7 @@ namespace dd4hep {
} // End namespace sim } // End namespace sim
} // End namespace dd4hep } // End namespace dd4hep
#endif // DD4HEP_DDG4_GEANT4TCUSERPARTICLEHANDLER_H #endif // DD4HEP_DDG4_GEANT4TVUSERPARTICLEHANDLER_H
//==================================================================== //====================================================================
// AIDA Detector description implementation // AIDA Detector description implementation
...@@ -79,32 +81,27 @@ namespace dd4hep { ...@@ -79,32 +81,27 @@ namespace dd4hep {
// //
//==================================================================== //====================================================================
// Framework include files // Framework include files
//#include <DDG4/Geant4TCUserParticleHandler.h> //#include <DDG4/Geant4TVUserParticleHandler.h>
#include <DDG4/Geant4Particle.h>
#include <DDG4/Factories.h> #include <DDG4/Factories.h>
#include <DDG4/Geant4Particle.h>
#include <DDG4/Geant4Kernel.h>
using namespace dd4hep::sim; using namespace dd4hep::sim;
DECLARE_GEANT4ACTION(Geant4TCUserParticleHandler) DECLARE_GEANT4ACTION(Geant4TVUserParticleHandler)
/// Standard constructor /// Standard constructor
Geant4TCUserParticleHandler::Geant4TCUserParticleHandler(Geant4Context* ctxt, const std::string& nam) Geant4TVUserParticleHandler::Geant4TVUserParticleHandler(Geant4Context* ctxt, const std::string& nam)
: Geant4UserParticleHandler(ctxt,nam) : Geant4UserParticleHandler(ctxt,nam)
{ {
declareProperty("TrackingVolume_Zmin",m_zTrackerMin=-1e100); m_trackingVolume = ctxt->kernel().detectorDescription().trackingVolume();
declareProperty("TrackingVolume_Zmax",m_zTrackerMax=1e100);
declareProperty("TrackingVolume_Rmax",m_rTracker=1e100);
} }
/// Post-track action callback /// Post-track action callback
void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p) { void Geant4TVUserParticleHandler::end(const G4Track* /* track */, Particle& p) {
double r_prod = std::sqrt(p.vsx*p.vsx + p.vsy*p.vsy); std::array<double, 3> start_point = {p.vsx, p.vsy, p.vsz};
double z_prod = p.vsz; bool starts_in_trk_vol = m_trackingVolume.ptr()->Contains(start_point.data());
bool starts_in_trk_vol = ( r_prod <= m_rTracker
&& z_prod >= (m_zTrackerMin == -1e100? -m_zTrackerMax : m_zTrackerMin)
&& z_prod <= m_zTrackerMax
) ;
dd4hep::detail::ReferenceBitMask<int> reason(p.reason); dd4hep::detail::ReferenceBitMask<int> reason(p.reason);
...@@ -116,12 +113,8 @@ void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p) ...@@ -116,12 +113,8 @@ void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p)
return; return;
} }
double r_end = std::sqrt(p.vex*p.vex + p.vey*p.vey); std::array<double, 3> end_point = {p.vex, p.vey, p.vez};
double z_end = p.vez; bool ends_in_trk_vol = m_trackingVolume.ptr()->Contains(end_point.data());
bool ends_in_trk_vol = ( r_end <= m_rTracker
&& z_end >= (m_zTrackerMin == -1e100? -m_zTrackerMax : m_zTrackerMin)
&& z_end <= m_zTrackerMax
) ;
// created and ended in calo but not primary particle // created and ended in calo but not primary particle
// //
...@@ -161,7 +154,7 @@ void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p) ...@@ -161,7 +154,7 @@ void Geant4TCUserParticleHandler::end(const G4Track* /* track */, Particle& p)
} }
/// Post-event action callback /// Post-event action callback
void Geant4TCUserParticleHandler::end(const G4Event* /* event */) { void Geant4TVUserParticleHandler::end(const G4Event* /* event */) {
} }
...@@ -122,7 +122,7 @@ class ParticleHandler(ConfigHelper): ...@@ -122,7 +122,7 @@ class ParticleHandler(ConfigHelper):
if not self.userParticleHandler: if not self.userParticleHandler:
return return
if self.userParticleHandler not in ["Geant4TCUserParticleHandler"]: if self.userParticleHandler not in ["Geant4TCUserParticleHandler", "Geant4TVUserParticleHandler"]:
logger.error("unknown UserParticleHandler: %r" % self.userParticleHandler) logger.error("unknown UserParticleHandler: %r" % self.userParticleHandler)
exit(1) exit(1)
...@@ -153,4 +153,12 @@ class ParticleHandler(ConfigHelper): ...@@ -153,4 +153,12 @@ class ParticleHandler(ConfigHelper):
part.adopt(user) part.adopt(user)
elif self.userParticleHandler == "Geant4TVUserParticleHandler":
if not kernel.detectorDescription().trackingVolume().isValid():
logger.error("Geant4TVUserParticleHandler requested but no tracking_volume defined in the XML")
exit(1)
user = DDG4.Action(kernel, "%s/UserParticleHandler" % self.userParticleHandler)
part.adopt(user)
return return
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