ATLAS Offline Software
Loading...
Searching...
No Matches
L2MuonSAMon.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 "L2MuonSAMon.h"
6
8#include "MuonMatchingTool.h"
9
10L2MuonSAMon :: L2MuonSAMon(const std::string& name, ISvcLocator* pSvcLocator )
11 : TrigMuonMonitorAlgorithm(name, pSvcLocator)
12{}
13
14
15StatusCode L2MuonSAMon :: initialize(){
17 ATH_CHECK( m_L2MuonSAContainerKey.initialize() );
18 return sc;
19}
20
21
22StatusCode L2MuonSAMon :: fillVariablesPerChain(const EventContext &ctx, const std::string &chain) const {
23
24 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
25
26 auto lb = Monitored::Scalar<int>(chain+"_LB",-1.0);
27 lb = GetEventInfo(ctx)->lumiBlock();
28
29 const float ZERO_LIMIT = 0.00001;
30
31 std::vector< TrigCompositeUtils::LinkInfo<xAOD::L2StandAloneMuonContainer> > featureCont = getTrigDecisionTool()->features<xAOD::L2StandAloneMuonContainer>( chain, TrigDefs::includeFailedDecisions );
32 for(const TrigCompositeUtils::LinkInfo<xAOD::L2StandAloneMuonContainer>& muLinkInfo : featureCont){
33 ATH_CHECK( muLinkInfo.isValid() );
34 const ElementLink<xAOD::L2StandAloneMuonContainer> muEL = muLinkInfo.link;
35
36
37 // basic EDM variables
38 auto saPt = Monitored::Scalar<float>(chain+"_Pt",-999.);
39 auto saEta = Monitored::Scalar<float>(chain+"_Eta",-999.);
40 auto saPhi = Monitored::Scalar<float>(chain+"_Phi",-999.);
41 auto saddr = Monitored::Scalar<int>(chain+"_saddr",-999.);
42 auto roiEta = Monitored::Scalar<float>(chain+"_roiEta",-999.);
43 auto roiPhi = Monitored::Scalar<float>(chain+"_roiPhi",-999.);
44 auto mf_failure = Monitored::Scalar<bool>(chain+"_mf_failure",false);
45
46 saPt = (*muEL)->pt();
47 saEta = (*muEL)->eta();
48 saPhi = (*muEL)->phi();
49 saddr = (*muEL)->sAddress();
50 roiEta = (*muEL)->roiEta();
51 roiPhi = (*muEL)->roiPhi();
52
53 ATH_MSG_DEBUG("saPt = " << saPt << ", saEta =" << saEta << ", saPhi = " << saPhi << ", saddr = " << saddr);
54 if(std::abs(saPt) < ZERO_LIMIT) mf_failure = true;
55
56 fill(m_group+"_"+chain, roiEta, roiPhi, mf_failure);
57 if( mf_failure ) continue;
58
59 // define barrel or endcap
60 auto isBarrel = Monitored::Scalar<bool>(chain+"_isBarrel",false);
61 auto isEndcap = Monitored::Scalar<bool>(chain+"_isEndcap",false);
62
63 if(saddr == -1) isEndcap = true;
64 else isBarrel = true;;
65
66 fill(m_group+"_"+chain, saPt, saEta, saPhi, saddr, isBarrel, isEndcap);
67
68
69 // define process flow
70 std::vector<int> proc_flow;
71 auto mon_proc_flow = Monitored::Collection(chain+"_proc_flow", proc_flow);
72
73 bool isL1hitThere = false;
74 bool isL1emuOkForTriggerPlane = false;
75 bool isMDThitThereForTriggerPlane = false;
76 bool isMDTFitOkForTriggerPlane = false;
77 bool isMDTFitOkFor2Plane = false;
78
79
80 // detector variables
81 // RPC and TGC
82 auto nRPC = Monitored::Scalar<int>(chain+"_RPC_Pad_N",0);
83 auto TGCMidRhoChi2 = Monitored::Scalar<float>(chain+"_TGC_Mid_rho_chi2",-1.0);
84 auto TGCMidPhiChi2 = Monitored::Scalar<float>(chain+"_TGC_Mid_phi_chi2",-1.0);
85 auto nTGCMidRho = Monitored::Scalar<int>(chain+"_TGC_Mid_rho_N",0);
86 auto nTGCMidPhi = Monitored::Scalar<int>(chain+"_TGC_Mid_phi_N",0);
87
88 nRPC = (*muEL)->rpcHitLayer().size();
89 TGCMidRhoChi2 = (*muEL)->tgcMidRhoChi2();
90 TGCMidPhiChi2 = (*muEL)->tgcMidPhiChi2();
91 nTGCMidRho = (*muEL)->tgcMidRhoN();
92 nTGCMidPhi = (*muEL)->tgcMidPhiN();
93
94 fill(m_group+"_"+chain, nRPC, TGCMidRhoChi2, TGCMidPhiChi2, nTGCMidRho, nTGCMidPhi, isBarrel, isEndcap);
95
96
97 // use process flow
98 if(isBarrel){
99 if( nRPC > 0 ) isL1hitThere = true;
100 float rpcFitMidSlope = (*muEL)->rpcFitMidSlope();
101 if( std::abs(rpcFitMidSlope) > ZERO_LIMIT ) isL1emuOkForTriggerPlane = true;
102 }
103 else {
104 if( nTGCMidRho > 0 && nTGCMidPhi > 0 ) isL1hitThere = true;
105 float TGCMid1Z = (*muEL)->tgcMid1Z();
106 if( std::abs(TGCMid1Z) > ZERO_LIMIT ) isL1emuOkForTriggerPlane = true;
107 }
108
109
110 // define inner, middle, and outer
111 int inner = 0;
112 int middle = 1;
113 int outer = 2;
114
115 if (isEndcap) {
119 } else {
123 }
124
125 float sign = 1;
126 if( saPhi < 0 ) sign = -1;
127
128
129 // super point
130 std::vector<float> sp_r, sp_z;
131
132 auto mon_sp_r= Monitored::Collection(chain+"_MDTpoints_r", sp_r);
133 auto mon_sp_z= Monitored::Collection(chain+"_MDTpoints_z", sp_z);
134
135 if( std::abs((*muEL)->superPointR(inner)) > ZERO_LIMIT ) {
136 sp_r.push_back( sign * (*muEL)->superPointR(inner) );
137 sp_z.push_back( (*muEL)->superPointZ(inner) );
138 }
139 if( std::abs((*muEL)->superPointR(middle)) > ZERO_LIMIT ) {
140 sp_r.push_back( sign * (*muEL)->superPointR(middle) );
141 sp_z.push_back( (*muEL)->superPointZ(middle) );
142 }
143 if( std::abs((*muEL)->superPointR(outer)) > ZERO_LIMIT ) {
144 sp_r.push_back( sign * (*muEL)->superPointR(outer) );
145 sp_z.push_back( (*muEL)->superPointZ(outer) );
146 }
147
148 fill(m_group+"_"+chain, mon_sp_r, mon_sp_z);
149
150
151 // MDT
152 auto MDTInnChi2 = Monitored::Scalar<float>(chain+"_MDT_Inn_fit_chi2",-1.0);
153 auto MDTMidChi2 = Monitored::Scalar<float>(chain+"_MDT_Mid_fit_chi2",-1.0);
154 auto MDTOutChi2 = Monitored::Scalar<float>(chain+"_MDT_Out_fit_chi2",-1.0);
155 auto n_mdt_hits = Monitored::Scalar<int>(chain+"_MDT_N",0);
156 auto n_mdt_hits_inner = Monitored::Scalar<int>(chain+"_MDT_Inn_N",0);
157 auto n_mdt_hits_middle = Monitored::Scalar<int>(chain+"_MDT_Mid_N",0);
158 auto n_mdt_hits_outer = Monitored::Scalar<int>(chain+"_MDT_Out_N",0);
159
160 MDTInnChi2 = (*muEL)->superPointChi2(inner);
161 MDTMidChi2 = (*muEL)->superPointChi2(middle);
162 MDTOutChi2 = (*muEL)->superPointChi2(outer);
163
164
165 std::vector<float> res_inn, res_mid, res_out;
166
167 auto mon_res_inn = Monitored::Collection(chain+"_MDT_Inn_residual",res_inn);
168 auto mon_res_mid = Monitored::Collection(chain+"_MDT_Mid_residual",res_mid);
169 auto mon_res_out = Monitored::Collection(chain+"_MDT_Out_residual",res_out);
170
171
172 n_mdt_hits = (*muEL)->nMdtHits();
173
174 for (int i_tube=0; i_tube<n_mdt_hits; i_tube++) {
175 float res = (*muEL)->mdtHitResidual(i_tube) / 10 ; // to cm
176 int imr = (*muEL)->mdtHitChamber(i_tube);
177
178 if (imr == inner) {
179 n_mdt_hits_inner++;
180 res_inn.push_back(res);
181 }
182 else if (imr == middle) {
183 n_mdt_hits_middle++;
184 res_mid.push_back(res);
185 }
186 else if (imr == outer) {
187 n_mdt_hits_outer++;
188 res_out.push_back(res);
189 }
190 }
191
192 fill(m_group+"_"+chain, MDTInnChi2, MDTMidChi2, MDTOutChi2, n_mdt_hits, n_mdt_hits_inner, n_mdt_hits_middle, n_mdt_hits_outer, mon_res_inn, mon_res_mid, mon_res_out, lb, isBarrel, isEndcap);
193
194
195 // use process flow
196 float MDTInnR = (*muEL)->superPointR(inner);
197 float MDTMidR = (*muEL)->superPointR(middle);
198 float MDTOutR = (*muEL)->superPointR(outer);
199
200 if( n_mdt_hits_middle > 0 ) isMDThitThereForTriggerPlane = true;
201 if( MDTMidR > ZERO_LIMIT ) isMDTFitOkForTriggerPlane = true;
202 if( isMDTFitOkForTriggerPlane && (MDTInnR > ZERO_LIMIT || MDTOutR > ZERO_LIMIT) ) isMDTFitOkFor2Plane = true;
203
204 proc_flow.push_back(1);
205 if( isL1hitThere ) proc_flow.push_back(2);
206 if( isL1emuOkForTriggerPlane ) proc_flow.push_back(3);
207 if( isMDThitThereForTriggerPlane ) proc_flow.push_back(4);
208 if( isMDTFitOkForTriggerPlane ) proc_flow.push_back(5);
209 if( isMDTFitOkFor2Plane ) proc_flow.push_back(6);
210
211 fill(m_group+"_"+chain, mon_proc_flow);
212
213
214 // matching to offline
215 const xAOD::Muon* RecMuonCB = m_matchTool->matchL2SAtoOff(ctx, (*muEL));
216 if(RecMuonCB == nullptr) continue;
217
218 std::vector<float> res_inn_OffMatch = res_inn;
219 std::vector<float> res_mid_OffMatch = res_mid;
220 std::vector<float> res_out_OffMatch = res_out;
221
222 auto mon_res_inn_OffMatch = Monitored::Collection(chain+"_MDT_Inn_residual_OffMatch",res_inn_OffMatch);
223 auto mon_res_mid_OffMatch = Monitored::Collection(chain+"_MDT_Mid_residual_OffMatch",res_mid_OffMatch);
224 auto mon_res_out_OffMatch = Monitored::Collection(chain+"_MDT_Out_residual_OffMatch",res_out_OffMatch);
225
226 fill(m_group+"_"+chain, mon_res_inn_OffMatch, mon_res_mid_OffMatch, mon_res_out_OffMatch, isBarrel, isEndcap);
227
228 }
229
230 return StatusCode::SUCCESS;
231}
232
233
234
235StatusCode L2MuonSAMon :: fillVariablesPerOfflineMuonPerChain(const EventContext&, const xAOD::Muon* mu, const std::string &chain) const {
236
237 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
238
239 const float ZERO_LIMIT = 0.00001;
240
241
242 // offline muon variables
243 auto offEta = Monitored::Scalar<float>(chain+"_offEta",-999.);
244 auto offPt_signed = Monitored::Scalar<float>(chain+"_offPt_signed",-999.);
245 offEta = mu->eta();
246
247 float offPt = mu->pt()/1e3;
248 float offPhi = mu->phi();
249 float offCharge = mu->charge();
250 offPt_signed = offPt * offCharge;
251
252
253 // get L2SA muon link
254 const TrigCompositeUtils::LinkInfo<xAOD::L2StandAloneMuonContainer> muLinkInfo = m_matchTool->searchL2SALinkInfo(mu, chain);
255 if ( !muLinkInfo.isValid() ) return StatusCode::SUCCESS;
257
258
259 // dR wrt offline
260 auto dRmin = Monitored::Scalar<float>(chain+"_dRmin",1000.);
261 dRmin = xAOD::P4Helpers::deltaR(mu, *muEL, false);
262
263 fill(m_group+"_"+chain, dRmin);
264 if( ! m_matchTool->isMatchedL2SA( *muEL, mu) ) return StatusCode::SUCCESS; // not matched to L2MuonSA
265
266
267 // L1 RoI wrt offline
268 float saPt = (*muEL)->pt();
269 float roiEta = (*muEL)->roiEta();
270 float roiPhi = (*muEL)->roiPhi();
271
272 auto roidEta = Monitored::Scalar<float>(chain+"_initialRoI_dEta",-999.);
273 auto roidPhi = Monitored::Scalar<float>(chain+"_initialRoI_dPhi",-999.);
274 auto roidR = Monitored::Scalar<float>(chain+"_initialRoI_dR",-999.);
275
276 roidEta = roiEta - offEta;
277 roidPhi = xAOD::P4Helpers::deltaPhi(offPhi, roiPhi);
278 roidR = sqrt(roidEta*roidEta + roidPhi*roidPhi);
279
280 fill(m_group+"_"+chain, roidEta, roidPhi, roidR, offEta);
281
282
283 // pt resolution, inverse pt resolution
284 auto ptresol = Monitored::Scalar<float>(chain+"_ptresol",-999.);
285 auto invptresol = Monitored::Scalar<float>(chain+"_invptresol",-999.);
286 if ( std::abs(offPt) > ZERO_LIMIT && std::abs(saPt) > ZERO_LIMIT ) {
287 ptresol = std::abs(saPt)/std::abs(offPt) - 1.;
288 invptresol = (1./(offPt * offCharge) - 1./saPt) / (1./(offPt * offCharge));
289 }
290
291
292 // inverse pt resolution depends on charge of offline muon
293 std::vector<float> invptresol_pos, invptresol_neg;
294
295 auto mon_invptresol_pos = Monitored::Collection(chain+"_invptresol_pos",invptresol_pos);
296 auto mon_invptresol_neg = Monitored::Collection(chain+"_invptresol_neg",invptresol_neg);
297
298 if( offCharge > 0. ) invptresol_pos.push_back(invptresol);
299 else invptresol_neg.push_back(invptresol);
300
301
302 // region variables
303 const float ETA_OF_BARREL = 1.05;
304 const float ETA_OF_ENDCAP1 = 1.5;
305 const float ETA_OF_ENDCAP2 = 2.0;
306 const float ETA_OF_ENDCAP3 = 2.5;
307
308 auto isBarrel = Monitored::Scalar<bool>(chain+"_isBarrel",false);
309 auto isBarrelA = Monitored::Scalar<bool>(chain+"_isBarrelA",false);
310 auto isBarrelC = Monitored::Scalar<bool>(chain+"_isBarrelC",false);
311 auto isEndcapA = Monitored::Scalar<bool>(chain+"_isEndcapA",false);
312 auto isEndcapC = Monitored::Scalar<bool>(chain+"_isEndcapC",false);
313 auto isEndcap1 = Monitored::Scalar<bool>(chain+"_isEndcap1",false);
314 auto isEndcap2 = Monitored::Scalar<bool>(chain+"_isEndcap2",false);
315 auto isEndcap3 = Monitored::Scalar<bool>(chain+"_isEndcap3",false);
316 auto isEndcap1A = Monitored::Scalar<bool>(chain+"_isEndcap1A",false);
317 auto isEndcap2A = Monitored::Scalar<bool>(chain+"_isEndcap2A",false);
318 auto isEndcap3A = Monitored::Scalar<bool>(chain+"_isEndcap3A",false);
319 auto isEndcap1C = Monitored::Scalar<bool>(chain+"_isEndcap1C",false);
320 auto isEndcap2C = Monitored::Scalar<bool>(chain+"_isEndcap2C",false);
321 auto isEndcap3C = Monitored::Scalar<bool>(chain+"_isEndcap3C",false);
322
323 // offline pt variables
324 auto pt4to6 = Monitored::Scalar<bool>(chain+"_pt4to6",false);
325 auto pt6to8 = Monitored::Scalar<bool>(chain+"_pt6to8",false);
326 auto ptover8 = Monitored::Scalar<bool>(chain+"_ptover8",false);
327
328
329 // define region
330 if( std::abs(offEta) < ETA_OF_BARREL ) {
331 if( offEta > 0. ) isBarrelA = true;
332 else isBarrelC = true;
333 }
334 else{
335 if( offEta > 0. ) isEndcapA = true;
336 else isEndcapC = true;
337 }
338
339
340 if( std::abs(offEta) < ETA_OF_BARREL ){
341 isBarrel = true;
342 if( offEta > 0. ) isBarrelA = true;
343 else isBarrelC = true;
344 }
345 else if ( std::abs(offEta) < ETA_OF_ENDCAP1 ){
346 isEndcap1 = true;
347 if( offEta > 0. ) isEndcap1A = true;
348 else isEndcap1C = true;
349 }
350 else if ( std::abs(offEta) < ETA_OF_ENDCAP2 ){
351 isEndcap2 = true;
352 if( offEta > 0. ) isEndcap2A = true;
353 else isEndcap2C = true;
354 }
355 else if ( std::abs(offEta) < ETA_OF_ENDCAP3 ){
356 isEndcap3 = true;
357 if( offEta > 0. ) isEndcap3A = true;
358 else isEndcap3C = true;
359 }
360
361
362 if( std::abs(offPt) > 4 ){
363 if( std::abs(offPt) < 6 ) pt4to6 = true;
364 else if( std::abs(offPt) < 8 ) pt6to8 = true;
365 else ptover8 = true;
366 }
367
368
369 fill(m_group+"_"+chain, ptresol, offPt_signed, offEta, isBarrel, isEndcap1, isEndcap2, isEndcap3, isBarrelA, isBarrelC, isEndcapA, isEndcapC, pt4to6, pt6to8, ptover8);
370 fill(m_group+"_"+chain, mon_invptresol_pos, mon_invptresol_neg, isBarrelA, isBarrelC, isEndcap1A, isEndcap2A, isEndcap3A, isEndcap1C, isEndcap2C, isEndcap3C);
371
372
373 return StatusCode::SUCCESS;
374}
375
376
377
378StatusCode L2MuonSAMon :: fillVariables(const EventContext &ctx) const {
379
380 ATH_MSG_DEBUG ("Filling histograms for " << name() << "...");
381
383
384 return StatusCode::SUCCESS;
385
386}
387
388
389
390StatusCode L2MuonSAMon :: fillVariablesPerOfflineMuon(const EventContext &ctx, const xAOD::Muon* mu) const {
391
392 ATH_CHECK( fillVariablesRatioPlots<xAOD::L2StandAloneMuon>(ctx, mu, "L2SA", xAOD::Muon::TrackParticleType::ExtrapolatedMuonSpectrometerTrackParticle,
393 [this](const EventContext &ctx, const xAOD::Muon *mu){ return m_matchTool->matchL2SAReadHandle(ctx,mu); }
394 ));
395
396 return StatusCode::SUCCESS;
397
398}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
static Double_t sc
int sign(int a)
const float ZERO_LIMIT
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
SG::ReadHandleKey< xAOD::L2StandAloneMuonContainer > m_L2MuonSAContainerKey
Definition L2MuonSAMon.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
int lb
Definition globals.cxx:23
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
static const unsigned int includeFailedDecisions
Run3 synonym of alsoDeactivateTEs.
@ BarrelInner
Inner station in the barrel spectrometer.
@ EndcapOuter
Outer station in the endcap spectrometer.
@ BarrelMiddle
Middle station in the barrel spectrometer.
@ EndcapMiddle
Middle station in the endcap spectrometer.
@ BarrelOuter
Outer station in the barrel spectrometer.
@ EndcapInner
Inner station in the endcap spectrometer.
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
L2StandAloneMuonContainer_v2 L2StandAloneMuonContainer
Define the latest version of the muon SA container.
Muon_v1 Muon
Reference the current persistent version:
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)