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 
7 #include "StoreGate/ReadHandle.h"
8 
9 
10 
12  const std::string& name,
13  const IInterface * parent) :
15  m_MaxDrJet(1.0),
16  m_MaxDrSubjet(0.2),
17  m_MaxNTracksSubjet(-1),
18  m_TrackSelectorTool("")
19 {
20  declareInterface<DiTauToolBase > (this);
21  declareProperty("MaxDrJet", m_MaxDrJet);
22  declareProperty("MaxDrSubjet", m_MaxDrSubjet);
23  declareProperty("MaxNTracksSubjet", m_MaxNTracksSubjet);
24  declareProperty("TrackSelectorTool", m_TrackSelectorTool);
25 }
26 
27 
29 
30 
32 
33  ATH_CHECK( m_TrackSelectorTool.retrieve() );
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
41  const EventContext& ctx) const
42 {
43  ATH_MSG_DEBUG("execute DiTauTrackFinder...");
44 
45  xAOD::DiTauJet *pDiTau = data->xAODDiTau;
46 
47  if (pDiTau == nullptr) {
48  ATH_MSG_ERROR("no di-tau candidate given");
49  return StatusCode::FAILURE;
50  }
51 
52  // retrieve track container
54 
55  std::vector<const xAOD::TrackParticle*> tauTracks; // good tracks in subjets
56  std::vector<const xAOD::TrackParticle*> isoTracks; // good tracks in isolation region
57  std::vector<const xAOD::TrackParticle*> otherTracks; // tracks failing the track criteria
58 
59  // get associated primary vertex
60  const xAOD::Vertex* pVertex = nullptr;
61  if (pDiTau->vertexLink().isValid()) {
62  pVertex = *pDiTau->vertexLink();
63  }
64  else {
65  ATH_MSG_WARNING("could not retieve VertexLink in ditau candidate");
66  }
67 
68  // get tracks
69  getTracksFromPV(data, pTrackParticleCont.get(), pVertex, tauTracks, isoTracks, otherTracks);
70 
71  // clear track links before association
72  pDiTau->clearTrackLinks();
73  pDiTau->clearIsoTrackLinks();
74  pDiTau->clearOtherTrackLinks();
75 
76  // drop subjets without good tracks
77  std::vector<fastjet::PseudoJet> vSubjets = data->subjets;
78  int nTracks;
79  for (auto subjet_itr = vSubjets.begin(); subjet_itr != vSubjets.end(); ) {
80  nTracks = 0;
81 
82  TLorentzVector temp_p4;
83  temp_p4.SetPtEtaPhiM(subjet_itr->pt(), subjet_itr->eta(), subjet_itr->phi_std(), subjet_itr->m());
84 
85  for (const auto& track : tauTracks) {
86  if ( temp_p4.DeltaR(track->p4()) < m_MaxDrSubjet) nTracks++;
87  }
88 
89  ATH_MSG_DEBUG("number of tracks in subjet: "<< nTracks);
90 
91  if (nTracks == 0) {
92  ATH_MSG_DEBUG("number of tracks is zero. Drop subjet");
93  subjet_itr = vSubjets.erase(subjet_itr); //point subjet_itr to the next element/end of the vector
94  } else if( m_MaxNTracksSubjet != -1 && nTracks > m_MaxNTracksSubjet){
95  ATH_MSG_DEBUG("number of tracks greater than MaxNTracksSubjet threshold. Drop subjet");
96  subjet_itr = vSubjets.erase(subjet_itr); //point subjet_itr to the next element/end of the vector
97  }
98  else {
99  ++subjet_itr;
100  }
101  }
102 
103  // check if ditau candidate has still at least 2 subjets
104  if (vSubjets.size()<=1) {
105  ATH_MSG_DEBUG("Found less than 2 subjets. Reject ditau candidate");
106  return StatusCode::FAILURE;
107  }
108 
109  data->subjets = vSubjets;
110  ATH_MSG_DEBUG("number of subjets after track association: " << data->subjets.size());
111  vSubjets.clear();
112 
113 
114  // associate tau tracks
115  for (const auto& track : tauTracks ) {
116  ATH_MSG_DEBUG("adding subjet track. eta: " << track->eta() << " phi: " << track->phi());
117  pDiTau->addTrack(pTrackParticleCont.get(), track);
118  }
119 
120  // associate isolation tracks
121  for (const auto& track : isoTracks ) {
122  ATH_MSG_DEBUG("adding iso track. eta: " << track->eta() << " phi: " << track->phi());
123  pDiTau->addIsoTrack(pTrackParticleCont.get(), track);
124  }
125 
126  // associate other tracks
127  for (const auto& track : otherTracks ) {
128  ATH_MSG_DEBUG("adding other track. eta: " << track->eta() << " phi: " << track->phi());
129  pDiTau->addOtherTrack(pTrackParticleCont.get(), track);
130  }
131 
132  return StatusCode::SUCCESS;
133 }
134 
135 
137  const xAOD::TrackParticleContainer* pTrackParticleCont,
138  const xAOD::Vertex* pVertex,
139  std::vector<const xAOD::TrackParticle*> &tauTracks,
140  std::vector<const xAOD::TrackParticle*> &isoTracks,
141  std::vector<const xAOD::TrackParticle*> &otherTracks) const {
142 
143  for (const auto *const track : *pTrackParticleCont ) {
145 
146  if (type == DiTauSubjetTrack)
147  tauTracks.push_back(track);
148  else if (type == DiTauIsoTrack)
149  isoTracks.push_back(track);
150  else if (type == DiTauOtherTrack)
151  otherTracks.push_back(track);
152  }
153 
154  std::sort(tauTracks.begin(), tauTracks.end(), TrackSort());
155  std::sort(isoTracks.begin(), isoTracks.end(), TrackSort());
156  std::sort(otherTracks.begin(), otherTracks.end(), TrackSort());
157 }
158 
159 
161  const xAOD::TrackParticle* track,
162  const xAOD::Vertex* pVertex) const {
163 
164  xAOD::DiTauJet *pDiTau = data->xAODDiTau;
165 
166  // check if track is outside the jet ditau cone
167  if ( pDiTau->p4().DeltaR(track->p4()) > m_MaxDrJet) return OutsideTrack;
168 
169  // check quality criteria
170  bool goodTrack = m_TrackSelectorTool->decision(*track, pVertex);
171  if (!goodTrack) return DiTauOtherTrack;
172 
173  // check if track is inside a subjet
174  std::vector<fastjet::PseudoJet> vSubjets = data->subjets;
175  for (const auto &subjet : vSubjets) {
176 
177  TLorentzVector temp_p4;
178  temp_p4.SetPtEtaPhiM(subjet.pt(), subjet.eta(), subjet.phi_std(), subjet.m());
179 
180  if (temp_p4.DeltaR(track->p4()) < m_MaxDrSubjet)
181  return DiTauSubjetTrack;
182  }
183 
184  // track is in isolation region
185  return DiTauIsoTrack;
186 }
DiTauTrackFinder::execute
virtual StatusCode execute(DiTauCandidateData *data, const EventContext &ctx) const override
Execute - called for each Ditau candidate.
Definition: DiTauTrackFinder.cxx:40
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:43
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:11
xAOD::DiTauJet_v1::clearIsoTrackLinks
void clearIsoTrackLinks()
Definition: DiTauJet_v1.cxx:304
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:136
DiTauTrackFinder::m_TrackSelectorTool
ToolHandle< Trk::ITrackSelectorTool > m_TrackSelectorTool
Definition: DiTauTrackFinder.h:66
DiTauTrackFinder::m_MaxNTracksSubjet
int m_MaxNTracksSubjet
Definition: DiTauTrackFinder.h:63
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DiTauTrackFinder::DiTauOtherTrack
@ DiTauOtherTrack
Definition: DiTauTrackFinder.h:42
TrackSort
Helper method to sort tracks.
Definition: TrackSort.h:24
TrackSort.h
DiTauTrackFinder::m_MaxDrJet
float m_MaxDrJet
Definition: DiTauTrackFinder.h:61
DiTauTrackFinder::~DiTauTrackFinder
virtual ~DiTauTrackFinder()
Destructor.
xAOD::DiTauJet_v1::clearOtherTrackLinks
void clearOtherTrackLinks()
Definition: DiTauJet_v1.cxx:336
DiTauTrackFinder::DiTauIsoTrack
@ DiTauIsoTrack
Definition: DiTauTrackFinder.h:41
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
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:794
DiTauTrackFinder.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DiTauToolBase
The base class for all tau tools.
Definition: DiTauToolBase.h:20
DiTauTrackFinder::DiTauSubjetTrack
@ DiTauSubjetTrack
Definition: DiTauTrackFinder.h:40
DiTauTrackFinder::diTauTrackType
DiTauTrackType diTauTrackType(const DiTauCandidateData *, const xAOD::TrackParticle *, const xAOD::Vertex *) const
Definition: DiTauTrackFinder.cxx:160
DiTauTrackFinder::DiTauTrackType
DiTauTrackType
Definition: DiTauTrackFinder.h:39
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:65
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:62
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:31