ATLAS Offline Software
Loading...
Searching...
No Matches
TrackRoiSelectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9
12
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/Service.h"
16
21
23#include <cmath> // std::fabs
24#include <algorithm> // for std::find
25
26
31 const std::string& name ) :
32 asg::AsgTool( name ) { }
33
34
39
41
42 ATH_MSG_DEBUG( "Initializing " << name() );
43
45 not m_triggerTrkParticleName.key().empty() ) );
46
47 ATH_CHECK( m_trigDecTool.retrieve() );
48
49 return StatusCode::SUCCESS;
50}
51
52
56template< class T >
58 const T& t, const TrigRoiDescriptor* r ) const {
59
60 if( r==0 ) {
61 ATH_MSG_ERROR( "Called with null RoiDescriptor" );
62 return true;
63 }
64
65 if( r->composite() ) {
66
67 for( unsigned i=r->size() ; i-- ; )
68 if( accept( t, (const TrigRoiDescriptor*)r->at(i) ) )
69 return true;
70
71 } else {
72
73 if( r->isFullscan() ) return true;
74
77 bool contained_phi = ( r->phiMinus() < r->phiPlus() ) ?
78 ( phi(t) > r->phiMinus() && phi(t) < r->phiPlus() ) :
79 ( phi(t) > r->phiMinus() || phi(t) < r->phiPlus() );
80
81 bool contained_zed = ( z0(t) > r->zedMinus() && z0(t) < r->zedPlus() );
82
85 bool contained_eta = ( eta(t) < r->etaPlus() && eta(t) > r->etaMinus() );
86
89 exitPoint_t exit = getExitPoint( z0(t), eta(t) );
90
94 exitPoint_t exitPlus = getExitPoint( r->zedPlus(), r->etaPlus() );
95 exitPoint_t exitMinus = getExitPoint( r->zedMinus(), r->etaMinus() );
96
97 float cross0 = exit.z * exitMinus.r - exit.r * exitMinus.z;
98 float cross1 = exit.z * exitPlus.r - exit.r * exitPlus.z;
99
100 contained_eta = ( cross0>0 && cross1<0 ) ? true : false;
101
103 float newphi = getOuterPhi( pTsig(t), phi(t), exit.r );
104
105 if( newphi < -999. ) return false;
106
107 if( r->phiMinus() < r->phiPlus() ) contained_phi &= ( newphi > r->phiMinus() && newphi < r->phiPlus() );
108 else contained_phi &= ( newphi > r->phiMinus() || newphi < r->phiPlus() );
109
110 if( contained_eta && contained_phi && contained_zed ) return true;
111 }
112
113 return false;
114}
115
118 const xAOD::TrackParticle& t, const TrigRoiDescriptor* r ) const;
119
122 const xAOD::TruthParticle& t, const TrigRoiDescriptor* r ) const;
123
124
129 float pt, float phi, float r ) const {
130
133
135 float mqR = 10 * pt / ( 2.99792458 * 2 ); // 2.998=speed of light, 2=Atlas B field
136 float ratio = 0.5 * r / mqR;
137 float newphi = phi;
138
140 if( std::fabs( ratio ) > 1 ) return -9999.;
141
143 newphi -= std::asin( ratio );
144
146 while( newphi < -M_PI ) newphi += 2 * M_PI;
147 while( newphi > M_PI ) newphi -= 2 * M_PI;
148
149 return newphi;
150}
151
152
157 float tz0, float teta ) const {
158
159 exitPoint_t exitPoint;
160 float rexit(0.), zexit(0.);
161 const float maxRadius = 1000.;
162 const float maxZed = 2700.;
163
164 if ( teta < 0 ) zexit = -maxZed;
165 else if ( teta > 0 ) zexit = maxZed;
166 else {
167 exitPoint.z = tz0;
168 exitPoint.r = maxRadius;
169 exitPoint.tantheta = 1e16; // don't really want to use nan
170 return exitPoint;
171 }
172
173 float tantheta = std::tan( 2 * std::atan( std::exp( -teta ) ) );
174
175 rexit = ( zexit - tz0 ) * tantheta;
176
178 if ( std::fabs(rexit) > maxRadius ) {
183
184 zexit = maxRadius / tantheta + tz0;
185 rexit = maxRadius;
186 }
187
188 exitPoint.z = zexit;
189 exitPoint.r = rexit;
190 exitPoint.tantheta = tantheta;
191 return exitPoint;
192}
193
194
198template< class T >
200 const std::vector< const T* >& tvec,
201 const TrigRoiDescriptor* r ) const {
202
203 std::vector< const T* > selectedTracks;
204
205 for( size_t it=0 ; it<tvec.size() ; it++ ) {
206 const T* thisTrack = tvec.at(it);
207 if( accept<T>( *thisTrack, r ) ) {
208 selectedTracks.push_back( thisTrack );
209 }
210 }
211
212 return selectedTracks;
213}
214
216template std::vector< const xAOD::TrackParticle* >
218 const std::vector< const xAOD::TrackParticle* >& tvec,
219 const TrigRoiDescriptor* r ) const;
220
222template std::vector< const xAOD::TruthParticle* >
224 const std::vector< const xAOD::TruthParticle* >& tvec,
225 const TrigRoiDescriptor* r ) const;
226
227
231std::vector< const xAOD::TrackParticle* >
233 const std::vector< const xAOD::TrackParticle* >& tvec,
234 const ElementLink< TrigRoiDescriptorCollection >& roiLink ) const
235{
238
242 m_trigDecTool->associateToEventView( handle, roiLink );
243
245 std::vector< const xAOD::TrackParticle* > selectedTrigTracks;
247 for( trkItr = trigTrkItrPair.first ; trkItr != trigTrkItrPair.second ; ++trkItr ) {
250 if( std::find( tvec.begin(), tvec.end(), *trkItr ) == tvec.end() ) {
251 ATH_MSG_DEBUG( "Trigger track does not pass quality selection. Skipping." );
252 continue;
253 }
254 selectedTrigTracks.push_back( *trkItr );
255 }
256
257 return selectedTrigTracks;
258}
259
260
265 TrackAnalysisCollections& trkAnaColls,
267
268 ATH_MSG_DEBUG( "Selecting tracks in RoI" );
269
271 ISvcLocator* svcLoc = Gaudi::svcLocator();
272 SmartIF< ITrackAnalysisDefinitionSvc > trkAnaDefSvc(
273 svcLoc->service( "TrkAnaDefSvc"+trkAnaColls.anaTag() ) );
274 ATH_CHECK( trkAnaDefSvc.isValid() );
275
276 const TrigRoiDescriptor* const* roi = roiLink.cptr();
277
280 if( not m_triggerTrkParticleName.key().empty() ) {
281 ATH_CHECK( trkAnaColls.fillTrigTrackVec(
284 roiLink ),
286 }
287
289 if( trkAnaDefSvc->useOffline() ) {
290 ATH_CHECK( trkAnaColls.fillOfflTrackVec(
291 getTracks(
293 *roi ),
295 }
296
298 if( trkAnaDefSvc->useTruth() ) {
299 ATH_CHECK( trkAnaColls.fillTruthPartVec(
300 getTracks(
302 *roi ),
304 }
305
307 ATH_MSG_DEBUG( "Tracks after RoI selection: " <<
308 trkAnaColls.printInfo( TrackAnalysisCollections::InRoI, false ) );
309
310 return StatusCode::SUCCESS;
311}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Class to hold for each event collections needed in the TrkAnalsis.
Utility methods to access track/truth particles parmeters in a consitent way in this package.
header file for class of same name
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const std::vector< const xAOD::TrackParticle * > & offlTrackVec(Stage stage=FULL)
StatusCode fillTrigTrackVec(const std::vector< const xAOD::TrackParticle * > &vec, Stage stage=FULL)
Trigger tracks.
const std::vector< const xAOD::TrackParticle * > & trigTrackVec(Stage stage=FULL)
const std::string & anaTag()
— Getter methods —
std::string printInfo(Stage stage=FULL, bool printVertex=true) const
print information about tracks in the collection(s)
StatusCode fillTruthPartVec(const std::vector< const xAOD::TruthParticle * > &vec, Stage stage=FULL)
fill truth/offline/trigger track vector (TEST or REFERENCE)
const std::vector< const xAOD::TruthParticle * > & truthPartVec(Stage stage=FULL)
get truth/offline/trigger track vector (TEST or REFERENCE)
StatusCode fillOfflTrackVec(const std::vector< const xAOD::TrackParticle * > &vec, Stage stage=FULL)
Offline tracks.
virtual StatusCode initialize() override
Initialize.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_triggerTrkParticleName
Trigger TrackParticleContainer's name.
float getOuterPhi(float pt, float phi, float r=1000.) const
std::vector< const T * > getTracks(const std::vector< const T * > &tvec, const TrigRoiDescriptor *r) const
track getter function (for offline tracks or truth particles)
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
TrigDecTool.
bool accept(const T &t, const TrigRoiDescriptor *r) const
geometric RoI filters - for non-trigger tracks (e.g. offline, truth, etc.)
std::vector< const xAOD::TrackParticle * > getTrigTracks(const std::vector< const xAOD::TrackParticle * > &tvec, const ElementLink< TrigRoiDescriptorCollection > &roiLink) const
TrigDecTool- and EventView-based getter function for trigger tracks.
exitPoint_t getExitPoint(float tz0, float teta) const
Geometric utility methods for track-RoI association.
StatusCode selectTracksInRoI(TrackAnalysisCollections &trkAnaColls, const ElementLink< TrigRoiDescriptorCollection > &roiLink)
Main Track selection method.
TrackRoiSelectionTool(const std::string &name)
Constructor.
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition AsgTool.h:133
int r
Definition globals.cxx:22
float phi(const U &p)
float z0(const U &p)
float pTsig(const U &p)
Accessor utility function for getting the value of signed pT.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.