ATLAS Offline Software
Loading...
Searching...
No Matches
TauAntiTauJetOverlapTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// System includes
6#include <typeinfo>
7
8// Framework includes
10
11// Local includes
16
17namespace ORUtils
18{
19
20 //---------------------------------------------------------------------------
21 // Constructor
22 //---------------------------------------------------------------------------
24 : BaseOverlapTool(name),
25 m_bJetLabel(""),
26 m_tauLabel(""),
28 m_dR(0.2),
29 m_useRapidity(true),
30 m_dRMatcher(nullptr),
31 m_antiTauDecHelper(nullptr)
32 {
33 declareProperty("BJetLabel", m_bJetLabel,
34 "Input b-jet flag. Disabled by default.");
35 declareProperty("TauLabel", m_tauLabel,
36 "Decoration which labels ID-ed taus");
37 declareProperty("AntiTauLabel", m_antiTauLabel,
38 "Decoration which labels anti-taus");
39 declareProperty("antiTauEventCategory", m_antiTauEventCategoryDecorName="antiTauEventCategory",
40 "Decoration which labels event type");
41 declareProperty("DR", m_dR, "Maximum dR for overlap match");
42 declareProperty("UseRapidity", m_useRapidity,
43 "Calculate delta-R using rapidity");
44 }
45
46 //---------------------------------------------------------------------------
47 // Initialize
48 //---------------------------------------------------------------------------
50 {
51 // Initialize the b-jet helper
52 if(!m_bJetLabel.empty()) {
53 ATH_MSG_DEBUG("Configuring btag-aware OR with btag label: " << m_bJetLabel);
54 resetAccessor (m_accessors->m_bJetAcc, *m_accessors, m_bJetLabel);
55 }
56
57 // Initialize the dR matcher
58 m_dRMatcher = std::make_unique<DeltaRMatcher>(m_dR, m_useRapidity);
60 addSubtool(*m_dRMatcher);
61
62 // Initialize the IDed-tau decoration helper
63 if(!m_tauLabel.empty()) {
64 ATH_MSG_DEBUG("Configuring tau OR with label: " << m_tauLabel);
66 std::make_unique<OverlapDecorationHelper<columnar::ContainerId::particle2>>
68 addSubtool(*m_tauDecHelper);
69 }
70
71 // Initialize the anti-tau decoration helper
72 if(!m_antiTauLabel.empty()) {
73 ATH_MSG_DEBUG("Configuring anti-tau OR with label: " << m_antiTauLabel);
75 std::make_unique<OverlapDecorationHelper<columnar::ContainerId::particle2>>
77 addSubtool(*m_antiTauDecHelper);
78 }
79
80 resetAccessor (m_accessors->m_evtAcc, *m_accessors, m_evtKeyName, {.addMTDependency = true});
81 resetAccessor (m_accessors->m_categoryAcc, *m_accessors, m_antiTauEventCategoryDecorName);
82 return StatusCode::SUCCESS;
83 }
84
85 //---------------------------------------------------------------------------
86 // Identify overlaps
87 //---------------------------------------------------------------------------
91 columnar::EventContextId eventContext) const
92 {
93 // Check the container types
94 ATH_CHECK( checkForXAODContainer<xAOD::JetContainer>(cont1, "First container arg is not of type JetContainer!") );
95 ATH_CHECK( checkForXAODContainer<xAOD::TauJetContainer>(cont2, "Second container arg is not of type TauJetContainer!") );
96
97 ATH_CHECK( internalFindOverlaps(cont1, cont2, eventContext) );
98 return StatusCode::SUCCESS;
99 }
100
101 //---------------------------------------------------------------------------
102 // Identify overlaps
103 //---------------------------------------------------------------------------
107 columnar::EventContextId eventContext) const
108 {
109 ATH_MSG_DEBUG("Removing overlapping taus and jets");
110 auto& acc = *m_accessors;
111
112 // Initialize output decorations if necessary
115
116 // Start by discarding all taus which are not ID or anti-ID
117 for(const auto tau : taus) {
118 if(!isSurvivingObject(tau)) continue;
119 if(isSurvivingTau(tau)) continue;
120 if(isSurvivingAntiTau(tau)) continue;
121 // remove it with trivial overlap with itself
122 ATH_CHECK( handleOverlap(tau, tau) );
123 }
124
125 // Remove bjets overlapping with ID taus
126 int ntaus = 0;
127 for(const auto tau : taus) {
128 if(!isSurvivingObject(tau)) continue;
129 // Only consider ID taus
130 if(!isSurvivingTau(tau)) continue;
131 ntaus++;
132 for(const auto jet : jets) {
133 if(!isSurvivingObject(jet)) continue;
134 if(m_dRMatcher->objectsMatch(tau, jet)){
135 ATH_CHECK( handleOverlap(jet, tau) );
136 }
137 }
138 }
139
140 // Remove anti-taus from remaining bjets
141 for(const auto jet : jets) {
142 if(!isSurvivingObject(jet)) continue;
143 if(!isBJet(jet)) continue;
144 for(const auto tau : taus) {
145 if(!isSurvivingObject(tau)) continue;
146 if(!isSurvivingAntiTau(tau)) continue;
147 if(m_dRMatcher->objectsMatch(tau, jet)) {
148 ATH_CHECK( handleOverlap(tau, jet) );
149 }
150 }
151 }
152
153 int nantitaus = 0;
154 int antiTauCategory = 0;
155 for(const auto tau : taus) {
156 if(!isSurvivingObject(tau)) continue;
157 if(!isSurvivingAntiTau(tau)) continue;
158 nantitaus++;
159 antiTauCategory = acc.m_categoryAcc(tau);
160 }
161
162 int nAntiTauMax = int(ntaus<antiTauCategory);
163
164 // AntiTauCategory = 1 for lephad event, 2 for hadhad events
165 // nAntiTauMax = 1 if we didn't get enough ID taus, 0 otherwise
166 auto eventInfo = acc.m_evtAcc(eventContext);
167 auto eventIndex = eventInfo(acc.m_eventNumberAcc); // pseudo-random selection of anti-taus // pseudo-random selection of anti-taus
168 if (nantitaus > 0) {
169 int selIndex = eventIndex%nantitaus;
170
171 int nSelectedAntitaus = 0;
172 int idx = 0;
173 for(const auto tau : taus) {
174 if(!isSurvivingObject(tau)) continue;
175 if(!isSurvivingAntiTau(tau) ) continue;
176 if (idx == selIndex && nSelectedAntitaus < nAntiTauMax) nSelectedAntitaus++;
177 else {
178 // remove excess anti-taus by applying OR fail (it trivially overlaps with itself)
179 ATH_CHECK( handleOverlap(tau, tau) );
180 }
181 idx++;
182 }
183 }
184
185 // Remove light jets from remaining anti-taus.
186 for(const auto tau : taus) {
187 if(!isSurvivingObject(tau)) continue;
188 if(!isSurvivingAntiTau(tau)) continue;
189 // if isSurviving
190 for(const auto jet : jets) {
191 if(!isSurvivingObject(jet)) continue;
192 // We don't need to check the bjet label, but it might save CPU.
193 if(isBJet(jet)) continue;
194 if(m_dRMatcher->objectsMatch(tau, jet)){
195 ATH_CHECK( handleOverlap(jet, tau) );
196 }
197 }
198 }
199
200 return StatusCode::SUCCESS;
201 }
202
203 //---------------------------------------------------------------------------
204 // Identify a user-labeled b-jet
205 //---------------------------------------------------------------------------
207 {
208 if(!m_bJetLabel.empty() && m_accessors->m_bJetAcc(jet)) return true;
209 return false;
210 }
211
212 //---------------------------------------------------------------------------
213 // Identify a user-labeled IDed-tau
214 //---------------------------------------------------------------------------
216 {
217 if(m_tauDecHelper && m_tauDecHelper->isSurvivingObject(tau)) return true;
218 return false;
219 }
220
221 //---------------------------------------------------------------------------
222 // Identify a user-labeled anti-tau
223 //---------------------------------------------------------------------------
225 {
226 if(m_antiTauDecHelper && m_antiTauDecHelper->isSurvivingObject(tau))
227 return true;
228 return false;
229 }
230
231
232} // namespace ORUtils
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
DataVector adapter that acts like it holds const pointers.
static Double_t taus
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
void initializeDecorations(columnar::Particle1Range container) const
BaseOverlapTool(const std::string &name)
Create proper constructor for Athena.
bool m_outputPassValue
Toggle the output flag logic.
StatusCode handleOverlap(const columnar::ObjectId< CI1, CM > &testParticle, const columnar::ObjectId< CI2, CM > &refParticle) const
Common helper method to handle an overlap result.
bool isSurvivingObject(columnar::Particle1Id obj) const
std::string m_outputLabel
Output object decoration which specifies overlapping objects.
StatusCode checkForXAODContainer(columnar::ObjectRange< CI, CM > cont, std::string_view message) const
check whether the container is of the right type
float m_dR
Flat delta-R cone for matching objects.
bool m_useRapidity
Calculate deltaR using rapidity.
Gaudi::Property< std::string > m_evtKeyName
std::string m_tauLabel
Decoration labelling an IDed tau.
virtual StatusCode initializeDerived() override
Initialize the tool.
std::unique_ptr< Accessors > m_accessors
std::unique_ptr< IParticleAssociator > m_dRMatcher
Delta-R matcher.
bool isSurvivingAntiTau(columnar::Particle2Id tau) const
Is this an anti-tau?
TauAntiTauJetOverlapTool(const std::string &name)
Create proper constructor for Athena.
std::unique_ptr< OverlapDecorationHelper< columnar::ContainerId::particle2 > > m_antiTauDecHelper
Decoration helper for the anti-taus.
std::unique_ptr< OverlapDecorationHelper< columnar::ContainerId::particle2 > > m_tauDecHelper
Decoration helper for the IDed taus.
bool isBJet(columnar::Particle1Id jet) const
Is this jet a b-jet?
std::string m_bJetLabel
Input jet decoration which labels a bjet.
std::string m_antiTauLabel
Decoration labelling an anti-tau.
virtual StatusCode findOverlaps(columnar::Particle1Range cont1, columnar::Particle2Range cont2, columnar::EventContextId eventContext) const override
Identify overlapping taus and jets.
virtual StatusCode internalFindOverlaps(columnar::Particle1Range jets, columnar::Particle2Range taus, columnar::EventContextId eventContext) const
Identify overlapping taus and jets.
bool isSurvivingTau(columnar::Particle2Id tau) const
Is this an ID tau?
ObjectId< ContainerId::particle1 > Particle1Id
Definition ParticleDef.h:48
ObjectId< ContainerId::particle2 > Particle2Id
Definition ParticleDef.h:54
ObjectId< ContainerId::eventContext > EventContextId
ObjectRange< ContainerId::particle2 > Particle2Range
Definition ParticleDef.h:53
ObjectRange< ContainerId::particle1 > Particle1Range
Definition ParticleDef.h:47
@ Jet
The object is a jet.
Definition ObjectType.h:40
@ Tau
The object is a tau (jet)
Definition ObjectType.h:49