ATLAS Offline Software
Loading...
Searching...
No Matches
L2muCombMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "L2muCombMon.h"
6
8#include "MuonMatchingTool.h"
10
11L2muCombMon :: L2muCombMon(const std::string& name, ISvcLocator* pSvcLocator )
12 : TrigMuonMonitorAlgorithm(name, pSvcLocator)
13{}
14
15
16StatusCode L2muCombMon :: initialize(){
18 ATH_CHECK( m_L2muCombContainerKey.initialize() );
19 return sc;
20}
21
22
23StatusCode L2muCombMon :: fillVariablesPerChain(const EventContext &ctx, const std::string &chain) const {
24
25 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
26
27 const float ZERO_LIMIT = 0.00001;
28
29
30 std::vector< TrigCompositeUtils::LinkInfo<xAOD::L2CombinedMuonContainer> > featureCont = getTrigDecisionTool()->features<xAOD::L2CombinedMuonContainer>( chain, TrigDefs::includeFailedDecisions );
31 const std::string featureStr{"feature"};
32 for(const TrigCompositeUtils::LinkInfo<xAOD::L2CombinedMuonContainer>& muLinkInfo : featureCont){
33 ATH_CHECK( muLinkInfo.isValid() );
34 const ElementLink<xAOD::L2CombinedMuonContainer> muEL = muLinkInfo.link;
35
36 // get L2SA feature
37 const TrigCompositeUtils::Decision* muDecision = muLinkInfo.source;
38 const std::vector<TrigCompositeUtils::LinkInfo<xAOD::L2StandAloneMuonContainer>> saLinkInfo = TrigCompositeUtils::findLinks<xAOD::L2StandAloneMuonContainer>(ctx, muDecision, featureStr);
39 if(saLinkInfo.size()>1){
40 ATH_MSG_DEBUG("More than one L2SA linked to L2 comb muon");
41 }
42 ATH_CHECK( saLinkInfo.at(0).isValid());
43 const ElementLink<xAOD::L2StandAloneMuonContainer> saEL = saLinkInfo.at(0).link;
44
45
46
47 // basic EDM variables
48 auto cbPt = Monitored::Scalar<float>(chain+"_Pt",-999.);
49 auto cbEta = Monitored::Scalar<float>(chain+"_Eta",-999.);
50 auto cbPhi = Monitored::Scalar<float>(chain+"_Phi",-999.);
51
52 cbPt = (*muEL)->pt()/1e3 * (*muEL)->charge(); // convert to GeV
53 cbEta = (*muEL)->eta();
54 cbPhi = (*muEL)->phi();
55
56 auto saPt = Monitored::Scalar<float>(chain+"_saPt",-999.);
57 auto saEta = Monitored::Scalar<float>(chain+"_saEta",-999.);
58 auto saPhi = Monitored::Scalar<float>(chain+"_saPhi",-999.);
59
60 saPt = (*saEL)->pt();
61 saEta = (*saEL)->eta();
62 saPhi = (*saEL)->phi();
63
64
65 // get L2SA track
66 const xAOD::L2StandAloneMuon* SATrack = nullptr;
67 float SATrackPt = -999.;
68 if( (*muEL)->muSATrackLink().isValid() ) {
69 SATrack = (*muEL)->muSATrack();
70 SATrackPt = SATrack->pt();
71 }
72
73
74 // CB and Offline matching
75 auto L2SA_success = Monitored::Scalar<bool>(chain+"_L2SA_success",false);
76 auto L2CB_success = Monitored::Scalar<bool>(chain+"_L2CB_success",false);
77 auto L2CBOFFmatching_failure = Monitored::Scalar<bool>(chain+"_L2CBOFFmatching_failure",false);
78 auto L2CB_failure = Monitored::Scalar<bool>(chain+"_L2CB_failure",false);
79 bool off_cb_match = false;
80 bool off_sa_match = false;
81 L2SA_success = std::abs(saPt) > ZERO_LIMIT;
82 L2CB_success = std::abs(cbPt) > ZERO_LIMIT;
83
84
85 // matching to offline
86 const xAOD::Muon* RecMuonCBmatchL2SA = m_matchTool->matchL2SAtoOff(ctx, (*saEL));
87 const xAOD::Muon* RecMuonCBmatchL2CB = m_matchTool->matchL2CBtoOff(ctx, (*muEL));
88 if( RecMuonCBmatchL2SA && L2SA_success) off_sa_match = true;
89 if( RecMuonCBmatchL2CB && L2CB_success) off_cb_match = true;
90
91
92 if(L2CB_success){
93 if(!off_cb_match) L2CBOFFmatching_failure = true;
94 }
95 else if (off_sa_match) L2CB_failure = true;
96
97 if( !L2CB_success ){
98 fill(m_group+"_"+chain, saPt, saEta, saPhi, L2SA_success, L2CB_failure);
99 continue;
100 }
101
102 fill(m_group+"_"+chain, cbPt, cbEta, cbPhi, L2CB_success, L2CBOFFmatching_failure);
103
104
105 // comparison L2muComb vs L2MuonSA
106 auto ptratio_toSA = Monitored::Scalar<float>(chain+"_ptratio_toSA",-999.);
107 auto dEta_toSA = Monitored::Scalar<float>(chain+"_dEta_toSA",-999.);
108 auto dPhi_toSA = Monitored::Scalar<float>(chain+"_dPhi_toSA",-999.);
109 auto dR_toSA = Monitored::Scalar<float>(chain+"_dR_toSA",-999.);
110
111 if( (*muEL)->muSATrackLink().isValid() && std::abs(saPt) > ZERO_LIMIT ){
112 ptratio_toSA = std::abs(cbPt / saPt);
113 dEta_toSA = cbEta - saEta;
114 dPhi_toSA = xAOD::P4Helpers::deltaPhi(cbPhi, saPhi);
115 dR_toSA = sqrt(dEta_toSA*dEta_toSA + dPhi_toSA*dPhi_toSA);
116
117 fill(m_group+"_"+chain, ptratio_toSA, dEta_toSA, dPhi_toSA, dR_toSA);
118 }
119
120
121 // get IDTrack
122 auto trkPt = Monitored::Scalar<float>(chain+"_trkPt",-999.);
123 auto trkEta = Monitored::Scalar<float>(chain+"_trkEta",-999.);
124 auto trkPhi = Monitored::Scalar<float>(chain+"_trkPhi",-999.);
125 auto trkZ0 = Monitored::Scalar<float>(chain+"_trkZ0",-999.);
126 auto trkChi2 = Monitored::Scalar<float>(chain+"_trkChi2",-999.);
127
128 const xAOD::TrackParticle* idtrk = nullptr;
129 if( (*muEL)->idTrackLink().isValid() ) {
130 idtrk = (*muEL)->idTrack();
131 trkPt = idtrk->pt() / 1e3 * idtrk->charge(); // convert to GeV
132 trkEta = idtrk->eta();
133 trkPhi = idtrk->phi0();
134 trkZ0 = idtrk->z0();
135 trkChi2 = idtrk->chiSquared();
136 }
137
138 fill(m_group+"_"+chain, trkPt);
139 if( std::abs(trkPt) > ZERO_LIMIT) fill(m_group+"_"+chain, trkEta, trkPhi, trkZ0, trkChi2);
140
141
142 // comparison L2muComb (IDTrack) vs L2MuonSA
143 auto ptratio_TrktoSA = Monitored::Scalar<float>(chain+"_ptratio_TrktoSA",-999.);
144 auto dEta_TrktoSA = Monitored::Scalar<float>(chain+"_dEta_TrktoSA",-999.);
145 auto dPhi_TrktoSA = Monitored::Scalar<float>(chain+"_dPhi_TrktoSA",-999.);
146 auto dR_TrktoSA = Monitored::Scalar<float>(chain+"_dR_TrktoSA",-999.);
147
148 if( (*muEL)->idTrackLink().isValid() && std::abs(saPt) > ZERO_LIMIT ){
149 ptratio_TrktoSA = std::abs(cbPt / saPt);
150 dEta_TrktoSA = cbEta - saEta;
151 dPhi_TrktoSA = xAOD::P4Helpers::deltaPhi(cbPhi, saPhi);
152 dR_TrktoSA = sqrt(dEta_TrktoSA*dEta_TrktoSA + dPhi_TrktoSA*dPhi_TrktoSA);
153
154 fill(m_group+"_"+chain, ptratio_TrktoSA, dEta_TrktoSA, dPhi_TrktoSA, dR_TrktoSA);
155 }
156
157
158 // Muon Feature error
159 std::vector<int> vec_MF_error;
160 auto MF_error = Monitored::Collection(chain+"_MF_error",vec_MF_error);
161
162 bool error = false;
163 if( SATrack ){
164 if(std::abs(saPt - SATrackPt) > ZERO_LIMIT){
165 vec_MF_error.push_back(2);
166 error = true;
167 }
168 } else{
169 vec_MF_error.push_back(1);
170 error = true;
171 }
172 if(std::abs(saPt) < ZERO_LIMIT){
173 vec_MF_error.push_back(3);
174 error = true;
175 }
176 if(!error) vec_MF_error.push_back(0);
177
178 fill(m_group+"_"+chain, MF_error);
179
180 }
181
182 return StatusCode::SUCCESS;
183}
184
185
186StatusCode L2muCombMon :: fillVariablesPerOfflineMuonPerChain(const EventContext&, const xAOD::Muon* mu, const std::string &chain) const {
187
188 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
189
190 const float ZERO_LIMIT = 0.00001;
191
192 auto offEta = Monitored::Scalar<float>(chain+"_offEta",-999.);
193 auto ptresol = Monitored::Scalar<float>(chain+"_ptresol",-999.);
194 auto dR = Monitored::Scalar<float>(chain+"_dR",-999.);
195
196 float offPt = mu->pt()/1e3;
197 //float offPhi = mu->phi(); //Comment out due to the failure at Tier0 (ATR-26161)
198 offEta = mu->eta();
199
200
201 // get L2CB muon link
202 const TrigCompositeUtils::LinkInfo<xAOD::L2CombinedMuonContainer> muLinkInfo = m_matchTool->searchL2CBLinkInfo(mu, chain);
203 if ( !muLinkInfo.isValid() ) return StatusCode::SUCCESS;
204 const ElementLink<xAOD::L2CombinedMuonContainer> muEL = muLinkInfo.link;
205
206
207 // dR wrt offline
208 auto dRmin = Monitored::Scalar<float>(chain+"_dRmin",1000.);
209 dRmin = xAOD::P4Helpers::deltaR(mu, *muEL, false);
210 fill(m_group+"_"+chain, dRmin);
211 if( ! m_matchTool->isMatchedL2CB(*muEL, mu) ) return StatusCode::SUCCESS; // not matched to L2muComb
212
213
214 // pt resolution
215 float cbPt = (*muEL)->pt()/1e3;
216 if ( std::abs(offPt) > ZERO_LIMIT && std::abs(cbPt) > ZERO_LIMIT ) ptresol = std::abs(cbPt)/std::abs(offPt) - 1.;
217 fill(m_group+"_"+chain, offEta, ptresol);
218
219
220 /* Comment out due to the failure at Tier0 (ATR-26161)
221 // HLT_Roi_L2SAMuon variables
222 const TrigCompositeUtils::Decision* muDecision = muLinkInfo.source;
223 const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> roiLinkInfo = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>(ctx, muDecision, "roi");
224 ATH_CHECK( roiLinkInfo.isValid() );
225 const ElementLink<TrigRoiDescriptorCollection> roiEL = roiLinkInfo.link;
226 float SAroiEta = (*roiEL)->eta();
227 float SAroiPhi = (*roiEL)->phi();
228
229 auto roidEta = Monitored::Scalar<float>(chain+"_L2SARoI_dEta",-999.);
230 auto roidPhi = Monitored::Scalar<float>(chain+"_L2SARoI_dPhi",-999.);
231 auto roidR = Monitored::Scalar<float>(chain+"_L2SARoI_dR",-999.);
232
233 roidEta = SAroiEta - offEta;
234 roidPhi = xAOD::P4Helpers::deltaPhi(offPhi, SAroiPhi);
235 roidR = sqrt(roidEta*roidEta + roidPhi*roidPhi);
236
237 fill(m_group+"_"+chain, roidEta, roidPhi, roidR, offEta);
238 */
239
240
241 return StatusCode::SUCCESS;
242}
243
244
245StatusCode L2muCombMon :: fillVariables(const EventContext &ctx) const {
246
247 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
248
250
251 return StatusCode::SUCCESS;
252
253}
254
255
256StatusCode L2muCombMon :: fillVariablesPerOfflineMuon(const EventContext &ctx, const xAOD::Muon* mu) const {
257
258 ATH_CHECK( fillVariablesRatioPlots<xAOD::L2CombinedMuon>(ctx, mu, "L2CB", xAOD::Muon::TrackParticleType::CombinedTrackParticle,
259 [this](const EventContext &c, const xAOD::Muon *m){ return m_matchTool->matchL2CBReadHandle(c,m); }
260 ));
261
262 return StatusCode::SUCCESS;
263
264}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
static Double_t sc
static const double ZERO_LIMIT
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
SG::ReadHandleKey< xAOD::L2CombinedMuonContainer > m_L2muCombContainerKey
Definition L2muCombMon.h:28
Declare a monitored scalar variable.
StatusCode fillVariableEtaPhi(const EventContext &ctx, const SG::ReadHandleKey< DataVector< T > > &ReadHandleKey, std::string &&trigstep, std::tuple< bool, double, double >(*PosFunc)(const T *)=&TrigMuonMonitorAlgorithm::defaultPosFunc< T >) const
Function that fills variables of etaphi2D plots.
StatusCode fillVariablesRatioPlots(const EventContext &ctx, const xAOD::Muon *mu, std::string &&trigstep, xAOD::Muon::TrackParticleType type, FUNCT matchFunc) const
Function that fills variables of ratio plots.
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
virtual double pt() const
The transverse momentum ( ) of the particle.
float z0() const
Returns the parameter.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
float chiSquared() const
Returns the of the overall track fit.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
float charge() const
Returns the charge.
float phi0() const
Returns the parameter, which has range to .
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
xAOD::TrigComposite Decision
void findLinks(const EventContext &ctx, const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
static const unsigned int includeFailedDecisions
Run3 synonym of alsoDeactivateTEs.
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
L2CombinedMuonContainer_v1 L2CombinedMuonContainer
Define the latest version of the muon CB container.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
L2StandAloneMuon_v2 L2StandAloneMuon
Define the latest version of the muon SA class.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22
ElementLink< T > link
Link to the feature.
Definition LinkInfo.h:55
void fill(H5::Group &out_file, size_t iterations)