ATLAS Offline Software
Loading...
Searching...
No Matches
MuonsLoader.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "xAODMuon/Muon.h"
8
10
11 // factory for functions which return the sort variable we
12 // use to order iparticles
15 {
16 using Ip = xAOD::Muon;
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
28 const ConstituentsInputConfig & cfg
29 ):
32 m_customSequenceGetter(getter_utils::CustomSequenceGetter<xAOD::Muon>(
33 cfg.inputs))
34 {
35 const SG::AuxElement::ConstAccessor<PartLinks> acc("muonLinks");
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::Muon*> MuonsLoader::getMuonsFromVertex(
50 const xAOD::Vertex& vertex
51 ) const
52 {
53 std::vector<std::pair<double, const xAOD::Muon*>> particles;
54 for (const xAOD::Muon *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::Muon*> only_particles;
59 only_particles.reserve(particles.size());
60for (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*>> MuonsLoader::getData(
67 const xAOD::Vertex& vertex) const {
68 Muons sorted_particles = getMuonsFromVertex(vertex);
69 std::vector<const xAOD::IParticle*> sorted_particles_ip;
70 for (const auto& p: sorted_particles) {
71 sorted_particles_ip.push_back(p);
72 }
73 return std::make_tuple(m_config.output_name, m_customSequenceGetter.getFeats(vertex, sorted_particles), sorted_particles_ip);
74 }
75
76 std::string MuonsLoader::getName() const {
77 return m_name;
78 }
80 return m_config.type;
81 }
82
83}
std::vector< const xAOD::Muon * > IPV
Definition MuonsLoader.h:54
std::function< double(const xAOD::Muon *, const Vertex &)> MuonSortVar
Definition MuonsLoader.h:48
std::vector< const xAOD::Muon * > getMuonsFromVertex(const xAOD::Vertex &vertex) const
ConstituentsType getType() const override
getter_utils::CustomSequenceGetter< xAOD::Muon > m_customSequenceGetter
Definition MuonsLoader.h:61
static MuonSortVar iparticleSortVar(ConstituentsSortOrder)
std::tuple< std::string, FlavorTagInference::Inputs, std::vector< const xAOD::IParticle * > > getData(const xAOD::Vertex &vertex) const override
std::function< IPV(const Vertex &)> m_associator
Definition MuonsLoader.h:62
std::string getName() const override
MuonsLoader(const ConstituentsInputConfig &cfg)
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition Muons.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Vertex_v1 Vertex
Define the latest version of the vertex class.
Muon_v1 Muon
Reference the current persistent version: