ATLAS Offline Software
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 
10 TrigMuonEfficiencyMon :: TrigMuonEfficiencyMon(const std::string& name, ISvcLocator* pSvcLocator )
11  : TrigMuonMonitorAlgorithm(name, pSvcLocator)
12 {}
13 
14 
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 
34  if(m_event_trigger.empty()) return true;
35  return getTrigDecisionTool()->isPassed(m_event_trigger);
36 }
37 
38 
39 
40 StatusCode 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 
55 StatusCode 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 
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;
193  xAOD::MuonContainer::const_iterator mu2_it = mu1_it;
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;
208  if(m_use_extrapolator){
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 }
TrigMuonEfficiencyMon::m_monitored_chains_L1
Gaudi::Property< std::vector< std::string > > m_monitored_chains_L1
Definition: TrigMuonEfficiencyMon.h:37
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TrigMuonEfficiencyMon::m_doL2CB
Gaudi::Property< bool > m_doL2CB
Definition: TrigMuonEfficiencyMon.h:41
TrigMuonMonitorAlgorithm::m_group
Gaudi::Property< std::string > m_group
Name of monitored group.
Definition: TrigMuonMonitorAlgorithm.h:141
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TrigMuonMonitorAlgorithm::m_matchTool
ToolHandle< MuonMatchingTool > m_matchTool
Definition: TrigMuonMonitorAlgorithm.h:129
xAOD::Muon_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Muon_v1.cxx:79
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
TrigMuonEfficiencyMon::m_eff_method
Gaudi::Property< std::string > m_eff_method
Definition: TrigMuonEfficiencyMon.h:34
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:189
TrigMuonEfficiencyMon::m_doEFIso
Gaudi::Property< bool > m_doEFIso
Definition: TrigMuonEfficiencyMon.h:44
TrigMuonEfficiencyMon::m_mass_highlim
Gaudi::Property< double > m_mass_highlim
Definition: TrigMuonEfficiencyMon.h:50
TrigMuonEfficiencyMon::selectMuons
virtual StatusCode selectMuons(SG::ReadHandle< xAOD::MuonContainer > &muons, std::vector< const xAOD::Muon * > &probes) const override
Function that defines the event selection for anlayses Users should reimlement in a subclass if neede...
Definition: TrigMuonEfficiencyMon.cxx:40
xAOD::Muon_v1::author
Author author() const
TrigMuonEfficiencyMon::m_monitored_chains_threshold
Gaudi::Property< std::vector< double > > m_monitored_chains_threshold
Definition: TrigMuonEfficiencyMon.h:38
TrigMuonEfficiencyMon::TrigMuonEfficiencyMon
TrigMuonEfficiencyMon(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigMuonEfficiencyMon.cxx:10
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TrigMuonEfficiencyMon::m_doEFCBFS
Gaudi::Property< bool > m_doEFCBFS
Definition: TrigMuonEfficiencyMon.h:46
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
xAOD::Muon_v1::charge
float charge() const
plotBeamSpotCompare.pass2
bool pass2
Definition: plotBeamSpotCompare.py:269
TrigMuonEfficiencyMon::m_l1seeds
std::map< std::string, std::string > m_l1seeds
Definition: TrigMuonEfficiencyMon.h:53
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
TrigMuonEfficiencyMon::m_event_trigger
Gaudi::Property< std::string > m_event_trigger
Definition: TrigMuonEfficiencyMon.h:35
plotBeamSpotCompare.pass1
bool pass1
Definition: plotBeamSpotCompare.py:231
MuonMatchingTool.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigMuonEfficiencyMon::m_doEFCB
Gaudi::Property< bool > m_doEFCB
Definition: TrigMuonEfficiencyMon.h:43
TrigMuonEfficiencyMon::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigMuonEfficiencyMon.cxx:15
xAOD::Muon_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
TrigMuonEfficiencyMon::m_mass_lowlim
Gaudi::Property< double > m_mass_lowlim
Definition: TrigMuonEfficiencyMon.h:49
TrigMuonEfficiencyMon::selectEvents
virtual bool selectEvents() const override
Function that defines the event selection for anlayses User should reimlement in a subclass if needed...
Definition: TrigMuonEfficiencyMon.cxx:33
TrigMuonMonitorAlgorithm
Base class from which analyzers can define a derived class to do specific analysis.
Definition: TrigMuonMonitorAlgorithm.h:22
Trk::ParametersBase
Definition: ParametersBase.h:55
TrigMuonEfficiencyMon::fillVariablesPerOfflineMuonPerChain
virtual StatusCode fillVariablesPerOfflineMuonPerChain(const EventContext &ctx, const xAOD::Muon *mu, const std::string &chain) const override
Function that fills variables of trigger objects associated to specified trigger chains comparing off...
Definition: TrigMuonEfficiencyMon.cxx:55
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
xAOD::Muon_v1::m
virtual double m() const
The invariant mass of the particle..
Definition: Muon_v1.cxx:62
TrigMuonEfficiencyMon::selectMuonsTagAndProbe
StatusCode selectMuonsTagAndProbe(SG::ReadHandle< xAOD::MuonContainer > &muons, std::vector< const xAOD::Muon * > &probes) const
Definition: TrigMuonEfficiencyMon.cxx:180
TrigMuonMonitorAlgorithm::m_monitored_chains
Gaudi::Property< std::vector< std::string > > m_monitored_chains
List of trigger chains that are monitored in fillVariablesPerChain and fillVariablesPerOfflineMuonPer...
Definition: TrigMuonMonitorAlgorithm.h:137
TrigMuonEfficiencyMon::m_doL2SA
Gaudi::Property< bool > m_doL2SA
Definition: TrigMuonEfficiencyMon.h:40
Muon::nsw::unknown
@ unknown
Definition: NSWTriggerElink.h:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthMonitorAlgorithm::lbAverageInteractionsPerCrossing
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx=Gaudi::Hive::currentContext()) const
Calculate the average mu, i.e.
Definition: AthMonitorAlgorithm.cxx:222
TrigMuonMonitorAlgorithm::m_muontype
Gaudi::Property< int > m_muontype
Requirement for the offline muon type considered in analyses.
Definition: TrigMuonMonitorAlgorithm.h:139
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TrigMuonEfficiencyMon::m_doEFSA
Gaudi::Property< bool > m_doEFSA
Definition: TrigMuonEfficiencyMon.h:42
MuonParameters::MuidCo
@ MuidCo
Definition: MuonParamDefs.h:60
TrigMuonEfficiencyMon::m_doEFSAFS
Gaudi::Property< bool > m_doEFSAFS
Definition: TrigMuonEfficiencyMon.h:45
TrigMuonEfficiencyMon::m_BarrelOnly
Gaudi::Property< bool > m_BarrelOnly
Definition: TrigMuonEfficiencyMon.h:47
LikeEnum::Medium
@ Medium
Definition: LikelihoodEnums.h:14
TrigMuonEfficiencyMon::m_use_extrapolator
Gaudi::Property< bool > m_use_extrapolator
Definition: TrigMuonEfficiencyMon.h:48
TrigMuonEfficiencyMon.h
TrigMuonMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigMuonMonitorAlgorithm.cxx:13
xAOD::Muon_v1::primaryTrackParticle
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:400
xAOD::STACO
@ STACO
Tracks produced by STACO.
Definition: TrackingPrimitives.h:99
TrigMuonEfficiencyMon::m_doL1
Gaudi::Property< bool > m_doL1
Definition: TrigMuonEfficiencyMon.h:39
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigMuonEfficiencyMon::m_tag_trig
Gaudi::Property< std::string > m_tag_trig
Definition: TrigMuonEfficiencyMon.h:36
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
TrigMuonMonitorAlgorithm::m_muonSelectionTool
ToolHandle< CP::IMuonSelectionTool > m_muonSelectionTool
Definition: TrigMuonMonitorAlgorithm.h:130
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TrigMuonEfficiencyMon::m_thresholds
std::map< std::string, double > m_thresholds
Definition: TrigMuonEfficiencyMon.h:54
MuonMatchingTool::reqdRL1byPt
static double reqdRL1byPt(double mupt)
Function compute dR used for matching offline muons and level 1 RoIs at the pivot plane.
Definition: MuonMatchingTool.cxx:520
xAOD::Muon_v1::muonType
MuonType muonType() const