diff --git a/DDDigi/io/DigiIO.h b/DDDigi/io/DigiIO.h index b429c62b952dc0804bac08e3e2a464d6c0c68cd4..ced444b50e4c04f48af0caa5a49a0ff127ca4fa3 100644 --- a/DDDigi/io/DigiIO.h +++ b/DDDigi/io/DigiIO.h @@ -26,6 +26,12 @@ /// Namespace for the AIDA detector description toolkit namespace dd4hep { + /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit + namespace sim { + // Forward declarations + class Geant4Particle; + } + /// Namespace for the Digitization part of the AIDA detector description toolkit namespace digi { @@ -40,6 +46,65 @@ namespace dd4hep { throw std::runtime_error("input_data: Invalid data!"); } }; + + /// Generci I/O helper to input/output digi data + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + template <typename T> struct data_io { + using particle_t = typename T::particle_type; + using trackerhit_t = typename T::input_trackerhit_type; + using calorimeterhit_t = typename T::input_calorimeterhit_type; + using pwrap_t = std::shared_ptr<particle_t>; + using twrap_t = std::shared_ptr<trackerhit_t>; + using cwrap_t = std::shared_ptr<calorimeterhit_t>; + + /// Default constructor + data_io() = default; + /// Default destructor + ~data_io() = default; + + /// Check if specialization can handle data conversion + template <typename DATA> + static bool _can_handle(const DATA& data); + + /// Convert data of particle type + template <typename CONT> static + std::vector<const particle_t*> _to_vector(const CONT& cont); + + /// Pre-create container of output data + template <typename CONT> static + void _pre_create(CONT* coll, std::size_t n); + + template <typename FIRST, typename SECOND> static + void _to_edm4hep(const FIRST& cont, SECOND coll); + + template <typename FIRST, typename SECOND> static + void _to_edm4hep(const FIRST& cont, SECOND coll, int hit_type); + + template <typename FIRST, typename SECOND, typename THIRD> static + void _to_digi(FIRST first, const SECOND& second, THIRD& third); + + template <typename FIRST, typename SECOND, typename PREDICATE> static + void _to_digi_if(const FIRST& first, SECOND& second, const PREDICATE& pred); + }; + + /// Structure definitions for DDG4 input data + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + struct ddg4_input { + typedef sim::Geant4Particle particle_type; + struct input_trackerhit_type {}; + struct input_calorimeterhit_type {}; + }; + } // End namespace digi } // End namespace dd4hep @@ -56,20 +121,41 @@ namespace dd4hep { /// Namespace for the AIDA detector description toolkit namespace dd4hep { - /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit - namespace sim { - // Forward declarations - class Geant4Particle; - } - /// Namespace for the Digitization part of the AIDA detector description toolkit namespace digi { edm4hep::Vector3d _toVectorD(const Position& ep); edm4hep::Vector3f _toVectorF(const Position& ep); + /// Structure definitions for edm4hep input data + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ + struct edm4hep_input { + typedef edm4hep::MutableMCParticle particle_type; + struct input_trackerhit_type {}; + struct input_calorimeterhit_type {}; + }; + + struct digi_input { + typedef Particle particle_type; + struct input_trackerhit_type {}; + struct input_calorimeterhit_type {}; + }; + + /// Generci I/O helper to output digi data in edm4hep format + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_DIGITIZATION + */ struct digi_io { public: + /// Default constructor digi_io() = default; template <typename FIRST_TYPE, typename OUTPUT_TYPE> static void _to_edm4hep(const FIRST_TYPE& first, OUTPUT_TYPE output); @@ -80,56 +166,6 @@ namespace dd4hep { template <typename FIRST_TYPE, typename SECOND_TYPE, typename OUTPUT_TYPE> static void _to_edm4hep(const FIRST_TYPE& first, const SECOND_TYPE& second, int hit_type, OUTPUT_TYPE output); }; - - struct ddg4_input { - typedef sim::Geant4Particle particle_type; - struct input_trackerhit_type {}; - struct input_calorimeterhit_type {}; - }; - - struct edm4hep_input { - typedef edm4hep::MutableMCParticle particle_type; - struct input_trackerhit_type {}; - struct input_calorimeterhit_type {}; - }; - - struct digi_input { - typedef Particle particle_type; - struct input_trackerhit_type {}; - struct input_calorimeterhit_type {}; - }; - - template <typename T> struct data_io { - using particle_t = typename T::particle_type; - using trackerhit_t = typename T::input_trackerhit_type; - using calorimeterhit_t = typename T::input_calorimeterhit_type; - using pwrap_t = std::shared_ptr<particle_t>; - using twrap_t = std::shared_ptr<trackerhit_t>; - using cwrap_t = std::shared_ptr<calorimeterhit_t>; - - data_io() = default; - - template <typename DATA> - static bool _can_handle(const DATA& data); - - template <typename CONT> static - std::vector<const particle_t*> _to_vector(const CONT& cont); - - template <typename CONT> static - void _pre_create(CONT* coll, std::size_t n); - - template <typename FIRST, typename SECOND> static - void _to_edm4hep(const FIRST& cont, SECOND coll); - - template <typename FIRST, typename SECOND> static - void _to_edm4hep(const FIRST& cont, SECOND coll, int hit_type); - - template <typename FIRST, typename SECOND, typename THIRD> static - void _to_digi(FIRST first, const SECOND& second, THIRD& third); - - template <typename FIRST, typename SECOND, typename PREDICATE> static - void _to_digi_if(const FIRST& first, SECOND& second, const PREDICATE& pred); - }; } // End namespace digi } // End namespace dd4hep #endif diff --git a/examples/DDDigi/scripts/TestSpillover.py b/examples/DDDigi/scripts/TestSpillover.py index b60267bd3126d9d27908c72c6b0b7361996eecb9..10eb95a1d47179e9ce985ac23e2b09af71a0eac4 100644 --- a/examples/DDDigi/scripts/TestSpillover.py +++ b/examples/DDDigi/scripts/TestSpillover.py @@ -90,7 +90,7 @@ def run(): spillover = input_action.adopt_action('DigiSequentialActionSequence/Spillover+25') evtreader = spillover.adopt_action('DigiDDG4ROOT/Reader+25ns', mask=0x4, - keep_raw = keep_raw, + keep_raw=keep_raw, input=[digi.next_input()], OutputLevel=rdr_output) attenuate = spillover.adopt_action('DigiAttenuatorSequence/Att+25ns',