Commit c028e73e authored by Nils Krumnack's avatar Nils Krumnack
Browse files

copy over PhysicsAnalysis/Algorithms from 21.2

Originally I had tried sweeping/cherry-picking this from 21.2, but
with all the three-way merges and commits that involve other
packages/directories that was rather painful, so this is now just a
direct copy from the current state in 21.2.
parent 8fe97364
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_ANALYSIS_ALGORITHMS_DICT_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_ANALYSIS_ALGORITHMS_DICT_H
#include <AsgAnalysisAlgorithms/AsgFlagSelectionTool.h>
#include <AsgAnalysisAlgorithms/AsgPtEtaSelectionTool.h>
#include <AsgAnalysisAlgorithms/AsgCutBookkeeperAlg.h>
#include <AsgAnalysisAlgorithms/AsgEventScaleFactorAlg.h>
#include <AsgAnalysisAlgorithms/AsgLeptonTrackSelectionAlg.h>
#include <AsgAnalysisAlgorithms/AsgOriginalObjectLinkAlg.h>
#include <AsgAnalysisAlgorithms/AsgSelectionAlg.h>
#include <AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h>
#include <AsgAnalysisAlgorithms/AsgxAODNTupleMakerAlg.h>
#include <AsgAnalysisAlgorithms/EventFlagSelectionAlg.h>
#include <AsgAnalysisAlgorithms/EventSelectionByObjectFlagAlg.h>
#include <AsgAnalysisAlgorithms/IsolationCloseByCorrectionAlg.h>
#include <AsgAnalysisAlgorithms/KinematicHistAlg.h>
#include <AsgAnalysisAlgorithms/ObjectCutFlowHistAlg.h>
#include <AsgAnalysisAlgorithms/OverlapRemovalAlg.h>
#include <AsgAnalysisAlgorithms/PileupReweightingAlg.h>
#include <AsgAnalysisAlgorithms/PMGTruthWeightAlg.h>
#include <AsgAnalysisAlgorithms/SysListDumperAlg.h>
#include <AsgAnalysisAlgorithms/SysListLoaderAlg.h>
#include <AsgAnalysisAlgorithms/TreeFillerAlg.h>
#include <AsgAnalysisAlgorithms/TreeMakerAlg.h>
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/// @author Tadej Novak
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_CUT_BOOKKEEPER_ALG_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_CUT_BOOKKEEPER_ALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <PMGAnalysisInterfaces/IPMGTruthWeightTool.h>
namespace CP
{
/// \brief an algorithm for dumping the CutBookkeeper metadata
/// into a histogram
class AsgCutBookkeeperAlg final : public EL::AnaAlgorithm
{
/// \brief the standard constructor
public:
AsgCutBookkeeperAlg (const std::string& name,
ISvcLocator* pSvcLocator);
public:
/// \brief initialize
StatusCode initialize () override;
public:
/// \brief run once on each file
StatusCode fileExecute () override;
public:
/// \brief finalize
StatusCode finalize () override;
/// \brief flag to enable systematics
private:
bool m_enableSystematics{false};
/// \brief the truth weight tool
private:
ToolHandle<PMGTools::IPMGTruthWeightTool> m_truthWeightTool;
/// \brief run number we are processing
private:
uint32_t m_runNumber {};
/// \brief MC channel number we are processing
private:
uint32_t m_mcChannelNumber {};
/// \brief weights helper struct
private:
struct WeightsGroup
{
float nEventsProcessed {};
float sumOfWeights {};
float sumOfWeightsSquared {};
};
/// \brief weights map
private:
std::unordered_map<size_t, WeightsGroup> m_weights;
/// \brief the pattern for histogram names
private:
std::string m_histPattern {"CutBookkeeper_%DSID%_%RUN%_%SYS%"};
};
}
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/// @author Tadej Novak
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_EVENT_SCALE_FACTOR_ALG_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_EVENT_SCALE_FACTOR_ALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <SelectionHelpers/ISelectionAccessor.h>
#include <SelectionHelpers/SelectionReadHandle.h>
#include <SystematicsHandles/SysCopyHandle.h>
#include <SystematicsHandles/SysDecorationHandle.h>
#include <SystematicsHandles/SysListHandle.h>
#include <xAODBase/IParticleContainer.h>
#include <xAODEventInfo/EventInfo.h>
namespace CP
{
/// \brief an algorithm for calculating per-event scale factors
class AsgEventScaleFactorAlg final : public EL::AnaAlgorithm
{
/// \brief the standard constructor
public:
AsgEventScaleFactorAlg (const std::string& name,
ISvcLocator* pSvcLocator);
public:
StatusCode initialize () override;
public:
StatusCode execute () override;
/// \brief the systematics list we run
private:
SysListHandle m_systematicsList {this};
/// \brief the event info we run on (empty by default)
private:
SysCopyHandle<xAOD::EventInfo> m_eventInfoHandle {
this, "eventInfo", "EventInfo", "the event info object to run on"};
/// \brief the jet collection we run on
private:
SysCopyHandle<xAOD::IParticleContainer> m_particleHandle {
this, "particles", "", "the particle collection to run on"};
/// \brief the preselection we apply to our input
private:
SelectionReadHandle m_preselection {
this, "preselection", "", "the preselection to apply"};
/// \brief the decoration for reading the scale factor
private:
SysDecorationHandle<float> m_scaleFactorInputDecoration {
this, "scaleFactorInputDecoration", "", "the decoration for the input efficiency scale factor"};
/// \brief the decoration for writing the scale factor
private:
SysDecorationHandle<float> m_scaleFactorOutputDecoration {
this, "scaleFactorOutputDecoration", "", "the decoration for the output efficiency scale factor"};
};
}
#endif
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
/// @author Teng Jian Khoo
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_FLAG_SELECTION_TOOL_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_FLAG_SELECTION_TOOL_H
#include <AsgTools/AsgTool.h>
#include <PATCore/IAsgSelectionTool.h>
#include <SelectionHelpers/ISelectionAccessor.h>
#include <xAODBase/IParticle.h>
#include <memory>
#include <string>
#include <vector>
namespace CP
{
/// \brief an \ref IAsgSelectionTool that cuts on char decorations
///
/// For ROOT I/O reasons, chars are commonly used to store boolean
/// properties, such as flags indicating whether particular criteria
/// have been passed. This tool provides a conversion of a list
/// of such decorations, interpreted as bools, into the SelectionType
/// encoding of TAccept, for use in AnaAlgSequence.
///
/// A list of flags may be provided to the tool, and the output will
/// simply concatenate them into the TAccept. Each selection criterion
/// must be passed (no OR behaviour), but the flag logic may be
/// inverted, such that flags may be encoded as "passX" or !"failX".
class AsgFlagSelectionTool final
: public asg::AsgTool, virtual public IAsgSelectionTool
{
//
// public interface
//
// Create a proper constructor for Athena
ASG_TOOL_CLASS( AsgFlagSelectionTool, IAsgSelectionTool )
/// \brief standard constructor
/// \par Guarantee
/// strong
/// \par Failures
/// out of memory II
public:
AsgFlagSelectionTool (const std::string& name);
//
// inherited interface
//
virtual StatusCode initialize () override;
virtual const Root::TAccept& getTAccept( ) const override;
virtual const Root::TAccept& accept( const xAOD::IParticle* /*part*/ ) const override;
//
// private interface
//
/// tool properties
/// \{
std::vector<std::string> m_selFlags;
std::vector<bool> m_invertFlags;
std::vector<std::unique_ptr<ISelectionAccessor> > m_acc_selFlags;
/// \}
/// \brief the \ref TAccept we are using
private:
mutable Root::TAccept m_accept;
};
}
#endif
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_LEPTON_TRACK_SELECTION_ALG_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_LEPTON_TRACK_SELECTION_ALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <PATCore/IAsgSelectionTool.h>
#include <SelectionHelpers/ISelectionAccessor.h>
#include <SelectionHelpers/SelectionReadHandle.h>
#include <SystematicsHandles/SysCopyHandle.h>
#include <SystematicsHandles/SysListHandle.h>
namespace CP
{
/// \brief an algorithm for performing track-vertex selection on
/// leptons
///
/// Originally I meant to implement this as an \ref
/// IAsgSelectionTool, but since this needs other objects besides
/// the lepton itself, I made it into an algorithm. Technically
/// this could also be addressed by retrieving those extra objects
/// in the seleciton tool, but this seemed like potential overkill,
/// given that the selection tools may be called very frequently and
/// are not really doing any form of heavy lifting at all. Still,
/// at some point we may decide to change this into a selection tool
/// instead (06 Aug 18).
class AsgLeptonTrackSelectionAlg final : public EL::AnaAlgorithm
{
/// \brief the standard constructor
public:
AsgLeptonTrackSelectionAlg (const std::string& name,
ISvcLocator* pSvcLocator);
public:
StatusCode initialize () override;
public:
StatusCode execute () override;
/// algorithm properties
/// \{
private:
float m_maxD0Significance {0};
float m_maxDeltaZ0SinTheta {0};
int m_nMinPixelHits{-1};
int m_nMaxPixelHits{-1};
int m_nMinSCTHits{-1};
int m_nMaxSCTHits{-1};
std::string m_selectionDecoration {"trackSelection"};
std::string m_eventInfo {"EventInfo"};
std::string m_primaryVertices {"PrimaryVertices"};
/// \}
/// \brief the systematics list we run
private:
SysListHandle m_systematicsList {this};
/// \brief the particle continer we run on
private:
SysCopyHandle<xAOD::IParticleContainer> m_particlesHandle {
this, "particles", "", "the asg collection to run on"};
/// \brief the preselection we apply to our input
private:
SelectionReadHandle m_preselection {
this, "preselection", "", "the preselection to apply"};
/// \brief the accessor for \ref m_selectionDecoration
private:
std::unique_ptr<ISelectionAccessor> m_selectionAccessor;
/// \brief the \ref TAccept we are using
private:
Root::TAccept m_accept;
};
}
#endif
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/// @author Tadej Novak
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_ORIGINAL_OBJECT_LINK_ALG_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_ORIGINAL_OBJECT_LINK_ALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <SystematicsHandles/SysCopyHandle.h>
#include <SystematicsHandles/SysListHandle.h>
#include <xAODBase/IParticleContainer.h>
namespace CP
{
/// \brief an algorithm for relinking a shallow copy with it's base container
/// when this was not done originally
///
/// In some cases we work with shallow copy containers that originally did
/// not have proper original object linking done when created.
/// Currently the client are b-tagging calibration shallow copies.
class AsgOriginalObjectLinkAlg final : public EL::AnaAlgorithm
{
/// \brief the standard constructor
public:
AsgOriginalObjectLinkAlg (const std::string& name,
ISvcLocator* pSvcLocator);
public:
StatusCode initialize () override;
public:
StatusCode execute () override;
/// \brief base container name
private:
std::string m_baseContainerName {""};
/// \brief the systematics list we run
private:
SysListHandle m_systematicsList {this};
/// \brief the particle container we run on
private:
SysCopyHandle<xAOD::IParticleContainer> m_particleHandle {
this, "particles", "", "the particle container to run on"};
};
}
#endif
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_PT_ETA_SELECTION_TOOL_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_PT_ETA_SELECTION_TOOL_H
#include <AsgTools/AsgTool.h>
#include <PATCore/IAsgSelectionTool.h>
#include <atomic>
namespace CP
{
/// \brief an \ref IAsgSelectionTool that performs basic pt and eta
/// cut (with an optional eta gap)
///
/// This is a very basic selection that needs to happen on all
/// object types to some degree. Instead of doing this separately
/// for each type, it is just one basic tool for all \ref IParticle
/// implementations. Also, this is a tool, not an algorithm,
/// because we already have an algorithm wrapping generic selection
/// tools and there is no benefit to making it an algorithm.
///
/// There may be some overlap with the individual selectors for the
/// given object types, but having a tool for this allows to apply
/// it at any point in the algorithm sequence.
class AsgPtEtaSelectionTool final
: public asg::AsgTool, virtual public IAsgSelectionTool
{
//
// public interface
//
// Create a proper constructor for Athena
ASG_TOOL_CLASS( AsgPtEtaSelectionTool, IAsgSelectionTool )
/// \brief standard constructor
/// \par Guarantee
/// strong
/// \par Failures
/// out of memory II
public:
AsgPtEtaSelectionTool (const std::string& name);
//
// inherited interface
//
virtual StatusCode initialize () override;
virtual const Root::TAccept& getTAccept( ) const override;
virtual const Root::TAccept& accept( const xAOD::IParticle* /*part*/ ) const override;
//
// private interface
//
/// tool properties
/// \{
private:
float m_minPt {0};
float m_maxPt {0};
float m_maxEta {0};
float m_etaGapLow {0};
float m_etaGapHigh {0};
bool m_useClusterEta {false};
bool m_printCastWarning {true};
bool m_printClusterWarning {true};
/// \}
/// Index for the minimum pT selection
int m_minPtCutIndex{ -1 };
/// Index for the maximum pT selection
int m_maxPtCutIndex{ -1 };
/// Index for the maximum eta selection
int m_maxEtaCutIndex{ -1 };
/// Index for the eta gap selection
int m_etaGapCutIndex{ -1 };
/// Index for the e/gamma casting
int m_egammaCastCutIndex{ -1 };
/// Index for the e/gamma calo-cluster
int m_egammaClusterCutIndex{ -1 };
/// \brief a version of \ref m_printCastWarning that we modify
/// once we printed the warning
///
/// I don't like modifying property values in the tool itself, so
/// I copy it over here and then modify once I print out.
///
/// Technically this tool isn't thread-safe due to the use of
/// TAccept, but once we move to master this will be fixed, so
/// this member is already made thread-safe so that we don't trip
/// up on that later.
private:
mutable std::atomic<bool> m_shouldPrintCastWarning {true};
/// \brief a version of \ref m_printClusterWarning that we modify
/// once we printed the warning
///
/// I don't like modifying property values in the tool itself, so
/// I copy it over here and then modify once I print out.
///
/// Technically this tool isn't thread-safe due to the use of
/// TAccept, but once we move to master this will be fixed, so
/// this member is already made thread-safe so that we don't trip
/// up on that later.
private:
mutable std::atomic<bool> m_shouldPrintClusterWarning {true};
/// \brief the \ref TAccept we are using
private:
mutable Root::TAccept m_accept;
};
}
#endif
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_SELECTION_ALG_H
#define ASG_ANALYSIS_ALGORITHMS__ASG_SELECTION_ALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <PATCore/IAsgSelectionTool.h>
#include <SelectionHelpers/ISelectionAccessor.h>
#include <SelectionHelpers/SelectionReadHandle.h>
#include <SystematicsHandles/SysCopyHandle.h>
#include <SystematicsHandles/SysListHandle.h>
namespace CP
{
/// \brief an algorithm for calling \ref IAsgSelectionTool
///
/// There are two ways to implement this: The way I chose is to call
/// the IAsgSelectionTool on the members of an IParticleContainer.
/// Among several issues this has some inefficiencies, because it
/// relies on dynamic_cast inside the IAsgSelectionTool. Also,
/// currently \ref CopyHandle only supports specific xAOD types for
/// IParticleContainer (though in practice this only matters if
/// systematics are applied in this algorithm).