ATLAS Offline Software
Loading...
Searching...
No Matches
L2muCombMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 for(const TrigCompositeUtils::LinkInfo<xAOD::L2CombinedMuonContainer>& muLinkInfo : featureCont){
32 ATH_CHECK( muLinkInfo.isValid() );
33 const ElementLink<xAOD::L2CombinedMuonContainer> muEL = muLinkInfo.link;
34
35 // get L2SA feature
36 const TrigCompositeUtils::Decision* muDecision = muLinkInfo.source;
37 const std::vector<TrigCompositeUtils::LinkInfo<xAOD::L2StandAloneMuonContainer>> saLinkInfo = TrigCompositeUtils::findLinks<xAOD::L2StandAloneMuonContainer>(muDecision, "feature");
38 if(saLinkInfo.size()>1){
39 ATH_MSG_DEBUG("More than one L2SA linked to L2 comb muon");
40 }
41 ATH_CHECK( saLinkInfo.at(0).isValid());
42 const ElementLink<xAOD::L2StandAloneMuonContainer> saEL = saLinkInfo.at(0).link;
43
44
45
46 // basic EDM variables
47 auto cbPt = Monitored::Scalar<float>(chain+"_Pt",-999.);
48 auto cbEta = Monitored::Scalar<float>(chain+"_Eta",-999.);
49 auto cbPhi = Monitored::Scalar<float>(chain+"_Phi",-999.);
50
51 cbPt = (*muEL)->pt()/1e3 * (*muEL)->charge(); // convert to GeV
52 cbEta = (*muEL)->eta();
53 cbPhi = (*muEL)->phi();
54
55 auto saPt = Monitored::Scalar<float>(chain+"_saPt",-999.);
56 auto saEta = Monitored::Scalar<float>(chain+"_saEta",-999.);
57 auto saPhi = Monitored::Scalar<float>(chain+"_saPhi",-999.);
58
59 saPt = (*saEL)->pt();
60 saEta = (*saEL)->eta();
61 saPhi = (*saEL)->phi();
62
63
64 // get L2SA track
65 const xAOD::L2StandAloneMuon* SATrack = nullptr;
66 float SATrackPt = -999.;
67 if( (*muEL)->muSATrackLink().isValid() ) {
68 SATrack = (*muEL)->muSATrack();
69 SATrackPt = SATrack->pt();
70 }
71
72
73 // CB and Offline matching
74 auto L2SA_success = Monitored::Scalar<bool>(chain+"_L2SA_success",false);
75 auto L2CB_success = Monitored::Scalar<bool>(chain+"_L2CB_success",false);
76 auto L2CBOFFmatching_failure = Monitored::Scalar<bool>(chain+"_L2CBOFFmatching_failure",false);
77 auto L2CB_failure = Monitored::Scalar<bool>(chain+"_L2CB_failure",false);
78 bool off_cb_match = false;
79 bool off_sa_match = false;
80 L2SA_success = std::abs(saPt) > ZERO_LIMIT;
81 L2CB_success = std::abs(cbPt) > ZERO_LIMIT;
82
83
84 // matching to offline
85 const xAOD::Muon* RecMuonCBmatchL2SA = m_matchTool->matchL2SAtoOff(ctx, (*saEL));
86 const xAOD::Muon* RecMuonCBmatchL2CB = m_matchTool->matchL2CBtoOff(ctx, (*muEL));
87 if( RecMuonCBmatchL2SA && L2SA_success) off_sa_match = true;
88 if( RecMuonCBmatchL2CB && L2CB_success) off_cb_match = true;
89
90
91 if(L2CB_success){
92 if(!off_cb_match) L2CBOFFmatching_failure = true;
93 }
94 else if (off_sa_match) L2CB_failure = true;
95
96 if( !L2CB_success ){
97 fill(m_group+"_"+chain, saPt, saEta, saPhi, L2SA_success, L2CB_failure);
98 continue;
99 }
100
101 fill(m_group+"_"+chain, cbPt, cbEta, cbPhi, L2CB_success, L2CBOFFmatching_failure);
102
103
104 // comparison L2muComb vs L2MuonSA
105 auto ptratio_toSA = Monitored::Scalar<float>(chain+"_ptratio_toSA",-999.);
106 auto dEta_toSA = Monitored::Scalar<float>(chain+"_dEta_toSA",-999.);
107 auto dPhi_toSA = Monitored::Scalar<float>(chain+"_dPhi_toSA",-999.);
108 auto dR_toSA = Monitored::Scalar<float>(chain+"_dR_toSA",-999.);
109
110 if( (*muEL)->muSATrackLink().isValid() && std::abs(saPt) > ZERO_LIMIT ){
111 ptratio_toSA = std::abs(cbPt / saPt);
112 dEta_toSA = cbEta - saEta;
113 dPhi_toSA = xAOD::P4Helpers::deltaPhi(cbPhi, saPhi);
114 dR_toSA = sqrt(dEta_toSA*dEta_toSA + dPhi_toSA*dPhi_toSA);
115
116 fill(m_group+"_"+chain, ptratio_toSA, dEta_toSA, dPhi_toSA, dR_toSA);
117 }
118
119
120 // get IDTrack
121 auto trkPt = Monitored::Scalar<float>(chain+"_trkPt",-999.);
122 auto trkEta = Monitored::Scalar<float>(chain+"_trkEta",-999.);
123 auto trkPhi = Monitored::Scalar<float>(chain+"_trkPhi",-999.);
124 auto trkZ0 = Monitored::Scalar<float>(chain+"_trkZ0",-999.);
125 auto trkChi2 = Monitored::Scalar<float>(chain+"_trkChi2",-999.);
126
127 const xAOD::TrackParticle* idtrk = nullptr;
128 if( (*muEL)->idTrackLink().isValid() ) {
129 idtrk = (*muEL)->idTrack();
130 trkPt = idtrk->pt() / 1e3 * idtrk->charge(); // convert to GeV
131 trkEta = idtrk->eta();
132 trkPhi = idtrk->phi0();
133 trkZ0 = idtrk->z0();
134 trkChi2 = idtrk->chiSquared();
135 }
136
137 fill(m_group+"_"+chain, trkPt);
138 if( std::abs(trkPt) > ZERO_LIMIT) fill(m_group+"_"+chain, trkEta, trkPhi, trkZ0, trkChi2);
139
140
141 // comparison L2muComb (IDTrack) vs L2MuonSA
142 auto ptratio_TrktoSA = Monitored::Scalar<float>(chain+"_ptratio_TrktoSA",-999.);
143 auto dEta_TrktoSA = Monitored::Scalar<float>(chain+"_dEta_TrktoSA",-999.);
144 auto dPhi_TrktoSA = Monitored::Scalar<float>(chain+"_dPhi_TrktoSA",-999.);
145 auto dR_TrktoSA = Monitored::Scalar<float>(chain+"_dR_TrktoSA",-999.);
146
147 if( (*muEL)->idTrackLink().isValid() && std::abs(saPt) > ZERO_LIMIT ){
148 ptratio_TrktoSA = std::abs(cbPt / saPt);
149 dEta_TrktoSA = cbEta - saEta;
150 dPhi_TrktoSA = xAOD::P4Helpers::deltaPhi(cbPhi, saPhi);
151 dR_TrktoSA = sqrt(dEta_TrktoSA*dEta_TrktoSA + dPhi_TrktoSA*dPhi_TrktoSA);
152
153 fill(m_group+"_"+chain, ptratio_TrktoSA, dEta_TrktoSA, dPhi_TrktoSA, dR_TrktoSA);
154 }
155
156
157 // Muon Feature error
158 std::vector<int> vec_MF_error;
159 auto MF_error = Monitored::Collection(chain+"_MF_error",vec_MF_error);
160
161 bool error = false;
162 if( SATrack ){
163 if(std::abs(saPt - SATrackPt) > ZERO_LIMIT){
164 vec_MF_error.push_back(2);
165 error = true;
166 }
167 } else{
168 vec_MF_error.push_back(1);
169 error = true;
170 }
171 if(std::abs(saPt) < ZERO_LIMIT){
172 vec_MF_error.push_back(3);
173 error = true;
174 }
175 if(!error) vec_MF_error.push_back(0);
176
177 fill(m_group+"_"+chain, MF_error);
178
179 }
180
181 return StatusCode::SUCCESS;
182}
183
184
185StatusCode L2muCombMon :: fillVariablesPerOfflineMuonPerChain(const EventContext&, const xAOD::Muon* mu, const std::string &chain) const {
186
187 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
188
189 const float ZERO_LIMIT = 0.00001;
190
191 auto offEta = Monitored::Scalar<float>(chain+"_offEta",-999.);
192 auto ptresol = Monitored::Scalar<float>(chain+"_ptresol",-999.);
193 auto dR = Monitored::Scalar<float>(chain+"_dR",-999.);
194
195 float offPt = mu->pt()/1e3;
196 //float offPhi = mu->phi(); //Comment out due to the failure at Tier0 (ATR-26161)
197 offEta = mu->eta();
198
199
200 // get L2CB muon link
201 const TrigCompositeUtils::LinkInfo<xAOD::L2CombinedMuonContainer> muLinkInfo = m_matchTool->searchL2CBLinkInfo(mu, chain);
202 if ( !muLinkInfo.isValid() ) return StatusCode::SUCCESS;
203 const ElementLink<xAOD::L2CombinedMuonContainer> muEL = muLinkInfo.link;
204
205
206 // dR wrt offline
207 auto dRmin = Monitored::Scalar<float>(chain+"_dRmin",1000.);
208 dRmin = xAOD::P4Helpers::deltaR(mu, *muEL, false);
209 fill(m_group+"_"+chain, dRmin);
210 if( ! m_matchTool->isMatchedL2CB(*muEL, mu) ) return StatusCode::SUCCESS; // not matched to L2muComb
211
212
213 // pt resolution
214 float cbPt = (*muEL)->pt()/1e3;
215 if ( std::abs(offPt) > ZERO_LIMIT && std::abs(cbPt) > ZERO_LIMIT ) ptresol = std::abs(cbPt)/std::abs(offPt) - 1.;
216 fill(m_group+"_"+chain, offEta, ptresol);
217
218
219 /* Comment out due to the failure at Tier0 (ATR-26161)
220 // HLT_Roi_L2SAMuon variables
221 const TrigCompositeUtils::Decision* muDecision = muLinkInfo.source;
222 const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> roiLinkInfo = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>(muDecision, "roi");
223 ATH_CHECK( roiLinkInfo.isValid() );
224 const ElementLink<TrigRoiDescriptorCollection> roiEL = roiLinkInfo.link;
225 float SAroiEta = (*roiEL)->eta();
226 float SAroiPhi = (*roiEL)->phi();
227
228 auto roidEta = Monitored::Scalar<float>(chain+"_L2SARoI_dEta",-999.);
229 auto roidPhi = Monitored::Scalar<float>(chain+"_L2SARoI_dPhi",-999.);
230 auto roidR = Monitored::Scalar<float>(chain+"_L2SARoI_dR",-999.);
231
232 roidEta = SAroiEta - offEta;
233 roidPhi = xAOD::P4Helpers::deltaPhi(offPhi, SAroiPhi);
234 roidR = sqrt(roidEta*roidEta + roidPhi*roidPhi);
235
236 fill(m_group+"_"+chain, roidEta, roidPhi, roidR, offEta);
237 */
238
239
240 return StatusCode::SUCCESS;
241}
242
243
244StatusCode L2muCombMon :: fillVariables(const EventContext &ctx) const {
245
246 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
247
249
250 return StatusCode::SUCCESS;
251
252}
253
254
255StatusCode L2muCombMon :: fillVariablesPerOfflineMuon(const EventContext &ctx, const xAOD::Muon* mu) const {
256
257 ATH_CHECK( fillVariablesRatioPlots<xAOD::L2CombinedMuon>(ctx, mu, "L2CB", xAOD::Muon::TrackParticleType::CombinedTrackParticle,
258 [this](const EventContext &ctx, const xAOD::Muon *mu){ return m_matchTool->matchL2CBReadHandle(ctx,mu); }
259 ));
260
261 return StatusCode::SUCCESS;
262
263}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
static Double_t sc
const float 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 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)
StatusCode fillVariableEtaPhi(const EventContext &ctx, 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.
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.
void findLinks(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)