DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4SDActions.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 <DDG4/Geant4SensDetAction.inl>
17 #include <DDG4/Geant4EventAction.h>
18 #include <G4OpticalPhoton.hh>
19 #include <G4VProcess.hh>
20 
21 
23 namespace dd4hep {
24 
26  namespace sim {
27 
28  namespace {
29  struct Geant4VoidSensitive {};
30  }
31  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32  // Geant4SensitiveAction<Geant4VoidSensitive>
33  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46  m_collectionID = -1;
47  }
48 
50  template <> bool
52  G4TouchableHistory* /* hist */) {
53  return true;
54  }
55 
57  template <> bool
59  G4TouchableHistory* /* hist */) {
60  return true;
61  }
63 
64  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65  // Geant4SensitiveAction<Geant4Tracker>
66  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
78  m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
79  }
80 
82  template <> bool
83  Geant4SensitiveAction<Geant4Tracker>::process(const G4Step* step,G4TouchableHistory* /* hist */) {
84  typedef Geant4Tracker::Hit Hit;
85  // Note: 1) We store in the hit the hit-direction, which is not the same as the track direction.
86  // 2) The energy deposit is the difference between incoming and outcoming energy.
87  Geant4StepHandler h(step);
88  auto contrib = Hit::extractContribution(step);
89  Direction hit_momentum = 0.5 * (h.preMom() + h.postMom());
90  double hit_deposit = h.deposit();
91  Hit* hit = new Hit(contrib, hit_momentum, hit_deposit);
92 
93  hit->cellID = cellID(step);
94  if ( 0 == hit->cellID ) {
95  hit->cellID = volumeID(step);
96  except("+++ Invalid CELL ID for hit!");
97  }
98  collection(m_collectionID)->add(hit);
99  mark(h.track);
100  print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
101  hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
102  Geant4TouchableHandler handler(step);
103  print(" Geant4 path:%s",handler.path().c_str());
104  return true;
105  }
106 
108  template <> bool
110  G4TouchableHistory* /* hist */)
111  {
112  typedef Geant4Tracker::Hit Hit;
113  Geant4FastSimHandler h(spot);
114  auto contrib = Hit::extractContribution(spot);
115  Hit* hit = new Hit(contrib, h.momentum(), h.deposit());
116 
117  hit->cellID = cellID(h.touchable(), h.avgPositionG4());
118  if ( 0 == hit->cellID ) {
119  hit->cellID = volumeID(h.touchable());
120  except("+++ Invalid CELL ID for hit!");
121  }
122  collection(m_collectionID)->add(hit);
123  mark(h.track);
124  print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
125  hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
126  Geant4TouchableHandler handler(h.touchable());
127  print(" Geant4 path:%s",handler.path().c_str());
128  return true;
129  }
130 
132 
133  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
134  // Geant4SensitiveAction<Geant4PhotonCounter>
135  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146  struct Geant4OpticalTracker {};
148 
151  m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
152  }
153 
155  template <> bool
156  Geant4SensitiveAction<Geant4OpticalTracker>::process(const G4Step* step,G4TouchableHistory* /* hist */) {
157  // Note: 1) We store in the hit the hit-direction, which is not the same as the track direction.
158  // 2) The energy deposit is the track momentum
159  typedef Geant4Tracker::Hit Hit;
160  Geant4StepHandler h(step);
161  auto contrib = Hit::extractContribution(step);
162  Direction hit_momentum = 0.5 * (h.preMom() + h.postMom());
163  double hit_deposit = contrib.deposit;
164  Hit* hit = new Hit(contrib, hit_momentum, hit_deposit);
165 
166  if (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) {
167  step->GetTrack()->SetTrackStatus(fStopAndKill);
168  }
169  hit->cellID = cellID(step);
170  if ( 0 == hit->cellID ) {
171  hit->cellID = volumeID( step ) ;
172  except("+++ Invalid CELL ID for hit!");
173  }
174  collection(m_collectionID)->add(hit);
175  mark(h.track);
176  print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
177  hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
178  Geant4TouchableHandler handler(step);
179  print(" Geant4 path:%s",handler.path().c_str());
180  return true;
181  }
182 
184  template <> bool
186  G4TouchableHistory* /* hist */)
187  {
188  typedef Geant4Tracker::Hit Hit;
189  Geant4FastSimHandler h(spot);
190  auto contrib = Hit::extractContribution(spot);
191  Hit* hit = new Hit(contrib, h.momentum(), contrib.deposit);
192 
193  hit->cellID = cellID(h.touchable(), h.avgPositionG4());
194  if ( 0 == hit->cellID ) {
195  hit->cellID = volumeID(h.touchable());
196  except("+++ Invalid CELL ID for hit!");
197  }
198  collection(m_collectionID)->add(hit);
199  mark(h.track);
200  print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
201  hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
202  Geant4TouchableHandler handler(h.touchable());
203  print(" Geant4 path:%s",handler.path().c_str());
204  return true;
205  }
207 
208  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
209  // Geant4SensitiveAction<Calorimeter>
210  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
223  m_collectionID = declareReadoutFilteredCollection<Geant4Calorimeter::Hit>();
224  }
225 
227  template <> bool
228  Geant4SensitiveAction<Geant4Calorimeter>::process(const G4Step* step,G4TouchableHistory*) {
229  typedef Geant4Calorimeter::Hit Hit;
230  Geant4StepHandler h(step);
231  HitContribution contrib = Hit::extractContribution(step);
232  Geant4HitCollection* coll = collection(m_collectionID);
233  VolumeID cell = 0;
234 
235  try {
236  cell = cellID(step);
237  } catch(std::runtime_error &e) {
238  std::stringstream out;
239  out << std::setprecision(20) << std::scientific;
240  out << "ERROR: " << e.what() << std::endl;
241  out << "Position: "
242  << "Pre (" << std::setw(24) << step->GetPreStepPoint()->GetPosition() << ") "
243  << "Post (" << std::setw(24) << step->GetPostStepPoint()->GetPosition() << ") "
244  << std::endl;
245  out << "Momentum: "
246  << " Pre (" <<std::setw(24) << step->GetPreStepPoint() ->GetMomentum() << ") "
247  << " Post (" <<std::setw(24) << step->GetPostStepPoint()->GetMomentum() << ") "
248  << std::endl;
249  std::cout << out.str();
250  return true;
251  }
252 
253  //Hit* hit = coll->find<Hit>(CellIDCompare<Hit>(cell));
254  Hit* hit = coll->findByKey<Hit>(cell);
255  if ( !hit ) {
256  Geant4TouchableHandler handler(step);
257  DDSegmentation::Vector3D pos = m_segmentation.position(cell);
258  Position global = h.localToGlobal(pos);
259  hit = new Hit(global);
260  hit->cellID = cell;
261  coll->add(cell, hit);
262  printM2("%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s [%s]",
263  c_name(),contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str(),
264  coll->GetName().c_str());
265  if ( 0 == hit->cellID ) { // for debugging only!
266  hit->cellID = cellID(step);
267  except("+++ Invalid CELL ID for hit!");
268  }
269  }
270  hit->truth.emplace_back(contrib);
271  hit->energyDeposit += contrib.deposit;
272  mark(h.track);
273  return true;
274  }
276  template <> bool
278  G4TouchableHistory* /* hist */)
279  {
280  typedef Geant4Calorimeter::Hit Hit;
281  Geant4FastSimHandler h(spot);
282  HitContribution contrib = Hit::extractContribution(spot);
283  Geant4HitCollection* coll = collection(m_collectionID);
284  VolumeID cell = 0;
285 
286  try {
287  cell = cellID(h.touchable(), h.avgPositionG4());
288  } catch(std::runtime_error &e) {
289  std::stringstream out;
290  out << std::setprecision(20) << std::scientific;
291  out << "ERROR: " << e.what() << std::endl;
292  out << "Position: (" << std::setw(24) << h.avgPositionG4() << ") " << std::endl;
293  out << "Momentum: (" << std::setw(24) << h.momentumG4() << ") " << std::endl;
294  std::cout << out.str();
295  return true;
296  }
297  Hit* hit = coll->findByKey<Hit>(cell);
298  if ( !hit ) {
299  Geant4TouchableHandler handler(h.touchable());
300  DDSegmentation::Vector3D pos = m_segmentation.position(cell);
301  Position global = h.localToGlobal(pos);
302  hit = new Hit(global);
303  hit->cellID = cell;
304  coll->add(cell, hit);
305  printM2("%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s [%s]",
306  c_name(),contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str(),
307  coll->GetName().c_str());
308  if ( 0 == hit->cellID ) { // for debugging only!
309  hit->cellID = cellID(h.touchable(), h.avgPositionG4());
310  except("+++ Invalid CELL ID for hit!");
311  }
312  }
313  hit->truth.emplace_back(contrib);
314  hit->energyDeposit += contrib.deposit;
315  mark(h.track);
316  return true;
317  }
318 
320 
321  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
322  // Geant4SensitiveAction<OpticalCalorimeter>
323  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
324 
337  struct Geant4OpticalCalorimeter {};
339 
342  m_collectionID = declareReadoutFilteredCollection<Geant4Calorimeter::Hit>();
343  }
345  template <> bool
346  Geant4SensitiveAction<Geant4OpticalCalorimeter>::process(const G4Step* step,G4TouchableHistory*) {
347  G4Track * track = step->GetTrack();
348  // check that particle is optical photon:
349  if( track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() ) {
350  return false;
351  }
352  else if ( track->GetCreatorProcess()->G4VProcess::GetProcessName() != "Cerenkov") {
353  track->SetTrackStatus(fStopAndKill);
354  return false;
355  }
356  else {
357  typedef Geant4Calorimeter::Hit Hit;
358  Geant4StepHandler h(step);
359  Geant4HitCollection* coll = collection(m_collectionID);
360  HitContribution contrib = Hit::extractContribution(step);
361  Position pos = h.prePos();
362  Hit* hit = coll->find<Hit>(PositionCompare<Hit,Position>(pos));
363  if ( !hit ) {
364  hit = new Hit(pos);
365  hit->cellID = volumeID(step);
366  coll->add(hit);
367  if ( 0 == hit->cellID ) {
368  hit->cellID = volumeID(step);
369  except("+++ Invalid CELL ID for hit!");
370  }
371  }
372  hit->energyDeposit += contrib.deposit;
373  hit->truth.emplace_back(contrib);
374  track->SetTrackStatus(fStopAndKill); // don't step photon any further
375  mark(h.track);
376  return true;
377  }
378  }
379 
381  template <> bool
383  G4TouchableHistory* /* hist */)
384  {
385  typedef Geant4Calorimeter::Hit Hit;
386  Geant4FastSimHandler h(spot);
387  const G4Track* track = h.track;
388  if( track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() ) {
389  return false;
390  }
391  else if ( track->GetCreatorProcess()->G4VProcess::GetProcessName() != "Cerenkov") {
392  return false;
393  }
394  else {
395  Geant4HitCollection* coll = collection(m_collectionID);
396  HitContribution contrib = Hit::extractContribution(spot);
397  Position pos = h.avgPosition();
398  Hit* hit = coll->find<Hit>(PositionCompare<Hit,Position>(pos));
399  if ( !hit ) {
400  hit = new Hit(pos);
401  hit->cellID = volumeID(h.touchable());
402  coll->add(hit);
403  if ( 0 == hit->cellID ) {
404  hit->cellID = volumeID(h.touchable());
405  except("+++ Invalid CELL ID for hit!");
406  }
407  }
408  hit->energyDeposit += contrib.deposit;
409  hit->truth.emplace_back(contrib);
410  mark(h.track);
411  return true;
412  }
413  }
415 
416 
417  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
418  // Geant4SensitiveAction<ScintillatorCalorimeter>
419  // For scintillator with Geant4 BirksLaw effect
420  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
421 
422 
423  /* \addtogroup Geant4SDActionPlugin
424  *
425  * @{
426  * \package Geant4ScintillatorCalorimeterAction
427  * \brief Sensitive detector meant for scintillator calorimeters
428  *
429  * This sensitive action will apply Birks' law to the energy deposits
430  *
431  * @}
432  */
435 
438  m_collectionID = declareReadoutFilteredCollection<Geant4Calorimeter::Hit>();
439  }
441  template <> bool
442  Geant4SensitiveAction<Geant4ScintillatorCalorimeter>::process(const G4Step* step,G4TouchableHistory*) {
443  typedef Geant4Calorimeter::Hit Hit;
444  Geant4StepHandler h(step);
445  HitContribution contrib = Hit::extractContribution(step,true);
446  Geant4HitCollection* coll = collection(m_collectionID);
447  VolumeID cell = 0;
448  try {
449  cell = cellID(step);
450  } catch(std::runtime_error &e) {
451  std::stringstream out;
452  out << std::setprecision(20) << std::scientific;
453  out << "ERROR: " << e.what() << std::endl;
454  out << "Position: "
455  << "Pre (" << std::setw(24) << step->GetPreStepPoint()->GetPosition() << ") "
456  << "Post (" << std::setw(24) << step->GetPostStepPoint()->GetPosition() << ") "
457  << std::endl;
458  out << "Momentum: "
459  << " Pre (" <<std::setw(24) << step->GetPreStepPoint() ->GetMomentum() << ") "
460  << " Post (" <<std::setw(24) << step->GetPostStepPoint()->GetMomentum() << ") "
461  << std::endl;
462  std::cout << out.str();
463  return true;
464  }
465  Hit* hit = coll->findByKey<Hit>(cell);
466  if ( !hit ) {
467  Geant4TouchableHandler handler(step);
468  DDSegmentation::Vector3D pos = m_segmentation.position(cell);
469  Position global = h.localToGlobal(pos);
470  hit = new Hit(global);
471  hit->cellID = cell;
472  coll->add(cell, hit);
473  printM2("CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s",
474  contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str());
475  if ( 0 == hit->cellID ) { // for debugging only!
476  hit->cellID = cellID(step);
477  except("+++ Invalid CELL ID for hit!");
478  }
479  }
480  hit->truth.emplace_back(contrib);
481  hit->energyDeposit += contrib.deposit;
482  mark(h.track);
483  return true;
484  }
485 
487  template <> bool
489  G4TouchableHistory* /* hist */)
490  {
491  typedef Geant4Calorimeter::Hit Hit;
492  Geant4FastSimHandler h(spot);
493  HitContribution contrib = Hit::extractContribution(spot);
494  Geant4HitCollection* coll = collection(m_collectionID);
495  VolumeID cell = 0;
496 
497  try {
498  cell = cellID(h.touchable(), h.avgPositionG4());
499  } catch(std::runtime_error &e) {
500  std::stringstream out;
501  out << std::setprecision(20) << std::scientific;
502  out << "ERROR: " << e.what() << std::endl;
503  out << "Position: (" << std::setw(24) << h.avgPositionG4() << ") " << std::endl;
504  out << "Momentum: (" << std::setw(24) << h.momentumG4() << ") " << std::endl;
505  std::cout << out.str();
506  return true;
507  }
508  Hit* hit = coll->findByKey<Hit>(cell);
509  if ( !hit ) {
510  Geant4TouchableHandler handler(h.touchable());
511  DDSegmentation::Vector3D pos = m_segmentation.position(cell);
512  Position global = h.localToGlobal(pos);
513  hit = new Hit(global);
514  hit->cellID = cell;
515  coll->add(cell, hit);
516  printM2("CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s",
517  contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str());
518  if ( 0 == hit->cellID ) { // for debugging only!
519  hit->cellID = cellID(h.touchable(), h.avgPositionG4());
520  except("+++ Invalid CELL ID for hit!");
521  }
522  }
523  hit->truth.emplace_back(contrib);
524  hit->energyDeposit += contrib.deposit;
525  mark(h.track);
526  return true;
527  }
528 
530 
544 
553  struct TrackerCombine {
557  G4VPhysicalVolume* firstSpotVolume { nullptr };
558  double mean_time { 0e0 };
559  double e_cut { 0e0 };
560  int current { -1 };
561  int combined { 0 };
562  long long int cell { 0 };
563 
565  }
566 
568  void start_collecting(const G4Track* track) {
569  pre.truth.deposit = 0.0;
571  sensitive->mark(track);
572  mean_pos.SetXYZ(0,0,0);
573  mean_time = 0;
574  post.copyFrom(pre);
575  combined = 0;
576  cell = 0;
577  }
578  void start(const G4Step* step, const G4StepPoint* point) {
579  pre.storePoint(step,point);
580  start_collecting(step->GetTrack());
581  firstSpotVolume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
582  }
583  void start(const Geant4FastSimSpot* spot) {
584  pre.storePoint(spot);
585  start_collecting(spot->primary);
586  firstSpotVolume = spot->volume();
587  }
588 
590  void update_collected_hit(const G4VTouchable* h, G4ThreeVector&& global) {
596  if ( 0 == cell ) {
597  cell = sensitive->cellID(h, global);
598  if ( 0 == cell ) {
599  cell = sensitive->volumeID(h) ;
600  sensitive->except("+++ Invalid CELL ID for hit!");
601  }
602  }
603  ++combined;
604  }
605  void update(const Geant4StepHandler& h) {
606  post.storePoint(h.step, h.post);
607  update_collected_hit(h.preTouchable(), h.avgPositionG4()); // Compute cellID
608  }
609  void update(const Geant4FastSimHandler& h) {
610  post.storePoint(h.spot);
611  update_collected_hit(h.touchable(), h.avgPositionG4()); // Compute cellID
612  }
613 
615  void clear() {
616  mean_pos.SetXYZ(0,0,0);
617  mean_time = 0;
618  post.clear();
619  pre.clear();
620  current = -1;
621  combined = 0;
622  cell = 0;
623  firstSpotVolume = nullptr;
624  }
625 
627  bool mustSaveTrack(const G4Track* tr) const {
628  return current > 0 && current != tr->GetTrackID();
629  }
630 
632  void extractHit(Geant4HitCollection* collection) {
633  if ( current == -1 ) {
634  return;
635  }
636  double depo = pre.truth.deposit;
637  double time = depo != 0 ? mean_time / depo : mean_time;
638  Position pos = depo != 0 ? mean_pos / depo : mean_pos;
639  Momentum mom = 0.5 * (pre.momentum + post.momentum);
640  double path_len = (post.position - pre.position).R();
642  depo, time, path_len, pos, mom);
643  hit->cellID = cell;
644  collection->add(hit);
645  sensitive->printM2("+++ TrackID:%6d [%s] CREATE hit combination with %2d deposit(s):"
646  " %e MeV Pos:%8.2f %8.2f %8.2f",
648  pos.X()/CLHEP::mm,pos.Y()/CLHEP::mm,pos.Z()/CLHEP::mm);
649  clear();
650  }
651 
652 
654  G4bool process(const G4Step* step, G4TouchableHistory* ) {
655  Geant4StepHandler h(step);
656  // std::cout << " process called - pre pos: " << h.prePos() << " post pos " << h.postPos()
657  // << " edep: " << h.deposit() << std::endl ;
658  void *prePV = h.volume(h.pre), *postPV = h.volume(h.post);
659 
662  if ( mustSaveTrack(h.track) ) {
663  extractHit(coll);
664  }
666  if ( current < 0 ) {
667  start(step, h.pre);
668  }
670  update(h);
671 
672  if ( prePV != postPV ) {
673  void* postSD = h.sd(h.post);
674  extractHit(coll);
675  if ( 0 != postSD ) {
676  void* preSD = h.sd(h.pre);
677  if ( preSD == postSD ) {
678  start(step,h.post);
679  }
680  }
681  }
682  else if ( h.track->GetTrackStatus() == fStopAndKill ) {
683  extractHit(coll);
684  }
685  return true;
686  }
687 
689  G4bool process(const Geant4FastSimSpot* spot, G4TouchableHistory* ) {
690  Geant4FastSimHandler h(spot);
691  G4VPhysicalVolume* prePV = firstSpotVolume, *postPV = h.volume();
694  if ( mustSaveTrack(h.track) ) {
695  extractHit(coll);
696  }
698  if ( current < 0 ) {
699  start(spot);
700  }
702  update(h);
703 
704  if ( firstSpotVolume && prePV != postPV ) {
705  void* postSD = h.sd();
706  extractHit(coll);
707  if ( 0 != postSD ) {
708  void* preSD = prePV ? prePV->GetLogicalVolume()->GetSensitiveDetector() : nullptr;
709  if ( preSD == postSD ) {
710  start(spot);
711  }
712  }
713  }
714  else if ( h.track->GetTrackStatus() == fStopAndKill ) {
715  extractHit(coll);
716  }
717  return true;
718  }
719 
721  void endEvent(const G4Event* /* event */) {
722  // We need to add the possibly last added hit to the collection here.
723  // otherwise the last hit would be assigned to the next event and the
724  // MC truth would be screwed.
725  //
726  // Alternatively the 'update' method would become rather CPU consuming,
727  // beacuse the extract action would have to be recalculated over and over.
728  if ( current > 0 ) {
730  extractHit(coll);
731  }
732  }
733  };
734 
737  eventAction().callAtEnd(&m_userData,&TrackerCombine::endEvent);
738  m_userData.e_cut = m_sensitive.energyCutoff();
739  m_userData.sensitive = this;
740  }
741 
744  m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
745  }
746 
748  template <> void Geant4SensitiveAction<TrackerCombine>::clear(G4HCofThisEvent*) {
749  m_userData.clear();
750  }
751 
753  template <> G4bool
754  Geant4SensitiveAction<TrackerCombine>::process(const G4Step* step, G4TouchableHistory* history) {
755  return m_userData.process(step, history);
756  }
757 
759  template <> bool
761  G4TouchableHistory* history) {
762  return m_userData.process(spot, history);
763  }
764 
769  }
770 }
771 
772 using namespace dd4hep::sim;
773 
774 #include <DDG4/Factories.h>
775 // Special void entry point
777 // Standard factories used for simulation
784 
785 // Need these factories for backwards compatibility
dd4hep::sim::TrackerCombine::start
void start(const Geant4FastSimSpot *spot)
Definition: Geant4SDActions.cpp:583
DECLARE_GEANT4SENSITIVE
#define DECLARE_GEANT4SENSITIVE(name)
Definition: Factories.h:204
dd4hep::sim::Geant4Tracker::Hit::momentum
Direction momentum
Hit direction.
Definition: Geant4Data.h:270
dd4hep::sim::Geant4OpticalCalorimeterAction
Geant4SensitiveAction< Geant4OpticalCalorimeter > Geant4OpticalCalorimeterAction
Definition: Geant4SDActions.cpp:414
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
dd4hep::sim::TrackerCombine::endEvent
void endEvent(const G4Event *)
Post-event action callback.
Definition: Geant4SDActions.cpp:721
dd4hep::sim::Geant4SimpleOpticalCalorimeterAction
Geant4OpticalCalorimeterAction Geant4SimpleOpticalCalorimeterAction
Definition: Geant4SDActions.cpp:768
dd4hep::sim::Geant4TouchableHandler
Helper class to ease the extraction of information from a G4Touchable object.
Definition: Geant4TouchableHandler.h:44
dd4hep::sim::Geant4SensitiveAction::defineCollections
virtual void defineCollections()
Define collections created by this sensitivie action object.
dd4hep::sim::Geant4OpticalCalorimeter
Helper class to define properties of optical calorimeters. UNTESTED.
Definition: Geant4SDActions.cpp:338
dd4hep::sim::Geant4StepHandler::prePos
Position prePos() const
Returns the pre-step position.
Definition: Geant4StepHandler.h:84
dd4hep::sim::Geant4SimpleTrackerAction
Geant4TrackerAction Geant4SimpleTrackerAction
Definition: Geant4SDActions.cpp:766
dd4hep::sim::Geant4HitData::MonteCarloContrib::pdgID
int pdgID
Particle ID from the PDG table.
Definition: Geant4Data.h:143
dd4hep::sim::Geant4FastSimHandler::momentumG4
G4ThreeVector momentumG4() const
Returns the track momentum as a G4ThreeVector.
Definition: Geant4FastSimHandler.h:86
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
dd4hep::sim::Geant4CalorimeterAction
Geant4SensitiveAction< Geant4Calorimeter > Geant4CalorimeterAction
Definition: Geant4SDActions.cpp:319
dd4hep::sim::Momentum
Position Momentum
Definition: Defs.h:27
dd4hep::sim::Geant4SimpleCalorimeterAction
Geant4CalorimeterAction Geant4SimpleCalorimeterAction
Definition: Geant4SDActions.cpp:767
dd4hep::sim::TrackerCombine::update
void update(const Geant4FastSimHandler &h)
Definition: Geant4SDActions.cpp:609
dd4hep::sim::Geant4StepHandler::pre
G4StepPoint * pre
Definition: Geant4StepHandler.h:49
dd4hep::sim::Geant4TrackerAction
Geant4SensitiveAction< Geant4Tracker > Geant4TrackerAction
Definition: Geant4SDActions.cpp:131
dd4hep::sim::Geant4StepHandler::preMom
Momentum preMom() const
Definition: Geant4StepHandler.h:127
dd4hep::sim::Geant4SensitiveAction::initialize
virtual void initialize() final
Initialization overload for specialization.
dd4hep::sim::Geant4FastSimHandler
Helper class to ease the extraction of information from a G4FastSimSpot object.
Definition: Geant4FastSimHandler.h:43
dd4hep::sim::Geant4HitCollection
Generic hit container class using Geant4HitWrapper objects.
Definition: Geant4HitCollection.h:201
Geant4EventAction.h
Geant4TrackerCombineAction
Sensitive detector meant for tracking detectors will combine multiple steps of the same track in the ...
dd4hep::sim::TrackerCombine::update
void update(const Geant4StepHandler &h)
Definition: Geant4SDActions.cpp:605
dd4hep::sim::TrackerCombine::process
G4bool process(const G4Step *step, G4TouchableHistory *)
Method for generating hit(s) using the information of G4Step object.
Definition: Geant4SDActions.cpp:654
dd4hep::sim::Geant4StepHandler::postMom
Momentum postMom() const
Definition: Geant4StepHandler.h:131
dd4hep::sim::Geant4HitCollection::find
TYPE * find(const Compare &cmp)
Find hits in a collection by comparison of attributes.
Definition: Geant4HitCollection.h:350
dd4hep::sim::Geant4Tracker::Hit::copyFrom
void copyFrom(const Hit &c)
Explicit assignment operation.
Definition: Geant4Data.cpp:133
dd4hep::sim::Geant4VoidSensitiveAction
Geant4SensitiveAction< Geant4VoidSensitive > Geant4VoidSensitiveAction
Definition: Geant4SDActions.cpp:62
Geant4TrackerAction
Sensitive detector meant for tracking detectors, will produce one hit per step.
dd4hep::sim::Direction
Position Direction
Definition: Defs.h:26
dd4hep::sim::TrackerCombine::update_collected_hit
void update_collected_hit(const G4VTouchable *h, G4ThreeVector &&global)
Update energy and track information during hit info accumulation.
Definition: Geant4SDActions.cpp:590
dd4hep::sim::Geant4HitData::cellID
long long int cellID
cellID
Definition: Geant4Data.h:124
dd4hep::sim::TrackerCombine::sensitive
Geant4Sensitive * sensitive
Definition: Geant4SDActions.cpp:556
dd4hep::sim::Geant4StepHandler::volume
G4VPhysicalVolume * volume(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:151
dd4hep::sim::Geant4HitHandler::trackDef
G4ParticleDefinition * trackDef() const
Definition: Geant4HitHandler.h:66
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::TrackerCombine::cell
long long int cell
Definition: Geant4SDActions.cpp:562
dd4hep::sim::TrackerCombine::TrackerCombine
TrackerCombine()
Definition: Geant4SDActions.cpp:564
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::Geant4SensitiveAction::process
virtual bool process(const G4Step *step, G4TouchableHistory *history) final
G4VSensitiveDetector interface: Method for generating hit(s) using the G4Step object.
dd4hep::sim::Geant4StepHandler
Helper class to ease the extraction of information from a G4Step object.
Definition: Geant4StepHandler.h:46
dd4hep::sim::TrackerCombine::start
void start(const G4Step *step, const G4StepPoint *point)
Definition: Geant4SDActions.cpp:578
dd4hep::sim::Geant4SensitiveAction::clear
virtual void clear(G4HCofThisEvent *hce) final
G4VSensitiveDetector interface: Method invoked if the event was aborted.
dd4hep::sim::PositionCompare
Specialized hit selector based on the hit's position.
Definition: Geant4HitCollection.h:395
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::Geant4ScintillatorCalorimeterAction
Geant4SensitiveAction< Geant4ScintillatorCalorimeter > Geant4ScintillatorCalorimeterAction
Definition: Geant4SDActions.cpp:529
dd4hep::sim::Geant4FastSimHandler::deposit
double deposit() const
Access the enery deposit of the energy spot.
Definition: Geant4FastSimHandler.h:90
dd4hep::sim::Geant4StepHandler::avgPositionG4
G4ThreeVector avgPositionG4() const
Average position vector of the step.
Definition: Geant4StepHandler.h:102
dd4hep::sim::Geant4StepHandler::post
G4StepPoint * post
Definition: Geant4StepHandler.h:50
dd4hep::sim::Geant4OpticalTrackerAction
Geant4SensitiveAction< Geant4OpticalTracker > Geant4OpticalTrackerAction
Definition: Geant4SDActions.cpp:206
dd4hep::sim::Geant4FastSimSpot::primary
const G4Track * primary
Definition: Geant4FastSimSpot.h:120
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::Geant4Tracker::Hit
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:263
dd4hep::sim::Geant4HitHandler::touchable
const G4VTouchable * touchable() const
Definition: Geant4HitHandler.h:63
dd4hep::sim::TrackerCombine::clear
void clear()
Clear collected information and restart for new hit.
Definition: Geant4SDActions.cpp:615
dd4hep::sim::TrackerCombine::combined
int combined
Definition: Geant4SDActions.cpp:561
dd4hep::sim::Geant4HitData::MonteCarloContrib::deposit
double deposit
Total energy deposit in this hit.
Definition: Geant4Data.h:145
dd4hep::sim::TrackerCombine::process
G4bool process(const Geant4FastSimSpot *spot, G4TouchableHistory *)
Method for generating hit(s) using the information of fast simulation spot object.
Definition: Geant4SDActions.cpp:689
dd4hep::sim::Geant4HitCollection::findByKey
TYPE * findByKey(VolumeID key)
Find hits in a collection by comparison of key value.
Definition: Geant4HitCollection.h:354
Geant4FastSimHandler.h
dd4hep::sim::Geant4FastSimHandler::avgPositionG4
G4ThreeVector avgPositionG4() const
Returns the post-step position as a G4ThreeVector.
Definition: Geant4FastSimHandler.h:77
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:71
dd4hep::sim::TrackerCombine::mean_pos
Position mean_pos
Definition: Geant4SDActions.cpp:555
dd4hep::sim::Geant4HitHandler::localToGlobal
Position localToGlobal(const Position &local) const
Coordinate transformation to global coordinates.
Definition: Geant4HitHandler.cpp:30
dd4hep::sim::Geant4SensitiveAction
Template class to ease the construction of sensitive detectors using particle template specialization...
Definition: Geant4SensDetAction.h:514
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
Geant4CalorimeterAction
Sensitive detector meant for calorimeters.
dd4hep::sim::TrackerCombine::mean_time
double mean_time
Definition: Geant4SDActions.cpp:558
dd4hep::sim::TrackerCombine::pre
Geant4Tracker::Hit pre
Definition: Geant4SDActions.cpp:554
dd4hep::sim::Geant4TrackerCombineAction
Geant4SensitiveAction< TrackerCombine > Geant4TrackerCombineAction
Definition: Geant4SDActions.cpp:765
dd4hep::sim::Geant4Calorimeter::Hit
DDG4 calorimeter hit class used by the generic DDG4 calorimeter sensitive detector.
Definition: Geant4Data.h:323
dd4hep::sim::Geant4HitData::MonteCarloContrib::trackID
int trackID
Geant 4 Track identifier.
Definition: Geant4Data.h:141
dd4hep::sim::TrackerCombine::post
Geant4Tracker::Hit post
Definition: Geant4SDActions.cpp:554
dd4hep::sim::Geant4FastSimHandler::spot
const Geant4FastSimSpot * spot
Definition: Geant4FastSimHandler.h:45
dd4hep::sim::Geant4StepHandler::deposit
double deposit() const
Definition: Geant4StepHandler.h:135
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
Factories.h
dd4hep::sim::Geant4FastSimSpot::volume
G4VPhysicalVolume * volume() const
Access the physical volume of the hit.
Definition: Geant4FastSimSpot.h:87
dd4hep::sim::Geant4FastSimHandler::sd
G4VSensitiveDetector * sd() const
Definition: Geant4FastSimHandler.h:102
VolumeID
dd4hep::DDSegmentation::VolumeID VolumeID
Definition: SegmentationDictionary.h:50
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4StepHandler::step
const G4Step * step
Definition: Geant4StepHandler.h:48
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:71
dd4hep::sim::Geant4Action::c_name
const char * c_name() const
Access name of the action.
Definition: Geant4Action.h:284
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::Geant4TouchableHandler::path
std::string path() const
Helper: Access the placement path of a Geant4 touchable object as a string.
Definition: Geant4TouchableHandler.cpp:58
dd4hep::sim::TrackerCombine::firstSpotVolume
G4VPhysicalVolume * firstSpotVolume
Definition: Geant4SDActions.cpp:557
dd4hep::sim::Geant4ScintillatorCalorimeter
Class to implement the standard sensitive detector for scintillator calorimeters.
Definition: Geant4SDActions.cpp:434
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4FastSimHandler::avgPosition
Position avgPosition() const
Returns the pre-gflashspot position.
Definition: Geant4FastSimHandler.h:72
dd4hep::sim::Geant4Tracker::Hit::storePoint
Hit & storePoint(const G4Step *step, const G4StepPoint *point)
Store Geant4 point and step information into tracker hit structure.
Definition: Geant4Data.cpp:154
dd4hep::sim::Geant4OpticalTracker
Helper class to define properties of optical trackers. UNTESTED.
Definition: Geant4SDActions.cpp:147
dd4hep::sim::Geant4FastSimHandler::momentum
Momentum momentum() const
Return track momentum in DD4hep notation.
Definition: Geant4FastSimHandler.h:67
dd4hep::sim::TrackerCombine::mustSaveTrack
bool mustSaveTrack(const G4Track *tr) const
Helper function to decide if the hit has to be extracted and saved in the collection.
Definition: Geant4SDActions.cpp:627
dd4hep::sim::Geant4HitCollection::add
void add(TYPE *hit_pointer)
Add a new hit with a check, that the hit is of the same type.
Definition: Geant4HitCollection.h:333
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:121
dd4hep::sim::Geant4FastSimHandler::volume
G4VPhysicalVolume * volume() const
Definition: Geant4FastSimHandler.h:93
dd4hep::sim::TrackerCombine::e_cut
double e_cut
Definition: Geant4SDActions.cpp:559
dd4hep::sim::TrackerCombine::current
int current
Definition: Geant4SDActions.cpp:560
dd4hep::sim::Geant4HitHandler::track
const G4Track * track
Definition: Geant4HitHandler.h:45
dd4hep::sim::Geant4StepHandler::preTouchable
const G4VTouchable * preTouchable() const
Definition: Geant4StepHandler.h:141
dd4hep::sim::Geant4StepHandler::sd
G4VSensitiveDetector * sd(const G4StepPoint *p) const
Definition: Geant4StepHandler.h:164
Geant4OpticalCalorimeterAction
Sensitive detector meant for optical calorimeters.
dd4hep::sim::TrackerCombine::start_collecting
void start_collecting(const G4Track *track)
Start a new hit.
Definition: Geant4SDActions.cpp:568
dd4hep::sim::TrackerCombine::extractHit
void extractHit(Geant4HitCollection *collection)
Extract hit information and add the created hit to the collection.
Definition: Geant4SDActions.cpp:632
dd4hep::sim::Geant4Tracker::Hit::clear
Hit & clear()
Clear hit content.
Definition: Geant4Data.cpp:144
dd4hep::sim::Geant4SensitiveAction::processFastSim
virtual bool processFastSim(const Geant4FastSimSpot *spot, G4TouchableHistory *history) final
GFLASH/FastSim interface: Method for generating hit(s) using the information of the fast simulation s...
dd4hep::sim::Geant4HitData::MonteCarloContrib::time
double time
Timestamp when this energy was deposited.
Definition: Geant4Data.h:147
dd4hep::sim::Geant4Action::printM2
void printM2(const char *fmt,...) const
Support for messages with variable output level using output level-2.
Definition: Geant4Action.cpp:166
Geant4OpticalTrackerAction
Sensitive detector meant for photon detectors, will produce one hit per step for regular particles,...
dd4hep::DDSegmentation::Vector3D::Z
double Z
Definition: Segmentation.h:71
Geant4VoidSensitiveAction
Void Sensitive detector action to skip the processing of a detector without changing the entire DDG4 ...
dd4hep::sim::TrackerCombine
Geant4 sensitive detector combining all deposits of one G4Track within one sensitive element.
Definition: Geant4SDActions.cpp:553