00001 #ifndef REWEIGHTUTILS_PARTICLESCALEFACTORTOOL_H 00002 #define REWEIGHTUTILS_PARTICLESCALEFACTORTOOL_H 1 00003 00004 #include "AsgTools/AsgTool.h" 00005 00006 #include "AsgAnalysisInterfaces/IObservableTool.h" 00007 #include "PATInterfaces/ISystematicsTool.h" 00008 00009 #include "TH1.h" 00010 #include "xAODBase/IParticle.h" 00011 00012 #include <functional> 00013 00014 class ParticleScaleFactorTool: public asg::AsgTool, public virtual IObservableTool , public CP::ISystematicsTool { 00015 public: 00016 //constructor for athena can be created using special macro 00017 //Note: if you add a second interface to your tool, you must use: ASG_TOOL_CLASS2( ToolName, Interface1, Interface2) 00018 ASG_TOOL_CLASS2( ParticleScaleFactorTool , IObservableTool , CP::ISystematicsTool ) 00019 //add another constructor for non-athena use cases 00020 ParticleScaleFactorTool( const std::string& name ); 00021 00022 ~ParticleScaleFactorTool(); 00023 00025 virtual StatusCode initialize() override; 00026 00027 virtual double evaluate(const xAOD::IParticle* particle) const override; 00028 00029 static double part_pt(const xAOD::IParticle& p) {return p.pt();} 00030 static double part_pt_gev(const xAOD::IParticle& p) {return p.pt()*1e-3;} 00031 static double part_eta(const xAOD::IParticle& p) {return p.eta();} 00032 static double part_decor(const xAOD::IParticle& p,const std::string& varname) { 00033 SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance(); 00034 const SG::auxid_t auxid = reg.findAuxID( varname ); 00035 if( auxid == SG::null_auxid ) { 00036 throw std::runtime_error("unknown aux id for decoration: " + varname); 00037 } 00038 const std::type_info* ti = reg.getType( auxid ); 00039 if( *ti == typeid( double ) ) { 00040 return p.auxdataConst< double >( varname ); 00041 } else if( *ti == typeid( float ) ) { 00042 return p.auxdataConst< float >( varname ); 00043 } else if( *ti == typeid( int ) ) { 00044 return p.auxdataConst< int >( varname ); 00045 } else if( *ti == typeid( unsigned int ) ) { 00046 return p.auxdataConst< unsigned int>( varname ); 00047 } 00048 throw std::runtime_error("Unrecognised type for decoration: " + varname); 00049 } 00050 00051 00053 bool isAffectedBySystematic( const CP::SystematicVariation& systematic ) const override { return (m_affectingSysts.find(systematic)!=m_affectingSysts.end()); } 00054 CP::SystematicSet affectingSystematics() const override { return m_affectingSysts; } 00055 CP::SystematicSet recommendedSystematics() const override { return affectingSystematics(); } 00056 CP::SystematicCode applySystematicVariation( const CP::SystematicSet& systConfig ) override; 00057 00058 private: 00059 std::string m_configFile; 00060 00061 CP::SystematicVariation m_currentSyst; 00062 00063 struct Hists { 00064 std::map<CP::SystematicVariation,TH1*> hists; 00065 const std::pair<CP::SystematicVariation,TH1*> getHist(const CP::SystematicVariation& set) const; 00066 std::vector<std::function<double(const xAOD::IParticle&)>> axisFuncs; 00067 }; 00068 00069 std::map<xAOD::Type::ObjectType,Hists> m_hists; 00070 00071 CP::SystematicSet m_affectingSysts; 00072 bool m_isNominal=true; 00073 00074 }; 00075 00076 #endif //> !REWEIGHTUTILS_PARTICLESCALEFACTORTOOL_H