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