Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// $Id:$
//====================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
// Framework include files
#include "DDG4/Geant4Hits.h"
// Geant4 include files
#include "G4Allocator.hh"
#include "G4ParticleDefinition.hh"
#include "G4ChargedGeantino.hh"
#include "G4OpticalPhoton.hh"
#include "G4Geantino.hh"
// C/C++ include files
#include <iostream>
using namespace std;
using namespace DD4hep::Simulation;
/// Check if the Geant4 track is a Geantino
bool Geant4Hit::isGeantino(G4Track* track) {
if ( track ) {
G4ParticleDefinition* def = track->GetDefinition();
if ( def == G4ChargedGeantino::Definition() )
return true;
if ( def != G4Geantino::Definition() ) {
return true;
}
}
return false;
}
Geant4Hit::Contribution Geant4Hit::extractContribution(G4Step* step) {
G4Track* trk = step->GetTrack();
double energy_deposit = (trk->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition())
? trk->GetTotalEnergy() : step->GetTotalEnergyDeposit();
Contribution contrib(trk->GetTrackID(),
trk->GetDefinition()->GetPDGEncoding(),
energy_deposit,
trk->GetGlobalTime());
return contrib;
}
/// Create tracker hit
Geant4Hit* Geant4Hit::createTrackerHit(G4Step* step) {
G4Track* trk = step->GetTrack();
G4StepPoint* pre = step->GetPreStepPoint();
G4StepPoint* post = step->GetPostStepPoint();
G4ThreeVector prePos = pre->GetPosition();
G4ThreeVector postPos = post->GetPosition();
G4ThreeVector direction = (postPos - prePos);
G4ThreeVector position = 0.5 * (prePos + postPos);
double hit_len = direction.mag();
double avgMom = (pre->GetMomentum().mag() + post->GetMomentum().mag()) / 2;
if (hit_len > 0)
direction.setMag(avgMom);
else
cerr << "prePos - postPos = 0 --> " << prePos << " | " << postPos << endl;
Geant4TrackerHit* hit = new Geant4TrackerHit(trk->GetTrackID(),
trk->GetDefinition()->GetPDGEncoding(),
step->GetTotalEnergyDeposit(),
trk->GetGlobalTime());
hit->position.set(position.x(),position.y(),position.z());
hit->momentum.set(direction.x(),direction.y(),direction.z());
hit->length = hit_len;
return hit;
}
static G4Allocator<Geant4TrackerHit> TrackerHitAllocator;
/// Default constructor
Geant4TrackerHit::Geant4TrackerHit() : Geant4Hit(), position(), momentum(), length(0.0), truth()
{
}
/// Standard initializing constructor
Geant4TrackerHit::Geant4TrackerHit(int track_id, int pdg_id, double deposit, double time_stamp)
: Geant4Hit(), position(), momentum(), length(0.0), truth(track_id, pdg_id, deposit, time_stamp)
{
}
/// Assignment operator
Geant4TrackerHit& Geant4TrackerHit::operator=(const Geant4TrackerHit& c) {
position = c.position;
momentum = c.momentum;
length = c.length;
truth = c.truth;
return *this;
}
/// Clear hit content
Geant4TrackerHit& Geant4TrackerHit::clear() {
position.set(0,0,0);
momentum.set(0,0,0);
length = 0.0;
truth.clear();
return *this;
}
/// Store Geant4 point and step information into tracker hit structure.
Geant4TrackerHit& Geant4TrackerHit::storePoint(G4Step* step, G4StepPoint* pnt) {
G4Track* trk = step->GetTrack();
G4ThreeVector pos = pnt->GetPosition();
G4ThreeVector mom = pnt->GetMomentum();
truth.trackID = trk->GetTrackID();
truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
truth.deposit = step->GetTotalEnergyDeposit();
truth.time = trk->GetGlobalTime();
position.set(pos.x(),pos.y(),pos.z());
momentum.set(mom.x(),mom.y(),mom.z());
length = 0;
return *this;
}
/// Geant4 required object allocator
void* Geant4TrackerHit::operator new(size_t) {
return TrackerHitAllocator.MallocSingle();
}
/// Geat4 required object destroyer
void Geant4TrackerHit::operator delete(void *p) {
TrackerHitAllocator.FreeSingle((Geant4TrackerHit*)p);
}
static G4Allocator<Geant4CalorimeterHit> CalorimeterHitAllocator;
/// Standard constructor
Geant4CalorimeterHit::Geant4CalorimeterHit(const Position& pos)
: Geant4Hit(), position(pos), truth(), energyDeposit(0)
{
}
/// Geant4 required object allocator
void* Geant4CalorimeterHit::operator new(size_t) {
return CalorimeterHitAllocator.MallocSingle();
}
/// Geat4 required object destroyer
void Geant4CalorimeterHit::operator delete(void *p) {
CalorimeterHitAllocator.FreeSingle((Geant4CalorimeterHit*)p);
}