ATLAS Offline Software
MuPatTrackBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MuPatTrackBuilder.h"
6 
7 #include <vector>
8 
12 #include "StoreGate/DataHandle.h"
14 #include "TrkTrack/Track.h"
17 
18 using namespace Muon;
19 MuPatTrackBuilder::MuPatTrackBuilder(const std::string& name, ISvcLocator* pSvcLocator):
20  AthReentrantAlgorithm(name,pSvcLocator) {
21 
22  }
24  ATH_CHECK(m_trackMaker.retrieve());
25  ATH_CHECK(m_edmHelperSvc.retrieve());
26  ATH_MSG_DEBUG("Retrieved " << m_trackMaker);
27 
28  ATH_CHECK(m_segmentKey.initialize());
29  ATH_CHECK(m_spectroTrackKey.initialize());
30 
31  if (!m_monTool.name().empty()) { ATH_CHECK(m_monTool.retrieve()); }
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 StatusCode MuPatTrackBuilder::execute(const EventContext& ctx) const {
37  typedef std::vector<const Muon::MuonSegment*> MuonSegmentCollection;
38 
40  if (!segmentColl.isValid()) {
41  ATH_MSG_WARNING("Could not find MuonSegmentCollection at " << segmentColl.name());
42  return StatusCode::FAILURE;
43  }
44 
45  if (!segmentColl.cptr()) {
46  ATH_MSG_WARNING("Obtained zero pointer for MuonSegmentCollection at " << segmentColl.name());
47  return StatusCode::FAILURE;
48  ;
49  }
50 
51  ATH_MSG_DEBUG("Retrieved MuonSegmentCollection " << segmentColl->size());
52 
54  msc.reserve(segmentColl->size());
55  for (const Trk::Segment* seg : *segmentColl) {
56  if (!seg) continue;
57  const Muon::MuonSegment* ms = dynamic_cast<const Muon::MuonSegment*>(seg);
58  if (ms) msc.push_back(ms);
59  }
60 
61  if (msc.size() != segmentColl->size()) {
62  ATH_MSG_WARNING("Input segment collection (size " << segmentColl->size() << ") and translated MuonSegment collection (size "
63  << msc.size() << ") are not the same size.");
64  }
65 
66  std::unique_ptr<TrackCollection> newtracks{m_trackMaker->find(ctx, msc)};
67  if (!newtracks) newtracks = std::make_unique<TrackCollection>();
68  const TrackCollection* track_raw_ptr = newtracks.get();
70  ATH_CHECK(spectroTracks.record(std::move(newtracks)));
71  ATH_MSG_DEBUG("TrackCollection '" << m_spectroTrackKey.key() << "' recorded in storegate, ntracks: " << track_raw_ptr->size());
72 
73  //---------------------------------------------------------------------------------------------------------------------//
74  //------------ Monitoring of muon segments and tracks inside the trigger algs ------------//
75  //------------ Author: Laurynas Mince ------------//
76  //------------ Created: 03.10.2019 ------------//
77  //---------------------------------------------------------------------------------------------------------------------//
78 
79  // Only run monitoring for online algorithms
80  if (not m_monTool.name().empty()) {
81  auto mstrks_n = Monitored::Scalar<int>("mstrks_n", track_raw_ptr->size());
82  auto mstrks_pt = Monitored::Collection("mstrks_pt", *track_raw_ptr, [](auto const& mstrk) {
83  return mstrk->perigeeParameters()->momentum().perp() / 1000.0;
84  }); // pT converted to GeV
85  auto mstrks_eta = Monitored::Collection("mstrks_eta", *track_raw_ptr, [](auto const& mstrk) {
86  return -log(tan(mstrk->perigeeParameters()->parameters()[Trk::theta] * 0.5));
87  });
88  auto mstrks_phi = Monitored::Collection("mstrks_phi", *track_raw_ptr,
89  [](auto const& mstrk) { return mstrk->perigeeParameters()->parameters()[Trk::phi0]; });
90  auto mssegs_n = Monitored::Scalar<int>("mssegs_n", msc.size());
91  auto mssegs_eta = Monitored::Collection("mssegs_eta", msc, [](auto const& seg) { return seg->globalPosition().eta(); });
92  auto mssegs_phi = Monitored::Collection("mssegs_phi", msc, [](auto const& seg) { return seg->globalPosition().phi(); });
93 
94  auto monitorIt = Monitored::Group(m_monTool, mstrks_n, mstrks_pt, mstrks_eta, mstrks_phi, mssegs_n, mssegs_eta, mssegs_phi);
95  }
96 
97  return StatusCode::SUCCESS;
98 } // execute
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:44
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
MuPatTrackBuilder::m_segmentKey
SG::ReadHandleKey< Trk::SegmentCollection > m_segmentKey
Key of input MuonSegmentCombination collection.
Definition: MuPatTrackBuilder.h:27
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
MuPatTrackBuilder::initialize
virtual StatusCode initialize() override
Definition: MuPatTrackBuilder.cxx:23
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:45
MuPatTrackBuilder::m_edmHelperSvc
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
helper Tool
Definition: MuPatTrackBuilder.h:33
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
DataHandle.h
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
Track.h
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
TrackCollection
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Definition: TrackCollection.h:19
Trk::theta
@ theta
Definition: ParamDefs.h:66
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
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
TrackCollection.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
MuPatTrackBuilder::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: MuPatTrackBuilder.h:38
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
IMuonEDMHelperSvc.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuPatTrackBuilder::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuPatTrackBuilder.cxx:36
MuPatTrackBuilder::m_trackMaker
ToolHandle< Muon::IMuonTrackFinder > m_trackMaker
Actual tool to do the track finding.
Definition: MuPatTrackBuilder.h:31
MuPatTrackBuilder.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuPatTrackBuilder::MuPatTrackBuilder
MuPatTrackBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuPatTrackBuilder.cxx:19
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
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
MuonSegment.h
Muon::MuonSegmentCollection
std::vector< const Muon::MuonSegment * > MuonSegmentCollection
Definition: MuonTrackSteering.h:44
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Trk::phi0
@ phi0
Definition: ParamDefs.h:65
SegmentCollection.h
TrackStateOnSurface.h
MuPatTrackBuilder::m_spectroTrackKey
SG::WriteHandleKey< TrackCollection > m_spectroTrackKey
Track output Key for tracks strictly in MS.
Definition: MuPatTrackBuilder.h:29
TrackParticleContainer.h