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