DD4hep  1.30.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 #ifdef DD4HEP_USE_GEANT4_UNITS
35 #define MM_2_CM 1.0
36 #else
37 #define MM_2_CM 0.1
38 #endif
39 
40 using namespace dd4hep::sim;
41 
42 #if 0
43 namespace {
44  Geant4ActionSD* _getSensitiveDetector(const std::string& name) {
45  G4SDManager* mgr = G4SDManager::GetSDMpointer();
46  G4VSensitiveDetector* sd = mgr->FindSensitiveDetector(name);
47  if (0 == sd) {
48  dd4hep::except("Geant4Sensitive", "DDG4: You requested to configure actions "
49  "for the sensitive detector %s,\nDDG4: which is not known to Geant4. "
50  "Are you sure you already converted the geometry?", name.c_str());
51  }
52  Geant4ActionSD* action_sd = dynamic_cast<Geant4ActionSD*>(sd);
53  if (0 == action_sd) {
54  throw dd4hep::except("Geant4Sensitive", "DDG4: You may only configure actions "
55  "for sensitive detectors of type Geant4ActionSD.\n"
56  "DDG4: The sensitive detector of %s is of type %s, which is incompatible.", name.c_str(),
57  typeName(typeid(*sd)).c_str());
58  }
59  return action_sd;
60  }
61 }
62 #endif
63 
65 Geant4ActionSD::Geant4ActionSD(const std::string& nam)
66  : Geant4Action(0, nam) {
68 }
69 
73 }
74 
76 Geant4Filter::Geant4Filter(Geant4Context* ctxt, const std::string& nam)
77  : Geant4Action(ctxt, nam) {
79 }
80 
84 }
85 
87 bool Geant4Filter::operator()(const G4Step*) const {
88  return true;
89 }
90 
93  except("The filter action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
94  return false;
95 }
96 
98 Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& det_ref)
99  : Geant4Action(ctxt, nam), m_detDesc(det_ref), m_detector(det)
100 {
102  if (!det.isValid()) {
103  except("DDG4: Detector elemnt for %s is invalid.", nam.c_str());
104  }
105  declareProperty("HitCreationMode", m_hitCreationMode = SIMPLE_MODE);
110 }
111 
115  m_filters.clear();
117 }
118 
121  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
122  adopt(filter);
123 }
124 
127  if (filter) {
128  filter->addRef();
129  m_filters.add(filter);
130  return;
131  }
132  except("Attempt to add invalid sensitive filter!");
133 }
134 
137  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
138  adopt_front(filter);
139 }
140 
143  if (filter) {
144  filter->addRef();
145  m_filters.add_front(filter);
146  return;
147  }
148  except("Attempt to add invalid sensitive filter!");
149 }
150 
152 bool Geant4Sensitive::accept(const G4Step* step) const {
153  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
154  bool result = m_filters.filter(filter, step);
155  return result;
156 }
157 
160  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
161  bool result = m_filters.filter(filter, spot);
162  return result;
163 }
164 
167  m_sensitiveDetector = sens_det;
168 }
169 
173  return *m_sensitiveDetector;
174  //m_sensitiveDetector = _getSensitiveDetector(m_detector.name());
175  //if ( m_sensitiveDetector ) return *m_sensitiveDetector;
176  except("DDG4: The sensitive detector for action %s was not properly configured.", name().c_str());
177  throw std::runtime_error("Geant4Sensitive::detector");
178 }
179 
182  return *m_sequence;
183 }
184 
187  return m_detDesc;
188 }
189 
191 const std::string& Geant4Sensitive::hitCollectionName(std::size_t which) const {
192  return sequence().hitCollectionName(which);
193 }
194 
197  return sequence().collection(which);
198 }
199 
202  return sequence().collectionByID(id);
203 }
204 
207 }
208 
210 void Geant4Sensitive::begin(G4HCofThisEvent* /* HCE */) {
211 }
212 
214 void Geant4Sensitive::end(G4HCofThisEvent* /* HCE */) {
215 }
216 
218 bool Geant4Sensitive::process(const G4Step* /* step */, G4TouchableHistory* /* history */) {
219  return false;
220 }
221 
223 bool Geant4Sensitive::processFastSim(const Geant4FastSimSpot* /* spot */, G4TouchableHistory* /* history */) {
224  except("The sensitive action %s does not support the GFLASH/FastSim interface for Geant4.", c_name());
225  return false;
226 }
227 
229 void Geant4Sensitive::clear(G4HCofThisEvent* /* HCE */) {
230 }
231 
233 void Geant4Sensitive::mark(const G4Track* track) const {
235  if ( truth ) truth->mark(track);
236 }
237 
239 void Geant4Sensitive::mark(const G4Step* step) const {
241  if ( truth ) truth->mark(step);
242 }
243 
245 long long int Geant4Sensitive::volumeID(const G4Step* step) {
246  Geant4StepHandler stepH(step);
248  VolumeID id = volMgr.volumeID(stepH.preTouchable());
249  return id;
250 }
251 
253 long long int Geant4Sensitive::volumeID(const G4VTouchable* touchable) {
255  VolumeID id = volMgr.volumeID(touchable);
256  return id;
257 }
258 
260 long long int Geant4Sensitive::cellID(const G4Step* step) {
261  Geant4StepHandler h(step);
263  VolumeID volID = volMgr.volumeID(h.preTouchable());
264  if ( m_segmentation.isValid() ) {
265  std::exception_ptr eptr;
266  G4ThreeVector global = 0.5 * (h.prePosG4()+h.postPosG4());
267  G4ThreeVector local = h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global);
268  Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
269  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
270  try {
271  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
272  return cID;
273  }
274  catch(const std::exception& e) {
275  eptr = std::current_exception();
276  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
277  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
278  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
279  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
280  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
281  error("....... Pre-step: %s SD: %s", h.volName(h.pre), h.sdName(h.pre).c_str());
282  if ( h.post )
283  error("....... Post-step: %s SD: %s", h.volName(h.post), h.sdName(h.post).c_str());
284  std::rethrow_exception(std::move(eptr));
285  }
286  }
287  return volID;
288 }
289 
291 long long int Geant4Sensitive::cellID(const G4VTouchable* touchable, const G4ThreeVector& global) {
293  VolumeID volID = volMgr.volumeID(touchable);
294  if ( m_segmentation.isValid() ) {
295  std::exception_ptr eptr;
296  G4ThreeVector local = touchable->GetHistory()->GetTopTransform().TransformPoint(global);
297  Position loc (local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM);
298  Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM);
299  try {
300  VolumeID cID = m_segmentation.cellID(loc, glob, volID);
301  return cID;
302  }
303  catch(const std::exception& e) {
304  auto* pvol = touchable->GetVolume();
305  auto* vol = pvol->GetLogicalVolume();
306  auto* sd = vol->GetSensitiveDetector();
307  eptr = std::current_exception();
308  error("cellID: failed to access segmentation for VolumeID: %016lX [%ld] [%s]", volID, volID, e.what());
309  error("....... G4-local: (%f, %f, %f) G4-global: (%f, %f, %f)",
310  local.x(), local.y(), local.z(), global.x(), global.y(), global.z());
311  error("....... TGeo-local: (%f, %f, %f) TGeo-global: (%f, %f, %f)",
312  loc.x(), loc.y(), loc.z(), glob.x(), glob.y(), glob.z());
313  error("....... Touchable: %s SD: %s", vol->GetName().c_str(), sd ? sd->GetName().c_str() : "???");
314  std::rethrow_exception(std::move(eptr));
315  }
316  }
317  return volID;
318 }
319 
322  : Geant4Action(ctxt, nam), m_hce(0), m_detector(0)
323 {
324  m_needsControl = true;
325  context()->sensitiveActions().insert(name(), this);
330 }
331 
336  m_filters.clear();
337  m_actors.clear();
339 }
340 
343  m_context = ctxt;
344  m_actors.updateContext(ctxt);
345  m_filters.updateContext(ctxt);
346 }
347 
350  Geant4Filter* filter = dynamic_cast<Geant4Filter*>(action);
351  adopt(filter);
352 }
353 
356  if (sensitive) {
357  sensitive->addRef();
358  m_actors.add(sensitive);
359  return;
360  }
361  except("Attempt to add invalid sensitive actor!");
362 }
363 
366  if (filter) {
367  filter->addRef();
368  m_filters.add(filter);
369  return;
370  }
371  except("Attempt to add invalid sensitive filter!");
372 }
373 
375 std::size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& collection_name, create_t func) {
376  m_collections.emplace_back(collection_name, make_pair(owner,func));
377  return m_collections.size() - 1;
378 }
379 
381 std::size_t Geant4SensDetActionSequence::Geant4SensDetActionSequence::defineCollections(Geant4ActionSD* sens_det) {
382  std::size_t count = 0;
383  m_detector = sens_det;
384  m_actors(&Geant4Sensitive::setDetector, sens_det);
386  for (HitCollections::const_iterator i = m_collections.begin(); i != m_collections.end(); ++i) {
387  sens_det->defineCollection((*i).first);
388  ++count;
389  }
390  return count;
391 }
392 
394 const std::string& Geant4SensDetActionSequence::hitCollectionName(std::size_t which) const {
395  if (which < m_collections.size()) {
396  return m_collections[which].first;
397  }
398  static std::string blank = "";
399  except("The collection name index for subdetector %s is out of range!", c_name());
400  return blank;
401 }
402 
405  if (which < m_collections.size()) {
406  int hc_id = m_detector->GetCollectionID(which);
407  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(hc_id);
408  if (c)
409  return c;
410  except("The collection index for subdetector %s is wrong!", c_name());
411  }
412  except("The collection name index for subdetector %s is out of range!", c_name());
413  return 0;
414 }
415 
418  Geant4HitCollection* c = (Geant4HitCollection*) m_hce->GetHC(id);
419  if (c)
420  return c;
421  except("The collection index for subdetector %s is wrong!", c_name());
422  return 0;
423 }
424 
426 bool Geant4SensDetActionSequence::accept(const G4Step* step) const {
427  bool (Geant4Filter::*filter)(const G4Step*) const = &Geant4Filter::operator();
428  bool result = m_filters.filter(filter, step);
429  return result;
430 }
431 
434  bool (Geant4Filter::*filter)(const Geant4FastSimSpot*) const = &Geant4Filter::operator();
435  bool result = m_filters.filter(filter, spot);
436  return result;
437 }
438 
440 bool Geant4SensDetActionSequence::process(const G4Step* step, G4TouchableHistory* history) {
441  bool result = false;
442  for (Geant4Sensitive* sensitive : m_actors) {
443  if ( sensitive->accept(step) )
444  result |= sensitive->process(step, history);
445  }
446  m_process(step, history);
447  return result;
448 }
449 
451 bool Geant4SensDetActionSequence::processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) {
452  bool result = false;
453  for (Geant4Sensitive* sensitive : m_actors) {
454  if ( sensitive->accept(spot) )
455  result |= sensitive->processFastSim(spot, history);
456  }
457  m_process(spot, history);
458  return result;
459 }
460 
465 void Geant4SensDetActionSequence::begin(G4HCofThisEvent* hce) {
466  m_hce = hce;
467  for (std::size_t count = 0; count < m_collections.size(); ++count) {
468  const HitCollection& cr = m_collections[count];
469  Geant4HitCollection* col = (*cr.second.second)(name(), cr.first, cr.second.first);
470  int id = m_detector->GetCollectionID(count);
471  m_hce->AddHitsCollection(id, col);
472  }
474  m_begin (m_hce);
475 }
476 
478 void Geant4SensDetActionSequence::end(G4HCofThisEvent* hce) {
479  m_end(hce);
481  // G4HCofThisEvent must be availible until end-event. m_hce = 0;
482 }
483 
485 
491  m_clear (m_hce);
493 }
494 
497  detail::releaseObjects(m_sequences);
498  m_sequences.clear();
499 }
500 
503  std::string n = "SD_Seq_" + nam;
504  Members::const_iterator i = m_sequences.find(n);
505  if (i != m_sequences.end())
506  return (*i).second;
507  except("Attempt to access undefined SensDetActionSequence: %s ", nam.c_str());
508  return nullptr;
509 }
510 
513  std::string nam = "SD_Seq_" + name;
514  Members::const_iterator i = m_sequences.find(nam);
515  if (i != m_sequences.end())
516  return (*i).second;
517  return 0;
518 }
519 
521 void Geant4SensDetSequences::insert(const std::string& name, Geant4SensDetActionSequence* seq) {
522  if (seq) {
523  std::string nam = "SD_Seq_" + name;
524  seq->addRef();
525  m_sequences[nam] = seq;
526  return;
527  }
528  except("Attempt to add invalid sensitive sequence with name:%s", name.c_str());
529 }
530 
533  m_sequences.clear();
534 }
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:342
dd4hep::sim::Geant4Sensitive::adopt
void adopt(Geant4Filter *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:126
dd4hep::sim::Geant4Sensitive::defineCollections
virtual void defineCollections()
Define collections created by this sensitivie action object.
Definition: Geant4SensDetAction.cpp:206
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:521
Geant4Mapping.h
dd4hep::sim::Geant4SensDetActionSequence::m_end
CallbackSequence m_end
Callback sequence for event finalization action.
Definition: Geant4SensDetAction.h:329
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:451
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:335
dd4hep::sim::Geant4ActionSD::~Geant4ActionSD
virtual ~Geant4ActionSD()
Default destructor.
Definition: Geant4SensDetAction.cpp:71
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:154
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:171
Geant4VolumeManager.h
dd4hep::sim::Geant4Sensitive::clear
virtual void clear(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:229
dd4hep::sim::Geant4SensDetActionSequence::clear
virtual void clear()
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: Geant4SensDetAction.cpp:490
dd4hep::sim::Geant4SensDetSequences::m_sequences
Members m_sequences
Definition: Geant4SensDetAction.h:470
dd4hep::sim::Geant4SensDetSequences::clear
void clear()
Clear the sequence list.
Definition: Geant4SensDetAction.cpp:532
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:218
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:98
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::sim::Geant4SensDetActionSequence::adopt
void adopt(Geant4Sensitive *sensitive)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:355
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:82
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
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:245
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:196
dd4hep::sim::Geant4Sensitive::~Geant4Sensitive
virtual ~Geant4Sensitive()
Standard destructor.
Definition: Geant4SensDetAction.cpp:113
dd4hep::sim::Geant4SensDetActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for event initialization action.
Definition: Geant4SensDetAction.h:327
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:321
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:136
dd4hep::sim::Geant4VolumeManager::volumeID
VolumeID volumeID(const G4VTouchable *touchable) const
Access CELLID by placement path.
Definition: Geant4VolumeManager.cpp:268
dd4hep::sim::Geant4SensDetActionSequence::m_process
CallbackSequence m_process
Callback sequence for step processing.
Definition: Geant4SensDetAction.h:331
dd4hep::sim::Geant4SensDetSequences::~Geant4SensDetSequences
virtual ~Geant4SensDetSequences()
Default destructor.
Definition: Geant4SensDetAction.cpp:496
dd4hep::sim::Geant4SensDetActionSequence::m_filters
Actors< Geant4Filter > m_filters
The list of sensitive detector filter objects.
Definition: Geant4SensDetAction.h:337
dd4hep::sim::Geant4SensDetSequences::find
Geant4SensDetActionSequence * find(const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:512
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
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:233
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:37
dd4hep::sim::Geant4Sensitive::m_readout
Readout m_readout
Reference to the readout structure.
Definition: Geant4SensDetAction.h:150
dd4hep::sim::Geant4Sensitive::setDetector
void setDetector(Geant4ActionSD *sens_det)
Access to the sensitive detector object.
Definition: Geant4SensDetAction.cpp:166
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:325
dd4hep::sim::Geant4Sensitive::m_detDesc
Detector & m_detDesc
Reference to the detector description object.
Definition: Geant4SensDetAction.h:143
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:152
dd4hep::sim::Geant4SensDetActionSequence::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:478
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::Geant4SensDetActionSequence::m_detector
Geant4ActionSD * m_detector
Reference to G4 sensitive detector.
Definition: Geant4SensDetAction.h:344
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:404
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 begining of each event.
Definition: Geant4SensDetAction.cpp:210
dd4hep::sim::Geant4SensDetActionSequence::accept
bool accept(const G4Step *step) const
Callback before hit processing starts. Invoke all filters.
Definition: Geant4SensDetAction.cpp:426
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:333
dd4hep::sim::Geant4VolumeManager
The Geant4VolumeManager to facilitate optimized lookups of cell IDs from touchables.
Definition: Geant4VolumeManager.h:42
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:74
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:342
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:346
dd4hep::sim::Geant4Filter::Geant4Filter
Geant4Filter(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SensDetAction.cpp:76
dd4hep::sim::Geant4SensDetActionSequence::m_collections
HitCollections m_collections
Hit collection creators.
Definition: Geant4SensDetAction.h:340
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:394
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:148
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
Primitives.h
VolumeID
dd4hep::DDSegmentation::VolumeID VolumeID
Definition: SegmentationDictionary.h:49
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:417
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4SensDetActionSequence::HitCollection
std::pair< std::string, std::pair< Geant4Sensitive *, create_t > > HitCollection
Definition: Geant4SensDetAction.h:320
dd4hep::sim::Geant4Context::kernel
Geant4Kernel & kernel() const
Access to the kernel object.
Definition: Geant4Context.h:233
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:317
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:260
dd4hep::sim::Geant4Sensitive::m_detector
DetElement m_detector
Reference to the detector element describing this sensitive element.
Definition: Geant4SensDetAction.h:146
dd4hep::sim::Geant4SensDetActionSequence::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:349
dd4hep::sim::Geant4Sensitive::adoptFilter
void adoptFilter(Geant4Action *filter)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SensDetAction.cpp:120
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:223
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:191
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:375
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::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:142
dd4hep::sim::Geant4SensDetActionSequence::begin
virtual void begin(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the begining of each event.
Definition: Geant4SensDetAction.cpp:465
dd4hep::sim::Geant4Sensitive::m_segmentation
Segmentation m_segmentation
Reference to segmentation.
Definition: Geant4SensDetAction.h:152
dd4hep::sim::Geant4SensDetSequences::operator[]
Geant4SensDetActionSequence * operator[](const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:502
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:65
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:201
dd4hep::sim::Geant4Sensitive::end
virtual void end(G4HCofThisEvent *hce)
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: Geant4SensDetAction.cpp:214
dd4hep::sim::Geant4Sensitive::sequence
Geant4SensDetActionSequence & sequence() const
Access to the hosting sequence.
Definition: Geant4SensDetAction.cpp:181
dd4hep::sim::Geant4SensDetActionSequence::m_clear
CallbackSequence m_clear
Callback sequence to invoke the event deletion.
Definition: Geant4SensDetAction.h:333
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:440
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:87
dd4hep::sim::Geant4Sensitive::detectorDescription
Detector & detectorDescription() const
Access the detector desciption object.
Definition: Geant4SensDetAction.cpp:186