DD4hep  1.38.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>
19 #include <DDG4/FileParameters.h>
21 #include <DDG4/RunParameters.h>
22 #include <DDG4/Geant4Kernel.h>
23 
25 #include <edm4hep/MCParticleCollection.h>
26 #include <edm4hep/SimTrackerHitCollection.h>
27 #include <edm4hep/CaloHitContributionCollection.h>
28 #include <edm4hep/SimCalorimeterHitCollection.h>
29 #include <edm4hep/EDM4hepVersion.h>
30 #include <edm4hep/Constants.h>
31 #if EDM4HEP_BUILD_VERSION < EDM4HEP_VERSION(0, 99, 0)
32  using edm4hep::CellIDEncoding;
33 #else
34  using edm4hep::labels::CellIDEncoding;
35 #endif
36 #if EDM4HEP_BUILD_VERSION >= EDM4HEP_VERSION(0, 99, 3)
37 #include <edm4hep/GeneratorEventParametersCollection.h>
38 #endif
39 
41 #include <podio/CollectionBase.h>
42 #include <podio/podioVersion.h>
43 #include <podio/Frame.h>
44 #include <podio/FrameCategories.h>
45 #if PODIO_BUILD_VERSION >= PODIO_VERSION(1, 0, 0)
46 #include <podio/Writer.h>
47 #else
48 #if PODIO_BUILD_VERSION >= PODIO_VERSION(0, 99, 0)
49 #include <podio/ROOTWriter.h>
50 #else
51 #include <podio/ROOTFrameWriter.h>
52 namespace podio {
53  using ROOTWriter = podio::ROOTFrameWriter;
54 }
55 #endif
56 #endif
57 
58 #include <atomic>
59 
61 namespace dd4hep {
62 
63  class ComponentCast;
64 
66  namespace sim {
67 
68  class Geant4ParticleMap;
69 
71 
77  protected:
78 #if PODIO_BUILD_VERSION >= PODIO_VERSION(1, 0, 0)
79  using writer_t = podio::Writer;
80 #else
81  using writer_t = podio::ROOTWriter;
82 #endif
83  using floatmap_t = std::map< std::string, float >;
84  using intmap_t = std::map< std::string, int >;
85  using stringmap_t = std::map< std::string, std::string >;
86  using trackermap_t = std::map< std::string, edm4hep::SimTrackerHitCollection >;
87  using calorimeterpair_t = std::pair< edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionCollection >;
88  using calorimetermap_t = std::map< std::string, calorimeterpair_t >;
89  std::unique_ptr<writer_t> m_file { };
90  std::atomic_size_t m_fileUseCount { 0 };
91  podio::Frame m_frame { };
92  edm4hep::MCParticleCollection m_particles { };
103  std::string m_section_name { podio::Category::Event };
104  int m_runNo { 0 };
105  int m_runNumberOffset { 0 };
106  int m_eventNo { 0 };
108  bool m_filesByRun { false };
109  bool m_rntuple { false };
110 
112  std::unique_ptr<RunParameters> m_runParameters = nullptr;
114  std::unique_ptr<FileParameters> m_fileParameters = nullptr;
115 
117  void saveParticles(Geant4ParticleMap* particles);
119  void saveFileMetaData();
120  public:
122  Geant4Output2EDM4hep(Geant4Context* ctxt, const std::string& nam);
124  virtual ~Geant4Output2EDM4hep();
126  virtual void beginRun(const G4Run* run);
128  virtual void endRun(const G4Run* run);
129 
131  virtual void saveRun(const G4Run* run);
133  virtual void saveEvent( OutputContext<G4Event>& ctxt);
135  virtual void saveCollection( OutputContext<G4Event>& ctxt, G4VHitsCollection* collection);
137  virtual void commit( OutputContext<G4Event>& ctxt);
138 
140  virtual void begin(const G4Event* event);
141  protected:
143  template <typename T>
144  void saveEventParameters(const std::map<std::string, T >& parameters) {
145  for(const auto& p : parameters) {
146  std::stringstream output;
147  output << "Saving event parameter: "
148  << std::setw(32) << p.first
149  << std::setw(20) << p.second;
150  info(output.str().c_str());
151  m_frame.putParameter(p.first, p.second);
152  }
153  }
154  };
155 
156  template <> void EventParameters::extractParameters(podio::Frame& frame) {
157  for(auto const& p: this->intParameters()) {
158  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
159  frame.putParameter(p.first, p.second);
160  }
161  for(auto const& p: this->fltParameters()) {
162  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
163  frame.putParameter(p.first, p.second);
164  }
165  for(auto const& p: this->strParameters()) {
166  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
167  frame.putParameter(p.first, p.second);
168  }
169  // This functionality is only present in podio > 0.16.2
170  for (auto const& p: this->dblParameters()) {
171  printout(DEBUG, "Geant4OutputEDM4hep", "Saving event parameter: %s", p.first.c_str());
172  frame.putParameter(p.first, p.second);
173  }
174  }
175 
176  template <> void RunParameters::extractParameters(podio::Frame& frame) {
177  for(auto const& p: this->intParameters()) {
178  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
179  frame.putParameter(p.first, p.second);
180  }
181  for(auto const& p: this->fltParameters()) {
182  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
183  frame.putParameter(p.first, p.second);
184  }
185  for(auto const& p: this->strParameters()) {
186  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
187  frame.putParameter(p.first, p.second);
188  }
189  // This functionality is only present in podio > 0.16.2
190  for (auto const& p: this->dblParameters()) {
191  printout(DEBUG, "Geant4OutputEDM4hep", "Saving run parameter: %s", p.first.c_str());
192  frame.putParameter(p.first, p.second);
193  }
194  }
195  template <> void FileParameters::extractParameters(podio::Frame& frame) {
196  for(auto const& p: this->intParameters()) {
197  printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str());
198  frame.putParameter(p.first, p.second);
199  }
200  for(auto const& p: this->fltParameters()) {
201  printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str());
202  frame.putParameter(p.first, p.second);
203  }
204  for(auto const& p: this->strParameters()) {
205  printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str());
206  frame.putParameter(p.first, p.second);
207  }
208  // This functionality is only present in podio > 0.16.2
209  for (auto const& p: this->dblParameters()) {
210  printout(DEBUG, "Geant4OutputEDM4hep", "Saving meta parameter: %s", p.first.c_str());
211  frame.putParameter(p.first, p.second);
212  }
213  }
214 
215  } // End namespace sim
216 } // End namespace dd4hep
217 #endif // DD4HEP_DDG4_GEANT4OUTPUT2EDM4hep_H
218 
219 //==========================================================================
220 // AIDA Detector description implementation
221 //--------------------------------------------------------------------------
222 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
223 // All rights reserved.
224 //
225 // For the licensing terms see $DD4hepINSTALL/LICENSE.
226 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
227 //
228 // Author : F.Gaede, DESY
229 //
230 //==========================================================================
231 
233 #include <DD4hep/InstanceCount.h>
234 #include <DD4hep/VolumeManager.h>
235 
239 #include <DDG4/Geant4Context.h>
240 #include <DDG4/Geant4Particle.h>
241 #include <DDG4/Geant4Data.h>
242 
245 #include <G4AutoLock.hh>
246 #include <G4Version.hh>
247 #include <G4ParticleDefinition.hh>
248 #include <G4VProcess.hh>
249 #include <G4Event.hh>
250 #include <G4Run.hh>
252 #include <CLHEP/Units/SystemOfUnits.h>
253 
255 #include <edm4hep/EventHeaderCollection.h>
256 
257 using namespace dd4hep::sim;
258 using namespace dd4hep;
259 
260 #include <DDG4/Factories.h>
262 
263 Geant4Output2EDM4hep::Geant4Output2EDM4hep(Geant4Context* ctxt, const std::string& nam)
265 : Geant4OutputAction(ctxt,nam), m_runNo(0), m_runNumberOffset(0), m_eventNumberOffset(0)
266 {
267  declareProperty("RunHeader", m_runHeader);
268  declareProperty("EventParametersInt", m_eventParametersInt);
269  declareProperty("EventParametersFloat", m_eventParametersFloat);
270  declareProperty("EventParametersString", m_eventParametersString);
271  declareProperty("RunParametersInt", m_runParametersInt);
272  declareProperty("RunParametersFloat", m_runParametersFloat);
273  declareProperty("RunParametersString", m_runParametersString);
274  declareProperty("RunNumberOffset", m_runNumberOffset);
275  declareProperty("EventNumberOffset", m_eventNumberOffset);
276  declareProperty("SectionName", m_section_name);
277  declareProperty("FilesByRun", m_filesByRun);
278  declareProperty("RNTuple", m_rntuple);
279 
280  info("Writer is now instantiated ..." );
282 }
283 
286  G4AutoLock protection_lock(mutex());
288 }
289 
290 // Callback to store the Geant4 run information
291 void Geant4Output2EDM4hep::beginRun(const G4Run* run) {
292  G4AutoLock protection_lock(mutex());
293  std::string fname = m_output;
294  m_runNo = run->GetRunID();
295  if ( m_filesByRun ) {
296  std::size_t idx = m_output.rfind(".");
297  if ( idx != std::string::npos ) {
298  fname = m_output.substr(0, idx) + _toString(m_runNo, ".run%08d") + m_output.substr(idx);
299  }
300  }
301  // Create the file only when it has not yet beeen created in another thread
302  if ( !fname.empty() && !m_file ) {
303 #if PODIO_BUILD_VERSION >= PODIO_VERSION(1, 0, 0)
304  m_file = std::make_unique<podio::Writer>(podio::makeWriter(fname, m_rntuple ? "rntuple" : "default"));
305 #else
306  m_file = std::make_unique<podio::ROOTWriter>(fname);
307 #endif
308  if ( !m_file ) {
309  fatal("+++ Failed to open output file: %s", fname.c_str());
310  }
311  printout( INFO, "Geant4Output2EDM4hep" ,"Opened %s for output", fname.c_str() ) ;
312  }
313  m_fileUseCount++;
314 }
315 
317 void Geant4Output2EDM4hep::endRun(const G4Run* run) {
318  G4AutoLock protection_lock(mutex());
319 
321  {
322  RunParameters* parameters = workerCtx->run().extension<RunParameters>(false);
323  if(parameters) {
324  if(m_runParameters) {
325  printout(ERROR, "Geant4Output2EDM4hep" ,"Some other thread already stored RunParameters");
326  } else {
327  m_runParameters = std::make_unique<RunParameters>(*parameters);
328  }
329  }
330  }
331 
332  {
333  FileParameters* parameters = workerCtx->run().extension<FileParameters>(false);
334  if(parameters) {
335  if(m_fileParameters) {
336  printout(ERROR, "Geant4Output2EDM4hep" ,"Some other thread already stored FileParameters");
337  } else {
338  m_fileParameters = std::make_unique<FileParameters>(*parameters);
339  }
340  }
341  }
342 
343  // Close the file only when this is the last thread using it.
344  // Note: Although the use count is atomic, the file pointer is not,
345  // and testing it requires locking.
346  if ( m_file && m_fileUseCount == 1 ) {
347  saveRun(run);
349  m_file->finish();
350  m_file.reset();
351  }
352  m_fileUseCount--;
353 }
354 
356  podio::Frame metaFrame{};
357  for (const auto& [name, encodingStr] : m_cellIDEncodingStrings) {
358  metaFrame.putParameter(podio::collMetadataParamName(name, CellIDEncoding), encodingStr);
359  }
360  if (m_fileParameters) {
361  m_fileParameters->extractParameters(metaFrame);
362  m_fileParameters.reset();
363  }
364  m_file->writeFrame(metaFrame, podio::Category::Metadata);
365 }
366 
369  if ( m_file ) {
370  m_frame.put( std::move(m_particles), "MCParticles");
371  for (auto it = m_trackerHits.begin(); it != m_trackerHits.end(); ++it) {
372  m_frame.put( std::move(it->second), it->first);
373  }
374  for (auto& [colName, calorimeterHits] : m_calorimeterHits) {
375  m_frame.put( std::move(calorimeterHits.first), colName);
376  m_frame.put( std::move(calorimeterHits.second), colName + "Contributions");
377  }
378  m_file->writeFrame(m_frame, m_section_name);
379  m_particles = { };
380  m_trackerHits.clear();
381  m_calorimeterHits.clear();
382  m_frame = {};
383  return;
384  }
385  except("+++ Failed to write output file. [Stream is not open]");
386 }
387 
389 void Geant4Output2EDM4hep::saveRun(const G4Run* run) {
390  // --- write an edm4hep::RunHeader ---------
391  // Runs are just Frames with different contents in EDM4hep / podio. We simply
392  // store everything as parameters for now
393  podio::Frame runHeader {};
394  for (const auto& [key, value] : m_runHeader)
395  runHeader.putParameter(key, value);
396 
397  for (const auto& [key, value] : m_runParametersInt)
398  runHeader.putParameter(key, value);
399 
400  for (const auto& [key, value] : m_runParametersFloat)
401  runHeader.putParameter(key, value);
402 
403  for (const auto& [key, value] : m_runParametersString)
404  runHeader.putParameter(key, value);
405 
406  m_runNo = m_runNumberOffset > 0 ? m_runNumberOffset + run->GetRunID() : run->GetRunID();
407  runHeader.putParameter("runNumber", m_runNo);
408  runHeader.putParameter("GEANT4Version", G4Version);
409  runHeader.putParameter("DD4hepVersion", versionString());
410  runHeader.putParameter("detectorName", context()->detectorDescription().header().name());
411  if (m_runParameters) {
412  m_runParameters->extractParameters(runHeader);
413  m_runParameters.reset();
414  }
415  m_file->writeFrame(runHeader, podio::Category::Run);
416 }
417 
418 void Geant4Output2EDM4hep::begin(const G4Event* event) {
420  m_eventNo = event->GetEventID();
421  m_frame = {};
422  m_particles = {};
423  m_trackerHits.clear();
424  m_calorimeterHits.clear();
425 }
426 
429  typedef detail::ReferenceBitMask<const int> PropertyMask;
430  typedef Geant4ParticleMap::ParticleMap ParticleMap;
431  const ParticleMap& pm = particles->particleMap;
432 
433  m_particles.clear();
434  if ( pm.size() > 0 ) {
435  size_t cnt = 0;
436  // Mapping of ids in the ParticleMap to indices in the MCParticle collection
437  std::map<int,int> p_ids;
438  std::vector<const Geant4Particle*> p_part;
439  p_part.reserve(pm.size());
440  // First create the particles
441  for (const auto& iParticle : pm) {
442  int id = iParticle.first;
443  const Geant4ParticleHandle p = iParticle.second;
444  PropertyMask mask(p->status);
445  // std::cout << " ********** mcp status : 0x" << std::hex << p->status << ", mask.isSet(G4PARTICLE_GEN_STABLE) x" << std::dec << mask.isSet(G4PARTICLE_GEN_STABLE) <<std::endl ;
446  const G4ParticleDefinition* def = p.definition();
447  auto mcp = m_particles.create();
448  mcp.setPDG(p->pdgID);
449  // Because EDM4hep is switching between vector3f[loat] and vector3d[ouble]
450  using MT = decltype(std::declval<edm4hep::MCParticle>().getMomentum().x);
451  mcp.setMomentum( {MT(p->psx/CLHEP::GeV),MT(p->psy/CLHEP::GeV),MT(p->psz/CLHEP::GeV)} );
452  mcp.setMomentumAtEndpoint( {MT(p->pex/CLHEP::GeV),MT(p->pey/CLHEP::GeV),MT(p->pez/CLHEP::GeV)} );
453 
454  double vs_fa[3] = { p->vsx/CLHEP::mm, p->vsy/CLHEP::mm, p->vsz/CLHEP::mm } ;
455  mcp.setVertex( vs_fa );
456 
457  double ve_fa[3] = { p->vex/CLHEP::mm, p->vey/CLHEP::mm, p->vez/CLHEP::mm } ;
458  mcp.setEndpoint( ve_fa );
459 
460  mcp.setTime(p->time/CLHEP::ns);
461  mcp.setMass(p->mass/CLHEP::GeV);
462  mcp.setCharge(def ? def->GetPDGCharge() : 0); // Charge(e+) = 1 !
463 
464  // Set generator status
465  mcp.setGeneratorStatus(0);
466  if( p->genStatus ) {
467  mcp.setGeneratorStatus( p->genStatus ) ;
468  } else {
469  if ( mask.isSet(G4PARTICLE_GEN_STABLE) ) mcp.setGeneratorStatus(1);
470  else if ( mask.isSet(G4PARTICLE_GEN_DECAYED) ) mcp.setGeneratorStatus(2);
471  else if ( mask.isSet(G4PARTICLE_GEN_DOCUMENTATION) ) mcp.setGeneratorStatus(3);
472  else if ( mask.isSet(G4PARTICLE_GEN_BEAM) ) mcp.setGeneratorStatus(4);
473  else if ( mask.isSet(G4PARTICLE_GEN_OTHER) ) mcp.setGeneratorStatus(9);
474  }
475 
476  // Set simulation status
477  mcp.setCreatedInSimulation( mask.isSet(G4PARTICLE_SIM_CREATED) );
478  mcp.setBackscatter( mask.isSet(G4PARTICLE_SIM_BACKSCATTER) );
479  mcp.setVertexIsNotEndpointOfParent( mask.isSet(G4PARTICLE_SIM_PARENT_RADIATED) );
480  mcp.setDecayedInTracker( mask.isSet(G4PARTICLE_SIM_DECAY_TRACKER) );
481  mcp.setDecayedInCalorimeter( mask.isSet(G4PARTICLE_SIM_DECAY_CALO) );
482  mcp.setHasLeftDetector( mask.isSet(G4PARTICLE_SIM_LEFT_DETECTOR) );
483  mcp.setStopped( mask.isSet(G4PARTICLE_SIM_STOPPED) );
484  mcp.setOverlay( false );
485 
486  //fg: if simstatus !=0 we have to set the generator status to 0:
487  if( mcp.isCreatedInSimulation() )
488  mcp.setGeneratorStatus( 0 ) ;
489 
490 #if EDM4HEP_MCPARTICLE_HAS_HELICITY
491  mcp.setHelicity(p->spin[2]);
492 #else
493  mcp.setSpin(p->spin);
494 #endif
495 
496  p_ids[id] = cnt++;
497  p_part.push_back(p);
498  }
499 
500  // Now establish parent-daughter relationships
501  for(size_t i=0; i < p_ids.size(); ++i) {
502  const Geant4Particle* p = p_part[i];
503  auto q = m_particles[i];
504 
505  for (const auto& idau : p->daughters) {
506  const auto k = p_ids.find(idau);
507  if (k == p_ids.end()) {
508  fatal("+++ Particle %d: FAILED to find daughter with ID:%d",p->id,idau);
509  continue;
510  }
511  int iqdau = (*k).second;
512  auto qdau = m_particles[iqdau];
513  q.addToDaughters(qdau);
514  }
515 
516  for (const auto& ipar : p->parents) {
517  if (ipar >= 0) { // A parent ID of -1 means NO parent, because a base of 0 is perfectly legal
518  const auto k = p_ids.find(ipar);
519  if (k == p_ids.end()) {
520  fatal("+++ Particle %d: FAILED to find parent with ID:%d",p->id,ipar);
521  continue;
522  }
523  int iqpar = (*k).second;
524  auto qpar = m_particles[iqpar];
525  q.addToParents(qpar);
526  }
527  }
528  }
529  }
530 }
531 
534  EventParameters* parameters = context()->event().extension<EventParameters>(false);
535  int runNumber(0), eventNumber(0);
536  const int eventNumberOffset(m_eventNumberOffset > 0 ? m_eventNumberOffset : 0);
537  const int runNumberOffset(m_runNumberOffset > 0 ? m_runNumberOffset : 0);
538  double eventWeight{0};
539  // Get event number, run number and parameters from extension ...
540  if ( parameters ) {
541  runNumber = parameters->runNumber() + runNumberOffset;
542  eventNumber = parameters->eventNumber() + eventNumberOffset;
543  parameters->extractParameters(m_frame);
544 #if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0)
545  eventWeight = m_frame.getParameter<double>("EventWeights").value_or(0.0);
546 #else
547  eventWeight = m_frame.getParameter<double>("EventWeights");
548 #endif
549  } else { // ... or from DD4hep framework
550  runNumber = m_runNo + runNumberOffset;
551  eventNumber = ctxt.context->GetEventID() + eventNumberOffset;
552  }
553  printout(INFO,"Geant4Output2EDM4hep","+++ Saving EDM4hep event %d run %d.", eventNumber, runNumber);
554 
555  // this does not compile as create() is we only get a const ref - need to review PODIO EventStore API
556  edm4hep::EventHeaderCollection header_collection;
557 
558  auto header = header_collection.create();
559  header.setRunNumber(runNumber);
560  header.setEventNumber(eventNumber);
561  header.setWeight(eventWeight);
562  //not implemented in EDM4hep ? header.setDetectorName(context()->detectorDescription().header().name());
563  header.setTimeStamp(std::time(nullptr));
564 
565  // extract event header, in case we come from edm4hep input
566  auto* meh = context()->event().extension<edm4hep::MutableEventHeader>(false);
567  if(meh) {
568  header.setTimeStamp(meh->getTimeStamp());
569 #if EDM4HEP_BUILD_VERSION >= EDM4HEP_VERSION(0, 99, 0)
570  for (auto const& weight: meh->getWeights()) {
571  header.addToWeights(weight);
572  }
573 #endif
574  }
575 
576  m_frame.put(std::move(header_collection), "EventHeader");
577 
578 #if EDM4HEP_BUILD_VERSION >= EDM4HEP_VERSION(0, 99, 3)
579  // Attach the generator event parameters again if they are available
580  auto* genEvtParams = context()->event().extension<edm4hep::MutableGeneratorEventParameters>(false);
581  if (genEvtParams) {
582  edm4hep::GeneratorEventParametersCollection genEvtParamsColl{};
583  genEvtParamsColl.push_back(*genEvtParams);
584  m_frame.put(std::move(genEvtParamsColl), edm4hep::labels::GeneratorEventParameters);
585  }
586 #endif
587 
588  saveEventParameters<int>(m_eventParametersInt);
589  saveEventParameters<float>(m_eventParametersFloat);
590  saveEventParameters<std::string>(m_eventParametersString);
591 
592  Geant4ParticleMap* part_map = context()->event().extension<Geant4ParticleMap>(false);
593  if ( part_map ) {
594  print("+++ Saving %d EDM4hep particles....",int(part_map->particleMap.size()));
595  if ( part_map->particleMap.size() > 0 ) {
596  saveParticles(part_map);
597  }
598  }
599 }
600 
611  operator std::string() const {
612  const auto* sd = m_coll->sensitive();
613  return dd4hep::sim::Geant4ConversionHelper::encoding(sd->sensitiveDetector());
614  }
615 private:
616  Geant4HitCollection* m_coll{nullptr};
617 };
618 
619 
622  Geant4HitCollection* coll = dynamic_cast<Geant4HitCollection*>(collection);
623  std::string colName = collection->GetName();
624  if( coll == nullptr ){
625  error(" no Geant4HitCollection: %s ", colName.c_str());
626  return ;
627  }
628  size_t nhits = collection->GetSize();
630  debug("+++ Saving EDM4hep collection %s with %d entries.", colName.c_str(), int(nhits));
631 
632  // Using try_emplace here to only fill this the first time we come across
633  m_cellIDEncodingStrings.try_emplace(colName, LazyEncodingExtraction{coll});
634 
635  //-------------------------------------------------------------------
636  if( typeid( Geant4Tracker::Hit ) == coll->type().type() ){
637  // Create the hit container even if there are no entries!
638  auto& hits = m_trackerHits[colName];
639  for(unsigned i=0 ; i < nhits ; ++i){
640  auto sth = hits.create();
641  const Geant4Tracker::Hit* hit = coll->hit(i);
642  const Geant4Tracker::Hit::Contribution& t = hit->truth;
643  int trackID = pm->particleID(t.trackID);
644  auto mcp = m_particles.at(trackID);
645  const auto& mom = hit->momentum;
646  const auto& pos = hit->position;
647  edm4hep::Vector3f();
648  sth.setCellID( hit->cellID ) ;
649  sth.setEDep(hit->energyDeposit/CLHEP::GeV);
650  sth.setPathLength(hit->length/CLHEP::mm);
651  sth.setTime(hit->truth.time/CLHEP::ns);
652 #if EDM4HEP_BUILD_VERSION >= EDM4HEP_VERSION(0, 10, 99)
653  sth.setParticle(mcp);
654 #else
655  sth.setMCParticle(mcp);
656 #endif
657  sth.setPosition( {pos.x()/CLHEP::mm, pos.y()/CLHEP::mm, pos.z()/CLHEP::mm} );
658  sth.setMomentum( {float(mom.x()/CLHEP::GeV),float(mom.y()/CLHEP::GeV),float(mom.z()/CLHEP::GeV)} );
659  auto particleIt = pm->particles().find(trackID);
660  if( ( particleIt != pm->particles().end()) ){
661  // if the original track ID of the particle is not the same as the
662  // original track ID of the hit it was produced by an MCParticle that
663  // is no longer stored
664  sth.setProducedBySecondary( (particleIt->second->originalG4ID != t.trackID) );
665  }
666  }
667  //-------------------------------------------------------------------
668  }
669  else if( typeid( Geant4Calorimeter::Hit ) == coll->type().type() ){
670  Geant4Sensitive* sd = coll->sensitive();
671  int hit_creation_mode = sd->hitCreationMode();
672  // Create the hit container even if there are no entries!
673  auto& hits = m_calorimeterHits[colName];
674  for(unsigned i=0 ; i < nhits ; ++i){
675  auto sch = hits.first.create();
676  const Geant4Calorimeter::Hit* hit = coll->hit(i);
677  const auto& pos = hit->position;
678  sch.setCellID( hit->cellID );
679  sch.setPosition({float(pos.x()/CLHEP::mm), float(pos.y()/CLHEP::mm), float(pos.z()/CLHEP::mm)});
680  sch.setEnergy( hit->energyDeposit/CLHEP::GeV );
681 
682 
683  // now add the individual step contributions
684  for(auto ci=hit->truth.begin(); ci != hit->truth.end(); ++ci){
685 
686  auto sCaloHitCont = hits.second.create();
687  sch.addToContributions( sCaloHitCont );
688 
689  const Geant4HitData::Contribution& c = *ci;
690  int trackID = pm->particleID(c.trackID);
691  auto mcp = m_particles.at(trackID);
692  sCaloHitCont.setEnergy( c.deposit/CLHEP::GeV );
693  sCaloHitCont.setTime( c.time/CLHEP::ns );
694  sCaloHitCont.setParticle( mcp );
695 
696 #if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(1, 0, 0)
697  // In case this contribution has been created via a fast simulation
698  // method, the step length has been set to -1 at its creation. All
699  // contributions that have gone through "normal" simulation will have a
700  // step length >= 0 by definition.
701  if (c.length < 0) {
702  mcp.setHandledByFastSim(true);
703  }
704 #endif
705  if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) {
706  edm4hep::Vector3f p(c.x/CLHEP::mm, c.y/CLHEP::mm, c.z/CLHEP::mm);
707  sCaloHitCont.setPDG( c.pdgID );
708  sCaloHitCont.setStepPosition( p );
709 #if EDM4HEP_BUILD_VERSION >= EDM4HEP_VERSION(0, 99, 3)
710  sCaloHitCont.setStepLength(c.length / CLHEP::mm);
711 #endif
712  }
713  }
714  }
715  //-------------------------------------------------------------------
716  } else {
717  error("+++ unknown type in Geant4HitCollection %s ", coll->type().type().name());
718  }
719 }
Geant4DataConversion.h
dd4hep::sim::G4PARTICLE_SIM_CREATED
@ G4PARTICLE_SIM_CREATED
Definition: Geant4Particle.h:87
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:291
dd4hep::sim::Geant4Output2EDM4hep::intmap_t
std::map< std::string, int > intmap_t
Definition: Geant4Output2EDM4hep.cpp:84
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
dd4hep::sim::Geant4Output2EDM4hep::m_runParametersFloat
floatmap_t m_runParametersFloat
Definition: Geant4Output2EDM4hep.cpp:100
dd4hep::sim::Geant4Output2EDM4hep::m_eventParametersString
stringmap_t m_eventParametersString
Definition: Geant4Output2EDM4hep.cpp:98
Geant4HitCollection.h
dd4hep::sim::Geant4Output2EDM4hep::m_eventNo
int m_eventNo
Definition: Geant4Output2EDM4hep.cpp:106
dd4hep::sim::Geant4Particle::vsz
double vsz
Definition: Geant4Particle.h:126
dd4hep::sim::ExtensionParameters::dblParameters
auto const & dblParameters() const
Get the double parameters.
Definition: ExtensionParameters.h:46
dd4hep::sim::Geant4Output2EDM4hep::m_runHeader
stringmap_t m_runHeader
Definition: Geant4Output2EDM4hep.cpp:95
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:389
dd4hep::sim::G4PARTICLE_GEN_STABLE
@ G4PARTICLE_GEN_STABLE
Definition: Geant4Particle.h:73
dd4hep::sim::Geant4Output2EDM4hep::commit
virtual void commit(OutputContext< G4Event > &ctxt)
Commit data at end of filling procedure.
Definition: Geant4Output2EDM4hep.cpp:368
dd4hep::sim::G4PARTICLE_SIM_PARENT_RADIATED
@ G4PARTICLE_SIM_PARENT_RADIATED
Definition: Geant4Particle.h:93
dd4hep::sim::Geant4Particle::mass
double mass
Particle mass.
Definition: Geant4Particle.h:134
dd4hep::sim::Geant4Particle::vey
double vey
Definition: Geant4Particle.h:128
dd4hep::sim::Geant4HitData::MonteCarloContrib::y
float y
Definition: Geant4Data.h:151
Detector.h
dd4hep::sim::Geant4Output2EDM4hep::endRun
virtual void endRun(const G4Run *run)
Callback to store the Geant4 run information.
Definition: Geant4Output2EDM4hep.cpp:317
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:132
dd4hep::sim::Geant4HitData::MonteCarloContrib::length
double length
Length of this step.
Definition: Geant4Data.h:149
dd4hep::sim::Geant4ParticleMap::particles
const ParticleMap & particles() const
Access the particle map.
Definition: Geant4Particle.h:363
dd4hep::sim::Geant4Output2EDM4hep::m_runParameters
std::unique_ptr< RunParameters > m_runParameters
RunParameters to be written when file is closed.
Definition: Geant4Output2EDM4hep.cpp:112
dd4hep::sim::Geant4Output2EDM4hep::saveCollection
virtual void saveCollection(OutputContext< G4Event > &ctxt, G4VHitsCollection *collection)
Callback to store each Geant4 hit collection.
Definition: Geant4Output2EDM4hep.cpp:621
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:104
dd4hep::sim::Geant4Particle::id
int id
not persistent
Definition: Geant4Particle.h:110
Geant4SensDetAction.h
dd4hep::sim::Geant4Output2EDM4hep::m_fileParameters
std::unique_ptr< FileParameters > m_fileParameters
FileParameters to be written when file is closed.
Definition: Geant4Output2EDM4hep.cpp:114
dd4hep::sim::Geant4HitCollection
Generic hit container class using Geant4HitWrapper objects.
Definition: Geant4HitCollection.h:201
dd4hep::sim::Geant4Output2EDM4hep::m_eventParametersFloat
floatmap_t m_eventParametersFloat
Definition: Geant4Output2EDM4hep.cpp:97
dd4hep::versionString
std::string versionString()
return a string with the current dd4hep version in the form vXX-YY.
Definition: DetectorImp.cpp:122
dd4hep::sim::Geant4Particle::pdgID
int pdgID
Definition: Geant4Particle.h:117
dd4hep::sim::Geant4HitCollection::hit
Geant4HitWrapper & hit(size_t which)
Access the hit wrapper.
Definition: Geant4HitCollection.h:325
dd4hep::sim::Geant4Output2EDM4hep::saveEventParameters
void saveEventParameters(const std::map< std::string, T > &parameters)
Fill event parameters in EDM4hep event.
Definition: Geant4Output2EDM4hep.cpp:144
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:130
LazyEncodingExtraction
Definition: Geant4Output2EDM4hep.cpp:605
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:533
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::m_runParametersString
stringmap_t m_runParametersString
Definition: Geant4Output2EDM4hep.cpp:101
dd4hep::sim::Geant4Output2EDM4hep::saveParticles
void saveParticles(Geant4ParticleMap *particles)
Data conversion interface for MC particles to EDM4hep format.
Definition: Geant4Output2EDM4hep.cpp:428
dd4hep::sim::G4PARTICLE_GEN_DOCUMENTATION
@ G4PARTICLE_GEN_DOCUMENTATION
Definition: Geant4Particle.h:75
dd4hep::sim::G4PARTICLE_SIM_BACKSCATTER
@ G4PARTICLE_SIM_BACKSCATTER
Definition: Geant4Particle.h:88
dd4hep::sim::Geant4ActionContainer::workerContext
Geant4Context * workerContext()
Thread's Geant4 execution context.
Definition: Geant4ActionContainer.cpp:65
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:91
RunParameters.h
dd4hep::sim::Geant4EventAction::mutex
G4Mutex & mutex() const
access to mutex for this action
Definition: Geant4EventAction.h:77
dd4hep::sim::Geant4Output2EDM4hep
Base class to output Geant4 event data to EDM4hep.
Definition: Geant4Output2EDM4hep.cpp:76
dd4hep::sim::Geant4Kernel::worker
Geant4Kernel & worker(unsigned long thread_identifier, bool create_if=false)
Access worker instance by its identifier.
Definition: Geant4Kernel.cpp:230
dd4hep::sim::RunParameters
Extension to pass input run data to output run data.
Definition: RunParameters.h:28
dd4hep::sim::Geant4Output2EDM4hep::calorimetermap_t
std::map< std::string, calorimeterpair_t > calorimetermap_t
Definition: Geant4Output2EDM4hep.cpp:88
dd4hep::sim::Geant4Sensitive::DETAILED_MODE
@ DETAILED_MODE
Definition: Geant4SensDetAction.h:128
VolumeManager.h
dd4hep::sim::Geant4OutputAction::OutputContext
Helper class for thread savety.
Definition: Geant4OutputAction.h:43
dd4hep::sim::Geant4Output2EDM4hep::m_eventParametersInt
intmap_t m_eventParametersInt
Definition: Geant4Output2EDM4hep.cpp:96
dd4hep::sim::Geant4ParticleMap
Data structure to map particles produced during the generation and the simulation.
Definition: Geant4Particle.h:339
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::Geant4Output2EDM4hep::writer_t
podio::Writer writer_t
Definition: Geant4Output2EDM4hep.cpp:79
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
FileParameters.h
dd4hep::sim::G4PARTICLE_SIM_STOPPED
@ G4PARTICLE_SIM_STOPPED
Definition: Geant4Particle.h:91
Geant4OutputAction.h
dd4hep::sim::Geant4Output2EDM4hep::stringmap_t
std::map< std::string, std::string > stringmap_t
Definition: Geant4Output2EDM4hep.cpp:85
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:103
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:93
dd4hep::sim::Geant4Particle::vez
double vez
Definition: Geant4Particle.h:128
dd4hep::sim::G4PARTICLE_SIM_DECAY_CALO
@ G4PARTICLE_SIM_DECAY_CALO
Definition: Geant4Particle.h:89
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:342
dd4hep::sim::Geant4Output2EDM4hep::calorimeterpair_t
std::pair< edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionCollection > calorimeterpair_t
Definition: Geant4Output2EDM4hep.cpp:87
dd4hep::sim::Geant4Output2EDM4hep::m_calorimeterHits
calorimetermap_t m_calorimeterHits
Definition: Geant4Output2EDM4hep.cpp:94
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:123
dd4hep::sim::ExtensionParameters::fltParameters
auto const & fltParameters() const
Get the float parameters.
Definition: ExtensionParameters.h:42
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:120
dd4hep::sim::Geant4Particle::status
int status
Definition: Geant4Particle.h:118
dd4hep::sim::G4PARTICLE_GEN_DECAYED
@ G4PARTICLE_GEN_DECAYED
Definition: Geant4Particle.h:74
dd4hep::sim::Geant4Particle::daughters
Particles daughters
The list of daughters of this MC particle.
Definition: Geant4Particle.h:142
dd4hep::sim::G4PARTICLE_SIM_DECAY_TRACKER
@ G4PARTICLE_SIM_DECAY_TRACKER
Definition: Geant4Particle.h:90
dd4hep::sim::Geant4Output2EDM4hep::~Geant4Output2EDM4hep
virtual ~Geant4Output2EDM4hep()
Default destructor.
Definition: Geant4Output2EDM4hep.cpp:285
dd4hep::sim::FileParameters
Extension to pass input run data to output run data.
Definition: FileParameters.h:28
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
dd4hep::sim::Geant4Kernel::thread_self
static unsigned long int thread_self()
Access thread identifier.
Definition: Geant4Kernel.cpp:211
LazyEncodingExtraction::LazyEncodingExtraction
LazyEncodingExtraction(Geant4HitCollection *coll)
Definition: Geant4Output2EDM4hep.cpp:608
dd4hep::sim::Geant4Output2EDM4hep::m_cellIDEncodingStrings
stringmap_t m_cellIDEncodingStrings
Definition: Geant4Output2EDM4hep.cpp:102
dd4hep::sim::Geant4Output2EDM4hep::m_rntuple
bool m_rntuple
Definition: Geant4Output2EDM4hep.cpp:109
dd4hep::sim::Geant4Output2EDM4hep::saveFileMetaData
void saveFileMetaData()
Store the metadata frame with e.g. the cellID encoding strings.
Definition: Geant4Output2EDM4hep.cpp:355
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:89
dd4hep::sim::Geant4Particle::time
double time
Particle creation time.
Definition: Geant4Particle.h:136
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::FileParameters::extractParameters
void extractParameters(T &destination)
Put parameters into destination.
dd4hep::sim::Geant4Particle::pex
double pex
The track momentum at the end vertex.
Definition: Geant4Particle.h:132
dd4hep::sim::Geant4Output2EDM4hep::m_runNumberOffset
int m_runNumberOffset
Definition: Geant4Output2EDM4hep.cpp:105
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:537
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::Geant4Output2EDM4hep::floatmap_t
std::map< std::string, float > floatmap_t
Definition: Geant4Output2EDM4hep.cpp:83
dd4hep::sim::Geant4Particle::vex
double vex
The end vertex.
Definition: Geant4Particle.h:128
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:126
dd4hep::sim::Geant4Particle::psx
double psx
The track momentum at the start vertex.
Definition: Geant4Particle.h:130
dd4hep::sim::G4PARTICLE_GEN_BEAM
@ G4PARTICLE_GEN_BEAM
Definition: Geant4Particle.h:76
dd4hep::sim::Geant4ParticleHandle::definition
const G4ParticleDefinition * definition() const
Access the Geant4 particle definition object (expensive!)
Definition: Geant4Particle.cpp:112
dd4hep::sim::Geant4Particle::pey
double pey
Definition: Geant4Particle.h:132
dd4hep::sim::ExtensionParameters::intParameters
auto const & intParameters() const
Get the int parameters.
Definition: ExtensionParameters.h:40
dd4hep::sim::Geant4Output2EDM4hep::m_filesByRun
bool m_filesByRun
Definition: Geant4Output2EDM4hep.cpp:108
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:345
dd4hep::sim::G4PARTICLE_SIM_LEFT_DETECTOR
@ G4PARTICLE_SIM_LEFT_DETECTOR
Definition: Geant4Particle.h:92
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:46
dd4hep::sim::RunParameters::extractParameters
void extractParameters(T &destination)
Put parameters into destination.
Definition: Geant4Output2LCIO.cpp:66
dd4hep::sim::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
dd4hep::sim::Geant4Output2EDM4hep::m_particles
edm4hep::MCParticleCollection m_particles
Definition: Geant4Output2EDM4hep.cpp:92
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:28
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:188
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:183
dd4hep::sim::Geant4Output2EDM4hep::m_eventNumberOffset
int m_eventNumberOffset
Definition: Geant4Output2EDM4hep.cpp:107
dd4hep::sim::Geant4Particle::parents
Particles parents
The list of parents of this MC particle.
Definition: Geant4Particle.h:140
dd4hep::sim::Geant4Output2EDM4hep::Geant4Output2EDM4hep
Geant4Output2EDM4hep(Geant4Context *ctxt, const std::string &nam)
Standard constructor.
Definition: Geant4Output2EDM4hep.cpp:264
Geant4Particle.h
dd4hep::sim::Geant4Particle::vsy
double vsy
Definition: Geant4Particle.h:126
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:86
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:418
dd4hep::sim::Geant4HitData::MonteCarloContrib
Utility class describing the monte carlo contribution of a given particle to a hit.
Definition: Geant4Data.h:138
Geant4Kernel.h
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:123
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:105
dd4hep::sim::Geant4Output2EDM4hep::m_runParametersInt
intmap_t m_runParametersInt
Definition: Geant4Output2EDM4hep.cpp:99
dd4hep::sim::Geant4Output2EDM4hep::m_fileUseCount
std::atomic_size_t m_fileUseCount
Definition: Geant4Output2EDM4hep.cpp:90
PropertyMask
dd4hep::detail::ReferenceBitMask< int > PropertyMask
Definition: EDM4hepFileReader.cpp:43
dd4hep::sim::ExtensionParameters::strParameters
auto const & strParameters() const
Get the string parameters.
Definition: ExtensionParameters.h:44
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:130
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:40
dd4hep::sim::G4PARTICLE_GEN_OTHER
@ G4PARTICLE_GEN_OTHER
Definition: Geant4Particle.h:78
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:38
dd4hep::sim::Geant4Calorimeter::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:328
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