ATLAS Offline Software
SystematicsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 // $Id: SystematicsTool.cxx 768505 2016-08-17 18:13:04Z ssnyder $
10 #include <iostream>
11 
12 // Infrastructure include(s):
13 #include "RootCoreUtils/Assert.h"
14 
15 // Local include(s):
20 
21 // Other include(s):
22 
23 namespace CP {
24 
26  : m_appliedSystematics(0) {
27 
28  RCU_NEW_INVARIANT( this );
29  }
30 
32  isAffectedBySystematic( const SystematicVariation& systematic ) const {
33 
34  RCU_READ_INVARIANT( this );
35  return ( m_affectingSystematics.find( systematic ) !=
37  }
38 
41 
42  RCU_READ_INVARIANT( this );
44  }
45 
48 
49  RCU_READ_INVARIANT( this );
51  }
52 
53  const SystematicSet&
55 
56  RCU_READ_INVARIANT( this );
57  if(m_appliedSystematics == 0){
58  std::cerr << "SystematicsTool::appliedSystematics WARNING: "
59  << "no systematic configuration has been applied yet. "
60  << "Returning NULL" << std::endl;
61  static const SystematicSet dummy;
62  return dummy;
63  }
64  return *m_appliedSystematics;
65  }
66 
68 
69  RCU_READ_INVARIANT( this );
70  return m_appliedSystematics->name();
71  }
72 
74  applySystematicVariation( const SystematicSet& systConfig ) {
75 
76  RCU_CHANGE_INVARIANT( this );
77 
78  // First, try to find this input set in the map
79  auto itr = m_systFilterMap.find(systConfig);
80 
81  // This is a new input set, so we need to filter it
82  if(itr == m_systFilterMap.end()){
83 
84  // Filter input systematics with the affecting systematics
85  SystematicSet myAppliedSystematics;
86  if( SystematicSet::
87  filterForAffectingSystematics( systConfig,
89  myAppliedSystematics ) !=
90  StatusCode::SUCCESS ) {
91  return StatusCode::FAILURE;
92  }
93 
94  // Insert the new filtered set onto our filter map
95  itr = m_systFilterMap.insert
96  (std::make_pair(systConfig, myAppliedSystematics)).first;
97 
98  }
99 
100  // Apply the filtered systematics
101  if( sysApplySystematicVariation( itr->second ) !=
102  StatusCode::SUCCESS ) {
103  return StatusCode::FAILURE;
104  }
105 
106  // Store the filtered systematics
107  m_appliedSystematics = &itr->second;
108  return StatusCode::SUCCESS;
109  }
110 
112  addAffectingSystematic( const SystematicVariation& systematic, bool recommended ) {
113 
114  RCU_READ_INVARIANT( this );
115 
117  reg.registerSystematic( systematic );
118  m_affectingSystematics.insert( systematic );
119  if( recommended ) {
120  if( addRecommendedSystematic(systematic) != StatusCode::SUCCESS ) {
121  return StatusCode::FAILURE;
122  }
123  }
124  return StatusCode::SUCCESS;
125  }
126 
128  addRecommendedSystematic( const SystematicVariation& systematic ) {
129 
130  RCU_READ_INVARIANT( this );
131 
133  m_recommendedSystematics.insert( systematic );
134  if( reg.addSystematicToRecommended( systematic ) !=
135  StatusCode::SUCCESS ) {
136  return StatusCode::FAILURE;
137  }
138  return StatusCode::SUCCESS;
139  }
140 
143 
144  RCU_READ_INVARIANT( this );
145 
148  reg.registerSystematics( systematics );
149  }
150 
153 
154  RCU_READ_INVARIANT( this );
155 
158  if( reg.addSystematicsToRecommended( systematics ) !=
159  StatusCode::SUCCESS ) {
160  return StatusCode::FAILURE;
161  }
162  return StatusCode::SUCCESS;
163  }
164 
166 
167  //RCU_INVARIANT( this != 0 );
168  }
169 
170 } // namespace CP
CP::SystematicsTool::testInvariant
void testInvariant() const
effects: test the invariance of this object guarantee: no-fail
Definition: SystematicsTool.cxx:165
CP::SystematicsTool::m_appliedSystematics
SystematicSet * m_appliedSystematics
description: pointer to currenty applied systematics
Definition: SystematicsTool.h:151
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::SystematicsTool::affectingSystematics
virtual SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by guarantee: strong failures: out of ...
Definition: SystematicsTool.cxx:40
CP::SystematicsTool::addAffectingSystematics
void addAffectingSystematics(const SystematicSet &systematics)
effects: add a SystematicSet to the registered systematics.
Definition: SystematicsTool.cxx:142
CP::SystematicSet::name
std::string name() const
returns: the systematics joined into a single string.
Definition: SystematicSet.cxx:278
CP::SystematicsTool::m_affectingSystematics
SystematicSet m_affectingSystematics
description: members directly corresponding to accessors
Definition: SystematicsTool.h:146
CP::SystematicsTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.
Definition: SystematicsTool.cxx:74
Assert.h
CP::SystematicVariation
Definition: SystematicVariation.h:47
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::SystematicsTool::recommendedSystematics
virtual SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool can be affected by guarantee: strong failures: out of ...
Definition: SystematicsTool.cxx:47
CP::SystematicsTool::isAffectedBySystematic
virtual bool isAffectedBySystematic(const SystematicVariation &systematic) const
returns: whether this tool is affected by the given systematic guarantee: no-fail
Definition: SystematicsTool.cxx:32
SystematicRegistry.h
CP::SystematicsTool::addRecommendedSystematic
StatusCode addRecommendedSystematic(const SystematicVariation &systematic)
effects: add a systematic to the list of recommended systematics failures: unsupported systematic
Definition: SystematicsTool.cxx:128
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::SystematicsTool::m_systFilterMap
std::unordered_map< SystematicSet, SystematicSet > m_systFilterMap
map of cached systematics filtering
Definition: SystematicsTool.h:154
CP::SystematicsTool::sysApplySystematicVariation
virtual StatusCode sysApplySystematicVariation(const SystematicSet &systConfig)=0
effects: configure this tool for the given list of systematic variations.
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
python.xAODType.dummy
dummy
Definition: xAODType.py:4
CP::SystematicsTool::appliedSystematicsString
std::string appliedSystematicsString() const
returns: a string representation of appliedSystematics() guarantee: strong failures: out of memory II...
Definition: SystematicsTool.cxx:67
SystematicsTool.h
StatusCode.h
CheckAppliedSFs.systematics
def systematics
Definition: CheckAppliedSFs.py:231
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
CP::SystematicsTool::SystematicsTool
SystematicsTool()
effects: standard constructor guarantee: strong failures: out of memory I
Definition: SystematicsTool.cxx:25
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition: SystematicSet.h:63
CP::SystematicsTool::m_recommendedSystematics
SystematicSet m_recommendedSystematics
Definition: SystematicsTool.h:147
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
CP::SystematicsTool::addAffectingSystematic
StatusCode addAffectingSystematic(const SystematicVariation &systematic, bool recommended)
effects: add a systematic to the list of registered systematics.
Definition: SystematicsTool.cxx:112
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
CP::SystematicsTool::addRecommendedSystematics
StatusCode addRecommendedSystematics(const SystematicSet &systematics)
effects: add a SystematicSet to the recommended systematics.
Definition: SystematicsTool.cxx:152
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
CP::SystematicsTool::appliedSystematics
const SystematicSet & appliedSystematics() const
returns: the list of systematics that have been applied to this tool.
Definition: SystematicsTool.cxx:54
SystematicVariation.h
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233