ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_HepMC
ISF_HepMC_Tools
src
GenParticleSimAcceptList.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
// class header include
6
#include "
GenParticleSimAcceptList.h
"
7
8
// HepMC includes
9
#include "
AtlasHepMC/GenParticle.h
"
10
#include "
AtlasHepMC/GenVertex.h
"
11
12
// Helper function
13
#include "
TruthUtils/HepMCHelpers.h
"
14
15
// For finding that file
16
#include "
PathResolver/PathResolver.h
"
17
18
// Units
19
#include <fstream>
20
#include <cstdlib>
21
23
ISF::GenParticleSimAcceptList::GenParticleSimAcceptList
(
const
std::string& t,
24
const
std::string& n,
25
const
IInterface* p )
26
: base_class(t,n,p)
27
{
28
}
29
30
// Athena algtool's Hooks
31
StatusCode
ISF::GenParticleSimAcceptList::initialize
()
32
{
33
ATH_MSG_VERBOSE
(
"Initializing ..."
);
34
35
// Initialize the list
36
m_pdgId
.clear();
37
38
for
(
auto
&acceptList :
m_acceptLists
) {
39
// Get the appropriate file handle
40
std::string resolvedFilename =
PathResolver::find_file
( acceptList ,
"DATAPATH"
);
41
std::ifstream white_list;
42
white_list.open( resolvedFilename );
43
if
(!white_list.is_open()){
44
ATH_MSG_ERROR
(
"Could not find accept list "
<< acceptList);
45
return
StatusCode::FAILURE;
46
}
47
48
// Parse the list into the vector
49
std::string a_line;
50
char
* pEnd;
51
while
(!white_list.eof()){
52
getline( white_list , a_line );
53
long
int
pdg = strtol( a_line.c_str() , &pEnd , 10 );
54
if
(std::find(
m_pdgId
.begin(),
m_pdgId
.end(), pdg) ==
m_pdgId
.end()) {
55
m_pdgId
.push_back(pdg);
56
}
else
{
57
ATH_MSG_DEBUG
(
"pdgId "
<< pdg <<
" already in acceptlist. Will not add it again."
);
58
}
59
}
60
61
// Sort the list for use later
62
std::sort
(
m_pdgId
.begin() ,
m_pdgId
.end() );
63
}
64
65
// All done!
66
return
StatusCode::SUCCESS;
67
}
68
70
bool
ISF::GenParticleSimAcceptList::pass
(
const
HepMC::ConstGenParticlePtr
& particle)
const
71
{
72
73
ATH_MSG_VERBOSE
(
"Checking whether "
<< particle <<
" passes the filter."
);
74
75
std::vector<int> vertices(500);
76
bool
so_far_so_good =
pass
( particle , vertices );
77
78
// Test all parent particles
79
const
int
id_of_particle = particle->id();
80
if
(so_far_so_good && particle->production_vertex() &&
m_qs
){
81
for
(
auto
& pit: particle->production_vertex()->particles_in()){
82
// Loop breaker
83
if
( pit->id() == id_of_particle )
continue
;
84
// Check this particle
85
vertices.clear();
86
bool
parent_all_clear =
pass
( pit , vertices );
87
ATH_MSG_VERBOSE
(
"Parent all clear: "
<< parent_all_clear <<
88
"\nIf true, will not pass the daughter because it should have been picked up through the parent already (to avoid multi-counting)."
);
89
so_far_so_good = so_far_so_good && !parent_all_clear;
90
}
// Loop over parents
91
}
// particle had parents
92
93
return
so_far_so_good;
94
}
95
96
98
bool
ISF::GenParticleSimAcceptList::pass
(
const
HepMC::ConstGenParticlePtr
& particle , std::vector<int> & used_vertices )
const
99
{
100
// See if the particle is in the accept list
101
bool
passFilter = std::binary_search(
m_pdgId
.begin() ,
m_pdgId
.end() , particle->pdg_id() ) ||
MC::isNucleus
( particle->pdg_id() );
102
// Remove documentation particles
103
passFilter = passFilter &&
MC::isPhysical
(particle);
104
// Test all daughter particles
105
if
(particle->end_vertex() &&
m_qs
&& passFilter){
106
// Primarily interested in passing particles decaying outside
107
// m_minDecayRadiusQS (nomimally the inner radius of the
108
// beampipe). However, it is also interesting to pass particles
109
// which start outside m_minDecayRadiusQS, but decay inside it.
110
passFilter = passFilter && ( (
m_minDecayRadiusQS
< particle->end_vertex()->position().
perp
()) || (m_minDecayRadiusQS < particle->production_vertex()->position().
perp
()) );
111
if
(passFilter) {
112
// Break loops
113
if
( std::find( used_vertices.begin() , used_vertices.end() , particle->end_vertex()->id() )==used_vertices.end() ){
114
used_vertices.push_back( particle->end_vertex()->id() );
115
for
(
auto
& pit: particle->end_vertex()->particles_out()){
116
passFilter = passFilter &&
pass
( pit , used_vertices );
117
if
(!passFilter) {
118
ATH_MSG_VERBOSE
(
"Daughter particle "
<< pit <<
" does not pass."
);
119
break
;
120
}
121
}
// Loop over daughters
122
}
// Break loops
123
}
// particle decayed before the min radius to be considered for simulation
124
else
{
125
ATH_MSG_VERBOSE
(
"Particle "
<< particle <<
" was produced and decayed within a radius of "
<<
m_minDecayRadiusQS
<<
" mm."
);
126
}
127
}
// particle had daughters
128
if
(!
m_useShadowEvent
&& !particle->end_vertex() &&
MC::isDecayed
(particle)) {
// no daughters... No end vertex... Check if this isn't trouble
129
ATH_MSG_ERROR
(
"Found a particle with no end vertex that does not appear in the accept list."
);
130
ATH_MSG_ERROR
(
"This is VERY likely pointing to a problem with either the configuration you "
);
131
ATH_MSG_ERROR
(
"are using, or a bug in the generator. Either way it should be fixed. The"
);
132
ATH_MSG_ERROR
(
"particle will come next, and then we will throw."
);
133
ATH_MSG_ERROR
( particle );
134
throw
std::runtime_error(
"GenParticleSimAcceptList: Particle with no end vertex and not in acceptlist"
);
135
}
136
137
return
passFilter;
138
}
139
140
141
StatusCode
ISF::GenParticleSimAcceptList::finalize
()
142
{
143
ATH_MSG_VERBOSE
(
"Finalizing ..."
);
144
return
StatusCode::SUCCESS;
145
}
perp
Scalar perp() const
perp method - perpendicular length
Definition
AmgMatrixBasePlugin.h:44
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
GenParticleSimAcceptList.h
GenParticle.h
GenVertex.h
HepMCHelpers.h
ATLAS-specific HepMC functions.
PathResolver.h
ISF::GenParticleSimAcceptList::finalize
virtual StatusCode finalize() override final
Definition
GenParticleSimAcceptList.cxx:141
ISF::GenParticleSimAcceptList::initialize
virtual StatusCode initialize() override final
Athena algtool's Hooks.
Definition
GenParticleSimAcceptList.cxx:31
ISF::GenParticleSimAcceptList::pass
virtual bool pass(const HepMC::ConstGenParticlePtr &particle) const override
passes through to the private version
Definition
GenParticleSimAcceptList.cxx:70
ISF::GenParticleSimAcceptList::m_qs
BooleanProperty m_qs
Switch for quasi-stable particle simulation.
Definition
GenParticleSimAcceptList.h:52
ISF::GenParticleSimAcceptList::m_acceptLists
StringArrayProperty m_acceptLists
The location of the accept lists.
Definition
GenParticleSimAcceptList.h:50
ISF::GenParticleSimAcceptList::GenParticleSimAcceptList
GenParticleSimAcceptList(const std::string &t, const std::string &n, const IInterface *p)
Constructor.
Definition
GenParticleSimAcceptList.cxx:23
ISF::GenParticleSimAcceptList::m_pdgId
std::vector< long int > m_pdgId
Allowed PDG IDs.
Definition
GenParticleSimAcceptList.h:51
ISF::GenParticleSimAcceptList::m_minDecayRadiusQS
DoubleProperty m_minDecayRadiusQS
Decay radius below which QS particles should be ignored.
Definition
GenParticleSimAcceptList.h:54
ISF::GenParticleSimAcceptList::m_useShadowEvent
BooleanProperty m_useShadowEvent
Definition
GenParticleSimAcceptList.h:53
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:220
HepMC::ConstGenParticlePtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition
GenParticle.h:20
MC::isDecayed
bool isDecayed(const T &p)
Identify if the particle decayed.
Definition
HepMCHelpers.h:43
MC::isNucleus
bool isNucleus(const T &p)
PDG rule 16 Nuclear codes are given as 10-digit numbers ±10LZZZAAAI.
Definition
HepMCHelpers.h:709
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition
HepMCHelpers.h:52
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
Generated on
for ATLAS Offline Software by
1.17.0