DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
LCIOSDTestActions.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 : F.Gaede, DESY
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <Exceptions.h>
16 #include <IMPL/LCCollectionVec.h>
17 #include <IMPL/SimTrackerHitImpl.h>
18 #include <IMPL/SimCalorimeterHitImpl.h>
19 #include <IMPL/MCParticleImpl.h>
20 #include <UTIL/Operators.h>
21 #include <UTIL/ILDConf.h>
22 
24 #include <DDG4/Geant4Data.h>
25 #include <DDG4/Geant4StepHandler.h>
26 
27 #include <DD4hep/Printout.h>
28 #include <DD4hep/InstanceCount.h>
29 
30 using namespace dd4hep::sim;
31 using namespace dd4hep;
32 
34 namespace Tests {
35 
36  // copied from Geant4SDActions.cpp (why is this not a public class ??????)
37 
39 
44  template <typename T> class Geant4SensitiveAction : public Geant4Sensitive {
45  protected:
49 
50  // properties:
52 
53  public:
54  // typedef SimpleHit::Contribution HitContribution;
55  // Standard , initializing constructor
56  Geant4SensitiveAction(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref)
57  : Geant4Sensitive(ctxt,nam,det,description_ref), m_collectionID(0) {
58  declareProperty("detailedHitsStoring", _detailedHitsStoring ) ;
59  defineCollections();
61  }
65  }
67  virtual void defineCollections() override {}
69  virtual void begin(G4HCofThisEvent* hce) override {
70  Base::begin(hce);
71  }
73  virtual void end(G4HCofThisEvent* hce) override {
74  Base::end(hce);
75  }
77  virtual bool process(const G4Step* step, G4TouchableHistory* history) override {
78  return Base::process(step,history);
79  }
81  virtual bool processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) override {
82  return Base::processFastSim(spot,history);
83  }
85  virtual void clear(G4HCofThisEvent* hce) override {
86  Base::clear(hce);
87  }
88  };
89 
90 
91  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
92  // Geant4SensitiveAction<SimpleTracker>
93  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94 
96 
101  class LcioTestTracker {};
102 
105  m_collectionID = Base::defineCollection<lcio::SimTrackerHitImpl>(m_sensitive.readout().name());
106  }
107 
109  template <> bool Geant4SensitiveAction<LcioTestTracker>::process(const G4Step* step,G4TouchableHistory* /*hist*/ ) {
110  Geant4StepHandler h(step);
111 
112  Position prePos = h.prePos();
113  Position postPos = h.postPos();
114  Position direction = postPos - prePos;
115  Position position = mean_direction(prePos,postPos);
116  double hit_len = direction.R();
117 
118  if (hit_len > 0) {
119  double new_len = mean_length(h.preMom(),h.postMom())/hit_len;
120  direction *= new_len/hit_len;
121  }
122 
123  lcio::SimTrackerHitImpl* hit = new lcio::SimTrackerHitImpl;
124  // (h.track->GetTrackID(),
125  // h.track->GetDefinition()->GetPDGEncoding(),
126  // step->GetTotalEnergyDeposit(),
127  // h.track->GetGlobalTime());
128 
129  // HitContribution contrib = Hit::extractContribution(step);
130 
131  VolumeID cell = volumeID( step ) ;
132  hit->setCellID0( cell & 0xffffffff ) ;
133  hit->setCellID1( ( cell >> 32 ) & 0xffffffff ) ;
134 
135  printout(INFO,"LcioTestTracker","%s> Add hit with deposit:%f Pos:%f %f %f - cellID0: 0x%x cellID1: 0x%x",
136  c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z() , hit->getCellID0() ,hit->getCellID1() );
137 
138  double pos[3] = {position.x(), position.y(), position.z()};
139  hit->setPosition( pos ) ;
140 
141  // hit->energyDeposit = contrib.deposit ;
142  // hit->position = position;
143  // hit->momentum = direction;
144  // hit->length = hit_len;
145  collection(m_collectionID)->add(hit);
146  return true;
147  }
148 
150  template <> bool
152  G4TouchableHistory* /*hist*/ )
153  {
154  except("Not implemented");
155  return true;
156  }
157 
158 
160 } // namespace
161 
162 #include <DDG4/Factories.h>
Tests::Geant4SensitiveAction::m_collectionID
size_t m_collectionID
Collection identifiers.
Definition: LCIOSDTestActions.cpp:48
Tests::Geant4SensitiveAction::clear
virtual void clear(G4HCofThisEvent *hce) override
G4VSensitiveDetector interface: Method invoked if the event was aborted.
Definition: LCIOSDTestActions.cpp:85
dd4hep::sim::Geant4SensitiveAction::defineCollections
virtual void defineCollections()
Define collections created by this sensitivie action object.
Tests::Geant4SensitiveAction::process
virtual bool process(const G4Step *step, G4TouchableHistory *history) override
G4VSensitiveDetector interface: Method for generating hit(s) using the G4Step object.
Definition: LCIOSDTestActions.cpp:77
dd4hep::sim::Geant4StepHandler::prePos
Position prePos() const
Returns the pre-step position.
Definition: Geant4StepHandler.h:84
Tests::Geant4SensitiveAction::defineCollections
virtual void defineCollections() override
Define collections created by this sensitivie action object.
Definition: LCIOSDTestActions.cpp:67
Tests::LcioTestTrackerAction
Geant4SensitiveAction< LcioTestTracker > LcioTestTrackerAction
Definition: LCIOSDTestActions.cpp:159
dd4hep::sim::Geant4StepHandler::preMom
Momentum preMom() const
Definition: Geant4StepHandler.h:127
Geant4SensDetAction.h
Tests::Geant4SensitiveAction::Geant4SensitiveAction
Geant4SensitiveAction(Geant4Context *ctxt, const std::string &nam, DetElement det, Detector &description_ref)
Definition: LCIOSDTestActions.cpp:56
dd4hep::sim::Geant4StepHandler::postMom
Momentum postMom() const
Definition: Geant4StepHandler.h:131
Tests::Geant4SensitiveAction::_detailedHitsStoring
bool _detailedHitsStoring
Definition: LCIOSDTestActions.cpp:51
Tests::Geant4SensitiveAction::end
virtual void end(G4HCofThisEvent *hce) override
G4VSensitiveDetector interface: Method invoked at the end of each event.
Definition: LCIOSDTestActions.cpp:73
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Geant4Data.h
Geant4StepHandler.h
dd4hep::sim::Geant4FastSimSpot
Spot definition for fast simulation and GFlash.
Definition: Geant4FastSimSpot.h:71
Tests::Geant4SensitiveAction
Deprecated: Simple SensitiveAction class ...
Definition: LCIOSDTestActions.cpp:44
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::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
Tests::Geant4SensitiveAction::~Geant4SensitiveAction
virtual ~Geant4SensitiveAction()
Default destructor.
Definition: LCIOSDTestActions.cpp:63
Tests::LcioTestTracker
Deprecated: Simple SensitiveAction class ...
Definition: LCIOSDTestActions.cpp:101
dd4hep::sim::Geant4StepHandler::postPos
Position postPos() const
Returns the post-step position.
Definition: Geant4StepHandler.h:93
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
Factories.h
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
Tests::Geant4SensitiveAction::processFastSim
virtual bool processFastSim(const Geant4FastSimSpot *spot, G4TouchableHistory *history) override
GFlash/FastSim interface: Method for generating hit(s) using the G4Step object.
Definition: LCIOSDTestActions.cpp:81
DECLARE_GEANT4SENSITIVE_NS
#define DECLARE_GEANT4SENSITIVE_NS(name_space, name)
Definition: Factories.h:201
Tests
Test namespace.
Definition: LCIOSDTestActions.cpp:34
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
ROOT::Math::mean_length
double mean_length(const dd4hep::Position &p1, const dd4hep::Position &p2)
Calculate the mean length of two vectors.
Definition: Objects.h:515
ROOT::Math::mean_direction
dd4hep::Position mean_direction(const dd4hep::Position &p1, const dd4hep::Position &p2)
Calculate the mean direction of two vectors.
Definition: Objects.h:519
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4Sensitive
The base class for Geant4 sensitive detector actions implemented by users.
Definition: Geant4SensDetAction.h:121
InstanceCount.h
Tests::Geant4SensitiveAction::begin
virtual void begin(G4HCofThisEvent *hce) override
G4VSensitiveDetector interface: Method invoked at the begining of each event.
Definition: LCIOSDTestActions.cpp:69
Printout.h
Tests::Geant4SensitiveAction::Base
Geant4Sensitive Base
Definition: LCIOSDTestActions.cpp:46
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::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
Exceptions.h