ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4UserActions
src
AthenaDebugStackingAction.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// System includes
6
#include <iostream>
7
#include <memory>
8
#include <string>
9
10
// Local includes
11
#include "
AthenaDebugStackingAction.h
"
12
13
// Truth includes
14
#include "
MCTruth/PrimaryParticleInformation.h
"
15
#include "
MCTruth/TrackInformation.h
"
16
#include "
MCTruth/TrackBarcodeInfo.h
"
17
#include "
MCTruth/AtlasG4EventUserInfo.h
"
18
19
// Geant4 includes
20
#include "G4Track.hh"
21
#include "G4Event.hh"
22
#include "G4EventManager.hh"
23
24
#include "
CxxUtils/checker_macros.h
"
25
#include "
CxxUtils/fpcompare.h
"
26
27
namespace
G4UA
28
{
29
30
//---------------------------------------------------------------------------
31
// Constructor
32
//---------------------------------------------------------------------------
33
AthenaDebugStackingAction::AthenaDebugStackingAction
(
const
Config
& config):
34
AthenaStackingAction
(config) {}
35
36
//---------------------------------------------------------------------------
37
// Classify a new track
38
//---------------------------------------------------------------------------
39
G4ClassificationOfNewTrack
40
AthenaDebugStackingAction::ClassifyNewTrack
(
const
G4Track* track)
41
{
42
// Kill neutrinos if enabled
43
if
(
m_config
.killAllNeutrinos &&
isNeutrino
(track)) {
44
return
fKill;
45
}
46
47
// Kill super-low-E photons
48
const
double
safeCut = 0.00005;
49
double
totalE = track->GetTotalEnergy();
50
if
(
isGamma
(track) && totalE < safeCut) {
51
return
fKill;
52
}
53
54
// TODO: Why is this here? Can I remove it?
55
G4Event*
ev
= G4EventManager::GetEventManager()->GetNonconstCurrentEvent();
56
AtlasG4EventUserInfo
* atlasG4EvtUserInfo
__attribute__
((
unused
)) =
57
static_cast<
AtlasG4EventUserInfo
*
>
(
ev
->GetUserInformation());
58
59
// Was track subject to a RR?
60
bool
rouletted =
false
;
61
62
// Neutron Russian Roulette
63
if
(
m_config
.russianRouletteNeutronThreshold > 0 &&
isNeutron
(track) &&
64
CxxUtils::fpcompare::equal
(track->GetWeight(), 1.0) &&
// do not re-Roulette particles
65
track->GetKineticEnergy() <
m_config
.russianRouletteNeutronThreshold) {
66
// shoot random number
67
if
( CLHEP::RandFlat::shoot() >
m_oneOverWeightNeutron
) {
68
if
(
m_config
.applyNRR) {
69
// Kill (w-1)/w neutrons
70
return
fKill;
71
}
else
{
72
// process them at the end of the stack
73
return
fWaiting;
74
}
75
}
76
rouletted =
true
;
77
// Weight the rest 1/w neutrons with a weight of w
78
if
(
m_config
.applyNRR) {
79
// TODO There may be another way to set the weights via
80
// another G4 interface avoiding the const_cast, but the
81
// changes are more major and will need more careful validation.
82
G4Track* mutableTrack
ATLAS_THREAD_SAFE
=
const_cast<
G4Track*
>
(track);
83
mutableTrack->SetWeight(
m_config
.russianRouletteNeutronWeight);
84
}
85
}
86
87
// Photon Russian Roulette
88
if
(
m_config
.russianRoulettePhotonThreshold > 0 &&
isGamma
(track) && track->GetOriginTouchable() &&
89
track->GetOriginTouchable()->GetVolume()->GetName().substr(0, 3) ==
"LAr"
&&
// only for photons created in LAr
90
CxxUtils::fpcompare::equal
(track->GetWeight(), 1.0) &&
// do not re-Roulette particles
91
track->GetKineticEnergy() <
m_config
.russianRoulettePhotonThreshold) {
92
// shoot random number
93
if
( CLHEP::RandFlat::shoot() >
m_oneOverWeightPhoton
) {
94
if
(
m_config
.applyPRR) {
95
// Kill (w-1)/w photons
96
return
fKill;
97
}
else
{
98
// process them at the end of the stack
99
return
fWaiting;
100
}
101
}
102
rouletted =
true
;
103
// Weight the rest 1/w neutrons with a weight of w
104
if
(
m_config
.applyPRR) {
105
// TODO There may be another way to set the weights via
106
// another G4 interface avoiding the const_cast, but the
107
// changes are more major and will need more careful validation.
108
G4Track* mutableTrack
ATLAS_THREAD_SAFE
=
const_cast<
G4Track*
>
(track);
109
mutableTrack->SetWeight(
m_config
.russianRoulettePhotonWeight);
110
}
111
}
112
113
// Handle primary particles
114
if
(track->GetParentID() == 0) {
// Condition for Primaries
115
// Extract the PrimaryParticleInformation
116
PrimaryParticleInformation
* primaryPartInfo = this->
getPrimaryParticleInformation
(track);
117
// Fill some information for this track
118
if
(primaryPartInfo) {
119
if
(!
m_config
.isISFJob) {
120
// don't do anything
121
auto
part = primaryPartInfo->
GetHepMCParticle
();
122
if
(part) {
123
// OK, we got back to HepMC
124
std::unique_ptr<TrackInformation> ti = std::make_unique<TrackInformation>(part);
125
ti->SetPrimaryGenParticle(part);
126
ti->SetGenerationZeroGenParticle(part);
127
ti->SetRegenerationNr(0);
128
ti->SetClassification(
TrackInformation::Primary
);
129
// regNr=0 and classify=Primary are default values anyway
133
track->SetUserInformation(ti.release());
134
}
135
// What does this condition mean?
136
else
if
(primaryPartInfo->
GetParticleUniqueID
() >= 0 && primaryPartInfo->
GetParticleBarcode
() >= 0) {
137
// PrimaryParticleInformation should at least provide a barcode
138
std::unique_ptr<TrackBarcodeInfo> bi = std::make_unique<TrackBarcodeInfo>(primaryPartInfo->
GetParticleUniqueID
(), primaryPartInfo->
GetParticleBarcode
());
142
track->SetUserInformation(bi.release());
143
}
144
}
// no ISFParticle attached
145
}
// has PrimaryParticleInformation
146
}
147
// Secondary track; decide whether to save or kill
148
else
if
(
isGamma
(track) &&
149
m_config
.photonEnergyCut > 0 &&
150
totalE <
m_config
.photonEnergyCut )
151
{
152
return
fKill;
153
}
154
// Put rouletted tracks at the end of the stack
155
if
(rouletted)
156
return
fWaiting;
157
else
158
return
fUrgent;
159
}
160
161
}
// namespace G4UA
AthenaDebugStackingAction.h
AtlasG4EventUserInfo.h
PrimaryParticleInformation.h
__attribute__
__attribute__((always_inline)) inline uint16_t TileCalibDrawerBase
Definition
TileCalibDrawerBase.h:192
TrackBarcodeInfo.h
TrackInformation.h
unused
void unused(Args &&...)
Definition
VP1ExpertSettings.cxx:39
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
AtlasG4EventUserInfo
This class is attached to G4Event objects as UserInformation.
Definition
AtlasG4EventUserInfo.h:26
G4UA::AthenaDebugStackingAction::ClassifyNewTrack
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *track) override final
Classify a new track.
Definition
AthenaDebugStackingAction.cxx:40
G4UA::AthenaDebugStackingAction::AthenaDebugStackingAction
AthenaDebugStackingAction(const Config &config)
Constructor with configuration.
Definition
AthenaDebugStackingAction.cxx:33
G4UA::AthenaStackingAction::m_config
Config m_config
Configuration options.
Definition
AthenaStackingAction.h:61
G4UA::AthenaStackingAction::m_oneOverWeightNeutron
double m_oneOverWeightNeutron
Definition
AthenaStackingAction.h:78
G4UA::AthenaStackingAction::m_oneOverWeightPhoton
double m_oneOverWeightPhoton
Definition
AthenaStackingAction.h:81
G4UA::AthenaStackingAction::AthenaStackingAction
AthenaStackingAction(const Config &config)
Constructor with configuration.
Definition
AthenaStackingAction.cxx:42
G4UA::AthenaStackingAction::isNeutrino
bool isNeutrino(const G4Track *) const
Identify track as a neutrino.
Definition
AthenaStackingAction.cxx:176
G4UA::AthenaStackingAction::isNeutron
bool isNeutron(const G4Track *) const
Identify track as a neutron.
Definition
AthenaStackingAction.cxx:194
G4UA::AthenaStackingAction::isGamma
bool isGamma(const G4Track *) const
Identify track as a photon.
Definition
AthenaStackingAction.cxx:188
G4UA::AthenaStackingAction::getPrimaryParticleInformation
PrimaryParticleInformation * getPrimaryParticleInformation(const G4Track *track) const
obtain the PrimaryParticleInformation from the current G4Track
Definition
AthenaStackingAction.cxx:158
PrimaryParticleInformation
This class is attached to G4PrimaryParticle objects as UserInformation.
Definition
PrimaryParticleInformation.h:39
PrimaryParticleInformation::GetParticleUniqueID
int GetParticleUniqueID() const
Definition
PrimaryParticleInformation.cxx:28
PrimaryParticleInformation::GetParticleBarcode
int GetParticleBarcode() const
Definition
PrimaryParticleInformation.cxx:18
PrimaryParticleInformation::GetHepMCParticle
HepMC::ConstGenParticlePtr GetHepMCParticle() const
return a pointer to the GenParticle used to create the G4PrimaryParticle
Definition
PrimaryParticleInformation.h:47
VTrackInformation::Primary
@ Primary
Definition
VTrackInformation.h:32
fpcompare.h
Workaround x86 precision issues for FP inequality comparisons.
ev
int ev
Definition
globals.cxx:25
CxxUtils::fpcompare::equal
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition
fpcompare.h:114
G4UA
for nSW
Definition
CalibrationDefaultProcessing.h:19
G4UA::AthenaStackingAction::Config
Configuration option struct for AthenaStackingAction.
Definition
AthenaStackingAction.h:29
Generated on
for ATLAS Offline Software by
1.17.0