ATLAS Offline Software
IParticlesLoader.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 namespace FlavorTagDiscriminants {
10 
11  // factory for functions which return the sort variable we
12  // use to order iparticles
15  {
16  typedef xAOD::IParticle Ip;
17  typedef xAOD::Jet Jet;
18  switch(config) {
20  return [](const Ip* tp, const Jet&) {return tp->pt();};
21  default: {
22  throw std::logic_error("Unknown sort function");
23  }
24  }
25  } // end of iparticle sort getter
26 
29  const FTagOptions& options
30  ):
32  m_iparticleSortVar(IParticlesLoader::iparticleSortVar(cfg.order)),
33  m_seqGetter(getter_utils::SeqGetter<xAOD::IParticle>(
34  cfg.inputs, options))
35  {
37  m_associator = [acc](const xAOD::Jet& jet) -> IPV {
38  IPV particles;
39  for (const ElementLink<IPC>& link : acc(jet)){
40  if (!link.isValid()) {
41  throw std::logic_error("invalid particle link");
42  }
43  particles.push_back(*link);
44  }
45  return particles;
46  };
47 
48  if (cfg.name.find("charged") != std::string::npos){
49  m_isCharged = true;
50  } else {
51  m_isCharged = false;
52  }
54  m_name = cfg.name;
55  }
56 
57  std::vector<const xAOD::IParticle*> IParticlesLoader::getIParticlesFromJet(
58  const xAOD::Jet& jet
59  ) const
60  {
61  std::vector<std::pair<double, const xAOD::IParticle*>> particles;
62  for (const xAOD::IParticle *tp : m_associator(jet)) {
63  particles.push_back({m_iparticleSortVar(tp, jet), tp});
64  }
65  std::sort(particles.begin(), particles.end(), std::greater<>());
66  std::vector<const xAOD::IParticle*> only_particles;
67  for (const auto& particle: particles) {
68  auto* flow = dynamic_cast<const xAOD::FlowElement*>(particle.second);
69  const xAOD::IParticle* obj = nullptr;
70  if (!flow){
71  throw std::runtime_error("IParticlesLoader: Dynamic cast to FlowElement failed");
72  }
73  if ((flow->isCharged() != m_isCharged)) continue;
74  else {
75  if (m_isCharged){
76  obj = flow->chargedObject(0);
77  }
78  else{
79  obj = flow;
80  }
81  }
82  if (!obj){
83  continue;
84  }
85  only_particles.push_back(obj);
86  }
87  return only_particles;
88  }
89 
90  std::tuple<std::string, Inputs, std::vector<const xAOD::IParticle*>> IParticlesLoader::getData(
91  const xAOD::Jet& jet,
92  [[maybe_unused]] const SG::AuxElement& btag) const {
93  IParticles sorted_particles = getIParticlesFromJet(jet);
94 
95  return std::make_tuple(m_config.output_name, m_seqGetter.getFeats(jet, sorted_particles), sorted_particles);
96  }
97 
99  return m_deps;
100  }
101  std::set<std::string> IParticlesLoader::getUsedRemap() const {
102  return m_used_remap;
103  }
104  std::string IParticlesLoader::getName() const {
105  return m_name;
106  }
108  return m_config.type;
109  }
110 
111 }
FlavorTagDiscriminants::getter_utils::SeqGetter::getFeats
std::pair< std::vector< float >, std::vector< int64_t > > getFeats(const xAOD::Jet &jet, const Const &constituents) const
Definition: CustomGetterUtils.cxx:414
FlavorTagDiscriminants::ConstituentsSortOrder
ConstituentsSortOrder
Definition: ConstituentsLoader.h:32
FlavorTagDiscriminants::IParticlesLoader::getIParticlesFromJet
std::vector< const xAOD::IParticle * > getIParticlesFromJet(const xAOD::Jet &jet) const
Definition: IParticlesLoader.cxx:57
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
FlavorTagDiscriminants::ConstituentsInputConfig
Definition: ConstituentsLoader.h:59
FlavorTagDiscriminants::IParticlesLoader::IParticleSortVar
std::function< double(const xAOD::IParticle *, const Jet &)> IParticleSortVar
Definition: IParticlesLoader.h:52
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
FlavorTagDiscriminants::IConstituentsLoader
Definition: ConstituentsLoader.h:75
FlavorTagDiscriminants::ConstituentsInputConfig::type
ConstituentsType type
Definition: ConstituentsLoader.h:62
FlavorTagDiscriminants::IParticlesLoader::Jet
xAOD::Jet Jet
Definition: IParticlesLoader.h:46
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:446
FlavorTagDiscriminants::IParticlesLoader::IParticles
std::vector< const xAOD::IParticle * > IParticles
Definition: IParticlesLoader.h:50
FlavorTagDiscriminants::IParticlesLoader::m_isCharged
bool m_isCharged
Definition: IParticlesLoader.h:70
ParticleTest.tp
tp
Definition: ParticleTest.py:25
FlavorTagDiscriminants::IParticlesLoader::getData
std::tuple< std::string, Inputs, std::vector< const xAOD::IParticle * > > getData(const xAOD::Jet &jet, [[maybe_unused]] const SG::AuxElement &btag) const override
Definition: IParticlesLoader.cxx:90
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
FlavorTagDiscriminants::IParticlesLoader::getDependencies
FTagDataDependencyNames getDependencies() const override
Definition: IParticlesLoader.cxx:98
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
FlavorTagDiscriminants::IParticlesLoader::iparticleSortVar
IParticleSortVar iparticleSortVar(ConstituentsSortOrder)
Definition: IParticlesLoader.cxx:13
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
FlavorTagDiscriminants::IConstituentsLoader::m_name
std::string m_name
Definition: ConstituentsLoader.h:93
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
FlavorTagDiscriminants::IConstituentsLoader::m_used_remap
std::set< std::string > m_used_remap
Definition: ConstituentsLoader.h:92
FlavorTagDiscriminants::IParticlesLoader::m_iparticleSortVar
IParticleSortVar m_iparticleSortVar
Definition: IParticlesLoader.h:67
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
FlavorTagDiscriminants::FTagDataDependencyNames
Definition: FTagDataDependencyNames.h:12
FlowElement.h
HepMC::flow
int flow(const T &a, int i)
Definition: Flow.h:51
FlavorTagDiscriminants::IParticlesLoader
Definition: IParticlesLoader.h:34
mc.order
order
Configure Herwig7.
Definition: mc.Herwig7_Dijet.py:12
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
FlavorTagDiscriminants::IParticlesLoader::getUsedRemap
std::set< std::string > getUsedRemap() const override
Definition: IParticlesLoader.cxx:101
FlavorTagDiscriminants::IParticlesLoader::m_seqGetter
getter_utils::SeqGetter< xAOD::IParticle > m_seqGetter
Definition: IParticlesLoader.h:68
FlavorTagDiscriminants::IConstituentsLoader::m_deps
FTagDataDependencyNames m_deps
Definition: ConstituentsLoader.h:90
FlavorTagDiscriminants::ConstituentsInputConfig::output_name
std::string output_name
Definition: ConstituentsLoader.h:61
FlavorTagDiscriminants::IParticlesLoader::getName
std::string getName() const override
Definition: IParticlesLoader.cxx:104
FlavorTagDiscriminants::IParticlesLoader::IParticlesLoader
IParticlesLoader(ConstituentsInputConfig, const FTagOptions &options)
Definition: IParticlesLoader.cxx:27
FlavorTagDiscriminants::ConstituentsSortOrder::PT_DESCENDING
@ PT_DESCENDING
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
FlavorTagDiscriminants::FTagOptions
Definition: DataPrepUtilities.h:45
FlavorTagDiscriminants::IParticlesLoader::getType
ConstituentsType getType() const override
Definition: IParticlesLoader.cxx:107
FlavorTagDiscriminants::IConstituentsLoader::m_config
ConstituentsInputConfig m_config
Definition: ConstituentsLoader.h:91
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
FlavorTagDiscriminants::getter_utils::SeqGetter::getUsedRemap
std::set< std::string > getUsedRemap() const
Definition: CustomGetterUtils.cxx:456
python.PyAthena.obj
obj
Definition: PyAthena.py:135
FlavorTagDiscriminants::ConstituentsType
ConstituentsType
Definition: ConstituentsLoader.h:48
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
IParticlesLoader.h
FlavorTagDiscriminants::IParticlesLoader::IPV
std::vector< const xAOD::IParticle * > IPV
Definition: IParticlesLoader.h:61
FlavorTagDiscriminants::IParticlesLoader::m_associator
std::function< IPV(const Jet &)> m_associator
Definition: IParticlesLoader.h:69
StringUtils.h
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25