ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonTruthMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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
58 bool passed_EF = false;
59 bool passed_L1 = false;
60
61 // Find pT cut from chain name
62 double pT_cut = 0.0;
63 std::size_t index_i = chain.find("mu")+2;
64 std::size_t index_f = chain.find("_", index_i+1);
65 if (index_f < chain.length()) {
66 pT_cut = std::stod(chain.substr(index_i, index_f - index_i));
67 }
68 else {
69 pT_cut = std::stod(chain.substr(index_i, chain.length()-1));
70 }
71 pT_cut = pT_cut + 1.0;
72
73 for (const auto truthMu : *truthMuons) {
74
75 // Fill truth histograms
76 double eta = 0.0; // Check eta to split pT into endcap barrel
77 eta = truthMu->eta();
78 if(std::abs(eta) > 2.5) continue; // cut on eta to only fill with muons inside detector geometry
79
80 truthPt = truthMu->pt()/1e3;
81 fill(m_group+"_"+chain,truthPt);
82 if(std::abs(eta) < 1.05){
83 truthBarrelPt = truthMu->pt()/1e3;
84 fill(m_group+"_"+chain, truthBarrelPt);
85 }
86 else{ // 1.05 < |eta| < 2.5
87 truthEndcapPt = truthMu->pt()/1e3;
88 fill(m_group+"_"+chain, truthEndcapPt);
89 }
90 if (pT_cut < truthPt){ // Apply pT cut to eta and phi distributions only
91 truthEta = truthMu->eta();
92 truthPhi = truthMu->phi();
93 truthIntPerBC = eventInfo->actualInteractionsPerCrossing();
94 fill(m_group+"_"+chain, truthEta, truthPhi, truthIntPerBC);
95 }
96
97 // Find match truth muons - EFSA matching for msonly chains, otherwise EFCB matching
98 std::string msonly = "msonly";
99 const xAOD::Muon* efmuon;
100 if(chain.find(msonly) != std::string::npos){ // Find EFCB muons
101 efmuon = m_matchTool->matchEFSA(truthMu, chain, passed_EF);
102 }
103 else{ // Find EFCB muons
104 efmuon = m_matchTool->matchEFCB(truthMu, chain, passed_EF);
105 }
106 const xAOD::MuonRoI* l1muon = m_matchTool->matchL1(truthMu, chain, passed_L1); // Find L1 muons
107
108 if(efmuon && passed_EF){ // Fill matched muon histograms
109 MatchedEFCBtruthPt = truthMu->pt()/1e3;
110 fill(m_group+"_"+chain, MatchedEFCBtruthPt);
111 if(std::abs(eta) < 1.05){
112 MatchedEFCBtruthBarrelPt = truthMu->pt()/1e3;
113 fill(m_group+"_"+chain, MatchedEFCBtruthBarrelPt);
114 }
115 else{ // 1.05 < |eta| < 2.5
116 MatchedEFCBtruthEndcapPt = truthMu->pt()/1e3;
117 fill(m_group+"_"+chain, MatchedEFCBtruthEndcapPt);
118 }
119 if (pT_cut < truthPt){
120 MatchedEFCBtruthEta = truthMu->eta();
121 MatchedEFCBtruthPhi = truthMu->phi();
122 MatchedEFCBtruthIntPerBC = eventInfo->actualInteractionsPerCrossing();
123 fill(m_group+"_"+chain, MatchedEFCBtruthEta, MatchedEFCBtruthPhi, MatchedEFCBtruthIntPerBC);
124 }
125 }
126
127 if(l1muon && passed_L1){ // Fill L1 muon matched histograms
128 MatchedL1truthPt = truthMu->pt()/1e3;
129 fill(m_group+"_"+chain, MatchedL1truthPt);
130 if(std::abs(eta) < 1.05){
131 MatchedL1truthBarrelPt = truthMu->pt()/1e3;
132 fill(m_group+"_"+chain, MatchedL1truthBarrelPt);
133 }
134 else{ // 1.05 < |eta| < 2.5
135 MatchedL1truthEndcapPt = truthMu->pt()/1e3;
136 fill(m_group+"_"+chain, MatchedL1truthEndcapPt);
137 }
138 if (pT_cut < truthPt){
139 MatchedL1truthEta = truthMu->eta();
140 MatchedL1truthPhi = truthMu->phi();
141 MatchedL1truthIntPerBC = eventInfo->actualInteractionsPerCrossing();
142 fill(m_group+"_"+chain, MatchedL1truthEta, MatchedL1truthPhi, MatchedL1truthIntPerBC);
143 }
144 }
145
146 if((l1muon && passed_L1) && !(passed_EF && efmuon)){
147 ATH_MSG_DEBUG("MuonTruthMon: passed L1 but not HLT");
148 }
149
150 if(!(passed_L1 && l1muon) && (passed_EF && efmuon)){
151 ATH_MSG_DEBUG("MuonTruthMon: passed HLT but not L1");
152 }
153
154 passed_L1 = false;
155 passed_EF = false;
156
157 }
158
159 return StatusCode::SUCCESS;
160}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(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)