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