ATLAS Offline Software
Loading...
Searching...
No Matches
TauLRTThinningTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3*/
4
7#include "GaudiKernel/ThreadLocalContext.h"
8#include <vector>
9#include <string>
10
12 const std::string& n,
13 const IInterface* p) :
14 base_class(t,n,p)
15{
16}
17
18
20{
21 ATH_CHECK( m_taus.initialize(m_streamName) );
22 ATH_CHECK( m_tauTracks.initialize(m_streamName) );
27
28 // set up the text-parsing machinery for selecting taus according to user cuts
29 if (!m_selectionString.empty()) {
30 ATH_MSG_INFO("Selection string for " << m_taus.key() << ": " << m_selectionString);
31 ATH_CHECK( initializeParser(m_selectionString) );
32 }
33 return StatusCode::SUCCESS;
34}
35
36
38{
39 ATH_MSG_INFO("Processed " << m_ntot << " taus, " << m_npass << " were kept");
40 ATH_CHECK( finalizeParser() );
41 return StatusCode::SUCCESS;
42}
43
44
46{
47 const EventContext& ctx = Gaudi::Hive::currentContext();
48
49 // retrieve containers and thin them
51 taus.thinAll();
52 size_t nTaus = taus->size();
53
55 tauTracks.thinAll();
56
58 trackParticles.thinAll();
59
61 trackLargeD0Particles.thinAll();
62
64 neutralPFOs.thinAll();
65
67 secondaryVertices.thinAll();
68
69
70 std::vector<const xAOD::TauJet*> tausToKeep;
71
72 // execute the text parser if requested
73 if (!m_selectionString.empty()) {
74 std::vector<int> entries = m_parser->evaluateAsVector();
75 size_t nEntries = entries.size();
76 if (nTaus != nEntries) {
77 ATH_MSG_ERROR("Incompatible sizes: " << nTaus << " vs " << nEntries << "! Please check your selection string uses the appropriate tau container.");
78 return StatusCode::FAILURE;
79 }
80 // identify which taus to keep
81 for (size_t i=0; i<nTaus; ++i) if (entries[i]==1) tausToKeep.push_back(taus->at(i));
82 }
83 // use all taus if no selection string is passed
84 else {
85 for (size_t i=0; i<nTaus; ++i) tausToKeep.push_back(taus->at(i));
86 }
87
88 // protection against duplicate taus -- built from different seed jets, but end up having same (eta,phi)
89 if( tausToKeep.size() > 0){
90 for(size_t i=0; i < tausToKeep.size()-1; i++){
91 const auto* aTau=tausToKeep[i];
92 auto it = std::remove_if(tausToKeep.begin()+i+1,tausToKeep.end(),[aTau](const xAOD::TauJet* bTau) {return aTau->p4().DeltaR(bTau->p4()) < 0.01;});
93 tausToKeep.erase (it, tausToKeep.end());
94 }
95 }
96
97 // keep the various tau-related objects for taus passing the selection
98 for (const auto* tau : tausToKeep) {
99 // tau
100 taus.keep(tau->index());
101
102 // classifiedCharged tau tracks
103 for (const xAOD::TauTrack* track : tau->tracks()) {
104 tauTracks.keep(track->index());
105
106 // associated ID track
107 bool isTrackLRT = track->flag(xAOD::TauJetParameters::TauTrackFlag::LargeRadiusTrack);
108 if (!isTrackLRT) {
109 trackParticles.keep(track->track()->index());
110 } else {
111 trackLargeD0Particles.keep(track->track()->index());
112 }
113 }
114
115 // neutral PFOs
116 for (size_t i=0; i<tau->nNeutralPFOs(); i++) {
117 neutralPFOs.keep(tau->neutralPFO(i)->index());
118 }
119
120 // secondary vertex
121 if (tau->secondaryVertex() != nullptr) {
122 secondaryVertices.keep(tau->secondaryVertex()->index());
123 }
124 }
125
126 // increment counters
127 m_npass += tausToKeep.size();
128 m_ntot += nTaus;
129
130 return StatusCode::SUCCESS;
131}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
static Double_t taus
Handle for requesting thinning for a data object.
SG::ThinningHandleKey< xAOD::VertexContainer > m_secondaryVertices
SG::ThinningHandleKey< xAOD::PFOContainer > m_neutralPFOs
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_trackLargeD0Particles
virtual StatusCode initialize() override
SG::ThinningHandleKey< xAOD::TauJetContainer > m_taus
TauLRTThinningTool(const std::string &t, const std::string &n, const IInterface *p)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_trackParticles
SG::ThinningHandleKey< xAOD::TauTrackContainer > m_tauTracks
virtual StatusCode doThinning() const override
Gaudi::Property< std::string > m_selectionString
void thinAll()
Mark that all elements should be thinned away.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
double entries
Definition listroot.cxx:49
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
TauTrack_v1 TauTrack
Definition of the current version.
Definition TauTrack.h:16
TauJet_v3 TauJet
Definition of the current "tau version".