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( (muon =efmuon->trackParticle(xAOD::Muon::TrackParticleType::CombinedTrackParticle)) != nullptr ) {
71 if(m_debug) {
72 msg() << MSG::DEBUG << "EF muon has combined muon" << endmsg;
73 }
74 if( efmuon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle) ) {
75 muon_idtrk = efmuon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
76 muidtrk_perigee = &(muon_idtrk->perigeeParameters());
77 selfpt = muon_idtrk->pt();
78 if(m_debug) {
79 msg() << MSG::DEBUG << "Found ID track attached to combined muon, " << muon_idtrk << ",pt = " << selfpt << endmsg;
80 }
81 }
82 else {
83 msg() << MSG::WARNING << "Found EF combined muon without a link to ID track, will use combined pt for self removal" << endmsg;
84 selfpt = muon->pt();
85 }
86 }//combinedmuon
87 else {
88 // for extrapolated muons use the extrapolated muon for self removal
89 if( !efmuon->trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle) ) {
90 if(m_removeSelf) {
91 msg() << MSG::WARNING << "This EF muon has neither a combined or extrapolated muon and removeSelf is requested, do not process further" << endmsg;
92 return StatusCode::FAILURE;
93 }//m_removeSelf
94 msg() << MSG::WARNING << "This EF muon has neither a combined, extrapolated or MS muon, do not process further" << endmsg;
95 return StatusCode::FAILURE;
96 }
97 else {
98 muon = efmuon->trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle);
99 selfpt = muon->pt();
100 }//extrapmuon
101 }//not combined
102
103 StatusCode isoResult = checkIsolation(muon, selfpt, muon_idtrk, muidtrk_perigee, idtrks, conesizes, results, dzvals, drvals, selfremoval);
104
105 return isoResult;
106}
107
108
109// Generic function to take whatever kind of muon and check isolation (so can pass a L2 or EF muon)
110StatusCode 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 {
111
113 if(m_removeSelf && selfpt==0.0) {
114 msg() << MSG::WARNING << "Inconsistency, removeSelf requested, but selfpt = 0" << endmsg;
115 }
116 if(!muon) {
117 msg() << MSG::WARNING << "Could not find a muon to update with the isolation, skipping this muon" << endmsg;
118 return StatusCode::FAILURE;
119 }
120
121 // fill results vector with 0
122 results.insert(results.end(), conesizes.size(), 0.0);
123
124 // loop over other tracks in the container
125 // these are arrays, so that if using leadTrk or dRMatched selfremoval it can be different between the two cone sizes
126 int ntrks_tmp[2];
127 ntrks_tmp[0]=0; ntrks_tmp[1]=0;
128
129
131 trkit!=trks->end(); ++trkit) {
132
133 if (m_debug)
134
135 msg() << MSG::DEBUG << "INFO: Track pT = " << (*trkit)->pt() << " eta = " << (*trkit)->eta() << endmsg;
136
137 // check track passes the selection tool
138 const auto& trkSelResult = m_trkSelTool->accept(*trkit);
139 if(trkSelResult) {
140 ATH_MSG_DEBUG("Track passes selection tool");
141 } else {
142 if(m_debug) {
143 ATH_MSG_DEBUG("Track failed selection tool");
144 for(unsigned int i=0; i<trkSelResult.getNCuts (); ++i) {
145 ATH_MSG_DEBUG(" Cut " << i << trkSelResult.getCutName(i).data() << " pass = " << trkSelResult.getCutResult(i));
146 }
147 }
148 continue; // skip this track
149 }
150
151 // check dZ if necessary
152 double dz=0;
153 if(m_deltaz_cut > 0.0 && muidtrk_perigee) {
154 const Trk::Perigee& idtrk_perigee = (*trkit)->perigeeParameters();
155 dz = idtrk_perigee.parameters()[Trk::z0] - muidtrk_perigee->parameters()[Trk::z0];
156 if( fabs(dz) > m_deltaz_cut ) {
157 if(m_debug) {
158 msg() << MSG::DEBUG << "Track failed dz cut, ignoring it. dz = " << dz << endmsg;
159 }
160 continue;
161 }//failed delta(z)
162 // store dz (after cut)
163 // if(dzvals) dzvals->push_back(dz); // moved to after the pT cut for plotting purposes
164 if(m_debug) {
165 msg() << MSG::DEBUG << "ID track passes dz cut. dz = " << dz << endmsg;
166 }
167
168 }//deltaz_cut
169 if(dzvals) dzvals->push_back(dz);
170
171 // check if trk within cone
172 double dr = 0;
173 if(muon_idtrk) { //use ID track for dR if available
174 dr = (*trkit)->p4().DeltaR( muon_idtrk->p4() );
175 } else { //use the muon
176 dr = (*trkit)->p4().DeltaR( muon->p4() );
177 }
178
179 if(drvals) drvals->push_back(dr);
180
181 // if needed check the inner annululs
182 if(m_useAnnulus) {
183 if( dr < m_annulusSize ) {
184 if(m_debug) {
185 msg() << MSG::DEBUG << "ID track within annulus, ignoring it, dR = " << dr << ", annulus = " << m_annulusSize << endmsg;
186
187 }
188 continue; // skip tracks in the annulus
189 }//annulus cut
190 if(m_debug) {
191 msg() << MSG::DEBUG << "ID track outside annulus, keep it, dR = " << dr << ", annulus = " << m_annulusSize << endmsg;
192 }
193 }//use Annulus
194
195 // Define new conesizes that depend on useVarIso flag
196 double ptvarcone20 = std::min(0.2,10000/selfpt);
197 double ptvarcone30 = std::min(0.3,10000/selfpt);
198 if (m_useVarIso){
199 conesizes.clear();
200 conesizes.push_back(ptvarcone20);
201 conesizes.push_back(ptvarcone30);
202 }
203
204 // add trk pT to relevant results vector
205 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
206 if(dr < conesizes.at(conepos) ) {
207 if(m_debug) {
208 msg() << MSG::DEBUG << "Adding trk pt = " << (*trkit)->pt() << ", with dr = " << dr << ", into cone = " << conesizes.at(conepos) << endmsg;
209 }
210 results.at(conepos) += (*trkit)->pt();
211 ++ntrks_tmp[conepos];
212
213 }
214 }
215
216 }// track loop
217
218 // Muon pT plots
219 selfremoval->push_back(selfpt);
220 selfremoval->push_back(muon->pt());
221
222 if(m_debug) {
223 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
224 msg() << MSG::DEBUG << "Scalar pT sum of tracks around this muon cone " << conesizes.at(conepos) << " = " << results.at(conepos) << endmsg;
225 }
226 }
227 if(m_removeSelf && !m_useAnnulus) { // remove muon pt from the sums
228 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
229 results.at(conepos) -= selfpt;
230 }
231 if(m_debug) {
232 for(unsigned int conepos=0; conepos<conesizes.size(); ++conepos) {
233 msg() << MSG::DEBUG << "Scalar pT sum of tracks around this muon cone " << conesizes.at(conepos) << " after self removal = " << results.at(conepos) << endmsg;
234 }
235 }
236
237 }//m_removeSelf
238
239 return StatusCode::SUCCESS;
240}
241
242
244
245 m_debug = msgLvl(MSG::DEBUG);
246
247 if(m_trkSelTool.retrieve().isFailure()){
248 ATH_MSG_FATAL("Could not retrieve InDetTrackSelectionTool");
249 return StatusCode::FAILURE;
250 }
251
252 if(m_debug) {
253 msg() << MSG::DEBUG << "Initializing TrigMuonEFTrackIsolationTool[" << name() << "]" << endmsg;
254 msg() << MSG::DEBUG
255 << "Properties set as follows: " << endmsg;
256 msg() << MSG::DEBUG
257 << "removeSelf " << m_removeSelf << endmsg;
258 msg() << MSG::DEBUG
259 << "deltaZCut " << m_deltaz_cut << endmsg;
260 msg() << MSG::DEBUG
261 << "useAnnulus " << m_useAnnulus << endmsg;
262 msg() << MSG::DEBUG
263 << "annulusSize " << m_annulusSize << endmsg;
264 msg() << MSG::DEBUG
265 << "useVarIso " << m_useVarIso << endmsg;
266 msg() << MSG::DEBUG
267 << "TrackSelectionTool " << m_trkSelTool << endmsg;
268
269 }//debug
270
271 // check the annulus size is valid
272 if(m_useAnnulus) {
274 msg() << MSG::ERROR << "Bad configuration of annulusSize = " << m_annulusSize << ", fix your config!" << endmsg;
275 return StatusCode::FAILURE;
276 }
277 }//useAnnulus
278
279 return StatusCode::SUCCESS;
280}
#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 TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be NULL) to the TrackParticle used in identification of this muon.
Definition Muon_v1.cxx:482
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: