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
18StatusCode TestMatchingToolAlg::execute(const EventContext& /*ctx*/) {
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
53 for(uint j = 0; j < muons->size(); j++) {
54 myParticles.clear();
55 myParticles.push_back(electrons->at(i));
56 myParticles.push_back(muons->at(j));
57 res = m_tmt->match(myParticles,"HLT_e17_lhloose_mu14");
58 m_matches["HLT_e17_lhloose_mu14"] += res;
59 ATH_MSG_INFO("HLT_e17_lhloose_mu14 = " << res);
60 }
61 }
62 // e-tau
63 if(taus){
64 for(uint j = 0; j < taus->size(); j++) {
65 myParticles.clear();
66 myParticles.push_back(electrons->at(i));
67 myParticles.push_back(taus->at(j));
68 res = m_tmt->match(myParticles,"HLT_e17_lhmedium_iloose_tau25_medium1_tracktwo");
69 m_matches["HLT_e17_lhmedium_iloose_tau25_medium1_tracktwo"] += res;
70 ATH_MSG_INFO("HLT_e17_lhmedium_iloose_tau25_medium1_tracktwo = " << res);
71 }
72 }
73 }
74 }
75
76 // here's an example for muon trigger, using the method for single-object trigger matching
77 if(muons){
78 for(auto muon : *muons) {
79 res = m_tmt->match(*muon,"HLT_mu18");
80 m_matches["HLT_mu18"] += res;
81 ATH_MSG_INFO("HLT_mu18 = " << res);
82 }
83 }
84 // here's an examplefor a tau trigger
85 if(taus){
86 for(uint j = 0; j < taus->size(); j++) {
87 res = m_tmt->match(*taus->at(j),"HLT_tau25_loose1_ptonly");
88 m_matches["HLT_tau25_loose1_ptonly"] += res;
89 ATH_MSG_INFO("HLT_tau25_loose1_ptonly = " << res);
90 }
91 }
92
93 //here's an example for a dilepton trigger
94 //form pairs to test a dilepton trigger
95 if(electrons) {
96 for(uint i = 0; i< electrons->size(); i++) {
97 for(uint j = i+1; j < electrons->size(); j++) {
98 myParticles.clear();
99 myParticles.push_back( electrons->at(i) );
100 myParticles.push_back( electrons->at(j) );
101 res = m_tmt->match(myParticles,"HLT_2e17_lhloose", 0.07);
102 m_matches["HLT_2e17_lhloose"] += res;
103 ATH_MSG_INFO("HLT_2e17_lhloose Matching Decision = " << res );
104 }
105 }
106 }
107
108 return StatusCode::SUCCESS;
109}
110
112 //write results out to a file ... single bin histograms
113 TFile f1("TestMatchingToolAlg.results.root","RECREATE");
114 for(auto& t : m_matches) {
115 TH1D* h = new TH1D(t.first.c_str(),t.first.c_str(),1,0,1);
116 h->SetBinContent(1,t.second);
117 h->Write();
118 }
119 f1.Close();
120 return StatusCode::SUCCESS;
121}
122
#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
ServiceHandle< StoreGateSvc > & evtStore()
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(const EventContext &ctx)
Execute method.
virtual StatusCode initialize()
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.