DD4hep  1.38.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::processRejected(const G4Step* /* step */, G4TouchableHistory* /* history */) {
275  return false;
276 }
277 
279 bool Geant4Sensitive::processFastSim(const Geant4FastSimSpot* /* spot */, G4TouchableHistory* /* history */) {
280  except("The sensitive action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
281  return false;
282 }
283 
285 void Geant4Sensitive::clear(G4HCofThisEvent* /* HCE */) {
286 }
287 
289 void Geant4Sensitive::mark(const G4Track* track) const {
291  if ( truth ) truth->mark(track);
292 }
293 
295 void Geant4Sensitive::mark(const G4Step* step) const {
297  if ( truth ) truth->mark(step);
298 }
299 
301 long long int Geant4Sensitive::volumeID(const G4Step* step) {
302  VolumeID volID = m_detector.id();
303  if( this->useVolumeManager() ) {
304  Geant4StepHandler stepH(step);
306  volID = volMgr.volumeID(stepH.preTouchable());
307  if( this->m_debugVolumeID ) {
308  _print_volumeid(this, "Volume ID", volID, step->GetTotalEnergyDeposit());
309  }
310  }
311  return volID;
312 }
313 
315 long long int Geant4Sensitive::volumeID(const G4VTouchable* touchable) {
316  VolumeID volID = m_detector.id();
317  if( this->useVolumeManager() ) {
319  volID= volMgr.volumeID(touchable);
320  if( this->m_debugVolumeID ) {
321  _print_volumeid(this, "Volume ID", volID);
322  }
323  }
324  return volID;
325 }
326 
328 long long int Geant4Sensitive::cellID(const G4Step* step) {
329  VolumeID volID = m_detector.id();
330  if( this->useVolumeManager() ) {
331  Geant4StepHandler h(step);
333  bool UsePostStepOnly = G4OpticalParameters::Instance() &&
334  G4OpticalParameters::Instance()->GetBoundaryInvokeSD() &&
335  (step->GetTrack()->GetDefinition() == G4OpticalPhoton::Definition());
336 
337  volID = volMgr.volumeID(UsePostStepOnly? h.postTouchable() : h.preTouchable());
338  if ( m_segmentation.isValid() ) {
339  std::exception_ptr eptr;
340  G4ThreeVector global = UsePostStepOnly? h.postPosG4() : 0.5 * (h.prePosG4()+h.postPosG4());
341  G4ThreeVector local = UsePostStepOnly? h.postTouchable()->GetHistory()->GetTopTransform().TransformPoint(global) :
342  h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global);
343  Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
344  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
345  try {
346  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
347  if( this->m_debugVolumeID ) {
348  _print_volumeid(this, "Cell ID", cID, step->GetTotalEnergyDeposit());
349  }
350  return cID;
351  }
352  catch(const std::exception& e) {
353  eptr = std::current_exception();
354  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
355  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
356  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
357  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
358  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
359  error("....... Pre-step: %s SD: %s", h.volName(h.pre), h.sdName(h.pre).c_str());
360  if ( h.post )
361  error("....... Post-step: %s SD: %s", h.volName(h.post), h.sdName(h.post).c_str());
362  std::rethrow_exception(std::move(eptr));
363  }
364  }
365  else if( this->m_debugVolumeID ) {
366  _print_volumeid(this, "Volume ID", volID, step->GetTotalEnergyDeposit());
367  }
368  }
369  return volID;
370 }
371 
373 long long int Geant4Sensitive::cellID(const G4VTouchable* touchable, const G4ThreeVector& global) {
374  VolumeID volID = m_detector.id();
375  if( this->useVolumeManager() ) {
377 
378  volID = volMgr.volumeID(touchable);
379  if ( m_segmentation.isValid() ) {
380  std::exception_ptr eptr;
381  G4ThreeVector local = touchable->GetHistory()->GetTopTransform().TransformPoint(global);
382  Position loc (local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
383  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
384  try {
385  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
386  if( this->m_debugVolumeID ) {
387  _print_volumeid(this, "Cell ID", cID);
388  }
389  return cID;
390  }
391  catch(const std::exception& e) {
392  auto* pvol = touchable->GetVolume();
393  auto* vol = pvol->GetLogicalVolume();
394  auto* sd = vol->GetSensitiveDetector();
395  eptr = std::current_exception();
396  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
397  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
398  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
399  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
400  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
401  error("....... Touchable: %s SD: %s", vol->GetName().c_str(), sd ? sd->GetName().c_str() : "???");
402  std::rethrow_exception(std::move(eptr));
403  }
404  }
405  else if( this->m_debugVolumeID ) {
406  _print_volumeid(this, "Volume ID", volID);
407  }
408  }
409  return volID;
410 }
411 
414  : Geant4Action(ctxt, nam), m_hce(0), m_detector(0)
415 {
416  m_needsControl = true;
417  context()->sensitiveActions().insert(name(), this);
421  declareProperty("SensitiveType", m_sensitiveType);
423 }
424 
429  m_filters.clear();
430  m_actors.clear();
432 }
433 
436  m_context = ctxt;
437  m_actors.updateContext(ctxt);
438  m_filters.updateContext(ctxt);
439 }
440 
443  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
444  adopt(filter);
445 }
446 
449  if (sensitive) {
450  sensitive->addRef();
451  m_actors.add(sensitive);
452  return;
453  }
454  except("Attempt to add invalid sensitive actor!");
455 }
456 
459  if (filter) {
460  filter->addRef();
461  m_filters.add(filter);
462  return;
463  }
464  except("Attempt to add invalid sensitive filter!");
465 }
466 
468 std::size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& collection_name, create_t func) {
469  m_collections.emplace_back(collection_name, make_pair(owner,func));
470  return m_collections.size() - 1;
471 }
472 
474 std::size_t Geant4SensDetActionSequence::Geant4SensDetActionSequence::defineCollections(Geant4ActionSD* sens_det) {
475  std::size_t count = 0;
476  m_detector = sens_det;
477  m_actors(&Geant4Sensitive::setDetector, sens_det);
479  for (HitCollections::const_iterator i = m_collections.begin(); i != m_collections.end(); ++i) {
480  sens_det->defineCollection((*i).first);
481  ++count;
482  }
483  return count;
484 }
485 
487 const std::string& Geant4SensDetActionSequence::hitCollectionName(std::size_t which) const {
488  if (which < m_collections.size()) {
489  return m_collections[which].first;
490  }
491  static std::string blank = "";
492  except("The collection name index for subdetector %s is out of range!", c_name());
493  return blank;
494 }
495 
498  if (which < m_collections.size()) {
499  int hc_id = m_detector->GetCollectionID(which);
500  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(hc_id);
501  if (c)
502  return c;
503  except("The collection index for subdetector %s is wrong!", c_name());
504  }
505  except("The collection name index for subdetector %s is out of range!", c_name());
506  return 0;
507 }
508 
511  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(id);
512  if (c)
513  return c;
514  except("The collection index for subdetector %s is wrong!", c_name());
515  return 0;
516 }
517 
519 bool Geant4SensDetActionSequence::accept(const G4Step* step) const {
520  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
521  bool result = m_filters.filter(filter, step);
522  return result;
523 }
524 
527  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
528  bool result = m_filters.filter(filter, spot);
529  return result;
530 }
531 
533 bool Geant4SensDetActionSequence::process(const G4Step* step, G4TouchableHistory* history) {
534  bool result = false;
535  for (Geant4Sensitive* sensitive : m_actors) {
536  if ( sensitive->accept(step) )
537  result |= sensitive->process(step, history);
538  else
539  sensitive->processRejected(step, history);
540  }
541  m_process(step, history);
542  return result;
543 }
544 
546 bool Geant4SensDetActionSequence::processRejected(const G4Step* step, G4TouchableHistory* history) {
547  bool result = false;
548  for (Geant4Sensitive* sensitive : m_actors)
549  result |= sensitive->processRejected(step, history);
550  return result;
551 }
552 
554 bool Geant4SensDetActionSequence::processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) {
555  bool result = false;
556  for (Geant4Sensitive* sensitive : m_actors) {
557  if ( sensitive->accept(spot) )
558  result |= sensitive->processFastSim(spot, history);
559  }
560  m_process(spot, history);
561  return result;
562 }
563 
568 void Geant4SensDetActionSequence::begin(G4HCofThisEvent* hce) {
569  m_hce = hce;
570  for (std::size_t count = 0; count < m_collections.size(); ++count) {
571  const HitCollection& cr = m_collections[count];
572  Geant4HitCollection* col = (*cr.second.second)(name(), cr.first, cr.second.first);
573  int id = m_detector->GetCollectionID(count);
574  m_hce->AddHitsCollection(id, col);
575  }
577  m_begin (m_hce);
578 }
579 
581 void Geant4SensDetActionSequence::end(G4HCofThisEvent* hce) {
582  m_end(hce);
584  // G4HCofThisEvent must be available until end-event. m_hce = 0;
585 }
586 
588 
594  m_clear (m_hce);
596 }
597 
600  detail::releaseObjects(m_sequences);
601  m_sequences.clear();
602 }
603 
606  std::string n = "SD_Seq_" + nam;
607  Members::const_iterator i = m_sequences.find(n);
608  if (i != m_sequences.end())
609  return (*i).second;
610  except("Attempt to access undefined SensDetActionSequence: %s ", nam.c_str());
611  return nullptr;
612 }
613 
616  std::string nam = "SD_Seq_" + name;
617  Members::const_iterator i = m_sequences.find(nam);
618  if (i != m_sequences.end())
619  return (*i).second;
620  return 0;
621 }
622 
624 void Geant4SensDetSequences::insert(const std::string& name, Geant4SensDetActionSequence* seq) {
625  if (seq) {
626  std::string nam = "SD_Seq_" + name;
627  seq->addRef();
628  m_sequences[nam] = seq;
629  return;
630  }
631  except("Attempt to add invalid sensitive sequence with name:%s", name.c_str());
632 }
633 
636  m_sequences.clear();
637 }
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:363
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:624
Geant4Mapping.h
dd4hep::sim::Geant4SensDetActionSequence::m_end
CallbackSequence m_end
Callback sequence for event finalization action.
Definition: Geant4SensDetAction.h:350
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:554
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:356
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:285
dd4hep::sim::Geant4SensDetActionSequence::clear
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:593
dd4hep::sim::Geant4SensDetSequences::m_sequences
Members m_sequences
Definition: Geant4SensDetAction.h:494
dd4hep::sim::Geant4SensDetSequences::clear
void clear()
Clear the sequence list.
Definition: Geant4SensDetAction.cpp:635
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::Geant4SensDetActionSequence::processRejected
virtual bool processRejected(const G4Step *step, G4TouchableHistory *history)
Callback for steps rejected by the sequence's filters: forwarded to processRejected() of every actor.
Definition: Geant4SensDetAction.cpp:546
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:448
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:301
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:348
dd4hep::sim::Geant4Sensitive::processRejected
virtual bool processRejected(const G4Step *step, G4TouchableHistory *history)
Callback for steps inside the sensitive volume that the filters rejected, called instead of process()...
Definition: Geant4SensDetAction.cpp:274
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:413
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:402
dd4hep::sim::Geant4SensDetActionSequence::m_process
CallbackSequence m_process
Callback sequence for step processing.
Definition: Geant4SensDetAction.h:352
dd4hep::sim::Geant4SensDetSequences::~Geant4SensDetSequences
virtual ~Geant4SensDetSequences()
Default destructor.
Definition: Geant4SensDetAction.cpp:599
dd4hep::sim::Geant4SensDetActionSequence::m_filters
Actors< Geant4Filter > m_filters
The list of sensitive detector filter objects.
Definition: Geant4SensDetAction.h:358
dd4hep::sim::Geant4SensDetSequences::find
Geant4SensDetActionSequence * find(const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:615
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:289
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:346
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:581
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:365
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:497
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:519
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:426
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:435
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:367
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:361
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:487
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:510
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:341
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:338
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:328
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:442
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:279
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:468
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:89
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:568
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:605
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:354
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:533
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