ATLAS Offline Software
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 
17 namespace ORUtils
18 {
19 
20  //---------------------------------------------------------------------------
21  // Constructor
22  //---------------------------------------------------------------------------
25  m_bJetLabel(""),
26  m_tauLabel(""),
27  m_antiTauLabel(""),
28  m_dR(0.2),
29  m_useRapidity(true),
30  m_bJetHelper(nullptr),
31  m_dRMatcher(nullptr),
32  m_antiTauDecHelper(nullptr)
33  {
34  declareProperty("BJetLabel", m_bJetLabel,
35  "Input b-jet flag. Disabled by default.");
36  declareProperty("TauLabel", m_tauLabel,
37  "Decoration which labels ID-ed taus");
38  declareProperty("AntiTauLabel", m_antiTauLabel,
39  "Decoration which labels anti-taus");
40  declareProperty("antiTauEventCategory", m_antiTauEventCategoryDecorName="antiTauEventCategory",
41  "Decoration which labels event type");
42  declareProperty("DR", m_dR, "Maximum dR for overlap match");
43  declareProperty("UseRapidity", m_useRapidity,
44  "Calculate delta-R using rapidity");
45  }
46 
47  //---------------------------------------------------------------------------
48  // Initialize
49  //---------------------------------------------------------------------------
51  {
52  // Initialize the b-jet helper
53  if(!m_bJetLabel.empty()) {
54  ATH_MSG_DEBUG("Configuring btag-aware OR with btag label: " << m_bJetLabel);
55  m_bJetHelper = std::make_unique<BJetHelper>(m_bJetLabel);
56  }
57 
58  // Initialize the dR matcher
60  m_dRMatcher = std::make_unique<DeltaRMatcher>(m_dR, m_useRapidity);
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>
68  }
69 
70  // Initialize the anti-tau decoration helper
71  if(!m_antiTauLabel.empty()) {
72  ATH_MSG_DEBUG("Configuring anti-tau OR with label: " << m_antiTauLabel);
74  std::make_unique<OverlapDecorationHelper>
76  }
77  return StatusCode::SUCCESS;
78  }
79 
80  //---------------------------------------------------------------------------
81  // Identify overlaps
82  //---------------------------------------------------------------------------
85  const xAOD::IParticleContainer& cont2) const
86  {
87  // Check the container types
88  if(typeid(cont1) != typeid(xAOD::JetContainer) &&
89  typeid(cont1) != typeid(ConstDataVector<xAOD::JetContainer>)) {
90  ATH_MSG_ERROR("First container arg is not of type JetContainer!");
91  return StatusCode::FAILURE;
92  }
93  if(typeid(cont2) != typeid(xAOD::TauJetContainer) &&
94  typeid(cont2) != typeid(ConstDataVector<xAOD::TauJetContainer>)) {
95  ATH_MSG_ERROR("Second container arg is not of type TauJetContainer!");
96  return StatusCode::FAILURE;
97  }
98  ATH_CHECK( findOverlaps(static_cast<const xAOD::JetContainer&>(cont1),
99  static_cast<const xAOD::TauJetContainer&>(cont2)) );
100  return StatusCode::SUCCESS;
101  }
102 
103  //---------------------------------------------------------------------------
104  // Identify overlaps
105  //---------------------------------------------------------------------------
108  const xAOD::TauJetContainer& taus) const
109  {
110  ATH_MSG_DEBUG("Removing overlapping taus and jets");
111  const EventContext& ctx = Gaudi::Hive::currentContext();
112 
113  // Initialize output decorations if necessary
114  m_decHelper->initializeDecorations(taus);
115  m_decHelper->initializeDecorations(jets);
116 
117  // Start by discarding all taus which are not ID or anti-ID
118  for(const auto tau : taus) {
119  if(!m_decHelper->isSurvivingObject(*tau)) continue;
120  if(isSurvivingTau(*tau)) continue;
121  if(isSurvivingAntiTau(*tau)) continue;
122  // remove it with trivial overlap with itself
123  ATH_CHECK( handleOverlap(tau, tau) );
124  }
125 
126  // Remove bjets overlapping with ID taus
127  int ntaus = 0;
128  for(const auto tau : taus) {
129  if(!m_decHelper->isSurvivingObject(*tau)) continue;
130  // Only consider ID taus
131  if(!isSurvivingTau(*tau)) continue;
132  ntaus++;
133  for(const auto jet : jets) {
134  if(!m_decHelper->isSurvivingObject(*jet)) continue;
135  if(m_dRMatcher->objectsMatch(*tau, *jet)){
136  ATH_CHECK( handleOverlap(jet, tau) );
137  }
138  }
139  }
140 
141  // Remove anti-taus from remaining bjets
142  for(const auto jet : jets) {
143  if(!m_decHelper->isSurvivingObject(*jet)) continue;
144  if(!isBJet(*jet)) continue;
145  for(const auto tau : taus) {
146  if(!m_decHelper->isSurvivingObject(*jet)) continue;
147  if(!isSurvivingAntiTau(*tau)) continue;
148  if(m_dRMatcher->objectsMatch(*tau, *jet)) {
149  ATH_CHECK( handleOverlap(tau, jet) );
150  }
151  }
152  }
153 
154  int nantitaus = 0;
155  int antiTauCategory = 0;
157  for(const auto tau : taus) {
158  if(!m_decHelper->isSurvivingObject(*tau)) continue;
159  if(!isSurvivingAntiTau(*tau)) continue;
160  nantitaus++;
161  antiTauCategory = categoryAcc(*tau);
162  }
163 
164  int nAntiTauMax = int(ntaus<antiTauCategory);
165 
166  // AntiTauCategory = 1 for lephad event, 2 for hadhad events
167  // nAntiTauMax = 1 if we didn't get enough ID taus, 0 otherwise
169  auto eventIndex = eventInfo->eventNumber(); // pseudo-random selection of anti-taus // pseudo-random selection of anti-taus
170  if (nantitaus > 0) {
171  int selIndex = eventIndex%nantitaus;
172 
173  int nSelectedAntitaus = 0;
174  int idx = 0;
175  for(const auto tau : taus) {
176  if(!m_decHelper->isSurvivingObject(*tau)) continue;
177  if(!isSurvivingAntiTau(*tau) ) continue;
178  if (idx == selIndex && nSelectedAntitaus < nAntiTauMax) nSelectedAntitaus++;
179  else {
180  // remove excess anti-taus by applying OR fail (it trivially overlaps with itself)
181  ATH_CHECK( handleOverlap(tau, tau) );
182  }
183  idx++;
184  }
185  }
186 
187  // Remove light jets from remaining anti-taus.
188  for(const auto tau : taus) {
189  if(!m_decHelper->isSurvivingObject(*tau)) continue;
190  if(!isSurvivingAntiTau(*tau)) continue;
191  // if isSurviving
192  for(const auto jet : jets) {
193  if(!m_decHelper->isSurvivingObject(*jet)) continue;
194  // We don't need to check the bjet label, but it might save CPU.
195  if(isBJet(*jet)) continue;
196  if(m_dRMatcher->objectsMatch(*tau, *jet)){
197  ATH_CHECK( handleOverlap(jet, tau) );
198  }
199  }
200  }
201 
202  return StatusCode::SUCCESS;
203  }
204 
205  //---------------------------------------------------------------------------
206  // Identify a user-labeled b-jet
207  //---------------------------------------------------------------------------
209  {
210  if(m_bJetHelper && m_bJetHelper->isBJet(jet)) return true;
211  return false;
212  }
213 
214  //---------------------------------------------------------------------------
215  // Identify a user-labeled IDed-tau
216  //---------------------------------------------------------------------------
218  {
219  if(m_tauDecHelper && m_tauDecHelper->isSurvivingObject(tau)) return true;
220  return false;
221  }
222 
223  //---------------------------------------------------------------------------
224  // Identify a user-labeled anti-tau
225  //---------------------------------------------------------------------------
227  {
228  if(m_antiTauDecHelper && m_antiTauDecHelper->isSurvivingObject(tau))
229  return true;
230  return false;
231  }
232 
233 
234 } // namespace ORUtils
ORUtils::TauAntiTauJetOverlapTool::initializeDerived
virtual StatusCode initializeDerived() override
Initialize the tool.
Definition: TauAntiTauJetOverlapTool.cxx:50
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ORUtils::TauAntiTauJetOverlapTool::findOverlaps
virtual StatusCode findOverlaps(const xAOD::IParticleContainer &cont1, const xAOD::IParticleContainer &cont2) const override
Identify overlapping taus and jets.
Definition: TauAntiTauJetOverlapTool.cxx:84
ORUtils::TauAntiTauJetOverlapTool::isSurvivingAntiTau
bool isSurvivingAntiTau(const xAOD::TauJet &tau) const
Is this an anti-tau? Returns false if anti-tau ID not configured.
Definition: TauAntiTauJetOverlapTool.cxx:226
ORUtils::TauAntiTauJetOverlapTool::m_tauDecHelper
std::unique_ptr< OverlapDecorationHelper > m_tauDecHelper
Decoration helper for the IDed taus.
Definition: TauAntiTauJetOverlapTool.h:129
CurrentContext.h
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ORUtils::TauAntiTauJetOverlapTool::m_useRapidity
bool m_useRapidity
Calculate deltaR using rapidity.
Definition: TauAntiTauJetOverlapTool.h:114
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
ORUtils
Definition: AltMuJetOverlapTool.h:20
TauAntiTauJetOverlapTool.h
ORUtils::TauAntiTauJetOverlapTool::m_tauLabel
std::string m_tauLabel
Decoration labelling an IDed tau.
Definition: TauAntiTauJetOverlapTool.h:106
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ORUtils::BaseOverlapTool
Common base class tool for overlap tools.
Definition: BaseOverlapTool.h:38
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ORUtils::TauAntiTauJetOverlapTool::m_bJetLabel
std::string m_bJetLabel
Input jet decoration which labels a bjet.
Definition: TauAntiTauJetOverlapTool.h:103
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ORUtils::BaseOverlapTool::m_outputPassValue
bool m_outputPassValue
Toggle the output flag logic.
Definition: BaseOverlapTool.h:80
ORUtils::BaseOverlapTool::m_decHelper
std::unique_ptr< OverlapDecorationHelper > m_decHelper
Helper for handling input/output decorations.
Definition: BaseOverlapTool.h:95
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ORUtils::TauAntiTauJetOverlapTool::m_dRMatcher
std::unique_ptr< IParticleAssociator > m_dRMatcher
Delta-R matcher.
Definition: TauAntiTauJetOverlapTool.h:126
ORUtils::TauAntiTauJetOverlapTool::m_bJetHelper
std::unique_ptr< BJetHelper > m_bJetHelper
BJet helper.
Definition: TauAntiTauJetOverlapTool.h:123
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:581
ORUtils::TauAntiTauJetOverlapTool::m_evtKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtKey
Definition: TauAntiTauJetOverlapTool.h:135
ORUtils::TauAntiTauJetOverlapTool::isSurvivingTau
bool isSurvivingTau(const xAOD::TauJet &tau) const
Is this an ID tau? Returns false if tau ID not configured.
Definition: TauAntiTauJetOverlapTool.cxx:217
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DeltaRMatcher.h
ReadHandle.h
Handle class for reading from StoreGate.
ORUtils::BaseOverlapTool::handleOverlap
virtual StatusCode handleOverlap(const xAOD::IParticle *testParticle, const xAOD::IParticle *refParticle) const
Common helper method to handle an overlap result.
Definition: BaseOverlapTool.cxx:64
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ORUtils::BaseOverlapTool::m_outputLabel
std::string m_outputLabel
Output object decoration which specifies overlapping objects.
Definition: BaseOverlapTool.h:76
ORUtils::TauAntiTauJetOverlapTool::isBJet
bool isBJet(const xAOD::Jet &jet) const
Is this jet a b-jet? Returns false if bjet ID not configured.
Definition: TauAntiTauJetOverlapTool.cxx:208
ORUtils::TauAntiTauJetOverlapTool::m_antiTauLabel
std::string m_antiTauLabel
Decoration labelling an anti-tau.
Definition: TauAntiTauJetOverlapTool.h:109
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
ORUtils::TauAntiTauJetOverlapTool::TauAntiTauJetOverlapTool
TauAntiTauJetOverlapTool(const std::string &name)
Create proper constructor for Athena.
Definition: TauAntiTauJetOverlapTool.cxx:23
ORUtils::TauAntiTauJetOverlapTool::m_antiTauDecHelper
std::unique_ptr< OverlapDecorationHelper > m_antiTauDecHelper
Decoration helper for the anti-taus.
Definition: TauAntiTauJetOverlapTool.h:132
ORUtils::TauAntiTauJetOverlapTool::m_dR
float m_dR
Flat delta-R cone for matching objects.
Definition: TauAntiTauJetOverlapTool.h:112
ORUtils::TauAntiTauJetOverlapTool::m_antiTauEventCategoryDecorName
std::string m_antiTauEventCategoryDecorName
Definition: TauAntiTauJetOverlapTool.h:134
EventInfoCnvParams::eventIndex
thread_local event_number_t eventIndex
Definition: IEvtIdModifierSvc.h:34