ATLAS Offline Software
TrigMuonEFTrackIsolationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
10  ISvcLocator* pSvcLocator )
11  :AthReentrantAlgorithm(name, pSvcLocator),
12  m_coneSizes()
13 {
14  // cone sizes are hard-coded to ensure the correct result goes to the edm
15  m_coneSizes.push_back(0.2);
16  m_coneSizes.push_back(0.3);
17 }
18 
19 
21 {
22  ATH_MSG_DEBUG("Initialization");
23 
24  ATH_MSG_DEBUG("*** Properties set as follows ***");
25  ATH_MSG_DEBUG("Track isolation tool : " << m_onlineEfIsoTool);
26  ATH_MSG_DEBUG("TrackParticles : " << m_trackParticleKey.key());
27  ATH_MSG_DEBUG("EFMuonParticles : " << m_efMuonContainerKey.key());
28  ATH_MSG_DEBUG("requireCombinedMuon : " << m_requireCombined);
29  ATH_MSG_DEBUG("useVarIso : " << m_useVarIso);
30 
32  ATH_CHECK( m_efMuonContainerKey.initialize() );
33  ATH_CHECK( m_muonContainerKey.initialize() );
34  ATH_CHECK( m_muonIso20Key.initialize() );
35  ATH_CHECK( m_muonIso30Key.initialize() );
36 
37 
38 
39  ATH_CHECK( m_onlineEfIsoTool.retrieve() );
40 
41  if ( not m_monTool.name().empty() ) {
42  ATH_CHECK( m_monTool.retrieve() );
43  }
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 
49 StatusCode TrigMuonEFTrackIsolationAlg::execute(const EventContext& ctx) const
50 {
51  ATH_MSG_DEBUG("Execution");
52 
53 
54  // variables to initialize and keep values for monitoring variables
55  std::vector<double> ini_cone2(0);
56  std::vector<double> ini_cone3(0);
57  std::vector<double> ini_trkdz(0);
58  std::vector<double> ini_trkdr(0);
59  std::vector<double> ini_selfpt(0);
60  std::vector<double> ini_removedpt(0);
61  std::vector<double> ini_combinedpt(0);
62  std::vector<int> ini_ntrks(0);
63 
64  // Monitoring histogram
65  auto trkptiso_cone2 = Monitored::Collection("trks_trkptiso_cone2", ini_cone2);
66  auto trkptiso_cone3 = Monitored::Collection("trks_trkptiso_cone3", ini_cone3);
67  auto trkdz = Monitored::Collection("trks_trkdz", ini_trkdz);
68  auto trkdr = Monitored::Collection("trks_trksdr", ini_trkdr);
69  auto muon_selfpt = Monitored::Collection("muon_selfpt", ini_selfpt);
70  auto muon_removedpt = Monitored::Collection("muon_removedpt", ini_removedpt);
71  auto muon_combinedpt = Monitored::Collection("muon_combinedpt", ini_combinedpt);
72  auto n_trks = Monitored::Collection("n_trks", ini_ntrks);
73 
74  auto monitorIt = Monitored::Group( m_monTool, trkptiso_cone2, trkptiso_cone3, trkdz, trkdr,
75  muon_selfpt, muon_removedpt, muon_combinedpt, n_trks );
76 
77  // get input objects
78  const xAOD::TrackParticleContainer *idTrackParticles = nullptr;
79  const xAOD::MuonContainer *efMuonContainer = nullptr;
80 
81  auto idTrackHandle = SG::makeHandle( m_trackParticleKey, ctx );
82  if( !idTrackHandle.isValid() ) {
83  ATH_MSG_ERROR("Failed to retrieve inner detector track particles");
84  return StatusCode::FAILURE;
85  }
86  idTrackParticles = idTrackHandle.cptr();
87  ATH_MSG_DEBUG("Inner detector track particles retrieved with size : " << idTrackHandle->size() << "...");
88 
89  auto efMuonHandle = SG::makeHandle( m_efMuonContainerKey, ctx );
90  if ( !efMuonHandle.isValid() ) {
91  ATH_MSG_ERROR("Failed to retrieve EF Muon Container " << m_efMuonContainerKey.key());
92  return StatusCode::FAILURE;
93  }
94  efMuonContainer = efMuonHandle.cptr();
95  ATH_MSG_DEBUG("EF Muons retrieved with size : " << efMuonHandle->size());
96 
97 
98  // start calculation
99  // prepare output
101 
102  StatusCode result = StatusCode::SUCCESS;
103  std::vector<double> isoResults;
104  std::vector<double> dzvals; // for monitoring
105  std::vector<double> drvals; // for monitoring
106  std::vector<double> selfremoval;
107 
109  ATH_CHECK(muonOutput.record(std::make_unique<xAOD::MuonContainer>(), std::make_unique<xAOD::MuonAuxContainer>()));
110  ATH_MSG_DEBUG("Record EF isolation muon : " << m_muonContainerKey.key());
111  muonContainer = muonOutput.ptr();
112 
115 
116  for ( auto muon : *efMuonContainer ) {
117  const xAOD::Muon::MuonType muonType = muon->muonType();
118  if ( muonType!=xAOD::Muon::MuonType::Combined) {
119  if ( m_requireCombined ) {
120  ATH_MSG_DEBUG("Not a combined or muon & requiredCombined = true, so ignore this muon");
121  continue;
122  } else {
123  if ( muonType!=xAOD::Muon::MuonType::MuonStandAlone ) {
124  ATH_MSG_DEBUG("EF muon hsa neither combined, segment tagged, nor standalone muon");
125  continue;
126  }
127  }
128  }
129  result = m_onlineEfIsoTool->calcTrackIsolation( muon, idTrackParticles, m_coneSizes, isoResults, &dzvals, &drvals, &selfremoval );
130 
131  ini_trkdz.insert( ini_trkdz.begin(), dzvals.begin(), dzvals.end());
132  ini_trkdr.insert( ini_trkdr.begin(), drvals.begin(), drvals.end());
133  if ( selfremoval.size()==2 ) {
134  ini_selfpt.push_back(selfremoval[0]*1e-3); // convert to GeV
135  ini_combinedpt.push_back(selfremoval[1]*1e-3); // convert to GeV
136  }
137 
138  if ( result.isFailure() || isoResults.size()!=2 ) {
139  ATH_MSG_WARNING("Isolation will not be set for this muon. result.isFailure: "<<result.isFailure()<<" isoResults.size: "<<isoResults.size());
140  }
141  else { // isolation tool was ok - store results
143  xAOD::Muon* outputmuon = muonContainer->back();
144  muonptCone20(*outputmuon) = isoResults[0];
145  muonptCone30(*outputmuon) = isoResults[1];
146  ini_cone2.push_back(isoResults[0]*1e-3); // convert to GeV
147  ini_cone3.push_back(isoResults[1]*1e-3); // convert to GeV
148  }
149  }//loop over muons
150 
151 
152  return StatusCode::SUCCESS;
153 }
muonContainer
xAOD::MuonContainer * muonContainer
Definition: TrigGlobEffCorrValidation.cxx:188
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
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
TrigMuonEFTrackIsolationAlg.h
TrigMuonEFTrackIsolationAlg::m_coneSizes
std::vector< double > m_coneSizes
Definition: TrigMuonEFTrackIsolationAlg.h:70
TrigMuonEFTrackIsolationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
execute execute the combined muon FEX.
Definition: TrigMuonEFTrackIsolationAlg.cxx:49
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigMuonEFTrackIsolationAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigMuonEFTrackIsolationAlg.h:73
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
MuonAuxContainer.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TrigMuonEFTrackIsolationAlg::m_efMuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_efMuonContainerKey
Definition: TrigMuonEFTrackIsolationAlg.h:50
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
TrigMuonEFTrackIsolationAlg::m_muonIso30Key
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonIso30Key
Definition: TrigMuonEFTrackIsolationAlg.h:59
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
TrigMuonEFTrackIsolationAlg::m_requireCombined
Gaudi::Property< bool > m_requireCombined
Definition: TrigMuonEFTrackIsolationAlg.h:64
TrigMuonEFTrackIsolationAlg::m_muonIso20Key
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonIso20Key
Definition: TrigMuonEFTrackIsolationAlg.h:56
TrigMuonEFTrackIsolationAlg::m_useVarIso
Gaudi::Property< bool > m_useVarIso
Definition: TrigMuonEFTrackIsolationAlg.h:67
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigMuonEFTrackIsolationAlg::initialize
virtual StatusCode initialize() override
initialize.
Definition: TrigMuonEFTrackIsolationAlg.cxx:20
TrigMuonEFTrackIsolationAlg::m_trackParticleKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleKey
Definition: TrigMuonEFTrackIsolationAlg.h:47
TrigMuonEFTrackIsolationAlg::TrigMuonEFTrackIsolationAlg
TrigMuonEFTrackIsolationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: TrigMuonEFTrackIsolationAlg.cxx:9
TrigMuonEFTrackIsolationAlg::m_onlineEfIsoTool
ToolHandle< IMuonEFTrackIsolationTool > m_onlineEfIsoTool
Tool handle for isolation tool.
Definition: TrigMuonEFTrackIsolationAlg.h:43
TrigMuonEFTrackIsolationAlg::m_muonContainerKey
SG::WriteHandleKey< xAOD::MuonContainer > m_muonContainerKey
Definition: TrigMuonEFTrackIsolationAlg.h:53