Commit 1cf00560 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

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

Systematics aware selection in Overlap Removal and Event Scale Factor algorithms

See merge request atlas/athena!47516
parents e0dee4bc f4cee29f
......@@ -56,6 +56,11 @@ namespace CP
SelectionReadHandle m_preselection {
this, "preselection", "", "the preselection to apply"};
/// \brief the decoration for reading systematically aware preselection
private:
SysReadDecorHandle<char> m_inputSelectionDecoration {
this, "inputSelectionDecoration", "", "the decoration for the input selection flag"};
/// \brief the decoration for reading the scale factor
private:
SysReadDecorHandle<float> m_scaleFactorInputDecoration {
......
......@@ -12,6 +12,7 @@
#include <AssociationUtils/ToolBox.h>
#include <SystematicsHandles/SysCopyHandle.h>
#include <SystematicsHandles/SysListHandle.h>
#include <SystematicsHandles/SysWriteDecorHandle.h>
namespace CP
{
......@@ -55,6 +56,30 @@ namespace CP
this, "photons", "", "the photons container to use"};
SysCopyHandle<xAOD::JetContainer> m_fatJetsHandle {
this, "fatJets", "", "the fat jets container to use"};
/// \brief the decoration for the overlap removal status
private:
SysWriteDecorHandle<char> m_electronsDecoration {
this, "electronsDecoration", "", "the decoration for the electron overlap removal selection"};
SysWriteDecorHandle<char> m_muonsDecoration {
this, "muonsDecoration", "", "the decoration for the muon overlap removal selection"};
SysWriteDecorHandle<char> m_jetsDecoration {
this, "jetsDecoration", "", "the decoration for the jet overlap removal selection"};
SysWriteDecorHandle<char> m_tausDecoration {
this, "tausDecoration", "", "the decoration for the tau overlap removal selection"};
SysWriteDecorHandle<char> m_photonsDecoration {
this, "photonsDecoration", "", "the decoration for the photon overlap removal selection"};
SysWriteDecorHandle<char> m_fatJetsDecoration {
this, "fatJetsDecoration", "", "the decoration for the fat jet overlap removal selection"};
/// \brief the tool output decoration for the overlap removal status
private:
std::string m_overlapRemovalDecoration;
/// \brief the accessor for \ref m_overlapRemovalDecoration
private:
std::unique_ptr<const SG::AuxElement::Accessor<char> > m_overlapRemovalAccessor;
};
}
......
......@@ -11,8 +11,6 @@
#include <AsgAnalysisAlgorithms/AsgEventScaleFactorAlg.h>
// #include <SelectionHelpers/SelectionHelpers.h>
//
// method implementations
//
......@@ -39,6 +37,7 @@ namespace CP
ANA_CHECK (m_eventInfoHandle.initialize (m_systematicsList));
ANA_CHECK (m_particleHandle.initialize (m_systematicsList));
ANA_CHECK (m_inputSelectionDecoration.initialize (m_systematicsList, m_particleHandle, SG::AllowEmpty));
ANA_CHECK (m_scaleFactorInputDecoration.initialize (m_systematicsList, m_particleHandle));
ANA_CHECK (m_scaleFactorOutputDecoration.initialize (m_systematicsList, m_eventInfoHandle));
ANA_CHECK (m_systematicsList.initialize());
......@@ -65,6 +64,9 @@ namespace CP
{
if (m_preselection.getBool (*particle))
{
if (m_inputSelectionDecoration && m_inputSelectionDecoration.get (*particle, sys) == 0)
continue;
scaleFactor *= m_scaleFactorInputDecoration.get (*particle, sys);
}
}
......
......@@ -23,6 +23,7 @@ namespace CP
: AnaAlgorithm (name, pSvcLocator)
{
declareProperty ("overlapTool", m_overlapTool);
declareProperty ("OutputLabel", m_overlapRemovalDecoration, "the decoration for the overlap removal tool output");
}
......@@ -30,13 +31,27 @@ namespace CP
StatusCode OverlapRemovalAlg ::
initialize ()
{
if (m_overlapRemovalDecoration.empty())
{
ANA_MSG_ERROR ("no overlap removal decoration name set");
return StatusCode::FAILURE;
}
m_overlapRemovalAccessor = std::make_unique<SG::AuxElement::Accessor<char> > (m_overlapRemovalDecoration);
ANA_CHECK (m_overlapTool.retrieve());
ANA_CHECK (m_electronsHandle.initialize (m_systematicsList, SG::AllowEmpty));
ANA_CHECK (m_electronsDecoration.initialize (m_systematicsList, m_electronsHandle, SG::AllowEmpty));
ANA_CHECK (m_muonsHandle.initialize (m_systematicsList, SG::AllowEmpty));
ANA_CHECK (m_muonsDecoration.initialize (m_systematicsList, m_muonsHandle, SG::AllowEmpty));
ANA_CHECK (m_jetsHandle.initialize (m_systematicsList, SG::AllowEmpty));
ANA_CHECK (m_jetsDecoration.initialize (m_systematicsList, m_jetsHandle, SG::AllowEmpty));
ANA_CHECK (m_tausHandle.initialize (m_systematicsList, SG::AllowEmpty));
ANA_CHECK (m_tausDecoration.initialize (m_systematicsList, m_tausHandle, SG::AllowEmpty));
ANA_CHECK (m_photonsHandle.initialize (m_systematicsList, SG::AllowEmpty));
ANA_CHECK (m_photonsDecoration.initialize (m_systematicsList, m_photonsHandle, SG::AllowEmpty));
ANA_CHECK (m_fatJetsHandle.initialize (m_systematicsList, SG::AllowEmpty));
ANA_CHECK (m_fatJetsDecoration.initialize (m_systematicsList, m_fatJetsHandle, SG::AllowEmpty));
ANA_CHECK (m_systematicsList.initialize());
return StatusCode::SUCCESS;
}
......@@ -48,27 +63,62 @@ namespace CP
{
for (const auto& sys : m_systematicsList.systematicsVector())
{
std::unordered_map<const xAOD::IParticleContainer *, const SysWriteDecorHandle<char> *> decorationsMap;
xAOD::ElectronContainer *electrons {nullptr};
if (m_electronsHandle)
{
ANA_CHECK (m_electronsHandle.getCopy (electrons, sys));
if (m_electronsDecoration)
decorationsMap.emplace(electrons, &m_electronsDecoration);
}
xAOD::MuonContainer *muons {nullptr};
if (m_muonsHandle)
{
ANA_CHECK (m_muonsHandle.getCopy (muons, sys));
if (m_muonsDecoration)
decorationsMap.emplace(muons, &m_muonsDecoration);
}
xAOD::JetContainer *jets {nullptr};
if (m_jetsHandle)
{
ANA_CHECK (m_jetsHandle.getCopy (jets, sys));
if (m_jetsDecoration)
decorationsMap.emplace(jets, &m_jetsDecoration);
}
xAOD::TauJetContainer *taus {nullptr};
if (m_tausHandle)
{
ANA_CHECK (m_tausHandle.getCopy (taus, sys));
if (m_tausDecoration)
decorationsMap.emplace(taus, &m_tausDecoration);
}
xAOD::PhotonContainer *photons {nullptr};
if (m_photonsHandle)
{
ANA_CHECK (m_photonsHandle.getCopy (photons, sys));
if (m_photonsDecoration)
decorationsMap.emplace(photons, &m_photonsDecoration);
}
xAOD::JetContainer *fatJets {nullptr};
if (m_fatJetsHandle)
{
ANA_CHECK (m_fatJetsHandle.getCopy (fatJets, sys));
if (m_fatJetsDecoration)
decorationsMap.emplace(fatJets, &m_fatJetsDecoration);
}
ATH_CHECK (m_overlapTool->removeOverlaps (electrons, muons, jets, taus,
photons, fatJets));
// Re-decorate if needed
for (const auto &pair : decorationsMap)
{
for (const xAOD::IParticle *particle : *(pair.first))
{
(*(pair.second)).set (*particle, (*m_overlapRemovalAccessor) (*particle), sys);
}
}
}
return StatusCode::SUCCESS;
......
......@@ -14,6 +14,7 @@ def makeOverlapAnalysisSequence( dataType,
bJetLabel = '',
boostedLeptons = False,
postfix = '',
shallowViewOutput = True,
enableCutflow = False ):
"""Function creating the overlap removal algorithm sequence
......@@ -66,6 +67,7 @@ def makeOverlapAnalysisSequence( dataType,
bJetLabel -- Flag to select b-jets with. If left empty, no b-jets are used
in the overlap removal.
boostedLeptons -- Set to True to enable boosted lepton overlap removal
shallowViewOutput -- Create a view container if required
enableCutflow -- Whether or not to dump the cutflow
"""
......@@ -77,6 +79,14 @@ def makeOverlapAnalysisSequence( dataType,
# Create the overlap removal algorithm:
alg = createAlgorithm( 'CP::OverlapRemovalAlg', 'OverlapRemovalAlg' + postfix )
alg.OutputLabel = outputLabel
if not shallowViewOutput:
alg.electronsDecoration = outputLabel + '_%SYS%'
alg.muonsDecoration = outputLabel + '_%SYS%'
alg.tausDecoration = outputLabel + '_%SYS%'
alg.jetsDecoration = outputLabel + '_%SYS%'
alg.photonsDecoration = outputLabel + '_%SYS%'
alg.fatJetsDecoration = outputLabel + '_%SYS%'
# Create its main tool, and set its basic properties:
addPrivateTool( alg, 'overlapTool', 'ORUtils::OverlapRemovalTool' )
......@@ -235,52 +245,64 @@ def makeOverlapAnalysisSequence( dataType,
pass
# Add the algorithm to the analysis sequence.
seq.append( alg,
inputPropName = { 'electrons' : 'electrons',
'muons' : 'muons',
'jets' : 'jets',
'taus' : 'taus',
'photons' : 'photons',
'fatJets' : 'fatJets' },
outputPropName = { 'electrons' : 'electronsOut',
'muons' : 'muonsOut',
'jets' : 'jetsOut',
'taus' : 'tausOut',
'photons' : 'photonsOut',
'fatJets' : 'fatJetsOut' } )
if shallowViewOutput:
seq.append( alg,
inputPropName = { 'electrons' : 'electrons',
'muons' : 'muons',
'jets' : 'jets',
'taus' : 'taus',
'photons' : 'photons',
'fatJets' : 'fatJets' },
outputPropName = { 'electrons' : 'electronsOut',
'muons' : 'muonsOut',
'jets' : 'jetsOut',
'taus' : 'tausOut',
'photons' : 'photonsOut',
'fatJets' : 'fatJetsOut' } )
pass
else:
seq.append( alg,
inputPropName = { 'electrons' : 'electrons',
'muons' : 'muons',
'jets' : 'jets',
'taus' : 'taus',
'photons' : 'photons',
'fatJets' : 'fatJets' } )
pass
# Add view container creation algorithms for all types.
for container in [ ( 'electrons', doElectrons ),
( 'muons', doMuons ),
( 'jets', doJets ),
( 'taus', doTaus ),
( 'photons', doPhotons ),
( 'fatJets', doFatJets ) ]:
if shallowViewOutput:
for container in [ ( 'electrons', doElectrons ),
( 'muons', doMuons ),
( 'jets', doJets ),
( 'taus', doTaus ),
( 'photons', doPhotons ),
( 'fatJets', doFatJets ) ]:
# Skip setting up a view container if the type is not being processed.
if not container[ 1 ]:
continue
# Skip setting up a view container if the type is not being processed.
if not container[ 1 ]:
continue
# Set up a cutflow alg.
if enableCutflow:
alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg',
'OverlapRemovalCutFlowDumperAlg_%s' % container[ 0 ] + postfix )
alg.histPattern = container[ 0 ] + postfix + '_OR_cflow_%SYS%'
if inputLabel:
alg.selection = [ '%s,as_char' % inputLabel,
'%s,as_char' % outputLabel ]
alg.selectionNCuts = [1, 1]
else:
alg.selection = [ '%s,as_char' % outputLabel ]
alg.selectionNCuts = [1]
seq.append( alg, inputPropName = { container[ 0 ] : 'input' } )
# Set up a cutflow alg.
if enableCutflow:
alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg',
'OverlapRemovalCutFlowDumperAlg_%s' % container[ 0 ] + postfix )
alg.histPattern = container[ 0 ] + postfix + '_OR_cflow_%SYS%'
if inputLabel:
alg.selection = [ '%s,as_char' % inputLabel,
'%s,as_char' % outputLabel ]
alg.selectionNCuts = [1, 1]
else:
alg.selection = [ '%s,as_char' % outputLabel ]
alg.selectionNCuts = [1]
seq.append( alg, inputPropName = { container[ 0 ] : 'input' } )
# Set up a view container for the type.
alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
'OverlapRemovalViewMaker_%s' % container[ 0 ] + postfix )
alg.selection = [ '%s,as_char' % outputLabel ]
seq.append( alg, inputPropName = { container[ 0 ] : 'input' },
outputPropName = { container[ 0 ] : 'output' } )
# Set up a view container for the type.
alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
'OverlapRemovalViewMaker_%s' % container[ 0 ] + postfix )
alg.selection = [ '%s,as_char' % outputLabel ]
seq.append( alg, inputPropName = { container[ 0 ] : 'input' },
outputPropName = { container[ 0 ] : 'output' } )
pass
# Return the sequence:
......
......@@ -5,6 +5,8 @@ from AnaAlgorithm.AnaAlgSequence import AnaAlgSequence
from AnaAlgorithm.DualUseConfig import createAlgorithm
def makeJetJvtAnalysisSequence( dataType, jetCollection,
preselection = '',
systematicsAwarePreselection = '',
enableFJvt = False,
globalSF = True,
runSelection = True,
......@@ -37,6 +39,8 @@ def makeJetJvtAnalysisSequence( dataType, jetCollection,
# Set up the per-event jet efficiency scale factor calculation algorithm
if dataType != 'data' and globalSF:
alg = createAlgorithm( 'CP::AsgEventScaleFactorAlg', 'JvtEventScaleFactorAlg' )
alg.preselection = preselection + '&&no_jvt' if preselection else 'no_jvt'
alg.inputSelectionDecoration = systematicsAwarePreselection
alg.scaleFactorInputDecoration = 'jvt_effSF_%SYS%'
alg.scaleFactorOutputDecoration = 'jvt_effSF_%SYS%'
......@@ -47,6 +51,8 @@ def makeJetJvtAnalysisSequence( dataType, jetCollection,
if enableFJvt:
alg = createAlgorithm( 'CP::AsgEventScaleFactorAlg', 'ForwardJvtEventScaleFactorAlg' )
alg.preselection = preselection + '&&no_fjvt' if preselection else 'no_fjvt'
alg.inputSelectionDecoration = systematicsAwarePreselection
alg.scaleFactorInputDecoration = 'fjvt_effSF_%SYS%'
alg.scaleFactorOutputDecoration = 'fjvt_effSF_%SYS%'
......
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