ATLAS Offline Software
ParticleScaleFactorTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef REWEIGHTUTILS_PARTICLESCALEFACTORTOOL_H
6 #define REWEIGHTUTILS_PARTICLESCALEFACTORTOOL_H 1
7 
8 #include "AsgTools/AsgTool.h"
9 
12 
13 #include "TH1.h"
14 #include "xAODBase/IParticle.h"
16 
17 #include <functional>
18 
19 class ParticleScaleFactorTool: public asg::AsgTool, public virtual IObservableTool , public virtual CP::ISystematicsTool {
20  public:
21  //constructor for athena can be created using special macro
22  //Note: if you add a second interface to your tool, you must use: ASG_TOOL_CLASS2( ToolName, Interface1, Interface2)
24  //add another constructor for non-athena use cases
25  ParticleScaleFactorTool( const std::string& name );
26 
28 
30  virtual StatusCode initialize() override;
31 
32  virtual double evaluate(const xAOD::IParticle* particle) const override;
33 
34  static double part_pt(const xAOD::IParticle& p) {return p.pt();}
35  static double part_pt_gev(const xAOD::IParticle& p) {return p.pt()*1e-3;}
36  static double part_eta(const xAOD::IParticle& p) {return p.eta();}
37  static double part_decor(const xAOD::IParticle& p,const std::string& varname) {
39  const SG::auxid_t auxid = reg.findAuxID( varname );
40  if( auxid == SG::null_auxid ) {
41  throw std::runtime_error("unknown aux id for decoration: " + varname);
42  }
43  const std::type_info* ti = reg.getType( auxid );
44  if( *ti == typeid( double ) ) {
46  return acc(p);
47  } else if( *ti == typeid( float ) ) {
49  return acc(p);
50  } else if( *ti == typeid( int ) ) {
52  return acc(p);
53  } else if( *ti == typeid( unsigned int ) ) {
55  return acc(p);
56  }
57  throw std::runtime_error("Unrecognised type for decoration: " + varname);
58  }
59 
60 
62  bool isAffectedBySystematic( const CP::SystematicVariation& systematic ) const override { return (m_affectingSysts.find(systematic)!=m_affectingSysts.end()); }
65  StatusCode applySystematicVariation( const CP::SystematicSet& systConfig ) override;
66 
67  private:
68  std::string m_configFile;
69 
71 
72  struct Hists {
73  std::map<CP::SystematicVariation,TH1*> hists;
74  const std::pair<CP::SystematicVariation,TH1*> getHist(const CP::SystematicVariation& set) const;
75  std::vector<std::function<double(const xAOD::IParticle&)>> axisFuncs;
76  };
77 
78  std::map<xAOD::Type::ObjectType,Hists> m_hists;
79 
81  bool m_isNominal=true;
82 
83 };
84 
85 #endif //> !REWEIGHTUTILS_PARTICLESCALEFACTORTOOL_H
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ParticleScaleFactorTool::recommendedSystematics
CP::SystematicSet recommendedSystematics() const override
the list of all systematics this tool recommends to use
Definition: ParticleScaleFactorTool.h:64
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
ParticleScaleFactorTool::Hists::hists
std::map< CP::SystematicVariation, TH1 * > hists
Definition: ParticleScaleFactorTool.h:73
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
ParticleScaleFactorTool
Definition: ParticleScaleFactorTool.h:19
ParticleScaleFactorTool::ParticleScaleFactorTool
ParticleScaleFactorTool(const std::string &name)
Definition: ParticleScaleFactorTool.cxx:17
IParticle.h
ParticleScaleFactorTool::applySystematicVariation
StatusCode applySystematicVariation(const CP::SystematicSet &systConfig) override
effects: configure this tool for the given list of systematic variations.
Definition: ParticleScaleFactorTool.cxx:241
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
SG::AuxTypeRegistry::findAuxID
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
Definition: AuxTypeRegistry.cxx:757
ParticleScaleFactorTool::Hists
Definition: ParticleScaleFactorTool.h:72
IObservableTool
Interface for tools that want to calculate a quantity from an xAOD::IParticle.
Definition: IObservableTool.h:32
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
ParticleScaleFactorTool::Hists::getHist
const std::pair< CP::SystematicVariation, TH1 * > getHist(const CP::SystematicVariation &set) const
Definition: ParticleScaleFactorTool.cxx:222
ParticleScaleFactorTool::part_decor
static double part_decor(const xAOD::IParticle &p, const std::string &varname)
Definition: ParticleScaleFactorTool.h:37
SG::ConstAccessor< double >
CP::SystematicVariation
Definition: SystematicVariation.h:47
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
ISystematicsTool.h
ParticleScaleFactorTool::affectingSystematics
CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by
Definition: ParticleScaleFactorTool.h:63
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
ParticleScaleFactorTool::m_currentSyst
CP::SystematicVariation m_currentSyst
Definition: ParticleScaleFactorTool.h:70
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxTypeRegistry::getType
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
Definition: AuxTypeRegistry.cxx:909
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ParticleScaleFactorTool::part_pt
static double part_pt(const xAOD::IParticle &p)
Definition: ParticleScaleFactorTool.h:34
ParticleScaleFactorTool::isAffectedBySystematic
bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const override
The ISystematicsTool methods.
Definition: ParticleScaleFactorTool.h:62
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ParticleScaleFactorTool::m_affectingSysts
CP::SystematicSet m_affectingSysts
Definition: ParticleScaleFactorTool.h:80
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
ParticleScaleFactorTool::initialize
virtual StatusCode initialize() override
Initialize is required by AsgTool base class.
Definition: ParticleScaleFactorTool.cxx:34
ParticleScaleFactorTool::Hists::axisFuncs
std::vector< std::function< double(const xAOD::IParticle &)> > axisFuncs
Definition: ParticleScaleFactorTool.h:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
IObservableTool.h
ParticleScaleFactorTool::m_configFile
std::string m_configFile
Definition: ParticleScaleFactorTool.h:68
ParticleScaleFactorTool::m_hists
std::map< xAOD::Type::ObjectType, Hists > m_hists
Definition: ParticleScaleFactorTool.h:78
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition: SystematicSet.h:63
CP::ISystematicsTool
Interface for all CP tools supporting systematic variations.
Definition: ISystematicsTool.h:32
ParticleScaleFactorTool::m_isNominal
bool m_isNominal
Definition: ParticleScaleFactorTool.h:81
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
ParticleScaleFactorTool::part_eta
static double part_eta(const xAOD::IParticle &p)
Definition: ParticleScaleFactorTool.h:36
ASG_TOOL_CLASS3
#define ASG_TOOL_CLASS3(CLASSNAME, INT1, INT2, INT3)
Definition: AsgToolMacros.h:85
CP::IReentrantSystematicsTool
interface for all CP tools supporting systematic variations within a reentrant algorithm
Definition: IReentrantSystematicsTool.h:58
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
ParticleScaleFactorTool::~ParticleScaleFactorTool
~ParticleScaleFactorTool()
Definition: ParticleScaleFactorTool.cxx:23
AsgTool.h
ParticleScaleFactorTool::part_pt_gev
static double part_pt_gev(const xAOD::IParticle &p)
Definition: ParticleScaleFactorTool.h:35
ParticleScaleFactorTool::evaluate
virtual double evaluate(const xAOD::IParticle *particle) const override
returns: the value that was calculated from the xAOD::IParticle
Definition: ParticleScaleFactorTool.cxx:189