ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
jet::UncertaintySet Class Reference

#include <UncertaintySet.h>

Inheritance diagram for jet::UncertaintySet:
Collaboration diagram for jet::UncertaintySet:

Public Member Functions

 UncertaintySet (const std::string &name="")
 
virtual ~UncertaintySet ()
 
virtual StatusCode initialize (const CP::SystematicSet &systConfig, const std::vector< UncertaintyGroup * > &groups)
 
virtual std::string getName () const
 
virtual bool getValidity (const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
 
virtual double getUncertainty (const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
 
virtual bool getValidUncertainty (double &unc, const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
 
virtual std::vector< CompScaleVar::TypeEnumgetScaleVars () const
 
virtual std::vector< std::pair< CompScaleVar::TypeEnum, bool > > getValiditySet (const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
 
virtual std::vector< std::pair< CompScaleVar::TypeEnum, double > > getUncertaintySet (const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
 
virtual std::vector< std::pair< CompScaleVar::TypeEnum, bool > > getValidUncertaintySet (std::vector< std::pair< CompScaleVar::TypeEnum, double > > &unc, const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
 
JetTopology::TypeEnum getTopology (const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

CompScaleVar::TypeEnum getSingleVar () const
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

const std::string m_name
 
bool m_isInit
 
std::vector< UncertaintyGroup * > m_groups
 
std::vector< float > m_shiftWeights
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Definition at line 24 of file UncertaintySet.h.

Constructor & Destructor Documentation

◆ UncertaintySet()

jet::UncertaintySet::UncertaintySet ( const std::string &  name = "")

Definition at line 20 of file UncertaintySet.cxx.

22  , m_name(name)
23  , m_isInit(false)
24  , m_groups()
25  , m_shiftWeights()
26 { }

◆ ~UncertaintySet()

jet::UncertaintySet::~UncertaintySet ( )
virtualdefault

Member Function Documentation

◆ getName()

std::string jet::UncertaintySet::getName ( ) const
virtual

Definition at line 72 of file UncertaintySet.cxx.

73 {
74  return m_name;
75 }

◆ getScaleVars()

std::vector< CompScaleVar::TypeEnum > jet::UncertaintySet::getScaleVars ( ) const
virtual

Definition at line 190 of file UncertaintySet.cxx.

191 {
192  // Make a super-set and fill it from each group
193  std::set<CompScaleVar::TypeEnum> scaleVarSet;
194  for (size_t iGroup = 0; iGroup < m_groups.size(); ++iGroup)
195  {
196  std::set<CompScaleVar::TypeEnum> localSet = m_groups.at(iGroup)->getScaleVars();
197  scaleVarSet.insert(localSet.begin(),localSet.end());
198  }
199 
200  // Convert to a vector
201  std::vector<CompScaleVar::TypeEnum> scaleVars;
202  std::set<CompScaleVar::TypeEnum>::const_iterator iter;
203  for (iter = scaleVarSet.begin(); iter != scaleVarSet.end(); ++iter)
204  scaleVars.push_back(*(iter));
205  return scaleVars;
206 }

◆ getSingleVar()

CompScaleVar::TypeEnum jet::UncertaintySet::getSingleVar ( ) const
private

Definition at line 83 of file UncertaintySet.cxx.

84 {
85  std::set<CompScaleVar::TypeEnum> vars = m_groups.at(0)->getScaleVars();
86  if (vars.size() != 1)
87  return CompScaleVar::UNKNOWN;
88  const CompScaleVar::TypeEnum singleVar = *(vars.begin());
89 
90  for (size_t iGroup = 1; iGroup < m_groups.size(); ++iGroup)
91  {
92  std::set<CompScaleVar::TypeEnum> vars2 = m_groups.at(iGroup)->getScaleVars();
93  if (vars2.size() != 1 || singleVar != *(vars2.begin()))
94  {
95  return CompScaleVar::UNKNOWN;
96  }
97  }
98 
99  return singleVar;
100 }

◆ getTopology()

JetTopology::TypeEnum jet::UncertaintySet::getTopology ( const CompScaleVar::TypeEnum  scaleVar = CompScaleVar::UNKNOWN) const

Definition at line 281 of file UncertaintySet.cxx.

282 {
283  // The topology is not normally needed
284  // Most variables are topology-independent, and thus are listed as "UNKNOWN"
285  // Mixing topology-agnostic and topology-specific variables is expected
286  // Mixing topology-specific variables of different topologies is not expected
287 
288  // Furthermore, the user can specify either a specific scale variable or not
289  // If the user doesn't specify (or specifies UNKNOWN, the default), then it checks all
290 
292 
293  for (const UncertaintyGroup* group : m_groups)
294  {
295  if (group->getTopology() != JetTopology::UNKNOWN)
296  {
298  result = group->getTopology();
299  else if (result != group->getTopology(scaleVar))
301  }
302  if (result == JetTopology::MIXED)
303  return result; // If it's mixed, it won't change any further
304  }
305 
306  return result; // If we got here, it's not a mixed topology, so return what it is
307 }

◆ getUncertainty()

double jet::UncertaintySet::getUncertainty ( const xAOD::Jet jet,
const xAOD::EventInfo eInfo,
const CompScaleVar::TypeEnum  scaleVar = CompScaleVar::UNKNOWN 
) const
virtual

Definition at line 123 of file UncertaintySet.cxx.

124 {
125  // This is the sum of shifts multiple uncorrelated groups
126  // This could be a positive or negative number
127  // Each individual group uncertainty will always be positive (quad sum of subgroups)
128  // But the weight may be positive or negative (+N sigma or -N sigma variations)
129 
130  if (m_groups.empty())
131  return 0;
132 
133  // If the scale var wasn't specified, need to ensure all groups match
134  const bool checkScaleVar = scaleVar == CompScaleVar::UNKNOWN;
135  const CompScaleVar::TypeEnum scaleVariable = checkScaleVar ? getSingleVar() : scaleVar;
136  if (scaleVariable == CompScaleVar::UNKNOWN)
137  {
138  ATH_MSG_ERROR("Asked for uncertainty of a multi-scale-variable set without specifying any scale variable: " << m_name);
139  return JESUNC_ERROR_CODE;
140  }
141 
142  // Checked conditions, now get the uncertainty
143  double unc = 0;
144  for (size_t iGroup = 0; iGroup < m_groups.size(); ++iGroup)
145  {
146  unc += m_groups.at(iGroup)->getUncertainty(jet,eInfo,scaleVariable)*m_shiftWeights.at(iGroup);
147  }
148 
149  return unc;
150 }

◆ getUncertaintySet()

std::vector< std::pair< CompScaleVar::TypeEnum, double > > jet::UncertaintySet::getUncertaintySet ( const xAOD::Jet jet,
const xAOD::EventInfo eInfo 
) const
virtual

Definition at line 227 of file UncertaintySet.cxx.

228 {
229  std::vector< std::pair<CompScaleVar::TypeEnum,double> > unc;
230 
231  // Simple case
232  if (m_groups.empty())
233  return unc;
234 
235  // Get the sets
236  const std::vector<CompScaleVar::TypeEnum> scaleVars = getScaleVars();
237 
238  // Process the sets one by one
239  for (size_t iVar = 0; iVar < scaleVars.size(); ++iVar)
240  unc.emplace_back(scaleVars.at(iVar),getUncertainty(jet,eInfo,scaleVars.at(iVar)));
241 
242  // Done, return
243  return unc;
244 }

◆ getValidity()

bool jet::UncertaintySet::getValidity ( const xAOD::Jet jet,
const xAOD::EventInfo eInfo,
const CompScaleVar::TypeEnum  scaleVar = CompScaleVar::UNKNOWN 
) const
virtual

Definition at line 102 of file UncertaintySet.cxx.

103 {
104  if (m_groups.empty())
105  return true;
106 
107  // If the scale var wasn't specified, need to ensure all groups match
108  const bool checkScaleVar = scaleVar == CompScaleVar::UNKNOWN;
109  const CompScaleVar::TypeEnum scaleVariable = checkScaleVar ? getSingleVar() : scaleVar;
110  if (scaleVariable == CompScaleVar::UNKNOWN)
111  {
112  ATH_MSG_ERROR("Asked for validity of a multi-scale variable set without specifying any scale variable: " << m_name);
113  return false;
114  }
115 
116  // Checked conditions, now get the validity
117  for (size_t iGroup = 0; iGroup < m_groups.size(); ++iGroup)
118  if (!m_groups.at(iGroup)->getValidity(jet,eInfo,scaleVariable))
119  return false;
120  return true;
121 }

◆ getValiditySet()

std::vector< std::pair< CompScaleVar::TypeEnum, bool > > jet::UncertaintySet::getValiditySet ( const xAOD::Jet jet,
const xAOD::EventInfo eInfo 
) const
virtual

Definition at line 208 of file UncertaintySet.cxx.

209 {
210  std::vector< std::pair<CompScaleVar::TypeEnum,bool> > validity;
211 
212  // Simple case
213  if (m_groups.empty())
214  return validity;
215 
216  // Get the sets
217  const std::vector<CompScaleVar::TypeEnum> scaleVars = getScaleVars();
218 
219  // Process the sets one by one
220  for (size_t iVar = 0; iVar < scaleVars.size(); ++iVar)
221  validity.emplace_back(scaleVars.at(iVar),getValidity(jet,eInfo,scaleVars.at(iVar)));
222 
223  // Done, return
224  return validity;
225 }

◆ getValidUncertainty()

bool jet::UncertaintySet::getValidUncertainty ( double &  unc,
const xAOD::Jet jet,
const xAOD::EventInfo eInfo,
const CompScaleVar::TypeEnum  scaleVar = CompScaleVar::UNKNOWN 
) const
virtual

Definition at line 152 of file UncertaintySet.cxx.

153 {
154  // See getUncertainty for discussion
155  // This is not just calling the other two methods for speed, O(n) instead of O(2n)
156 
157  if (m_groups.empty())
158  {
159  unc = 0;
160  return true;
161  }
162 
163  // If the scale var wasn't specified, need to ensure all groups match
164  const bool checkScaleVar = scaleVar == CompScaleVar::UNKNOWN;
165  const CompScaleVar::TypeEnum scaleVariable = checkScaleVar ? getSingleVar() : scaleVar;
166  if (scaleVariable == CompScaleVar::UNKNOWN)
167  {
168  ATH_MSG_ERROR("Asked for valid uncertainty of a multi-scale-variable set without specifying any scale variable: " << m_name);
169  return false;
170  }
171 
172  // Checked conditions, now get the uncertainty and validity
173  double localUnc = 0;
174  for (size_t iGroup = 0; iGroup < m_groups.size(); ++iGroup)
175  {
176  if (!m_groups.at(iGroup)->getValidity(jet,eInfo,scaleVariable))
177  return false;
178  localUnc += m_groups.at(iGroup)->getUncertainty(jet,eInfo,scaleVariable)*m_shiftWeights.at(iGroup);
179  }
180  unc = localUnc;
181  return true;
182 }

◆ getValidUncertaintySet()

std::vector< std::pair< CompScaleVar::TypeEnum, bool > > jet::UncertaintySet::getValidUncertaintySet ( std::vector< std::pair< CompScaleVar::TypeEnum, double > > &  unc,
const xAOD::Jet jet,
const xAOD::EventInfo eInfo 
) const
virtual

Definition at line 246 of file UncertaintySet.cxx.

247 {
248  std::vector< std::pair<CompScaleVar::TypeEnum,bool> > validity;
249  std::vector< std::pair<CompScaleVar::TypeEnum,double> > localUnc;
250 
251  // Simple case
252  if (m_groups.empty())
253  {
254  unc = localUnc;
255  return validity;
256  }
257 
258  // Get the sets
259  const std::vector<CompScaleVar::TypeEnum> scaleVars = getScaleVars();
260 
261  // Process the sets one by one
262  for (size_t iVar = 0; iVar < scaleVars.size(); ++iVar)
263  {
264  double localUncValue = JESUNC_ERROR_CODE;
265  validity.emplace_back(scaleVars.at(iVar),getValidUncertainty(localUncValue,jet,eInfo,scaleVars.at(iVar)));
266  localUnc.emplace_back(scaleVars.at(iVar),localUncValue);
267  }
268 
269  // Done, return
270  unc = localUnc;
271  return validity;
272 }

◆ initialize()

StatusCode jet::UncertaintySet::initialize ( const CP::SystematicSet systConfig,
const std::vector< UncertaintyGroup * > &  groups 
)
virtual

Definition at line 31 of file UncertaintySet.cxx.

32 {
33  // Ensure it wasn't already initialized
34  if (m_isInit)
35  {
36  ATH_MSG_ERROR("Blocking double-initialization for: " << m_name.c_str());
37  return StatusCode::FAILURE;
38  }
39 
40  // Parse all of the names to get the groups
41  std::set<UncertaintyGroup*> compSet;
42  for (CP::SystematicSet::const_iterator iter = systConfig.begin(); iter != systConfig.end(); ++iter)
43  for (size_t iGroup = 0; iGroup < groups.size(); ++iGroup)
44  if (groups.at(iGroup)->getName().CompareTo(iter->basename().c_str()) == 0)
45  {
46  // Watch for double-specified elements
47  if (compSet.count(groups.at(iGroup)))
48  {
49  ATH_MSG_ERROR("Multiple independent shifts requested for a single group: " << groups.at(iGroup)->getName().Data());
50  return StatusCode::FAILURE;
51  }
52  compSet.insert(groups.at(iGroup));
53 
54  m_groups.push_back(groups.at(iGroup));
55  m_shiftWeights.push_back(iter->parameter());
56  break;
57  }
58 
59 
60  // Ensure all of the elements were found
61  if (systConfig.size() != m_groups.size())
62  {
63  ATH_MSG_ERROR(Form("Input SystematicSet is %zu elements, but only found %zu UncertaintyGroups",systConfig.size(),m_groups.size()));
64  return StatusCode::FAILURE;
65  }
66 
67  // All good
68  m_isInit = true;
69  return StatusCode::SUCCESS;
70 }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49  {
50 #ifndef XAOD_STANDALONE
52 #else // not XAOD_STANDALONE
53  return m_msg;
54 #endif // not XAOD_STANDALONE
55  }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level  lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57  {
58 #ifndef XAOD_STANDALONE
60 #else // not XAOD_STANDALONE
61  m_msg << lvl;
62  return m_msg;
63 #endif // not XAOD_STANDALONE
64  }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level  lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41  {
42 #ifndef XAOD_STANDALONE
43  return ::AthMessaging::msgLvl( lvl );
44 #else // not XAOD_STANDALONE
45  return m_msg.msgLevel( lvl );
46 #endif // not XAOD_STANDALONE
47  }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_groups

std::vector<UncertaintyGroup*> jet::UncertaintySet::m_groups
private

Definition at line 55 of file UncertaintySet.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_isInit

bool jet::UncertaintySet::m_isInit
private

Definition at line 54 of file UncertaintySet.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_name

const std::string jet::UncertaintySet::m_name
private

Definition at line 53 of file UncertaintySet.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_shiftWeights

std::vector<float> jet::UncertaintySet::m_shiftWeights
private

Definition at line 56 of file UncertaintySet.h.


The documentation for this class was generated from the following files:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
ChainDefInMenu.groups
groups
Definition: ChainDefInMenu.py:44
jet::JetTopology::UNKNOWN
@ UNKNOWN
Definition: UncertaintyEnum.h:209
get_generator_info.result
result
Definition: get_generator_info.py:21
jet::UncertaintySet::m_name
const std::string m_name
Definition: UncertaintySet.h:53
jet::UncertaintySet::m_shiftWeights
std::vector< float > m_shiftWeights
Definition: UncertaintySet.h:56
CP::SystematicSet::size
size_t size() const
returns: size of the set
Definition: SystematicSet.h:71
CP::SystematicSet::const_iterator
std::set< SystematicVariation >::const_iterator const_iterator
Definition: SystematicSet.h:52
jet::UncertaintySet::m_groups
std::vector< UncertaintyGroup * > m_groups
Definition: UncertaintySet.h:55
jet::UncertaintySet::getValidity
virtual bool getValidity(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
Definition: UncertaintySet.cxx:102
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
jet::UncertaintySet::getValidUncertainty
virtual bool getValidUncertainty(double &unc, const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
Definition: UncertaintySet.cxx:152
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
JESUNC_ERROR_CODE
#define JESUNC_ERROR_CODE
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:23
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
jet::UncertaintySet::getUncertainty
virtual double getUncertainty(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const CompScaleVar::TypeEnum scaleVar=CompScaleVar::UNKNOWN) const
Definition: UncertaintySet.cxx:123
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
jet::UncertaintySet::getSingleVar
CompScaleVar::TypeEnum getSingleVar() const
Definition: UncertaintySet.cxx:83
jet::CompScaleVar::UNKNOWN
@ UNKNOWN
Definition: UncertaintyEnum.h:93
jet::JetTopology::MIXED
@ MIXED
Definition: UncertaintyEnum.h:214
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
jet::UncertaintySet::getScaleVars
virtual std::vector< CompScaleVar::TypeEnum > getScaleVars() const
Definition: UncertaintySet.cxx:190
jet::UncertaintySet::m_isInit
bool m_isInit
Definition: UncertaintySet.h:54
jet::CompScaleVar::TypeEnum
TypeEnum
Definition: UncertaintyEnum.h:91
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
CP::SystematicSet::begin
const_iterator begin() const
description: const iterator to the beginning of the set
Definition: SystematicSet.h:55
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
jet::JetTopology::TypeEnum
TypeEnum
Definition: UncertaintyEnum.h:208
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7