ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEFInfoToMuonCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5//
6// TrigMuonEFInfoToMuonCnvTool.cxx
7//
8// Created by Mark Owen on 12/03/2014.
9//
10
12
13#include "AthLinks/ElementLink.h"
16
20TrigMuonEFInfoToMuonCnvTool::TrigMuonEFInfoToMuonCnvTool(const std::string& type, const std::string& name, const IInterface* parent) :
21 AthAlgTool(type,name,parent)
22{
23 declareInterface<ITrigMuonEFInfoToMuonCnvTool>(this);
24
25 declareProperty( "MakeIDTrackLink", m_makeIDTrackLink = true);
26 declareProperty( "xAODEFInDetTrackParticleContainerName", m_inDetTrackParticles = "EFInDetTrackParticles" );
27}
28
33
34 if(m_makeIDTrackLink) ATH_MSG_INFO("Will make links to EF ID xAOD track particles");
35 else ATH_MSG_INFO("Will not make links to EF ID xAOD track particles");
36 ATH_MSG_INFO("EF ID track particle container name: " << m_inDetTrackParticles);
37
38 return StatusCode::SUCCESS;
39}
40
48 xAOD::MuonContainer& muoncontainer,
49 xAOD::TrackParticleContainer* combParticleContainer,
50 xAOD::TrackParticleContainer* extrapParticleContainer) const {
51
52 ATH_MSG_DEBUG("Start conversion of TrigMuonEFInfo, n(muons) to convert = " << efinfo.TrackContainer()->size());
53 const int nmuin = muoncontainer.size();
54 // loop on TrigMuonEFInfoTracks attached to this TrigMuonEFInfo object
55 for( const auto *infotrk : *(efinfo.TrackContainer()) ) {
56
57 if( !infotrk->hasExtrapolatedTrack() && !infotrk->hasCombinedTrack() ){
58 ATH_MSG_WARNING("TrigMuonEFInfoTrack has no extrapolated or combined track, will not be converted to xAOD");
59 continue;
60 }
61
62 // TrigMuonEFInfoTracks are essentially muons, so create an xAOD::Muon at this point and put it in the container
63 xAOD::Muon* muon = new xAOD::Muon();
64 muoncontainer.push_back(muon);
65
66 // make extrapolated TrackParticle and fill it
67 if(infotrk->hasExtrapolatedTrack()) {
68 const TrigMuonEFTrack* extraptrk = infotrk->ExtrapolatedTrack();
69 xAOD::TrackParticle* extrapTrackPart = new xAOD::TrackParticle();
70 if(extrapParticleContainer) extrapParticleContainer->push_back( extrapTrackPart );
71 else extrapTrackPart->makePrivateStore();
72
73 StatusCode sc = convertTrigMuonEFTrack( *extraptrk, *extrapTrackPart );
74 if(sc.isFailure()) return sc;
75
76 // create and set element link to the xAOD::TrackParticle
77 if(extrapParticleContainer) {
78 ElementLink<xAOD::TrackParticleContainer> link( *extrapParticleContainer, extrapParticleContainer->size() - 1 );
79 muon->setTrackParticleLink( xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle, link );
80 }
81
82 // set main muon 4-vector to the extrapolated track
83 muon->setP4(extraptrk->pt(),extraptrk->eta(),extraptrk->phi());
84 // set some author flags - note this relies on the 'knowledge' that we only ran muid at EF before 2015
85 muon->addAllAuthor(xAOD::Muon::Author::MuidSA);
86 muon->setAuthor(xAOD::Muon::Author::MuidSA);
87 muon->setMuonType(xAOD::Muon::MuonType::MuonStandAlone);
88
89 // clean up the track particle in case we did not put it in a container
90 if(!extrapParticleContainer) delete extraptrk;
91 }
92
93 // make combined TrackParticle object and fill it
94 if(infotrk->hasCombinedTrack()) {
95 const TrigMuonEFCbTrack* combtrk = infotrk->CombinedTrack();
96 xAOD::TrackParticle* combinedTrackPart = new xAOD::TrackParticle();
97 if(combParticleContainer) combParticleContainer->push_back( combinedTrackPart );
98 else combinedTrackPart->makePrivateStore();
99
100 StatusCode sc = convertTrigMuonEFTrack( *combtrk, *combinedTrackPart );
101 if(sc.isFailure()) return sc;
102
103 // create and set element link to the xAOD::TrackParticle
104 if(combParticleContainer) {
105 ElementLink<xAOD::TrackParticleContainer> link( *combParticleContainer, combParticleContainer->size() - 1 );
106 muon->setTrackParticleLink( xAOD::Muon::TrackParticleType::CombinedTrackParticle, link );
107 }
108
109 // set main muon 4-vector to the combined track
110 muon->setP4(combtrk->pt(),combtrk->eta(),combtrk->phi());
111 // set some author flags - note this relies on the 'knowledge' that we ran muid and mugirl at EF before 2015
112 if( infotrk->MuonType() == TrigMuonEFInfoTrack::MuonTypeEFMuon ) {
113 muon->addAllAuthor(xAOD::Muon::Author::MuidCo);
114 muon->setAuthor(xAOD::Muon::Author::MuidCo);
115 muon->setMuonType(xAOD::Muon::MuonType::Combined);
116 } else {
117 muon->addAllAuthor(xAOD::Muon::Author::MuGirl);
118 muon->setAuthor(xAOD::Muon::Author::MuGirl);
119 // we set all MuGirl to be combined because we set the combined track, could change this once ID track link works
120 muon->setMuonType(xAOD::Muon::MuonType::Combined);
121 }
122
124 // create element link to the ID track
126 if(oldLink.isValid()) {
127 // This code assumes that the tracks in the xAOD EF ID track container are in the same order as in the Rec::TrackParticle container
128 // Same assumption was made in the offline code,
130 std::string name = m_inDetTrackParticles;
131 if (name.empty())
132 name = oldLink.dataID();
133 newLink.resetWithKeyAndIndex( name, oldLink.index() );
134 if(newLink.isValid()) ATH_MSG_VERBOSE("Successfully created element link to ID xAOD track particle");
135 else ATH_MSG_WARNING("Created an invalid element link to ID xAOD track particle");
136
137 } else ATH_MSG_WARNING("TrigMuonEFCbTrack with invalid element link to ID track - cannot create link for xAOD muon");
138 }//create element link to ID track
139
140 // clean up the track particle in case we did not put it in a container
141 if(!combParticleContainer) delete combinedTrackPart;
142
143 } // valid combinedTrack
144
145 }// loop on TrigMuonEFInfoTracks in the TrigMuonEFInfo objects
146
147 ATH_MSG_DEBUG("Conversion finished, n(muons) added to xAOD container = " << muoncontainer.size()-nmuin);
148
149 return StatusCode::SUCCESS;
150
151}// end convertTrigMuonEFInfo function
152
155 xAOD::MuonContainer& muoncontainer,
156 xAOD::TrackParticleContainer* combParticleContainer,
157 xAOD::TrackParticleContainer* extrapParticleContainer) const {
158 //loop on TrigMunEFInfo objects and convert them
159 for(const auto *efinfo : efinfocont) {
160 StatusCode sc = convertTrigMuonEFInfo( *efinfo, muoncontainer, combParticleContainer, extrapParticleContainer );
161 if(sc.isFailure()) return sc;
162 }
163
164 return StatusCode::SUCCESS;
165}// end convertTrigMuonEFInfoContainer
166
171 double p = 0.0001;
172 const double charge = eftrack.charge();
173 if( std::abs(eftrack.p()) < p ) {
174 ATH_MSG_WARNING("TrigMuonEFTrack has p close to zero = " << eftrack.p() << "set to " << p);
175 } else {
176 p = std::abs(eftrack.p());
177 }
178 const double qoverp = charge / p;
179 double theta = atan(eftrack.tanTh());
180 if(theta < 0.0) theta += M_PI ; // atan returns theta in -pi/2 -> pi/2, so convert to 0 -> pi
181
182 trackpart.setDefiningParameters( eftrack.d0(), eftrack.z0(), eftrack.phi(), theta, qoverp);
183 trackpart.setParametersOrigin( eftrack.posX(), eftrack.posY(), eftrack.posZ() );
184
185 /*if(abs(eftrack.pt() - trackpart.pt())> 10.0) {
186 if(eftrack.pt() < 1000000.0) {
187 ATH_MSG_ERROR("pT mismatch, parameters are:");
188 ATH_MSG_ERROR("input d0, z0, phi, theta, qoverp = " << eftrack.d0() << ", " << eftrack.z0() << ", " << eftrack.phi() << ", " << theta << ", " << qoverp);
189 ATH_MSG_ERROR("old e, pt, eta, phi, m = " << std::fixed << std::setprecision(8) << eftrack.e() << ", " << eftrack.pt() << ", " << eftrack.eta() << ", " << eftrack.phi() << ", " << eftrack.m());
190 ATH_MSG_ERROR("new e, pt, eta, phi, m = " << std::fixed << std::setprecision(8) << trackpart.e() << ", " << trackpart.pt() << ", " << trackpart.eta() << ", " << trackpart.phi() << ", " << trackpart.m());
191 return StatusCode::FAILURE;
192 }
193 }*/
194
195 return StatusCode::SUCCESS;
196} // end convertTrigMuonEFTrack function
#define M_PI
Scalar theta() const
theta method
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual double eta() const
pseudo rapidity
virtual double p() const
momentum magnitude
virtual double pt() const
transverse momentum
virtual double tanTh() const
tan theta
virtual double phi() const
get phi data member
const ElementLink< Rec::TrackParticleContainer > & getIDTrackParticleLink() const
virtual StatusCode convertTrigMuonEFInfoContainer(const TrigMuonEFInfoContainer &efinfocont, xAOD::MuonContainer &muoncontainer, xAOD::TrackParticleContainer *combParticleContainer, xAOD::TrackParticleContainer *extrapParticleContainer) const override
Convert full TrigMuonEFInfoContainer into xAOD::MuonContainer.
TrigMuonEFInfoToMuonCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
bool m_makeIDTrackLink
Flag to decide if we want to make element link to EF ID xAOD tracks - only turn on once EF ID convers...
virtual StatusCode initialize() override
initialize the tool
StatusCode convertTrigMuonEFTrack(const TrigMuonEFTrack &eftrack, xAOD::TrackParticle &trackpart) const
Convert TrigMuonEFTrack into a xAOD::TrackParticle.
std::string m_inDetTrackParticles
Name of container that holds the EF ID xAOD track particles.
virtual StatusCode convertTrigMuonEFInfo(const TrigMuonEFInfo &efinfo, xAOD::MuonContainer &muoncontainer, xAOD::TrackParticleContainer *combParticleContainer, xAOD::TrackParticleContainer *extrapParticleContainer) const override
Convert a single TrigMuonEFInfo object into (maybe multiple) xAOD::Muon objects.
static const int MuonTypeEFMuon
const TrigMuonEFInfoTrackContainer * TrackContainer() const
double posZ() const
double posY() const
double posX() const
double d0() const
double z0() const
double charge() const
void setParametersOrigin(float x, float y, float z)
Set the origin for the parameters.
void setDefiningParameters(float d0, float z0, float phi0, float theta, float qOverP)
Set the defining parameters.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".