ATLAS Offline Software
Loading...
Searching...
No Matches
LinkerBranch.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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 connectCollections(primColl, secondColl, fromPrimToSec,
40 [](const xAOD::IParticle* a, const xAOD::IParticle* b){
41 return a == b;
42 }, altPrimName, altSecName);
43 }
45 ParticleBranch_ptr secondColl,
46 Linker_t fromPrimToSec,
47 BiLinker_t fromSecToPrim,
48 const std::string& altPrimName,
49 const std::string& altSecName) {
50 return primColl->addVariable(std::make_unique<LinkerBranch>(*primColl, secondColl, fromPrimToSec, altPrimName)) &&
51 secondColl->addVariable(std::unique_ptr<IParticleDecorationBranch>{new BilateralLinkerBranch(*secondColl, std::move(primColl), std::move(fromPrimToSec), std::move(fromSecToPrim), altSecName)});
52 }
53
54
56 ParticleBranch_ptr primColl,
57 Linker_t linker,
58 BiLinker_t fromSecToPrim,
59 const std::string& altName):
60 VectorBranch<unsigned short>{parent.tree(),
61 std::format("{:}_{:}Link", parent.name(), altName.empty() ? primColl->name() : altName)},
62 m_parent{parent},
63 m_linkColl{primColl.get()},
64 m_linkPrimToSec{std::move(linker)},
65 m_linkSecToPrim{std::move(fromSecToPrim)} {
66 setDefault(-1);
67 parent.getTree().addBranch(primColl);
68 }
69
81 bool BilateralLinkerBranch::fill(const EventContext& ctx) {
82 if (m_parent.size()) {
84 get(m_parent.size() -1);
85 const std::vector<const xAOD::IParticle*>& linkMe = m_linkColl->getCached();
86 for (std::size_t primToSec = 0 ; primToSec < linkMe.size(); ++primToSec) {
87 const xAOD::IParticle* primP = m_linkPrimToSec(linkMe[primToSec]);
88 const size_t linkIdx = m_parent.find([&](const xAOD::IParticle* inBilat){
89 return m_linkSecToPrim(primP, inBilat);
90 });
91 if (linkIdx < size()) {
92 get(linkIdx) = primToSec;
93 }
94 }
95 }
96 ATH_MSG_VERBOSE("Fill "<<name()<<", size: "<<m_parent.size()<<"/"<<size()<<", "<<m_parent.name());
98 }
99}
#define ATH_MSG_VERBOSE(x,...)
static Double_t a
BilateralLinkerBranch(IParticleFourMomBranch &bilatColl, ParticleBranch_ptr primColl, Linker_t linker, BiLinker_t fromSecToPrim, 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::function< bool(const xAOD::IParticle *inBilateral, const xAOD::IParticle *inPrimary)> BiLinker_t
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