File indexing completed on 2025-03-13 08:20:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Primitives.h>
0016 #include <DDG4/Geant4DataDump.h>
0017
0018 using namespace dd4hep::sim;
0019 using PropertyMask = dd4hep::detail::ReferenceBitMask<const int>;
0020
0021
0022 Geant4DataDump::Geant4DataDump(const std::string& tag) : m_tag(tag) {
0023 }
0024
0025
0026 Geant4DataDump::~Geant4DataDump() {
0027 }
0028
0029
0030 void Geant4DataDump::print(PrintLevel level, Geant4ParticleHandle p) const {
0031 PropertyMask mask(p->reason);
0032 int parent = p->parents.empty() ? -1 : *p->parents.begin();
0033 printout(level, m_tag, " +++ TrackID: %6d %12d %6d %-7s %3s %5d %6s %8.3g %-4s %-7s %-7s %-3s",
0034 p->id,
0035 p->pdgID,
0036 parent,
0037 yes_no(mask.isSet(G4PARTICLE_PRIMARY)),
0038 yes_no(mask.isSet(G4PARTICLE_HAS_SECONDARIES)),
0039 int(p->daughters.size()),
0040 yes_no(mask.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD)),
0041 p.energy(),
0042 yes_no(mask.isSet(G4PARTICLE_CREATED_CALORIMETER_HIT)),
0043 yes_no(mask.isSet(G4PARTICLE_CREATED_TRACKER_HIT)),
0044 yes_no(mask.isSet(G4PARTICLE_KEEP_PROCESS)),
0045 mask.isSet(G4PARTICLE_KEEP_PARENT) ? "YES" : ""
0046 );
0047 }
0048
0049
0050 void Geant4DataDump::print(PrintLevel level, int id, Geant4ParticleHandle p) const {
0051 PropertyMask mask(p->reason);
0052 int parent = p->parents.empty() ? -1 : *p->parents.begin();
0053 printout(level, m_tag, " +++ TrackID: %6d [key:%d] %12d %6d %-7s %3s %5d %6s %8.3g %-4s %-7s %-7s %-3s",
0054 p->id, id,
0055 p->pdgID,
0056 parent,
0057 yes_no(mask.isSet(G4PARTICLE_PRIMARY)),
0058 yes_no(mask.isSet(G4PARTICLE_HAS_SECONDARIES)),
0059 int(p->daughters.size()),
0060 yes_no(mask.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD)),
0061 p.energy(),
0062 yes_no(mask.isSet(G4PARTICLE_CREATED_CALORIMETER_HIT)),
0063 yes_no(mask.isSet(G4PARTICLE_CREATED_TRACKER_HIT)),
0064 yes_no(mask.isSet(G4PARTICLE_KEEP_PROCESS)),
0065 mask.isSet(G4PARTICLE_KEEP_PARENT) ? "YES" : ""
0066 );
0067 }
0068
0069
0070 void Geant4DataDump::print(PrintLevel level, const std::string& container, const Particles* parts) const {
0071 if ( parts ) {
0072 PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
0073 printout(level,m_tag,"+++ Track container: %-21s --------------- Track KEEP reasoning ---------------",container.c_str());
0074 printout(level,m_tag,"+++ # of Tracks:%6d PDG Parent Primary Secondary Energy %-8s Calo Tracker Process/Par",
0075 int(parts->size()),"in [MeV]");
0076 for(Particle* p : *parts) {
0077 Geant4ParticleHandle ph(p);
0078 print(low_lvl, ph);
0079 }
0080 }
0081 }
0082
0083
0084 void Geant4DataDump::print(PrintLevel level, const Geant4ParticleMap* parts) const {
0085 if ( parts ) {
0086 PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
0087 typedef Geant4ParticleMap::ParticleMap ParticleMap;
0088 const ParticleMap& pm = parts->particles();
0089 printout(level,m_tag,"+++ Geant4 Particle map %-18s --------------- Track KEEP reasoning ---------------","");
0090 printout(level,m_tag,"+++ # of Tracks:%6d PDG Parent Primary Secondary Energy %-8s Calo Tracker Process/Par",
0091 int(pm.size()),"in [MeV]");
0092 for(const auto& p : pm)
0093 print(low_lvl, p.first, p.second);
0094 }
0095 }
0096
0097
0098 void Geant4DataDump::print(PrintLevel level, const TrackerHit* h) const {
0099 const SimpleHit::Contribution& t = h->truth;
0100 printout(level,m_tag," +++ Hit: Cell: %016llX Pos:(%9.3g,%9.3g,%9.3g) Len:%9.3g [mm] E:%9.3g MeV TrackID:%6d PDG:%12d dep:%9.3g time:%9.3g [ns]",
0101 h->cellID,h->position.x(),h->position.y(),h->position.z(),h->length,h->energyDeposit,t.trackID,t.pdgID,t.deposit,t.time);
0102 }
0103
0104
0105 void Geant4DataDump::print(PrintLevel level, const std::string& container, const TrackerHits* hits) const {
0106 if ( hits ) {
0107 PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
0108 printout(level,m_tag,"+++ Hit Collection: %s # Tracker hits %d",container.c_str(),int(hits->size()));
0109 for(const TrackerHit* hit : *hits)
0110 print(low_lvl, hit);
0111 }
0112 }
0113
0114
0115 void Geant4DataDump::print(PrintLevel level, const CalorimeterHit* h) const {
0116 PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
0117 printout(level,m_tag," +++ Hit: Cell: %016llX Pos:(%9.3g,%9.3g,%9.3g) [mm] E:%9.3g MeV #Contributions:%3d",
0118 h->cellID,h->position.x(),h->position.y(),h->position.z(),h->energyDeposit,h->truth.size());
0119 int cnt=0;
0120 for(const SimpleHit::Contribution& c : h->truth) {
0121 printout(low_lvl,m_tag," Contribution #%3d TrackID:%6d PDG:%12d %9.3g MeV %9.3g ns",
0122 cnt,c.trackID,c.pdgID,c.deposit,c.time);
0123 ++cnt;
0124 }
0125 }
0126
0127
0128 void Geant4DataDump::print(PrintLevel level, const std::string& container, const CalorimeterHits* hits) const {
0129 if ( hits ) {
0130 PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
0131 printout(level,m_tag,"+++ Hit Collection: %s # Calorimeter hits %d",container.c_str(),int(hits->size()));
0132 for(const CalorimeterHit* hit : *hits)
0133 print(low_lvl, hit);
0134 return;
0135 }
0136 }