ATLAS Offline Software
Loading...
Searching...
No Matches
RecoverZeroPixelHitMuons.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <TVector3.h>
7
8RecoverZeroPixelHitMuons::RecoverZeroPixelHitMuons(const std::string& name, ISvcLocator* pSvcLocator) :
9 AthReentrantAlgorithm(name, pSvcLocator)
10{
11}
12
14{
18
19 return StatusCode::SUCCESS;
20}
21
22
23StatusCode RecoverZeroPixelHitMuons::execute(const EventContext& context) const
24{
25
27 if( ! inputMuons.isValid() ) {
28 ATH_MSG_ERROR ("Couldn't retrieve xAOD::MuonContainer with key: " << m_inputMuonContainerKey.key() );
29 return StatusCode::FAILURE;
30 }
31
33 if( ! inputTracks.isValid() ) {
34 ATH_MSG_ERROR ("Couldn't retrieve xAOD::TrackParticleContainer with key: " << m_inputTrackContainerKey.key() );
35 return StatusCode::FAILURE;
36 }
37
38 auto outputMuons = std::make_unique<xAOD::MuonContainer>();
39 auto outputMuonsAux = std::make_unique<xAOD::MuonAuxContainer>();
40
41 outputMuons->setStore (outputMuonsAux.get());
42
44 double track_eta=0.0;
45 double track_phi=0.0;
46 double track_charge=0.0;
47 double mu_charge=0.0;
48 std::vector<const xAOD::Muon*> matchedMuons;
49 int n_tracks=0;
50 for (const xAOD::TrackParticle *t : *inputTracks){
51 n_tracks++;
52 // if we have a pixel hit, should reconstruct these guys as combined muons
53 uint8_t nPixHits = 0;
54 t->summaryValue(nPixHits,xAOD::numberOfPixelHits);
55 if (nPixHits > 0) continue;
56
57 // Define ID track vector and charge
58 TVector3 track_vector;
59 track_vector.SetPtEtaPhi(t->pt(), t->eta(), t->phi());
60 track_eta=t->eta();
61 track_phi=t->phi();
62 track_charge=t->charge();
63 // loop over muons
65 float min_dR=999.;
66 float min_mu_charge=0.0;
68
69 for (muItr = inputMuons->begin(); muItr != inputMuons->end(); ++muItr){
70 const xAOD::Muon &m = *(*muItr);
71 if (m.muonType() != xAOD::Muon::MuonStandAlone) continue;
72 if (std::find(matchedMuons.begin(), matchedMuons.end(), *muItr) != matchedMuons.end()) continue;
73
74 // Define SA muon vector
75 TVector3 mu_vector;
76 mu_vector.SetPtEtaPhi(m.pt(), m.eta(), m.phi());
77 mu_charge=m.charge();
78 float mu_dR=mu_vector.DeltaR(track_vector);
79
80 // Update matching between ID track and SA muon
81 if (mu_dR < min_dR){
82 min_dR=mu_dR;
83 min_mu_charge=mu_charge;
84 muMatchItr=muItr;
85 }
86 }
87 if ((min_dR < m_matchingDeltaR) && (min_mu_charge == track_charge)){
88 matchedMuons.push_back(*muMatchItr);
89 const xAOD::Muon &muon_match = *(*muMatchItr);
90 xAOD::Muon *zeroPixelHitMuon = new xAOD::Muon(muon_match);
91 outputMuons->push_back(zeroPixelHitMuon);
92 zeroPixelHitMuon->setP4(muon_match.pt(),track_eta,track_phi);
93 zeroPixelHitMuon->setCharge(min_mu_charge);
94 // Set to not assigned Muon Type to distinguish from other muons, will need to properly define in MuonType enum later
95 zeroPixelHitMuon->setMuonType((xAOD::Muon::MuonType)10);
96 ElementLink<xAOD::TrackParticleContainer> link( *inputTracks, n_tracks-1 );
97 zeroPixelHitMuon->setTrackParticleLink(xAOD::Muon::InnerDetectorTrackParticle, link);
98 }
99
100 }
101
103
104 CHECK( outputMuonsHandle.record (std::move(outputMuons), std::move (outputMuonsAux)) );
105
106
107
108 return StatusCode::SUCCESS;
109}
110
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define CHECK(...)
Evaluate an expression and check for errors.
An algorithm that can be simultaneously executed in multiple threads.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
RecoverZeroPixelHitMuons(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTrackContainerKey
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &context) const override
Gaudi::Property< float > m_matchingDeltaR
SG::WriteHandleKey< xAOD::MuonContainer > m_outputMuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_inputMuonContainerKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setTrackParticleLink(TrackParticleType type, const ElementLink< TrackParticleContainer > &link)
Set method for TrackParticle links.
Definition Muon_v1.cxx:501
void setMuonType(MuonType type)
virtual double pt() const
The transverse momentum ( ) of the particle.
void setP4(double pt, double eta, double phi)
Set method for IParticle values.
Definition Muon_v1.cxx:58
void setCharge(float charge)
Set the charge (must be the same as primaryTrackParticle() )
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].