DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Data.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/InstanceCount.h>
17 
18 #include <DDG4/Geant4Data.h>
19 #include <DDG4/Geant4StepHandler.h>
21 
22 // Geant4 include files
23 #include <G4Step.hh>
24 #include <G4Allocator.hh>
25 #include <G4OpticalPhoton.hh>
26 
27 using namespace dd4hep::sim;
28 
32 }
33 
37 }
38 
42 }
43 
47 }
48 
51 }
52 
56 }
57 
61 }
62 
65  Geant4StepHandler h(step);
66  double deposit =
67  (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
68  const G4ThreeVector& pre = h.prePosG4();
69  const G4ThreeVector& post = h.postPosG4();
70  G4ThreeVector mom = h.track->GetMomentum();
71  double len = (post-pre).mag() ;
72  double position[] = { (pre.x()+post.x())/2.0,(pre.y()+post.y())/2.0,(pre.z()+post.z())/2.0 };
73  double momentum[] = { mom.x(), mom.y(), mom.z() };
74  return Contribution(h.trkID(), h.trkPdgID(), deposit, h.trkTime(), len, position, momentum);
75 }
76 
78 Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* step, bool ApplyBirksLaw) {
79  Geant4StepHandler h(step);
80  if ( ApplyBirksLaw == true ) h.doApplyBirksLaw();
81  double deposit =
82  (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
83  const G4ThreeVector& pre = h.prePosG4();
84  const G4ThreeVector& post = h.postPosG4();
85  G4ThreeVector mom = h.track->GetMomentum();
86  double length = (post-pre).mag() ;
87  double momentum[] = { mom.x(), mom.y(), mom.z() };
88  double position[] = { (pre.x()+post.x())/2.0,(pre.y()+post.y())/2.0,(pre.z()+post.z())/2.0 };
89  return Contribution(h.trkID(), h.trkPdgID(), deposit, h.trkTime(), length, position, momentum);
90 }
91 
94  Geant4FastSimHandler h(spot);
95  const G4Track* t = spot->primary;
96  G4ThreeVector mom = t->GetMomentum();
97  G4ThreeVector pos = h.avgPositionG4();
98  double position[] = { pos.x(), pos.y(), pos.z() };
99  double momentum[] = { mom.x(), mom.y(), mom.z() };
100  return Contribution( h.trkID(), h.trkPdgID(), h.energy(), h. trkTime(), 0e0, position, momentum);
101 }
102 
106 }
107 
109 Geant4Tracker::Hit::Hit(int track_id, int pdg_id, double deposit, double time_stamp,
110  double len, const Position& pos, const Direction& mom)
111  : Geant4HitData(), position(pos), momentum(mom), length(len), energyDeposit(deposit),
112  truth(track_id, pdg_id, deposit, time_stamp, len, pos, mom)
113 {
114  g4ID = track_id;
116 }
117 
119 Geant4Tracker::Hit::Hit(const Geant4HitData::Contribution& contrib, const Direction& mom, double depo)
120  : Geant4HitData(), position(contrib.x, contrib.y, contrib.z),
121  momentum(mom), length(contrib.length), energyDeposit(depo), truth(contrib)
122 {
123  g4ID = truth.trackID;
125 }
126 
130 }
131 
134  if ( &c != this ) {
135  energyDeposit = c.energyDeposit;
136  position = c.position;
137  momentum = c.momentum;
138  length = c.length;
139  truth = c.truth;
140  }
141 }
142 
145  position.SetXYZ(0, 0, 0);
146  momentum.SetXYZ(0, 0, 0);
147  energyDeposit = 0.0;
148  length = 0.0;
149  truth.clear();
150  return *this;
151 }
152 
154 Geant4Tracker::Hit& Geant4Tracker::Hit::storePoint(const G4Step* step, const G4StepPoint* pnt) {
155  G4Track* trk = step->GetTrack();
156  G4ThreeVector trm = trk->GetMomentum();
157  G4ThreeVector pos = pnt->GetPosition();
158  G4ThreeVector mom = pnt->GetMomentum();
159  double dep = step->GetTotalEnergyDeposit();
160 
161  truth.deposit = dep;
162  truth.trackID = trk->GetTrackID();
163  truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
164  truth.time = trk->GetGlobalTime();
165  truth.setPosition(pos.x(), pos.y(), pos.z());
166  truth.setMomentum(trm.x(), trm.y(), trm.z());
167 
168  energyDeposit = dep;
169  position.SetXYZ(pos.x(), pos.y(), pos.z());
170  momentum.SetXYZ(mom.x(), mom.y(), mom.z());
171  length = 0;
172  return *this;
173 }
174 
177  const G4Track* trk = spot->primary;
178  double dep = spot->hit->GetEnergy();
179  G4ThreeVector trm = trk->GetMomentum();
180  G4ThreeVector pos = spot->hitPosition();
181  G4ThreeVector mom = trk->GetMomentum().unit() * dep;
182 
183  this->truth.deposit = dep;
184  this->truth.trackID = trk->GetTrackID();
185  this->truth.time = trk->GetGlobalTime();
186  this->truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
187  this->truth.setPosition(pos.x(), pos.y(), pos.z());
188  this->truth.setMomentum(trm.x(), trm.y(), trm.z());
189 
190  this->energyDeposit = dep;
191  this->position.SetXYZ(pos.x(), pos.y(), pos.z());
192  this->momentum.SetXYZ(mom.x(), mom.y(), mom.z());
193  this->length = 0;
194  return *this;
195 }
196 
200 }
201 
203 Geant4Calorimeter::Hit::Hit(const Position& pos) : position(pos) {
205 }
206 
210 }
dd4hep::sim::Geant4Tracker::Hit::momentum
Direction momentum
Hit direction.
Definition: Geant4Data.h:270
dd4hep::sim::SimpleRun::SimpleRun
SimpleRun()
Default constructor.
Definition: Geant4Data.cpp:30
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
dd4hep::sim::Geant4HitData::Contribution
MonteCarloContrib Contribution
Definition: Geant4Data.h:231
dd4hep::sim::Geant4Calorimeter::Hit::~Hit
virtual ~Hit()
Default destructor.
Definition: Geant4Data.cpp:208
dd4hep::sim::Geant4FastSimHandler
Helper class to ease the extraction of information from a G4FastSimSpot object.
Definition: Geant4FastSimHandler.h:43
dd4hep::sim::Geant4Tracker::Hit::copyFrom
void copyFrom(const Hit &c)
Explicit assignment operation.
Definition: Geant4Data.cpp:133
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Direction
Position Direction
Definition: Defs.h:26
Geant4Data.h
dd4hep::sim::Geant4Tracker::Hit::~Hit
virtual ~Hit()
Default destructor.
Definition: Geant4Data.cpp:128
Geant4StepHandler.h
dd4hep::sim::Geant4HitHandler::trkID
int trkID() const
Access the G4 track ID.
Definition: Geant4HitHandler.h:73
dd4hep::sim::Geant4StepHandler::prePosG4
const G4ThreeVector & prePosG4() const
Returns the pre-step position as a G4ThreeVector.
Definition: Geant4StepHandler.h:89
dd4hep::sim::Geant4HitHandler::trackDef
G4ParticleDefinition * trackDef() const
Definition: Geant4HitHandler.h:66
dd4hep::sim::Geant4HitHandler::trkTime
double trkTime() const
Definition: Geant4HitHandler.h:80
dd4hep::sim::Geant4FastSimSpot
Spot definition for fast simulation and GFlash.
Definition: Geant4FastSimSpot.h:71
dd4hep::sim::Geant4HitHandler::trkEnergy
double trkEnergy() const
Definition: Geant4HitHandler.h:83
dd4hep::sim::Geant4HitData::~Geant4HitData
virtual ~Geant4HitData()
Default destructor.
Definition: Geant4Data.cpp:59
dd4hep::sim::Geant4FastSimSpot::hit
const G4FastHit * hit
Definition: Geant4FastSimSpot.h:118
dd4hep::sim::Geant4StepHandler
Helper class to ease the extraction of information from a G4Step object.
Definition: Geant4StepHandler.h:46
dd4hep::sim::Geant4FastSimSpot::primary
const G4Track * primary
Definition: Geant4FastSimSpot.h:120
dd4hep::sim::Geant4Tracker::Hit
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:263
dd4hep::sim::SimpleEvent::SimpleEvent
SimpleEvent()
Default constructor.
Definition: Geant4Data.cpp:40
dd4hep::sim::Geant4Tracker::Hit::length
double length
Length of the track segment contributing to this hit.
Definition: Geant4Data.h:272
dd4hep::sim::Geant4HitData::g4ID
long g4ID
Original Geant 4 track identifier of the creating track (debugging)
Definition: Geant4Data.h:128
dd4hep::sim::Geant4FastSimSpot::hitPosition
G4ThreeVector hitPosition() const
Spot's hit position.
Definition: Geant4FastSimSpot.h:83
dd4hep::sim::Geant4Tracker::Hit::Hit
Hit()
Default constructor.
Definition: Geant4Data.cpp:104
dd4hep::sim::Geant4HitData
Base class for geant4 hit structures used by the default DDG4 sensitive detector implementations.
Definition: Geant4Data.h:110
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::SimpleRun::~SimpleRun
virtual ~SimpleRun()
Default destructor.
Definition: Geant4Data.cpp:35
dd4hep::sim::Geant4Calorimeter::Hit::Hit
Hit()
Default constructor (for ROOT)
Definition: Geant4Data.cpp:198
Geant4FastSimHandler.h
dd4hep::sim::Geant4FastSimHandler::avgPositionG4
G4ThreeVector avgPositionG4() const
Returns the post-step position as a G4ThreeVector.
Definition: Geant4FastSimHandler.h:77
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
dd4hep::sim::Geant4HitData::Geant4HitData
Geant4HitData()
Default constructor.
Definition: Geant4Data.cpp:54
dd4hep::sim::Geant4HitHandler::trkPdgID
int trkPdgID() const
Definition: Geant4HitHandler.h:69
dd4hep::sim::Geant4StepHandler::postPosG4
const G4ThreeVector & postPosG4() const
Returns the post-step position as a G4ThreeVector.
Definition: Geant4StepHandler.h:98
dd4hep::sim::Geant4HitData::MonteCarloContrib::trackID
int trackID
Geant 4 Track identifier.
Definition: Geant4Data.h:141
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4FastSimHandler::energy
double energy() const
Returns total energy deposit.
Definition: Geant4FastSimHandler.h:63
dd4hep::sim::DataExtension::~DataExtension
virtual ~DataExtension()
Default destructor.
Definition: Geant4Data.cpp:50
dd4hep::sim::Geant4HitData::extractContribution
static Contribution extractContribution(const G4Step *step)
Extract the MC contribution for a given hit from the step information.
Definition: Geant4Data.cpp:64
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::Geant4HitData::MonteCarloContrib
Utility class describing the monte carlo contribution of a given particle to a hit.
Definition: Geant4Data.h:138
dd4hep::sim::Geant4StepHandler::doApplyBirksLaw
void doApplyBirksLaw(void)
Set applyBirksLaw to ture.
Definition: Geant4StepHandler.h:196
G4FastHit::GetEnergy
G4double GetEnergy() const
Get energy.
Definition: Geant4FastSimSpot.h:39
dd4hep::sim::Geant4Tracker::Hit::energyDeposit
double energyDeposit
Energy deposit in the tracker hit.
Definition: Geant4Data.h:274
dd4hep::sim::Geant4HitHandler::track
const G4Track * track
Definition: Geant4HitHandler.h:45
InstanceCount.h
dd4hep::sim::Geant4StepHandler::totalEnergy
double totalEnergy() const
Returns total energy deposit.
Definition: Geant4StepHandler.h:77
Printout.h
dd4hep::sim::Geant4Tracker::Hit::clear
Hit & clear()
Clear hit content.
Definition: Geant4Data.cpp:144
dd4hep::sim::SimpleEvent::~SimpleEvent
virtual ~SimpleEvent()
Default destructor.
Definition: Geant4Data.cpp:45