File indexing completed on 2025-01-18 09:14:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDDigi/DigiROOTInput.h>
0016 #include "DigiIO.h"
0017
0018 #include <DDG4/Geant4Data.h>
0019 #include <DDG4/Geant4Particle.h>
0020
0021
0022 #include <TROOT.h>
0023 #include <TBranch.h>
0024
0025
0026 namespace dd4hep {
0027
0028
0029 namespace digi {
0030
0031
0032
0033
0034
0035
0036
0037
0038 class DigiDDG4ROOT : public DigiROOTInput {
0039 public:
0040
0041 TClass* m_trackerHitClass { nullptr };
0042 TClass* m_caloHitClass { nullptr };
0043 TClass* m_particlesClass { nullptr };
0044
0045 public:
0046
0047 DigiDDG4ROOT(const DigiKernel& krnl, const std::string& nam) : DigiROOTInput(krnl, nam) {
0048 m_particlesClass = gROOT->GetClass(typeid(std::vector<dd4hep::sim::Geant4Particle*>), kTRUE);
0049 m_trackerHitClass = gROOT->GetClass(typeid(std::vector<dd4hep::sim::Geant4Tracker::Hit*>), kTRUE);
0050 m_caloHitClass = gROOT->GetClass(typeid(std::vector<dd4hep::sim::Geant4Calorimeter::Hit*>), kTRUE);
0051 assert(m_particlesClass != 0);
0052 assert(m_trackerHitClass != 0);
0053 assert(m_caloHitClass != 0);
0054 }
0055
0056
0057 template <typename T>
0058 void from_dd4g4(DigiContext& context,
0059 DataSegment& segment,
0060 const std::string& tag,
0061 Key::mask_type mask,
0062 const char* nam,
0063 void* ptr) const
0064 {
0065 DepositVector out(nam, mask, SegmentEntry::UNKNOWN);
0066 std::map<CellID, std::shared_ptr<T> > hits;
0067 std::size_t len = 0;
0068 if ( ptr ) {
0069 input_data<T> data(ptr);
0070 const DepositPredicate<EnergyCut> predicate ({ this->epsilon });
0071 len = data.size();
0072 data_io<ddg4_input>::_to_digi_if(data.get(), hits, predicate);
0073 data_io<ddg4_input>::_to_digi(Key(nam, segment.id, mask), hits, out);
0074 data.clear();
0075 }
0076 info("%s+++ %-24s Converted %6ld DDG4 %-14s hits to %6ld cell deposits",
0077 context.event->id(), nam, len, tag.c_str(), out.size());
0078 put_data(segment, Key(out.name, mask), out);
0079 if ( m_keep_raw ) {
0080 put_data(segment, Key(std::string(nam)+".ddg4", mask, segment.id), hits);
0081 }
0082 }
0083
0084 void from_dd4g4(DigiContext& context,
0085 DataSegment& segment,
0086 int mask,
0087 const std::string& nam,
0088 void* ptr) const
0089 {
0090 ParticleMapping particles(nam, mask);
0091 if ( ptr ) {
0092 input_data<sim::Geant4Particle> data(ptr);
0093 data_io<ddg4_input>::_to_digi(Key(nam, segment.id, mask), data.get(), particles);
0094 data.clear();
0095 }
0096 debug("%s+++ Converted %ld DDG4 particles", context.event->id(), particles.size());
0097 put_data(segment, Key(nam, mask), particles);
0098 }
0099
0100
0101 virtual void operator()(DigiContext& context, work_t& work) const override {
0102 TBranch& br = work.container.branch;
0103 void** add = (void**)br.GetAddress();
0104 int msk = work.container.key.mask();
0105 TClass* cls = &work.container.clazz;
0106 auto& seg = work.segment;
0107 const char* nam = br.GetName();
0108
0109 if ( cls == m_caloHitClass )
0110 from_dd4g4<sim::Geant4Calorimeter::Hit>(context, seg, "calorimeter", msk, nam, *add);
0111 else if ( cls == m_trackerHitClass )
0112 from_dd4g4<sim::Geant4Tracker::Hit>(context, seg, "tracker", msk, nam, *add);
0113 else if ( cls == m_particlesClass )
0114 from_dd4g4(context, seg, msk, nam, *add);
0115 else
0116 except("Unknown data type encountered in branch: %s", nam);
0117 }
0118 };
0119 }
0120 }
0121
0122
0123 #include <DDDigi/DigiFactories.h>
0124 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiDDG4ROOT)