ATLAS Offline Software
NSubjettinessTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 #include "fastjet/contrib/Nsubjettiness.hh"
11 #include "fastjet/contrib/AxesDefinition.hh"
12 
15 {
16  declareProperty("Alpha", m_Alpha = 1.0);
17  declareProperty("AlphaList", m_rawAlphaVals = {});
18  declareProperty("DoDichroic", m_doDichroic = false);
19 }
20 
22 
25 
27  m_moments.emplace( 1.0, moments_t(1.0, m_prefix) );
28 
30  if( std::abs(m_Alpha-1.0) > 1.0e-5 ) {
31 
33  ATH_MSG_WARNING( "The Alpha property is deprecated, please use the AlphaList property to provide a list of values" );
34 
37 
38  }
39 
41  for( float alpha : m_rawAlphaVals ) {
42 
44  float alphaFix = round( alpha * 10.0 ) / 10.0;
45  if( std::abs(alpha-alphaFix) > 1.0e-5 ) ATH_MSG_DEBUG( "alpha = " << alpha << " has been rounded to " << alphaFix );
46 
48  if( alphaFix < 0.0 ) {
49  ATH_MSG_WARNING( "alpha must be positive. Skipping alpha = " << alpha );
50  continue;
51  }
52 
54  m_moments.emplace( alphaFix, moments_t(alphaFix, m_prefix) );
55 
56  }
57 
58  for( auto const& moment : m_moments ) {
59  ATH_MSG_DEBUG( "Including alpha = " << moment.first );
60  }
61 
62  return StatusCode::SUCCESS;
63 
64 }
65 
67 
68  fastjet::PseudoJet jet;
69  fastjet::PseudoJet jet_ungroomed;
70 
72  bool calculate = SetupDecoration(jet,injet);
73 
75  bool calculate_ungroomed = false;
76 
77  if( m_doDichroic ) {
78 
80  static const SG::ConstAccessor<ElementLink<xAOD::JetContainer> > ParentAcc ("Parent");
81  ElementLink<xAOD::JetContainer> parentLink = ParentAcc (injet);
82 
84  if( !parentLink.isValid() ) {
85  ATH_MSG_ERROR( "Parent element link is not valid. Aborting" );
86  return 1;
87  }
88 
89  const xAOD::Jet* parentJet = *(parentLink);
90  calculate_ungroomed = SetupDecoration(jet_ungroomed,*parentJet);
91  }
92 
93  // Supress a warning about undefined behavior in the fastjet
94  // WTA_KT_Axes ctor:
95  // .../fastjet/contrib/AxesDefinition.hh:551:43: runtime error: member access within address 0x7ffd770850d0 which does not point to an object of type 'WTA_KT_Axes'
96  // 0x7ffd770850d0: note: object has invalid vptr
97  std::once_flag oflag;
98  std::call_once (oflag, CxxUtils::ubsan_suppress,
99  []() { fastjet::contrib::WTA_KT_Axes x; });
100 
101  for( auto const& moment : m_moments ) {
102 
103  float alpha = moment.first;
104 
106  fastjet::contrib::NormalizedCutoffMeasure normalized_measure(alpha, injet.getSizeParameter(), 1000000);
107 
108  float Tau1_value = -999;
109  float Tau2_value = -999;
110  float Tau3_value = -999;
111  float Tau4_value = -999;
112 
113  float Tau2_ungroomed_value = -999;
114  float Tau3_ungroomed_value = -999;
115  float Tau4_ungroomed_value = -999;
116 
117  float Tau1_wta_value = -999;
118  float Tau2_wta_value = -999;
119  float Tau3_wta_value = -999;
120  float Tau4_wta_value = -999;
121 
122  float Tau2_wta_ungroomed_value = -999;
123  float Tau3_wta_ungroomed_value = -999;
124  float Tau4_wta_ungroomed_value = -999;
125 
126  if( calculate ) {
127 
130  fastjet::contrib::KT_Axes kt_axes;
131  JetSubStructureUtils::Nsubjettiness tau1(1, kt_axes, normalized_measure);
132  JetSubStructureUtils::Nsubjettiness tau2(2, kt_axes, normalized_measure);
133  JetSubStructureUtils::Nsubjettiness tau3(3, kt_axes, normalized_measure);
134  JetSubStructureUtils::Nsubjettiness tau4(4, kt_axes, normalized_measure);
135 
136  Tau1_value = tau1.result(jet);
137  Tau2_value = tau2.result(jet);
138  Tau3_value = tau3.result(jet);
139  Tau4_value = tau4.result(jet);
140 
141  if( calculate_ungroomed ) {
142  Tau2_ungroomed_value = tau2.result(jet_ungroomed);
143  Tau3_ungroomed_value = tau3.result(jet_ungroomed);
144  Tau4_ungroomed_value = tau4.result(jet_ungroomed);
145  }
146 
149  fastjet::contrib::WTA_KT_Axes wta_kt_axes;
150  JetSubStructureUtils::Nsubjettiness tau1_wta(1, wta_kt_axes, normalized_measure);
151  JetSubStructureUtils::Nsubjettiness tau2_wta(2, wta_kt_axes, normalized_measure);
152  JetSubStructureUtils::Nsubjettiness tau3_wta(3, wta_kt_axes, normalized_measure);
153  JetSubStructureUtils::Nsubjettiness tau4_wta(4, wta_kt_axes, normalized_measure);
154 
155  Tau1_wta_value = tau1_wta.result(jet);
156  Tau2_wta_value = tau2_wta.result(jet);
157  Tau3_wta_value = tau3_wta.result(jet);
158  Tau4_wta_value = tau4_wta.result(jet);
159 
160  if( calculate_ungroomed ) {
161  Tau2_wta_ungroomed_value = tau2_wta.result(jet_ungroomed);
162  Tau3_wta_ungroomed_value = tau3_wta.result(jet_ungroomed);
163  Tau4_wta_ungroomed_value = tau4_wta.result(jet_ungroomed);
164  }
165 
166  }
167 
168  (*moment.second.dec_Tau1)(injet) = Tau1_value;
169  (*moment.second.dec_Tau2)(injet) = Tau2_value;
170  (*moment.second.dec_Tau3)(injet) = Tau3_value;
171  (*moment.second.dec_Tau4)(injet) = Tau4_value;
172 
173  (*moment.second.dec_Tau2_ungroomed)(injet) = Tau2_ungroomed_value;
174  (*moment.second.dec_Tau3_ungroomed)(injet) = Tau3_ungroomed_value;
175  (*moment.second.dec_Tau4_ungroomed)(injet) = Tau4_ungroomed_value;
176 
177  (*moment.second.dec_Tau1_wta)(injet) = Tau1_wta_value;
178  (*moment.second.dec_Tau2_wta)(injet) = Tau2_wta_value;
179  (*moment.second.dec_Tau3_wta)(injet) = Tau3_wta_value;
180  (*moment.second.dec_Tau4_wta)(injet) = Tau4_wta_value;
181 
182  (*moment.second.dec_Tau2_wta_ungroomed)(injet) = Tau2_wta_ungroomed_value;
183  (*moment.second.dec_Tau3_wta_ungroomed)(injet) = Tau3_wta_ungroomed_value;
184  (*moment.second.dec_Tau4_wta_ungroomed)(injet) = Tau4_wta_ungroomed_value;
185 
186  }
187 
188  return 0;
189 
190 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ubsan_suppress.h
Helper for suppressing ubsan warnings.
JetSubStructureUtils::Nsubjettiness::result
virtual double result(const fastjet::PseudoJet &jet) const
Definition: Nsubjettiness.h:21
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
NSubjettinessTool::moments_t
Definition: NSubjettinessTool.h:60
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
x
#define x
NSubjettinessTool::modifyJet
int modifyJet(xAOD::Jet &injet) const
Modify a single jet. This is obsolete and set to be removed.
Definition: NSubjettinessTool.cxx:66
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::Jet_v1::getSizeParameter
float getSizeParameter() const
Definition: Jet_v1.cxx:245
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
NSubjettinessTool::m_rawAlphaVals
std::vector< float > m_rawAlphaVals
Definition: NSubjettinessTool.h:44
JetSubStructureMomentToolsBase::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetSubStructureMomentToolsBase.cxx:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Nsubjettiness.h
NSubjettinessTool::m_Alpha
float m_Alpha
Configurable as properties.
Definition: NSubjettinessTool.h:40
NSubjettinessTool::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: NSubjettinessTool.cxx:21
EMFourMomBuilder::calculate
void calculate(xAOD::Electron &electron)
Definition: EMFourMomBuilder.cxx:68
JetSubStructureMomentToolsBase::m_prefix
std::string m_prefix
Definition: JetSubStructureMomentToolsBase.h:30
JetSubStructureMomentToolsBase::SetupDecoration
bool SetupDecoration(fastjet::PseudoJet &pseudojet, const xAOD::Jet &jet, bool requireJetStructure=false) const
Definition: JetSubStructureMomentToolsBase.cxx:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
NSubjettinessTool::m_moments
std::map< float, moments_t > m_moments
Map of decorators using alpha as the key.
Definition: NSubjettinessTool.h:48
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
NSubjettinessTool::NSubjettinessTool
NSubjettinessTool(const std::string &name)
Definition: NSubjettinessTool.cxx:13
JetSubStructureUtils::Nsubjettiness
Definition: Nsubjettiness.h:14
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetSubStructureMomentToolsBase
Definition: JetSubStructureMomentToolsBase.h:18
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
NSubjettinessTool::m_doDichroic
bool m_doDichroic
Vector of input values before cleaning.
Definition: NSubjettinessTool.h:45
CxxUtils::ubsan_suppress
void ubsan_suppress(void(*func)())
Helper for suppressing ubsan warnings.
Definition: ubsan_suppress.cxx:69
NSubjettinessTool.h