DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4DataDump.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Primitives.h>
16 #include <DDG4/Geant4DataDump.h>
17 
18 using namespace dd4hep::sim;
19 using PropertyMask = dd4hep::detail::ReferenceBitMask<const int>;
20 
22 Geant4DataDump::Geant4DataDump(const std::string& tag) : m_tag(tag) {
23 }
24 
27 }
28 
30 void Geant4DataDump::print(PrintLevel level, Geant4ParticleHandle p) const {
31  PropertyMask mask(p->reason);
32  int parent = p->parents.empty() ? -1 : *p->parents.begin();
33  printout(level, m_tag, " +++ TrackID: %6d %12d %6d %-7s %3s %5d %6s %8.3g %-4s %-7s %-7s %-3s",
34  p->id,
35  p->pdgID,
36  parent,
37  yes_no(mask.isSet(G4PARTICLE_PRIMARY)),
38  yes_no(mask.isSet(G4PARTICLE_HAS_SECONDARIES)),
39  int(p->daughters.size()),
40  yes_no(mask.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD)),
41  p.energy(),
42  yes_no(mask.isSet(G4PARTICLE_CREATED_CALORIMETER_HIT)),
43  yes_no(mask.isSet(G4PARTICLE_CREATED_TRACKER_HIT)),
44  yes_no(mask.isSet(G4PARTICLE_KEEP_PROCESS)),
45  mask.isSet(G4PARTICLE_KEEP_PARENT) ? "YES" : ""
46  );
47 }
48 
50 void Geant4DataDump::print(PrintLevel level, int id, Geant4ParticleHandle p) const {
51  PropertyMask mask(p->reason);
52  int parent = p->parents.empty() ? -1 : *p->parents.begin();
53  printout(level, m_tag, " +++ TrackID: %6d [key:%d] %12d %6d %-7s %3s %5d %6s %8.3g %-4s %-7s %-7s %-3s",
54  p->id, id,
55  p->pdgID,
56  parent,
57  yes_no(mask.isSet(G4PARTICLE_PRIMARY)),
58  yes_no(mask.isSet(G4PARTICLE_HAS_SECONDARIES)),
59  int(p->daughters.size()),
60  yes_no(mask.isSet(G4PARTICLE_ABOVE_ENERGY_THRESHOLD)),
61  p.energy(),
62  yes_no(mask.isSet(G4PARTICLE_CREATED_CALORIMETER_HIT)),
63  yes_no(mask.isSet(G4PARTICLE_CREATED_TRACKER_HIT)),
64  yes_no(mask.isSet(G4PARTICLE_KEEP_PROCESS)),
65  mask.isSet(G4PARTICLE_KEEP_PARENT) ? "YES" : ""
66  );
67 }
68 
70 void Geant4DataDump::print(PrintLevel level, const std::string& container, const Particles* parts) const {
71  if ( parts ) {
72  PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
73  printout(level,m_tag,"+++ Track container: %-21s --------------- Track KEEP reasoning ---------------",container.c_str());
74  printout(level,m_tag,"+++ # of Tracks:%6d PDG Parent Primary Secondary Energy %-8s Calo Tracker Process/Par",
75  int(parts->size()),"in [MeV]");
76  for(Particle* p : *parts) {
78  print(low_lvl, ph);
79  }
80  }
81 }
82 
84 void Geant4DataDump::print(PrintLevel level, const Geant4ParticleMap* parts) const {
85  if ( parts ) {
86  PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
87  typedef Geant4ParticleMap::ParticleMap ParticleMap;
88  const ParticleMap& pm = parts->particles();
89  printout(level,m_tag,"+++ Geant4 Particle map %-18s --------------- Track KEEP reasoning ---------------","");
90  printout(level,m_tag,"+++ # of Tracks:%6d PDG Parent Primary Secondary Energy %-8s Calo Tracker Process/Par",
91  int(pm.size()),"in [MeV]");
92  for(const auto& p : pm)
93  print(low_lvl, p.first, p.second);
94  }
95 }
96 
98 void Geant4DataDump::print(PrintLevel level, const TrackerHit* h) const {
99  const SimpleHit::Contribution& t = h->truth;
100  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]",
101  h->cellID,h->position.x(),h->position.y(),h->position.z(),h->length,h->energyDeposit,t.trackID,t.pdgID,t.deposit,t.time);
102 }
103 
105 void Geant4DataDump::print(PrintLevel level, const std::string& container, const TrackerHits* hits) const {
106  if ( hits ) {
107  PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
108  printout(level,m_tag,"+++ Hit Collection: %s # Tracker hits %d",container.c_str(),int(hits->size()));
109  for(const TrackerHit* hit : *hits)
110  print(low_lvl, hit);
111  }
112 }
113 
115 void Geant4DataDump::print(PrintLevel level, const CalorimeterHit* h) const {
116  PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
117  printout(level,m_tag," +++ Hit: Cell: %016llX Pos:(%9.3g,%9.3g,%9.3g) [mm] E:%9.3g MeV #Contributions:%3d",
118  h->cellID,h->position.x(),h->position.y(),h->position.z(),h->energyDeposit,h->truth.size());
119  int cnt=0;
120  for(const SimpleHit::Contribution& c : h->truth) {
121  printout(low_lvl,m_tag," Contribution #%3d TrackID:%6d PDG:%12d %9.3g MeV %9.3g ns",
122  cnt,c.trackID,c.pdgID,c.deposit,c.time);
123  ++cnt;
124  }
125 }
126 
128 void Geant4DataDump::print(PrintLevel level, const std::string& container, const CalorimeterHits* hits) const {
129  if ( hits ) {
130  PrintLevel low_lvl = level == ALWAYS ? ALWAYS : PrintLevel(level-1);
131  printout(level,m_tag,"+++ Hit Collection: %s # Calorimeter hits %d",container.c_str(),int(hits->size()));
132  for(const CalorimeterHit* hit : *hits)
133  print(low_lvl, hit);
134  return;
135  }
136 }
dd4hep::sim::Geant4DataDump::~Geant4DataDump
virtual ~Geant4DataDump()
Standard destructor.
Definition: Geant4DataDump.cpp:26
dd4hep::sim::G4PARTICLE_CREATED_TRACKER_HIT
@ G4PARTICLE_CREATED_TRACKER_HIT
Definition: Geant4Particle.h:64
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
dd4hep::sim::G4PARTICLE_ABOVE_ENERGY_THRESHOLD
@ G4PARTICLE_ABOVE_ENERGY_THRESHOLD
Definition: Geant4Particle.h:60
dd4hep::sim::G4PARTICLE_KEEP_PARENT
@ G4PARTICLE_KEEP_PARENT
Definition: Geant4Particle.h:62
dd4hep::sim::Geant4Particle::reason
int reason
Definition: Geant4Particle.h:111
dd4hep::sim::Geant4HitData::MonteCarloContrib::pdgID
int pdgID
Particle ID from the PDG table.
Definition: Geant4Data.h:143
dd4hep::sim::Geant4ParticleMap::particles
const ParticleMap & particles() const
Access the particle map.
Definition: Geant4Particle.h:361
dd4hep::sim::G4PARTICLE_KEEP_PROCESS
@ G4PARTICLE_KEEP_PROCESS
Definition: Geant4Particle.h:61
dd4hep::sim::Geant4Particle::id
int id
not persistent
Definition: Geant4Particle.h:108
dd4hep::sim::Geant4Particle::pdgID
int pdgID
Definition: Geant4Particle.h:115
dd4hep::sim::Geant4DataDump::Geant4DataDump
Geant4DataDump(const std::string &tag)
Default constructor.
Definition: Geant4DataDump.cpp:22
dd4hep::sim::Geant4HitData::cellID
long long int cellID
cellID
Definition: Geant4Data.h:124
Geant4DataDump.h
dd4hep::sim::Geant4ParticleMap
Data structure to map particles produced during the generation and the simulation.
Definition: Geant4Particle.h:337
dd4hep::sim::Geant4DataDump::CalorimeterHits
std::vector< SimpleCalorimeter::Hit * > CalorimeterHits
Definition: Geant4DataDump.h:46
dd4hep::sim::Geant4DataDump::m_tag
std::string m_tag
Tag variable.
Definition: Geant4DataDump.h:50
dd4hep::sim::Geant4Tracker::Hit
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:263
dd4hep::sim::Geant4Tracker::Hit::length
double length
Length of the track segment contributing to this hit.
Definition: Geant4Data.h:272
dd4hep::sim::Geant4ParticleMap::ParticleMap
std::map< int, Particle * > ParticleMap
Definition: Geant4Particle.h:340
dd4hep::sim::Geant4DataDump::TrackerHits
std::vector< SimpleTracker::Hit * > TrackerHits
Definition: Geant4DataDump.h:43
dd4hep::sim::Geant4HitData::MonteCarloContrib::deposit
double deposit
Total energy deposit in this hit.
Definition: Geant4Data.h:145
dd4hep::sim::Geant4Particle::daughters
Particles daughters
The list of daughters of this MC particle.
Definition: Geant4Particle.h:140
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
dd4hep::sim::Geant4Calorimeter::Hit::energyDeposit
double energyDeposit
Total energy deposit.
Definition: Geant4Data.h:332
dd4hep::sim::Geant4Calorimeter::Hit
DDG4 calorimeter hit class used by the generic DDG4 calorimeter sensitive detector.
Definition: Geant4Data.h:323
dd4hep::sim::Geant4HitData::MonteCarloContrib::trackID
int trackID
Geant 4 Track identifier.
Definition: Geant4Data.h:141
dd4hep::sim::G4PARTICLE_HAS_SECONDARIES
@ G4PARTICLE_HAS_SECONDARIES
Definition: Geant4Particle.h:59
Primitives.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
PropertyMask
dd4hep::detail::ReferenceBitMask< int > PropertyMask
Definition: HepMC3EventReader.cpp:37
dd4hep::sim::Geant4Calorimeter::Hit::truth
Contributions truth
Hit contributions by individual particles.
Definition: Geant4Data.h:330
dd4hep::sim::Geant4ParticleHandle
Data structure to access derived MC particle information.
Definition: Geant4Particle.h:181
dd4hep::sim::Geant4Particle::parents
Particles parents
The list of parents of this MC particle.
Definition: Geant4Particle.h:138
dd4hep::sim::G4PARTICLE_CREATED_CALORIMETER_HIT
@ G4PARTICLE_CREATED_CALORIMETER_HIT
Definition: Geant4Particle.h:63
dd4hep::sim::Geant4HitData::MonteCarloContrib
Utility class describing the monte carlo contribution of a given particle to a hit.
Definition: Geant4Data.h:138
dd4hep::sim::G4PARTICLE_PRIMARY
@ G4PARTICLE_PRIMARY
Definition: Geant4Particle.h:58
dd4hep::sim::Geant4Tracker::Hit::energyDeposit
double energyDeposit
Energy deposit in the tracker hit.
Definition: Geant4Data.h:274
dd4hep::sim::Geant4Particle
Data structure to store the MC particle information.
Definition: Geant4Particle.h:103
dd4hep::sim::Geant4DataDump::Particles
std::vector< Particle * > Particles
Definition: Geant4DataDump.h:40
dd4hep::sim::Geant4ParticleHandle::energy
double energy() const
Scalar particle energy.
Definition: Geant4Particle.h:308
dd4hep::sim::Geant4HitData::MonteCarloContrib::time
double time
Timestamp when this energy was deposited.
Definition: Geant4Data.h:147
dd4hep::sim::Geant4Calorimeter::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:328
dd4hep::sim::Geant4DataDump::print
void print(PrintLevel level, Geant4ParticleHandle p) const
Print a single particle to the output logging using the specified print level.
Definition: Geant4DataDump.cpp:30