ATLAS Offline Software
Loading...
Searching...
No Matches
TestMatchingToolAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
9#include "TH1D.h"
10#include "TFile.h"
11
13 m_tmt.setTypeAndName("Trig::MatchingTool/MyMatchingTool");
14 CHECK(m_tmt.retrieve()); //important to retrieve here, because TrigDecisionTool must be initialized before event loop
15 return StatusCode::SUCCESS;
16}
17
19
20 //For more documentation on the tool, see: https://twiki.cern.ch/twiki/bin/view/Atlas/XAODMatchingTool
21 //As of Feb 2016:
22 //Recommended threshold for egamma triggers: 0.07
23 //Recommended threshold for muon triggers: 0.1
24
25 //here's an example of using the tool
26 const xAOD::IParticleContainer* electrons = 0;
28 const xAOD::IParticleContainer *muons = 0;
29 CHECK( evtStore()->retrieve( electrons, "Electrons" ));
30 CHECK( evtStore()->retrieve( muons, "Muons" ) );
31 CHECK( evtStore()->retrieve( taus, "TauJets" ) );
32 if(electrons) ATH_MSG_INFO("Offline Electron container size " << electrons->size());
33 if(muons) ATH_MSG_INFO("Offline Muon container size " << muons->size());
34 if(taus) ATH_MSG_INFO("Offline Tau container size " << taus->size());
35 //tool takes a vector of IParticles, and a trigger chain expression
36 //can also take a single IParticle for single object trigger matching
37 std::vector<const xAOD::IParticle*> myParticles;
38
39 //here's an example of a single object trigger
40 bool res(false);
41 if (electrons) {
42 for(uint i = 0; i< electrons->size(); i++) {
43 myParticles.clear();
44 myParticles.push_back( electrons->at(i) );
45 res = m_tmt->match(myParticles,"HLT_e17_lhloose",0.07 /*explicit dR threhsold*/);
46 m_matches["HLT_e17_lhloose"] += res;
47 ATH_MSG_INFO("HLT_e17_lhloose Matching Decision = " << res );
48
49 // here's an example of a combined trigger
50 // e-mu
51 if(muons){
52 for(uint j = 0; j < muons->size(); j++) {
53 myParticles.clear();
54 myParticles.push_back(electrons->at(i));
55 myParticles.push_back(muons->at(j));
56 res = m_tmt->match(myParticles,"HLT_e17_lhloose_mu14");
57 m_matches["HLT_e17_lhloose_mu14"] += res;
58 ATH_MSG_INFO("HLT_e17_lhloose_mu14 = " << res);
59 }
60 }
61 // e-tau
62 if(taus){
63 for(uint j = 0; j < taus->size(); j++) {
64 myParticles.clear();
65 myParticles.push_back(electrons->at(i));
66 myParticles.push_back(taus->at(j));
67 res = m_tmt->match(myParticles,"HLT_e17_lhmedium_iloose_tau25_medium1_tracktwo");
68 m_matches["HLT_e17_lhmedium_iloose_tau25_medium1_tracktwo"] += res;
69 ATH_MSG_INFO("HLT_e17_lhmedium_iloose_tau25_medium1_tracktwo = " << res);
70 }
71 }
72 }
73 }
74
75 // here's an example for muon trigger, using the method for single-object trigger matching
76 if(muons){
77 for(auto muon : *muons) {
78 res = m_tmt->match(*muon,"HLT_mu18");
79 m_matches["HLT_mu18"] += res;
80 ATH_MSG_INFO("HLT_mu18 = " << res);
81 }
82 }
83 // here's an examplefor a tau trigger
84 if(taus){
85 for(uint j = 0; j < taus->size(); j++) {
86 res = m_tmt->match(*taus->at(j),"HLT_tau25_loose1_ptonly");
87 m_matches["HLT_tau25_loose1_ptonly"] += res;
88 ATH_MSG_INFO("HLT_tau25_loose1_ptonly = " << res);
89 }
90 }
91
92 //here's an example for a dilepton trigger
93 //form pairs to test a dilepton trigger
94 if(electrons) {
95 for(uint i = 0; i< electrons->size(); i++) {
96 for(uint j = i+1; j < electrons->size(); j++) {
97 myParticles.clear();
98 myParticles.push_back( electrons->at(i) );
99 myParticles.push_back( electrons->at(j) );
100 res = m_tmt->match(myParticles,"HLT_2e17_lhloose", 0.07);
101 m_matches["HLT_2e17_lhloose"] += res;
102 ATH_MSG_INFO("HLT_2e17_lhloose Matching Decision = " << res );
103 }
104 }
105 }
106
107 return StatusCode::SUCCESS;
108}
109
111 //write results out to a file ... single bin histograms
112 TFile f1("TestMatchingToolAlg.results.root","RECREATE");
113 for(auto& t : m_matches) {
114 TH1D* h = new TH1D(t.first.c_str(),t.first.c_str(),1,0,1);
115 h->SetBinContent(1,t.second);
116 h->Write();
117 }
118 f1.Close();
119 return StatusCode::SUCCESS;
120}
121
#define ATH_MSG_INFO(x)
#define CHECK(...)
Evaluate an expression and check for errors.
std::pair< std::vector< unsigned int >, bool > res
unsigned int uint
static Double_t taus
Header file for AthHistogramAlgorithm.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
ToolHandle< Trig::IMatchingTool > m_tmt
std::map< std::string, int > m_matches
virtual StatusCode finalize()
virtual StatusCode execute()
virtual StatusCode initialize()
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.