ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonMatching.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#ifdef ROOTCORE
11#endif // ROOTCORE
12
18
19#define MUONMASS ParticleConstants::muonMassInMeV
20
21namespace Trig {
22
23 TrigMuonMatching::TrigMuonMatching( const std::string& name )
24 : asg::AsgMetadataTool( name ),
25 m_trigDecTool("Trig::TrigDecisionTool/TrigDecisionTool")
26 {
27 declareProperty( "TriggerTool", m_trigDecTool);
28 }
29
32
34 // Greet the user:
35 ATH_MSG_INFO( "Initialising... " );
36
37 ATH_CHECK(m_trigDecTool.retrieve());
38
39 return StatusCode::SUCCESS;
40 }
41
43 const std::string &chain,
44 const double mindelR) const
45 {
46 return match(mu->eta(),mu->phi(),chain,mindelR);
47 }
48
50 const std::string &l1item,
51 const double DelR) const
52 {
53 return matchL1(mu->eta(),mu->phi(),l1item,DelR);
54 }
55
57 const std::string &chain,
58 const double mindelR) const
59 {
60 Double_t delmin = mindelR;
61 EFmuon efmuon,dummy;
62 return matchedTrackDetail(efmuon, dummy, mu->eta(), mu->phi(), delmin, chain);
63 }
64
66 const std::string &l1item,
67 const double DelR) const
68 {
69 Double_t l1dr = DelR;
70 const xAOD::MuonRoIContainer* muonrois = 0;
71 StatusCode sc = evtStore()->retrieve(muonrois,"LVL1MuonRoIs");
72 if(!sc){
73 ATH_MSG_ERROR("TrigMuonMatching::matchL1 : could not retrieve LVL1MuonRoIs");
74 return false;
75 }
76 Int_t threshold = getL1pt(l1item);
77 xAOD::MuonRoIContainer::const_iterator muroi_itr = muonrois->begin();
78 xAOD::MuonRoIContainer::const_iterator muroi_end = muonrois->end();
79 for( ; muroi_itr != muroi_end; ++muroi_itr ) {
80 if((*muroi_itr)->thrValue() >= threshold*1000){
81 Double_t dR = TrigMuonMatching::dR(mu->eta(), mu->phi(), (*muroi_itr)->eta(), (*muroi_itr)->phi());
82 if(dR < l1dr){
83 l1dr = dR;
84 }
85 }
86 }
87 return l1dr;
88 }
89
91 const xAOD::Muon* mu2,
92 const std::string& chain,
93 std::pair<Bool_t, Bool_t>& result1,
94 std::pair<Bool_t, Bool_t>& result2,
95 const Double_t& mindelR)
96 {
97 TLorentzVector mu_1, mu_2;
98 mu_1.SetPtEtaPhiM(mu1->pt(),mu1->eta(),mu1->phi(),MUONMASS);
99 mu_2.SetPtEtaPhiM(mu2->pt(),mu2->eta(),mu2->phi(),MUONMASS);
100 Bool_t valid = matchDimuon(mu_1,mu_2,chain,result1,result2,mindelR);
101 return valid;
102 }
103
104 Bool_t TrigMuonMatching::match(const double eta,
105 const double phi,
106 const std::string &chain,
107 const double mindelR) const
108 {
109 if(!m_trigDecTool->isPassed(chain)){
110 return false;
111 }
112 Double_t delmin = mindelR;
113 EFmuon efmuon,dummy;
114
115 matchedTrackDetail(efmuon, dummy, eta, phi, delmin, chain);
116 return efmuon.valid;
117 }
118
119 Bool_t TrigMuonMatching::matchL1(const double eta,
120 const double phi,
121 const std::string &l1item,
122 const double DelR) const
123 {
124 if(!m_trigDecTool->isPassed("L1_MU.*")){
125 return false;
126 }
127 Double_t l1dr = DelR;
128 const xAOD::MuonRoIContainer* muonrois = 0;
129 StatusCode sc = evtStore()->retrieve(muonrois,"LVL1MuonRoIs");
130 if(!sc){
131 ATH_MSG_ERROR("TrigMuonMatching::matchL1 : could not retrieve LVL1MuonRoIs");
132 return false;
133 }
134 Int_t threshold = getL1pt(l1item);
135 xAOD::MuonRoIContainer::const_iterator muroi_itr = muonrois->begin();
136 xAOD::MuonRoIContainer::const_iterator muroi_end = muonrois->end();
137 for( ; muroi_itr != muroi_end; ++muroi_itr ) {
138 if((*muroi_itr)->thrValue() >= threshold*1000){
139 Double_t dR = TrigMuonMatching::dR(eta, phi, (*muroi_itr)->eta(), (*muroi_itr)->phi());
140 if(dR < l1dr){
141 return true;
142 }
143 }
144 }
145 return false;
146 }
147
149 const std::string &l1item,
150 const std::string &chain,
151 const double DelR) const
152 {
153 if(!m_trigDecTool->isPassed("L1_MU.*")){
154 return false;
155 }
156 const xAOD::MuonRoIContainer* muonrois = 0;
157 StatusCode sc = evtStore()->retrieve(muonrois,"LVL1MuonRoIs");
158 if(!sc){
159 ATH_MSG_ERROR("TrigMuonMatching::matchL1 : could not retrieve LVL1MuonRoIs");
160 return false;
161 }
162 xAOD::MuonRoIContainer::const_iterator muroi_itr = muonrois->begin();
163 xAOD::MuonRoIContainer::const_iterator muroi_end = muonrois->end();
164 Int_t threshold = getL1pt(l1item);
165 unsigned int ROI = 0;
166 for( ; muroi_itr != muroi_end; ++muroi_itr ) {
167 if(!((*muroi_itr)->thrValue() >= threshold*1000)) continue;
168 ROI = (*muroi_itr)->getRoI();
169 const std::string eventTrigger = chain;
170
171 auto cg = m_trigDecTool->getChainGroup(eventTrigger);
172 auto fc = cg->features(TrigDefs::alsoDeactivateTEs);
173#if defined(XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
174 auto MuFeatureContainers = fc.containerFeature<xAOD::L2StandAloneMuonContainer>("",TrigDefs::alsoDeactivateTEs);
175#else
176 const std::vector< Trig::Feature<xAOD::L2StandAloneMuonContainer> > MuFeatureContainers = fc.get<xAOD::L2StandAloneMuonContainer>("", TrigDefs::alsoDeactivateTEs);
177#endif
178 for(auto mucont : MuFeatureContainers){
179 for(auto muon : *mucont.cptr()){
180 if(muon->roiNumber() == ROI){
181 Double_t dR = TrigMuonMatching::dR(mu->eta(), mu->phi(), muon->eta(), muon->phi());
182 if(dR < DelR) return true;
183 }
184 }
185 }
186 }
187
188 return false;
189 }
190
192 const std::string &chain,
193 const double DelR) const
194 {
195 const std::string eventTrigger = chain;
196
197 auto cg = m_trigDecTool->getChainGroup(eventTrigger);
198 auto fc = cg->features(TrigDefs::alsoDeactivateTEs);
199#if defined(XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
200 auto MuFeatureContainers = fc.containerFeature<xAOD::L2CombinedMuonContainer>("",TrigDefs::alsoDeactivateTEs);
201#else
202 const std::vector< Trig::Feature<xAOD::L2CombinedMuonContainer> > MuFeatureContainers = fc.get<xAOD::L2CombinedMuonContainer>("", TrigDefs::alsoDeactivateTEs);
203#endif
204
205 for(auto mucont : MuFeatureContainers){
206 for(auto muon : *mucont.cptr()){
207 Double_t dR = TrigMuonMatching::dR(mu->eta(), mu->phi(), muon->eta(), muon->phi());
208 if(dR < DelR) return true;
209 }
210 }
211 return false;
212 }
213
214 Bool_t TrigMuonMatching::matchDimuon(const TLorentzVector& muon1,
215 const TLorentzVector& muon2,
216 const std::string& chain,
217 std::pair<Bool_t, Bool_t>& result1,
218 std::pair<Bool_t, Bool_t>& result2,
219 const Double_t& mindelR)
220 {
221 Double_t delmin = mindelR;
222 DimuonChainInfo chainInfo(chain);
223 if (not decodeDimuonChain(chainInfo)) {
224 ATH_MSG_ERROR("TrigMuonMatching : Failed to decode chain " << chain << " matchDimuon can accept only chains named HLT_2muXX and HLT_muXX_mu8noL1.");
225 return false;
226 }
227
228 std::pair<Bool_t, Bool_t> rc12, rc21;
229 rc12 = matchDimuon(muon1, muon2, chainInfo, delmin);
230 if(chainInfo.isSymmetric){
231 rc21.first = rc12.second; rc21.second = rc12.first;
232 }
233
234 else{
235 rc21 = matchDimuon(muon2, muon1, chainInfo, delmin);
236 }
237
238 result1.first = rc12.first; result1.second = rc21.second;
239 result2.first = rc21.first; result2.second = rc12.second;
240 return true;
241 }
242
243 Bool_t TrigMuonMatching::isPassedRerun(const std::string& trigger) const
244 {
245 const unsigned int bits = m_trigDecTool->isPassedBits(trigger);
246 if( (bits & TrigDefs::EF_passedRaw) && ! ( bits & TrigDefs::EF_passThrough) && ( bits & TrigDefs::EF_resurrected)){
247 return true;
248 }
249 return false;
250 }
251
252 std::pair<Bool_t, Bool_t> TrigMuonMatching::matchDimuon(const TLorentzVector& muon1,
253 const TLorentzVector& muon2,
254 const DimuonChainInfo& chainInfo,
255 const double mindelR)
256 {
257
258 EFmuon trkId1, trkId2, dummy;
259 const Double_t dr1 = matchedTrackDetail(trkId1, dummy, muon1.Eta(), muon1.Phi(), mindelR, chainInfo.thresholds.first);
260
261 // for full scan trigger.
262
263 const Double_t dr2 = matchedTrackDetail(trkId2, dummy, muon2.Eta(), muon2.Phi(), mindelR, chainInfo.thresholds.second);
264
265 if(trkId1.valid && trkId2.valid &&
266 isEqual(trkId1.pt, trkId2.pt) &&
267 isEqual(trkId1.eta, trkId2.eta) &&
268 isEqual(trkId1.phi, trkId2.phi)){
269 if(dr1 > dr2){
270 matchedTrackDetail(trkId1, trkId2, muon1.Eta(), muon1.Phi(), mindelR, chainInfo.thresholds.first);
271 }
272 else{
273 matchedTrackDetail(trkId2, trkId1, muon2.Eta(), muon2.Phi(), mindelR, chainInfo.thresholds.second);
274 }
275 }
276
277 return std::pair<Bool_t, Bool_t> (trkId1.valid, trkId2.valid);
278 }
279
280
281
282 double TrigMuonMatching::dR(const double eta1,
283 const double phi1,
284 const double eta2,
285 const double phi2) const
286 {
287 double deta = fabs(eta1 - eta2);
288 double dphi = fabs(phi1 - phi2) < TMath::Pi() ? fabs(phi1 - phi2) : 2*TMath:: \
289 Pi() - fabs(phi1 - phi2);
290 return sqrt(deta*deta + dphi*dphi);
291 }
292
293
294 int TrigMuonMatching::getL1pt(const std::string& l1item) const
295 {
296 int rc = -1;
297
298 std::vector<std::string> tokens;
299 tokenize(l1item, tokens, "_");
300 std::string pt;
301 if (tokens.size() == 1) {
302 pt = tokens.at(0);
303
304 } else if ((tokens.size() == 2 ) and (tokens.at(0) == "L1")) {
305 pt = tokens.at(1);
306
307 } else {
308 ATH_MSG_ERROR("TrigMuonMatching::getL1pt : cannot parse " << l1item);
309 return rc;
310 }
311
312 const size_t index = pt.find("MU");
313 if (index != std::string::npos) {
314 std::istringstream iss(pt.substr(index + 2));
315 iss >> rc;
316 } else {
317 ATH_MSG_ERROR("TrigMuonMatching::getL1pt : cannot parse " << l1item);
318 }
319
320 return rc;
321 }
322
323
324 void TrigMuonMatching::tokenize(const std::string& str,
325 std::vector<std::string>& tokens,
326 const std::string& delimiters) const
327 {
328 tokens.clear();
329 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
330 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
331
332 while ((std::string::npos != pos) or (std::string::npos != lastPos)) {
333 tokens.push_back(str.substr(lastPos, pos - lastPos));
334 lastPos = str.find_first_not_of(delimiters, pos);
335 pos = str.find_first_of(delimiters, lastPos);
336 }
337 }
338
339
341 const EFmuon& usedEFMuonId,
342 const double eta,
343 const double phi,
344 const double mindelR,
345 const std::string& chainForEventTrigger) const
346 {
347 efMuonId.valid = false;
348 Double_t drmin = mindelR;
349
350 const std::string eventTrigger = chainForEventTrigger;
351
352 auto cg = m_trigDecTool->getChainGroup(eventTrigger);
353 auto fc = cg->features();
354
355#if defined(XAOD_STANDALONE) || defined(XAOD_ANALYSIS)
356 auto MuFeatureContainers = fc.containerFeature<xAOD::MuonContainer>();
357#else
358 const std::vector< Trig::Feature<xAOD::MuonContainer> > MuFeatureContainers = fc.get<xAOD::MuonContainer>();
359#endif
360
361 for(auto mucont : MuFeatureContainers){
362 for(auto mu : *mucont.cptr()){
363
364 // l1 matching
365
366 if(isEqual(usedEFMuonId.pt, mu->pt()) &&
367 isEqual(usedEFMuonId.eta, mu->eta()) &&
368 isEqual(usedEFMuonId.phi, mu->phi())) continue;
369
370 Double_t dr = dR(eta,phi,mu->eta(),mu->phi());
371 if(drmin > dr){
372 drmin = dr;
373 efMuonId.pt = mu->pt();
374 efMuonId.eta = mu->eta();
375 efMuonId.phi = mu->phi();
376 efMuonId.valid = true;
377 }
378 }
379 }
380 return drmin;
381 }
382
383 /*
384 double TrigMuonMatching::matchedTrackDetail(const double eta,
385 const double phi,
386 const std::string chain,
387 const std::string l1item)
388 {
389 auto cg = m_trigDecTool->getChainGroup(chain);
390 auto fc = cg->features();
391 auto MuFeatureContainers = fc.containerFeature<xAOD::MuonContainer>();
392 double dR_min = m_matchingDr;
393 for(auto mucont : MuFeatureContainers){
394
395 // l1 item matching
396
397 for(auto mu : *mucont.cptr()){
398
399 // l1 item matching
400 double dr = dR(eta,phi,mu->eta(),mu->phi());
401 if(dr < dR_min ) dR_min = dr;
402 }
403 }
404 return dR_min;
405 }
406 */
407
409 {
410 chainInfo.isValid = false;
411 std::map<std::string, DimuonChainInfo >::const_iterator p = m_DimuonChainMap.find(chainInfo.chain);
412 if (p != m_DimuonChainMap.end()) {
413 chainInfo = p->second;
414 return chainInfo.isValid;
415 }
416 std::vector<std::string> tokens;
417 tokenize(chainInfo.chain, tokens, "_");
418 if (tokens.size() < 2) return false;
419 if (tokens[0] != "HLT") return false;
420 chainInfo.isSymmetric = (tokens[1].substr(0, 3) == "2mu");
421
422 if(chainInfo.isSymmetric) {
423 std::string threshold = std::string("HLT_" + tokens[1].substr(1));
424 chainInfo.thresholds.first = threshold;
425 chainInfo.thresholds.second = threshold;
426 chainInfo.isValid = true;
427 //if (tokens.size() == 3) chainInfo.tightness = tokens[2];
428 }
429 else {
430 if(tokens.size() != 3) return false;
431
432 std::string high = std::string("HLT_" + tokens[1]);
433 chainInfo.thresholds.first = high;
434 chainInfo.thresholds.second = chainInfo.chain;
435 chainInfo.isValid = true;
436 return chainInfo.isValid;
437
438 }
439 m_DimuonChainMap[chainInfo.chain] = chainInfo;
440 return chainInfo.isValid;
441 }
442
443 bool TrigMuonMatching::isEqual(const double x,
444 const double y) const
445 {
446 if (fabs(x - y) < std::numeric_limits<float>::epsilon()) return true;
447 return false;
448 }
449
450} // namespace CP
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
static Double_t sc
static Double_t rc
A number of constexpr particle constants to avoid hardcoding them directly in various places.
#define MUONMASS
#define y
#define x
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Double_t matchedTrackDetail(EFmuon &efMuonId, const EFmuon &usedEFMuonId, const double eta, const double phi, const double mindelR, const std::string &chainEventTrigger) const
TrigMuonMatching(const std::string &name)
void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters) const
std::map< std::string, DimuonChainInfo > m_DimuonChainMap
bool isEqual(const double x, const double y) const
virtual Double_t minDelR(const xAOD::Muon *mu, const std::string &chain, const double mindelR=0.1) const override
virtual Bool_t match(const xAOD::Muon *mu, const std::string &chain, const double mindelR=0.1) const override
ToolHandle< Trig::TrigDecisionTool > m_trigDecTool
virtual Double_t minDelRL1(const xAOD::Muon *mu, const std::string &l1item, const double DelR=0.2) const override
virtual Bool_t matchL2SA(const xAOD::Muon *mu, const std::string &l1item, const std::string &chain, const double DelR=0.2) const override
bool decodeDimuonChain(DimuonChainInfo &chainInfo)
virtual StatusCode initialize(void) override
Dummy implementation of the initialisation function.
virtual Bool_t matchL2CB(const xAOD::Muon *mu, const std::string &chain, const double DelR=0.2) const override
virtual Bool_t matchDimuon(const xAOD::Muon *mu1, const xAOD::Muon *mu2, const std::string &chain, std::pair< Bool_t, Bool_t > &result1, std::pair< Bool_t, Bool_t > &result2, const Double_t &mindelR=0.1) override
double dR(const double eta1, const double phi1, const double eta2, const double phi2) const
virtual Bool_t isPassedRerun(const std::string &trigger) const override
int getL1pt(const std::string &l1item) const
virtual Bool_t matchL1(const xAOD::Muon *mu, const std::string &l1item, const double DelR=0.2) const override
AsgMetadataTool(const std::string &name)
Normal ASG tool constructor with a name.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
The common trigger namespace for trigger analysis tools.
Definition index.py:1
MuonRoIContainer_v1 MuonRoIContainer
L2CombinedMuonContainer_v1 L2CombinedMuonContainer
Define the latest version of the muon CB container.
L2StandAloneMuonContainer_v2 L2StandAloneMuonContainer
Define the latest version of the muon SA container.
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
std::pair< std::string, std::string > thresholds