DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Data.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/Printout.h"
17 #include "DD4hep/InstanceCount.h"
18 #include "DDG4/Geant4Data.h"
19 #include "DDG4/Geant4StepHandler.h"
20 
21 // Geant4 include files
22 #include "G4Step.hh"
23 #include "G4Allocator.hh"
24 #include "G4OpticalPhoton.hh"
25 
26 using namespace std;
27 using namespace DD4hep;
28 using namespace DD4hep::Simulation;
29 
31 SimpleRun::SimpleRun()
32  : runID(-1), numEvents(0) {
34 }
35 
39 }
40 
43  : runID(-1), eventID(-1) {
45 }
46 
50 }
51 
54 }
55 
58  : cellID(0), flag(0), g4ID(0), extension() {
60 }
61 
65 }
66 
69  Geant4StepHandler h(step);
70  double deposit =
71  (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
72  const G4ThreeVector& pre = h.prePosG4();
73  const G4ThreeVector& post = h.postPosG4();
74  float pos[] = {float((pre.x()+post.x())/2.0),float((pre.y()+post.y())/2.0),float((pre.z()+post.z())/2.0) };
75  Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),pos);
76  return contrib;
77 }
79 Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* step, bool ApplyBirksLaw) {
80  Geant4StepHandler h(step);
81  if ( ApplyBirksLaw == true ) h.doApplyBirksLaw();
82  double deposit =
83  (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
84  const G4ThreeVector& pre = h.prePosG4();
85  const G4ThreeVector& post = h.postPosG4();
86  float pos[] = {float((pre.x()+post.x())/2.0),float((pre.y()+post.y())/2.0),float((pre.z()+post.z())/2.0) };
87  Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),pos);
88  return contrib;
89 }
90 
93 : Geant4HitData(), position(), momentum(), length(0.0), truth(), energyDeposit(0.0) {
95 }
96 
98 Geant4Tracker::Hit::Hit(int track_id, int pdg_id, double deposit, double time_stamp)
99 : Geant4HitData(), position(), momentum(), length(0.0), truth(track_id, pdg_id, deposit, time_stamp), energyDeposit(deposit) {
101 }
102 
106 }
107 
110  if ( &c != this ) {
111  position = c.position;
112  momentum = c.momentum;
113  length = c.length;
114  truth = c.truth;
115  }
116  return *this;
117 }
118 
121  position.SetXYZ(0, 0, 0);
122  momentum.SetXYZ(0, 0, 0);
123  length = 0.0;
124  truth.clear();
125  return *this;
126 }
127 
129 Geant4Tracker::Hit& Geant4Tracker::Hit::storePoint(const G4Step* step, const G4StepPoint* pnt) {
130  G4Track* trk = step->GetTrack();
131  G4ThreeVector pos = pnt->GetPosition();
132  G4ThreeVector mom = pnt->GetMomentum();
133 
134  truth.trackID = trk->GetTrackID();
135  truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
136  truth.deposit = step->GetTotalEnergyDeposit();
137  truth.time = trk->GetGlobalTime();
138  position.SetXYZ(pos.x(), pos.y(), pos.z());
139  momentum.SetXYZ(mom.x(), mom.y(), mom.z());
140  length = 0;
141  return *this;
142 }
143 
146 : Geant4HitData(), position(), truth(), energyDeposit(0) {
148 }
149 
152 : Geant4HitData(), position(pos), truth(), energyDeposit(0) {
154 }
155 
159 }
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:228
double length
Length of the track segment contributing to this hit.
Definition: Geant4Data.h:235
Direction momentum
Hit direction.
Definition: Geant4Data.h:233
static void decrement(T *)
Decrement count according to type information.
virtual ~SimpleRun()
Default destructor.
Definition: Geant4Data.cpp:37
const G4ThreeVector & postPosG4() const
Returns the post-step position as a G4ThreeVector.
virtual ~DataExtension()
Default destructor.
Definition: Geant4Data.cpp:53
Helper class to ease the extraction of information from a G4Step object.
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:237
not persisten. ROOT cannot handle
Definition: Geant4Data.h:140
Hit & clear()
Clear hit content.
Definition: Geant4Data.cpp:120
virtual ~Hit()
Default destructor.
Definition: Geant4Data.cpp:104
Hit & storePoint(const G4Step *step, const G4StepPoint *point)
Store Geant4 point and step information into tracker hit structure.
Definition: Geant4Data.cpp:129
Position position
Hit position.
Definition: Geant4Data.h:231
Hit & operator=(const Hit &c)
Assignment operator.
Definition: Geant4Data.cpp:109
static Contribution extractContribution(const G4Step *step)
Extract the MC contribution for a given hit from the step information.
Definition: Geant4Data.cpp:68
G4ParticleDefinition * trackDef() const
ROOT::Math::XYZVector Position
Definition: Objects.h:75
virtual ~Geant4HitData()
Default destructor.
Definition: Geant4Data.cpp:63
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Hit()
Default constructor (for ROOT)
Definition: Geant4Data.cpp:145
double totalEnergy() const
Returns total energy deposit.
void doApplyBirksLaw(void)
Set applyBirksLaw to ture.
Geant4HitData()
Default constructor.
Definition: Geant4Data.cpp:57
SimpleEvent()
Default constructor.
Definition: Geant4Data.cpp:42
const G4ThreeVector & prePosG4() const
Returns the pre-step position as a G4ThreeVector.
virtual ~SimpleEvent()
Default destructor.
Definition: Geant4Data.cpp:48
virtual ~Hit()
Default destructor.
Definition: Geant4Data.cpp:157
Base class for geant4 hit structures used by the default DDG4 sensitive detector implementations.
Definition: Geant4Data.h:108