DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Output2EDM4hep.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 : F.Gaede, DESY
11 //
12 //==========================================================================
13 #ifndef DD4HEP_DDG4_GEANT4OUTPUT2EDM4hep_H
14 #define DD4HEP_DDG4_GEANT4OUTPUT2EDM4hep_H
15 
17 #include <DD4hep/Detector.h>
18 #include <DDG4/EventParameters.h>
20 #include <DDG4/RunParameters.h>
21 
23 #include <edm4hep/MCParticleCollection.h>
24 #include <edm4hep/SimTrackerHitCollection.h>
25 #include <edm4hep/CaloHitContributionCollection.h>
26 #include <edm4hep/SimCalorimeterHitCollection.h>
27 #include <edm4hep/EDM4hepVersion.h>
28 #include <edm4hep/Constants.h>
30 #include <podio/CollectionBase.h>
31 #include <podio/podioVersion.h>
32 #include <podio/Frame.h>
33 #include <podio/FrameCategories.h>
34 #if PODIO_BUILD_VERSION >= PODIO_VERSION(0, 99, 0)
35 #include <podio/ROOTWriter.h>
36 #else
37 #include <podio/ROOTFrameWriter.h>
38 namespace podio {
39  using ROOTWriter = podio::ROOTFrameWriter;
40 }
41 #endif
42 
44 namespace dd4hep {
45 
46  class ComponentCast;
47 
49  namespace sim {
50 
51  class Geant4ParticleMap;
52 
54 
60  protected:
61  using writer_t = podio::ROOTWriter;
62  using stringmap_t = std::map< std::string, std::string >;
63  using trackermap_t = std::map< std::string, edm4hep::SimTrackerHitCollection >;
64  using calorimeterpair_t = std::pair< edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionCollection >;
65  using calorimetermap_t = std::map< std::string, calorimeterpair_t >;
66  std::unique_ptr<writer_t> m_file { };
67  podio::Frame m_frame { };
68  edm4hep::MCParticleCollection m_particles { };
76  std::string m_section_name { "events" };
77  int m_runNo { 0 };
78  int m_runNumberOffset { 0 };
79  int m_eventNo { 0 };
81  bool m_filesByRun { false };
82 
84  void saveParticles(Geant4ParticleMap* particles);
86  void saveFileMetaData();
87  public:
89  Geant4Output2EDM4hep(Geant4Context* ctxt, const std::string& nam);
91  virtual ~Geant4Output2EDM4hep();
93  virtual void beginRun(const G4Run* run);
95  virtual void endRun(const G4Run* run);
96 
98  virtual void saveRun(const G4Run* run);
100  virtual void saveEvent( OutputContext<G4Event>& ctxt);
102  virtual void saveCollection( OutputContext<G4Event>& ctxt, G4VHitsCollection* collection);
104  virtual void commit( OutputContext<G4Event>& ctxt);
105 
107  virtual void begin(const G4Event* event);
108  protected:
110  template <typename T>
111  void saveEventParameters(const std::map<std::string, std::string >& parameters) {
112  for(const auto& p : parameters) {
113  info("Saving event parameter: %-32s = %s", p.first.c_str(), p.second.c_str());
114  m_frame.putParameter(p.first, p.second);
115  }
116  }
117  };
118 
119  template <> void EventParameters::extractParameters(podio::Frame& frame) {
120  for(auto const& p: this->intParameters()) {
121  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
122  frame.putParameter(p.first, p.second);
123  }
124  for(auto const& p: this->fltParameters()) {
125  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
126  frame.putParameter(p.first, p.second);
127  }
128  for(auto const& p: this->strParameters()) {
129  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
130  frame.putParameter(p.first, p.second);
131  }
132 #if PODIO_BUILD_VERSION > PODIO_VERSION(0, 16, 2)
133  // This functionality is only present in podio > 0.16.2
134  for (auto const& p: this->dblParameters()) {
135  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
136  frame.putParameter(p.first, p.second);
137  }
138 #endif
139  }
140 
141  template <> void RunParameters::extractParameters(podio::Frame& frame) {
142  for(auto const& p: this->intParameters()) {
143  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
144  frame.putParameter(p.first, p.second);
145  }
146  for(auto const& p: this->fltParameters()) {
147  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
148  frame.putParameter(p.first, p.second);
149  }
150  for(auto const& p: this->strParameters()) {
151  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
152  frame.putParameter(p.first, p.second);
153  }
154 #if PODIO_BUILD_VERSION > PODIO_VERSION(0, 16, 2)
155  // This functionality is only present in podio > 0.16.2
156  for (auto const& p: this->dblParameters()) {
157  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
158  frame.putParameter(p.first, p.second);
159  }
160 #endif
161  }
162 
163  } // End namespace sim
164 } // End namespace dd4hep
165 #endif // DD4HEP_DDG4_GEANT4OUTPUT2EDM4hep_H
166 
167 //==========================================================================
168 // AIDA Detector description implementation
169 //--------------------------------------------------------------------------
170 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
171 // All rights reserved.
172 //
173 // For the licensing terms see $DD4hepINSTALL/LICENSE.
174 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
175 //
176 // Author : F.Gaede, DESY
177 //
178 //==========================================================================
179 
181 #include <DD4hep/InstanceCount.h>
182 #include <DD4hep/VolumeManager.h>
183 
187 #include <DDG4/Geant4Context.h>
188 #include <DDG4/Geant4Particle.h>
189 #include <DDG4/Geant4Data.h>
190 
193 #include <G4Threading.hh>
194 #include <G4AutoLock.hh>
195 #include <G4Version.hh>
196 #include <G4ParticleDefinition.hh>
197 #include <G4VProcess.hh>
198 #include <G4Event.hh>
199 #include <G4Run.hh>
201 #include <CLHEP/Units/SystemOfUnits.h>
202 
204 #include <edm4hep/EventHeaderCollection.h>
205 
206 using namespace dd4hep::sim;
207 using namespace dd4hep;
208 
209 namespace {
210  G4Mutex action_mutex = G4MUTEX_INITIALIZER;
211 }
212 
213 #include <DDG4/Factories.h>
215 
216 Geant4Output2EDM4hep::Geant4Output2EDM4hep(Geant4Context* ctxt, const std::string& nam)
218 : Geant4OutputAction(ctxt,nam), m_runNo(0), m_runNumberOffset(0), m_eventNumberOffset(0)
219 {
220  declareProperty("RunHeader", m_runHeader);
221  declareProperty("EventParametersInt", m_eventParametersInt);
222  declareProperty("EventParametersFloat", m_eventParametersFloat);
223  declareProperty("EventParametersString", m_eventParametersString);
224  declareProperty("RunNumberOffset", m_runNumberOffset);
225  declareProperty("EventNumberOffset", m_eventNumberOffset);
226  declareProperty("SectionName", m_section_name);
227  declareProperty("FilesByRun", m_filesByRun);
228  info("Writer is now instantiated ..." );
230 }
231 
234  G4AutoLock protection_lock(&action_mutex);
235  m_file.reset();
237 }
238 
239 // Callback to store the Geant4 run information
240 void Geant4Output2EDM4hep::beginRun(const G4Run* run) {
241  G4AutoLock protection_lock(&action_mutex);
242  std::string fname = m_output;
243  m_runNo = run->GetRunID();
244  if ( m_filesByRun ) {
245  std::size_t idx = m_output.rfind(".");
246  if ( idx != std::string::npos ) {
247  fname = m_output.substr(0, idx) + _toString(m_runNo, ".run%08d") + m_output.substr(idx);
248  }
249  }
250  if ( !fname.empty() ) {
251  m_file = std::make_unique<podio::ROOTWriter>(fname);
252  if ( !m_file ) {
253  fatal("+++ Failed to open output file: %s", fname.c_str());
254  }
255  printout( INFO, "Geant4Output2EDM4hep" ,"Opened %s for output", fname.c_str() ) ;
256  }
257 }
258 
260 void Geant4Output2EDM4hep::endRun(const G4Run* run) {
261  saveRun(run);
263  if ( m_file ) {
264  m_file->finish();
265  m_file.reset();
266  }
267 }
268 
270  podio::Frame metaFrame{};
271  for (const auto& [name, encodingStr] : m_cellIDEncodingStrings) {
272  metaFrame.putParameter(podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding), encodingStr);
273  }
274 
275  m_file->writeFrame(metaFrame, "metadata");
276 }
277 
280  if ( m_file ) {
281  G4AutoLock protection_lock(&action_mutex);
282  m_frame.put( std::move(m_particles), "MCParticles");
283  for (auto it = m_trackerHits.begin(); it != m_trackerHits.end(); ++it) {
284  m_frame.put( std::move(it->second), it->first);
285  }
286  for (auto& [colName, calorimeterHits] : m_calorimeterHits) {
287  m_frame.put( std::move(calorimeterHits.first), colName);
288  m_frame.put( std::move(calorimeterHits.second), colName + "Contributions");
289  }
290  m_file->writeFrame(m_frame, m_section_name);
291  m_particles.clear();
292  m_trackerHits.clear();
293  m_calorimeterHits.clear();
294  m_frame = {};
295  return;
296  }
297  except("+++ Failed to write output file. [Stream is not open]");
298 }
299 
301 void Geant4Output2EDM4hep::saveRun(const G4Run* run) {
302  G4AutoLock protection_lock(&action_mutex);
303  // --- write an edm4hep::RunHeader ---------
304  // Runs are just Frames with different contents in EDM4hep / podio. We simply
305  // store everything as parameters for now
306  podio::Frame runHeader {};
307  for (const auto& [key, value] : m_runHeader)
308  runHeader.putParameter(key, value);
309 
310  m_runNo = m_runNumberOffset > 0 ? m_runNumberOffset + run->GetRunID() : run->GetRunID();
311  runHeader.putParameter("runNumber", m_runNo);
312  runHeader.putParameter("GEANT4Version", G4Version);
313  runHeader.putParameter("DD4hepVersion", versionString());
314  runHeader.putParameter("detectorName", context()->detectorDescription().header().name());
315 
316  RunParameters* parameters = context()->run().extension<RunParameters>(false);
317  if ( parameters ) {
318  parameters->extractParameters(runHeader);
319  }
320 
321  m_file->writeFrame(runHeader, "runs");
322 }
323 
324 void Geant4Output2EDM4hep::begin(const G4Event* event) {
326  m_eventNo = event->GetEventID();
327  m_frame = {};
328  m_particles = {};
329  m_trackerHits.clear();
330  m_calorimeterHits.clear();
331 }
332 
335  typedef detail::ReferenceBitMask<const int> PropertyMask;
336  typedef Geant4ParticleMap::ParticleMap ParticleMap;
337  const ParticleMap& pm = particles->particleMap;
338 
339  m_particles.clear();
340  if ( pm.size() > 0 ) {
341  size_t cnt = 0;
342  // Mapping of ids in the ParticleMap to indices in the MCParticle collection
343  std::map<int,int> p_ids;
344  std::vector<const Geant4Particle*> p_part;
345  p_part.reserve(pm.size());
346  // First create the particles
347  for (const auto& iParticle : pm) {
348  int id = iParticle.first;
349  const Geant4ParticleHandle p = iParticle.second;
350  PropertyMask mask(p->status);
351  // std::cout << " ********** mcp status : 0x" << std::hex << p->status << ", mask.isSet(G4PARTICLE_GEN_STABLE) x" << std::dec << mask.isSet(G4PARTICLE_GEN_STABLE) <<std::endl ;
352  const G4ParticleDefinition* def = p.definition();
353  auto mcp = m_particles.create();
354  mcp.setPDG(p->pdgID);
355  // Because EDM4hep is switching between vector3f[loat] and vector3d[ouble]
356  using MT = decltype(std::declval<edm4hep::MCParticle>().getMomentum().x);
357  mcp.setMomentum( {MT(p->psx/CLHEP::GeV),MT(p->psy/CLHEP::GeV),MT(p->psz/CLHEP::GeV)} );
358  mcp.setMomentumAtEndpoint( {MT(p->pex/CLHEP::GeV),MT(p->pey/CLHEP::GeV),MT(p->pez/CLHEP::GeV)} );
359 
360  double vs_fa[3] = { p->vsx/CLHEP::mm, p->vsy/CLHEP::mm, p->vsz/CLHEP::mm } ;
361  mcp.setVertex( vs_fa );
362 
363  double ve_fa[3] = { p->vex/CLHEP::mm, p->vey/CLHEP::mm, p->vez/CLHEP::mm } ;
364  mcp.setEndpoint( ve_fa );
365 
366  mcp.setTime(p->time/CLHEP::ns);
367  mcp.setMass(p->mass/CLHEP::GeV);
368  mcp.setCharge(def ? def->GetPDGCharge() : 0); // Charge(e+) = 1 !
369 
370  // Set generator status
371  mcp.setGeneratorStatus(0);
372  if( p->genStatus ) {
373  mcp.setGeneratorStatus( p->genStatus ) ;
374  } else {
375  if ( mask.isSet(G4PARTICLE_GEN_STABLE) ) mcp.setGeneratorStatus(1);
376  else if ( mask.isSet(G4PARTICLE_GEN_DECAYED) ) mcp.setGeneratorStatus(2);
377  else if ( mask.isSet(G4PARTICLE_GEN_DOCUMENTATION) ) mcp.setGeneratorStatus(3);
378  else if ( mask.isSet(G4PARTICLE_GEN_BEAM) ) mcp.setGeneratorStatus(4);
379  else if ( mask.isSet(G4PARTICLE_GEN_OTHER) ) mcp.setGeneratorStatus(9);
380  }
381 
382  // Set simulation status
383  mcp.setCreatedInSimulation( mask.isSet(G4PARTICLE_SIM_CREATED) );
384  mcp.setBackscatter( mask.isSet(G4PARTICLE_SIM_BACKSCATTER) );
385  mcp.setVertexIsNotEndpointOfParent( mask.isSet(G4PARTICLE_SIM_PARENT_RADIATED) );
386  mcp.setDecayedInTracker( mask.isSet(G4PARTICLE_SIM_DECAY_TRACKER) );
387  mcp.setDecayedInCalorimeter( mask.isSet(G4PARTICLE_SIM_DECAY_CALO) );
388  mcp.setHasLeftDetector( mask.isSet(G4PARTICLE_SIM_LEFT_DETECTOR) );
389  mcp.setStopped( mask.isSet(G4PARTICLE_SIM_STOPPED) );
390  mcp.setOverlay( false );
391 
392  //fg: if simstatus !=0 we have to set the generator status to 0:
393  if( mcp.isCreatedInSimulation() )
394  mcp.setGeneratorStatus( 0 ) ;
395 
396  mcp.setSpin(p->spin);
397  mcp.setColorFlow(p->colorFlow);
398 
399  p_ids[id] = cnt++;
400  p_part.push_back(p);
401  }
402 
403  // Now establish parent-daughter relationships
404  for(size_t i=0; i < p_ids.size(); ++i) {
405  const Geant4Particle* p = p_part[i];
406  auto q = m_particles[i];
407 
408  for (const auto& idau : p->daughters) {
409  const auto k = p_ids.find(idau);
410  if (k == p_ids.end()) {
411  fatal("+++ Particle %d: FAILED to find daughter with ID:%d",p->id,idau);
412  continue;
413  }
414  int iqdau = (*k).second;
415  auto qdau = m_particles[iqdau];
416  q.addToDaughters(qdau);
417  }
418 
419  for (const auto& ipar : p->parents) {
420  if (ipar >= 0) { // A parent ID of -1 means NO parent, because a base of 0 is perfectly legal
421  const auto k = p_ids.find(ipar);
422  if (k == p_ids.end()) {
423  fatal("+++ Particle %d: FAILED to find parent with ID:%d",p->id,ipar);
424  continue;
425  }
426  int iqpar = (*k).second;
427  auto qpar = m_particles[iqpar];
428  q.addToParents(qpar);
429  }
430  }
431  }
432  }
433 }
434 
437  EventParameters* parameters = context()->event().extension<EventParameters>(false);
438  int runNumber(0), eventNumber(0);
439  const int eventNumberOffset(m_eventNumberOffset > 0 ? m_eventNumberOffset : 0);
440  const int runNumberOffset(m_runNumberOffset > 0 ? m_runNumberOffset : 0);
441  double eventWeight{0};
442  // Get event number, run number and parameters from extension ...
443  if ( parameters ) {
444  runNumber = parameters->runNumber() + runNumberOffset;
445  eventNumber = parameters->eventNumber() + eventNumberOffset;
446  parameters->extractParameters(m_frame);
447 #if PODIO_BUILD_VERSION > PODIO_VERSION(0, 16, 2)
448  // This functionality is only present in podio > 0.16.2
449 #if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0)
450  eventWeight = m_frame.getParameter<double>("EventWeights").value_or(0.0);
451 #else
452  eventWeight = m_frame.getParameter<double>("EventWeights");
453 #endif
454 #endif
455  } else { // ... or from DD4hep framework
456  runNumber = m_runNo + runNumberOffset;
457  eventNumber = ctxt.context->GetEventID() + eventNumberOffset;
458  }
459  printout(INFO,"Geant4Output2EDM4hep","+++ Saving EDM4hep event %d run %d.", eventNumber, runNumber);
460 
461  // this does not compile as create() is we only get a const ref - need to review PODIO EventStore API
462  edm4hep::EventHeaderCollection header_collection;
463  auto header = header_collection.create();
464  header.setRunNumber(runNumber);
465  header.setEventNumber(eventNumber);
466  header.setWeight(eventWeight);
467  //not implemented in EDM4hep ? header.setDetectorName(context()->detectorDescription().header().name());
468  header.setTimeStamp( std::time(nullptr) ) ;
469  m_frame.put( std::move(header_collection), "EventHeader");
470 
471  saveEventParameters<int>(m_eventParametersInt);
472  saveEventParameters<float>(m_eventParametersFloat);
473  saveEventParameters<std::string>(m_eventParametersString);
474 
475  Geant4ParticleMap* part_map = context()->event().extension<Geant4ParticleMap>(false);
476  if ( part_map ) {
477  print("+++ Saving %d EDM4hep particles....",int(part_map->particleMap.size()));
478  if ( part_map->particleMap.size() > 0 ) {
479  saveParticles(part_map);
480  }
481  }
482 }
483 
494  operator std::string() const {
495  const auto* sd = m_coll->sensitive();
496  return dd4hep::sim::Geant4ConversionHelper::encoding(sd->sensitiveDetector());
497  }
498 private:
499  Geant4HitCollection* m_coll{nullptr};
500 };
501 
502 
505  Geant4HitCollection* coll = dynamic_cast<Geant4HitCollection*>(collection);
506  std::string colName = collection->GetName();
507  if( coll == nullptr ){
508  error(" no Geant4HitCollection: %s ", colName.c_str());
509  return ;
510  }
511  size_t nhits = collection->GetSize();
513  debug("+++ Saving EDM4hep collection %s with %d entries.", colName.c_str(), int(nhits));
514 
515  // Using try_emplace here to only fill this the first time we come across
516  m_cellIDEncodingStrings.try_emplace(colName, LazyEncodingExtraction{coll});
517 
518  //-------------------------------------------------------------------
519  if( typeid( Geant4Tracker::Hit ) == coll->type().type() ){
520  // Create the hit container even if there are no entries!
521  auto& hits = m_trackerHits[colName];
522  for(unsigned i=0 ; i < nhits ; ++i){
523  auto sth = hits->create();
524  const Geant4Tracker::Hit* hit = coll->hit(i);
525  const Geant4Tracker::Hit::Contribution& t = hit->truth;
526  int trackID = pm->particleID(t.trackID);
527  auto mcp = m_particles.at(trackID);
528  const auto& mom = hit->momentum;
529  const auto& pos = hit->position;
530  edm4hep::Vector3f();
531  sth.setCellID( hit->cellID ) ;
532  sth.setEDep(hit->energyDeposit/CLHEP::GeV);
533  sth.setPathLength(hit->length/CLHEP::mm);
534  sth.setTime(hit->truth.time/CLHEP::ns);
535 #if EDM4HEP_BUILD_VERSION >= EDM4HEP_VERSION(0, 10, 99)
536  sth.setParticle(mcp);
537 #else
538  sth.setMCParticle(mcp);
539 #endif
540  sth.setPosition( {pos.x()/CLHEP::mm, pos.y()/CLHEP::mm, pos.z()/CLHEP::mm} );
541  sth.setMomentum( {float(mom.x()/CLHEP::GeV),float(mom.y()/CLHEP::GeV),float(mom.z()/CLHEP::GeV)} );
542  auto particleIt = pm->particles().find(trackID);
543  if( ( particleIt != pm->particles().end()) ){
544  // if the original track ID of the particle is not the same as the
545  // original track ID of the hit it was produced by an MCParticle that
546  // is no longer stored
547  sth.setProducedBySecondary( (particleIt->second->originalG4ID != t.trackID) );
548  }
549  }
550  //-------------------------------------------------------------------
551  }
552  else if( typeid( Geant4Calorimeter::Hit ) == coll->type().type() ){
553  Geant4Sensitive* sd = coll->sensitive();
554  int hit_creation_mode = sd->hitCreationMode();
555  // Create the hit container even if there are no entries!
556  auto& hits = m_calorimeterHits[colName];
557  for(unsigned i=0 ; i < nhits ; ++i){
558  auto sch = hits.first->create();
559  const Geant4Calorimeter::Hit* hit = coll->hit(i);
560  const auto& pos = hit->position;
561  sch.setCellID( hit->cellID );
562  sch.setPosition({float(pos.x()/CLHEP::mm), float(pos.y()/CLHEP::mm), float(pos.z()/CLHEP::mm)});
563  sch.setEnergy( hit->energyDeposit/CLHEP::GeV );
564 
565 
566  // now add the individual step contributions
567  for(auto ci=hit->truth.begin(); ci != hit->truth.end(); ++ci){
568 
569  auto sCaloHitCont = hits.second->create();
570  sch.addToContributions( sCaloHitCont );
571 
572  const Geant4HitData::Contribution& c = *ci;
573  int trackID = pm->particleID(c.trackID);
574  auto mcp = m_particles.at(trackID);
575  sCaloHitCont.setEnergy( c.deposit/CLHEP::GeV );
576  sCaloHitCont.setTime( c.time/CLHEP::ns );
577  sCaloHitCont.setParticle( mcp );
578 
579  if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) {
580  edm4hep::Vector3f p(c.x/CLHEP::mm, c.y/CLHEP::mm, c.z/CLHEP::mm);
581  sCaloHitCont.setPDG( c.pdgID );
582  sCaloHitCont.setStepPosition( p );
583  }
584  }
585  }
586  //-------------------------------------------------------------------
587  } else {
588  error("+++ unknown type in Geant4HitCollection %s ", coll->type().type().name());
589  }
590 }
dd4hep::sim::Geant4Output2EDM4hep::m_eventParametersFloat
stringmap_t m_eventParametersFloat
Definition: Geant4Output2EDM4hep.cpp:73
Geant4DataConversion.h
dd4hep::sim::G4PARTICLE_SIM_CREATED
@ G4PARTICLE_SIM_CREATED
Definition: Geant4Particle.h:85
dd4hep::sim::Geant4Output2EDM4hep::m_eventParametersInt
stringmap_t m_eventParametersInt
Definition: Geant4Output2EDM4hep.cpp:72
dd4hep::sim::Geant4Tracker::Hit::momentum
Direction momentum
Hit direction.
Definition: Geant4Data.h:270
dd4hep::sim::Geant4Output2EDM4hep::beginRun
virtual void beginRun(const G4Run *run)
Callback to store the Geant4 run information.
Definition: Geant4Output2EDM4hep.cpp:240
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
dd4hep::sim::Geant4Output2EDM4hep::m_eventParametersString
stringmap_t m_eventParametersString
Definition: Geant4Output2EDM4hep.cpp:74
Geant4HitCollection.h
dd4hep::sim::Geant4Output2EDM4hep::m_eventNo
int m_eventNo
Definition: Geant4Output2EDM4hep.cpp:79
dd4hep::sim::Geant4Particle::vsz
double vsz
Definition: Geant4Particle.h:124
dd4hep::sim::RunParameters::strParameters
auto const & strParameters() const
Get the string Run parameters.
Definition: RunParameters.h:60
dd4hep::sim::Geant4Output2EDM4hep::m_runHeader
stringmap_t m_runHeader
Definition: Geant4Output2EDM4hep.cpp:71
dd4hep::sim::Geant4HitData::MonteCarloContrib::pdgID
int pdgID
Particle ID from the PDG table.
Definition: Geant4Data.h:143
dd4hep::sim::Geant4Output2EDM4hep::saveRun
virtual void saveRun(const G4Run *run)
Callback to store the Geant4 run information.
Definition: Geant4Output2EDM4hep.cpp:301
dd4hep::sim::G4PARTICLE_GEN_STABLE
@ G4PARTICLE_GEN_STABLE
Definition: Geant4Particle.h:71
dd4hep::sim::Geant4Output2EDM4hep::commit
virtual void commit(OutputContext< G4Event > &ctxt)
Commit data at end of filling procedure.
Definition: Geant4Output2EDM4hep.cpp:279
dd4hep::sim::G4PARTICLE_SIM_PARENT_RADIATED
@ G4PARTICLE_SIM_PARENT_RADIATED
Definition: Geant4Particle.h:91
dd4hep::sim::Geant4Particle::mass
double mass
Particle mass.
Definition: Geant4Particle.h:132
dd4hep::sim::Geant4Particle::vey
double vey
Definition: Geant4Particle.h:126
dd4hep::sim::Geant4HitData::MonteCarloContrib::y
float y
Definition: Geant4Data.h:151
dd4hep::sim::EventParameters::intParameters
auto const & intParameters() const
Get the int event parameters.
Definition: EventParameters.h:60
Detector.h
dd4hep::sim::Geant4Output2EDM4hep::endRun
virtual void endRun(const G4Run *run)
Callback to store the Geant4 run information.
Definition: Geant4Output2EDM4hep.cpp:260
dd4hep::sim::EventParameters::fltParameters
auto const & fltParameters() const
Get the float event parameters.
Definition: EventParameters.h:62
dd4hep::info
std::size_t info(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:65
dd4hep::sim::Geant4Particle::pez
double pez
Definition: Geant4Particle.h:130
dd4hep::sim::Geant4ParticleMap::particles
const ParticleMap & particles() const
Access the particle map.
Definition: Geant4Particle.h:361
dd4hep::sim::Geant4Output2EDM4hep::saveCollection
virtual void saveCollection(OutputContext< G4Event > &ctxt, G4VHitsCollection *collection)
Callback to store each Geant4 hit collection.
Definition: Geant4Output2EDM4hep.cpp:504
dd4hep::sim::Geant4Context::run
Geant4Run & run() const
Access the geant4 run – valid only between BeginRun() and EndRun()!
Definition: Geant4Context.cpp:72
dd4hep::sim::Geant4Output2EDM4hep::m_runNo
int m_runNo
Definition: Geant4Output2EDM4hep.cpp:77
dd4hep::sim::Geant4Particle::id
int id
not persistent
Definition: Geant4Particle.h:108
dd4hep::sim::RunParameters::dblParameters
auto const & dblParameters() const
Get the double Run parameters.
Definition: RunParameters.h:62
Geant4SensDetAction.h
dd4hep::sim::Geant4HitCollection
Generic hit container class using Geant4HitWrapper objects.
Definition: Geant4HitCollection.h:201
dd4hep::versionString
std::string versionString()
return a string with the current dd4hep version in the form vXX-YY.
Definition: DetectorImp.cpp:139
dd4hep::sim::EventParameters::strParameters
auto const & strParameters() const
Get the string event parameters.
Definition: EventParameters.h:64
dd4hep::sim::Geant4Particle::pdgID
int pdgID
Definition: Geant4Particle.h:115
dd4hep::sim::Geant4HitCollection::hit
Geant4HitWrapper & hit(size_t which)
Access the hit wrapper.
Definition: Geant4HitCollection.h:325
dd4hep::_toString
std::string _toString(bool value)
String conversions: boolean value to string.
Definition: Handle.cpp:332
G4VHitsCollection
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:47
dd4hep::sim::Geant4OutputAction
Base class to output Geant4 event data to persistent media.
Definition: Geant4OutputAction.h:40
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Particle::psz
double psz
Definition: Geant4Particle.h:128
LazyEncodingExtraction
Definition: Geant4Output2EDM4hep.cpp:488
Geant4Data.h
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
dd4hep::sim::Geant4Output2EDM4hep::saveEvent
virtual void saveEvent(OutputContext< G4Event > &ctxt)
Callback to store the Geant4 event.
Definition: Geant4Output2EDM4hep.cpp:436
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4HitData::cellID
long long int cellID
cellID
Definition: Geant4Data.h:124
dd4hep::sim::Geant4Output2EDM4hep::saveParticles
void saveParticles(Geant4ParticleMap *particles)
Data conversion interface for MC particles to EDM4hep format.
Definition: Geant4Output2EDM4hep.cpp:334
dd4hep::sim::G4PARTICLE_GEN_DOCUMENTATION
@ G4PARTICLE_GEN_DOCUMENTATION
Definition: Geant4Particle.h:73
dd4hep::sim::G4PARTICLE_SIM_BACKSCATTER
@ G4PARTICLE_SIM_BACKSCATTER
Definition: Geant4Particle.h:86
dd4hep::sim::Geant4Action::fatal
void fatal(const char *fmt,...) const
Support of fatal messages. Throws exception.
Definition: Geant4Action.cpp:248
dd4hep::sim::Geant4Output2EDM4hep::m_frame
podio::Frame m_frame
Definition: Geant4Output2EDM4hep.cpp:67
RunParameters.h
dd4hep::sim::Geant4Output2EDM4hep
Base class to output Geant4 event data to EDM4hep.
Definition: Geant4Output2EDM4hep.cpp:59
dd4hep::sim::RunParameters
Extension to pass input run data to output run data.
Definition: RunParameters.h:31
dd4hep::sim::Geant4Output2EDM4hep::calorimetermap_t
std::map< std::string, calorimeterpair_t > calorimetermap_t
Definition: Geant4Output2EDM4hep.cpp:65
dd4hep::sim::Geant4Sensitive::DETAILED_MODE
@ DETAILED_MODE
Definition: Geant4SensDetAction.h:126
VolumeManager.h
dd4hep::sim::Geant4OutputAction::OutputContext
Helper class for thread savety.
Definition: Geant4OutputAction.h:43
dd4hep::sim::Geant4ParticleMap
Data structure to map particles produced during the generation and the simulation.
Definition: Geant4Particle.h:337
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
dd4hep::sim::Geant4Event::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:151
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::RunParameters::fltParameters
auto const & fltParameters() const
Get the float Run parameters.
Definition: RunParameters.h:58
dd4hep::sim::G4PARTICLE_SIM_STOPPED
@ G4PARTICLE_SIM_STOPPED
Definition: Geant4Particle.h:89
Geant4OutputAction.h
dd4hep::sim::Geant4Output2EDM4hep::stringmap_t
std::map< std::string, std::string > stringmap_t
Definition: Geant4Output2EDM4hep.cpp:62
EventParameters.h
dd4hep::sim::Geant4HitCollection::sensitive
Geant4Sensitive * sensitive() const
Access the sensitive detector.
Definition: Geant4HitCollection.h:313
dd4hep::sim::Geant4Output2EDM4hep::m_section_name
std::string m_section_name
Definition: Geant4Output2EDM4hep.cpp:76
dd4hep::sim::EventParameters::extractParameters
void extractParameters(T &destination)
Put parameters into destination.
Definition: Geant4Output2LCIO.cpp:46
dd4hep::sim::Geant4Action::error
void error(const char *fmt,...) const
Support of error messages.
Definition: Geant4Action.cpp:231
dd4hep::sim::Geant4Output2EDM4hep::m_trackerHits
trackermap_t m_trackerHits
Definition: Geant4Output2EDM4hep.cpp:69
dd4hep::sim::Geant4Particle::vez
double vez
Definition: Geant4Particle.h:126
dd4hep::sim::G4PARTICLE_SIM_DECAY_CALO
@ G4PARTICLE_SIM_DECAY_CALO
Definition: Geant4Particle.h:87
dd4hep::sim::Geant4Output2EDM4hep::saveEventParameters
void saveEventParameters(const std::map< std::string, std::string > &parameters)
Fill event parameters in EDM4hep event.
Definition: Geant4Output2EDM4hep.cpp:111
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::Geant4Output2EDM4hep::calorimeterpair_t
std::pair< edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionCollection > calorimeterpair_t
Definition: Geant4Output2EDM4hep.cpp:64
dd4hep::sim::Geant4Output2EDM4hep::m_calorimeterHits
calorimetermap_t m_calorimeterHits
Definition: Geant4Output2EDM4hep.cpp:70
dd4hep::sim::Geant4Particle::colorFlow
int colorFlow[2]
Definition: Geant4Particle.h:117
dd4hep::sim::Geant4HitData::MonteCarloContrib::deposit
double deposit
Total energy deposit in this hit.
Definition: Geant4Data.h:145
dd4hep::sim::Geant4Particle::spin
float spin[3]
Definition: Geant4Particle.h:121
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4Particle::genStatus
unsigned short genStatus
Definition: Geant4Particle.h:118
dd4hep::sim::Geant4Particle::status
int status
Definition: Geant4Particle.h:116
dd4hep::sim::G4PARTICLE_GEN_DECAYED
@ G4PARTICLE_GEN_DECAYED
Definition: Geant4Particle.h:72
dd4hep::sim::Geant4Particle::daughters
Particles daughters
The list of daughters of this MC particle.
Definition: Geant4Particle.h:140
dd4hep::sim::G4PARTICLE_SIM_DECAY_TRACKER
@ G4PARTICLE_SIM_DECAY_TRACKER
Definition: Geant4Particle.h:88
dd4hep::sim::Geant4Output2EDM4hep::~Geant4Output2EDM4hep
virtual ~Geant4Output2EDM4hep()
Default destructor.
Definition: Geant4Output2EDM4hep.cpp:233
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
LazyEncodingExtraction::LazyEncodingExtraction
LazyEncodingExtraction(Geant4HitCollection *coll)
Definition: Geant4Output2EDM4hep.cpp:491
dd4hep::sim::Geant4Output2EDM4hep::m_cellIDEncodingStrings
stringmap_t m_cellIDEncodingStrings
Definition: Geant4Output2EDM4hep.cpp:75
dd4hep::sim::Geant4Output2EDM4hep::saveFileMetaData
void saveFileMetaData()
Store the metadata frame with e.g. the cellID encoding strings.
Definition: Geant4Output2EDM4hep.cpp:269
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4Output2EDM4hep::m_file
std::unique_ptr< writer_t > m_file
Definition: Geant4Output2EDM4hep.cpp:66
dd4hep::sim::Geant4Particle::time
double time
Particle creation time.
Definition: Geant4Particle.h:134
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::Geant4Particle::pex
double pex
The track momentum at the end vertex.
Definition: Geant4Particle.h:130
dd4hep::sim::Geant4Output2EDM4hep::m_runNumberOffset
int m_runNumberOffset
Definition: Geant4Output2EDM4hep.cpp:78
dd4hep::sim::Geant4HitCollection::type
const ComponentCast & type() const
Type information of the object stored.
Definition: Geant4HitCollection.cpp:87
dd4hep::sim::Geant4ParticleMap::particleID
int particleID(int track, bool throw_if_not_found=true) const
Access the equivalent track id (shortcut to the usage of TrackEquivalents)
Definition: Geant4Particle.cpp:541
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
dd4hep::sim::Geant4HitData::MonteCarloContrib::trackID
int trackID
Geant 4 Track identifier.
Definition: Geant4Data.h:141
dd4hep::sim::Geant4Particle::vex
double vex
The end vertex.
Definition: Geant4Particle.h:126
dd4hep::sim::Geant4Run::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:95
dd4hep::sim::Geant4Particle::vsx
double vsx
The starting vertex.
Definition: Geant4Particle.h:124
dd4hep::sim::Geant4Particle::psx
double psx
The track momentum at the start vertex.
Definition: Geant4Particle.h:128
dd4hep::sim::G4PARTICLE_GEN_BEAM
@ G4PARTICLE_GEN_BEAM
Definition: Geant4Particle.h:74
dd4hep::sim::Geant4ParticleHandle::definition
const G4ParticleDefinition * definition() const
Access the Geant4 particle definition object (expensive!)
Definition: Geant4Particle.cpp:116
dd4hep::sim::Geant4Particle::pey
double pey
Definition: Geant4Particle.h:130
dd4hep::sim::Geant4Output2EDM4hep::m_filesByRun
bool m_filesByRun
Definition: Geant4Output2EDM4hep.cpp:81
Factories.h
dd4hep::sim::Geant4OutputAction::m_output
std::string m_output
Property: "Output" output destination.
Definition: Geant4OutputAction.h:56
dd4hep::sim::Geant4ParticleMap::particleMap
ParticleMap particleMap
Mapping of particles of this event.
Definition: Geant4Particle.h:343
dd4hep::sim::G4PARTICLE_SIM_LEFT_DETECTOR
@ G4PARTICLE_SIM_LEFT_DETECTOR
Definition: Geant4Particle.h:90
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
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::RunParameters::extractParameters
void extractParameters(T &destination)
Put parameters into destination.
Definition: Geant4Output2LCIO.cpp:66
dd4hep::sim::Geant4Output2EDM4hep::m_particles
edm4hep::MCParticleCollection m_particles
Definition: Geant4Output2EDM4hep.cpp:68
dd4hep::sim::Geant4HitData::MonteCarloContrib::x
float x
Proper position of the hit contribution.
Definition: Geant4Data.h:151
dd4hep::sim::Geant4OutputAction::OutputContext::context
const T * context
Definition: Geant4OutputAction.h:45
dd4hep::sim::EventParameters
Event extension to pass input event data to output event.
Definition: EventParameters.h:31
dd4hep::sim::Geant4Calorimeter::Hit::truth
Contributions truth
Hit contributions by individual particles.
Definition: Geant4Data.h:330
dd4hep::sim::Geant4Sensitive::hitCreationMode
int hitCreationMode() const
Property access to the hit creation mode.
Definition: Geant4SensDetAction.h:173
dd4hep::sim::EventParameters::dblParameters
auto const & dblParameters() const
Get the double event parameters.
Definition: EventParameters.h:66
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4ParticleHandle
Data structure to access derived MC particle information.
Definition: Geant4Particle.h:181
dd4hep::sim::Geant4Output2EDM4hep::m_eventNumberOffset
int m_eventNumberOffset
Definition: Geant4Output2EDM4hep.cpp:80
dd4hep::sim::Geant4Particle::parents
Particles parents
The list of parents of this MC particle.
Definition: Geant4Particle.h:138
dd4hep::sim::Geant4Output2EDM4hep::Geant4Output2EDM4hep
Geant4Output2EDM4hep(Geant4Context *ctxt, const std::string &nam)
Standard constructor.
Definition: Geant4Output2EDM4hep.cpp:217
Geant4Particle.h
dd4hep::sim::Geant4Particle::vsy
double vsy
Definition: Geant4Particle.h:124
dd4hep::sim::Geant4Action::debug
void debug(const char *fmt,...) const
Support of debug messages.
Definition: Geant4Action.cpp:207
dd4hep::sim::Geant4Output2EDM4hep::trackermap_t
std::map< std::string, edm4hep::SimTrackerHitCollection > trackermap_t
Definition: Geant4Output2EDM4hep.cpp:63
dd4hep::sim::Geant4Output2EDM4hep::begin
virtual void begin(const G4Event *event)
begin-of-event callback - creates EDM4hep event and adds it to the event context
Definition: Geant4Output2EDM4hep.cpp:324
dd4hep::sim::Geant4HitData::MonteCarloContrib
Utility class describing the monte carlo contribution of a given particle to a hit.
Definition: Geant4Data.h:138
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:121
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
InstanceCount.h
dd4hep::sim::Geant4ConversionHelper::encoding
static std::string encoding(VolumeManager vm, VolumeID vid)
Access to the data encoding using the volume manager and a specified volume id.
Definition: Geant4DataConversion.cpp:28
dd4hep::sim::Geant4Particle::psy
double psy
Definition: Geant4Particle.h:128
dd4hep::sim::Geant4HitData::MonteCarloContrib::z
float z
Definition: Geant4Data.h:151
dd4hep::sim::EventParameters::eventNumber
int eventNumber() const
Get the event number.
Definition: EventParameters.h:52
dd4hep::sim::G4PARTICLE_GEN_OTHER
@ G4PARTICLE_GEN_OTHER
Definition: Geant4Particle.h:76
Geant4Context.h
dd4hep::sim::Geant4HitData::MonteCarloContrib::time
double time
Timestamp when this energy was deposited.
Definition: Geant4Data.h:147
dd4hep::sim::EventParameters::runNumber
int runNumber() const
Get the run number.
Definition: EventParameters.h:50
dd4hep::sim::Geant4Calorimeter::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:328
dd4hep::sim::Geant4Output2EDM4hep::writer_t
podio::ROOTWriter writer_t
Definition: Geant4Output2EDM4hep.cpp:61
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::RunParameters::intParameters
auto const & intParameters() const
Get the int Run parameters.
Definition: RunParameters.h:56