ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonTruthMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
14
15#include "TrigMuonTruthMon.h"
16
17TrigMuonTruthMon :: TrigMuonTruthMon(const std::string& name, ISvcLocator* pSvcLocator )
18 : TrigMuonMonitorAlgorithm(name, pSvcLocator)
19{}
20
21StatusCode TrigMuonTruthMon :: initialize(){
23 ATH_CHECK( m_muonTruthParticlesKey.initialize() );
24 return sc;
25}
26
27StatusCode TrigMuonTruthMon :: fillVariablesPerChain(const EventContext &ctx, const std::string &chain) const {
28 ATH_MSG_DEBUG("Filling muon truth monitoring histograms for " << name() << "...");
29
30 SG::ReadHandle<xAOD::TruthParticleContainer> truthMuons(m_muonTruthParticlesKey, ctx); // Access truth muons
31 SG::ReadHandle<xAOD::EventInfo> eventInfo(m_EventInfoKey, ctx); // Access event info
32
33 if (! truthMuons.isValid() ) {
34 ATH_MSG_ERROR("xAOD::TruthParticleContainer with name "<< m_muonTruthParticlesKey << " is not valid");
35 return StatusCode::FAILURE;
36 }
37
38 auto truthEta = Monitored::Scalar<float>(chain+"_truthEta",-999.);
39 auto truthPhi = Monitored::Scalar<float>(chain+"_truthPhi",-999.);
40 auto truthPt = Monitored::Scalar<float>(chain+"_truthPt",-999.);
41 auto truthEndcapPt = Monitored::Scalar<float>(chain+"_truthEndcapPt",-999.);
42 auto truthBarrelPt = Monitored::Scalar<float>(chain+"_truthBarrelPt",-999.);
43 auto truthIntPerBC = Monitored::Scalar<float>(chain+"_truthIntPerBC",-999.);
44
45 auto MatchedEFCBtruthEta = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthEta",-999.); // Names need to match those in the config.py file
46 auto MatchedEFCBtruthPhi = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthPhi",-999.);
47 auto MatchedEFCBtruthPt = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthPt",-999.);
48 auto MatchedEFCBtruthEndcapPt = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthEndcapPt",-999.);
49 auto MatchedEFCBtruthBarrelPt = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthBarrelPt",-999.);
50 auto MatchedEFCBtruthIntPerBC = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthIntPerBC",-999.);
51 auto MatchedL1truthEta = Monitored::Scalar<float>(chain+"_MatchedL1truthEta",-999.); // Names need to match those in the config.py file
52 auto MatchedL1truthPhi = Monitored::Scalar<float>(chain+"_MatchedL1truthPhi",-999.);
53 auto MatchedL1truthPt = Monitored::Scalar<float>(chain+"_MatchedL1truthPt",-999.);
54 auto MatchedL1truthEndcapPt = Monitored::Scalar<float>(chain+"_MatchedL1truthEndcapPt",-999.);
55 auto MatchedL1truthBarrelPt = Monitored::Scalar<float>(chain+"_MatchedL1truthBarrelPt",-999.);
56 auto MatchedL1truthIntPerBC = Monitored::Scalar<float>(chain+"_MatchedL1truthIntPerBC",-999.);
57 auto MatchedL2CBtruthEta = Monitored::Scalar<float>(chain+"_MatchedL2CBtruthEta",-999.); // Names need to match those in the config.py file
58 auto MatchedL2CBtruthPhi = Monitored::Scalar<float>(chain+"_MatchedL2CBtruthPhi",-999.);
59 auto MatchedL2CBtruthPt = Monitored::Scalar<float>(chain+"_MatchedL2CBtruthPt",-999.);
60 auto MatchedL2CBtruthEndcapPt = Monitored::Scalar<float>(chain+"_MatchedL2CBtruthEndcapPt",-999.);
61 auto MatchedL2CBtruthBarrelPt = Monitored::Scalar<float>(chain+"_MatchedL2CBtruthBarrelPt",-999.);
62 auto MatchedL2CBtruthIntPerBC = Monitored::Scalar<float>(chain+"_MatchedL2CBtruthIntPerBC",-999.);
63
64 bool passed_EF = false;
65 bool passed_L1 = false;
66 bool passed_L2CB = false;
67
68 // Find pT cut from chain name
69 double pT_cut = 0.0;
70 std::size_t index_i = chain.find("mu")+2;
71 std::size_t index_f = chain.find("_", index_i+1);
72 if (index_f < chain.length()) {
73 pT_cut = std::stod(chain.substr(index_i, index_f - index_i));
74 }
75 else {
76 pT_cut = std::stod(chain.substr(index_i, chain.length()-1));
77 }
78 pT_cut = pT_cut + 1.0;
79
80 for (const auto truthMu : *truthMuons) {
81 // Fill truth histograms
82 double eta = truthMu->eta();
83 if(std::abs(eta) > 2.5) continue; // cut on eta to only fill with muons inside detector geometry
84
85 using var_t = Monitored::Scalar<float>;
86 auto fillTruthVars = [&] (var_t& truthEtaVar, var_t& truthPhiVar, var_t& truthPtVar,
87 var_t& truthEndcapPtVar, var_t& truthBarrelPtVar, var_t& truthIntPerBCVar) {
88 truthPtVar = truthMu->pt()/1e3;
89 fill(m_group+"_"+chain,truthPtVar);
90 if(std::abs(eta) < 1.05){
91 truthBarrelPtVar = truthMu->pt()/1e3;
92 fill(m_group+"_"+chain, truthBarrelPtVar);
93 }
94 else{ // 1.05 < |eta| < 2.5
95 truthEndcapPtVar = truthMu->pt()/1e3;
96 fill(m_group+"_"+chain, truthEndcapPtVar);
97 }
98 if (pT_cut < truthPt){ // Apply pT cut to eta and phi distributions only
99 truthEtaVar = truthMu->eta();
100 truthPhiVar = truthMu->phi();
101 truthIntPerBCVar = eventInfo->actualInteractionsPerCrossing();
102 fill(m_group+"_"+chain, truthEtaVar, truthPhiVar, truthIntPerBCVar);
103 }
104 };
105
106 fillTruthVars(truthEta, truthPhi, truthPt,
107 truthEndcapPt, truthBarrelPt, truthIntPerBC);
108
109 // Find match truth muons - EFSA matching for msonly chains, otherwise EFCB matching
110 const xAOD::Muon* efmuon;
111 if(chain.find("msonly") != std::string::npos){ // Find EFCB muons
112 efmuon = m_matchTool->matchEFSA(truthMu, chain, passed_EF);
113 }
114 else{ // Find EFCB muons
115 efmuon = m_matchTool->matchEFCB(truthMu, chain, passed_EF);
116 }
117
118 if(efmuon && passed_EF){
119 fillTruthVars(MatchedEFCBtruthEta, MatchedEFCBtruthPhi, MatchedEFCBtruthPt,
120 MatchedEFCBtruthEndcapPt, MatchedEFCBtruthBarrelPt, MatchedEFCBtruthIntPerBC);
121 }
122
123 // Find L1 muons
124 const xAOD::MuonRoI* l1muon = m_matchTool->matchL1(ctx, truthMu, chain, passed_L1);
125
126 if(l1muon && passed_L1){ // Fill L1 muon matched histograms
127 fillTruthVars(MatchedL1truthEta, MatchedL1truthPhi, MatchedL1truthPt,
128 MatchedL1truthEndcapPt, MatchedL1truthBarrelPt, MatchedL1truthIntPerBC);
129 }
130
131 if((l1muon && passed_L1) && !(passed_EF && efmuon)){
132 ATH_MSG_DEBUG("MuonTruthMon: passed L1 but not HLT");
133 }
134
135 if(!(passed_L1 && l1muon) && (passed_EF && efmuon)){
136 ATH_MSG_DEBUG("MuonTruthMon: passed HLT but not L1");
137 }
138
139 const bool isPh2FastReco = chain.find("newFast") != std::string::npos;
140 bool isFound = false;
141 // PhaseII fast reco CB is not yet implemented, so for now we will use the L2SA matching for these chains
142 if(chain.find("msonly") != std::string::npos || isPh2FastReco){ // Find L2SA muons
143 isFound = isPh2FastReco
144 ? m_matchTool->matchFastRecoSA(truthMu, chain, passed_L2CB) != nullptr
145 : m_matchTool->matchL2SA(truthMu, chain, passed_L2CB) != nullptr;
146
147 } else{ // Find EFCB muons
148 isFound = m_matchTool->matchL2CB(truthMu, chain, passed_L2CB) != nullptr;
149 }
150 ATH_MSG_VERBOSE("L2CB matching: passed: " << passed_L2CB << ", found:" << isFound);
151
152 if (isFound && passed_L2CB) {
153 fillTruthVars(MatchedL2CBtruthEta, MatchedL2CBtruthPhi, MatchedL2CBtruthPt,
154 MatchedL2CBtruthEndcapPt, MatchedL2CBtruthBarrelPt, MatchedL2CBtruthIntPerBC);
155 }
156
157 passed_L1 = false;
158 passed_EF = false;
159 passed_L2CB = false;
160
161 }
162
163 return StatusCode::SUCCESS;
164}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Key for retrieving EventInfo from StoreGate.
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Gaudi::Property< std::string > m_group
Name of monitored group.
TrigMuonMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
initialize
ToolHandle< MuonMatchingTool > m_matchTool
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_muonTruthParticlesKey
Muon_v1 Muon
Reference the current persistent version:
MuonRoI_v1 MuonRoI
Definition MuonRoI.h:15
void fill(H5::Group &out_file, size_t iterations)