ATLAS Offline Software
IParticlesLoader.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "xAODBase/IParticle.h"
8 
10 
11  // factory for functions which return the sort variable we
12  // use to order iparticles
15  {
16  using Ip = xAOD::IParticle;
17  using Vertex = xAOD::Vertex;
18  switch(config) {
20  return [](const Ip* tp, const Vertex&) {return tp->pt();};
21  default: {
22  throw std::logic_error("Unknown sort function");
23  }
24  }
25  } // end of iparticle sort getter
26 
29  ):
31  m_iparticleSortVar(IParticlesLoader::iparticleSortVar(cfg.order)),
32  m_customSequenceGetter(getter_utils::CustomSequenceGetter<xAOD::IParticle>(
33  cfg.inputs))
34  {
35  const SG::AuxElement::ConstAccessor<PartLinks> acc("particleLinks");
36  m_associator = [acc](const xAOD::Vertex& vertex) -> IPV {
37  IPV particles;
38  for (const ElementLink<IPC>& link : acc(vertex)){
39  if (!link.isValid()) {
40  throw std::logic_error("invalid particle link");
41  }
42  particles.push_back(*link);
43  }
44  return particles;
45  };
46  m_name = cfg.name;
47  }
48 
49  std::vector<const xAOD::IParticle*> IParticlesLoader::getIParticlesFromVertex(
50  const xAOD::Vertex& vertex
51  ) const
52  {
53  std::vector<std::pair<double, const xAOD::IParticle*>> particles;
54  for (const xAOD::IParticle *tp : m_associator(vertex)) {
55  particles.emplace_back(m_iparticleSortVar(tp, vertex), tp);
56  }
57  std::sort(particles.begin(), particles.end(), std::greater<>());
58  std::vector<const xAOD::IParticle*> only_particles;
59  only_particles.reserve(particles.size());
60 for (const auto& particle: particles) {
61  only_particles.push_back(particle.second);
62  }
63  return only_particles;
64  }
65 
66  std::tuple<std::string, FlavorTagInference::Inputs, std::vector<const xAOD::IParticle*>> IParticlesLoader::getData(
67  const xAOD::Vertex& vertex) const {
68  IParticles sorted_particles = getIParticlesFromVertex(vertex);
69  return std::make_tuple(m_config.output_name, m_customSequenceGetter.getFeats(vertex, sorted_particles), sorted_particles);
70  }
71 
72  std::string IParticlesLoader::getName() const {
73  return m_name;
74  }
76  return m_config.type;
77  }
78 
79 }
InDetGNNHardScatterSelection::ConstituentsInputConfig::output_name
std::string output_name
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:47
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
InDetGNNHardScatterSelection::IParticlesLoader::IParticleSortVar
std::function< double(const xAOD::IParticle *, const Vertex &)> IParticleSortVar
Definition: IParticlesLoader.h:44
InDetGNNHardScatterSelection::IParticlesLoader::IParticlesLoader
IParticlesLoader(const ConstituentsInputConfig &)
Definition: IParticlesLoader.cxx:27
InDetGNNHardScatterSelection::IParticlesLoader::IPV
std::vector< const xAOD::IParticle * > IPV
Definition: IParticlesLoader.h:53
IParticle.h
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
InDetGNNHardScatterSelection::getter_utils::CustomSequenceGetter::getFeats
std::pair< std::vector< float >, std::vector< int64_t > > getFeats(const xAOD::Vertex &jet, const Constituents &constituents) const
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/Root/CustomGetterUtils.cxx:284
ParticleTest.tp
tp
Definition: ParticleTest.py:25
InDetGNNHardScatterSelection::ConstituentsInputConfig
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:45
InDetGNNHardScatterSelection::ConstituentsType
ConstituentsType
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:31
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
InDetGNNHardScatterSelection::IConstituentsLoader
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:61
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
InDetGNNHardScatterSelection::ConstituentsInputConfig::type
ConstituentsType type
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:49
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
InDetGNNHardScatterSelection::IParticlesLoader::getType
ConstituentsType getType() const override
Definition: IParticlesLoader.cxx:75
InDetGNNHardScatterSelection::ConstituentsSortOrder
ConstituentsSortOrder
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:25
InDetGNNHardScatterSelection::IParticlesLoader::m_associator
std::function< IPV(const Vertex &)> m_associator
Definition: IParticlesLoader.h:61
InDetGNNHardScatterSelection::IParticlesLoader::iparticleSortVar
static IParticleSortVar iparticleSortVar(ConstituentsSortOrder)
Definition: IParticlesLoader.cxx:13
InDetGNNHardScatterSelection::IParticlesLoader
Definition: IParticlesLoader.h:29
InDetGNNHardScatterSelection::IParticlesLoader::m_customSequenceGetter
getter_utils::CustomSequenceGetter< xAOD::IParticle > m_customSequenceGetter
Definition: IParticlesLoader.h:60
mc.order
order
Configure Herwig7.
Definition: mc.Herwig7_Dijet.py:12
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
InDetGNNHardScatterSelection::IConstituentsLoader::m_config
ConstituentsInputConfig m_config
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:71
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
InDetGNNHardScatterSelection::IParticlesLoader::getName
std::string getName() const override
Definition: IParticlesLoader.cxx:72
InDetGNNHardScatterSelection::ConstituentsSortOrder::PT_DESCENDING
@ PT_DESCENDING
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
InDetGNNHardScatterSelection
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:22
InDetGNNHardScatterSelection::IConstituentsLoader::m_name
std::string m_name
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/ConstituentsLoader.h:72
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
InDetGNNHardScatterSelection::IParticlesLoader::getIParticlesFromVertex
std::vector< const xAOD::IParticle * > getIParticlesFromVertex(const xAOD::Vertex &vertex) const
Definition: IParticlesLoader.cxx:49
InDetGNNHardScatterSelection::IParticlesLoader::IParticles
std::vector< const xAOD::IParticle * > IParticles
Definition: IParticlesLoader.h:42
InDetGNNHardScatterSelection::IParticlesLoader::m_iparticleSortVar
IParticleSortVar m_iparticleSortVar
Definition: IParticlesLoader.h:59
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
IParticlesLoader.h
InDetGNNHardScatterSelection::IParticlesLoader::getData
std::tuple< std::string, FlavorTagInference::Inputs, std::vector< const xAOD::IParticle * > > getData(const xAOD::Vertex &vertex) const override
Definition: IParticlesLoader.cxx:66