ATLAS Offline Software
Loading...
Searching...
No Matches
TauThinningTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "GaudiKernel/ThreadLocalContext.h"
8#include <vector>
9#include <string>
10
11
13 const std::string& n,
14 const IInterface* p) :
15 base_class(t,n,p)
16{
17}
18
19
21{
22 ATH_CHECK( m_taus.initialize(m_streamName) );
23 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 neutralPFOs.thinAll();
62
64 secondaryVertices.thinAll();
65
66
67 std::vector<const xAOD::TauJet*> tausToKeep;
68
69 // execute the text parser if requested
70 if (!m_selectionString.empty()) {
71 std::vector<int> entries = m_parser->evaluateAsVector();
72 size_t nEntries = entries.size();
73 if (nTaus != nEntries) {
74 ATH_MSG_ERROR("Incompatible sizes: " << nTaus << " vs " << nEntries << "! Please check your selection string uses the appropriate tau container.");
75 return StatusCode::FAILURE;
76 }
77 // identify which taus to keep
78 for (size_t i=0; i<nTaus; ++i) if (entries[i]==1) tausToKeep.push_back(taus->at(i));
79 }
80 // use all taus if no selection string is passed
81 else {
82 for (size_t i=0; i<nTaus; ++i) tausToKeep.push_back(taus->at(i));
83 }
84
85 // protection against duplicate taus -- built from different seed jets, but end up having same (eta,phi)
86 if( tausToKeep.size() > 0){
87 for(size_t i=0; i < tausToKeep.size()-1; i++){
88 const auto* aTau=tausToKeep[i];
89 auto it = std::remove_if(tausToKeep.begin()+i+1,tausToKeep.end(),[aTau](const xAOD::TauJet* bTau) {return aTau->p4().DeltaR(bTau->p4()) < 0.01;});
90 tausToKeep.erase (it, tausToKeep.end());
91 }
92 }
93
94 // keep the various tau-related objects for taus passing the selection
95 for (const auto* tau : tausToKeep) {
96 // tau
97 taus.keep(tau->index());
98
99 // classifiedCharged tau tracks
100 for (const xAOD::TauTrack* track : tau->tracks()) {
101 tauTracks.keep(track->index());
102
103 // associated ID track
104 trackParticles.keep(track->track()->index());
105 }
106
107 // neutral PFOs
108 for (size_t i=0; i<tau->nNeutralPFOs(); i++) {
109 neutralPFOs.keep(tau->neutralPFO(i)->index());
110 }
111
112 // secondary vertex
113 if (tau->secondaryVertex() != nullptr) {
114 secondaryVertices.keep(tau->secondaryVertex()->index());
115 }
116 }
117
118 // increment counters
119 m_npass += tausToKeep.size();
120 m_ntot += nTaus;
121
122 return StatusCode::SUCCESS;
123}
#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.
virtual StatusCode finalize() override
SG::ThinningHandleKey< xAOD::PFOContainer > m_neutralPFOs
std::atomic< unsigned int > m_npass
Gaudi::Property< std::string > m_selectionString
TauThinningTool(const std::string &t, const std::string &n, const IInterface *p)
virtual StatusCode initialize() override
SG::ThinningHandleKey< xAOD::TauJetContainer > m_taus
virtual StatusCode doThinning() const override
std::atomic< unsigned int > m_ntot
SG::ThinningHandleKey< xAOD::TauTrackContainer > m_tauTracks
SG::ThinningHandleKey< xAOD::VertexContainer > m_secondaryVertices
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_trackParticles
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".