ATLAS Offline Software
JetHitAssociationAlg.cxx
Go to the documentation of this file.
1 /*
2 Copyright (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 
15 namespace 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
31  ATH_CHECK(m_HitsXRelToBeamspotKey.initialize());
33  ATH_CHECK(m_HitsYRelToBeamspotKey.initialize());
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) = vectorEL;
102  }
103 
104  return StatusCode::SUCCESS;
105  }
106 
107 
109  return StatusCode::SUCCESS;
110  }
111 
112 }
FlavorTagDiscriminants::JetHitAssociationAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: JetHitAssociationAlg.cxx:43
FlavorTagDiscriminants::JetHitAssociationAlg::m_inputPixHitCollectionKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_inputPixHitCollectionKey
Definition: JetHitAssociationAlg.h:47
FlavorTagDiscriminants::JetHitAssociationAlg::m_jetCollectionKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetCollectionKey
Definition: JetHitAssociationAlg.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
FlavorTagDiscriminants::JetHitAssociationAlg::m_hitAssociationKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_hitAssociationKey
Definition: JetHitAssociationAlg.h:56
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
FlavorTagDiscriminants::JetHitAssociationAlg::JetHitAssociationAlg
JetHitAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: JetHitAssociationAlg.cxx:17
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
JetHitAssociationAlg.h
M_PI
#define M_PI
Definition: ActiveFraction.h:11
FlavorTagDiscriminants::JetHitAssociationAlg::finalize
virtual StatusCode finalize() override
Definition: JetHitAssociationAlg.cxx:108
FlavorTagDiscriminants::JetHitAssociationAlg::m_HitsYRelToBeamspotKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitsYRelToBeamspotKey
Definition: JetHitAssociationAlg.h:53
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FlavorTagDiscriminants::JetHitAssociationAlg::m_maxHits
Gaudi::Property< int > m_maxHits
Definition: JetHitAssociationAlg.h:62
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:538
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ReadDecorHandle.h
Handle class for reading a decoration on an object.
FlavorTagDiscriminants::JetHitAssociationAlg::m_dPhiHitToJet
Gaudi::Property< float > m_dPhiHitToJet
Definition: JetHitAssociationAlg.h:59
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
FlavorTagDiscriminants::JetHitAssociationAlg::initialize
virtual StatusCode initialize() override
Definition: JetHitAssociationAlg.cxx:21
FlavorTagDiscriminants::JetHitAssociationAlg::m_HitsXRelToBeamspotKey
SG::ReadDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitsXRelToBeamspotKey
Definition: JetHitAssociationAlg.h:50