Skip to content
Snippets Groups Projects
Commit b8720fbe authored by Whitney Armstrong's avatar Whitney Armstrong
Browse files

Adding Photomultiplier SD

parent 8c7c2586
Branches
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ endif()
# ---------------------------------------------------------------------------
# load additional OS dependent settings
include(cmake/os.cmake)
include(cmake/root.cmake)
#----------------------------------------------------------------------------
# Find Libraries
......
......@@ -5,12 +5,14 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
# locations on all platforms.
include(GNUInstallDirs)
include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
dd4hep_configure_output()
#-----------------------------------------------------------------------------------
find_package(Acts REQUIRED COMPONENTS Core IdentificationPlugin TGeoPlugin DD4hepPlugin )
dd4hep_configure_output()
add_subdirectory(pid/sdet)
#dd4hep_package (GenDetectors MAJOR ${NPDet_VERSION_MAJOR} MINOR ${NPDet_VERSION_MINOR} PATCH ${NPDet_VERSION_PATCH}
# USES [ROOT REQUIRED COMPONENTS Geom GenVector]
# [DD4hep REQUIRED COMPONENTS DDCore DDRec]
......
......@@ -31,6 +31,7 @@ def run():
geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
geant4.printDetectors()
logger.info("# Configure UI")
geant4.setupUI('qt',vis=True,macro='vis.mac')
......@@ -150,7 +151,9 @@ def run():
#kernel.registerGlobalFilter(f3)
#kernel.registerGlobalFilter(f4)
logger.info("# First the tracking detectors")
logger.info("# First the PID detectors")
seq, act = geant4.setupDetector('ForwardRICH','PhotoMultiplierSDAction')
#seq, act = geant4.setupTracker('SiVertexBarrel')
#seq.adopt(f1)
## seq.adopt(f4)
......
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
#find_package ( DD4hep REQUIRED )
#include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
include ( ${DD4hep_DIR}/cmake/DD4hepBuild.cmake )
dd4hep_configure_output()
dd4hep_set_compiler_flags()
set( sdet_headers
include/PhotoMultiplierHit.h
)
root_generate_dictionary(G__DDG4_PIDsdet
#$<BUILD_INTERFACE:-I${SPDLOG_INCLUDE_DIR}>
#$<BUILD_INTERFACE:-I${FMT_INCLUDE_DIR}>
-I${CMAKE_CURRENT_SOURCE_DIR}
-I${CMAKE_CURRENT_SOURCE_DIR}/include
${sdet_headers}
LINKDEF LinkDef.h
)
add_custom_target(G__DDG4_PIDsdet_ROOTDICT DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/G__DDG4_PIDsdet.cxx)
#dd4hep_add_dictionary(G__DDG4_PIDsdet
# SOURCES ${DD4hep_DIR}/include/ROOT/Warnings.h src/PhotoMultiplierHit.h
# LINKDEF ${DD4hep_DIR}/include/ROOT/LinkDef.h
# OUTPUT ${LIBRARY_OUTPUT_PATH}
# USES DD4hep::DDCore DD4hep::DDG4 Geant4::Interface
# )
#
#---- Example of a client library with user defined plugins --------------------
dd4hep_add_plugin( DDG4_PIDsdet
GENERATED G__DDG4_PIDsdet.cxx
SOURCES
src/PhotoMultiplierHit.cpp
src/PhotoMultiplierSDAction.cpp
USES DD4hep::DDCore DD4hep::DDG4 Geant4::Interface ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO
)
add_dependencies(DDG4_PIDsdet G__DDG4_PIDsdet_ROOTDICT)
target_include_directories(DDG4_PIDsdet
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PUBLIC $<INSTALL_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
install(TARGETS DDG4_PIDsdet DESTINATION lib)
# # Geant4 material scan. From position=0,0,0 to end-of-world
# dd4hep_add_test_reg( DDG4_PIDsdet_g4material_scan_SiliconBlock_LONGTEST
# COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4_PIDsdet.sh"
# EXEC_ARGS python ${DD4hep_ROOT}/bin/g4MaterialScan --compact=file:${CMAKE_INSTALL_PREFIX}/examples/ClientTests/compact/SiliconBlock.xml
# "--position=0,0,0" "--direction=0,1,0"
# REGEX_PASS " Terminate Geant4 and delete associated actions."
# )
#
# dd4hep_add_test_reg( DDG4_PIDsdet_sim_SiliconBlock_LONGTEST
# COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4_PIDsdet.sh"
# EXEC_ARGS python ${DDG4_PIDsdet_INSTALL}/scripts/PhotoMultiplierSD_sim.py
# --compact=file:${CMAKE_INSTALL_PREFIX}/examples/ClientTests/compact/SiliconBlock.xml
# REGEX_PASS NONE
# REGEX_FAIL "Exception;EXCEPTION;ERROR;Error" )
#endif()
#if defined(__CINT__) || defined(__MAKECINT__) || defined(__CLING__) || defined(__ROOTCLING__)
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;
/// Define namespaces
#pragma link C++ namespace dd4hep;
#pragma link C++ namespace dd4hep::sim;
#pragma link C++ namespace npdet;
#pragma link C++ class npdet::PhotoMultiplierHit+;
#endif
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
#ifndef SOMEEXPERIMENT_MYTRACKERHIT_H
#define SOMEEXPERIMENT_MYTRACKERHIT_H
/// Framework include files
#include "DDG4/Geant4Data.h"
namespace SomeExperiment {
/// This is the hit definition.
/** I took here the same definition of the default Geant4Tracker class,
* (see DDG4/Geant4Data.h) but it could be anything else as well.
*
* Please note:
* ============
* The MC truth handling as implemented in the Geant4ParticleHandler
* will not work with this class if the object(s) are saved with
* the standard Geant4Output2ROOT event action. If the hit is
* specialized, the output writing also must be specialized if
* MC truth handling should be supported.
* Otherwise it is sufficient to provide a ROOT dictionary as long as the
* base class dd4hep::sim::Geant4HitData is kept.
*
* \author M.Frank
* \version 1.0
* \ingroup DD4HEP_SIMULATION
*/
class MyTrackerHit /* : public dd4hep::sim::Geant4HitData */ {
public:
/// dd4hep::sim::Geant4HitData: cellID
long long int cellID = 0;
/// dd4hep::sim::Geant4HitData: User flag to classify hits
long flag = 0;
/// dd4hep::sim::Geant4HitData: Original Geant 4 track identifier of the creating track (debugging)
long g4ID = -1;
/// Hit position
dd4hep::Position position;
/// Hit direction
dd4hep::Direction momentum;
/// Length of the track segment contributing to this hit
double length = 0;
/// Monte Carlo / Geant4 information
dd4hep::sim::Geant4HitData::MonteCarloContrib truth;
/// Energy deposit in the tracker hit
double energyDeposit = 0;
public:
/// Default constructor
MyTrackerHit() = default;
/// Initializing constructor
MyTrackerHit(int track_id, int pdg_id, double deposit, double time_stamp)
: length(0.0), truth(track_id, pdg_id, deposit, time_stamp, 0.), energyDeposit(deposit) {}
/// Default destructor
virtual ~MyTrackerHit() = default;
/// Assignment operator
MyTrackerHit& operator=(const MyTrackerHit& c);
/// Clear hit content
MyTrackerHit& clear();
/// Store Geant4 point and step information into tracker hit structure.
MyTrackerHit& storePoint(const G4Step* step, const G4StepPoint* pnt);
};
}
// CINT configuration
#if defined(__CINT__) || defined(__MAKECINT__) || defined(__CLING__) || defined(__ROOTCLING__)
#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::sim;
#pragma link C++ namespace SomeExperiment;
#pragma link C++ class SomeExperiment::MyTrackerHit+;
#endif
#endif /* SOMEEXPERIMENT_MYTRACKERHIT_H */
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : Whitney Armstrong
//
//==========================================================================
#ifndef NPDet_PhotoMultiplierHIT_H
#define NPDet_PhotoMultiplierHIT_H
/// Framework include files
#include "DDG4/Geant4Data.h"
namespace npdet {
/// PhotoMultiplier Hit definition.
/** Nearly the same as a tracker hit but stores energy (convertable to wavelength).
*
* Please note:
* ============
* The MC truth handling as implemented in the Geant4ParticleHandler
* will not work with this class if the object(s) are saved with
* the standard Geant4Output2ROOT event action. If the hit is
* specialized, the output writing also must be specialized if
* MC truth handling should be supported.
* Otherwise it is sufficient to provide a ROOT dictionary as long as the
* base class dd4hep::sim::Geant4HitData is kept.
*
* \author Whitney Armstrong
* \version 1.0
* \ingroup DD4HEP_SIMULATION
*/
class PhotoMultiplierHit /* : public dd4hep::sim::Geant4HitData */ {
public:
/// dd4hep::sim::Geant4HitData: cellID
int64_t cellID = 0;
/// dd4hep::sim::Geant4HitData: User flag to classify hits
long flag = 0;
/// dd4hep::sim::Geant4HitData: Original Geant 4 track identifier of the creating track (debugging)
long g4ID = -1;
/// Hit position
dd4hep::Position position;
/// Hit direction
dd4hep::Direction momentum;
/// Length of the track segment contributing to this hit
double length = 0;
/// Monte Carlo / Geant4 information
dd4hep::sim::Geant4HitData::MonteCarloContrib truth;
/// Energy of photon
double energy = 0;
public:
/// Default constructor
PhotoMultiplierHit() = default;
/// Initializing constructor
PhotoMultiplierHit(int track_id, int pdg_id, double en, double time_stamp)
: length(0.0), truth(track_id, pdg_id, en, time_stamp, 0.), energy(en) {}
/// Default destructor
virtual ~PhotoMultiplierHit() = default;
/// Assignment operator
PhotoMultiplierHit& operator=(const PhotoMultiplierHit& c);
/// Clear hit content
PhotoMultiplierHit& clear();
/// Store Geant4 point and step information into tracker hit structure.
PhotoMultiplierHit& storePoint(const G4Step* step, const G4StepPoint* pnt);
};
}
#endif
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
/// Framework include files
#include "MyTrackerHit.h"
#include "G4Track.hh"
using namespace SomeExperiment;
/// Assignment operator
MyTrackerHit& MyTrackerHit::operator=(const MyTrackerHit& c) {
if ( &c != this ) {
position = c.position;
momentum = c.momentum;
length = c.length;
truth = c.truth;
}
return *this;
}
/// Clear hit content
MyTrackerHit& MyTrackerHit::clear() {
position.SetXYZ(0, 0, 0);
momentum.SetXYZ(0, 0, 0);
length = 0.0;
truth.clear();
return *this;
}
/// Store Geant4 point and step information into tracker hit structure.
MyTrackerHit& MyTrackerHit::storePoint(const G4Step* step, const G4StepPoint* pnt) {
G4Track* trk = step->GetTrack();
G4ThreeVector pos = pnt->GetPosition();
G4ThreeVector mom = pnt->GetMomentum();
truth.trackID = trk->GetTrackID();
truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
truth.deposit = step->GetTotalEnergyDeposit();
truth.time = trk->GetGlobalTime();
position.SetXYZ(pos.x(), pos.y(), pos.z());
momentum.SetXYZ(mom.x(), mom.y(), mom.z());
length = 0;
return *this;
}
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
// Framework include files
#include "MyTrackerHit.h"
#include "DDG4/Geant4SensDetAction.inl"
#include "DDG4/Factories.h"
//using namespace CLHEP;
namespace SomeExperiment {
class MyTrackerSD {
public:
typedef MyTrackerHit Hit;
// If we need special data to personalize the action, be put it here
int mumDeposits = 0;
double integratedDeposit = 0;
};
}
/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
/// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
namespace sim {
using namespace SomeExperiment;
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Geant4SensitiveAction<MyTrackerSD>
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/** \addtogroup Geant4SDActionPlugin
*
* @{
* \package MyTrackerSDAction
* \brief Sensitive detector meant for tracking detectors, will produce one hit per step
*
* @}
*/
/// Define collections created by this sensitivie action object
template <> void Geant4SensitiveAction<MyTrackerSD>::defineCollections() {
m_collectionID = declareReadoutFilteredCollection<MyTrackerSD::Hit>();
}
/// Method for generating hit(s) using the information of G4Step object.
template <> bool Geant4SensitiveAction<MyTrackerSD>::process(G4Step* step,G4TouchableHistory* /*hist*/ ) {
Geant4StepHandler h(step);
Position prePos = h.prePos();
Position postPos = h.postPos();
Position direction = postPos - prePos;
Position position = mean_direction(prePos,postPos);
double hit_len = direction.R();
// Somehow extract here the physics you want
MyTrackerSD::Hit* hit = new MyTrackerSD::Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime());
Geant4HitData::MonteCarloContrib contrib = Geant4HitData::extractContribution(step);
hit->cellID = cellID(step);
hit->energyDeposit = contrib.deposit;
hit->position = position;
hit->momentum = 0.5*(h. preMom() + h.postMom());
hit->length = hit_len;
collection(m_collectionID)->add(hit);
mark(h.track);
if ( 0 == hit->cellID ) {
hit->cellID = volumeID(step);
except("+++ Invalid CELL ID for hit!");
}
printP1("Hit with deposit:%f Pos:%f %f %f ID=%016X",
step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(),
(void*)hit->cellID);
Geant4TouchableHandler handler(step);
print(" Geant4 path:%s",handler.path().c_str());
// Do something with my personal data (can be also something more clever ;-):
m_userData.integratedDeposit += contrib.deposit;
++m_userData.mumDeposits;
return true;
}
}
}
//--- Factory declaration
namespace dd4hep { namespace sim {
typedef Geant4SensitiveAction<MyTrackerSD> MyTrackerSDAction;
}}
DECLARE_GEANT4SENSITIVE(MyTrackerSDAction)
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : Whitney Armstrong
//
//==========================================================================
#include "PhotoMultiplierHit.h"
#include "G4Track.hh"
using namespace npdet;
/// Assignment operator
PhotoMultiplierHit& PhotoMultiplierHit::operator=(const PhotoMultiplierHit& c) {
if ( &c != this ) {
position = c.position;
momentum = c.momentum;
length = c.length;
truth = c.truth;
energy = c.energy;
}
return *this;
}
/// Clear hit content
PhotoMultiplierHit& PhotoMultiplierHit::clear() {
position.SetXYZ(0, 0, 0);
momentum.SetXYZ(0, 0, 0);
energy = 0.0;
length = 0.0;
truth.clear();
return *this;
}
/// Store Geant4 point and step information into tracker hit structure.
PhotoMultiplierHit& PhotoMultiplierHit::storePoint(const G4Step* step, const G4StepPoint* pnt) {
G4Track* trk = step->GetTrack();
G4ThreeVector pos = pnt->GetPosition();
G4ThreeVector mom = pnt->GetMomentum();
truth.trackID = trk->GetTrackID();
truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
truth.deposit = step->GetTotalEnergyDeposit();
truth.time = trk->GetGlobalTime();
position.SetXYZ(pos.x(), pos.y(), pos.z());
momentum.SetXYZ(mom.x(), mom.y(), mom.z());
length = 0;
energy = pnt->GetTotalEnergy();
return *this;
}
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
// Framework include files
#include "PhotoMultiplierHit.h"
#include "DDG4/Geant4SensDetAction.inl"
#include "DDG4/Factories.h"
//using namespace CLHEP;
namespace npdet {
class PhotoMultiplierSD {
public:
using Hit = PhotoMultiplierHit;
int nPhotons = 0;
double averageEnergy = 0;
};
}
/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
/// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
namespace sim {
using namespace npdet;
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Geant4SensitiveAction<PhotoMultiplierSD>
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/** \addtogroup Geant4SDActionPlugin
*
* @{
* \package PhotoMultiplierSDAction
* \brief Sensitive detector meant for photon counting detectors, will produce one hit per step
*
* @}
*/
/// Define collections created by this sensitivie action object
template <> void Geant4SensitiveAction<PhotoMultiplierSD>::defineCollections() {
m_collectionID = declareReadoutFilteredCollection<PhotoMultiplierSD::Hit>();
}
/// Method for generating hit(s) using the information of G4Step object.
template <> bool Geant4SensitiveAction<PhotoMultiplierSD>::process(G4Step* step,G4TouchableHistory* /*hist*/ ) {
Geant4StepHandler h(step);
Position prePos = h.prePos();
Position postPos = h.postPos();
Position direction = postPos - prePos;
Position position = mean_direction(prePos,postPos);
double hit_len = direction.R();
// Somehow extract here the physics you want
PhotoMultiplierSD::Hit* hit = new PhotoMultiplierSD::Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime());
Geant4HitData::MonteCarloContrib contrib = Geant4HitData::extractContribution(step);
hit->cellID = cellID(step);
hit->energy = contrib.deposit;
hit->position = position;
hit->momentum = 0.5*(h. preMom() + h.postMom());
hit->length = hit_len;
collection(m_collectionID)->add(hit);
mark(h.track);
if ( 0 == hit->cellID ) {
hit->cellID = volumeID(step);
except("+++ Invalid CELL ID for hit!");
}
printP1("Hit with deposit:%f Pos:%f %f %f ID=%016X",
step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(),
(void*)hit->cellID);
Geant4TouchableHandler handler(step);
print(" Geant4 path:%s",handler.path().c_str());
// Do something with my personal data (can be also something more clever ;-):
m_userData.averageEnergy += contrib.deposit;
++m_userData.nPhotons;
return true;
}
}
}
//--- Factory declaration
namespace dd4hep { namespace sim {
//typedef Geant4SensitiveAction<PhotoMultiplierSD> PhotoMultiplierSDAction;
using PhotoMultiplierSDAction = Geant4SensitiveAction<PhotoMultiplierSD>;
}}
DECLARE_GEANT4SENSITIVE(PhotoMultiplierSDAction)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment