ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
TrackWriteFastSim
src
TrackFastSimSD.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Class header
6
#include "
TrackWriteFastSim/TrackFastSimSD.h
"
7
8
// Athena headers
9
#include "
HitManagement/HitCollectionMap.h
"
10
#include "
MCTruth/AtlasG4EventUserInfo.h
"
11
#include "
MCTruth/TrackHelper.h
"
12
13
// Geant4 headers
14
#include "G4ChargedGeantino.hh"
15
#include "G4DynamicParticle.hh"
16
#include "G4EventManager.hh"
17
#include "G4Geantino.hh"
18
#include "G4Track.hh"
19
#include "G4VPhysicalVolume.hh"
20
#include "G4VSolid.hh"
21
22
// STL headers
23
#include <cmath>
24
#include <memory>
25
26
TrackFastSimSD::TrackFastSimSD
(
const
std::string& name,
const
std::string& outputCollectionName,
const
int
SD_type)
27
: G4VSensitiveDetector( name )
28
,
m_outputCollectionName
( outputCollectionName )
29
,
m_SD_type
( SD_type )
30
{
31
}
32
33
// Initialize from G4.
34
void
TrackFastSimSD::Initialize
(G4HCofThisEvent *)
35
{
36
m_trackRecordCollection
=
getTrackRecordCollection
();
37
}
38
39
G4bool
TrackFastSimSD::ProcessHits
(G4Step* aStep,G4TouchableHistory* )
40
{
41
if
(!
m_SD_type
) {
return
false
; }
42
const
G4StepPoint *preStep=aStep->GetPreStepPoint();
43
const
G4VPhysicalVolume *preVol=preStep->GetPhysicalVolume();
44
const
G4StepPoint *postStep=aStep->GetPostStepPoint();
45
const
G4VPhysicalVolume *postVol=postStep->GetPhysicalVolume();
46
47
if
(preVol==postVol) {
return
false
; }
48
49
const
G4Track *track(aStep->GetTrack());
50
51
// PDG Code
52
int
pdgcode = (track->GetDefinition())?track->GetDefinition()->GetPDGEncoding():0;
53
if
(track->GetDefinition() == G4Geantino::Definition() ) pdgcode=999;
54
if
(track->GetDefinition() == G4ChargedGeantino::Definition() ) pdgcode=998;
55
56
// Position and Momentum
57
G4ThreeVector pos=postStep->GetPosition();
58
G4ThreeVector mom=postStep->GetMomentum();
59
60
if
(
m_SD_type
==2)
61
{
62
// need to get the local position
63
const
G4TouchableHistory* touchHist =
static_cast<
const
G4TouchableHistory*
>
(preStep->GetTouchable());
64
const
G4AffineTransform trans = track->GetTouchable()->GetHistory()->GetTopTransform();
// trans from global to local
65
G4ThreeVector localPos=trans.TransformPoint(pos);
66
G4ThreeVector localMom=mom;
67
trans.ApplyAxisTransform(localMom);
// rotate momentum as needed
68
const
G4VSolid *shape= touchHist->GetSolid();
69
const
G4ThreeVector normal=shape->SurfaceNormal(localPos);
70
// check if particle is entering. if it is extiting don't record it.
71
if
(normal.dot(localPos)>=0.)
return
false
;
72
}
73
74
// Energy
75
const
double
ener=postStep->GetTotalEnergy();
76
77
// Time
78
const
double
time=postStep->GetGlobalTime();
79
80
// Barcode
81
TrackHelper
trHelp(track);
82
const
int
barcode = trHelp.
GetBarcode
();
// FIXME barcode based
83
const
int
id
= trHelp.
GetUniqueID
();
84
const
int
status = trHelp.
GetStatus
();
85
86
//create the TimedTrackRecord
87
return
AddHit
(pdgcode,
88
status,
89
ener,
90
mom,
91
pos,
92
time,
93
barcode,
// FIXME barcode based
94
id
,
95
preVol->GetName());
96
}
97
98
void
TrackFastSimSD::WriteTrack
(
const
G4Track* track,
const
bool
originPos,
const
bool
originMom)
99
{
100
if
(!track) { G4cout <<
"ERROR: the track pointer was zero"
<< G4endl;
return
; }
101
102
G4VPhysicalVolume *preVol=track->GetVolume();
103
104
const
int
pdgcode = (track->GetDefinition())?track->GetDefinition()->GetPDGEncoding():0;
105
106
const
G4ThreeVector pos = originPos?track->GetVertexPosition():track->GetPosition();
107
const
double
ener=originMom?(track->GetVertexKineticEnergy()+track->GetDynamicParticle()->GetMass()):track->GetTotalEnergy();
108
G4ThreeVector mom = track->GetMomentum();
109
if
(originMom){
110
double
mommag = std::sqrt(std::pow(ener,2)-std::pow(track->GetDynamicParticle()->GetMass(),2));
111
mom = track->GetVertexMomentumDirection()*mommag;
112
}
113
114
const
double
time=track->GetGlobalTime();
115
TrackHelper
trHelp(track);
116
const
int
barcode = trHelp.
GetBarcode
();
// FIXME barcode based
117
const
int
id
= trHelp.
GetUniqueID
();
118
const
int
status = trHelp.
GetStatus
();
119
120
//create the TimedTrackRecord
121
AddHit
(pdgcode,
122
status,
123
ener,
124
mom,
125
pos,
126
time,
127
barcode,
// FIXME barcode based
128
id
,
129
preVol ? preVol->GetName() :
"Unknown"
);
130
}
131
132
TrackRecordCollection
*
TrackFastSimSD::getTrackRecordCollection
()
const
133
{
134
auto
* eventManager = G4EventManager::GetEventManager();
135
if
(!eventManager) {
136
return
nullptr
;
137
}
138
139
auto
* eventInfo =
140
dynamic_cast<
AtlasG4EventUserInfo
*
>
(eventManager->GetUserInformation());
141
if
(!eventInfo) {
142
return
nullptr
;
143
}
144
145
std::shared_ptr<HitCollectionMap> hitCollections = eventInfo->
GetHitCollectionMap
();
146
return
hitCollections ? hitCollections->Find<
TrackRecordCollection
>(
m_outputCollectionName
)
147
:
nullptr
;
148
}
AtlasG4EventUserInfo.h
HitCollectionMap.h
TrackFastSimSD.h
TrackHelper.h
TrackRecordCollection
AtlasHitsVector< TrackRecord > TrackRecordCollection
Definition
TrackRecordCollection.h:12
AtlasG4EventUserInfo
This class is attached to G4Event objects as UserInformation.
Definition
AtlasG4EventUserInfo.h:26
AtlasG4EventUserInfo::GetHitCollectionMap
std::shared_ptr< HitCollectionMap > GetHitCollectionMap() const
Get the HitCollectionMap object with shared ownership.
Definition
AtlasG4EventUserInfo.h:82
TrackFastSimSD::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition
TrackFastSimSD.cxx:39
TrackFastSimSD::AddHit
bool AddHit(Args &&... args)
Templated method to stuff a single hit into the sensitive detector class.
Definition
TrackFastSimSD.h:38
TrackFastSimSD::m_trackRecordCollection
TrackRecordCollection * m_trackRecordCollection
Definition
TrackFastSimSD.h:52
TrackFastSimSD::m_SD_type
int m_SD_type
Definition
TrackFastSimSD.h:53
TrackFastSimSD::TrackFastSimSD
TrackFastSimSD(const std::string &name, const std::string &outputCollectionName, const int SD_type=0)
Definition
TrackFastSimSD.cxx:26
TrackFastSimSD::getTrackRecordCollection
TrackRecordCollection * getTrackRecordCollection() const
Definition
TrackFastSimSD.cxx:132
TrackFastSimSD::Initialize
void Initialize(G4HCofThisEvent *) override final
Definition
TrackFastSimSD.cxx:34
TrackFastSimSD::m_outputCollectionName
std::string m_outputCollectionName
Definition
TrackFastSimSD.h:50
TrackFastSimSD::WriteTrack
void WriteTrack(const G4Track *, const bool, const bool)
Definition
TrackFastSimSD.cxx:98
TrackHelper
Definition
TrackHelper.h:20
TrackHelper::GetBarcode
int GetBarcode() const
Return the truth barcode/id/status used for detector output.
Definition
TrackHelper.cxx:57
TrackHelper::GetUniqueID
int GetUniqueID() const
Definition
TrackHelper.cxx:66
TrackHelper::GetStatus
int GetStatus() const
Definition
TrackHelper.cxx:75
Generated on
for ATLAS Offline Software by
1.17.0