ATLAS Offline Software
Loading...
Searching...
No Matches
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
19class 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 ) ) {
45 SG::ConstAccessor<double> acc (varname);
46 return acc(p);
47 } else if( *ti == typeid( float ) ) {
48 SG::ConstAccessor<float> acc (varname);
49 return acc(p);
50 } else if( *ti == typeid( int ) ) {
51 SG::ConstAccessor<int> acc (varname);
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
#define ASG_TOOL_CLASS3(CLASSNAME, INT1, INT2, INT3)
Helper class to provide constant type-safe access to aux data.
interface for all CP tools supporting systematic variations within a reentrant algorithm
Interface for all CP tools supporting systematic variations.
Class to wrap a set of SystematicVariations.
Interface for tools that want to calculate a quantity from an xAOD::IParticle.
virtual double evaluate(const xAOD::IParticle *particle) const override
returns: the value that was calculated from the xAOD::IParticle
CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by
std::map< xAOD::Type::ObjectType, Hists > m_hists
bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const override
The ISystematicsTool methods.
CP::SystematicVariation m_currentSyst
static double part_decor(const xAOD::IParticle &p, const std::string &varname)
ParticleScaleFactorTool(const std::string &name)
CP::SystematicSet recommendedSystematics() const override
the list of all systematics this tool recommends to use
static double part_pt_gev(const xAOD::IParticle &p)
static double part_eta(const xAOD::IParticle &p)
static double part_pt(const xAOD::IParticle &p)
virtual StatusCode initialize() override
Initialize is required by AsgTool base class.
StatusCode applySystematicVariation(const CP::SystematicSet &systConfig) override
effects: configure this tool for the given list of systematic variations.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
STL class.
Class providing the definition of the 4-vector interface.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
const std::pair< CP::SystematicVariation, TH1 * > getHist(const CP::SystematicVariation &set) const
std::map< CP::SystematicVariation, TH1 * > hists
std::vector< std::function< double(const xAOD::IParticle &)> > axisFuncs