ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMuonEFIdtpHypoTool.cxx
Go to the documentation of this file.
1/*
2# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "GaudiKernel/SystemOfUnits.h"
6
10
11class ISvcLocator;
12
13// --------------------------------------------------------------------------------
14// --------------------------------------------------------------------------------
15
16TrigMuonEFIdtpHypoTool::TrigMuonEFIdtpHypoTool(const std::string & type, const std::string & name, const IInterface* parent):
17 AthAlgTool(type, name, parent),
18 m_decisionId(HLT::Identifier::fromToolName(name)) {
19}
20
21// --------------------------------------------------------------------------------
22// --------------------------------------------------------------------------------
23
25{
26 if( m_muonqualityCut ) {
27 if(m_muonSelTool.retrieve().isFailure()) {
28 ATH_MSG_ERROR("Unable to retrieve " << m_muonSelTool);
29 return StatusCode::FAILURE;
30 }
31 } else m_muonSelTool.disable();
32
33 if( m_acceptAll ) {
34 ATH_MSG_DEBUG("Accepting all the events!");
35 } else {
36 if(m_ptBins.size()<=0) {
37 ATH_MSG_ERROR("Trying to configure hypo with no pT bins. This is probably a configuration mistake.");
38 return StatusCode::FAILURE;
39 }
40 m_bins.resize(m_ptBins.size());
41 for(size_t j=0; j<m_ptBins.size(); j++){
42 m_bins[j] = m_ptBins[j].size() - 1;
43 if (m_bins[j] != m_ptThresholds[j].size()) {
44 ATH_MSG_ERROR("bad thresholds setup .... exiting!");
45 return StatusCode::FAILURE;
46 }
47 if (msgLvl(MSG::DEBUG)) {
48 for (std::vector<float>::size_type i=0; i<m_bins[j];++i) {
49 ATH_MSG_DEBUG( "bin " << m_ptBins[j][i] << " - " << m_ptBins[j][i+1]<<" with Pt Threshold of " << (m_ptThresholds[j][i])/Gaudi::Units::GeV<< " GeV");
50 }
51 }
52 }
53 }
54
55 if ( not m_monTool.name().empty() ) {
56 ATH_CHECK( m_monTool.retrieve() );
57 ATH_MSG_DEBUG("MonTool name: " << m_monTool);
58 }
59
60 return StatusCode::SUCCESS;
61}
62
63// --------------------------------------------------------------------------------
64// --------------------------------------------------------------------------------
65
67{
68 // for pass through mode
69 if(m_acceptAll) {
70 ATH_MSG_DEBUG("Accept property is set: taking all the events");
71 return true;
72 }
73
74 const xAOD::Muon* muon = input.muon;
75 if( !muon ){
76 ATH_MSG_ERROR("Retrieval of xAOD::MuonContainer failed");
77 return false;
78 }
79 if(! muon->primaryTrackParticle()) return false;
80
81 const xAOD::TrackParticle* tr = muon->trackParticle(xAOD::Muon::TrackParticleType::ExtrapolatedMuonSpectrometerTrackParticle);
82 if ( !tr ) {
83 ATH_MSG_DEBUG("No TrackParticle found.");
84 return false;
85 }
86
87 // monitored Variables
88 std::vector<float> fexPt, fexEta, fexPhi, selPt, selEta, selPhi;
89 auto muonPtMon = Monitored::Collection("SA_pt", fexPt);
90 auto muonEtaMon = Monitored::Collection("SA_eta", fexEta);
91 auto muonPhiMon = Monitored::Collection("SA_phi", fexPhi);
92 auto muonPtSelMon = Monitored::Collection("SA_pt_sel", selPt);
93 auto muonEtaSelMon = Monitored::Collection("SA_eta_sel", selEta);
94 auto muonPhiSelMon = Monitored::Collection("SA_phi_sel", selPhi);
95 auto monitorIt = Monitored::Group(m_monTool, muonPtMon, muonEtaMon, muonPhiMon, muonPtSelMon, muonEtaSelMon, muonPhiSelMon);
96
97 //
98 bool result = false;
99
100 ATH_MSG_VERBOSE("Retrieved track with abs pt "<< (*tr).pt()/Gaudi::Units::GeV << " GeV ");
101 fexPt.push_back(tr->pt()/Gaudi::Units::GeV);
102 fexEta.push_back(tr->eta());
103 fexPhi.push_back(tr->phi());
104
105 // apply hypo cuts
106 float absEta = std::abs(tr->eta());
107 float threshold = 0;
108 for (std::vector<float>::size_type k=0; k<m_bins[0]; ++k) {
109 if (absEta > m_ptBins[cutIndex][k] && absEta <= m_ptBins[cutIndex][k+1]) threshold = m_ptThresholds[cutIndex][k];
110 }
111 if ( (std::abs(tr->pt())/Gaudi::Units::GeV > (threshold/Gaudi::Units::GeV)) &&
112 ( (!m_muonqualityCut) || (m_muonqualityCut && passedQualityCuts(muon)) ) ) { // selection passed
113 result = true;
114 selPt.push_back(tr->pt()/Gaudi::Units::GeV);
115 selEta.push_back(tr->eta());
116 selPhi.push_back(tr->phi());
117 }
118
119 ATH_MSG_VERBOSE(" REGTEST muon pt is " << tr->pt()/Gaudi::Units::GeV << " GeV "
120 << " with Charge " << tr->charge()
121 << " and threshold cut is " << threshold/Gaudi::Units::GeV << " GeV"
122 << " so hypothesis is " << (result?"true":"false"));
123
124 // hypo result
125 return result;
126}
127
128// --------------------------------------------------------------------------------
129// --------------------------------------------------------------------------------
130
132{
133 bool passCut = false;
134
135 const xAOD::TrackParticle* metrack = muon->trackParticle( xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle );
136 float reducedChi2 = -10;
137
138 if( metrack ) {
139 reducedChi2 = muon->primaryTrackParticle()->chiSquared()/muon->primaryTrackParticle()->numberDoF();
140 // Selection criteria based on the requirements that are part of the muon quality working points (offline)
141 if(std::abs(reducedChi2) < 8.0 && !m_muonSelTool->isBadMuon(*muon) && muon->author()==xAOD::Muon::MuidSA) passCut = true;
142 }
143
144 return passCut;
145}
146
147// --------------------------------------------------------------------------------
148// --------------------------------------------------------------------------------
149
150StatusCode TrigMuonEFIdtpHypoTool::decide(std::vector<MuonEFIdperfInfo>& toolInput) const
151{
152 size_t numTrigger = m_ptBins.size();
153 size_t numMuon=toolInput.size();
154 if(numTrigger==1){
155 ATH_MSG_DEBUG("Applying selection of single << " << m_decisionId);
156 return inclusiveSelection(toolInput);
157 }
158 else{
159 ATH_MSG_DEBUG("Applying selection of multiplicity "<< m_decisionId<<" with nMuons"<<numMuon);
160 return multiplicitySelection(toolInput);
161 }
162 return StatusCode::SUCCESS;
163}
164
165// --------------------------------------------------------------------------------
166// --------------------------------------------------------------------------------
167
168StatusCode TrigMuonEFIdtpHypoTool::inclusiveSelection(std::vector<MuonEFIdperfInfo>& toolInput) const
169{
170 for(auto& tool : toolInput) {
171 if(TrigCompositeUtils::passed(m_decisionId.numeric(), tool.previousDecisionIDs)){
172 if(decideOnSingleObject(tool, 0)) {
173 ATH_MSG_DEBUG("Passes selection");
175 }
176 }
177 else ATH_MSG_DEBUG("Does not pass selection");
178 }
179
180 return StatusCode::SUCCESS;
181}
182
183// --------------------------------------------------------------------------------
184// --------------------------------------------------------------------------------
185
186StatusCode TrigMuonEFIdtpHypoTool::multiplicitySelection(std::vector<MuonEFIdperfInfo>& toolInput) const
187{
188 HLT::Index2DVec passingSelection(m_ptBins.size());
189 for(size_t cutIndex=0; cutIndex < m_ptBins.size(); ++cutIndex) {
190 size_t elementIndex{0};
191 for(auto& tool : toolInput) {
192 if(TrigCompositeUtils::passed(m_decisionId.numeric(), tool.previousDecisionIDs)){
193 if(decideOnSingleObject(tool, cutIndex)){
194 ATH_MSG_DEBUG("Passing selection "<<m_decisionId << " , Index["<<elementIndex<<"]");
195 passingSelection[cutIndex].push_back(elementIndex);
196 }
197 else ATH_MSG_DEBUG("Not passing selection "<<m_decisionId << " , Index["<<elementIndex<<"]");
198 }
199 else{
200 ATH_MSG_DEBUG("No match for decisionId "<<m_decisionId);
201 }
202 elementIndex++;
203 }
204 //If nothing passes, then we should stop
205 if(passingSelection[cutIndex].empty()){
206 ATH_MSG_DEBUG("No muons passed the selection "<<cutIndex<<" rejecting...");
207 return StatusCode::SUCCESS;
208 }
209 }
210 std::set<size_t> passingIndices;
211 HLT::elementsInUniqueCombinations(passingSelection, passingIndices);
212
213 if(passingIndices.empty()) {
214 ATH_MSG_DEBUG("No muons passed selection "<<m_decisionId);
215 return StatusCode::SUCCESS;
216 }
217 for(auto i : passingIndices) {
218 ATH_MSG_DEBUG("Muon["<<i<<"] passes "<<m_decisionId<<" with pT = "<<toolInput[i].muon->pt()/Gaudi::Units::GeV << "GeV");
219 TrigCompositeUtils::addDecisionID(m_decisionId.numeric(), toolInput[i].decision);
220 }
221
222 //
223 return StatusCode::SUCCESS;
224}
225
226// --------------------------------------------------------------------------------
227// --------------------------------------------------------------------------------
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
static const Attributes_t empty
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
bool msgLvl(const MSG::Level lvl) const
Group of local monitoring quantities and retain correlation when filling histograms
StatusCode decide(std::vector< TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo > &toolInput) const
Gaudi::Property< std::vector< std::vector< double > > > m_ptBins
StatusCode multiplicitySelection(std::vector< TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo > &toolInput) const
ToolHandle< GenericMonitoringTool > m_monTool
Gaudi::Property< bool > m_muonqualityCut
bool passedQualityCuts(const xAOD::Muon *muon) const
bool decideOnSingleObject(TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo &input, size_t cutIndex) const
StatusCode inclusiveSelection(std::vector< TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo > &toolInput) const
std::vector< size_t > m_bins
TrigMuonEFIdtpHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< std::vector< std::vector< double > > > m_ptThresholds
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
virtual StatusCode initialize() override
Gaudi::Property< bool > m_acceptAll
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
float charge() const
Returns the charge.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
void elementsInUniqueCombinations(const Index2DVec &indices, std::set< size_t > &participants, const std::function< bool(const Index1DVec &)> &filter)
std::vector< Index1DVec > Index2DVec
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version: