ATLAS Offline Software
Loading...
Searching...
No Matches
JetHitAssociationAlg.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5//Include header file
7
10
11//Include some helpful ROOT objects here.
12#include "math.h"
13
14
15namespace FlavorTagDiscriminants {
16
17 JetHitAssociationAlg::JetHitAssociationAlg(const std::string& name, ISvcLocator* loc)
18 : AthReentrantAlgorithm(name, loc){}
19
20
22
23 ATH_MSG_INFO( "Initializing " << name() );
24
25 // Initialize reader
27 ATH_CHECK(m_jetCollectionKey.initialize());
28
29 // Initialize decoration reader
34
35 // Initialize decorator
37 CHECK(m_hitAssociationKey.initialize());
38
39 return StatusCode::SUCCESS;
40 }
41
42
43 StatusCode JetHitAssociationAlg::execute(const EventContext& ctx) const {
44 ATH_MSG_DEBUG( "Executing " << name());
45
46 // Read out jets
48 if ( !jetReadHandle.isValid() ) {
49 ATH_MSG_ERROR("Failed to retrieve jet container with key " << m_jetCollectionKey.key() );
50 return StatusCode::FAILURE;
51 }
52
53 std::vector<const xAOD::Jet*> jets;
54 jets.reserve( jetReadHandle->size() );
55 for (const xAOD::Jet *jet : *jetReadHandle) {
56 jets.push_back(jet);
57 }
58
59 // Read out hits relative to beamspot
62
63 // Calculate hit phi values
64 std::vector<std::pair<float, const xAOD::TrackMeasurementValidation*>> hitCoord;
65
66 for (const auto* hit : *HitsXRelToBeamspot) {
67 auto localX = HitsXRelToBeamspot(*hit);
68 auto localY = HitsYRelToBeamspot(*hit);
69 float phi = std::atan2(localY, localX);
70 hitCoord.emplace_back(phi,hit);
71 }
72
73 // Set up element link
75
76 // Loop over jets
77 for (const xAOD::Jet *jet : jets) {
78 std::vector<std::pair<float, const xAOD::TrackMeasurementValidation*>> closeHits;
79 std::vector<ElementLink<xAOD::TrackMeasurementValidationContainer> > vectorEL;
80 double jetPhi = jet->phi();
81
82 // Compare phi values of hits and jets
83 for (const auto& [hitPhi, hit]: hitCoord) {
84 float dPhi = std::abs(jetPhi-hitPhi);
85 while (dPhi > M_PI) {dPhi -= 2. * M_PI; dPhi = std::abs(dPhi);}
86
87 if (dPhi < m_dPhiHitToJet) {
88 closeHits.emplace_back(dPhi, hit);
89 }
90 }
91
92 // Sort hits by dPhi and associate maximal m_maxHits hits to each jet
93 std::sort(closeHits.begin(), closeHits.end(),[](const auto& p1, const auto& p2) { return p1 < p2; });
94 closeHits.resize(std::min(int(m_maxHits), int(closeHits.size())));
95
96 for (const auto& [phi, hit]: closeHits) {
98 }
99
100 // Decorate the ElementLinks of hits to jet
101 hitAssociation(*jet) = std::move(vectorEL);
102 }
103
104 return StatusCode::SUCCESS;
105 }
106
107
109 return StatusCode::SUCCESS;
110 }
111
112}
#define M_PI
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode execute(const EventContext &) const override
SG::WriteDecorHandleKey< xAOD::JetContainer > m_hitAssociationKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_inputPixHitCollectionKey
JetHitAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitsXRelToBeamspotKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetCollectionKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitsYRelToBeamspotKey
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".