ATLAS Offline Software
Loading...
Searching...
No Matches
LinkerBranch.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5#include <format>
6namespace MuonVal{
8 ParticleBranch_ptr linkColl,
9 Linker_t linker,
10 const std::string& altName):
11 VectorBranch<unsigned short>{parent.tree(),
12 std::format("{:}_{:}Link", parent.name(), altName.empty() ? linkColl->name() : altName)},
13 m_linkColl{linkColl},
14 m_linkerFunc{std::move(linker)} {}
15
23 push_back(&p);
24 }
26 const xAOD::IParticle* related = m_linkerFunc(p);
27 ParticleBranch_ptr linkColl = m_linkColl.lock();
28 linkColl->push_back(related);
29 VectorBranch<unsigned short>::push_back(linkColl->find(related));
30 }
31
32
34 ParticleBranch_ptr secondColl,
35 Linker_t fromPrimToSec,
36 const std::string& altPrimName,
37 const std::string& altSecName) {
38 return primColl->addVariable(std::make_unique<LinkerBranch>(*primColl, secondColl, fromPrimToSec, altPrimName)) &&
39 secondColl->addVariable(std::unique_ptr<IParticleDecorationBranch>{new BilateralLinkerBranch(*secondColl, std::move(primColl), std::move(fromPrimToSec), altSecName)});
40 }
41
43 ParticleBranch_ptr primColl,
44 Linker_t linker,
45 const std::string& altName):
46 VectorBranch<unsigned short>{parent.tree(),
47 std::format("{:}_{:}Link", parent.name(), altName.empty() ? primColl->name() : altName)},
48 m_parent{parent},
49 m_linkColl{primColl},
50 m_linkerFunc{std::move(linker)} {
51 setDefault(-1);
52 }
53
65 bool BilateralLinkerBranch::fill(const EventContext& ctx) {
66 if (m_parent.size()) {
68 get(m_parent.size() -1);
69 ParticleBranch_ptr linkColl = m_linkColl.lock();
70 const std::vector<const xAOD::IParticle*>& linkeMe = linkColl->getCached();
71 for (std::size_t primToSec = 0 ; primToSec < linkeMe.size(); ++primToSec) {
72 const size_t linkIdx = m_parent.find(m_linkerFunc(linkeMe[primToSec]));
73 if (linkIdx < size()) {
74 get(linkIdx) = primToSec;
75 }
76 }
77 }
78 ATH_MSG_VERBOSE("Fill "<<name()<<", size: "<<m_parent.size()<<"/"<<size()<<", "<<m_parent.name());
80 }
81}
#define ATH_MSG_VERBOSE(x)
BilateralLinkerBranch(IParticleFourMomBranch &bilatColl, ParticleBranch_ptr primColl, Linker_t linker, const std::string &altName)
bool fill(const EventContext &ctx) override
The fill method checks if enough information is provided such that the branch is cleared from the inf...
LinkerBranch::Linker_t Linker_t
LinkerBranch::ParticleBranch_ptr ParticleBranch_ptr
static bool connectCollections(ParticleBranch_ptr primColl, ParticleBranch_ptr secondColl, Linker_t fromPrimToSec, const std::string &altPrimName="", const std::string &altSecName="")
const IParticleFourMomBranch & m_parent
std::weak_ptr< IParticleFourMomBranch > m_linkColl
void operator+=(const xAOD::IParticle *p) override
void push_back(const xAOD::IParticle *p) override
Interface methods to handle the particle.
Helper class to easily to add xAOD::IParticles and associated decorator variables to the MuonTesterTr...
std::function< const xAOD::IParticle *(const xAOD::IParticle *)> Linker_t
Typedef of the linker function.
void operator+=(const xAOD::IParticle *p) override
LinkerBranch(IParticleFourMomBranch &parent, ParticleBranch_ptr linkColl, Linker_t linker, const std::string &altName="")
Standard constructor fo the LinkerBranch.
std::shared_ptr< IParticleFourMomBranch > ParticleBranch_ptr
Abreviation of the pointer to the particle branch.
void push_back(const xAOD::IParticle *p) override
Interface methods to handle the particle.
std::weak_ptr< IParticleFourMomBranch > m_linkColl
std::string name() const override final
void push_back(const T &value)
Adds a new element at the end of the vector.
bool fill(const EventContext &ctx) override
Clears vector in cases that it has not been updated in this event Retursn falls if the vector has not...
VectorBranch(TTree *tree, const std::string &name)
Class providing the definition of the 4-vector interface.
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19