ATLAS Offline Software
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 
11 class ISvcLocator;
12 
13 // --------------------------------------------------------------------------------
14 // --------------------------------------------------------------------------------
15 
16 TrigMuonEFIdtpHypoTool::TrigMuonEFIdtpHypoTool(const std::string & type, const std::string & name, const IInterface* 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 
150 StatusCode 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 
168 StatusCode 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 
186 StatusCode 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");
220  }
221 
222  //
223  return StatusCode::SUCCESS;
224 }
225 
226 // --------------------------------------------------------------------------------
227 // --------------------------------------------------------------------------------
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
get_generator_info.result
result
Definition: get_generator_info.py:21
TrigMuonEFIdtpHypoTool::m_acceptAll
Gaudi::Property< bool > m_acceptAll
Definition: TrigMuonEFIdtpHypoTool.h:66
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
HLT::Identifier::numeric
TrigCompositeUtils::DecisionID numeric() const
numeric ID
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:47
xAOD::TrackParticle_v1::charge
float charge() const
Returns the charge.
Definition: TrackParticle_v1.cxx:150
TrigMuonEFIdtpHypoTool::m_muonSelTool
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Definition: TrigMuonEFIdtpHypoTool.h:72
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
TrigCompositeUtils::addDecisionID
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
Definition: TrigCompositeUtilsRoot.cxx:61
TrigMuonEFIdtpHypoTool::initialize
virtual StatusCode initialize() override
Definition: TrigMuonEFIdtpHypoTool.cxx:24
TrigMuonEFIdtpHypoTool.h
TrigMuonEFIdtpHypoTool::multiplicitySelection
StatusCode multiplicitySelection(std::vector< TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo > &toolInput) const
Definition: TrigMuonEFIdtpHypoTool.cxx:186
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TrigMuonEFIdtpHypoTool::m_ptBins
Gaudi::Property< std::vector< std::vector< double > > > m_ptBins
Definition: TrigMuonEFIdtpHypoTool.h:62
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
TrigMuonEFIdtpHypoTool::decideOnSingleObject
bool decideOnSingleObject(TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo &input, size_t cutIndex) const
Definition: TrigMuonEFIdtpHypoTool.cxx:66
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigMuonEFIdtpHypoTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigMuonEFIdtpHypoTool.h:71
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TrigMuonEFIdtpHypoTool::m_decisionId
HLT::Identifier m_decisionId
Definition: TrigMuonEFIdtpHypoTool.h:58
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigMuonEFIdtpHypoTool::m_bins
std::vector< size_t > m_bins
Definition: TrigMuonEFIdtpHypoTool.h:70
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrigMuonEFIdtpHypoTool::m_muonqualityCut
Gaudi::Property< bool > m_muonqualityCut
Definition: TrigMuonEFIdtpHypoTool.h:60
HLT::elementsInUniqueCombinations
void elementsInUniqueCombinations(const Index2DVec &indices, std::set< size_t > &participants, std::function< bool(const Index1DVec &)> &&filter)
Definition: Combinators.cxx:154
TrigMuonEFIdtpHypoTool::m_ptThresholds
Gaudi::Property< std::vector< std::vector< double > > > m_ptThresholds
Definition: TrigMuonEFIdtpHypoTool.h:64
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
threshold
Definition: chainparser.cxx:74
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
MuonParameters::MuidSA
@ MuidSA
Definition: MuonParamDefs.h:59
TrigMuonEFIdtpHypoTool::passedQualityCuts
bool passedQualityCuts(const xAOD::Muon *muon) const
Definition: TrigMuonEFIdtpHypoTool.cxx:131
TrigMuonEFIdtpHypoTool::inclusiveSelection
StatusCode inclusiveSelection(std::vector< TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo > &toolInput) const
Definition: TrigMuonEFIdtpHypoTool.cxx:168
Combinators.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
TauGNNUtils::Variables::absEta
bool absEta(const xAOD::TauJet &tau, double &out)
Definition: TauGNNUtils.cxx:232
HLT::Index2DVec
std::vector< Index1DVec > Index2DVec
Definition: TrigCompositeUtils/TrigCompositeUtils/Combinators.h:140
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
TrigMuonEFIdtpHypoTool::TrigMuonEFIdtpHypoTool
TrigMuonEFIdtpHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrigMuonEFIdtpHypoTool.cxx:16
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
TrigMuonEFIdtpHypoTool::decide
StatusCode decide(std::vector< TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo > &toolInput) const
Definition: TrigMuonEFIdtpHypoTool.cxx:150
TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo
Definition: TrigMuonEFIdtpHypoTool.h:27
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
fitman.k
k
Definition: fitman.py:528