ATLAS Offline Software
Loading...
Searching...
No Matches
ITrigGlobalEfficiencyCorrectionTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4
5// contact: jmaurer@cern.ch
6
7#ifndef TRIGGERANALYSISINTERFACES_ITRIGGLOBALEFFICIENCYCORRECTIONTOOL_H
8#define TRIGGERANALYSISINTERFACES_ITRIGGLOBALEFFICIENCYCORRECTIONTOOL_H 1
9
12#include "xAODEgamma/Electron.h"
13#include "xAODMuon/Muon.h"
14#include "xAODEgamma/Photon.h"
15
16#include <vector>
17#include <type_traits>
18#include <string_view>
19
21{
22public:
24
25 template<typename Arg> static constexpr bool validArgs(unsigned nTrailingDoubles);
26 template<typename Arg1, typename Arg2, typename... OtherArgs> static constexpr bool validArgs(unsigned nTrailingDoubles);
27
28 virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector<const xAOD::IParticle*>& particles, double& efficiencyScaleFactor) = 0;
29 virtual CP::CorrectionCode getEfficiency(const std::vector<const xAOD::IParticle*>& particles, double& efficiencyData, double& efficiencyMc) = 0;
30 virtual CP::CorrectionCode checkTriggerMatching(bool& matched, const std::vector<const xAOD::IParticle*>& particles) = 0;
31 virtual CP::CorrectionCode checkTriggerMatching(std::unordered_map<std::string, bool>& matched_per_trigger, const std::vector<const xAOD::IParticle*>& particles) = 0;
32
39 template<typename... Args>
40 auto getEfficiencyScaleFactor(Args&... args) -> std::enable_if_t<validArgs<Args...>(1), CP::CorrectionCode>;
41 template<typename... Args>
42 auto getEfficiency(Args&... args) -> std::enable_if_t<validArgs<Args...>(2), CP::CorrectionCode>;
43 template<typename BoolOrMap, typename... Args>
44 auto checkTriggerMatching(BoolOrMap& matched, Args&... args) -> std::enable_if_t<validArgs<Args...>(0), CP::CorrectionCode>;
45
47 virtual CP::CorrectionCode getRelevantTriggers(std::vector<std::string>& triggers) = 0;
48
50 virtual CP::CorrectionCode countTriggerLegs(const std::string& trigger, std::size_t& numberOfLegs) = 0;
51
53 virtual CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyScaleFactor) = 0;
54 virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyData, double& efficiencyMc) = 0;
55
57 static std::string toolnameForDefaultScaleFactor() { return "RETURN_DEFAULT_SCALE_FACTOR"; }
58protected:
59 double* handleArg(double& arg, std::vector<const xAOD::IParticle*>&) { return &arg; }
60 template<typename P> double* handleArg(const std::vector<P>& arg, std::vector<const xAOD::IParticle*>& particles)
61 {
62 for(auto ptr : arg) particles.push_back(static_cast<const xAOD::IParticle*>(ptr));
63 return nullptr;
64 }
65};
66
67template<typename Arg>
68constexpr bool ITrigGlobalEfficiencyCorrectionTool::validArgs(unsigned nTrailingDoubles)
69{
70 if(std::is_same<double, Arg>::value) return (nTrailingDoubles==1);
71 using P = std::remove_cv_t<Arg>;
72 return std::is_same<P, std::vector<xAOD::Electron*>>::value
73 || std::is_same<P, std::vector<const xAOD::Electron*>>::value
74 || std::is_same<P, std::vector<xAOD::Muon*>>::value
75 || std::is_same<P, std::vector<const xAOD::Muon*>>::value
76 || std::is_same<P, std::vector<xAOD::Photon*>>::value
77 || std::is_same<P, std::vector<const xAOD::Photon*>>::value;
78}
79
80template<typename Arg1, typename Arg2, typename... OtherArgs>
81constexpr bool ITrigGlobalEfficiencyCorrectionTool::validArgs(unsigned nTrailingDoubles)
82{
83 bool xs [] = { std::is_same<OtherArgs, double>::value..., true };
84 for(bool x : xs) if(!x) return validArgs<Arg1>(0) && validArgs<Arg2, OtherArgs...>(nTrailingDoubles);
85 unsigned nTD = sizeof...(OtherArgs);
86 if(nTD == nTrailingDoubles) return validArgs<Arg1>(0) && validArgs<Arg2>(0);
87 if(nTD == nTrailingDoubles-1) return validArgs<Arg1>(0) && std::is_same<Arg2, double>::value;
88 if(nTD == nTrailingDoubles-2) return std::is_same<Arg1, double>::value && std::is_same<Arg2, double>::value;
89 return false;
90}
91
92template<typename... Args>
94 -> std::enable_if_t<validArgs<Args...>(1), CP::CorrectionCode>
95{
96 std::vector<const xAOD::IParticle*> particles;
97 double* sf[] = { nullptr, handleArg(args, particles)... };
98 return getEfficiencyScaleFactor(particles, *sf[sizeof...(Args)]);
99}
100
101template<typename... Args>
103 -> std::enable_if_t<validArgs<Args...>(2), CP::CorrectionCode>
104{
105 std::vector<const xAOD::IParticle*> particles;
106 double* eff[] = { nullptr, handleArg(args, particles)... };
107 return getEfficiency(particles, *eff[sizeof...(Args)-1], *eff[sizeof...(Args)]);
108}
109
110template<typename BoolOrMap, typename... Args>
112 -> std::enable_if_t<validArgs<Args...>(0), CP::CorrectionCode>
113{
114 std::vector<const xAOD::IParticle*> particles;
115 double* eff[] __attribute__((unused)) = { nullptr, handleArg(args, particles)... };
116 return checkTriggerMatching(matched, particles);
117}
118
119#endif //> !TRIGGERANALYSISINTERFACES_ITRIGGLOBALEFFICIENCYCORRECTIONTOOL_H
#define ASG_TOOL_INTERFACE(CLASSNAME)
static Double_t P(Double_t *tt, Double_t *par)
__attribute__((always_inline)) inline uint16_t TileCalibDrawerBase
#define x
void unused(Args &&...)
Return value from object correction CP tools.
Interface for all CP tools supporting systematic variations.
double * handleArg(const std::vector< P > &arg, std::vector< const xAOD::IParticle * > &particles)
virtual CP::CorrectionCode getEfficiency(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyData, double &efficiencyMc)=0
virtual CP::CorrectionCode countTriggerLegs(const std::string &trigger, std::size_t &numberOfLegs)=0
This utility function provides the number of legs for the specified trigger.
virtual CP::CorrectionCode checkTriggerMatching(bool &matched, const std::vector< const xAOD::IParticle * > &particles)=0
virtual CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const std::vector< const xAOD::IParticle * > &particles, double &efficiencyScaleFactor)=0
These should in principle not be used (except by unit tests), as the CP tools require the EventInfo d...
virtual CP::CorrectionCode checkTriggerMatching(std::unordered_map< std::string, bool > &matched_per_trigger, const std::vector< const xAOD::IParticle * > &particles)=0
double * handleArg(double &arg, std::vector< const xAOD::IParticle * > &)
static std::string toolnameForDefaultScaleFactor()
To be used with the ListOfLegsPerTool property:
virtual CP::CorrectionCode getRelevantTriggers(std::vector< std::string > &triggers)=0
This will fill the 'triggers' argument with the names of the triggers relevant for the current run nu...
virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyScaleFactor)=0
static constexpr bool validArgs(unsigned nTrailingDoubles)
virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector< const xAOD::IParticle * > &particles, double &efficiencyData, double &efficiencyMc)=0
Class providing the definition of the 4-vector interface.