ATLAS Offline Software
DiTauTrackFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
10 
14 
15 #include "tauRecTools/TrackSort.h"
16 #include "StoreGate/ReadHandle.h"
17 
18 #include "fastjet/PseudoJet.hh"
19 
20 
22  const std::string& name,
23  const IInterface * parent) :
25  m_MaxDrJet(1.0),
26  m_MaxDrSubjet(0.2),
27  m_MaxNTracksSubjet(-1),
28  m_TrackSelectorTool("")
29 {
30  declareInterface<DiTauToolBase > (this);
31  declareProperty("MaxDrJet", m_MaxDrJet);
32  declareProperty("MaxDrSubjet", m_MaxDrSubjet);
33  declareProperty("MaxNTracksSubjet", m_MaxNTracksSubjet);
34  declareProperty("TrackSelectorTool", m_TrackSelectorTool);
35 }
36 
37 
39 
40 
42 
43  ATH_CHECK( m_TrackSelectorTool.retrieve() );
45 
46  return StatusCode::SUCCESS;
47 }
48 
49 
51  const EventContext& ctx) const
52 {
53  ATH_MSG_DEBUG("execute DiTauTrackFinder...");
54 
55  xAOD::DiTauJet *pDiTau = data->xAODDiTau;
56 
57  if (pDiTau == nullptr) {
58  ATH_MSG_ERROR("no di-tau candidate given");
59  return StatusCode::FAILURE;
60  }
61 
62  // retrieve track container
64 
65  std::vector<const xAOD::TrackParticle*> tauTracks; // good tracks in subjets
66  std::vector<const xAOD::TrackParticle*> isoTracks; // good tracks in isolation region
67  std::vector<const xAOD::TrackParticle*> otherTracks; // tracks failing the track criteria
68 
69  // get associated primary vertex
70  const xAOD::Vertex* pVertex = nullptr;
71  if (pDiTau->vertexLink().isValid()) {
72  pVertex = *pDiTau->vertexLink();
73  }
74  else {
75  ATH_MSG_WARNING("could not retieve VertexLink in ditau candidate");
76  }
77 
78  // get tracks
79  getTracksFromPV(data, pTrackParticleCont.get(), pVertex, tauTracks, isoTracks, otherTracks);
80 
81  // clear track links before association
82  pDiTau->clearTrackLinks();
83  pDiTau->clearIsoTrackLinks();
84  pDiTau->clearOtherTrackLinks();
85 
86  // drop subjets without good tracks
87  std::vector<fastjet::PseudoJet> vSubjets = data->subjets;
88  int nTracks;
89  for (auto subjet_itr = vSubjets.begin(); subjet_itr != vSubjets.end(); ) {
90  nTracks = 0;
91 
92  TLorentzVector temp_p4;
93  temp_p4.SetPtEtaPhiM(subjet_itr->pt(), subjet_itr->eta(), subjet_itr->phi_std(), subjet_itr->m());
94 
95  for (const auto& track : tauTracks) {
96  if ( temp_p4.DeltaR(track->p4()) < m_MaxDrSubjet) nTracks++;
97  }
98 
99  ATH_MSG_DEBUG("number of tracks in subjet: "<< nTracks);
100 
101  if (nTracks == 0) {
102  ATH_MSG_DEBUG("number of tracks is zero. Drop subjet");
103  subjet_itr = vSubjets.erase(subjet_itr); //point subjet_itr to the next element/end of the vector
104  } else if( m_MaxNTracksSubjet != -1 && nTracks > m_MaxNTracksSubjet){
105  ATH_MSG_DEBUG("number of tracks greater than MaxNTracksSubjet threshold. Drop subjet");
106  subjet_itr = vSubjets.erase(subjet_itr); //point subjet_itr to the next element/end of the vector
107  }
108  else {
109  ++subjet_itr;
110  }
111  }
112 
113  // check if ditau candidate has still at least 2 subjets
114  if (vSubjets.size()<=1) {
115  ATH_MSG_DEBUG("Found less than 2 subjets. Reject ditau candidate");
116  return StatusCode::FAILURE;
117  }
118 
119  data->subjets = vSubjets;
120  ATH_MSG_DEBUG("number of subjets after track association: " << data->subjets.size());
121  vSubjets.clear();
122 
123 
124  // associate tau tracks
125  for (const auto& track : tauTracks ) {
126  ATH_MSG_DEBUG("adding subjet track. eta: " << track->eta() << " phi: " << track->phi());
127  pDiTau->addTrack(pTrackParticleCont.get(), track);
128  }
129 
130  // associate isolation tracks
131  for (const auto& track : isoTracks ) {
132  ATH_MSG_DEBUG("adding iso track. eta: " << track->eta() << " phi: " << track->phi());
133  pDiTau->addIsoTrack(pTrackParticleCont.get(), track);
134  }
135 
136  // associate other tracks
137  for (const auto& track : otherTracks ) {
138  ATH_MSG_DEBUG("adding other track. eta: " << track->eta() << " phi: " << track->phi());
139  pDiTau->addOtherTrack(pTrackParticleCont.get(), track);
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
145 
147  const xAOD::TrackParticleContainer* pTrackParticleCont,
148  const xAOD::Vertex* pVertex,
149  std::vector<const xAOD::TrackParticle*> &tauTracks,
150  std::vector<const xAOD::TrackParticle*> &isoTracks,
151  std::vector<const xAOD::TrackParticle*> &otherTracks) const {
152 
153  for (const auto *const track : *pTrackParticleCont ) {
155 
156  if (type == DiTauSubjetTrack)
157  tauTracks.push_back(track);
158  else if (type == DiTauIsoTrack)
159  isoTracks.push_back(track);
160  else if (type == DiTauOtherTrack)
161  otherTracks.push_back(track);
162  }
163 
164  std::sort(tauTracks.begin(), tauTracks.end(), TrackSort());
165  std::sort(isoTracks.begin(), isoTracks.end(), TrackSort());
166  std::sort(otherTracks.begin(), otherTracks.end(), TrackSort());
167 }
168 
169 
171  const xAOD::TrackParticle* track,
172  const xAOD::Vertex* pVertex) const {
173 
174  xAOD::DiTauJet *pDiTau = data->xAODDiTau;
175 
176  // check if track is outside the jet ditau cone
177  if ( pDiTau->p4().DeltaR(track->p4()) > m_MaxDrJet) return OutsideTrack;
178 
179  // check quality criteria
180  bool goodTrack = m_TrackSelectorTool->decision(*track, pVertex);
181  if (!goodTrack) return DiTauOtherTrack;
182 
183  // check if track is inside a subjet
184  std::vector<fastjet::PseudoJet> vSubjets = data->subjets;
185  for (const auto &subjet : vSubjets) {
186 
187  TLorentzVector temp_p4;
188  temp_p4.SetPtEtaPhiM(subjet.pt(), subjet.eta(), subjet.phi_std(), subjet.m());
189 
190  if (temp_p4.DeltaR(track->p4()) < m_MaxDrSubjet)
191  return DiTauSubjetTrack;
192  }
193 
194  // track is in isolation region
195  return DiTauIsoTrack;
196 }
DiTauTrackFinder::execute
virtual StatusCode execute(DiTauCandidateData *data, const EventContext &ctx) const override
Execute - called for each Ditau candidate.
Definition: DiTauTrackFinder.cxx:50
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
xAOD::DiTauJet_v1::vertexLink
const VertexLink_t & vertexLink() const
DiTauTrackFinder::OutsideTrack
@ OutsideTrack
Definition: DiTauTrackFinder.h:47
xAOD::DiTauJet_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: DiTauJet_v1.cxx:30
FlavorTagDiscriminants::hbb_key::subjet
const std::string subjet
Definition: HbbConstants.h:18
xAOD::DiTauJet_v1::clearTrackLinks
void clearTrackLinks()
Definition: DiTauJet_v1.cxx:272
DiTauTrackFinder::DiTauTrackFinder
DiTauTrackFinder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: DiTauTrackFinder.cxx:21
xAOD::DiTauJet_v1::clearIsoTrackLinks
void clearIsoTrackLinks()
Definition: DiTauJet_v1.cxx:304
DiTauToolBase.h
xAOD::DiTauJet_v1::addOtherTrack
void addOtherTrack(const xAOD::TrackParticleContainer *, const xAOD::TrackParticle *)
Definition: DiTauJet_v1.cxx:326
DiTauTrackFinder::getTracksFromPV
void getTracksFromPV(const DiTauCandidateData *, const xAOD::TrackParticleContainer *, const xAOD::Vertex *, std::vector< const xAOD::TrackParticle * > &, std::vector< const xAOD::TrackParticle * > &, std::vector< const xAOD::TrackParticle * > &) const
Definition: DiTauTrackFinder.cxx:146
DiTauTrackFinder::m_TrackSelectorTool
ToolHandle< Trk::ITrackSelectorTool > m_TrackSelectorTool
Definition: DiTauTrackFinder.h:70
DiTauTrackFinder::m_MaxNTracksSubjet
int m_MaxNTracksSubjet
Definition: DiTauTrackFinder.h:67
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DiTauCandidateData.h
DiTauTrackFinder::DiTauOtherTrack
@ DiTauOtherTrack
Definition: DiTauTrackFinder.h:46
TrackSort
Helper method to sort tracks.
Definition: TrackSort.h:24
TrackSort.h
DiTauTrackFinder::m_MaxDrJet
float m_MaxDrJet
Definition: DiTauTrackFinder.h:65
DiTauTrackFinder::~DiTauTrackFinder
virtual ~DiTauTrackFinder()
Destructor.
xAOD::DiTauJet_v1::clearOtherTrackLinks
void clearOtherTrackLinks()
Definition: DiTauJet_v1.cxx:336
DiTauTrackFinder::DiTauIsoTrack
@ DiTauIsoTrack
Definition: DiTauTrackFinder.h:45
xAOD::DiTauJet_v1::addTrack
void addTrack(const xAOD::TrackParticleContainer *, const xAOD::TrackParticle *)
Definition: DiTauJet_v1.cxx:262
xAOD::DiTauJet_v1::addIsoTrack
void addIsoTrack(const xAOD::TrackParticleContainer *, const xAOD::TrackParticle *)
Definition: DiTauJet_v1.cxx:294
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParametersIdHelper.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DiTauTrackFinder.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DiTauToolBase
The base class for all tau tools.
Definition: DiTauToolBase.h:20
DiTauTrackFinder::DiTauSubjetTrack
@ DiTauSubjetTrack
Definition: DiTauTrackFinder.h:44
DiTauTrackFinder::diTauTrackType
DiTauTrackType diTauTrackType(const DiTauCandidateData *, const xAOD::TrackParticle *, const xAOD::Vertex *) const
Definition: DiTauTrackFinder.cxx:170
DiTauTrackFinder::DiTauTrackType
DiTauTrackType
Definition: DiTauTrackFinder.h:43
IParticleCaloExtensionTool.h
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DiTauTrackFinder::m_TrackParticleContainerName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackParticleContainerName
Definition: DiTauTrackFinder.h:69
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::DiTauJet_v1
Definition: DiTauJet_v1.h:31
DiTauTrackFinder::m_MaxDrSubjet
float m_MaxDrSubjet
Definition: DiTauTrackFinder.h:66
DiTauCandidateData
Definition: DiTauCandidateData.h:15
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ReadHandle.h
Handle class for reading from StoreGate.
DiTauTrackFinder::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: DiTauTrackFinder.cxx:41
ITrackSelectorTool.h