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 using namespace dd4hep::sim;
44 
45 namespace {
46 
47 #if 0
48  Geant4ActionSD* _getSensitiveDetector(const std::string& name) {
49  G4SDManager* mgr = G4SDManager::GetSDMpointer();
50  G4VSensitiveDetector* sd = mgr->FindSensitiveDetector(name);
51  if (0 == sd) {
52  dd4hep::except("Geant4Sensitive", "DDG4: You requested to configure actions "
53  "for the sensitive detector %s,\nDDG4: which is not known to Geant4. "
54  "Are you sure you already converted the geometry?", name.c_str());
55  }
56  Geant4ActionSD* action_sd = dynamic_cast<Geant4ActionSD*>(sd);
57  if (0 == action_sd) {
58  throw dd4hep::except("Geant4Sensitive", "DDG4: You may only configure actions "
59  "for sensitive detectors of type Geant4ActionSD.\n"
60  "DDG4: The sensitive detector of %s is of type %s, which is incompatible.", name.c_str(),
61  typeName(typeid(*sd)).c_str());
62  }
63  return action_sd;
64  }
65 #endif
66 
67  void _print_volumeid(const Geant4Sensitive* action, dd4hep::DDSegmentation::VolumeID volID) {
68  dd4hep::SensitiveDetector sensitive = action->sensitiveDetector();
69  if( sensitive.isValid() ) {
70  dd4hep::Readout readout = sensitive.readout();
71  if( readout.isValid() ) {
72  dd4hep::IDDescriptor id = readout.idSpec();
73  if( id.isValid() ) {
74  std::string value = id.str(volID);
75  action->always("Volume ID: %016llX -> %s", volID, value.c_str());
76  return;
77  }
78  action->always("Volume ID: %016llX -> Readout: %s [no ID descriptor]", volID, readout.name());
79  return;
80  }
81  action->always("Volume ID: %016llX -> Sensitive: %s [no readout]", volID, sensitive.name());
82  return;
83  }
84  action->always("Volume ID: %016llX [internal error: no sensitive detectector]", volID);
85  }
86 
87 }
88 
90 Geant4ActionSD::Geant4ActionSD(const std::string& nam)
91  : Geant4Action(0, nam) {
93 }
94 
98 }
99 
101 Geant4Filter::Geant4Filter(Geant4Context* ctxt, const std::string& nam)
102  : Geant4Action(ctxt, nam) {
104 }
105 
109 }
110 
112 bool Geant4Filter::operator()(const G4Step*) const {
113  return true;
114 }
115 
118  except("The filter action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
119  return false;
120 }
121 
123 Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& det_ref)
124  : Geant4Action(ctxt, nam), m_detDesc(det_ref), m_detector(det)
125 {
127  if (!det.isValid()) {
128  except("DDG4: Detector element for %s is invalid.", nam.c_str());
129  }
130  declareProperty("UseVolumeManager", m_useVolumeManager = true);
131  declareProperty("HitCreationMode", m_hitCreationMode = SIMPLE_MODE);
132  declareProperty("DebugVolumeID", m_debugVolumeID = false);
137 }
138 
142  m_filters.clear();
144 }
145 
147 int Geant4Sensitive::id() const {
148  return this->m_detector.id();
149 }
150 
153  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
154  adopt(filter);
155 }
156 
159  if (filter) {
160  filter->addRef();
161  m_filters.add(filter);
162  return;
163  }
164  except("Attempt to add invalid sensitive filter!");
165 }
166 
169  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
170  adopt_front(filter);
171 }
172 
175  if (filter) {
176  filter->addRef();
177  m_filters.add_front(filter);
178  return;
179  }
180  except("Attempt to add invalid sensitive filter!");
181 }
182 
184 bool Geant4Sensitive::accept(const G4Step* step) const {
185  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
186  bool result = m_filters.filter(filter, step);
187  return result;
188 }
189 
192  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
193  bool result = m_filters.filter(filter, spot);
194  return result;
195 }
196 
199  m_sensitiveDetector = sens_det;
200 }
201 
205  return *m_sensitiveDetector;
206  //m_sensitiveDetector = _getSensitiveDetector(m_detector.name());
207  //if ( m_sensitiveDetector ) return *m_sensitiveDetector;
208  except("DDG4: The sensitive detector for action %s was not properly configured.", name().c_str());
209  throw std::runtime_error("Geant4Sensitive::detector");
210 }
211 
214  return *m_sequence;
215 }
216 
219  return m_detDesc;
220 }
221 
223 const std::string& Geant4Sensitive::hitCollectionName(std::size_t which) const {
224  return sequence().hitCollectionName(which);
225 }
226 
229  return sequence().collection(which);
230 }
231 
234  return sequence().collectionByID(id);
235 }
236 
239 }
240 
242 void Geant4Sensitive::begin(G4HCofThisEvent* /* HCE */) {
243 }
244 
246 void Geant4Sensitive::end(G4HCofThisEvent* /* HCE */) {
247 }
248 
250 bool Geant4Sensitive::process(const G4Step* /* step */, G4TouchableHistory* /* history */) {
251  return false;
252 }
253 
255 bool Geant4Sensitive::processFastSim(const Geant4FastSimSpot* /* spot */, G4TouchableHistory* /* history */) {
256  except("The sensitive action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
257  return false;
258 }
259 
261 void Geant4Sensitive::clear(G4HCofThisEvent* /* HCE */) {
262 }
263 
265 void Geant4Sensitive::mark(const G4Track* track) const {
267  if ( truth ) truth->mark(track);
268 }
269 
271 void Geant4Sensitive::mark(const G4Step* step) const {
273  if ( truth ) truth->mark(step);
274 }
275 
277 long long int Geant4Sensitive::volumeID(const G4Step* step) {
278  VolumeID volID = m_detector.id();
279  if( this->useVolumeManager() ) {
280  Geant4StepHandler stepH(step);
282  volID = volMgr.volumeID(stepH.preTouchable());
283  if( this->m_debugVolumeID ) {
284  _print_volumeid(this, volID);
285  }
286  }
287  return volID;
288 }
289 
291 long long int Geant4Sensitive::volumeID(const G4VTouchable* touchable) {
292  VolumeID volID = m_detector.id();
293  if( this->useVolumeManager() ) {
295  volID= volMgr.volumeID(touchable);
296  if( this->m_debugVolumeID ) {
297  _print_volumeid(this, volID);
298  }
299  }
300  return volID;
301 }
302 
304 long long int Geant4Sensitive::cellID(const G4Step* step) {
305  VolumeID volID = m_detector.id();
306  if( this->useVolumeManager() ) {
307  Geant4StepHandler h(step);
309  bool UsePostStepOnly = G4OpticalParameters::Instance() &&
310  G4OpticalParameters::Instance()->GetBoundaryInvokeSD() &&
311  (step->GetTrack()->GetDefinition() == G4OpticalPhoton::Definition());
312 
313  volID = volMgr.volumeID(UsePostStepOnly? h.postTouchable() : h.preTouchable());
314  if ( m_segmentation.isValid() ) {
315  std::exception_ptr eptr;
316  G4ThreeVector global = UsePostStepOnly? h.postPosG4() : 0.5 * (h.prePosG4()+h.postPosG4());
317  G4ThreeVector local = UsePostStepOnly? h.postTouchable()->GetHistory()->GetTopTransform().TransformPoint(global) :
318  h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global);
319  Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
320  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
321  try {
322  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
323  if( this->m_debugVolumeID ) {
324  _print_volumeid(this, cID);
325  }
326  return cID;
327  }
328  catch(const std::exception& e) {
329  eptr = std::current_exception();
330  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
331  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
332  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
333  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
334  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
335  error("....... Pre-step: %s SD: %s", h.volName(h.pre), h.sdName(h.pre).c_str());
336  if ( h.post )
337  error("....... Post-step: %s SD: %s", h.volName(h.post), h.sdName(h.post).c_str());
338  std::rethrow_exception(std::move(eptr));
339  }
340  }
341  else if( this->m_debugVolumeID ) {
342  _print_volumeid(this, volID);
343  }
344  }
345  return volID;
346 }
347 
349 long long int Geant4Sensitive::cellID(const G4VTouchable* touchable, const G4ThreeVector& global) {
350  VolumeID volID = m_detector.id();
351  if( this->useVolumeManager() ) {
353 
354  volID = volMgr.volumeID(touchable);
355  if ( m_segmentation.isValid() ) {
356  std::exception_ptr eptr;
357  G4ThreeVector local = touchable->GetHistory()->GetTopTransform().TransformPoint(global);
358  Position loc (local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
359  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
360  try {
361  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
362  if( this->m_debugVolumeID ) {
363  _print_volumeid(this, cID);
364  }
365  return cID;
366  }
367  catch(const std::exception& e) {
368  auto* pvol = touchable->GetVolume();
369  auto* vol = pvol->GetLogicalVolume();
370  auto* sd = vol->GetSensitiveDetector();
371  eptr = std::current_exception();
372  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
373  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
374  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
375  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
376  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
377  error("....... Touchable: %s SD: %s", vol->GetName().c_str(), sd ? sd->GetName().c_str() : "???");
378  std::rethrow_exception(std::move(eptr));
379  }
380  }
381  else if( this->m_debugVolumeID ) {
382  _print_volumeid(this, volID);
383  }
384  }
385  return volID;
386 }
387 
390  : Geant4Action(ctxt, nam), m_hce(0), m_detector(0)
391 {
392  m_needsControl = true;
393  context()->sensitiveActions().insert(name(), this);
397  declareProperty("SensitiveType", m_sensitiveType);
399 }
400 
405  m_filters.clear();
406  m_actors.clear();
408 }
409 
412  m_context = ctxt;
413  m_actors.updateContext(ctxt);
414  m_filters.updateContext(ctxt);
415 }
416 
419  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
420  adopt(filter);
421 }
422 
425  if (sensitive) {
426  sensitive->addRef();
427  m_actors.add(sensitive);
428  return;
429  }
430  except("Attempt to add invalid sensitive actor!");
431 }
432 
435  if (filter) {
436  filter->addRef();
437  m_filters.add(filter);
438  return;
439  }
440  except("Attempt to add invalid sensitive filter!");
441 }
442 
444 std::size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& collection_name, create_t func) {
445  m_collections.emplace_back(collection_name, make_pair(owner,func));
446  return m_collections.size() - 1;
447 }
448 
450 std::size_t Geant4SensDetActionSequence::Geant4SensDetActionSequence::defineCollections(Geant4ActionSD* sens_det) {
451  std::size_t count = 0;
452  m_detector = sens_det;
453  m_actors(&Geant4Sensitive::setDetector, sens_det);
455  for (HitCollections::const_iterator i = m_collections.begin(); i != m_collections.end(); ++i) {
456  sens_det->defineCollection((*i).first);
457  ++count;
458  }
459  return count;
460 }
461 
463 const std::string& Geant4SensDetActionSequence::hitCollectionName(std::size_t which) const {
464  if (which < m_collections.size()) {
465  return m_collections[which].first;
466  }
467  static std::string blank = "";
468  except("The collection name index for subdetector %s is out of range!", c_name());
469  return blank;
470 }
471 
474  if (which < m_collections.size()) {
475  int hc_id = m_detector->GetCollectionID(which);
476  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(hc_id);
477  if (c)
478  return c;
479  except("The collection index for subdetector %s is wrong!", c_name());
480  }
481  except("The collection name index for subdetector %s is out of range!", c_name());
482  return 0;
483 }
484 
487  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(id);
488  if (c)
489  return c;
490  except("The collection index for subdetector %s is wrong!", c_name());
491  return 0;
492 }
493 
495 bool Geant4SensDetActionSequence::accept(const G4Step* step) const {
496  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
497  bool result = m_filters.filter(filter, step);
498  return result;
499 }
500 
503  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
504  bool result = m_filters.filter(filter, spot);
505  return result;
506 }
507 
509 bool Geant4SensDetActionSequence::process(const G4Step* step, G4TouchableHistory* history) {
510  bool result = false;
511  for (Geant4Sensitive* sensitive : m_actors) {
512  if ( sensitive->accept(step) )
513  result |= sensitive->process(step, history);
514  }
515  m_process(step, history);
516  return result;
517 }
518 
520 bool Geant4SensDetActionSequence::processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) {
521  bool result = false;
522  for (Geant4Sensitive* sensitive : m_actors) {
523  if ( sensitive->accept(spot) )
524  result |= sensitive->processFastSim(spot, history);
525  }
526  m_process(spot, history);
527  return result;
528 }
529 
534 void Geant4SensDetActionSequence::begin(G4HCofThisEvent* hce) {
535  m_hce = hce;
536  for (std::size_t count = 0; count < m_collections.size(); ++count) {
537  const HitCollection& cr = m_collections[count];
538  Geant4HitCollection* col = (*cr.second.second)(name(), cr.first, cr.second.first);
539  int id = m_detector->GetCollectionID(count);
540  m_hce->AddHitsCollection(id, col);
541  }
543  m_begin (m_hce);
544 }
545 
547 void Geant4SensDetActionSequence::end(G4HCofThisEvent* hce) {
548  m_end(hce);
550  // G4HCofThisEvent must be available until end-event. m_hce = 0;
551 }
552 
554 
560  m_clear (m_hce);
562 }
563 
566  detail::releaseObjects(m_sequences);
567  m_sequences.clear();
568 }
569 
572  std::string n = "SD_Seq_" + nam;
573  Members::const_iterator i = m_sequences.find(n);
574  if (i != m_sequences.end())
575  return (*i).second;
576  except("Attempt to access undefined SensDetActionSequence: %s ", nam.c_str());
577  return nullptr;
578 }
579 
582  std::string nam = "SD_Seq_" + name;
583  Members::const_iterator i = m_sequences.find(nam);
584  if (i != m_sequences.end())
585  return (*i).second;
586  return 0;
587 }
588 
590 void Geant4SensDetSequences::insert(const std::string& name, Geant4SensDetActionSequence* seq) {
591  if (seq) {
592  std::string nam = "SD_Seq_" + name;
593  seq->addRef();
594  m_sequences[nam] = seq;
595  return;
596  }
597  except("Attempt to add invalid sensitive sequence with name:%s", name.c_str());
598 }
599 
602  m_sequences.clear();
603 }
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:158
dd4hep::sim::Geant4Sensitive::defineCollections
virtual void defineCollections()
Define collections created by this sensitivie action object.
Definition: Geant4SensDetAction.cpp:238
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:590
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:520
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:96
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:203
Geant4VolumeManager.h
dd4hep::sim::Geant4Sensitive::clear
virtual void clear(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:261
dd4hep::sim::Geant4SensDetActionSequence::clear
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:559
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:601
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::IDDescriptor
Class implementing the ID encoding of the detector response.
Definition: IDDescriptor.h:36
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:250
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:123
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:424
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:107
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:277
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:228
dd4hep::sim::Geant4Sensitive::~Geant4Sensitive
virtual ~Geant4Sensitive()
Standard destructor.
Definition: Geant4SensDetAction.cpp:140
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:389
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:168
dd4hep::sim::Geant4VolumeManager::volumeID
VolumeID volumeID(const G4VTouchable *touchable) const
Access CELLID by Geant4 touchable object.
Definition: Geant4VolumeManager.cpp:342
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:565
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:581
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:265
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:198
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:184
dd4hep::sim::Geant4SensDetActionSequence::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:547
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:147
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:473
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:242
dd4hep::sim::Geant4SensDetActionSequence::accept
bool accept(const G4Step *step) const
Callback before hit processing starts. Invoke all filters.
Definition: Geant4SensDetAction.cpp:495
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:402
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:411
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:101
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:463
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:486
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:304
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:418
dd4hep::sim::Geant4Sensitive::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:152
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:255
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:223
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:444
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::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:174
dd4hep::sim::Geant4SensDetActionSequence::begin
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the beginning of each event.
Definition: Geant4SensDetAction.cpp:534
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:571
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:90
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:233
dd4hep::sim::Geant4Sensitive::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:246
dd4hep::sim::Geant4Sensitive::sequence
Geant4SensDetActionSequence & sequence() const
Access to the hosting sequence.
Definition: Geant4SensDetAction.cpp:213
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:509
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:112
dd4hep::sim::Geant4Sensitive::detectorDescription
Detector & detectorDescription() const
Access the detector description object.
Definition: Geant4SensDetAction.cpp:218