ATLAS Offline Software
TauThinningTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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) );
24  ATH_CHECK( m_trackParticles.initialize(m_streamName) );
25  ATH_CHECK( m_neutralPFOs.initialize(m_streamName) );
26  ATH_CHECK( m_secondaryVertices.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 
54  SG::ThinningHandle<xAOD::TauTrackContainer> tauTracks(m_tauTracks, ctx);
55  tauTracks.thinAll();
56 
57  SG::ThinningHandle<xAOD::TrackParticleContainer> trackParticles(m_trackParticles, ctx);
58  trackParticles.thinAll();
59 
60  SG::ThinningHandle<xAOD::PFOContainer> neutralPFOs(m_neutralPFOs, ctx);
61  neutralPFOs.thinAll();
62 
63  SG::ThinningHandle<xAOD::VertexContainer> secondaryVertices(m_secondaryVertices, ctx);
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 
86  if(tausToKeep.size() >0) {
87  for(size_t i=0; i < tausToKeep.size()-1; i++){
88  for (size_t j=i+1; j < tausToKeep.size(); j++){
89  if( (tausToKeep.at(i)->p4().DeltaR(tausToKeep.at(j)->p4())) < 0.01){
90  ATH_MSG_WARNING("Found duplicated tau with eta " << tausToKeep.at(j)->eta() << " phi " << tausToKeep.at(j)->phi() << " pt " << tausToKeep.at(j)->pt() << ". Removing it ...");
91  tausToKeep.erase( tausToKeep.begin()+j);
92  }
93  }
94  }
95  }
96 
97 
98  // keep the various tau-related objects for taus passing the selection
99  for (const auto* tau : tausToKeep) {
100  // tau
101  taus.keep(tau->index());
102 
103  // classifiedCharged tau tracks
104  for (const xAOD::TauTrack* track : tau->tracks()) {
105  tauTracks.keep(track->index());
106 
107  // associated ID track
108  trackParticles.keep(track->track()->index());
109  }
110 
111  // neutral PFOs
112  for (size_t i=0; i<tau->nNeutralPFOs(); i++) {
113  neutralPFOs.keep(tau->neutralPFO(i)->index());
114  }
115 
116  // secondary vertex
117  if (tau->secondaryVertex() != nullptr) {
118  secondaryVertices.keep(tau->secondaryVertex()->index());
119  }
120  }
121 
122  // increment counters
123  m_npass += tausToKeep.size();
124  m_ntot += nTaus;
125 
126  return StatusCode::SUCCESS;
127 }
SG::ThinningHandleBase::thinAll
void thinAll()
Mark that all elements should be thinned away.
Definition: ThinningHandleBase.cxx:136
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ThinningHandle.h
Handle for requesting thinning for a data object.
DerivationFramework::TauThinningTool::TauThinningTool
TauThinningTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: TauThinningTool.cxx:12
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TauThinningTool::initialize
virtual StatusCode initialize() override
Definition: TauThinningTool.cxx:20
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
DerivationFramework::TauThinningTool::finalize
virtual StatusCode finalize() override
Definition: TauThinningTool.cxx:37
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition: ThinningHandleBase.cxx:68
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TauThinningTool.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
entries
double entries
Definition: listroot.cxx:49
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
DerivationFramework::TauThinningTool::doThinning
virtual StatusCode doThinning() const override
Definition: TauThinningTool.cxx:45