ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEfficiencyMon.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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(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(muons, probes);
44 } else {
45 for (const xAOD::Muon* mu : *muons) {
46 if( mu->muonType()<=m_muontype && (mu->author()==xAOD::Muon::Author::MuidCo || mu->author()==xAOD::Muon::Author::STACO) && mu->quality()==xAOD::Muon::Quality::Medium ){
47 probes.push_back(mu);
48 }
49 }
50 }
51 return StatusCode::SUCCESS;
52}
53
54
55StatusCode TrigMuonEfficiencyMon :: fillVariablesPerOfflineMuonPerChain(const EventContext& ctx, const xAOD::Muon* mu, const std::string &chain) const {
56
57
58 auto muPt = Monitored::Scalar<double>(m_group+"_muPt");
59 auto muEta = Monitored::Scalar<float>(m_group+"_muEta");
60 auto muPhi = Monitored::Scalar<float>(m_group+"_muPhi");
61 auto averageMu = Monitored::Scalar<float>(m_group+"_averageMu");
62
63 muPt = mu->pt()/1e3;
64 muEta = mu->eta();
65 muPhi = mu->phi();
66 averageMu = lbAverageInteractionsPerCrossing(ctx);
67
68 auto L1pass = Monitored::Scalar<bool>(m_group+"_L1pass",false);
69 auto L2SApass = Monitored::Scalar<bool>(m_group+"_L2SApass",false);
70 auto L2CBpass = Monitored::Scalar<bool>(m_group+"_L2CBpass",false);
71 auto EFSApass = Monitored::Scalar<bool>(m_group+"_EFSApass",false);
72 auto EFCBpass = Monitored::Scalar<bool>(m_group+"_EFCBpass",false);
73 auto EFIsopass = Monitored::Scalar<bool>(m_group+"_EFIsopass",false);
74 auto EFSAFSpass = Monitored::Scalar<bool>(m_group+"_EFSAFSpass",false);
75 auto EFCBFSpass = Monitored::Scalar<bool>(m_group+"_EFCBFSpass",false);
76
77
78 if(m_doL1){
79 bool activestate = false;
80 m_matchTool->matchL1(muEta, muPhi, 0.25, chain, activestate);
81 L1pass = activestate;
82 } else {
83 L1pass = true;
84 }
85
86
87 if(L1pass){
88 if(m_doL2SA){
89 bool activestate = false;
90 m_matchTool->matchL2SA(mu, chain, activestate);
91 L2SApass = activestate;
92 } else {
93 L2SApass = true;
94 }
95 }
96
97
98 if(L2SApass){
99 if(m_doL2CB){
100 bool activestate = false;
101 m_matchTool->matchL2CB(mu, chain, activestate);
102 L2CBpass = activestate;
103 } else {
104 L2CBpass = true;
105 }
106 }
107
108
109 if(L2CBpass){
110 if(m_doEFSA){
111 bool activestate = false;
112 m_matchTool->matchEFSA(mu, chain, activestate);
113 EFSApass = activestate;
114 } else {
115 EFSApass = true;
116 }
117 }
118
119
120 if(EFSApass){
121 if(m_doEFCB){
122 bool activestate = false;
123 m_matchTool->matchEFCB(mu, chain, activestate);
124 EFCBpass = activestate;
125 } else {
126 EFCBpass = true;
127 }
128 }
129
130
131 if(EFCBpass){
132 if(m_doEFIso){
133 bool activestate = false;
134 m_matchTool->matchEFIso(mu, chain, activestate);
135 EFIsopass = activestate;
136 } else {
137 EFIsopass = true;
138 }
139 }
140
141
142 if(m_doEFSAFS){
143 bool activestate = false;
144 m_matchTool->matchEFSAFS(mu, chain, activestate);
145 EFSAFSpass = activestate;
146 } else {
147 EFSAFSpass = true;
148 }
149
150
151 if(EFSAFSpass){
152 if(m_doEFCBFS){
153 bool activestate = false;
154 m_matchTool->matchEFCBFS(mu, chain, activestate);
155 EFCBFSpass = activestate;
156 } else {
157 EFCBFSpass = true;
158 }
159 }
160
161
162 ATH_MSG_DEBUG("doL1:" << m_doL1 << " L1pass:" << L1pass << " doL2SA:" << m_doL2SA << " L2SAPass:" << L2SApass << " doL2CB:" << m_doL2CB << " L2CBpass:" << L2CBpass <<
163 " doEFSA:" << m_doEFSA << " EFSApass:" << EFSApass << " doEFCB:" << m_doEFCB << " EFCBpass:" << EFCBpass << " doEFIso:" << m_doEFIso << " EFIsopass:" << EFIsopass <<
164 " doEFSAFS:" << m_doEFSAFS << " EFSAFSpass:" << EFSAFSpass << " doEFCBFS:" << m_doEFCBFS << " EFCBFSpass:" << EFCBFSpass);
165
167 // Inclusive
168 fill(m_group, muPt, L1pass, L2SApass, L2CBpass, EFSApass, EFCBpass, EFIsopass, EFSAFSpass, EFCBFSpass);
169
170 // Plateau
171 if(muPt>m_thresholds.at(chain)){
172 fill(m_group, muEta, muPhi, averageMu, L1pass, L2SApass, L2CBpass, EFSApass, EFCBpass, EFIsopass, EFSAFSpass, EFCBFSpass);
173 }
174
175 return StatusCode::SUCCESS;
176}
177
178
179
180StatusCode TrigMuonEfficiencyMon :: selectMuonsTagAndProbe(SG::ReadHandle<xAOD::MuonContainer> &muons, std::vector<const xAOD::Muon*> &probes) const {
181
182 std::vector<float> vec_invmass;
183 vec_invmass.clear();
184
185 std::vector<std::pair<const xAOD::Muon*, const xAOD::Muon*> > dimuons;
186 xAOD::MuonContainer::const_iterator mu1_it = muons->begin();
187 xAOD::MuonContainer::const_iterator mu1_end = muons->end();
188 for(; mu1_it!=mu1_end; ++mu1_it){
189 const xAOD::Muon *mu1 = *mu1_it;
190 if( mu1->muonType()>m_muontype ) continue;
191 if( mu1->author()==xAOD::Muon::Author::unknown || mu1->author()>xAOD::Muon::Author::STACO ) continue;
192 if( m_muonSelectionTool->getQuality(*mu1)>xAOD::Muon::Medium ) continue;
194 xAOD::MuonContainer::const_iterator mu2_end = mu1_end;
195 for(++mu2_it; mu2_it!=mu2_end; ++mu2_it){
196 const xAOD::Muon *mu2 = *mu2_it;
197 if( mu2->muonType()>m_muontype ) continue;
198 if( mu2->author()==xAOD::Muon::Author::unknown || mu2->author()>xAOD::Muon::Author::STACO ) continue;
199 if( m_muonSelectionTool->getQuality(*mu2)>xAOD::Muon::Medium ) continue;
200 if( mu1->charge()*mu2->charge()>0 ) continue;
201
202 TLorentzVector lvmu1 = mu1->p4();
203 TLorentzVector lvmu2 = mu2->p4();
204 double dimu_mass = (lvmu1+lvmu2).M()/1.e3;
205 vec_invmass.push_back(dimu_mass);
206 bool bit_mass = (dimu_mass > m_mass_lowlim) && (dimu_mass < m_mass_highlim);
207 bool bit_dR = lvmu1.DeltaR(lvmu2)>0.5;
209 const xAOD::TrackParticle *track1 = mu1->primaryTrackParticle();
210 const Trk::TrackParameters *extTrack1 = m_matchTool->extTrackToPivot(track1);
211 const xAOD::TrackParticle *track2 = mu2->primaryTrackParticle();
212 const Trk::TrackParameters *extTrack2 = m_matchTool->extTrackToPivot(track2);
213 if(extTrack1 && extTrack2){
214 TLorentzVector lvext1 = lvmu1;
215 TLorentzVector lvext2 = lvmu2;
216 double mupt1 = mu1->pt();
217 double mupt2 = mu2->pt();
218 lvext1.SetPtEtaPhiM( mupt1, extTrack1->position().eta(), extTrack1->position().phi(), mu1->m());
219 lvext2.SetPtEtaPhiM( mupt2, extTrack2->position().eta(), extTrack2->position().phi(), mu2->m());
220 bit_dR = lvext1.DeltaR(lvext2) > (MuonMatchingTool::reqdRL1byPt(mupt1)+MuonMatchingTool::reqdRL1byPt(mupt2));
221 }
222 }
223
224 // For ttbar events
225 if( m_eff_method == "TTbarTagAndProbe" && !bit_dR ) continue;
226 // For Zmumu events
227 if( m_eff_method == "ZTagAndProbe" && !(bit_mass && bit_dR) ) continue;
228
229 dimuons.emplace_back(mu1,mu2);
230 }
231 }// loop over muons
232
233 auto invmass = Monitored::Collection(m_group+"_invmass", vec_invmass);
234 fill(m_group, invmass);
235
236
237 for (std::pair<const xAOD::Muon*,const xAOD::Muon*> dimu : dimuons){
238 bool pass1 = false;
239 bool pass2 = false;
240
241 m_matchTool->matchEFIso(dimu.first, m_tag_trig, pass1);
242 m_matchTool->matchEFIso(dimu.second, m_tag_trig, pass2);
243
244 if(pass1){
245 if(std::find(probes.begin(), probes.end(), dimu.second)==probes.end()){
246 if(m_BarrelOnly){
247 if( std::abs( dimu.second->eta() ) > 0. && std::abs( dimu.second->eta() ) < 1.05 ) probes.push_back(dimu.second);
248 }
249 else probes.push_back(dimu.second);
250 }
251 }
252 if(pass2){
253 if(std::find(probes.begin(), probes.end(), dimu.first)==probes.end()){
254 if(m_BarrelOnly){
255 if( std::abs( dimu.first->eta() ) > 0. && std::abs( dimu.first->eta() ) < 1.05 ) probes.push_back(dimu.first);
256 }
257 else probes.push_back(dimu.first);
258 }
259 }
260 }
261
262 return StatusCode::SUCCESS;;
263}
#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
StatusCode selectMuonsTagAndProbe(SG::ReadHandle< xAOD::MuonContainer > &muons, std::vector< const xAOD::Muon * > &probes) const
Gaudi::Property< std::string > m_tag_trig
Gaudi::Property< bool > m_doEFCBFS
Gaudi::Property< bool > m_doL1
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.
const TrackParticle * primaryTrackParticle() const
Returns a pointer (which should not usually be NULL, but might be if the muon has been stripped of in...
Definition Muon_v1.cxx:396
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition Muon_v1.cxx:71
virtual double m() const
The invariant mass of the particle..
Definition Muon_v1.cxx:54
virtual double pt() const
The transverse momentum ( ) of the particle.
float charge() const
Author author() const
MuonType muonType() const
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx=Gaudi::Hive::currentContext()) 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)