DD4hep  1.34.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 #if 0
46 namespace {
47  Geant4ActionSD* _getSensitiveDetector(const std::string& name) {
48  G4SDManager* mgr = G4SDManager::GetSDMpointer();
49  G4VSensitiveDetector* sd = mgr->FindSensitiveDetector(name);
50  if (0 == sd) {
51  dd4hep::except("Geant4Sensitive", "DDG4: You requested to configure actions "
52  "for the sensitive detector %s,\nDDG4: which is not known to Geant4. "
53  "Are you sure you already converted the geometry?", name.c_str());
54  }
55  Geant4ActionSD* action_sd = dynamic_cast<Geant4ActionSD*>(sd);
56  if (0 == action_sd) {
57  throw dd4hep::except("Geant4Sensitive", "DDG4: You may only configure actions "
58  "for sensitive detectors of type Geant4ActionSD.\n"
59  "DDG4: The sensitive detector of %s is of type %s, which is incompatible.", name.c_str(),
60  typeName(typeid(*sd)).c_str());
61  }
62  return action_sd;
63  }
64 }
65 #endif
66 
68 Geant4ActionSD::Geant4ActionSD(const std::string& nam)
69  : Geant4Action(0, nam) {
71 }
72 
76 }
77 
79 Geant4Filter::Geant4Filter(Geant4Context* ctxt, const std::string& nam)
80  : Geant4Action(ctxt, nam) {
82 }
83 
87 }
88 
90 bool Geant4Filter::operator()(const G4Step*) const {
91  return true;
92 }
93 
96  except("The filter action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
97  return false;
98 }
99 
101 Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& det_ref)
102  : Geant4Action(ctxt, nam), m_detDesc(det_ref), m_detector(det)
103 {
105  if (!det.isValid()) {
106  except("DDG4: Detector element for %s is invalid.", nam.c_str());
107  }
108  declareProperty("UseVolumeManager", m_useVolumeManager = true);
109  declareProperty("HitCreationMode", m_hitCreationMode = SIMPLE_MODE);
114 }
115 
119  m_filters.clear();
121 }
122 
124 int Geant4Sensitive::id() const {
125  return this->m_detector.id();
126 }
127 
130  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
131  adopt(filter);
132 }
133 
136  if (filter) {
137  filter->addRef();
138  m_filters.add(filter);
139  return;
140  }
141  except("Attempt to add invalid sensitive filter!");
142 }
143 
146  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
147  adopt_front(filter);
148 }
149 
152  if (filter) {
153  filter->addRef();
154  m_filters.add_front(filter);
155  return;
156  }
157  except("Attempt to add invalid sensitive filter!");
158 }
159 
161 bool Geant4Sensitive::accept(const G4Step* step) const {
162  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
163  bool result = m_filters.filter(filter, step);
164  return result;
165 }
166 
169  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
170  bool result = m_filters.filter(filter, spot);
171  return result;
172 }
173 
176  m_sensitiveDetector = sens_det;
177 }
178 
182  return *m_sensitiveDetector;
183  //m_sensitiveDetector = _getSensitiveDetector(m_detector.name());
184  //if ( m_sensitiveDetector ) return *m_sensitiveDetector;
185  except("DDG4: The sensitive detector for action %s was not properly configured.", name().c_str());
186  throw std::runtime_error("Geant4Sensitive::detector");
187 }
188 
191  return *m_sequence;
192 }
193 
196  return m_detDesc;
197 }
198 
200 const std::string& Geant4Sensitive::hitCollectionName(std::size_t which) const {
201  return sequence().hitCollectionName(which);
202 }
203 
206  return sequence().collection(which);
207 }
208 
211  return sequence().collectionByID(id);
212 }
213 
216 }
217 
219 void Geant4Sensitive::begin(G4HCofThisEvent* /* HCE */) {
220 }
221 
223 void Geant4Sensitive::end(G4HCofThisEvent* /* HCE */) {
224 }
225 
227 bool Geant4Sensitive::process(const G4Step* /* step */, G4TouchableHistory* /* history */) {
228  return false;
229 }
230 
232 bool Geant4Sensitive::processFastSim(const Geant4FastSimSpot* /* spot */, G4TouchableHistory* /* history */) {
233  except("The sensitive action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
234  return false;
235 }
236 
238 void Geant4Sensitive::clear(G4HCofThisEvent* /* HCE */) {
239 }
240 
242 void Geant4Sensitive::mark(const G4Track* track) const {
244  if ( truth ) truth->mark(track);
245 }
246 
248 void Geant4Sensitive::mark(const G4Step* step) const {
250  if ( truth ) truth->mark(step);
251 }
252 
254 long long int Geant4Sensitive::volumeID(const G4Step* step) {
255  VolumeID volID = m_detector.id();
256  if( this->useVolumeManager() ) {
257  Geant4StepHandler stepH(step);
259  volID = volMgr.volumeID(stepH.preTouchable());
260  }
261  return volID;
262 }
263 
265 long long int Geant4Sensitive::volumeID(const G4VTouchable* touchable) {
266  VolumeID volID = m_detector.id();
267  if( this->useVolumeManager() ) {
269  volID= volMgr.volumeID(touchable);
270  }
271  return volID;
272 }
273 
275 long long int Geant4Sensitive::cellID(const G4Step* step) {
276  VolumeID volID = m_detector.id();
277  if( this->useVolumeManager() ) {
278  Geant4StepHandler h(step);
280  bool UsePostStepOnly = G4OpticalParameters::Instance() &&
281  G4OpticalParameters::Instance()->GetBoundaryInvokeSD() &&
282  (step->GetTrack()->GetDefinition() == G4OpticalPhoton::Definition());
283 
284  volID = volMgr.volumeID(UsePostStepOnly? h.postTouchable() : h.preTouchable());
285  if ( m_segmentation.isValid() ) {
286  std::exception_ptr eptr;
287  G4ThreeVector global = UsePostStepOnly? h.postPosG4() : 0.5 * (h.prePosG4()+h.postPosG4());
288  G4ThreeVector local = UsePostStepOnly? h.postTouchable()->GetHistory()->GetTopTransform().TransformPoint(global) :
289  h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global);
290  Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
291  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
292  try {
293  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
294  return cID;
295  }
296  catch(const std::exception& e) {
297  eptr = std::current_exception();
298  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
299  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
300  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
301  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
302  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
303  error("....... Pre-step: %s SD: %s", h.volName(h.pre), h.sdName(h.pre).c_str());
304  if ( h.post )
305  error("....... Post-step: %s SD: %s", h.volName(h.post), h.sdName(h.post).c_str());
306  std::rethrow_exception(std::move(eptr));
307  }
308  }
309  }
310  return volID;
311 }
312 
314 long long int Geant4Sensitive::cellID(const G4VTouchable* touchable, const G4ThreeVector& global) {
315  VolumeID volID = m_detector.id();
316  if( this->useVolumeManager() ) {
318 
319  volID = volMgr.volumeID(touchable);
320  if ( m_segmentation.isValid() ) {
321  std::exception_ptr eptr;
322  G4ThreeVector local = touchable->GetHistory()->GetTopTransform().TransformPoint(global);
323  Position loc (local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
324  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
325  try {
326  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
327  return cID;
328  }
329  catch(const std::exception& e) {
330  auto* pvol = touchable->GetVolume();
331  auto* vol = pvol->GetLogicalVolume();
332  auto* sd = vol->GetSensitiveDetector();
333  eptr = std::current_exception();
334  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
335  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
336  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
337  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
338  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
339  error("....... Touchable: %s SD: %s", vol->GetName().c_str(), sd ? sd->GetName().c_str() : "???");
340  std::rethrow_exception(std::move(eptr));
341  }
342  }
343  }
344  return volID;
345 }
346 
349  : Geant4Action(ctxt, nam), m_hce(0), m_detector(0)
350 {
351  m_needsControl = true;
352  context()->sensitiveActions().insert(name(), this);
357 }
358 
363  m_filters.clear();
364  m_actors.clear();
366 }
367 
370  m_context = ctxt;
371  m_actors.updateContext(ctxt);
372  m_filters.updateContext(ctxt);
373 }
374 
377  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
378  adopt(filter);
379 }
380 
383  if (sensitive) {
384  sensitive->addRef();
385  m_actors.add(sensitive);
386  return;
387  }
388  except("Attempt to add invalid sensitive actor!");
389 }
390 
393  if (filter) {
394  filter->addRef();
395  m_filters.add(filter);
396  return;
397  }
398  except("Attempt to add invalid sensitive filter!");
399 }
400 
402 std::size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& collection_name, create_t func) {
403  m_collections.emplace_back(collection_name, make_pair(owner,func));
404  return m_collections.size() - 1;
405 }
406 
408 std::size_t Geant4SensDetActionSequence::Geant4SensDetActionSequence::defineCollections(Geant4ActionSD* sens_det) {
409  std::size_t count = 0;
410  m_detector = sens_det;
411  m_actors(&Geant4Sensitive::setDetector, sens_det);
413  for (HitCollections::const_iterator i = m_collections.begin(); i != m_collections.end(); ++i) {
414  sens_det->defineCollection((*i).first);
415  ++count;
416  }
417  return count;
418 }
419 
421 const std::string& Geant4SensDetActionSequence::hitCollectionName(std::size_t which) const {
422  if (which < m_collections.size()) {
423  return m_collections[which].first;
424  }
425  static std::string blank = "";
426  except("The collection name index for subdetector %s is out of range!", c_name());
427  return blank;
428 }
429 
432  if (which < m_collections.size()) {
433  int hc_id = m_detector->GetCollectionID(which);
434  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(hc_id);
435  if (c)
436  return c;
437  except("The collection index for subdetector %s is wrong!", c_name());
438  }
439  except("The collection name index for subdetector %s is out of range!", c_name());
440  return 0;
441 }
442 
445  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(id);
446  if (c)
447  return c;
448  except("The collection index for subdetector %s is wrong!", c_name());
449  return 0;
450 }
451 
453 bool Geant4SensDetActionSequence::accept(const G4Step* step) const {
454  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
455  bool result = m_filters.filter(filter, step);
456  return result;
457 }
458 
461  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
462  bool result = m_filters.filter(filter, spot);
463  return result;
464 }
465 
467 bool Geant4SensDetActionSequence::process(const G4Step* step, G4TouchableHistory* history) {
468  bool result = false;
469  for (Geant4Sensitive* sensitive : m_actors) {
470  if ( sensitive->accept(step) )
471  result |= sensitive->process(step, history);
472  }
473  m_process(step, history);
474  return result;
475 }
476 
478 bool Geant4SensDetActionSequence::processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) {
479  bool result = false;
480  for (Geant4Sensitive* sensitive : m_actors) {
481  if ( sensitive->accept(spot) )
482  result |= sensitive->processFastSim(spot, history);
483  }
484  m_process(spot, history);
485  return result;
486 }
487 
492 void Geant4SensDetActionSequence::begin(G4HCofThisEvent* hce) {
493  m_hce = hce;
494  for (std::size_t count = 0; count < m_collections.size(); ++count) {
495  const HitCollection& cr = m_collections[count];
496  Geant4HitCollection* col = (*cr.second.second)(name(), cr.first, cr.second.first);
497  int id = m_detector->GetCollectionID(count);
498  m_hce->AddHitsCollection(id, col);
499  }
501  m_begin (m_hce);
502 }
503 
505 void Geant4SensDetActionSequence::end(G4HCofThisEvent* hce) {
506  m_end(hce);
508  // G4HCofThisEvent must be available until end-event. m_hce = 0;
509 }
510 
512 
518  m_clear (m_hce);
520 }
521 
524  detail::releaseObjects(m_sequences);
525  m_sequences.clear();
526 }
527 
530  std::string n = "SD_Seq_" + nam;
531  Members::const_iterator i = m_sequences.find(n);
532  if (i != m_sequences.end())
533  return (*i).second;
534  except("Attempt to access undefined SensDetActionSequence: %s ", nam.c_str());
535  return nullptr;
536 }
537 
540  std::string nam = "SD_Seq_" + name;
541  Members::const_iterator i = m_sequences.find(nam);
542  if (i != m_sequences.end())
543  return (*i).second;
544  return 0;
545 }
546 
548 void Geant4SensDetSequences::insert(const std::string& name, Geant4SensDetActionSequence* seq) {
549  if (seq) {
550  std::string nam = "SD_Seq_" + name;
551  seq->addRef();
552  m_sequences[nam] = seq;
553  return;
554  }
555  except("Attempt to add invalid sensitive sequence with name:%s", name.c_str());
556 }
557 
560  m_sequences.clear();
561 }
dd4hep::sim::Geant4Sensitive::m_sequence
Geant4SensDetActionSequence * m_sequence
Reference to the containing action sequence.
Definition: Geant4SensDetAction.h:133
Geant4MonteCarloTruth.h
dd4hep::sim::Geant4SensDetActionSequence::m_sensitive
SensitiveDetector m_sensitive
Reference to the sensitive detector element.
Definition: Geant4SensDetAction.h:353
dd4hep::sim::Geant4Sensitive::m_useVolumeManager
bool m_useVolumeManager
Property: Use the volume manager to access CellID and VolumeID.
Definition: Geant4SensDetAction.h:139
dd4hep::sim::Geant4Sensitive::adopt
void adopt(Geant4Filter *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:135
dd4hep::sim::Geant4Sensitive::defineCollections
virtual void defineCollections()
Define collections created by this sensitivie action object.
Definition: Geant4SensDetAction.cpp:215
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:548
Geant4Mapping.h
dd4hep::sim::Geant4SensDetActionSequence::m_end
CallbackSequence m_end
Callback sequence for event finalization action.
Definition: Geant4SensDetAction.h:340
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:478
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:346
dd4hep::sim::Geant4ActionSD::~Geant4ActionSD
virtual ~Geant4ActionSD()
Default destructor.
Definition: Geant4SensDetAction.cpp:74
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:157
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:180
Geant4VolumeManager.h
dd4hep::sim::Geant4Sensitive::clear
virtual void clear(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:238
dd4hep::sim::Geant4SensDetActionSequence::clear
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:517
dd4hep::sim::Geant4SensDetSequences::m_sequences
Members m_sequences
Definition: Geant4SensDetAction.h:481
dd4hep::sim::Geant4SensDetSequences::clear
void clear()
Clear the sequence list.
Definition: Geant4SensDetAction.cpp:559
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:227
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:101
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:382
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:35
dd4hep::sim::Geant4Filter::~Geant4Filter
virtual ~Geant4Filter()
Standard destructor.
Definition: Geant4SensDetAction.cpp:85
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:254
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:205
dd4hep::sim::Geant4Sensitive::~Geant4Sensitive
virtual ~Geant4Sensitive()
Standard destructor.
Definition: Geant4SensDetAction.cpp:117
dd4hep::sim::Geant4SensDetActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for event initialization action.
Definition: Geant4SensDetAction.h:338
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:124
dd4hep::sim::Geant4SensDetActionSequence::Geant4SensDetActionSequence
Geant4SensDetActionSequence(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SensDetAction.cpp:348
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:145
dd4hep::sim::Geant4VolumeManager::volumeID
VolumeID volumeID(const G4VTouchable *touchable) const
Access CELLID by Geant4 touchable object.
Definition: Geant4VolumeManager.cpp:327
dd4hep::sim::Geant4SensDetActionSequence::m_process
CallbackSequence m_process
Callback sequence for step processing.
Definition: Geant4SensDetAction.h:342
dd4hep::sim::Geant4SensDetSequences::~Geant4SensDetSequences
virtual ~Geant4SensDetSequences()
Default destructor.
Definition: Geant4SensDetAction.cpp:523
dd4hep::sim::Geant4SensDetActionSequence::m_filters
Actors< Geant4Filter > m_filters
The list of sensitive detector filter objects.
Definition: Geant4SensDetAction.h:348
dd4hep::sim::Geant4SensDetSequences::find
Geant4SensDetActionSequence * find(const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:539
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:242
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:153
dd4hep::sim::Geant4Sensitive::setDetector
void setDetector(Geant4ActionSD *sens_det)
Access to the sensitive detector object.
Definition: Geant4SensDetAction.cpp:175
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:336
dd4hep::sim::Geant4Sensitive::m_detDesc
Detector & m_detDesc
Reference to the detector description object.
Definition: Geant4SensDetAction.h:146
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:161
dd4hep::sim::Geant4SensDetActionSequence::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:505
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
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:124
dd4hep::sim::Geant4SensDetActionSequence::m_detector
Geant4ActionSD * m_detector
Reference to G4 sensitive detector.
Definition: Geant4SensDetAction.h:355
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:431
dd4hep::sim::Geant4Sensitive::m_hitCreationMode
int m_hitCreationMode
Property: Hit creation mode. Maybe one of the enum HitCreationFlags.
Definition: Geant4SensDetAction.h:137
dd4hep::sim::Geant4Sensitive::begin
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the beginning of each event.
Definition: Geant4SensDetAction.cpp:219
dd4hep::sim::Geant4SensDetActionSequence::accept
bool accept(const G4Step *step) const
Callback before hit processing starts. Invoke all filters.
Definition: Geant4SensDetAction.cpp:453
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:360
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:369
dd4hep::sim::Geant4Mapping::volumeManager
Geant4VolumeManager volumeManager() const
Access the volume manager.
Definition: Geant4Mapping.cpp:69
dd4hep::sim::Geant4SensDetActionSequence::m_sensitiveType
std::string m_sensitiveType
The true sensitive type of the detector.
Definition: Geant4SensDetAction.h:357
dd4hep::sim::Geant4Filter::Geant4Filter
Geant4Filter(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SensDetAction.cpp:79
dd4hep::sim::Geant4SensDetActionSequence::m_collections
HitCollections m_collections
Hit collection creators.
Definition: Geant4SensDetAction.h:351
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:421
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:151
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:444
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:331
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:179
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:328
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:275
dd4hep::sim::Geant4Sensitive::m_detector
DetElement m_detector
Reference to the detector element describing this sensitive element.
Definition: Geant4SensDetAction.h:149
dd4hep::sim::Geant4SensDetActionSequence::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:376
dd4hep::sim::Geant4Sensitive::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:129
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:232
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:200
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:402
dd4hep::sim::Geant4Filter
Base class to construct filters for Geant4 sensitive detectors.
Definition: Geant4SensDetAction.h:94
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
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:121
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:151
dd4hep::sim::Geant4SensDetActionSequence::begin
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the beginning of each event.
Definition: Geant4SensDetAction.cpp:492
dd4hep::sim::Geant4Sensitive::m_segmentation
Segmentation m_segmentation
Reference to segmentation.
Definition: Geant4SensDetAction.h:155
dd4hep::sim::Geant4SensDetSequences::operator[]
Geant4SensDetActionSequence * operator[](const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:529
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:68
dd4hep::sim::Geant4Sensitive::m_sensitiveDetector
Geant4ActionSD * m_sensitiveDetector
Reference to G4 sensitive detector.
Definition: Geant4SensDetAction.h:131
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:210
dd4hep::sim::Geant4Sensitive::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:223
dd4hep::sim::Geant4Sensitive::sequence
Geant4SensDetActionSequence & sequence() const
Access to the hosting sequence.
Definition: Geant4SensDetAction.cpp:190
dd4hep::sim::Geant4SensDetActionSequence::m_clear
CallbackSequence m_clear
Callback sequence to invoke the event deletion.
Definition: Geant4SensDetAction.h:344
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:467
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:90
dd4hep::sim::Geant4Sensitive::detectorDescription
Detector & detectorDescription() const
Access the detector description object.
Definition: Geant4SensDetAction.cpp:195