ATLAS Offline Software
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 
6 #include "TestMatchingToolAlg.h"
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
27  const xAOD::IParticleContainer *taus = 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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TestMatchingToolAlg::m_tmt
ToolHandle< Trig::IMatchingTool > m_tmt
Definition: TestMatchingToolAlg.h:25
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TestMatchingToolAlg::finalize
virtual StatusCode finalize()
Definition: TestMatchingToolAlg.cxx:110
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
TestMatchingToolAlg::execute
virtual StatusCode execute()
Definition: TestMatchingToolAlg.cxx:18
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IParticleContainer.h
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
TestMatchingToolAlg.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TestMatchingToolAlg::initialize
virtual StatusCode initialize()
Definition: TestMatchingToolAlg.cxx:12
h
TestMatchingToolAlg::m_matches
std::map< std::string, int > m_matches
Definition: TestMatchingToolAlg.h:27
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
read_hist_ntuple.f1
f1
Definition: read_hist_ntuple.py:4