ATLAS Offline Software
util/TrigMuonMatching_example.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 #ifdef ROOTCORE
7 #include "xAODRootAccess/Init.h"
10 #include "AsgMessaging/Check.h"
11 #endif
12 
15 
16 #include "xAODMuon/MuonContainer.h"
18 
20 
21 #include "TChain.h"
22 #include "TError.h"
23 #include "TFile.h"
24 #include "TH1F.h"
25 #include "TLorentzVector.h"
26 #include "TCanvas.h"
27 
28 #include <iostream>
29 
30 using namespace std;
31 using namespace Trig;
32 using namespace TrigConf;
33 using namespace xAOD;
34 
35 // Config
36 const char* APP_NAME = "TrigMuonMatching_example";
37 const char* OUTPUT_FILE = "TrigMuonMatching_example.root";
38 
39 // Helpers
40 TChain *getFilesFromCommandLine(int argc, char* argv[]);
41 
42 int main( int argc, char* argv[] ) {
43 
44  // Initialize (as done for all xAOD standalone programs!)
46 
48  if (chain == nullptr) {
49  return 1;
50  }
51 
52  // The TEvent object
53  TEvent event(TEvent::kBranchAccess);
55 
56  // The configuration tool.
57  xAODConfigTool configTool("xAODConfigTool");
58  ToolHandle<TrigConf::ITrigConfigTool> configHandle(&configTool);
59  ASG_CHECK_SA(APP_NAME,configHandle->initialize());
60 
61  // The decision tool
62  TrigDecisionTool trigDecTool("TrigDecTool");
63  ASG_CHECK_SA(APP_NAME, trigDecTool.setProperty("ConfigTool",configHandle));
64  ASG_CHECK_SA(APP_NAME, trigDecTool.setProperty("TrigDecisionKey","xTrigDecision"));
65  ASG_CHECK_SA(APP_NAME, trigDecTool.initialize());
66  ToolHandle<Trig::TrigDecisionTool> m_trigDec(&trigDecTool);
67 
68  Trig::TrigMuonMatching m_match_Tool("TestMatchClass");
69  ASG_CHECK_SA(APP_NAME, m_match_Tool.setProperty("TriggerTool",m_trigDec));
70  ASG_CHECK_SA(APP_NAME, m_match_Tool.initialize());
71 
73  auto outputFile = TFile::Open(OUTPUT_FILE, "RECREATE");
74  if (outputFile == nullptr || !outputFile->IsOpen()) {
75  return 1;
76  }
77 
78  auto hmu_offline_pt = new TH1F("mu_offline_pt","mu_offline_pt", 100, 0, 300);
79  auto hmu_hltmatch_pt = new TH1F("mu_hltmatch_pt","mu_hltmatch_pt", 100, 0, 300);
80  auto hmu_l1match_pt = new TH1F("mu_l1match_pt","mu_l1match_pt", 100, 0, 300);
81  auto hmu_L2SAmatch_pt = new TH1F("mu_L2SAmatch_pt","mu_L2SAmatch_pt", 100, 0, 300);
82  auto hmu_L2CBmatch_pt = new TH1F("mu_L2CBmatch_pt","mu_L2CBmatch_pt", 100, 0, 300);
83 
84  // Run the files
85  size_t nEntries = chain->GetEntries();
86  for (size_t entry = 0; entry < nEntries; entry++) {
87  event.getEntry(entry);
88 
89  xAOD::MuonContainer* goodMuons = new xAOD::MuonContainer();
90  xAOD::MuonAuxContainer* goodMuonsAux = new xAOD::MuonAuxContainer();
91  goodMuons->setStore(goodMuonsAux);
92 
93  const xAOD::MuonContainer* muons = 0;
94  RETURN_CHECK(APP_NAME, event.retrieve(muons,"Muons"));
95  std::cout << "Number of muons " << muons->size() << std::endl;
96  for(const auto* mu : *muons){
97  std::cout << "muon pt " << mu->pt() << std::endl;
98  hmu_offline_pt->Fill(mu->pt()*0.001);
99  Bool_t ismu26_imedium = false;
100  Bool_t ismu50 = false;
101  ismu26_imedium = m_match_Tool.match(mu,"HLT_mu26_imedium");
102  ismu50 = m_match_Tool.match(mu,"HLT_mu50");
103  if(ismu26_imedium){
104  std::cout << "HLT_mu26_imedium matched." << std::endl;
105  hmu_hltmatch_pt->Fill(mu->pt()*0.001);
106  }
107  if(ismu50)std::cout << "HLT_mu50 matched." << std::endl;
108 
109  // L1
110  Bool_t isMU20 = false;
111  isMU20 = m_match_Tool.matchL1(mu,"L1_MU20");
112  if(isMU20){
113  std::cout << "L1_MU20 matched." << std::endl;
114  hmu_l1match_pt->Fill(mu->pt()*0.001);
115  }
116 
117  // L2SA
118  Bool_t isL2SA = false;
119  isL2SA = m_match_Tool.matchL2SA(mu,"L1_MU20","HLT_mu26_imedium");
120  if(isL2SA){
121  std::cout << "L2SA matched" << std::endl;
122  hmu_L2SAmatch_pt->Fill(mu->pt()*0.001);
123  }
124 
125  // L2CB
126  Bool_t isL2CB = false;
127  isL2CB = m_match_Tool.matchL2CB(mu,"HLT_mu26_imedium");
128  if(isL2CB){
129  std::cout << "L2CB matched" << std::endl;
130  hmu_L2CBmatch_pt->Fill(mu->pt()*0.001);
131  }
132 
133  xAOD::Muon* muon = new xAOD::Muon();
134  muon->makePrivateStore(*mu);
135  goodMuons->push_back(muon);
136  }
137 
138  Int_t index = 0;
139  const xAOD::Muon *mu1 = 0;
140  const xAOD::Muon *mu2 = 0;
141  if(goodMuons->size()==2){
142  for(const auto mu : *goodMuons){
143  if(index == 0) mu1 = mu;
144  if(index == 1) mu2 = mu;
145  index = index + 1;
146  }
147  std::pair<Bool_t,Bool_t> result1, result2;
148  Bool_t valid;
149  valid = m_match_Tool.matchDimuon(mu1, mu2, "HLT_2mu14", result1, result2);
150  if(!valid) std::cout << "not supported 2mu14" << std::endl;
151  if(result1.first && result2.first) std::cout << "HLT_2mu14 matched" << std::endl;
152 
153  std::pair<Bool_t,Bool_t> result3, result4;
154  valid = m_match_Tool.matchDimuon(mu1, mu2, "HLT_mu18_mu8noL1", result3, result4);
155  if(!valid) std::cout << "not supported mu18_mu8noL1" << std::endl;
156  if((result1.first && result2.second) || (result1.second && result2.first)) std::cout << "HLT_mu18_mu8noL1 matched" << std::endl;
157 
158  }
159 
160  }
161 
162  TCanvas* c1 = new TCanvas();
163  hmu_offline_pt -> Draw();
164  hmu_offline_pt ->SetLineColor(1);
165  hmu_hltmatch_pt -> Draw("same");
166  hmu_hltmatch_pt ->SetLineColor(2);
167  hmu_l1match_pt -> Draw("same");
168  hmu_l1match_pt ->SetLineColor(3);
169  hmu_L2SAmatch_pt -> Draw("same");
170  hmu_L2SAmatch_pt ->SetLineColor(4);
171  hmu_L2CBmatch_pt -> Draw("same");
172  hmu_L2CBmatch_pt ->SetLineColor(5);
173  c1->Write();
174 
175  outputFile->Write();
176  outputFile->Close();
177 }
178 
179 TChain *getFilesFromCommandLine(int argc, char* argv[])
180 {
181  if (argc < 2) {
182  ::Error(APP_NAME, "Usage: %s <xAOD file> [xAOD file2]...", APP_NAME);
183  return nullptr;
184  }
185 
186  auto chain = new TChain("CollectionTree");
187  for (int i = 1; i < argc; i++) {
188  chain->Add(argv[i]);
189  }
190 
191  return chain;
192 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
RETURN_CHECK
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition: ReturnCheck.h:26
Trig::TrigMuonMatching::initialize
virtual StatusCode initialize(void) override
Definition: TrigMuonMatching.cxx:32
getFilesFromCommandLine
TChain * getFilesFromCommandLine(int argc, char *argv[])
Definition: util/TrigMuonMatching_example.cxx:179
xAODConfigTool.h
Check.h
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
TrigMuonMatching.h
Trig::TrigMuonMatching
Definition: TrigMuonMatching.h:23
xAOD::MuonContainer
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonContainer.h:14
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
index
Definition: index.py:1
Trig::TrigMuonMatching::matchL1
virtual Bool_t matchL1(const xAOD::Muon *mu, const std::string &l1item, const double DelR=0.2) const override
Definition: TrigMuonMatching.cxx:48
extractSporadic.c1
c1
Definition: extractSporadic.py:134
TrigDecisionTool.h
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
Trig::TrigDecisionTool
Definition: TrigDecisionTool.h:65
ReturnCheck.h
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MuonAuxContainer.h
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
compareGeometries.outputFile
string outputFile
Definition: compareGeometries.py:25
xAOD::MuonAuxContainer_v5
Temporary container used until we have I/O for AuxStoreInternal.
Definition: MuonAuxContainer_v5.h:31
calibdata.valid
list valid
Definition: calibdata.py:45
Trig::TrigMuonMatching::match
virtual Bool_t match(const xAOD::Muon *mu, const std::string &chain, const double mindelR=0.1) const override
Definition: TrigMuonMatching.cxx:41
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
APP_NAME
const char * APP_NAME
Definition: util/TrigMuonMatching_example.cxx:36
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
OUTPUT_FILE
const char * OUTPUT_FILE
Definition: util/TrigMuonMatching_example.cxx:37
TEvent.h
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trig::TrigMuonMatching::matchL2SA
virtual Bool_t matchL2SA(const xAOD::Muon *mu, const std::string &l1item, const std::string &chain, const double DelR=0.2) const override
Definition: TrigMuonMatching.cxx:147
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
MuonContainer.h
main
int main(int argc, char *argv[])
Definition: util/TrigMuonMatching_example.cxx:42
Trig::TrigMuonMatching::matchDimuon
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
Definition: TrigMuonMatching.cxx:89
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
ASG_CHECK_SA
#define ASG_CHECK_SA(SOURCE, EXP)
Helper macro for checking the status code of a call outside of an ASG tool.
Definition: Check.h:69
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
xAOD::MuonAuxContainer
MuonAuxContainer_v5 MuonAuxContainer
Definition of the current Muon auxiliary container.
Definition: MuonAuxContainer.h:19
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Trig::TrigDecisionTool::initialize
StatusCode initialize()
Definition: TrigDecisionTool.cxx:45
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
Trig::TrigMuonMatching::matchL2CB
virtual Bool_t matchL2CB(const xAOD::Muon *mu, const std::string &chain, const double DelR=0.2) const override
Definition: TrigMuonMatching.cxx:190
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
TrigConf::xAODConfigTool
Trigger configuration metadata tool for xAOD analysis.
Definition: xAODConfigTool.h:55