ATLAS Offline Software
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>
6 namespace MuonVal{
8  ParticleBranch_ptr linkColl,
9  Linker_t linker,
10  const std::string& altName):
12  std::format("{:}_{:}Link", parent.name(), altName.empty() ? linkColl->name() : altName)},
13  m_linkColl{linkColl},
14  m_linkerFunc{std::move(linker)} {}
15 
17  push_back(p);
18  }
20  push_back(p);
21  }
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, primColl, fromPrimToSec, altSecName)});
40  }
41 
43  ParticleBranch_ptr primColl,
44  Linker_t linker,
45  const std::string& altName):
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 
55  }
57  push_back(&p);
58  }
60  push_back(p);
61  }
63  push_back(p);
64  }
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 }
MuonVal::BilateralLinkerBranch::m_parent
const IParticleFourMomBranch & m_parent
Definition: LinkerBranch.h:76
MuonVal::BilateralLinkerBranch::Linker_t
LinkerBranch::Linker_t Linker_t
Definition: LinkerBranch.h:54
vtune_athena.format
format
Definition: vtune_athena.py:14
LinkerBranch.h
xAOD::short
short
Definition: Vertex_v1.cxx:165
MuonVal::BilateralLinkerBranch::push_back
void push_back(const xAOD::IParticle *p) override
Interface methods to handle the particle.
Definition: LinkerBranch.cxx:54
MuonVal::VectorBranch
Definition: VectorBranch.h:14
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonVal::LinkerBranch::Linker_t
std::function< const xAOD::IParticle *(const xAOD::IParticle *)> Linker_t
Typedef of the linker function.
Definition: LinkerBranch.h:25
MuonVal::LinkerBranch::LinkerBranch
LinkerBranch(IParticleFourMomBranch &parent, ParticleBranch_ptr linkColl, Linker_t linker, const std::string &altName="")
Standard constructor fo the LinkerBranch.
Definition: LinkerBranch.cxx:7
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
MuonVal::BilateralLinkerBranch::ParticleBranch_ptr
LinkerBranch::ParticleBranch_ptr ParticleBranch_ptr
Definition: LinkerBranch.h:55
MuonVal::LinkerBranch::m_linkColl
std::weak_ptr< IParticleFourMomBranch > m_linkColl
Definition: LinkerBranch.h:47
MuonVal::BilateralLinkerBranch::fill
bool fill(const EventContext &ctx) override
The fill method checks if enough information is provided such that the branch is cleared from the inf...
Definition: LinkerBranch.cxx:65
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
MuonVal::BilateralLinkerBranch::m_linkerFunc
Linker_t m_linkerFunc
Definition: LinkerBranch.h:78
MuonVal::VectorBranch::fill
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...
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MuonVal::IParticleFourMomBranch::size
size_t size() const
How many particles have been pushed back already.
Definition: IParticleFourMomBranch.cxx:29
MuonVal::BilateralLinkerBranch::connectCollections
static bool connectCollections(ParticleBranch_ptr primColl, ParticleBranch_ptr secondColl, Linker_t fromPrimToSec, const std::string &altPrimName="", const std::string &altSecName="")
Definition: LinkerBranch.cxx:33
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
MuonVal::LinkerBranch::operator+=
void operator+=(const xAOD::IParticle *p) override
Definition: LinkerBranch.cxx:16
MuonVal::BilateralLinkerBranch::operator+=
void operator+=(const xAOD::IParticle *p) override
Definition: LinkerBranch.cxx:59
MuonVal
Class to store array like branches into the n-tuples.
Definition: HitValAlg.cxx:19
MuonVal::MuonTesterTree::name
std::string name() const
Name of the tree.
Definition: MuonTesterTree.cxx:20
MuonVal::LinkerBranch::m_linkerFunc
Linker_t m_linkerFunc
Definition: LinkerBranch.h:48
MuonVal::BilateralLinkerBranch::m_linkColl
std::weak_ptr< IParticleFourMomBranch > m_linkColl
Definition: LinkerBranch.h:77
MuonVal::MuonTesterBranch::parent
MuonTesterTree & parent()
Returns the reference to the MuonTesterTree parent.
Definition: MuonTesterBranch.cxx:38
MuonVal::IMuonTesterBranch::name
virtual std::string name() const =0
Returns the name of the branch.
MuonVal::IParticleFourMomBranch::name
std::string name() const override
Name of the four momentum branch.
Definition: IParticleFourMomBranch.cxx:30
MuonVal::BilateralLinkerBranch::BilateralLinkerBranch
BilateralLinkerBranch(IParticleFourMomBranch &bilatColl, ParticleBranch_ptr primColl, Linker_t linker, const std::string &altName)
Definition: LinkerBranch.cxx:42
MuonVal::VectorBranch< unsigned short >::get
unsigned short & get(size_t idx)
MuonVal::VectorBranch< unsigned short >::size
size_t size() const
Returns the number of actual saved elements.
MuonVal::IParticleFourMomBranch
Helper class to easily to add xAOD::IParticles and associated decorator variables to the MuonTesterTr...
Definition: IParticleFourMomBranch.h:31
MuonVal::MuonTesterTree::tree
TTree * tree()
TTree object.
Definition: MuonTesterTree.cxx:22
MuonVal::LinkerBranch::ParticleBranch_ptr
std::shared_ptr< IParticleFourMomBranch > ParticleBranch_ptr
Abreviation of the pointer to the particle branch.
Definition: LinkerBranch.h:21
MuonVal::IParticleFourMomBranch::find
size_t find(const xAOD::IParticle &p) const
Returns the position at which the particle has already be inserted in the chain – If the particle is ...
Definition: IParticleFourMomBranch.cxx:68
MuonVal::LinkerBranch::push_back
void push_back(const xAOD::IParticle *p) override
Interface methods to handle the particle.
Definition: LinkerBranch.cxx:25