ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEfficiencyMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "MuonMatchingTool.h"
8#include <algorithm>
9
10TrigMuonEfficiencyMon :: TrigMuonEfficiencyMon(const std::string& name, ISvcLocator* pSvcLocator )
11 : TrigMuonMonitorAlgorithm(name, pSvcLocator)
12{}
13
14
15StatusCode TrigMuonEfficiencyMon :: initialize(){
17
18 // Pairing HLT and L1
19 unsigned int nchains = m_monitored_chains.size();
20 if(nchains!=m_monitored_chains_L1.size() || nchains!=m_monitored_chains_threshold.size()){
21 ATH_MSG_ERROR("Configuration seems to be wrong. The size of \"L1Seeds\" and \"Thresholds\" should be same as \"MonitoredChainds\".");
22 return StatusCode::FAILURE;
23 } else {
24 for(unsigned int ichain=0; ichain<nchains; ++ichain){
27 }
28 }
29 return sc;
30}
31
32
33bool TrigMuonEfficiencyMon :: selectEvents() const {
34 if(m_event_trigger.empty()) return true;
36}
37
38
39
40StatusCode TrigMuonEfficiencyMon :: selectMuons(const EventContext& ctx, SG::ReadHandle<xAOD::MuonContainer> &muons, std::vector<const xAOD::Muon*> &probes) const {
41
42 if(m_eff_method.value().find("TagAndProbe")!=std::string::npos){
43 return selectMuonsTagAndProbe(ctx, muons, probes);
44 } else {
45 for (const xAOD::Muon* mu : *muons) {
46 if( static_cast<int>(mu->muonType())<=m_muontype &&
47 mu->author()==xAOD::Muon::Author::MuidCo &&
48 mu->quality()==xAOD::Muon::Quality::Medium ){
49 probes.push_back(mu);
50 }
51 }
52 }
53 return StatusCode::SUCCESS;
54}
55
56
57StatusCode TrigMuonEfficiencyMon :: fillVariablesPerOfflineMuonPerChain(const EventContext& ctx, const xAOD::Muon* mu, const std::string &chain) const {
58
59
60 auto muPt = Monitored::Scalar<double>(m_group+"_muPt");
61 auto muEta = Monitored::Scalar<float>(m_group+"_muEta");
62 auto muPhi = Monitored::Scalar<float>(m_group+"_muPhi");
63 auto averageMu = Monitored::Scalar<float>(m_group+"_averageMu");
64
65 muPt = mu->pt()/1e3;
66 muEta = mu->eta();
67 muPhi = mu->phi();
68 averageMu = lbAverageInteractionsPerCrossing(ctx);
69
70 auto L1pass = Monitored::Scalar<bool>(m_group+"_L1pass",false);
71 auto L2SApass = Monitored::Scalar<bool>(m_group+"_L2SApass",false);
72 auto L2CBpass = Monitored::Scalar<bool>(m_group+"_L2CBpass",false);
73 auto EFSApass = Monitored::Scalar<bool>(m_group+"_EFSApass",false);
74 auto EFCBpass = Monitored::Scalar<bool>(m_group+"_EFCBpass",false);
75 auto EFIsopass = Monitored::Scalar<bool>(m_group+"_EFIsopass",false);
76 auto EFSAFSpass = Monitored::Scalar<bool>(m_group+"_EFSAFSpass",false);
77 auto EFCBFSpass = Monitored::Scalar<bool>(m_group+"_EFCBFSpass",false);
78
79
80 if(m_doL1){
81 bool activestate = false;
82 m_matchTool->matchL1(ctx, muEta, muPhi, 0.25, chain, activestate);
83 L1pass = activestate;
84 } else {
85 L1pass = true;
86 }
87
88
89 if(L1pass){
90 if(m_doL2SA){
91 bool activestate = false;
92 const bool isPh2FastReco = chain.find("newFast") != std::string::npos;
93 if (isPh2FastReco) {
94 m_matchTool->matchFastRecoSA(ctx, mu, chain, activestate);
95 } else {
96 m_matchTool->matchL2SA(ctx, mu, chain, activestate);
97 }
98 L2SApass = activestate;
99 } else {
100 L2SApass = true;
101 }
102 }
103
104
105 if(L2SApass){
106 if(m_doL2CB){
107 bool activestate = false;
108 m_matchTool->matchL2CB(mu, chain, activestate);
109 L2CBpass = activestate;
110 } else {
111 L2CBpass = true;
112 }
113 }
114
115
116 if(L2CBpass){
117 if(m_doEFSA){
118 bool activestate = false;
119 m_matchTool->matchEFSA(mu, chain, activestate);
120 EFSApass = activestate;
121 } else {
122 EFSApass = true;
123 }
124 }
125
126
127 if(EFSApass){
128 if(m_doEFCB){
129 bool activestate = false;
130 m_matchTool->matchEFCB(mu, chain, activestate);
131 EFCBpass = activestate;
132 } else {
133 EFCBpass = true;
134 }
135 }
136
137
138 if(EFCBpass){
139 if(m_doEFIso){
140 bool activestate = false;
141 m_matchTool->matchEFIso(mu, chain, activestate);
142 EFIsopass = activestate;
143 } else {
144 EFIsopass = true;
145 }
146 }
147
148
149 if(m_doEFSAFS){
150 bool activestate = false;
151 m_matchTool->matchEFSAFS(mu, chain, activestate);
152 EFSAFSpass = activestate;
153 } else {
154 EFSAFSpass = true;
155 }
156
157
158 if(EFSAFSpass){
159 if(m_doEFCBFS){
160 bool activestate = false;
161 m_matchTool->matchEFCBFS(mu, chain, activestate);
162 EFCBFSpass = activestate;
163 } else {
164 EFCBFSpass = true;
165 }
166 }
167
168
169 ATH_MSG_DEBUG("doL1:" << m_doL1 << " L1pass:" << L1pass << " doL2SA:" << m_doL2SA << " L2SAPass:" << L2SApass << " doL2CB:" << m_doL2CB << " L2CBpass:" << L2CBpass <<
170 " doEFSA:" << m_doEFSA << " EFSApass:" << EFSApass << " doEFCB:" << m_doEFCB << " EFCBpass:" << EFCBpass << " doEFIso:" << m_doEFIso << " EFIsopass:" << EFIsopass <<
171 " doEFSAFS:" << m_doEFSAFS << " EFSAFSpass:" << EFSAFSpass << " doEFCBFS:" << m_doEFCBFS << " EFCBFSpass:" << EFCBFSpass);
172
174 // Inclusive
175 fill(m_group, muPt, L1pass, L2SApass, L2CBpass, EFSApass, EFCBpass, EFIsopass, EFSAFSpass, EFCBFSpass);
176
177 // Plateau
178 if(muPt>m_thresholds.at(chain)){
179 fill(m_group, muEta, muPhi, averageMu, L1pass, L2SApass, L2CBpass, EFSApass, EFCBpass, EFIsopass, EFSAFSpass, EFCBFSpass);
180 }
181
182 return StatusCode::SUCCESS;
183}
184
185
186
187StatusCode TrigMuonEfficiencyMon :: selectMuonsTagAndProbe(const EventContext& ctx, SG::ReadHandle<xAOD::MuonContainer> &muons, std::vector<const xAOD::Muon*> &probes) const {
188
189 std::vector<float> vec_invmass;
190 vec_invmass.clear();
191
192 std::vector<std::pair<const xAOD::Muon*, const xAOD::Muon*> > dimuons;
193 xAOD::MuonContainer::const_iterator mu1_it = muons->begin();
194 xAOD::MuonContainer::const_iterator mu1_end = muons->end();
195 for(; mu1_it!=mu1_end; ++mu1_it){
196 const xAOD::Muon *mu1 = *mu1_it;
197 if( m_muonSelectionTool->getQuality(*mu1)>xAOD::Muon::Quality::Medium ) continue;
199 xAOD::MuonContainer::const_iterator mu2_end = mu1_end;
200 for(++mu2_it; mu2_it!=mu2_end; ++mu2_it){
201 const xAOD::Muon *mu2 = *mu2_it;
202 if( m_muonSelectionTool->getQuality(*mu2)>xAOD::Muon::Quality::Medium ) continue;
203 if( mu1->charge()*mu2->charge()>0 ) continue;
204
205 TLorentzVector lvmu1 = mu1->p4();
206 TLorentzVector lvmu2 = mu2->p4();
207 double dimu_mass = (lvmu1+lvmu2).M()/1.e3;
208 vec_invmass.push_back(dimu_mass);
209 bool bit_mass = (dimu_mass > m_mass_lowlim) && (dimu_mass < m_mass_highlim);
210 bool bit_dR = lvmu1.DeltaR(lvmu2)>0.5;
212 const xAOD::TrackParticle *track1 = mu1->trackParticle(xAOD::Muon::TrackParticleType::Primary);
213 const Trk::TrackParameters *extTrack1 = m_matchTool->extTrackToPivot(ctx, track1);
214 const xAOD::TrackParticle *track2 = mu2->trackParticle(xAOD::Muon::TrackParticleType::Primary);
215 const Trk::TrackParameters *extTrack2 = m_matchTool->extTrackToPivot(ctx, track2);
216 if(extTrack1 && extTrack2){
217 TLorentzVector lvext1 = lvmu1;
218 TLorentzVector lvext2 = lvmu2;
219 double mupt1 = mu1->pt();
220 double mupt2 = mu2->pt();
221 lvext1.SetPtEtaPhiM( mupt1, extTrack1->position().eta(), extTrack1->position().phi(), mu1->m());
222 lvext2.SetPtEtaPhiM( mupt2, extTrack2->position().eta(), extTrack2->position().phi(), mu2->m());
223 bit_dR = lvext1.DeltaR(lvext2) > (MuonMatchingTool::reqdRL1byPt(mupt1)+MuonMatchingTool::reqdRL1byPt(mupt2));
224 }
225 }
226
227 // For ttbar events
228 if( m_eff_method == "TTbarTagAndProbe" && !bit_dR ) continue;
229 // For Zmumu events
230 if( m_eff_method == "ZTagAndProbe" && !(bit_mass && bit_dR) ) continue;
231
232 dimuons.emplace_back(mu1,mu2);
233 }
234 }// loop over muons
235
236 auto invmass = Monitored::Collection(m_group+"_invmass", vec_invmass);
237 fill(m_group, invmass);
238
239
240 for (std::pair<const xAOD::Muon*,const xAOD::Muon*> dimu : dimuons){
241 bool pass1 = false;
242 bool pass2 = false;
243
244 m_matchTool->matchEFIso(dimu.first, m_tag_trig, pass1);
245 m_matchTool->matchEFIso(dimu.second, m_tag_trig, pass2);
246
247 if(pass1){
248 if(std::find(probes.begin(), probes.end(), dimu.second)==probes.end()){
249 if(m_BarrelOnly){
250 if( std::abs( dimu.second->eta() ) > 0. && std::abs( dimu.second->eta() ) < 1.05 ) probes.push_back(dimu.second);
251 }
252 else probes.push_back(dimu.second);
253 }
254 }
255 if(pass2){
256 if(std::find(probes.begin(), probes.end(), dimu.first)==probes.end()){
257 if(m_BarrelOnly){
258 if( std::abs( dimu.first->eta() ) > 0. && std::abs( dimu.first->eta() ) < 1.05 ) probes.push_back(dimu.first);
259 }
260 else probes.push_back(dimu.first);
261 }
262 }
263 }
264
265 return StatusCode::SUCCESS;;
266}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
Declare a monitored scalar variable.
static double reqdRL1byPt(double mupt)
Function compute dR used for matching offline muons and level 1 RoIs at the pivot plane.
std::map< std::string, double > m_thresholds
Gaudi::Property< bool > m_doEFIso
std::map< std::string, std::string > m_l1seeds
Gaudi::Property< std::vector< std::string > > m_monitored_chains_L1
Gaudi::Property< std::vector< double > > m_monitored_chains_threshold
Gaudi::Property< std::string > m_tag_trig
Gaudi::Property< bool > m_doEFCBFS
Gaudi::Property< bool > m_doL1
StatusCode selectMuonsTagAndProbe(const EventContext &ctx, SG::ReadHandle< xAOD::MuonContainer > &muons, std::vector< const xAOD::Muon * > &probes) const
Gaudi::Property< bool > m_doEFSAFS
Gaudi::Property< bool > m_doEFCB
Gaudi::Property< bool > m_doEFSA
Gaudi::Property< double > m_mass_lowlim
Gaudi::Property< bool > m_BarrelOnly
Gaudi::Property< double > m_mass_highlim
Gaudi::Property< std::string > m_eff_method
Gaudi::Property< bool > m_doL2SA
Gaudi::Property< std::string > m_event_trigger
Gaudi::Property< bool > m_use_extrapolator
Gaudi::Property< bool > m_doL2CB
Gaudi::Property< std::string > m_group
Name of monitored group.
TrigMuonMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::vector< std::string > > m_monitored_chains
List of trigger chains that are monitored in fillVariablesPerChain and fillVariablesPerOfflineMuonPer...
Gaudi::Property< int > m_muontype
Requirement for the offline muon type considered in analyses.
virtual StatusCode initialize() override
initialize
ToolHandle< CP::IMuonSelectionTool > m_muonSelectionTool
ToolHandle< MuonMatchingTool > m_matchTool
const Amg::Vector3D & position() const
Access method for the position.
virtual double m() const override
The invariant mass of the particle..
Definition Muon_v1.cxx:67
virtual double pt() const override
The transverse momentum ( ) of the particle.
const TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be a nullptr) to the TrackParticle used in identification of this muon.
Definition Muon_v1.cxx:422
float charge() const
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Definition Muon_v1.cxx:84
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx) const
Calculate the average mu, i.e.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
ParametersBase< TrackParametersDim, Charged > TrackParameters
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
void fill(H5::Group &out_file, size_t iterations)