DD4hep  1.35.0
Detector Description Toolkit for High Energy Physics
Geant4SensDetAction.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/Printout.h>
16 #include <DD4hep/Primitives.h>
17 #include <DD4hep/InstanceCount.h>
18 
19 #include <DDG4/Geant4Kernel.h>
20 #include <DDG4/Geant4Mapping.h>
21 #include <DDG4/Geant4StepHandler.h>
25 
26 // Geant4 include files
27 #include <G4Step.hh>
28 #include <G4SDManager.hh>
29 #include <G4VSensitiveDetector.hh>
30 
31 // C/C++ include files
32 #include <stdexcept>
33 
34 #include "G4OpticalParameters.hh"
35 #include "G4OpticalPhoton.hh"
36 
37 #ifdef DD4HEP_USE_GEANT4_UNITS
38 #define MM_2_CM 1.0
39 #else
40 #define MM_2_CM 0.1
41 #endif
42 
43 namespace dd4hep {
44  namespace sim {
46  void _print_volumeid(const std::string& tag, const IDDescriptor& id, DDSegmentation::VolumeID volID) {
47  if( id.isValid() ) {
48  std::string value = id.str(volID);
49  printout(ALWAYS, tag, "Volume ID: %016llX -> %s", volID, value.c_str());
50  return;
51  }
52  printout(ALWAYS, tag, "Volume ID: %016llX [no ID descriptor]", volID);
53  }
54 
56  void _print_volumeid(const Geant4Sensitive* action, const char* tag, DDSegmentation::VolumeID volID, double ene=-1e0) {
57  SensitiveDetector sensitive = action->sensitiveDetector();
58  char text[64];
59  text[0] = 0;
60  if( ene > 0e0 ) {
61  ::snprintf(text, sizeof(text), "Deposit: %12.3e GeV", ene/1e9);
62  }
63  if( sensitive.isValid() ) {
64  Readout readout = sensitive.readout();
65  if( readout.isValid() ) {
66  IDDescriptor id = readout.idSpec();
67  if( id.isValid() ) {
68  std::string value = id.str(volID);
69  action->always("%-16s %016llX -> %s %s", tag, volID, value.c_str(), text);
70  return;
71  }
72  action->always("%-16s %016llX -> Readout: %s [no ID descriptor] %s", tag, volID, readout.name(), text);
73  return;
74  }
75  action->always("%-16s %016llX -> Sensitive: %s [no readout] %s", volID, sensitive.name(), text);
76  return;
77  }
78  action->always("%-16s %016llX [internal error: no sensitive detectector] %s", volID, text);
79  }
80  }
81 }
82 
83 using namespace dd4hep::sim;
84 
85 namespace {
86 
87 #if 0
88  Geant4ActionSD* _getSensitiveDetector(const std::string& name) {
89  G4SDManager* mgr = G4SDManager::GetSDMpointer();
90  G4VSensitiveDetector* sd = mgr->FindSensitiveDetector(name);
91  if (0 == sd) {
92  dd4hep::except("Geant4Sensitive", "DDG4: You requested to configure actions "
93  "for the sensitive detector %s,\nDDG4: which is not known to Geant4. "
94  "Are you sure you already converted the geometry?", name.c_str());
95  }
96  Geant4ActionSD* action_sd = dynamic_cast<Geant4ActionSD*>(sd);
97  if (0 == action_sd) {
98  throw dd4hep::except("Geant4Sensitive", "DDG4: You may only configure actions "
99  "for sensitive detectors of type Geant4ActionSD.\n"
100  "DDG4: The sensitive detector of %s is of type %s, which is incompatible.", name.c_str(),
101  typeName(typeid(*sd)).c_str());
102  }
103  return action_sd;
104  }
105 #endif
106 }
107 
109 Geant4ActionSD::Geant4ActionSD(const std::string& nam)
110  : Geant4Action(0, nam) {
112 }
113 
117 }
118 
120 Geant4Filter::Geant4Filter(Geant4Context* ctxt, const std::string& nam)
121  : Geant4Action(ctxt, nam) {
123 }
124 
128 }
129 
131 bool Geant4Filter::operator()(const G4Step*) const {
132  return true;
133 }
134 
137  except("The filter action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
138  return false;
139 }
140 
142 Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& det_ref)
143  : Geant4Action(ctxt, nam), m_detDesc(det_ref), m_detector(det)
144 {
146  if (!det.isValid()) {
147  except("DDG4: Detector element for %s is invalid.", nam.c_str());
148  }
149  declareProperty("UseVolumeManager", m_useVolumeManager = true);
150  declareProperty("HitCreationMode", m_hitCreationMode = SIMPLE_MODE);
151  declareProperty("DebugVolumeID", m_debugVolumeID = false);
156 }
157 
161  m_filters.clear();
163 }
164 
166 int Geant4Sensitive::id() const {
167  return this->m_detector.id();
168 }
169 
172  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
173  adopt(filter);
174 }
175 
178  if (filter) {
179  filter->addRef();
180  m_filters.add(filter);
181  return;
182  }
183  except("Attempt to add invalid sensitive filter!");
184 }
185 
188  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
189  adopt_front(filter);
190 }
191 
194  if (filter) {
195  filter->addRef();
196  m_filters.add_front(filter);
197  return;
198  }
199  except("Attempt to add invalid sensitive filter!");
200 }
201 
203 bool Geant4Sensitive::accept(const G4Step* step) const {
204  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
205  bool result = m_filters.filter(filter, step);
206  return result;
207 }
208 
211  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
212  bool result = m_filters.filter(filter, spot);
213  return result;
214 }
215 
218  m_sensitiveDetector = sens_det;
219 }
220 
224  return *m_sensitiveDetector;
225  //m_sensitiveDetector = _getSensitiveDetector(m_detector.name());
226  //if ( m_sensitiveDetector ) return *m_sensitiveDetector;
227  except("DDG4: The sensitive detector for action %s was not properly configured.", name().c_str());
228  throw std::runtime_error("Geant4Sensitive::detector");
229 }
230 
233  return *m_sequence;
234 }
235 
238  return m_detDesc;
239 }
240 
242 const std::string& Geant4Sensitive::hitCollectionName(std::size_t which) const {
243  return sequence().hitCollectionName(which);
244 }
245 
248  return sequence().collection(which);
249 }
250 
253  return sequence().collectionByID(id);
254 }
255 
258 }
259 
261 void Geant4Sensitive::begin(G4HCofThisEvent* /* HCE */) {
262 }
263 
265 void Geant4Sensitive::end(G4HCofThisEvent* /* HCE */) {
266 }
267 
269 bool Geant4Sensitive::process(const G4Step* /* step */, G4TouchableHistory* /* history */) {
270  return false;
271 }
272 
274 bool Geant4Sensitive::processFastSim(const Geant4FastSimSpot* /* spot */, G4TouchableHistory* /* history */) {
275  except("The sensitive action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
276  return false;
277 }
278 
280 void Geant4Sensitive::clear(G4HCofThisEvent* /* HCE */) {
281 }
282 
284 void Geant4Sensitive::mark(const G4Track* track) const {
286  if ( truth ) truth->mark(track);
287 }
288 
290 void Geant4Sensitive::mark(const G4Step* step) const {
292  if ( truth ) truth->mark(step);
293 }
294 
296 long long int Geant4Sensitive::volumeID(const G4Step* step) {
297  VolumeID volID = m_detector.id();
298  if( this->useVolumeManager() ) {
299  Geant4StepHandler stepH(step);
301  volID = volMgr.volumeID(stepH.preTouchable());
302  if( this->m_debugVolumeID ) {
303  _print_volumeid(this, "Volume ID", volID, step->GetTotalEnergyDeposit());
304  }
305  }
306  return volID;
307 }
308 
310 long long int Geant4Sensitive::volumeID(const G4VTouchable* touchable) {
311  VolumeID volID = m_detector.id();
312  if( this->useVolumeManager() ) {
314  volID= volMgr.volumeID(touchable);
315  if( this->m_debugVolumeID ) {
316  _print_volumeid(this, "Volume ID", volID);
317  }
318  }
319  return volID;
320 }
321 
323 long long int Geant4Sensitive::cellID(const G4Step* step) {
324  VolumeID volID = m_detector.id();
325  if( this->useVolumeManager() ) {
326  Geant4StepHandler h(step);
328  bool UsePostStepOnly = G4OpticalParameters::Instance() &&
329  G4OpticalParameters::Instance()->GetBoundaryInvokeSD() &&
330  (step->GetTrack()->GetDefinition() == G4OpticalPhoton::Definition());
331 
332  volID = volMgr.volumeID(UsePostStepOnly? h.postTouchable() : h.preTouchable());
333  if ( m_segmentation.isValid() ) {
334  std::exception_ptr eptr;
335  G4ThreeVector global = UsePostStepOnly? h.postPosG4() : 0.5 * (h.prePosG4()+h.postPosG4());
336  G4ThreeVector local = UsePostStepOnly? h.postTouchable()->GetHistory()->GetTopTransform().TransformPoint(global) :
337  h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global);
338  Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
339  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
340  try {
341  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
342  if( this->m_debugVolumeID ) {
343  _print_volumeid(this, "Cell ID", cID, step->GetTotalEnergyDeposit());
344  }
345  return cID;
346  }
347  catch(const std::exception& e) {
348  eptr = std::current_exception();
349  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
350  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
351  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
352  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
353  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
354  error("....... Pre-step: %s SD: %s", h.volName(h.pre), h.sdName(h.pre).c_str());
355  if ( h.post )
356  error("....... Post-step: %s SD: %s", h.volName(h.post), h.sdName(h.post).c_str());
357  std::rethrow_exception(std::move(eptr));
358  }
359  }
360  else if( this->m_debugVolumeID ) {
361  _print_volumeid(this, "Volume ID", volID, step->GetTotalEnergyDeposit());
362  }
363  }
364  return volID;
365 }
366 
368 long long int Geant4Sensitive::cellID(const G4VTouchable* touchable, const G4ThreeVector& global) {
369  VolumeID volID = m_detector.id();
370  if( this->useVolumeManager() ) {
372 
373  volID = volMgr.volumeID(touchable);
374  if ( m_segmentation.isValid() ) {
375  std::exception_ptr eptr;
376  G4ThreeVector local = touchable->GetHistory()->GetTopTransform().TransformPoint(global);
377  Position loc (local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
378  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
379  try {
380  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
381  if( this->m_debugVolumeID ) {
382  _print_volumeid(this, "Cell ID", cID);
383  }
384  return cID;
385  }
386  catch(const std::exception& e) {
387  auto* pvol = touchable->GetVolume();
388  auto* vol = pvol->GetLogicalVolume();
389  auto* sd = vol->GetSensitiveDetector();
390  eptr = std::current_exception();
391  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
392  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
393  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
394  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
395  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
396  error("....... Touchable: %s SD: %s", vol->GetName().c_str(), sd ? sd->GetName().c_str() : "???");
397  std::rethrow_exception(std::move(eptr));
398  }
399  }
400  else if( this->m_debugVolumeID ) {
401  _print_volumeid(this, "Volume ID", volID);
402  }
403  }
404  return volID;
405 }
406 
409  : Geant4Action(ctxt, nam), m_hce(0), m_detector(0)
410 {
411  m_needsControl = true;
412  context()->sensitiveActions().insert(name(), this);
416  declareProperty("SensitiveType", m_sensitiveType);
418 }
419 
424  m_filters.clear();
425  m_actors.clear();
427 }
428 
431  m_context = ctxt;
432  m_actors.updateContext(ctxt);
433  m_filters.updateContext(ctxt);
434 }
435 
438  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
439  adopt(filter);
440 }
441 
444  if (sensitive) {
445  sensitive->addRef();
446  m_actors.add(sensitive);
447  return;
448  }
449  except("Attempt to add invalid sensitive actor!");
450 }
451 
454  if (filter) {
455  filter->addRef();
456  m_filters.add(filter);
457  return;
458  }
459  except("Attempt to add invalid sensitive filter!");
460 }
461 
463 std::size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& collection_name, create_t func) {
464  m_collections.emplace_back(collection_name, make_pair(owner,func));
465  return m_collections.size() - 1;
466 }
467 
469 std::size_t Geant4SensDetActionSequence::Geant4SensDetActionSequence::defineCollections(Geant4ActionSD* sens_det) {
470  std::size_t count = 0;
471  m_detector = sens_det;
472  m_actors(&Geant4Sensitive::setDetector, sens_det);
474  for (HitCollections::const_iterator i = m_collections.begin(); i != m_collections.end(); ++i) {
475  sens_det->defineCollection((*i).first);
476  ++count;
477  }
478  return count;
479 }
480 
482 const std::string& Geant4SensDetActionSequence::hitCollectionName(std::size_t which) const {
483  if (which < m_collections.size()) {
484  return m_collections[which].first;
485  }
486  static std::string blank = "";
487  except("The collection name index for subdetector %s is out of range!", c_name());
488  return blank;
489 }
490 
493  if (which < m_collections.size()) {
494  int hc_id = m_detector->GetCollectionID(which);
495  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(hc_id);
496  if (c)
497  return c;
498  except("The collection index for subdetector %s is wrong!", c_name());
499  }
500  except("The collection name index for subdetector %s is out of range!", c_name());
501  return 0;
502 }
503 
506  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(id);
507  if (c)
508  return c;
509  except("The collection index for subdetector %s is wrong!", c_name());
510  return 0;
511 }
512 
514 bool Geant4SensDetActionSequence::accept(const G4Step* step) const {
515  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
516  bool result = m_filters.filter(filter, step);
517  return result;
518 }
519 
522  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
523  bool result = m_filters.filter(filter, spot);
524  return result;
525 }
526 
528 bool Geant4SensDetActionSequence::process(const G4Step* step, G4TouchableHistory* history) {
529  bool result = false;
530  for (Geant4Sensitive* sensitive : m_actors) {
531  if ( sensitive->accept(step) )
532  result |= sensitive->process(step, history);
533  }
534  m_process(step, history);
535  return result;
536 }
537 
539 bool Geant4SensDetActionSequence::processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) {
540  bool result = false;
541  for (Geant4Sensitive* sensitive : m_actors) {
542  if ( sensitive->accept(spot) )
543  result |= sensitive->processFastSim(spot, history);
544  }
545  m_process(spot, history);
546  return result;
547 }
548 
553 void Geant4SensDetActionSequence::begin(G4HCofThisEvent* hce) {
554  m_hce = hce;
555  for (std::size_t count = 0; count < m_collections.size(); ++count) {
556  const HitCollection& cr = m_collections[count];
557  Geant4HitCollection* col = (*cr.second.second)(name(), cr.first, cr.second.first);
558  int id = m_detector->GetCollectionID(count);
559  m_hce->AddHitsCollection(id, col);
560  }
562  m_begin (m_hce);
563 }
564 
566 void Geant4SensDetActionSequence::end(G4HCofThisEvent* hce) {
567  m_end(hce);
569  // G4HCofThisEvent must be available until end-event. m_hce = 0;
570 }
571 
573 
579  m_clear (m_hce);
581 }
582 
585  detail::releaseObjects(m_sequences);
586  m_sequences.clear();
587 }
588 
591  std::string n = "SD_Seq_" + nam;
592  Members::const_iterator i = m_sequences.find(n);
593  if (i != m_sequences.end())
594  return (*i).second;
595  except("Attempt to access undefined SensDetActionSequence: %s ", nam.c_str());
596  return nullptr;
597 }
598 
601  std::string nam = "SD_Seq_" + name;
602  Members::const_iterator i = m_sequences.find(nam);
603  if (i != m_sequences.end())
604  return (*i).second;
605  return 0;
606 }
607 
609 void Geant4SensDetSequences::insert(const std::string& name, Geant4SensDetActionSequence* seq) {
610  if (seq) {
611  std::string nam = "SD_Seq_" + name;
612  seq->addRef();
613  m_sequences[nam] = seq;
614  return;
615  }
616  except("Attempt to add invalid sensitive sequence with name:%s", name.c_str());
617 }
618 
621  m_sequences.clear();
622 }
dd4hep::sim::Geant4Sensitive::m_sequence
Geant4SensDetActionSequence * m_sequence
Reference to the containing action sequence.
Definition: Geant4SensDetAction.h:135
Geant4MonteCarloTruth.h
dd4hep::sim::Geant4SensDetActionSequence::m_sensitive
SensitiveDetector m_sensitive
Reference to the sensitive detector element.
Definition: Geant4SensDetAction.h:357
dd4hep::sim::Geant4Sensitive::m_useVolumeManager
bool m_useVolumeManager
Property: Use the volume manager to access CellID and VolumeID.
Definition: Geant4SensDetAction.h:141
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:26
dd4hep::sim::Geant4Sensitive::adopt
void adopt(Geant4Filter *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:177
dd4hep::sim::Geant4Sensitive::defineCollections
virtual void defineCollections()
Define collections created by this sensitivie action object.
Definition: Geant4SensDetAction.cpp:257
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4Context::detectorDescription
Detector & detectorDescription() const
Access to detector description.
Definition: Geant4Context.cpp:91
dd4hep::sim::Geant4SensDetSequences::insert
void insert(const std::string &name, Geant4SensDetActionSequence *seq)
Insert sequence member.
Definition: Geant4SensDetAction.cpp:609
Geant4Mapping.h
dd4hep::sim::Geant4SensDetActionSequence::m_end
CallbackSequence m_end
Callback sequence for event finalization action.
Definition: Geant4SensDetAction.h:344
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:43
dd4hep::sim::Geant4SensDetActionSequence::processFastSim
virtual bool processFastSim(const Geant4FastSimSpot *spot, G4TouchableHistory *history)
GFLASH/FastSim interface: Method for generating hit(s) using the information of the fast simulation s...
Definition: Geant4SensDetAction.cpp:539
dd4hep::sim::Geant4ActionContainer::sensitiveAction
Geant4SensDetActionSequence * sensitiveAction(const std::string &name)
Access to the sensitive detector action from the actioncontainer object.
Definition: Geant4ActionContainer.cpp:139
dd4hep::sim::Geant4SensDetActionSequence::m_actors
Actors< Geant4Sensitive > m_actors
The list of sensitive detector objects.
Definition: Geant4SensDetAction.h:350
dd4hep::sim::Geant4ActionSD::~Geant4ActionSD
virtual ~Geant4ActionSD()
Default destructor.
Definition: Geant4SensDetAction.cpp:115
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::sim::Geant4Sensitive::m_filters
Actors< Geant4Filter > m_filters
The list of sensitive detector filter objects.
Definition: Geant4SensDetAction.h:161
dd4hep::sim::Geant4StepHandler::pre
G4StepPoint * pre
Definition: Geant4StepHandler.h:49
dd4hep::sim::Geant4Sensitive::detector
Geant4ActionSD & detector() const
Access to the sensitive detector object.
Definition: Geant4SensDetAction.cpp:222
Geant4VolumeManager.h
dd4hep::sim::Geant4Sensitive::clear
virtual void clear(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:280
dd4hep::sim::Geant4SensDetActionSequence::clear
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:578
dd4hep::sim::Geant4SensDetSequences::m_sequences
Members m_sequences
Definition: Geant4SensDetAction.h:485
dd4hep::sim::Geant4SensDetSequences::clear
void clear()
Clear the sequence list.
Definition: Geant4SensDetAction.cpp:620
dd4hep::sim::Geant4Action::m_context
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:116
dd4hep::sim::Geant4StepHandler::volName
const char * volName(const G4StepPoint *p, const char *undefined="") const
Definition: Geant4StepHandler.h:147
Geant4SensDetAction.h
dd4hep::sim::Geant4HitCollection
Generic hit container class using Geant4HitWrapper objects.
Definition: Geant4HitCollection.h:201
dd4hep::sim::Geant4Sensitive::process
virtual bool process(const G4Step *step, G4TouchableHistory *history)
G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
Definition: Geant4SensDetAction.cpp:269
dd4hep::sim::Geant4Sensitive::Geant4Sensitive
Geant4Sensitive(Geant4Context *context, const std::string &name, DetElement det, Detector &description)
Constructor. The sensitive detector element is identified by the detector name.
Definition: Geant4SensDetAction.cpp:142
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:126
dd4hep::sim::Geant4SensDetActionSequence::adopt
void adopt(Geant4Sensitive *sensitive)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:443
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
Geant4StepHandler.h
dd4hep::sim::Geant4Mapping::instance
static Geant4Mapping & instance()
Possibility to define a singleton instance.
Definition: Geant4Mapping.cpp:36
dd4hep::sim::Geant4Filter::~Geant4Filter
virtual ~Geant4Filter()
Standard destructor.
Definition: Geant4SensDetAction.cpp:126
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::sim::Geant4StepHandler::postTouchable
const G4VTouchable * postTouchable() const
Definition: Geant4StepHandler.h:144
dd4hep::sim::Geant4Context::sensitiveActions
Geant4SensDetSequences & sensitiveActions() const
Access to the sensitive detector sequences from the kernel object.
Definition: Geant4Context.cpp:143
dd4hep::sim::Geant4StepHandler::prePosG4
const G4ThreeVector & prePosG4() const
Returns the pre-step position as a G4ThreeVector.
Definition: Geant4StepHandler.h:89
dd4hep::sim::Geant4FastSimSpot
Spot definition for fast simulation and GFlash.
Definition: Geant4FastSimSpot.h:71
dd4hep::sim::Geant4Sensitive::volumeID
long long int volumeID(const G4Step *step)
Returns the volumeID of the sensitive volume corresponding to the step.
Definition: Geant4SensDetAction.cpp:296
dd4hep::sim::Geant4Sensitive::collection
Geant4HitCollection * collection(std::size_t which)
Retrieve the hits collection associated with this detector by its serial number.
Definition: Geant4SensDetAction.cpp:247
dd4hep::sim::Geant4Sensitive::~Geant4Sensitive
virtual ~Geant4Sensitive()
Standard destructor.
Definition: Geant4SensDetAction.cpp:159
dd4hep::sim::Geant4SensDetActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for event initialization action.
Definition: Geant4SensDetAction.h:342
dd4hep::sim::Geant4StepHandler
Helper class to ease the extraction of information from a G4Step object.
Definition: Geant4StepHandler.h:46
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::Geant4Sensitive::SIMPLE_MODE
@ SIMPLE_MODE
Definition: Geant4SensDetAction.h:126
dd4hep::sim::Geant4SensDetActionSequence::Geant4SensDetActionSequence
Geant4SensDetActionSequence(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SensDetAction.cpp:408
dd4hep::sim::Geant4StepHandler::post
G4StepPoint * post
Definition: Geant4StepHandler.h:50
dd4hep::sim::Geant4Sensitive::adoptFilter_front
void adoptFilter_front(Geant4Action *filter)
Add an actor responding to all callbacks to the sequence front. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:187
dd4hep::sim::Geant4VolumeManager::volumeID
VolumeID volumeID(const G4VTouchable *touchable) const
Access CELLID by Geant4 touchable object.
Definition: Geant4VolumeManager.cpp:383
dd4hep::sim::Geant4SensDetActionSequence::m_process
CallbackSequence m_process
Callback sequence for step processing.
Definition: Geant4SensDetAction.h:346
dd4hep::sim::Geant4SensDetSequences::~Geant4SensDetSequences
virtual ~Geant4SensDetSequences()
Default destructor.
Definition: Geant4SensDetAction.cpp:584
dd4hep::sim::Geant4SensDetActionSequence::m_filters
Actors< Geant4Filter > m_filters
The list of sensitive detector filter objects.
Definition: Geant4SensDetAction.h:352
dd4hep::sim::Geant4SensDetSequences::find
Geant4SensDetActionSequence * find(const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:600
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:187
dd4hep::sim::Geant4Sensitive::mark
void mark(const G4Track *track) const
Mark the track to be kept for MC truth propagation during hit processing.
Definition: Geant4SensDetAction.cpp:284
dd4hep::sim::Geant4ActionSD::GetCollectionID
virtual G4int GetCollectionID(G4int i)=0
This is a utility method which returns the hits collection ID.
dd4hep::sim::Geant4Action::error
void error(const char *fmt,...) const
Support of error messages.
Definition: Geant4Action.cpp:231
MM_2_CM
#define MM_2_CM
Definition: Geant4SensDetAction.cpp:40
dd4hep::sim::Geant4Sensitive::m_readout
Readout m_readout
Reference to the readout structure.
Definition: Geant4SensDetAction.h:157
dd4hep::sim::Geant4Sensitive::setDetector
void setDetector(Geant4ActionSD *sens_det)
Access to the sensitive detector object.
Definition: Geant4SensDetAction.cpp:217
G4VSensitiveDetector
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
Definition: Geant4Classes.h:59
dd4hep::sim::Geant4SensDetActionSequence::m_hce
G4HCofThisEvent * m_hce
Geant4 hit collection context.
Definition: Geant4SensDetAction.h:340
dd4hep::sim::Geant4Sensitive::m_detDesc
Detector & m_detDesc
Reference to the detector description object.
Definition: Geant4SensDetAction.h:150
dd4hep::Detector::sensitiveDetector
virtual SensitiveDetector sensitiveDetector(const std::string &name) const =0
Retrieve a sensitive detector by its name from the detector description.
dd4hep::sim::Geant4Sensitive::accept
bool accept(const G4Step *step) const
Callback before hit processing starts. Invoke all filters.
Definition: Geant4SensDetAction.cpp:203
dd4hep::sim::Geant4SensDetActionSequence::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:566
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::Geant4Sensitive::sensitiveDetector
SensitiveDetector sensitiveDetector() const
Access the dd4hep sensitive detector.
Definition: Geant4SensDetAction.h:213
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4MonteCarloTruth
Default Interface class to handle monte carlo truth records.
Definition: Geant4MonteCarloTruth.h:43
dd4hep::sim::Geant4Sensitive::id
int id() const
Get the detector identifier (DetElement::id())
Definition: Geant4SensDetAction.cpp:166
dd4hep::sim::Geant4SensDetActionSequence::m_detector
Geant4ActionSD * m_detector
Reference to G4 sensitive detector.
Definition: Geant4SensDetAction.h:359
dd4hep::sim::Geant4SensDetActionSequence::collection
Geant4HitCollection * collection(std::size_t which) const
Retrieve the hits collection associated with this detector by its serial number.
Definition: Geant4SensDetAction.cpp:492
dd4hep::sim::Geant4Sensitive::m_hitCreationMode
int m_hitCreationMode
Property: Hit creation mode. Maybe one of the enum HitCreationFlags.
Definition: Geant4SensDetAction.h:139
dd4hep::IDDescriptor::str
std::string str(VolumeID vid) const
Decode volume IDs and return string reprensentation for debugging purposes.
Definition: IDDescriptor.cpp:174
dd4hep::sim::Geant4Sensitive::begin
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the beginning of each event.
Definition: Geant4SensDetAction.cpp:261
dd4hep::sim::Geant4SensDetActionSequence::accept
bool accept(const G4Step *step) const
Callback before hit processing starts. Invoke all filters.
Definition: Geant4SensDetAction.cpp:514
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::release
long release()
Decrease reference count. Implicit destruction.
Definition: Geant4Action.cpp:76
dd4hep::sim::Geant4SensDetActionSequence::~Geant4SensDetActionSequence
virtual ~Geant4SensDetActionSequence()
Default destructor.
Definition: Geant4SensDetAction.cpp:421
dd4hep::sim::Geant4VolumeManager
The Geant4VolumeManager to facilitate optimized lookups of cell IDs from touchables.
Definition: Geant4VolumeManager.h:47
dd4hep::Readout::segmentation
Segmentation segmentation() const
Access segmentation structure.
Definition: Readout.cpp:134
dd4hep::Segmentation::cellID
CellID cellID(const Position &localPosition, const Position &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the local position
Definition: Segmentations.cpp:72
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4SensDetActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4SensDetAction.cpp:430
dd4hep::sim::Geant4Mapping::volumeManager
Geant4VolumeManager volumeManager() const
Access the volume manager.
Definition: Geant4Mapping.cpp:70
dd4hep::sim::Geant4SensDetActionSequence::m_sensitiveType
std::string m_sensitiveType
The true sensitive type of the detector.
Definition: Geant4SensDetAction.h:361
dd4hep::sim::Geant4Filter::Geant4Filter
Geant4Filter(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SensDetAction.cpp:120
dd4hep::sim::IDDescriptor
IDDescriptor IDDescriptor
Definition: LCIOConversions.cpp:69
dd4hep::sim::Geant4SensDetActionSequence::m_collections
HitCollections m_collections
Hit collection creators.
Definition: Geant4SensDetAction.h:355
dd4hep::sim::Geant4ActionSD
Interface class to access properties of the underlying Geant4 sensitive detector structure.
Definition: Geant4SensDetAction.h:61
dd4hep::sim::Geant4StepHandler::postPosG4
const G4ThreeVector & postPosG4() const
Returns the post-step position as a G4ThreeVector.
Definition: Geant4StepHandler.h:98
dd4hep::sim::Geant4SensDetActionSequence::hitCollectionName
const std::string & hitCollectionName(std::size_t which) const
Access HitCollection container names.
Definition: Geant4SensDetAction.cpp:482
dd4hep::SensitiveDetector::type
std::string type() const
Access the type of the sensitive detector.
Definition: DetElement.cpp:409
dd4hep::sim::Geant4Sensitive::m_sensitive
SensitiveDetector m_sensitive
Reference to the sensitive detector element.
Definition: Geant4SensDetAction.h:155
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:80
Primitives.h
VolumeID
dd4hep::DDSegmentation::VolumeID VolumeID
Definition: SegmentationDictionary.h:50
dd4hep::sim::Geant4Action::addRef
long addRef()
Increase reference count.
Definition: Geant4Action.cpp:71
dd4hep::sim::Geant4SensDetActionSequence::collectionByID
Geant4HitCollection * collectionByID(std::size_t id) const
Retrieve the hits collection associated with this detector by its collection identifier.
Definition: Geant4SensDetAction.cpp:505
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:46
dd4hep::sim::Geant4SensDetActionSequence::HitCollection
std::pair< std::string, std::pair< Geant4Sensitive *, create_t > > HitCollection
Definition: Geant4SensDetAction.h:335
dd4hep::sim::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
dd4hep::sim::Geant4Sensitive::useVolumeManager
bool useVolumeManager() const
Access volume manager usage flag. This is a subdetector specific flag.
Definition: Geant4SensDetAction.h:183
dd4hep::sim::Geant4Action::c_name
const char * c_name() const
Access name of the action.
Definition: Geant4Action.h:284
dd4hep::sim::Geant4SensDetActionSequence
The sequencer to host Geant4 sensitive actions called if particles interact with sensitive elements.
Definition: Geant4SensDetAction.h:332
dd4hep::sim::Geant4Sensitive::cellID
long long int cellID(const G4Step *step)
Returns the cellID of the sensitive volume corresponding to the step.
Definition: Geant4SensDetAction.cpp:323
dd4hep::sim::Geant4Sensitive::m_detector
DetElement m_detector
Reference to the detector element describing this sensitive element.
Definition: Geant4SensDetAction.h:153
dd4hep::sim::Geant4SensDetActionSequence::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:437
dd4hep::sim::Geant4Sensitive::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:171
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4Sensitive::processFastSim
virtual bool processFastSim(const Geant4FastSimSpot *spot, G4TouchableHistory *history)
GFLASH/FastSim interface: Method for generating hit(s) using the information of the fast simulation s...
Definition: Geant4SensDetAction.cpp:274
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::SensitiveDetector::readout
Readout readout() const
Access readout structure of the sensitive detector.
Definition: DetElement.cpp:420
dd4hep::sim::Geant4Sensitive::hitCollectionName
const std::string & hitCollectionName(std::size_t which) const
Access HitCollection container names.
Definition: Geant4SensDetAction.cpp:242
dd4hep::sim::Geant4SensDetActionSequence::defineCollection
std::size_t defineCollection(Geant4Sensitive *owner, const std::string &name, create_t func)
Initialize the usage of a hit collection. Returns the collection identifier.
Definition: Geant4SensDetAction.cpp:463
dd4hep::sim::Geant4Filter
Base class to construct filters for Geant4 sensitive detectors.
Definition: Geant4SensDetAction.h:96
dd4hep::sim::Geant4StepHandler::sdName
std::string sdName(const G4StepPoint *p, const std::string &undefined="") const
Definition: Geant4StepHandler.h:168
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4Action::always
void always(const char *fmt,...) const
Support of always printed messages.
Definition: Geant4Action.cpp:199
dd4hep::sim::_print_volumeid
void _print_volumeid(const std::string &tag, const IDDescriptor &id, DDSegmentation::VolumeID volID)
Print volume ID.
Definition: Geant4SensDetAction.cpp:46
dd4hep::Readout
Handle to the implementation of the readout structure of a subdetector.
Definition: Readout.h:38
Geant4Kernel.h
dd4hep::DetElement::id
int id() const
Get the detector identifier.
Definition: DetElement.cpp:169
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:123
dd4hep::Readout::idSpec
IDDescriptor idSpec() const
Access IDDescription structure.
Definition: Readout.cpp:112
dd4hep::sim::Geant4Sensitive::adopt_front
void adopt_front(Geant4Filter *filter)
Add an actor responding to all callbacks to the sequence front. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:193
dd4hep::sim::Geant4SensDetActionSequence::begin
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the beginning of each event.
Definition: Geant4SensDetAction.cpp:553
dd4hep::sim::Geant4Sensitive::m_segmentation
Segmentation m_segmentation
Reference to segmentation.
Definition: Geant4SensDetAction.h:159
dd4hep::sim::Geant4SensDetSequences::operator[]
Geant4SensDetActionSequence * operator[](const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:590
dd4hep::sim::Geant4MonteCarloTruth::mark
virtual void mark(const G4Track *track)=0
Mark a Geant4 track to be kept for later MC truth analysis.
InstanceCount.h
dd4hep::sim::Geant4StepHandler::preTouchable
const G4VTouchable * preTouchable() const
Definition: Geant4StepHandler.h:141
dd4hep::sim::Geant4ActionSD::Geant4ActionSD
Geant4ActionSD(const std::string &name)
Standard action constructor.
Definition: Geant4SensDetAction.cpp:109
dd4hep::sim::Geant4Sensitive::m_sensitiveDetector
Geant4ActionSD * m_sensitiveDetector
Reference to G4 sensitive detector.
Definition: Geant4SensDetAction.h:133
Printout.h
dd4hep::sim::Geant4Sensitive::collectionByID
Geant4HitCollection * collectionByID(std::size_t id)
Retrieve the hits collection associated with this detector by its collection identifier.
Definition: Geant4SensDetAction.cpp:252
dd4hep::sim::Geant4Sensitive::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:265
dd4hep::sim::Geant4Sensitive::sequence
Geant4SensDetActionSequence & sequence() const
Access to the hosting sequence.
Definition: Geant4SensDetAction.cpp:232
dd4hep::sim::Geant4Sensitive::m_debugVolumeID
bool m_debugVolumeID
Property: Debug/Print Cell IDs in functions cellID(), volumeID()
Definition: Geant4SensDetAction.h:143
dd4hep::sim::Geant4SensDetActionSequence::m_clear
CallbackSequence m_clear
Callback sequence to invoke the event deletion.
Definition: Geant4SensDetAction.h:348
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4SensDetActionSequence::process
virtual bool process(const G4Step *step, G4TouchableHistory *history)
G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
Definition: Geant4SensDetAction.cpp:528
dd4hep::sim::Geant4ActionSD::defineCollection
virtual std::size_t defineCollection(const std::string &name)=0
Initialize the usage of a hit collection. Returns the collection identifier.
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4Filter::operator()
virtual bool operator()(const G4Step *step) const
Filter action. Return true if hits should be processed. Default returns true.
Definition: Geant4SensDetAction.cpp:131
dd4hep::sim::Geant4Sensitive::detectorDescription
Detector & detectorDescription() const
Access the detector description object.
Definition: Geant4SensDetAction.cpp:237