ATLAS Offline Software
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 
20 TrigMuonEFInfoToMuonCnvTool::TrigMuonEFInfoToMuonCnvTool(const std::string& type, const std::string& name, const IInterface* 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 
125  if(m_makeIDTrackLink) {
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
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
TrigMuonEFTrack::posX
double posX() const
Definition: TrigMuonEFTrack.h:98
TrigMuonEFTrack::charge
double charge() const
Definition: TrigMuonEFTrack.h:52
xAOD::MuGirl
@ MuGirl
MuGirl.
Definition: TrackingPrimitives.h:141
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigMuonEFTrack
Definition: TrigMuonEFTrack.h:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TrigMuonEFInfoToMuonCnvTool::initialize
virtual StatusCode initialize() override
initialize the tool
Definition: TrigMuonEFInfoToMuonCnvTool.cxx:32
TrigMuonEFInfoToMuonCnvTool::convertTrigMuonEFInfo
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.
Definition: TrigMuonEFInfoToMuonCnvTool.cxx:47
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
TrigMuonEFCbTrack.h
M_PI
#define M_PI
Definition: ActiveFraction.h:11
TrigMuonEFTrack::d0
double d0() const
Definition: TrigMuonEFTrack.h:59
xAOD::TrackParticle_v1::setDefiningParameters
void setDefiningParameters(float d0, float z0, float phi0, float theta, float qOverP)
Set the defining parameters.
Definition: TrackParticle_v1.cxx:177
TrigMuonEFCbTrack::getIDTrackParticleLink
const ElementLink< Rec::TrackParticleContainer > & getIDTrackParticleLink() const
Definition: TrigMuonEFCbTrack.h:53
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TrigMuonEFInfoContainer
Definition: TrigMuonEFInfoContainer.h:27
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TrigMuonEFInfoToMuonCnvTool::convertTrigMuonEFInfoContainer
virtual StatusCode convertTrigMuonEFInfoContainer(const TrigMuonEFInfoContainer &efinfocont, xAOD::MuonContainer &muoncontainer, xAOD::TrackParticleContainer *combParticleContainer, xAOD::TrackParticleContainer *extrapParticleContainer) const override
Convert full TrigMuonEFInfoContainer into xAOD::MuonContainer.
Definition: TrigMuonEFInfoToMuonCnvTool.cxx:156
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
P4IPtCotThPhiMBase::p
virtual double p() const
momentum magnitude
Definition: P4IPtCotThPhiMBase.cxx:18
TrigMuonEFTrack::posY
double posY() const
Definition: TrigMuonEFTrack.h:108
P4IPtCotThPhiMBase::eta
virtual double eta() const
pseudo rapidity
Definition: P4IPtCotThPhiMBase.cxx:76
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
P4IPtCotThPhiM::phi
virtual double phi() const
get phi data member
Definition: P4IPtCotThPhiM.h:106
TrigMuonEFInfoToMuonCnvTool::m_inDetTrackParticles
std::string m_inDetTrackParticles
Name of container that holds the EF ID xAOD track particles.
Definition: TrigMuonEFInfoToMuonCnvTool.h:61
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TrigMuonEFCbTrack
Definition: TrigMuonEFCbTrack.h:28
TrigMuonEFInfoToMuonCnvTool::m_makeIDTrackLink
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...
Definition: TrigMuonEFInfoToMuonCnvTool.h:58
charge
double charge(const T &p)
Definition: AtlasPID.h:494
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
MuonParameters::MuidSA
@ MuidSA
Definition: MuonParamDefs.h:59
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
TrigMuonEFTrack::posZ
double posZ() const
Definition: TrigMuonEFTrack.h:118
TrigMuonEFInfoToMuonCnvTool::convertTrigMuonEFTrack
StatusCode convertTrigMuonEFTrack(const TrigMuonEFTrack &eftrack, xAOD::TrackParticle &trackpart) const
Convert TrigMuonEFTrack into a xAOD::TrackParticle.
Definition: TrigMuonEFInfoToMuonCnvTool.cxx:172
TrigMuonEFInfoToMuonCnvTool.h
MuonParameters::MuidCo
@ MuidCo
Definition: MuonParamDefs.h:60
TrigMuonEFTrack::z0
double z0() const
Definition: TrigMuonEFTrack.h:69
TrigMuonEFInfoTrackContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigMuonEFInfoToMuonCnvTool::TrigMuonEFInfoToMuonCnvTool
TrigMuonEFInfoToMuonCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: TrigMuonEFInfoToMuonCnvTool.cxx:20
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigMuonEFInfo::TrackContainer
const TrigMuonEFInfoTrackContainer * TrackContainer() const
Definition: TrigMuonEFInfo.h:94
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
TrigMuonEFInfoTrack::MuonTypeEFMuon
static const int MuonTypeEFMuon
Definition: TrigMuonEFInfoTrack.h:25
xAOD::TrackParticle_v1::setParametersOrigin
void setParametersOrigin(float x, float y, float z)
Set the origin for the parameters.
Definition: TrackParticle_v1.cxx:473
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigMuonEFInfo
Definition: TrigMuonEFInfo.h:24
P4IPtCotThPhiMBase::pt
virtual double pt() const
transverse momentum
Definition: P4IPtCotThPhiMBase.cxx:12
P4IPtCotThPhiMBase::tanTh
virtual double tanTh() const
tan theta
Definition: P4IPtCotThPhiMBase.cxx:36