ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CP::SystematicsSvc Class Referencefinal

the canonical implementation of ISystematicsSvc More...

#include <SystematicsSvc.h>

Inheritance diagram for CP::SystematicsSvc:
Collaboration diagram for CP::SystematicsSvc:

Public Member Functions

 SystematicsSvc (const std::string &name, ISvcLocator *pSvcLocator)
 standard constructor More...
 
virtual StatusCode initialize () override
 set up/tear down functions More...
 
virtual StatusCode finalize () override
 
virtual std::vector< CP::SystematicSetmakeSystematicsVector () const override
 get the list of systematics More...
 
virtual StatusCode addSystematics (const CP::SystematicSet &recommended, const CP::SystematicSet &affecting) const override
 register a set of recommended and affecting systematics More...
 
virtual CP::SystematicSet getObjectSystematics (const std::string &name) const override
 get the systematics for the given object in the event store More...
 
virtual StatusCode setObjectSystematics (const std::string &name, const CP::SystematicSet &systematics) const override
 set the systematics for the given object in the event store More...
 
virtual CP::SystematicSet getDecorSystematics (const std::string &objectName, const std::string &decorName) const override
 get the systematics for the given object in the event store More...
 
virtual StatusCode setDecorSystematics (const std::string &objectName, const std::string &decorName, const CP::SystematicSet &systematics) const override
 set the systematics for the given object in the event store More...
 
virtual StatusCode registerCopy (const std::string &fromName, const std::string &toName) const override
 register a (shallow) copy from one object to the next More...
 
virtual std::string getCopySource (const std::string &toName) const override
 get a source object name from which a target object has been copied More...
 
virtual StatusCode makeSystematicsName (std::string &result, const std::string &name, const CP::SystematicSet &sys) const override
 make the name for the given systematics More...
 
virtual void print () const
 Print the state of the service. More...
 
template<typename T >
void declareServiceInterface ()
 add the given interface to the list of interfaces More...
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvi)
 query interface for gaudi More...
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 
 DeclareInterfaceID (CP::ISystematicsSvc, 1, 0)
 

Private Attributes

Gaudi::Property< std::vector< std::string > > m_systematicsList {this, "systematicsList", {}, "the list of systematics to run"}
 the names of the systematics to request More...
 
Gaudi::Property< std::string > m_systematicsRegex {this, "systematicsRegex", "(.*)", "systematics filter regex"}
 the regular expression for filterinf systematics More...
 
Gaudi::Property< float > m_sigmaRecommended {this, "sigmaRecommended", 0, "the sigma with which to run recommended systematics"}
 load all recommended systematics at the given number of sigmas More...
 
Gaudi::Property< std::string > m_nominalSystematicsName {this, "nominalSystematicsName", "NOSYS", "the name to use for the nominal systematic (instead of the empty string)"}
 nominal systematics name More...
 
SystematicSet m_affectingSystematics ATLAS_THREAD_SAFE
 the list of affecting systematics More...
 
SystematicSet m_recommendedSystematics ATLAS_THREAD_SAFE
 the list of recommended systematics More...
 
std::unordered_map< std::string, CP::SystematicSet > m_objectSystematics ATLAS_THREAD_SAFE
 the list of per-object systematics More...
 
std::unordered_map< std::string, CP::SystematicSet > m_decorSystematics ATLAS_THREAD_SAFE
 the list of per-object-and-decoration systematics More...
 
std::unordered_map< std::string, std::string > m_copies ATLAS_THREAD_SAFE
 the map of registered copies More...
 
std::mutex m_systematicsMutex
 a mutex for accessing the above mutable members More...
 
std::vector< std::pair< const InterfaceID &(*)(), void *(*)(AsgService *)> > m_interfaces
 list of interfaces we have More...
 

Detailed Description

the canonical implementation of ISystematicsSvc

Definition at line 23 of file SystematicsSvc.h.

Constructor & Destructor Documentation

◆ SystematicsSvc()

CP::SystematicsSvc::SystematicsSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

standard constructor

Guarantee
strong
Failures
out of memory II

Definition at line 28 of file SystematicsSvc.cxx.

31  : AsgService (name, pSvcLocator)
32  {
33  declareServiceInterface<ISystematicsSvc>();
34  }

Member Function Documentation

◆ addSystematics()

StatusCode CP::SystematicsSvc::addSystematics ( const CP::SystematicSet recommended,
const CP::SystematicSet affecting 
) const
overridevirtual

register a set of recommended and affecting systematics

This is usually obtained from an CP::ISystematicsTool and is used for calculating the list of systematics to use on the fly.

Implements CP::ISystematicsSvc.

Definition at line 104 of file SystematicsSvc.cxx.

107  {
108  std::lock_guard<std::mutex> lock (m_systematicsMutex);
109 
110  for (const CP::SystematicVariation& mysys : recommended)
111  {
112  if (affecting.find (mysys) == affecting.end())
113  {
114  ANA_MSG_ERROR ("systematic is only registered as recommended, not affecting: " << mysys);
115  return StatusCode::FAILURE;
116  }
117  }
118 
119  m_affectingSystematics.insert (affecting);
120  m_recommendedSystematics.insert (recommended);
121  return StatusCode::SUCCESS;
122  }

◆ DeclareInterfaceID()

CP::ISystematicsSvc::DeclareInterfaceID ( CP::ISystematicsSvc  ,
,
 
)
inherited

◆ declareServiceInterface()

template<typename T >
void asg::AsgService::declareServiceInterface
inherited

add the given interface to the list of interfaces

Definition at line 76 of file AsgService.h.

77  {
78 #ifndef XAOD_STANDALONE
79  m_interfaces.emplace_back (T::interfaceID, [] (AsgService *self) -> void* {return dynamic_cast<T*>(self);});
80 #endif
81  }

◆ finalize()

StatusCode CP::SystematicsSvc::finalize ( )
overridevirtual

Reimplemented from asg::AsgService.

Definition at line 265 of file SystematicsSvc.cxx.

267  {
268  if (m_systematicsList.empty()) {
269  ANA_MSG_INFO ("no systematics were run.");
270  }
271  else{
272  for (const CP::SystematicVariation& mysys : m_affectingSystematics)
273  {
274  // this logic checks whether a systematic is recommended and
275  // affecting, or only affecting. if it is only the later, it
276  // reports the systematic in parenthesis to set it apart.
277  if (m_recommendedSystematics.find (mysys) == m_recommendedSystematics.end())
278  ANA_MSG_INFO ("found systematic: (" << mysys << ")");
279  else
280  ANA_MSG_INFO ("found systematic: " << mysys);
281  }
282 
283  if(m_systematicsRegex!=".*") {
284  ANA_MSG_INFO("Systematics regex '" << m_systematicsRegex << "' matched:");
285  for(const CP::SystematicSet& mysys : makeSystematicsVector()) {
286  ANA_MSG_INFO (" '" << mysys.name() << "'");
287  }
288  }
289  }
290  return StatusCode::SUCCESS;
291  }

◆ getCopySource()

std::string CP::SystematicsSvc::getCopySource ( const std::string &  toName) const
overridevirtual

get a source object name from which a target object has been copied

Implements CP::ISystematicsSvc.

Definition at line 218 of file SystematicsSvc.cxx.

220  {
221  std::lock_guard<std::mutex> lock (m_systematicsMutex);
222  auto iter = m_copies.find (toName);
223  if (iter == m_copies.end())
224  return "";
225  else
226  return iter->second;
227  }

◆ getDecorSystematics()

CP::SystematicSet CP::SystematicsSvc::getDecorSystematics ( const std::string &  objectName,
const std::string &  decorName 
) const
overridevirtual

get the systematics for the given object in the event store

Implements CP::ISystematicsSvc.

Definition at line 159 of file SystematicsSvc.cxx.

162  {
163  const std::string name = objectName + "." + decorName;
164  std::unique_lock<std::mutex> lock (m_systematicsMutex);
165  auto iter = m_decorSystematics.find (name);
166  if (iter != m_decorSystematics.end())
167  return iter->second;
168  auto jter = m_copies.find (objectName);
169  if (jter != m_copies.end())
170  {
171  const std::string& copyName = jter->second;
172  lock.unlock();
173  return getDecorSystematics (copyName, decorName);
174  }
175  return CP::SystematicSet ();
176  }

◆ getObjectSystematics()

CP::SystematicSet CP::SystematicsSvc::getObjectSystematics ( const std::string &  name) const
overridevirtual

get the systematics for the given object in the event store

Implements CP::ISystematicsSvc.

Definition at line 126 of file SystematicsSvc.cxx.

128  {
129  std::lock_guard<std::mutex> lock (m_systematicsMutex);
130  auto iter = m_objectSystematics.find (name);
131  if (iter != m_objectSystematics.end())
132  return iter->second;
133  else
134  return CP::SystematicSet ();
135  }

◆ initialize()

StatusCode CP::SystematicsSvc::initialize ( )
overridevirtual

set up/tear down functions

Reimplemented from asg::AsgService.

Definition at line 38 of file SystematicsSvc.cxx.

40  {
41  if (!std::isfinite (m_sigmaRecommended) ||
43  {
44  ANA_MSG_ERROR ("invalid value for sigmaRecommended: " << m_sigmaRecommended);
45  return StatusCode::FAILURE;
46  }
47 
48  if (m_sigmaRecommended != 0)
49  {
50  if (!m_systematicsList.empty())
51  {
52  ANA_MSG_ERROR ("can't specify both sigmaRecommended and systematicsList");
53  return StatusCode::FAILURE;
54  }
55  }
56  return StatusCode::SUCCESS;
57  }

◆ makeSystematicsName()

StatusCode CP::SystematicsSvc::makeSystematicsName ( std::string &  result,
const std::string &  name,
const CP::SystematicSet sys 
) const
overridevirtual

make the name for the given systematics

Implements CP::ISystematicsSvc.

Definition at line 231 of file SystematicsSvc.cxx.

235  {
236  if (name.empty())
237  {
238  ANA_MSG_ERROR ("not allowed to make systematic name for empty string");
239  return StatusCode::FAILURE;
240  }
241 
242  result = name;
243 
244  const auto sysSplit = result.find ("%SYS%");
245  if (sysSplit == std::string::npos)
246  {
247  if (!sys.empty())
248  {
249  ANA_MSG_ERROR ("can't set systematics on name without \"%SYS%\": \"" << name << "\" sys=" << sys.name());
250  return StatusCode::FAILURE;
251  }
252  } else
253  {
254  std::string sysName = sys.name();
255  if (sysName.empty())
257  result.replace (sysSplit, 5, sysName);
258  }
259 
260  return StatusCode::SUCCESS;
261  }

◆ makeSystematicsVector()

std::vector< CP::SystematicSet > CP::SystematicsSvc::makeSystematicsVector ( ) const
overridevirtual

get the list of systematics

Implements CP::ISystematicsSvc.

Definition at line 61 of file SystematicsSvc.cxx.

63  {
64  std::lock_guard<std::mutex> lock (m_systematicsMutex);
65  std::vector<CP::SystematicSet> systematicsVector;
66 
67  if (m_sigmaRecommended != 0)
68  {
69  assert (m_sigmaRecommended > 0);
70 
72  sys.setSigma (m_sigmaRecommended);
73  sys.calc (m_recommendedSystematics);
74 
75  std::regex expr (m_systematicsRegex.value());
76  for (const CP::SystematicSet& mysys : sys.result(""))
77  {
78  if (!regex_match (mysys.name(), expr))
79  {
80  ANA_MSG_DEBUG ("skipping systematic: " << mysys.name());
81  } else {
82  ANA_MSG_DEBUG ("configuring systematic: " << mysys.name());
83  systematicsVector.push_back (mysys);
84  }
85  }
86  } else if (m_systematicsList.empty())
87  {
88  // take an empty property as running just the central
89  // systematics set. implication is that you can't really run
90  // doing nothing, but that ought to be Ok.
91  systematicsVector.push_back (CP::SystematicSet ());
92  } else
93  {
94  for (const std::string& sysName : m_systematicsList)
95  systematicsVector.push_back (CP::SystematicSet (sysName));
96  }
97 
98  assert (!systematicsVector.empty());
99  return systematicsVector;
100  }

◆ msg() [1/2]

MsgStream& AthCommonMsg< Service >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< Service >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< Service >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ print()

void asg::AsgService::print ( ) const
virtualinherited

Print the state of the service.

Implements asg::IAsgService.

Definition at line 48 of file AsgService.cxx.

49  {
50  ATH_MSG_INFO( "AsgService " << name() << " @ " << this );
51  return;
52  }

◆ queryInterface()

StatusCode asg::AsgService::queryInterface ( const InterfaceID &  riid,
void **  ppvi 
)
virtualinherited

query interface for gaudi

Definition at line 57 of file AsgService.cxx.

59  {
60  for (const auto& interface : m_interfaces)
61  {
62  if (riid == interface.first())
63  {
64  *ppvi = interface.second (this);
65  addRef();
66  return StatusCode::SUCCESS;
67  }
68  }
69  return AsgServiceBase::queryInterface (riid, ppvi);
70  }

◆ registerCopy()

StatusCode CP::SystematicsSvc::registerCopy ( const std::string &  fromName,
const std::string &  toName 
) const
overridevirtual

register a (shallow) copy from one object to the next

Implements CP::ISystematicsSvc.

Definition at line 202 of file SystematicsSvc.cxx.

205  {
206  std::lock_guard<std::mutex> lock (m_systematicsMutex);
207  auto emplace_result = m_copies.try_emplace (toName, fromName);
208  if (emplace_result.second == false)
209  {
210  ANA_MSG_ERROR ("duplicate copy registered for name " << toName);
211  return StatusCode::FAILURE;
212  }
213  return StatusCode::SUCCESS;
214  }

◆ setDecorSystematics()

StatusCode CP::SystematicsSvc::setDecorSystematics ( const std::string &  objectName,
const std::string &  decorName,
const CP::SystematicSet systematics 
) const
overridevirtual

set the systematics for the given object in the event store

Implements CP::ISystematicsSvc.

Definition at line 180 of file SystematicsSvc.cxx.

184  {
185  const std::string name = objectName + "." + decorName;
186  auto mysystematics = systematics;
187  std::lock_guard<std::mutex> lock (m_systematicsMutex);
188  for (const CP::SystematicVariation& mysys : systematics)
189  {
190  if (m_affectingSystematics.find (mysys) == m_affectingSystematics.end())
191  {
192  ANA_MSG_ERROR ("systematic is set as object systematic, but not affecting: " << mysys);
193  return StatusCode::FAILURE;
194  }
195  }
196  m_decorSystematics[name] = std::move (mysystematics);
197  return StatusCode::SUCCESS;
198  }

◆ setObjectSystematics()

StatusCode CP::SystematicsSvc::setObjectSystematics ( const std::string &  name,
const CP::SystematicSet systematics 
) const
overridevirtual

set the systematics for the given object in the event store

Implements CP::ISystematicsSvc.

Definition at line 139 of file SystematicsSvc.cxx.

142  {
143  auto mysystematics = systematics;
144  std::lock_guard<std::mutex> lock (m_systematicsMutex);
145  for (const CP::SystematicVariation& mysys : systematics)
146  {
147  if (m_affectingSystematics.find (mysys) == m_affectingSystematics.end())
148  {
149  ANA_MSG_ERROR ("systematic is set as object systematic, but not affecting: " << mysys);
150  return StatusCode::FAILURE;
151  }
152  }
153  m_objectSystematics[name] = std::move (mysystematics);
154  return StatusCode::SUCCESS;
155  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/5]

SystematicSet m_affectingSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of affecting systematics

Definition at line 104 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [2/5]

SystematicSet m_recommendedSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of recommended systematics

Definition at line 108 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [3/5]

std::unordered_map<std::string,CP::SystematicSet> m_objectSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of per-object systematics

Definition at line 112 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [4/5]

std::unordered_map<std::string,CP::SystematicSet> m_decorSystematics CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the list of per-object-and-decoration systematics

Definition at line 116 of file SystematicsSvc.h.

◆ ATLAS_THREAD_SAFE [5/5]

std::unordered_map<std::string,std::string> m_copies CP::SystematicsSvc::ATLAS_THREAD_SAFE
mutableprivate

the map of registered copies

Definition at line 120 of file SystematicsSvc.h.

◆ m_interfaces

std::vector<std::pair<const InterfaceID& (*)(),void *(*)(AsgService*)> > asg::AsgService::m_interfaces
privateinherited

list of interfaces we have

Definition at line 68 of file AsgService.h.

◆ m_nominalSystematicsName

Gaudi::Property<std::string> CP::SystematicsSvc::m_nominalSystematicsName {this, "nominalSystematicsName", "NOSYS", "the name to use for the nominal systematic (instead of the empty string)"}
private

nominal systematics name

Definition at line 99 of file SystematicsSvc.h.

◆ m_sigmaRecommended

Gaudi::Property<float> CP::SystematicsSvc::m_sigmaRecommended {this, "sigmaRecommended", 0, "the sigma with which to run recommended systematics"}
private

load all recommended systematics at the given number of sigmas

The idea here is that this allows to run a simple analysis by itself without having to generate the list of systematics manually.

Definition at line 95 of file SystematicsSvc.h.

◆ m_systematicsList

Gaudi::Property<std::vector<std::string> > CP::SystematicsSvc::m_systematicsList {this, "systematicsList", {}, "the list of systematics to run"}
private

the names of the systematics to request

Definition at line 82 of file SystematicsSvc.h.

◆ m_systematicsMutex

std::mutex CP::SystematicsSvc::m_systematicsMutex
mutableprivate

a mutex for accessing the above mutable members

Definition at line 124 of file SystematicsSvc.h.

◆ m_systematicsRegex

Gaudi::Property<std::string> CP::SystematicsSvc::m_systematicsRegex {this, "systematicsRegex", "(.*)", "systematics filter regex"}
private

the regular expression for filterinf systematics

Definition at line 86 of file SystematicsSvc.h.


The documentation for this class was generated from the following files:
CaloCondBlobAlgs_fillNoiseFromASCII.sysName
sysName
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:93
CP::MakeSystematicsVector
This class handles turning the list of systematics into the actual list of nuisance parameter points ...
Definition: MakeSystematicsVector.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::SystematicsSvc::getDecorSystematics
virtual CP::SystematicSet getDecorSystematics(const std::string &objectName, const std::string &decorName) const override
get the systematics for the given object in the event store
Definition: SystematicsSvc.cxx:160
CP::SystematicsSvc::m_systematicsMutex
std::mutex m_systematicsMutex
a mutex for accessing the above mutable members
Definition: SystematicsSvc.h:124
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
CP::SystematicVariation
Definition: SystematicVariation.h:47
CP::SystematicsSvc::m_systematicsList
Gaudi::Property< std::vector< std::string > > m_systematicsList
the names of the systematics to request
Definition: SystematicsSvc.h:82
asg::AsgService::m_interfaces
std::vector< std::pair< const InterfaceID &(*)(), void *(*)(AsgService *)> > m_interfaces
list of interfaces we have
Definition: AsgService.h:68
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CP::SystematicsSvc::m_sigmaRecommended
Gaudi::Property< float > m_sigmaRecommended
load all recommended systematics at the given number of sigmas
Definition: SystematicsSvc.h:95
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
CP::SystematicsSvc::makeSystematicsVector
virtual std::vector< CP::SystematicSet > makeSystematicsVector() const override
get the list of systematics
Definition: SystematicsSvc.cxx:62
CheckAppliedSFs.systematics
def systematics
Definition: CheckAppliedSFs.py:231
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition: SystematicSet.h:63
CP::SystematicsSvc::m_nominalSystematicsName
Gaudi::Property< std::string > m_nominalSystematicsName
nominal systematics name
Definition: SystematicsSvc.h:99
asg::AsgService::AsgService
AsgService(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AsgService.cxx:19
CP::SystematicsSvc::m_systematicsRegex
Gaudi::Property< std::string > m_systematicsRegex
the regular expression for filterinf systematics
Definition: SystematicsSvc.h:86
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288