ATLAS Offline Software
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 {
22 public:
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"; }
58 protected:
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 
67 template<typename Arg>
68 constexpr 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 
80 template<typename Arg1, typename Arg2, typename... OtherArgs>
81 constexpr 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 
92 template<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 
101 template<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 
110 template<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
ITrigGlobalEfficiencyCorrectionTool::getEfficiencyScaleFactor
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...
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
ITrigGlobalEfficiencyCorrectionTool::countTriggerLegs
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.
Muon.h
DMTest::P
P_v1 P
Definition: P.h:23
ITrigGlobalEfficiencyCorrectionTool::handleArg
double * handleArg(double &arg, std::vector< const xAOD::IParticle * > &)
Definition: ITrigGlobalEfficiencyCorrectionTool.h:59
ITrigGlobalEfficiencyCorrectionTool
Definition: ITrigGlobalEfficiencyCorrectionTool.h:21
athena.value
value
Definition: athena.py:124
python.TrigTLAMonitorAlgorithm.triggers
triggers
Definition: TrigTLAMonitorAlgorithm.py:196
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
Args
Definition: test_lwtnn_fastgraph.cxx:12
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
x
#define x
ISystematicsTool.h
ITrigGlobalEfficiencyCorrectionTool::validArgs
static constexpr bool validArgs(unsigned nTrailingDoubles)
Definition: ITrigGlobalEfficiencyCorrectionTool.h:68
ITrigGlobalEfficiencyCorrectionTool::getEfficiency
virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector< const xAOD::IParticle * > &particles, double &efficiencyData, double &efficiencyMc)=0
Photon.h
ITrigGlobalEfficiencyCorrectionTool::checkTriggerMatching
virtual CP::CorrectionCode checkTriggerMatching(std::unordered_map< std::string, bool > &matched_per_trigger, const std::vector< const xAOD::IParticle * > &particles)=0
ASG_TOOL_INTERFACE
#define ASG_TOOL_INTERFACE(CLASSNAME)
Definition: AsgToolMacros.h:40
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
ITrigGlobalEfficiencyCorrectionTool::handleArg
double * handleArg(const std::vector< P > &arg, std::vector< const xAOD::IParticle * > &particles)
Definition: ITrigGlobalEfficiencyCorrectionTool.h:60
CP::ISystematicsTool
Interface for all CP tools supporting systematic variations.
Definition: ISystematicsTool.h:32
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
unused
void unused(Args &&...)
Definition: VP1ExpertSettings.cxx:39
ITrigGlobalEfficiencyCorrectionTool::getEfficiencyScaleFactor
virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyScaleFactor)=0
__attribute__
__attribute__((always_inline)) inline uint16_t TileCalibDrawerBase
Definition: TileCalibDrawerBase.h:190
ITrigGlobalEfficiencyCorrectionTool::checkTriggerMatching
virtual CP::CorrectionCode checkTriggerMatching(bool &matched, const std::vector< const xAOD::IParticle * > &particles)=0
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
ITrigGlobalEfficiencyCorrectionTool::getEfficiency
virtual CP::CorrectionCode getEfficiency(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyData, double &efficiencyMc)=0
ITrigGlobalEfficiencyCorrectionTool::getRelevantTriggers
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...
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
ITrigGlobalEfficiencyCorrectionTool::toolnameForDefaultScaleFactor
static std::string toolnameForDefaultScaleFactor()
To be used with the ListOfLegsPerTool property:
Definition: ITrigGlobalEfficiencyCorrectionTool.h:57
CorrectionCode.h
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
Electron.h