ATLAS Offline Software
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 
11 using std::vector;
12 
16 TrigMuonEFTrackIsolationTool::TrigMuonEFTrackIsolationTool(const std::string& type, const std::string& name, const IInterface* 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 
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
90  if( !efmuon->muonSpectrometerTrackParticleLink().isValid() ) {
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 {
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)
111 StatusCode 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 
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) {
274  if(m_annulusSize < 0.0 || m_annulusSize > 0.2) {
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 }
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
xAOD::Iso::ptvarcone30
@ ptvarcone30
Definition: IsolationType.h:56
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::Iso::ptvarcone20
@ ptvarcone20
Mini-Isolation http://arxiv.org/abs/1007.2221.
Definition: IsolationType.h:55
TrigMuonEFTrackIsolationTool::m_deltaz_cut
double m_deltaz_cut
cut between z of muon id trk and z of id trks - < 0 means no cut
Definition: TrigMuonEFTrackIsolationTool.h:41
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::z0
@ z0
Definition: ParamDefs.h:70
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
TrigMuonEFTrackIsolationTool::m_debug
bool m_debug
Definition: TrigMuonEFTrackIsolationTool.h:38
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
TrigMuonEFTrackIsolationTool::initialize
virtual StatusCode initialize() override
initialize the tool
Definition: TrigMuonEFTrackIsolationTool.cxx:244
xAOD::TrackParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TrackParticle_v1.cxx:129
TrigMuonEFTrackIsolationTool.h
xAOD::TrackParticle_v1::perigeeParameters
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
Definition: TrackParticle_v1.cxx:485
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
vector< double >
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigMuonEFTrackIsolationTool::m_useVarIso
bool m_useVarIso
flag to determine if we want to use offline isolation variables
Definition: TrigMuonEFTrackIsolationTool.h:53
TrigMuonEFTrackIsolationTool::calcTrackIsolation
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.
Definition: TrigMuonEFTrackIsolationTool.cxx:49
xAOD::Muon_v1::muonSpectrometerTrackParticleLink
const ElementLink< TrackParticleContainer > & muonSpectrometerTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TrigMuonEFTrackIsolationTool::m_annulusSize
double m_annulusSize
size of the annulus within which we ignore tracks
Definition: TrigMuonEFTrackIsolationTool.h:50
DataVector< xAOD::TrackParticle_v1 >
P4Helpers.h
min
#define min(a, b)
Definition: cfImp.cxx:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
python.ami.results
def results
Definition: ami.py:386
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Muon_v1::inDetTrackParticleLink
const ElementLink< TrackParticleContainer > & inDetTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigMuonEFTrackIsolationTool::checkIsolation
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
Definition: TrigMuonEFTrackIsolationTool.cxx:111
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TrigMuonEFTrackIsolationTool::m_removeSelf
bool m_removeSelf
flag to determine whether to remove pT of muon track from the calculation
Definition: TrigMuonEFTrackIsolationTool.h:44
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
TrigMuonEFTrackIsolationTool::TrigMuonEFTrackIsolationTool
TrigMuonEFTrackIsolationTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: TrigMuonEFTrackIsolationTool.cxx:16
TrigMuonEFTrackIsolationTool::m_trkSelTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelTool
Track selection tool.
Definition: TrigMuonEFTrackIsolationTool.h:56
TrigMuonEFTrackIsolationTool::m_useAnnulus
bool m_useAnnulus
flag to determine if we should use an inner annulus
Definition: TrigMuonEFTrackIsolationTool.h:47
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::Muon_v1::combinedTrackParticleLink
const ElementLink< TrackParticleContainer > & combinedTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.