Commit e0dee4bc authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'cp/outputalg-master' into 'master'

Improve systematics handling in AsgxAODNTupleMakerAlg

See merge request atlas/athena!47514
parents 67fb1fed 21e8c8a6
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
// Framework include(s): // Framework include(s):
#include "AsgMessaging/AsgMessaging.h" #include "AsgMessaging/AsgMessaging.h"
#include "AsgServices/ServiceHandle.h"
#include "AnaAlgorithm/AnaAlgorithm.h" #include "AnaAlgorithm/AnaAlgorithm.h"
#include "SystematicsHandles/SysListHandle.h" #include "SystematicsHandles/SysListHandle.h"
...@@ -356,8 +357,8 @@ namespace CP { ...@@ -356,8 +357,8 @@ namespace CP {
/// ///
bool m_isInitialized = false; bool m_isInitialized = false;
/// The systematic list to consider during execution /// \brief the handle for the systematics service
SysListHandle m_systematicsList{ this }; ServiceHandle<ISystematicsSvc> m_systematicsService {"SystematicsSvc", ""};
/// @} /// @}
......
...@@ -308,6 +308,8 @@ namespace CP { ...@@ -308,6 +308,8 @@ namespace CP {
"Name of the tree to write" ); "Name of the tree to write" );
declareProperty( "Branches", m_branches, declareProperty( "Branches", m_branches,
"Branches to write to the output tree" ); "Branches to write to the output tree" );
declareProperty( "systematicsService", m_systematicsService,
"systematics service" );
} }
StatusCode AsgxAODNTupleMakerAlg::initialize() { StatusCode AsgxAODNTupleMakerAlg::initialize() {
...@@ -319,7 +321,7 @@ namespace CP { ...@@ -319,7 +321,7 @@ namespace CP {
} }
// Set up the systematics list. // Set up the systematics list.
ATH_CHECK( m_systematicsList.initialize() ); ATH_CHECK( m_systematicsService.retrieve() );
// Reset the initialisation flag: // Reset the initialisation flag:
m_isInitialized = false; m_isInitialized = false;
...@@ -396,7 +398,7 @@ namespace CP { ...@@ -396,7 +398,7 @@ namespace CP {
} }
// Consider all systematics but skip the nominal one // Consider all systematics but skip the nominal one
for( const auto& sys : m_systematicsList.systematicsVector() ) { for( const auto& sys : m_systematicsService->makeSystematicsVector() ) {
// Nominal already processed // Nominal already processed
if( sys.empty() ) { if( sys.empty() ) {
continue; continue;
...@@ -439,18 +441,56 @@ namespace CP { ...@@ -439,18 +441,56 @@ namespace CP {
// Check if we are running nominal // Check if we are running nominal
bool nominal = sys.empty(); bool nominal = sys.empty();
// Check if we are affected by the systematics
bool systematicsContainer{false};
bool systematicsDecoration{false};
bool affectedContainer{true};
bool affectedDecoration{true};
// Event store key for the object under consideration. // Event store key for the object under consideration.
std::string key; std::string key = match[ 1 ];
ANA_CHECK (m_systematicsList.service().makeSystematicsName( key, match[ 1 ], sys )); if( key.find( "%SYS%" ) != std::string::npos )
{
systematicsContainer = true;
const CP::SystematicSet affecting = m_systematicsService->getObjectSystematics( key );
CP::SystematicSet matching;
ANA_CHECK( SystematicSet::filterForAffectingSystematics( sys, affecting, matching ) );
if( !nominal && matching.empty() ) {
ATH_MSG_VERBOSE( "Container \"" << key << "\" is not affected by systematics \"" << sys.name() << "\"" );
affectedContainer = false;
}
ANA_CHECK( m_systematicsService->makeSystematicsName( key, match[ 1 ], matching ) );
}
// Auxiliary variable name for the object under consideration. // Auxiliary variable name for the object under consideration.
std::string auxName; std::string auxName = match[ 2 ];
ANA_CHECK (m_systematicsList.service().makeSystematicsName( auxName, match[ 2 ], if( auxName.find( "%SYS%" ) != std::string::npos )
sys )); {
systematicsDecoration = true;
const CP::SystematicSet affecting = m_systematicsService->getDecorSystematics( match[ 1 ], auxName );
CP::SystematicSet matching;
ANA_CHECK( SystematicSet::filterForAffectingSystematics( sys, affecting, matching ) );
if( !nominal && matching.empty() ) {
ATH_MSG_VERBOSE( "Decoration \"" << auxName << "\" is not affected by systematics \"" << sys.name() << "\"" );
affectedDecoration = false;
}
ANA_CHECK( m_systematicsService->makeSystematicsName( auxName, match[ 2 ], matching ) );
}
// Ignore the branch if neither container nor decoration are affected by the systematic
if( !nominal
&& ( ( systematicsContainer && systematicsDecoration && !affectedContainer && !affectedDecoration )
|| ( !systematicsContainer && systematicsDecoration && !affectedDecoration )
|| ( systematicsContainer && !systematicsDecoration && !affectedContainer ) ) )
{
ANA_MSG_VERBOSE( "Neither container nor decoration are affected by systematics \"" << sys.name() << "\""
<< " for branch rule \"" << branchDecl << "\"" );
return StatusCode::SUCCESS;
}
// Branch name for the variable. // Branch name for the variable.
std::string brName; std::string brName = match[ 3 ];
ANA_CHECK (m_systematicsList.service().makeSystematicsName( brName, match[ 3 ], if( brName.find( "%SYS%" ) != std::string::npos )
sys )); ANA_CHECK (m_systematicsService->makeSystematicsName( brName, match[ 3 ], sys ));
// If the %SYS% pattern was not used in this setup, then stop // If the %SYS% pattern was not used in this setup, then stop
// on non-nominal systematic. // on non-nominal systematic.
...@@ -499,10 +539,10 @@ namespace CP { ...@@ -499,10 +539,10 @@ namespace CP {
ALLOW_MISSING, msg() ) ) { ALLOW_MISSING, msg() ) ) {
bool created = false; bool created = false;
ATH_CHECK( m_elements[ key ].addBranch( *m_tree, ATH_CHECK( m_elements[ key ].addBranch( *m_tree,
auxName, auxName,
brName, brName,
ALLOW_MISSING, ALLOW_MISSING,
created ) ); created ) );
if( created ) { if( created ) {
ATH_MSG_DEBUG( "Writing branch \"" << brName ATH_MSG_DEBUG( "Writing branch \"" << brName
<< "\" from object/variable \"" << key << "\" from object/variable \"" << key
...@@ -520,9 +560,11 @@ namespace CP { ...@@ -520,9 +560,11 @@ namespace CP {
} }
// Check if the rule was meaningful or not: // Check if the rule was meaningful or not:
if( nominal && ! branchCreated && key == match[ 1 ] ) { if( ! branchCreated ) {
ATH_MSG_ERROR( "No branch was created for rule: \"" ATH_MSG_ERROR( "No branch was created for rule: \""
<< branchDecl << "\"" ); << branchDecl << "\""
<< " and systematics: \""
<< sys.name() << "\"" );
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
......
...@@ -58,6 +58,9 @@ def makeSequence (dataType) : ...@@ -58,6 +58,9 @@ def makeSequence (dataType) :
ntupleMaker.Branches = [ 'AnalysisMuons_NOSYS.eta -> mu_eta', ntupleMaker.Branches = [ 'AnalysisMuons_NOSYS.eta -> mu_eta',
'AnalysisMuons_NOSYS.phi -> mu_phi', 'AnalysisMuons_NOSYS.phi -> mu_phi',
'AnalysisMuons_%SYS%.pt -> mu_%SYS%_pt', ] 'AnalysisMuons_%SYS%.pt -> mu_%SYS%_pt', ]
if dataType != 'data':
ntupleMaker.Branches += [ 'AnalysisMuons_%SYS%.muon_effSF_tight_%SYS% -> mu_%SYS%_effSF' ]
ntupleMaker.OutputLevel = 2 # For output validation
algSeq += ntupleMaker algSeq += ntupleMaker
treeFiller = createAlgorithm( 'CP::TreeFillerAlg', 'TreeFiller' ) treeFiller = createAlgorithm( 'CP::TreeFillerAlg', 'TreeFiller' )
treeFiller.TreeName = 'muons' treeFiller.TreeName = 'muons'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment