ATLAS Offline Software
Loading...
Searching...
No Matches
ConstituentLoaderTauHit.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7namespace FlavorTagInference {
10 m_hits_key{hits_key}
11 {
12 for(const InputVariableConfig& input_var : cfg.inputs) {
13 m_feature_extractors.push_back(getFeatureExtractor(input_var.name));
14 }
15 }
16
17
18 std::tuple<Inputs, std::vector<const xAOD::IParticle*>> ConstituentLoaderTauHit::getData(const xAOD::IParticle& p) const
19 {
20 const std::vector<const xAOD::TrackMeasurementValidation*> hits = getParticleHits(p);
21 return std::make_tuple(getFeatures(p, hits), std::vector<const xAOD::IParticle*>{} );
22 }
23
24
25 const std::vector<const xAOD::TrackMeasurementValidation*> ConstituentLoaderTauHit::getParticleHits(const xAOD::IParticle& p) const
26 {
28
29 std::vector<const xAOD::TrackMeasurementValidation*> hits;
30 for(const ElementLink<xAOD::TrackMeasurementValidationContainer>& el : hitsHandle(p)) {
31 if(el.isValid()) hits.push_back(*el);
32
33 // Truncate hits input (already sorted by the upstream JetHitAssociationAlg)
34 if(hits.size() == m_config.max_n_constituents) break;
35 }
36
37 return hits;
38 }
39
40
41 const Eigen::Matrix3d ConstituentLoaderTauHit::getJABInvMatrix(const xAOD::IParticle& p) const
42 {
43 // We often work with hits associated to a particle in the following coordinates:
44 // - jet (particle axis) projection,
45 // - adjacent projection (orthogonal to the jet axis and the beam),
46 // - beamline projection.
47 // Since the jet and the beam aren't perpendicular for eta != 0, this isn't a fully-orthogonal basis.
48 //
49 // We also approximate the eta-phi coordinates of the jet to be approximately constant w.r.t. the event vertex,
50 // considering the very-small displacements of the beamspot in the x-y plane, and the relatively small difference
51 // in eta with small (+/- 50mm) changes in z. We might need to revisit this approximation, but we'll use it for now.
52
53 // Use zhat as the beamline
54 Eigen::Vector3d bhat(0, 0, 1);
55
56 const TLorentzVector p4 = p.p4();
57 Eigen::Vector3d jhat = Eigen::Vector3d(p4.X(), p4.Y(), p4.Z()).normalized();
58
59 Eigen::Vector3d ahat = bhat.cross(jhat).normalized();
60
61 // Build the matrix m that maps the jab displacement such that m*jab = detector
62 Eigen::Matrix3d m;
63 m << jhat, ahat, bhat;
64
65 return m.inverse();
66 }
67
68
69 const Inputs ConstituentLoaderTauHit::getFeatures(const xAOD::IParticle& p, const std::vector<const xAOD::TrackMeasurementValidation*>& hits) const
70 {
71 std::vector<int64_t> features_dim = {static_cast<int64_t>(hits.size()), static_cast<int64_t>(m_feature_extractors.size())};
72
73 const Eigen::Matrix3d jav_inv = getJABInvMatrix(p);
74
75 std::vector<float> features;
76 features.reserve(hits.size() * m_feature_extractors.size());
77 for(const xAOD::TrackMeasurementValidation* hit : hits) {
78 for(const FeatureFunc_t& extractor : m_feature_extractors) {
79 features.push_back(extractor(p, *hit, jav_inv));
80 }
81 }
82
83 return Inputs{std::move(features), std::move(features_dim)};
84 }
85
86
88 {
89 try {
90 return m_func_map.at(var_name);
91 } catch (const std::out_of_range &e) {
92 throw std::runtime_error("Variable '" + var_name + "' not defined");
93 }
94 }
95
96} // namespace FlavorTagInference
97
98
99
100namespace TauHitVars {
101
102float j(const xAOD::IParticle& /*p*/, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d& jab_inv) {
103 static const SG::ConstAccessor<float> acc_localX("HitsXRelToBeamspot");
104 static const SG::ConstAccessor<float> acc_localY("HitsYRelToBeamspot");
105 static const SG::ConstAccessor<float> acc_localZ("HitsZRelToBeamspot");
106
107 return jab_inv(0, 0)*acc_localX(hit) + jab_inv(0, 1)*acc_localY(hit) + jab_inv(0, 2)*acc_localZ(hit);
108}
109
110
111float a(const xAOD::IParticle& /*p*/, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d& jab_inv) {
112 static const SG::ConstAccessor<float> acc_localX("HitsXRelToBeamspot");
113 static const SG::ConstAccessor<float> acc_localY("HitsYRelToBeamspot");
114 static const SG::ConstAccessor<float> acc_localZ("HitsZRelToBeamspot");
115
116 return jab_inv(1, 0)*acc_localX(hit) + jab_inv(1, 1)*acc_localY(hit) + jab_inv(1, 2)*acc_localZ(hit);
117}
118
119
120float b(const xAOD::IParticle& /*p*/, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d& jab_inv) {
121 static const SG::ConstAccessor<float> acc_localX("HitsXRelToBeamspot");
122 static const SG::ConstAccessor<float> acc_localY("HitsYRelToBeamspot");
123 static const SG::ConstAccessor<float> acc_localZ("HitsZRelToBeamspot");
124
125 return jab_inv(2, 0)*acc_localX(hit) + jab_inv(2, 1)*acc_localY(hit) + jab_inv(2, 2)*acc_localZ(hit);
126}
127
128
129float layer(const xAOD::IParticle& /*p*/, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d& /*jab_inv*/) {
130 static const SG::AuxElement::ConstAccessor<int> acc_layer("layer");
131 return acc_layer(hit);
132}
133
134} // namespace TauHitVars
static Double_t a
std::tuple< Inputs, std::vector< const xAOD::IParticle * > > getData(const xAOD::IParticle &p) const override
std::function< float(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &, const Eigen::Matrix3d &)> FeatureFunc_t
FeatureFunc_t getFeatureExtractor(const std::string &var_name) const
const Inputs getFeatures(const xAOD::IParticle &p, const std::vector< const xAOD::TrackMeasurementValidation * > &hits) const
ConstituentLoaderTauHit(const ConstituentsInputConfig &cfg, const std::string &hits_key)
static const std::unordered_map< std::string, FeatureFunc_t > m_func_map
const std::vector< const xAOD::TrackMeasurementValidation * > getParticleHits(const xAOD::IParticle &p) const
const Eigen::Matrix3d getJABInvMatrix(const xAOD::IParticle &p) const
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:570
Helper class to provide constant type-safe access to aux data.
Class providing the definition of the 4-vector interface.
This file contains "getter" functions used for accessing tagger inputs from the EDM.
std::pair< std::vector< float >, std::vector< int64_t > > Inputs
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
float layer(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &)
float b(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version: