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 
21 
22 TrigTauTrackRoiUpdater::TrigTauTrackRoiUpdater(const std::string & name, ISvcLocator* pSvcLocator) :
23  AthReentrantAlgorithm(name, pSvcLocator)
24 {
25 }
26 
28 {
29 }
30 
32 {
33  ATH_MSG_DEBUG( "Initializing " << name() );
34  ATH_MSG_DEBUG( "z0HalfWidth " << m_z0HalfWidth );
35  ATH_MSG_DEBUG( "etaHalfWidth " << m_etaHalfWidth );
36  ATH_MSG_DEBUG( "phiHalfWidth " << m_phiHalfWidth );
37  ATH_MSG_DEBUG( "nHitPix " << m_nHitPix );
38  ATH_MSG_DEBUG( "nSiHoles " << m_nSiHoles );
39 
40  if(m_z0HalfWidth<0. || m_etaHalfWidth<0. || m_phiHalfWidth<0.) {
41  ATH_MSG_ERROR( "Incorrect parameters." );
42  return StatusCode::FAILURE;
43  }
44 
45  ATH_MSG_DEBUG( "Initialising HandleKeys" );
47  CHECK( m_tracksKey.initialize() );
49  CHECK( m_tauJetKey.initialize(SG::AllowEmpty) );
50 
51  return StatusCode::SUCCESS;
52 }
53 
54 StatusCode TrigTauTrackRoiUpdater::execute(const EventContext& ctx) const
55 {
56  ATH_MSG_DEBUG( "Running "<< name() );
57 
58  // Retrieve Input TrackCollection
59  SG::ReadHandle< TrackCollection > TrackCollectionHandle = SG::makeHandle( m_tracksKey,ctx );
60  CHECK( TrackCollectionHandle.isValid() );
61  const TrackCollection *foundTracks = TrackCollectionHandle.get();
62 
63  if(foundTracks == nullptr) {
64  ATH_MSG_ERROR( "No track container found, the track ROI updater should not be scheduled" );
65  return StatusCode::FAILURE;
66  }
67  ATH_MSG_DEBUG( "Found " << foundTracks->size() << " fast tracks, updating the RoI" );
68 
69  const Trk::Track *leadTrack = nullptr;
70  const Trk::Perigee *trackPer = nullptr;
71  const Trk::TrackSummary* summary = nullptr;
72  double trkPtMax = 0.;
73 
74  // use the highest-pt track satisfying quality cuts is used
75  // if no track is found, the input ROI is used
76  for (const Trk::Track* track : *foundTracks) {
77  trackPer = track->perigeeParameters();
78  summary = track->trackSummary();
79  if(summary==nullptr) {
80  ATH_MSG_WARNING( "track summary not available in RoI updater " << name() );
81  continue;
82  }
83  float trackPt = trackPer->pT();
84  if ( trackPt > trkPtMax ) {
85  int nPix = summary->get(Trk::numberOfPixelHits);
86  if(nPix<0) nPix=0;
87  if(nPix < m_nHitPix) {
88  ATH_MSG_DEBUG( "Track rejected because of nHitPix " << nPix << " < " << m_nHitPix );
89  continue;
90  }
91  int nPixHole = summary->get(Trk::numberOfPixelHoles);
92  if (nPixHole < 0) nPixHole = 0;
93  int nSCTHole = summary->get(Trk::numberOfSCTHoles);
94  if (nSCTHole < 0) nSCTHole = 0;
95  if((nPixHole + nSCTHole) > m_nSiHoles) {
96  ATH_MSG_DEBUG( "Track rejected because of nSiHoles " << nPixHole+nSCTHole << " > " << m_nSiHoles );
97  continue;
98  }
99  leadTrack = track;
100  trkPtMax = trackPt;
101  }
102  }
103 
104  // get RoI descriptor
106  ATH_MSG_DEBUG("Size of roisHandle: "<<roisHandle->size());
107  const TrigRoiDescriptor *roiDescriptor = roisHandle->at(0);
108 
109  // if a leading track is found, update all the ROI parameters (eta, etaMinus, etaPlus, phi, phiMinus, phiPlus, zed, zedMinus, zedPlus)
110  // else, only update the eta/phi width (etaMinus, etaPlus, phiMinus, phiPlus)
111  double zed = roiDescriptor->zed();
112  double zedMinus = roiDescriptor->zedMinus();
113  double zedPlus = roiDescriptor->zedPlus();
114  double eta = roiDescriptor->eta();
115  double phi = roiDescriptor->phi();
116  if( leadTrack ) {
117  zed = leadTrack->perigeeParameters()->parameters()[Trk::z0];
118  zedMinus = zed - m_z0HalfWidth;
119  zedPlus = zed + m_z0HalfWidth;
120  eta = leadTrack->perigeeParameters()->eta();
121  phi = leadTrack->perigeeParameters()->parameters()[Trk::phi0];
122  }
123  double etaMinus = eta - m_etaHalfWidth;
124  double etaPlus = eta + m_etaHalfWidth;
125  double phiMinus = CxxUtils::wrapToPi( phi - m_phiHalfWidth );
126  double phiPlus = CxxUtils::wrapToPi( phi + m_phiHalfWidth );
127 
128  // Prepare the new RoI
129  TrigRoiDescriptor *outRoi = new TrigRoiDescriptor(roiDescriptor->roiWord(), roiDescriptor->l1Id(), roiDescriptor->roiId(),
130  eta, etaMinus, etaPlus,
131  phi, phiMinus, phiPlus,
132  zed, zedMinus, zedPlus);
133 
134  ATH_MSG_DEBUG("Input RoI " << *roiDescriptor);
135  ATH_MSG_DEBUG("Output RoI " << *outRoi);
136 
137  auto roICollection = std::make_unique<TrigRoiDescriptorCollection>();
138  roICollection->push_back(outRoi);
139 
140  // Save Outputs
141  ATH_MSG_DEBUG( "Saving RoIs to be used as input to Fast Tracking -- TO BE CHANGED -- ::: " << m_roIOutputKey.key() );
143  CHECK( outputRoiHandle.record( std::move( roICollection ) ) );
144 
145  return StatusCode::SUCCESS;
146 }
147 
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:64
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:79
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
TrigTauTrackRoiUpdater::m_roIInputKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roIInputKey
Definition: TrigTauTrackRoiUpdater.h:36
TrigRoiDescriptor::roiWord
virtual unsigned int roiWord() const override final
Definition: TrigRoiDescriptor.h:135
TrigTauTrackRoiUpdater::m_tracksKey
SG::ReadHandleKey< TrackCollection > m_tracksKey
Definition: TrigTauTrackRoiUpdater.h:37
Trk::z0
@ z0
Definition: ParamDefs.h:70
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
Trk::numberOfSCTHoles
@ numberOfSCTHoles
number of Holes in both sides of a SCT module
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:73
TrigTauTrackRoiUpdater::m_roIOutputKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roIOutputKey
Definition: TrigTauTrackRoiUpdater.h:38
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigTauTrackRoiUpdater::~TrigTauTrackRoiUpdater
~TrigTauTrackRoiUpdater()
Definition: TrigTauTrackRoiUpdater.cxx:27
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
TrigRoiDescriptor::l1Id
virtual unsigned int l1Id() const override final
Definition: TrigRoiDescriptor.h:134
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
TrigTauTrackRoiUpdater::m_nSiHoles
Gaudi::Property< int > m_nSiHoles
Definition: TrigTauTrackRoiUpdater.h:34
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:470
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
PathResolver.h
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:195
TrigTauTrackRoiUpdater::m_phiHalfWidth
Gaudi::Property< float > m_phiHalfWidth
Definition: TrigTauTrackRoiUpdater.h:32
phihelper.h
Helper for azimuthal angle calculations.
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::TrigTauTrackRoiUpdater
TrigTauTrackRoiUpdater(const std::string &, ISvcLocator *)
Definition: TrigTauTrackRoiUpdater.cxx:22
HelperFunctions.h
TrigTauTrackRoiUpdater::m_etaHalfWidth
Gaudi::Property< float > m_etaHalfWidth
Definition: TrigTauTrackRoiUpdater.h:31
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
TrigTauTrackRoiUpdater::m_z0HalfWidth
Gaudi::Property< float > m_z0HalfWidth
Definition: TrigTauTrackRoiUpdater.h:30
TrigTauTrackRoiUpdater::m_tauJetKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauJetKey
Definition: TrigTauTrackRoiUpdater.h:40
TrigTauTrackRoiUpdater::m_nHitPix
Gaudi::Property< int > m_nHitPix
Definition: TrigTauTrackRoiUpdater.h:33
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
TrigRoiDescriptor.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
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:54
TrigTauTrackRoiUpdater::initialize
virtual StatusCode initialize() override
Definition: TrigTauTrackRoiUpdater.cxx:31
Trk::phi0
@ phi0
Definition: ParamDefs.h:71
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