ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEFTrackIsolationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// local includes
7
8// athena includes
10
11using std::vector;
12
16TrigMuonEFTrackIsolationTool::TrigMuonEFTrackIsolationTool(const std::string& type, const std::string& name, const IInterface* parent) :
17 AthAlgTool( type, name, parent ),
18 m_debug(false),
19 m_deltaz_cut(0.0),
20 m_removeSelf(true),
21 m_useAnnulus(false),
22 m_annulusSize(-1.0),
23 m_useVarIso(false),
24 m_trkSelTool( "InDet::InDetTrackSelectionTool/TrackSelectionTool", this )
25{
26
27 declareInterface<IMuonEFTrackIsolationTool>(this);
28
29 declareProperty("deltaZCut", m_deltaz_cut);
30 declareProperty("removeSelf", m_removeSelf);
31 declareProperty("useAnnulus", m_useAnnulus);
32 declareProperty("annulusSize", m_annulusSize);
33 declareProperty("useVarIso", m_useVarIso);
34 declareProperty("TrackSelectionTool",m_trkSelTool);
35}
36
48
49StatusCode TrigMuonEFTrackIsolationTool::calcTrackIsolation(const xAOD::Muon* efmuon, const xAOD::TrackParticleContainer* idtrks, const vector<double>& conesizes, vector<double>& results, vector<double>* dzvals, vector<double>* drvals, vector<double>* selfremoval) const {
50
51
52 if (m_debug)
53 msg() << MSG::DEBUG << "Running isolation over EF Muon!" << endmsg;
54
55 // clear vectors
56 results.clear();
57 dzvals->clear();
58 drvals->clear();
59 selfremoval->clear();
60
61 // this will point to the muon (combined or extrapolated)
62 const xAOD::TrackParticle* muon=0;
63
64 // variable to store pt of the muon (this is different for different muon types so we pass it separately)
65 double selfpt=0.0;
66
67 //for combined muons use the associated ID track for the self removal
68 const xAOD::TrackParticle* muon_idtrk = 0;
69 const Trk::Perigee* muidtrk_perigee = 0;
70 if( efmuon->combinedTrackParticleLink().isValid() ) {
71 if(m_debug) {
72 msg() << MSG::DEBUG << "EF muon has combined muon" << endmsg;
73 }
74 muon = *(efmuon->combinedTrackParticleLink());
75 if( efmuon->inDetTrackParticleLink().isValid() ) {
76 muon_idtrk = *(efmuon->inDetTrackParticleLink());
77 muidtrk_perigee = &(muon_idtrk->perigeeParameters());
78 selfpt = muon_idtrk->pt();
79 if(m_debug) {
80 msg() << MSG::DEBUG << "Found ID track attached to combined muon, " << muon_idtrk << ",pt = " << selfpt << endmsg;
81 }
82 }
83 else {
84 msg() << MSG::WARNING << "Found EF combined muon without a link to ID track, will use combined pt for self removal" << endmsg;
85 selfpt = muon->pt();
86 }
87 }//combinedmuon
88 else {
89 // for extrapolated muons use the extrapolated muon for self removal
91 if(m_removeSelf) {
92 msg() << MSG::WARNING << "This EF muon has neither a combined or extrapolated muon and removeSelf is requested, do not process further" << endmsg;
93 return StatusCode::FAILURE;
94 }//m_removeSelf
95 msg() << MSG::WARNING << "This EF muon has neither a combined, extrapolated or MS muon, do not process further" << endmsg;
96 return StatusCode::FAILURE;
97 }
98 else {
99 muon = *(efmuon->muonSpectrometerTrackParticleLink());
100 selfpt = muon->pt();
101 }//extrapmuon
102 }//not combined
103
104 StatusCode isoResult = checkIsolation(muon, selfpt, muon_idtrk, muidtrk_perigee, idtrks, conesizes, results, dzvals, drvals, selfremoval);
105
106 return isoResult;
107}
108
109
110// Generic function to take whatever kind of muon and check isolation (so can pass a L2 or EF muon)
111StatusCode TrigMuonEFTrackIsolationTool::checkIsolation(const xAOD::IParticle* muon, double selfpt, const xAOD::TrackParticle* muon_idtrk, const Trk::Perigee* muidtrk_perigee, const xAOD::TrackParticleContainer* trks, vector<double> conesizes, vector<double>& results, vector<double>* dzvals, vector<double>* drvals, vector<double>* selfremoval) const {
112
114 if(m_removeSelf && selfpt==0.0) {
115 msg() << MSG::WARNING << "Inconsistency, removeSelf requested, but selfpt = 0" << endmsg;
116 }
117 if(!muon) {
118 msg() << MSG::WARNING << "Could not find a muon to update with the isolation, skipping this muon" << endmsg;
119 return StatusCode::FAILURE;
120 }
121
122 // fill results vector with 0
123 results.insert(results.end(), conesizes.size(), 0.0);
124
125 // loop over other tracks in the container
126 // these are arrays, so that if using leadTrk or dRMatched selfremoval it can be different between the two cone sizes
127 int ntrks_tmp[2];
128 ntrks_tmp[0]=0; ntrks_tmp[1]=0;
129
130
132 trkit!=trks->end(); ++trkit) {
133
134 if (m_debug)
135
136 msg() << MSG::DEBUG << "INFO: Track pT = " << (*trkit)->pt() << " eta = " << (*trkit)->eta() << endmsg;
137
138 // check track passes the selection tool
139 const auto& trkSelResult = m_trkSelTool->accept(*trkit);
140 if(trkSelResult) {
141 ATH_MSG_DEBUG("Track passes selection tool");
142 } else {
143 if(m_debug) {
144 ATH_MSG_DEBUG("Track failed selection tool");
145 for(unsigned int i=0; i<trkSelResult.getNCuts (); ++i) {
146 ATH_MSG_DEBUG(" Cut " << i << trkSelResult.getCutName(i).data() << " pass = " << trkSelResult.getCutResult(i));
147 }
148 }
149 continue; // skip this track
150 }
151
152 // check dZ if necessary
153 double dz=0;
154 if(m_deltaz_cut > 0.0 && muidtrk_perigee) {
155 const Trk::Perigee& idtrk_perigee = (*trkit)->perigeeParameters();
156 dz = idtrk_perigee.parameters()[Trk::z0] - muidtrk_perigee->parameters()[Trk::z0];
157 if( fabs(dz) > m_deltaz_cut ) {
158 if(m_debug) {
159 msg() << MSG::DEBUG << "Track failed dz cut, ignoring it. dz = " << dz << endmsg;
160 }
161 continue;
162 }//failed delta(z)
163 // store dz (after cut)
164 // if(dzvals) dzvals->push_back(dz); // moved to after the pT cut for plotting purposes
165 if(m_debug) {
166 msg() << MSG::DEBUG << "ID track passes dz cut. dz = " << dz << endmsg;
167 }
168
169 }//deltaz_cut
170 if(dzvals) dzvals->push_back(dz);
171
172 // check if trk within cone
173 double dr = 0;
174 if(muon_idtrk) { //use ID track for dR if available
175 dr = (*trkit)->p4().DeltaR( muon_idtrk->p4() );
176 } else { //use the muon
177 dr = (*trkit)->p4().DeltaR( muon->p4() );
178 }
179
180 if(drvals) drvals->push_back(dr);
181
182 // if needed check the inner annululs
183 if(m_useAnnulus) {
184 if( dr < m_annulusSize ) {
185 if(m_debug) {
186 msg() << MSG::DEBUG << "ID track within annulus, ignoring it, dR = " << dr << ", annulus = " << m_annulusSize << endmsg;
187
188 }
189 continue; // skip tracks in the annulus
190 }//annulus cut
191 if(m_debug) {
192 msg() << MSG::DEBUG << "ID track outside annulus, keep it, dR = " << dr << ", annulus = " << m_annulusSize << endmsg;
193 }
194 }//use Annulus
195
196 // Define new conesizes that depend on useVarIso flag
197 double ptvarcone20 = std::min(0.2,10000/selfpt);
198 double ptvarcone30 = std::min(0.3,10000/selfpt);
199 if (m_useVarIso){
200 conesizes.clear();
201 conesizes.push_back(ptvarcone20);
202 conesizes.push_back(ptvarcone30);
203 }
204
205 // add trk pT to relevant results vector
206 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
207 if(dr < conesizes.at(conepos) ) {
208 if(m_debug) {
209 msg() << MSG::DEBUG << "Adding trk pt = " << (*trkit)->pt() << ", with dr = " << dr << ", into cone = " << conesizes.at(conepos) << endmsg;
210 }
211 results.at(conepos) += (*trkit)->pt();
212 ++ntrks_tmp[conepos];
213
214 }
215 }
216
217 }// track loop
218
219 // Muon pT plots
220 selfremoval->push_back(selfpt);
221 selfremoval->push_back(muon->pt());
222
223 if(m_debug) {
224 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
225 msg() << MSG::DEBUG << "Scalar pT sum of tracks around this muon cone " << conesizes.at(conepos) << " = " << results.at(conepos) << endmsg;
226 }
227 }
228 if(m_removeSelf && !m_useAnnulus) { // remove muon pt from the sums
229 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
230 results.at(conepos) -= selfpt;
231 }
232 if(m_debug) {
233 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
234 msg() << MSG::DEBUG << "Scalar pT sum of tracks around this muon cone " << conesizes.at(conepos) << " after self removal = " << results.at(conepos) << endmsg;
235 }
236 }
237
238 }//m_removeSelf
239
240 return StatusCode::SUCCESS;
241}
242
243
245
246 m_debug = msgLvl(MSG::DEBUG);
247
248 if(m_trkSelTool.retrieve().isFailure()){
249 ATH_MSG_FATAL("Could not retrieve InDetTrackSelectionTool");
250 return StatusCode::FAILURE;
251 }
252
253 if(m_debug) {
254 msg() << MSG::DEBUG << "Initializing TrigMuonEFTrackIsolationTool[" << name() << "]" << endmsg;
255 msg() << MSG::DEBUG
256 << "Properties set as follows: " << endmsg;
257 msg() << MSG::DEBUG
258 << "removeSelf " << m_removeSelf << endmsg;
259 msg() << MSG::DEBUG
260 << "deltaZCut " << m_deltaz_cut << endmsg;
261 msg() << MSG::DEBUG
262 << "useAnnulus " << m_useAnnulus << endmsg;
263 msg() << MSG::DEBUG
264 << "annulusSize " << m_annulusSize << endmsg;
265 msg() << MSG::DEBUG
266 << "useVarIso " << m_useVarIso << endmsg;
267 msg() << MSG::DEBUG
268 << "TrackSelectionTool " << m_trkSelTool << endmsg;
269
270 }//debug
271
272 // check the annulus size is valid
273 if(m_useAnnulus) {
275 msg() << MSG::ERROR << "Bad configuration of annulusSize = " << m_annulusSize << ", fix your config!" << endmsg;
276 return StatusCode::FAILURE;
277 }
278 }//useAnnulus
279
280 return StatusCode::SUCCESS;
281}
#define endmsg
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
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)
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
StatusCode checkIsolation(const xAOD::IParticle *muon, double selfpt, const xAOD::TrackParticle *muon_idtrk, const Trk::Perigee *muidtrk_perigee, const xAOD::TrackParticleContainer *trks, std::vector< double > conesizes, std::vector< double > &results, std::vector< double > *dzvals, std::vector< double > *drvals, std::vector< double > *selfremoval) const
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool
Track selection tool.
double m_annulusSize
size of the annulus within which we ignore tracks
bool m_useAnnulus
flag to determine if we should use an inner annulus
virtual StatusCode initialize() override
initialize the tool
TrigMuonEFTrackIsolationTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
bool m_removeSelf
flag to determine whether to remove pT of muon track from the calculation
double m_deltaz_cut
cut between z of muon id trk and z of id trks - < 0 means no cut
virtual StatusCode calcTrackIsolation(const xAOD::Muon *efmuon, const xAOD::TrackParticleContainer *idtrks, const std::vector< double > &conesizes, std::vector< double > &results, std::vector< double > *dzvals, std::vector< double > *drvals, std::vector< double > *selfremoval) const override
Sum the track pT in cones around the muon.
bool m_useVarIso
flag to determine if we want to use offline isolation variables
Class providing the definition of the 4-vector interface.
const ElementLink< TrackParticleContainer > & combinedTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.
const ElementLink< TrackParticleContainer > & inDetTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.
const ElementLink< TrackParticleContainer > & muonSpectrometerTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ z0
Definition ParamDefs.h:64
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: