ATLAS Offline Software
TrigTauTrackRoiUpdater.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cmath>
6 
8 
9 #include "GaudiKernel/IToolSvc.h"
10 #include "GaudiKernel/StatusCode.h"
11 
13 #include "CxxUtils/phihelper.h"
14 
15 #include "TrkTrack/Track.h"
18 
19 TrigTauTrackRoiUpdater::TrigTauTrackRoiUpdater(const std::string& name, ISvcLocator* pSvcLocator)
20  : AthReentrantAlgorithm(name, pSvcLocator)
21 {
22 
23 }
24 
25 
27 {
28 
29 }
30 
31 
33 {
34  ATH_MSG_DEBUG("Initializing " << name() );
35  ATH_MSG_DEBUG("z0HalfWidth: " << m_z0HalfWidth );
36  ATH_MSG_DEBUG("etaHalfWidth: " << m_etaHalfWidth );
37  ATH_MSG_DEBUG("phiHalfWidth: " << m_phiHalfWidth );
38  ATH_MSG_DEBUG("nHitPix: " << m_nHitPix );
39  ATH_MSG_DEBUG("nSiHoles: " << m_nSiHoles );
40 
41  if(m_z0HalfWidth < 0 || m_etaHalfWidth < 0 || m_phiHalfWidth < 0) {
42  ATH_MSG_ERROR("Incorrect parameters");
43  return StatusCode::FAILURE;
44  }
45 
46  ATH_MSG_DEBUG("Initialising HandleKeys");
48  ATH_CHECK(m_tracksKey.initialize());
50 
51  return StatusCode::SUCCESS;
52 }
53 
54 
55 StatusCode TrigTauTrackRoiUpdater::execute(const EventContext& ctx) const
56 {
57  ATH_MSG_DEBUG("Running " << name());
58 
59  //---------------------------------------------------------------
60  // Prepare I/O
61  //---------------------------------------------------------------
62 
63  // Prepare output RoI container
64  std::unique_ptr<TrigRoiDescriptorCollection> roiCollection = std::make_unique<TrigRoiDescriptorCollection>();
66  ATH_CHECK(outputRoIHandle.record(std::move(roiCollection)));
67 
68 
69  // Retrieve Input TrackCollection
70  SG::ReadHandle<TrackCollection> TrackCollectionHandle = SG::makeHandle(m_tracksKey, ctx);
71  ATH_CHECK(TrackCollectionHandle.isValid());
72  const TrackCollection* foundTracks = TrackCollectionHandle.get();
73 
74  if(!foundTracks) {
75  ATH_MSG_ERROR("No track container found, the Track RoI updater should not be scheduled");
76  return StatusCode::FAILURE;
77  }
78  ATH_MSG_DEBUG("Found " << foundTracks->size() << " FTF tracks, updating the RoI");
79 
80 
81  // Retrieve input RoI descriptor
83  ATH_MSG_DEBUG("Size of roisHandle: " << roisHandle->size());
84  const TrigRoiDescriptor* roiDescriptor = roisHandle->at(0); // We only have one RoI in the handle
85 
86 
87  // Fill local variables for RoI reference position
88  float eta = roiDescriptor->eta();
89  float phi = roiDescriptor->phi();
90 
91  float zed = roiDescriptor->zed();
92  float zedMinus = roiDescriptor->zedMinus();
93  float zedPlus = roiDescriptor->zedPlus();
94 
95 
96 
97  //---------------------------------------------------------------
98  // Find leading track
99  //---------------------------------------------------------------
100 
101  const Trk::Track* leadTrack = nullptr;
102  float trkPtMax = 0;
103 
104  // Use the highest-pt track satisfying quality cuts
105  // If no track is found, the input ROI is used
106  for(const Trk::Track* track : *foundTracks) {
107  const Trk::TrackSummary* summary = track->trackSummary();
108  if(!summary) {
109  ATH_MSG_WARNING("Track summary not available in RoI updater" << name() << ". Skipping track...");
110  continue;
111  }
112 
113  float trackPt = track->perigeeParameters()->pT();
114  if(trackPt > trkPtMax) {
115  int nPix = summary->get(Trk::numberOfPixelHits);
116  if(nPix < 0) nPix = 0;
117  if(nPix < m_nHitPix) {
118  ATH_MSG_DEBUG("Track rejected because nHitPix " << nPix << " < " << m_nHitPix);
119  continue;
120  }
121 
122  int nPixHoles = summary->get(Trk::numberOfPixelHoles);
123  if(nPixHoles < 0) nPixHoles = 0;
125  if(nSCTHoles < 0) nSCTHoles = 0;
126  if((nPixHoles + nSCTHoles) > m_nSiHoles) {
127  ATH_MSG_DEBUG("Track rejected because nSiHoles " << nPixHoles + nSCTHoles << " > " << m_nSiHoles);
128  continue;
129  }
130 
131  leadTrack = track;
132  trkPtMax = trackPt;
133  }
134  }
135 
136 
137 
138  //---------------------------------------------------------------
139  // Update the RoI
140  //---------------------------------------------------------------
141 
142  // If a leading track is found, update all the ROI position and size parameters;
143  // else, only update the eta/phi width (etaMinus, etaPlus, phiMinus, phiPlus)
144  if(leadTrack) {
145  zed = leadTrack->perigeeParameters()->parameters()[Trk::z0];
146  zedMinus = zed - m_z0HalfWidth;
147  zedPlus = zed + m_z0HalfWidth;
148  eta = leadTrack->perigeeParameters()->eta();
149  phi = leadTrack->perigeeParameters()->parameters()[Trk::phi0];
150  }
151 
152  float etaMinus = eta - m_etaHalfWidth;
153  float etaPlus = eta + m_etaHalfWidth;
154  float phiMinus = CxxUtils::wrapToPi(phi - m_phiHalfWidth);
155  float phiPlus = CxxUtils::wrapToPi(phi + m_phiHalfWidth);
156 
157 
158  // Create the new RoI
159  outputRoIHandle->push_back(std::make_unique<TrigRoiDescriptor>(
160  roiDescriptor->roiWord(), roiDescriptor->l1Id(), roiDescriptor->roiId(),
161  eta, etaMinus, etaPlus,
162  phi, phiMinus, phiPlus,
163  zed, zedMinus, zedPlus
164  ));
165 
166 
167  ATH_MSG_DEBUG("Input RoI: " << *roiDescriptor);
168  ATH_MSG_DEBUG("Output RoI: " << *outputRoIHandle->back());
169 
170  return StatusCode::SUCCESS;
171 }
Trk::numberOfPixelHits
@ numberOfPixelHits
number of pixel layers on track with absence of hits
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:57
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
RoiDescriptor::zedMinus
virtual double zedMinus() const override final
z at the most backward end of the RoI
Definition: RoiDescriptor.h:113
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
TrigRoiDescriptor::roiWord
virtual unsigned int roiWord() const override final
Definition: TrigRoiDescriptor.h:135
Trk::z0
@ z0
Definition: ParamDefs.h:64
TrigTauTrackRoiUpdater::m_nHitPix
Gaudi::Property< int > m_nHitPix
Definition: TrigTauTrackRoiUpdater.h:48
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
TrigTauTrackRoiUpdater::m_roIInputKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roIInputKey
Definition: TrigTauTrackRoiUpdater.h:51
TrigTauTrackRoiUpdater::m_roIOutputKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roIOutputKey
Definition: TrigTauTrackRoiUpdater.h:53
Trk::numberOfSCTHoles
@ numberOfSCTHoles
number of Holes in both sides of a SCT module
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:73
TrigTauTrackRoiUpdater::m_phiHalfWidth
Gaudi::Property< float > m_phiHalfWidth
Definition: TrigTauTrackRoiUpdater.h:47
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Track.h
TrigTauTrackRoiUpdater.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigTauTrackRoiUpdater::m_z0HalfWidth
Gaudi::Property< float > m_z0HalfWidth
Definition: TrigTauTrackRoiUpdater.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigTauTrackRoiUpdater::~TrigTauTrackRoiUpdater
~TrigTauTrackRoiUpdater()
Definition: TrigTauTrackRoiUpdater.cxx:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrackCollection.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigRoiDescriptor::l1Id
virtual unsigned int l1Id() const override final
Definition: TrigRoiDescriptor.h:134
TrackSummary.h
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.
IDTPM::nSCTHoles
float nSCTHoles(const U &p)
Definition: TrackParametersHelper.h:403
DataVector< Trk::Track >
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TauGNNUtils::Variables::Track::trackPt
bool trackPt(const xAOD::TauJet &, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:472
Trk::numberOfPixelHoles
@ numberOfPixelHoles
number of pixels which have a ganged ambiguity.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:59
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
TrigTauTrackRoiUpdater::m_tracksKey
SG::ReadHandleKey< TrackCollection > m_tracksKey
Definition: TrigTauTrackRoiUpdater.h:52
RoiDescriptor::zed
virtual double zed() const override final
Definition: RoiDescriptor.h:102
Trk::TrackSummary
A summary of the information contained by a track.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:287
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
phihelper.h
Helper for azimuthal angle calculations.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
TrigRoiDescriptor::roiId
virtual unsigned int roiId() const override final
these quantities probably don't need to be used any more
Definition: TrigRoiDescriptor.h:133
SG::WriteHandle< TrigRoiDescriptorCollection >
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
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
TrigTauTrackRoiUpdater::m_etaHalfWidth
Gaudi::Property< float > m_etaHalfWidth
Definition: TrigTauTrackRoiUpdater.h:46
TrigTauTrackRoiUpdater::TrigTauTrackRoiUpdater
TrigTauTrackRoiUpdater(const std::string &, ISvcLocator *)
Definition: TrigTauTrackRoiUpdater.cxx:19
TrigTauTrackRoiUpdater::m_nSiHoles
Gaudi::Property< int > m_nSiHoles
Definition: TrigTauTrackRoiUpdater.h:49
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
TrigRoiDescriptor.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigTauTrackRoiUpdater::execute
virtual StatusCode execute(const EventContext &) const override
Definition: TrigTauTrackRoiUpdater.cxx:55
TrigTauTrackRoiUpdater::initialize
virtual StatusCode initialize() override
Definition: TrigTauTrackRoiUpdater.cxx:32
Trk::phi0
@ phi0
Definition: ParamDefs.h:65
RoiDescriptor::zedPlus
virtual double zedPlus() const override final
z at the most forward end of the RoI
Definition: RoiDescriptor.h:112
SCT_Monitoring::summary
@ summary
Definition: SCT_MonitoringNumbers.h:65