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.get()},
14 m_linkerFunc{std::move(linker)} {
15 parent.getTree().addBranch(linkColl);
16 }
17
25 push_back(&p);
26 }
28 const xAOD::IParticle* related = m_linkerFunc(p);
29 m_linkColl->push_back(related);
31 }
32
33
35 ParticleBranch_ptr secondColl,
36 Linker_t fromPrimToSec,
37 const std::string& altPrimName,
38 const std::string& altSecName) {
39 return primColl->addVariable(std::make_unique<LinkerBranch>(*primColl, secondColl, fromPrimToSec, altPrimName)) &&
40 secondColl->addVariable(std::unique_ptr<IParticleDecorationBranch>{new BilateralLinkerBranch(*secondColl, std::move(primColl), std::move(fromPrimToSec), altSecName)});
41 }
42
44 ParticleBranch_ptr primColl,
45 Linker_t linker,
46 const std::string& altName):
47 VectorBranch<unsigned short>{parent.tree(),
48 std::format("{:}_{:}Link", parent.name(), altName.empty() ? primColl->name() : altName)},
49 m_parent{parent},
50 m_linkColl{primColl.get()},
51 m_linkerFunc{std::move(linker)} {
52 setDefault(-1);
53 parent.getTree().addBranch(primColl);
54 }
55
67 bool BilateralLinkerBranch::fill(const EventContext& ctx) {
68 if (m_parent.size()) {
70 get(m_parent.size() -1);
71 const std::vector<const xAOD::IParticle*>& linkeMe = m_linkColl->getCached();
72 for (std::size_t primToSec = 0 ; primToSec < linkeMe.size(); ++primToSec) {
73 const size_t linkIdx = m_parent.find(m_linkerFunc(linkeMe[primToSec]));
74 if (linkIdx < size()) {
75 get(linkIdx) = primToSec;
76 }
77 }
78 }
79 ATH_MSG_VERBOSE("Fill "<<name()<<", size: "<<m_parent.size()<<"/"<<size()<<", "<<m_parent.name());
81 }
82}
#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
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...
IParticleFourMomBranch * m_linkColl
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::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