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 
38  template<typename... Args>
39  auto getEfficiencyScaleFactor(Args&... args) -> std::enable_if_t<validArgs<Args...>(1), CP::CorrectionCode>;
40  template<typename... Args>
41  auto getEfficiency(Args&... args) -> std::enable_if_t<validArgs<Args...>(2), CP::CorrectionCode>;
42  template<typename... Args>
43  auto checkTriggerMatching(bool& matched, Args&... args) -> std::enable_if_t<validArgs<Args...>(0), CP::CorrectionCode>;
44 
46  virtual CP::CorrectionCode getRelevantTriggers(std::vector<std::string>& triggers) = 0;
47 
49  virtual CP::CorrectionCode countTriggerLegs(const std::string& trigger, std::size_t& numberOfLegs) = 0;
50 
52  virtual CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyScaleFactor) = 0;
53  virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyData, double& efficiencyMc) = 0;
54 
56  static std::string toolnameForDefaultScaleFactor() { return "RETURN_DEFAULT_SCALE_FACTOR"; }
57 protected:
58  double* handleArg(double& arg, std::vector<const xAOD::IParticle*>&) { return &arg; }
59  template<typename P> double* handleArg(const std::vector<P>& arg, std::vector<const xAOD::IParticle*>& particles)
60  {
61  for(auto ptr : arg) particles.push_back(static_cast<const xAOD::IParticle*>(ptr));
62  return nullptr;
63  }
64 };
65 
66 template<typename Arg>
67 constexpr bool ITrigGlobalEfficiencyCorrectionTool::validArgs(unsigned nTrailingDoubles)
68 {
69  if(std::is_same<double, Arg>::value) return (nTrailingDoubles==1);
70  using P = std::remove_cv_t<Arg>;
71  return std::is_same<P, std::vector<xAOD::Electron*>>::value
72  || std::is_same<P, std::vector<const xAOD::Electron*>>::value
73  || std::is_same<P, std::vector<xAOD::Muon*>>::value
74  || std::is_same<P, std::vector<const xAOD::Muon*>>::value
75  || std::is_same<P, std::vector<xAOD::Photon*>>::value
76  || std::is_same<P, std::vector<const xAOD::Photon*>>::value;
77 }
78 
79 template<typename Arg1, typename Arg2, typename... OtherArgs>
80 constexpr bool ITrigGlobalEfficiencyCorrectionTool::validArgs(unsigned nTrailingDoubles)
81 {
82  bool xs [] = { std::is_same<OtherArgs, double>::value..., true };
83  for(bool x : xs) if(!x) return validArgs<Arg1>(0) && validArgs<Arg2, OtherArgs...>(nTrailingDoubles);
84  unsigned nTD = sizeof...(OtherArgs);
85  if(nTD == nTrailingDoubles) return validArgs<Arg1>(0) && validArgs<Arg2>(0);
86  if(nTD == nTrailingDoubles-1) return validArgs<Arg1>(0) && std::is_same<Arg2, double>::value;
87  if(nTD == nTrailingDoubles-2) return std::is_same<Arg1, double>::value && std::is_same<Arg2, double>::value;
88  return false;
89 }
90 
91 template<typename... Args>
93  -> std::enable_if_t<validArgs<Args...>(1), CP::CorrectionCode>
94 {
95  std::vector<const xAOD::IParticle*> particles;
96  double* sf[] = { nullptr, handleArg(args, particles)... };
97  return getEfficiencyScaleFactor(particles, *sf[sizeof...(Args)]);
98 }
99 
100 template<typename... Args>
102  -> std::enable_if_t<validArgs<Args...>(2), CP::CorrectionCode>
103 {
104  std::vector<const xAOD::IParticle*> particles;
105  double* eff[] = { nullptr, handleArg(args, particles)... };
106  return getEfficiency(particles, *eff[sizeof...(Args)-1], *eff[sizeof...(Args)]);
107 }
108 
109 template<typename... Args>
111  -> std::enable_if_t<validArgs<Args...>(0), CP::CorrectionCode>
112 {
113  std::vector<const xAOD::IParticle*> particles;
114  double* eff[] __attribute__((unused)) = { nullptr, handleArg(args, particles)... };
115  return checkTriggerMatching(matched, particles);
116 }
117 
118 #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...
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:58
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:67
ITrigGlobalEfficiencyCorrectionTool::getEfficiency
virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector< const xAOD::IParticle * > &particles, double &efficiencyData, double &efficiencyMc)=0
Photon.h
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:59
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:56
CorrectionCode.h
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
Electron.h
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80