ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEFInfoToMuonCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 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::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::MuidSA);
86 muon->setAuthor(xAOD::Muon::MuidSA);
87 muon->setMuonType(xAOD::Muon::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::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::MuidCo);
114 muon->setAuthor(xAOD::Muon::MuidCo);
115 muon->setMuonType(xAOD::Muon::Combined);
116 } else {
117 muon->addAllAuthor(xAOD::Muon::MuGirl);
118 muon->setAuthor(xAOD::Muon::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::Combined);
121 //if( infotrk->MuonType() == TrigMuonEFInfoTrack::MuGirlMuonTag) muon->setMuonType(xAOD::Muon::SegmentTagged);
122 //else muon->setMuonType(xAOD::Muon::Combined);
123 }
124
126 // create element link to the ID track
128 if(oldLink.isValid()) {
129 // This code assumes that the tracks in the xAOD EF ID track container are in the same order as in the Rec::TrackParticle container
130 // Same assumption was made in the offline code,
132 std::string name = m_inDetTrackParticles;
133 if (name.empty())
134 name = oldLink.dataID();
135 newLink.resetWithKeyAndIndex( name, oldLink.index() );
136 if(newLink.isValid()) ATH_MSG_VERBOSE("Successfully created element link to ID xAOD track particle");
137 else ATH_MSG_WARNING("Created an invalid element link to ID xAOD track particle");
138
139 } else ATH_MSG_WARNING("TrigMuonEFCbTrack with invalid element link to ID track - cannot create link for xAOD muon");
140 }//create element link to ID track
141
142 // clean up the track particle in case we did not put it in a container
143 if(!combParticleContainer) delete combinedTrackPart;
144
145 } // valid combinedTrack
146
147 }// loop on TrigMuonEFInfoTracks in the TrigMuonEFInfo objects
148
149 ATH_MSG_DEBUG("Conversion finished, n(muons) added to xAOD container = " << muoncontainer.size()-nmuin);
150
151 return StatusCode::SUCCESS;
152
153}// end convertTrigMuonEFInfo function
154
157 xAOD::MuonContainer& muoncontainer,
158 xAOD::TrackParticleContainer* combParticleContainer,
159 xAOD::TrackParticleContainer* extrapParticleContainer) const {
160 //loop on TrigMunEFInfo objects and convert them
161 for(const auto *efinfo : efinfocont) {
162 StatusCode sc = convertTrigMuonEFInfo( *efinfo, muoncontainer, combParticleContainer, extrapParticleContainer );
163 if(sc.isFailure()) return sc;
164 }
165
166 return StatusCode::SUCCESS;
167}// end convertTrigMuonEFInfoContainer
168
173 double p = 0.0001;
174 const double charge = eftrack.charge();
175 if( std::abs(eftrack.p()) < p ) {
176 ATH_MSG_WARNING("TrigMuonEFTrack has p close to zero = " << eftrack.p() << "set to " << p);
177 } else {
178 p = std::abs(eftrack.p());
179 }
180 const double qoverp = charge / p;
181 double theta = atan(eftrack.tanTh());
182 if(theta < 0.0) theta += M_PI ; // atan returns theta in -pi/2 -> pi/2, so convert to 0 -> pi
183
184 trackpart.setDefiningParameters( eftrack.d0(), eftrack.z0(), eftrack.phi(), theta, qoverp);
185 trackpart.setParametersOrigin( eftrack.posX(), eftrack.posY(), eftrack.posZ() );
186
187 /*if(abs(eftrack.pt() - trackpart.pt())> 10.0) {
188 if(eftrack.pt() < 1000000.0) {
189 ATH_MSG_ERROR("pT mismatch, parameters are:");
190 ATH_MSG_ERROR("input d0, z0, phi, theta, qoverp = " << eftrack.d0() << ", " << eftrack.z0() << ", " << eftrack.phi() << ", " << theta << ", " << qoverp);
191 ATH_MSG_ERROR("old e, pt, eta, phi, m = " << std::fixed << std::setprecision(8) << eftrack.e() << ", " << eftrack.pt() << ", " << eftrack.eta() << ", " << eftrack.phi() << ", " << eftrack.m());
192 ATH_MSG_ERROR("new e, pt, eta, phi, m = " << std::fixed << std::setprecision(8) << trackpart.e() << ", " << trackpart.pt() << ", " << trackpart.eta() << ", " << trackpart.phi() << ", " << trackpart.m());
193 return StatusCode::FAILURE;
194 }
195 }*/
196
197 return StatusCode::SUCCESS;
198} // 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
void makePrivateStore()
Create a new (empty) private store for this object.
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".