ATLAS Offline Software
MuonSFTestHelper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 #ifndef XAOD_STANDALONE
5 #ifndef MUONEFFICIENCYCORRECTION_MUONSFTESTHELPER_H
6 #define MUONEFFICIENCYCORRECTION_MUONSFTESTHELPER_H
7 
8 // EDM include(s):
9 #include "xAODMuon/Muon.h"
10 
11 // Tool Includes
15 
19 
20 #include <GaudiKernel/ToolHandle.h>
21 
22 //General includes
23 #include <memory>
24 #include <map>
25 #include <TTree.h>
26 #include <TH1.h>
27 #include <TFile.h>
28 //Helper class to test the Muon efficiency SFs plus their systematics
29 namespace TestMuonSF {
30  //####################################################
31  // Helper class to write ntuples to test the #
32  // MuonTriggerScaleFactors #
33  //####################################################
34 
36  public:
38  const ToolHandle<CP::IMuonTriggerScaleFactors>& Handle,
39  const std::string& muonContainer,
40  const std::string& Trigger);
41  virtual ~TriggerSFBranches() = default;
42 
43  bool fill(const EventContext& ctx) override final;
44  bool init() override final;
45 
46  private:
47  CP::CorrectionCode getSF(const xAOD::MuonContainer* muons,
48  MuonVal::ScalarBranch<double> &Var,
49  const CP::SystematicVariation &syst);
50 
51  SG::ReadHandleKey<xAOD::MuonContainer> m_key{};
52 
53  ToolHandle<CP::IMuonTriggerScaleFactors> m_handle{};
54  std::string m_trigger{};
60  };
61 
62 
64  public:
65  virtual void setMuon(const xAOD::Muon& muon) = 0;
66  };
67  //###################################################################
68  // Helper class to write the scale-factor ntuples to test the #
69  // MuonReconstruction/ Isolation/ TTVA scalefactors #
70  //###################################################################
72  public:
74  const ToolHandle<CP::IMuonEfficiencyScaleFactors> &handle,
75  const std::string& rel_name = "");
76 
77  virtual ~MuonSFBranches() = default;
78 
79 
80  void setMuon(const xAOD::Muon& muon) override final;
81 
82  bool fill(const EventContext& ctx) override final;
83 
84  bool init() override final;
85 
87  static std::string systName(const CP::SystematicSet& set) {
88  return set.name().empty() ? std::string("") : std::string("__") + set.name();
89  }
90 
91  private:
92  ToolHandle<CP::IMuonEfficiencyScaleFactors> m_handle{};
93  bool m_uncorrelate_sys{false};
94 
97  struct SFSet {
98  SFSet(const CP::SystematicSet& _cpSet,
99  MuonSFBranches& _parent):
100  cpSet{_cpSet}, parent{_parent}{}
102  bool init() {
103  return scaleFactor.init() && mcEff.init() && dataEff.init();
104  }
106  bool fill(const EventContext& ctx) {
107  return scaleFactor.fill(ctx) && mcEff.fill(ctx) && dataEff.fill(ctx);
108  }
117  };
118 
120 
121  std::vector<std::unique_ptr<SFSet>> m_SFs{};
122 
123  };
124  //#######################################################
125  // Helper class for writing #
126  // scale-factor replicas to the test-ntuples #
127  //#######################################################
128 
130  public:
132  const ToolHandle<CP::IMuonEfficiencyScaleFactors> &handle,
133  const std::string& rel_name = "");
134 
135  void setMuon(const xAOD::Muon& muon) override final;
136 
137  bool init() override;
138 
139  bool fill(const EventContext& ctx) override;
140 
141  private:
142  ToolHandle<CP::IMuonEfficiencyScaleFactors> m_handle{};
143 
144  std::map<CP::SystematicSet, std::shared_ptr<MuonVal::VectorBranch<float>>> m_SFs{};
145  };
146 }
147 #endif
148 #endif
muonContainer
xAOD::MuonContainer * muonContainer
Definition: TrigGlobEffCorrValidation.cxx:188
TestMuonSF::TriggerSFBranches::m_sys_up_SF
MuonVal::ScalarBranch< double > m_sys_up_SF
Definition: MuonSFTestHelper.h:58
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
MuonVal::ScalarBranch::fill
bool fill(const EventContext &ctx) override
The fill method checks if enough information is provided such that the branch is cleared from the inf...
TestMuonSF::MuonSFBranches::SFSet::mcEff
MuonVal::ScalarBranch< float > mcEff
Definition: MuonSFTestHelper.h:115
TestMuonSF::TriggerSFBranches::TriggerSFBranches
TriggerSFBranches(MuonVal::MuonTesterTree &tree, const ToolHandle< CP::IMuonTriggerScaleFactors > &Handle, const std::string &muonContainer, const std::string &Trigger)
Definition: MuonSFTestHelper.cxx:29
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
TestMuonSF::TriggerSFBranches::~TriggerSFBranches
virtual ~TriggerSFBranches()=default
TestMuonSF::MuonReplicaBranches::fill
bool fill(const EventContext &ctx) override
The fill method checks if enough information is provided such that the branch is cleared from the inf...
Definition: MuonSFTestHelper.cxx:208
xAOD::MuonContainer
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonContainer.h:14
TestMuonSF::MuonReplicaBranches
Definition: MuonSFTestHelper.h:129
Muon.h
TestMuonSF::MuonSFBranches::m_handle
ToolHandle< CP::IMuonEfficiencyScaleFactors > m_handle
Definition: MuonSFTestHelper.h:92
TestMuonSF::MuonSFBranches::m_uncorrelate_sys
bool m_uncorrelate_sys
Definition: MuonSFTestHelper.h:93
MuonVal::MuonTesterBranch
Definition: MuonTesterBranch.h:21
TestMuonSF::TriggerSFBranches::fill
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
Definition: MuonSFTestHelper.cxx:48
TestMuonSF::MuonReplicaBranches::setMuon
void setMuon(const xAOD::Muon &muon) override final
Definition: MuonSFTestHelper.cxx:218
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
TestMuonSF::MuonSFBranches::SFSet
Helper struct to store scale factor, data efficiency + mc efficiency for each systematic variation.
Definition: MuonSFTestHelper.h:97
TestMuonSF
Definition: MuonSFTestHelper.h:29
TestMuonSF::MuonSFBranches::SFSet::init
bool init()
Initialization of the branches.
Definition: MuonSFTestHelper.h:102
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
TestMuonSF::MuonSFBranches::SFSet::cpSet
const CP::SystematicSet cpSet
Systematic set.
Definition: MuonSFTestHelper.h:110
TestMuonSF::MuonEffiBranch
Definition: MuonSFTestHelper.h:63
MuonTesterTree.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
TestMuonSF::MuonSFBranches::SFSet::SFSet
SFSet(const CP::SystematicSet &_cpSet, MuonSFBranches &_parent)
Definition: MuonSFTestHelper.h:98
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
TestMuonSF::MuonReplicaBranches::init
bool init() override
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
Definition: MuonSFTestHelper.cxx:200
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MuonVal::MuonTesterBranch::tree
TTree * tree() override final
Returns the underlying TTree object.
Definition: MuonTesterBranch.cxx:53
TestMuonSF::TriggerSFBranches::m_handle
ToolHandle< CP::IMuonTriggerScaleFactors > m_handle
Definition: MuonSFTestHelper.h:53
IMuonSelectionTool.h
TestMuonSF::MuonSFBranches
Definition: MuonSFTestHelper.h:71
TestMuonSF::TriggerSFBranches::m_trigger
std::string m_trigger
Definition: MuonSFTestHelper.h:54
IMuonEfficiencyScaleFactors.h
TestMuonSF::MuonReplicaBranches::m_handle
ToolHandle< CP::IMuonEfficiencyScaleFactors > m_handle
Definition: MuonSFTestHelper.h:142
MuonVal::MuonTesterTree
Definition: MuonTesterTree.h:30
TestMuonSF::TriggerSFBranches::m_nominal_SF
MuonVal::ScalarBranch< double > m_nominal_SF
Definition: MuonSFTestHelper.h:55
TestMuonSF::TriggerSFBranches::m_sys_down_SF
MuonVal::ScalarBranch< double > m_sys_down_SF
Definition: MuonSFTestHelper.h:59
TestMuonSF::MuonSFBranches::~MuonSFBranches
virtual ~MuonSFBranches()=default
TestMuonSF::TriggerSFBranches
Definition: MuonSFTestHelper.h:35
TestMuonSF::MuonSFBranches::fill
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
Definition: MuonSFTestHelper.cxx:112
IMuonTriggerScaleFactors.h
TestMuonSF::TriggerSFBranches::m_stat_up_SF
MuonVal::ScalarBranch< double > m_stat_up_SF
Definition: MuonSFTestHelper.h:56
MuonVal::MuonTesterBranch::name
std::string name() const override final
Returns the name of the branch.
Definition: MuonTesterBranch.cxx:51
ScalarBranch.h
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
TestMuonSF::MuonSFBranches::fillSystematic
CP::CorrectionCode fillSystematic(const xAOD::Muon &muon, SFSet &set)
Definition: MuonSFTestHelper.cxx:154
MuonVal::ScalarBranch::init
bool init() override
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
MuonVal
Class to store array like branches into the n-tuples.
Definition: MuonTPMetaDataAlg.cxx:25
TestMuonSF::MuonEffiBranch::setMuon
virtual void setMuon(const xAOD::Muon &muon)=0
MuonVal::ScalarBranch< double >
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
TestMuonSF::MuonSFBranches::SFSet::scaleFactor
MuonVal::ScalarBranch< float > scaleFactor
Actual branches storing scaleFactor & mcEff & dataEff.
Definition: MuonSFTestHelper.h:114
TestMuonSF::MuonSFBranches::SFSet::dataEff
MuonVal::ScalarBranch< float > dataEff
Definition: MuonSFTestHelper.h:116
MuonTesterBranch.h
TestMuonSF::MuonSFBranches::setMuon
void setMuon(const xAOD::Muon &muon) override final
Definition: MuonSFTestHelper.cxx:120
TestMuonSF::TriggerSFBranches::init
bool init() override final
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
Definition: MuonSFTestHelper.cxx:38
TestMuonSF::MuonSFBranches::MuonSFBranches
MuonSFBranches(MuonVal::MuonTesterTree &tree, const ToolHandle< CP::IMuonEfficiencyScaleFactors > &handle, const std::string &rel_name="")
Definition: MuonSFTestHelper.cxx:90
TestMuonSF::MuonSFBranches::m_SFs
std::vector< std::unique_ptr< SFSet > > m_SFs
Definition: MuonSFTestHelper.h:121
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
TestMuonSF::TriggerSFBranches::m_stat_down_SF
MuonVal::ScalarBranch< double > m_stat_down_SF
Definition: MuonSFTestHelper.h:57
Prompt::Def::Var
Var
Definition: VarHolder.h:57
TestMuonSF::MuonSFBranches::SFSet::parent
MuonSFBranches & parent
Parent from which the TTree pointer & name is retrieved.
Definition: MuonSFTestHelper.h:112
TestMuonSF::MuonSFBranches::SFSet::fill
bool fill(const EventContext &ctx)
check that all branches are set properly
Definition: MuonSFTestHelper.h:106
TestMuonSF::TriggerSFBranches::getSF
CP::CorrectionCode getSF(const xAOD::MuonContainer *muons, MuonVal::ScalarBranch< double > &Var, const CP::SystematicVariation &syst)
Definition: MuonSFTestHelper.cxx:68
TestMuonSF::TriggerSFBranches::m_key
SG::ReadHandleKey< xAOD::MuonContainer > m_key
Definition: MuonSFTestHelper.h:51
TestMuonSF::MuonReplicaBranches::m_SFs
std::map< CP::SystematicSet, std::shared_ptr< MuonVal::VectorBranch< float > > > m_SFs
Definition: MuonSFTestHelper.h:144
TestMuonSF::MuonSFBranches::init
bool init() override final
The init method checks whether the branch name has already registered to the MuonTree and tries then ...
Definition: MuonSFTestHelper.cxx:97
TestMuonSF::MuonReplicaBranches::MuonReplicaBranches
MuonReplicaBranches(MuonVal::MuonTesterTree &tree, const ToolHandle< CP::IMuonEfficiencyScaleFactors > &handle, const std::string &rel_name="")
Definition: MuonSFTestHelper.cxx:193
TestMuonSF::MuonSFBranches::systName
static std::string systName(const CP::SystematicSet &set)
Dummy helper function that encodes the systname set.
Definition: MuonSFTestHelper.h:87