ATLAS Offline Software
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 
12 
14 #include "GaudiKernel/ISvcLocator.h"
15 #include "GaudiKernel/Service.h"
16 
18 #include "TrackRoiSelectionTool.h"
20 #include "TrackParametersHelper.h"
21 
23 #include <cmath> // std::fabs
24 
25 
30  const std::string& name ) :
31  asg::AsgTool( name ) { }
32 
33 
38 
40 
41  ATH_MSG_INFO( "Initializing " << name() );
42 
43  ATH_CHECK( m_triggerTrkParticleName.initialize(
44  not m_triggerTrkParticleName.key().empty() ) );
45 
46  ATH_CHECK( m_trigDecTool.retrieve() );
47 
48  return StatusCode::SUCCESS;
49 }
50 
51 
55 template< class T >
57  const T& t, const TrigRoiDescriptor* r ) const {
58 
59  if( r==0 ) {
60  ATH_MSG_ERROR( "Called with null RoiDescriptor" );
61  return true;
62  }
63 
64  if( r->composite() ) {
65 
66  for( unsigned i=r->size() ; i-- ; )
67  if( accept( t, (const TrigRoiDescriptor*)r->at(i) ) )
68  return true;
69 
70  } else {
71 
72  if( r->isFullscan() ) return true;
73 
76  bool contained_phi = ( r->phiMinus() < r->phiPlus() ) ?
77  ( phi(t) > r->phiMinus() && phi(t) < r->phiPlus() ) :
78  ( phi(t) > r->phiMinus() || phi(t) < r->phiPlus() );
79 
80  bool contained_zed = ( z0(t) > r->zedMinus() && z0(t) < r->zedPlus() );
81 
84  bool contained_eta = ( eta(t) < r->etaPlus() && eta(t) > r->etaMinus() );
85 
88  exitPoint_t exit = getExitPoint( z0(t), eta(t) );
89 
93  exitPoint_t exitPlus = getExitPoint( r->zedPlus(), r->etaPlus() );
94  exitPoint_t exitMinus = getExitPoint( r->zedMinus(), r->etaMinus() );
95 
96  float cross0 = exit.z * exitMinus.r - exit.r * exitMinus.z;
97  float cross1 = exit.z * exitPlus.r - exit.r * exitPlus.z;
98 
99  contained_eta = ( cross0>0 && cross1<0 ) ? true : false;
100 
102  float newphi = getOuterPhi( pTsig(t), phi(t), exit.r );
103 
104  if( newphi < -999. ) return false;
105 
106  if( r->phiMinus() < r->phiPlus() ) contained_phi &= ( newphi > r->phiMinus() && newphi < r->phiPlus() );
107  else contained_phi &= ( newphi > r->phiMinus() || newphi < r->phiPlus() );
108 
109  if( contained_eta && contained_phi && contained_zed ) return true;
110  }
111 
112  return false;
113 }
114 
117  const xAOD::TrackParticle& t, const TrigRoiDescriptor* r ) const;
118 
121  const xAOD::TruthParticle& t, const TrigRoiDescriptor* r ) const;
122 
123 
128  float pt, float phi, float r ) const {
129 
132 
134  float mqR = 10 * pt / ( 2.99792458 * 2 ); // 2.998=speed of light, 2=Atlas B field
135  float ratio = 0.5 * r / mqR;
136  float newphi = phi;
137 
139  if( std::fabs( ratio ) > 1 ) return -9999.;
140 
142  newphi -= std::asin( ratio );
143 
145  while( newphi < -M_PI ) newphi += 2 * M_PI;
146  while( newphi > M_PI ) newphi -= 2 * M_PI;
147 
148  return newphi;
149 }
150 
151 
156  float tz0, float teta ) const {
157 
158  exitPoint_t exitPoint;
159  float rexit(0.), zexit(0.);
160  const float maxRadius = 1000.;
161  const float maxZed = 2700.;
162 
163  if ( teta < 0 ) zexit = -maxZed;
164  else if ( teta > 0 ) zexit = maxZed;
165  else {
166  exitPoint.z = tz0;
167  exitPoint.r = maxRadius;
168  exitPoint.tantheta = 1e16; // don't really want to use nan
169  return exitPoint;
170  }
171 
172  float tantheta = std::tan( 2 * std::atan( std::exp( -teta ) ) );
173 
174  rexit = ( zexit - tz0 ) * tantheta;
175 
177  if ( std::fabs(rexit) > maxRadius ) {
182 
183  zexit = maxRadius / tantheta + tz0;
184  rexit = maxRadius;
185  }
186 
187  exitPoint.z = zexit;
188  exitPoint.r = rexit;
189  exitPoint.tantheta = tantheta;
190  return exitPoint;
191 }
192 
193 
197 template< class T >
199  const std::vector< const T* >& tvec,
200  const TrigRoiDescriptor* r ) const {
201 
202  std::vector< const T* > selectedTracks;
203 
204  for( size_t it=0 ; it<tvec.size() ; it++ ) {
205  const T* thisTrack = tvec.at(it);
206  if( accept<T>( *thisTrack, r ) ) {
207  selectedTracks.push_back( thisTrack );
208  }
209  }
210 
211  return selectedTracks;
212 }
213 
215 template std::vector< const xAOD::TrackParticle* >
217  const std::vector< const xAOD::TrackParticle* >& tvec,
218  const TrigRoiDescriptor* r ) const;
219 
221 template std::vector< const xAOD::TruthParticle* >
223  const std::vector< const xAOD::TruthParticle* >& tvec,
224  const TrigRoiDescriptor* r ) const;
225 
226 
230 std::vector< const xAOD::TrackParticle* >
233  const ElementLink< TrigRoiDescriptorCollection >& roiLink ) const {
234 
236 
237 
240  m_trigDecTool->associateToEventView( handle, roiLink );
241  std::vector< const xAOD::TrackParticle* > selectedTrigTracks
242  (selTrigTrkItrPair.first, selTrigTrkItrPair.second);
243 
244  return selectedTrigTracks;
245 }
246 
247 
252  TrackAnalysisCollections& trkAnaColls,
254 
255  ATH_MSG_DEBUG( "Selecting tracks in RoI" );
256 
258  ISvcLocator* svcLoc = Gaudi::svcLocator();
259  SmartIF<ITrackAnalysisDefinitionSvc> trkAnaDefSvc( svcLoc->service( "TrkAnaDefSvc"+trkAnaColls.anaTag() ) );
260  ATH_CHECK( trkAnaDefSvc.isValid() );
261 
262  const TrigRoiDescriptor* const* roi = roiLink.cptr();
263 
265  ATH_CHECK( trkAnaColls.fillTrigTrackVec(
266  getTrigTracks( m_triggerTrkParticleName, roiLink ),
268 
270  if( trkAnaDefSvc->useOffline() ) {
271  ATH_CHECK( trkAnaColls.fillOfflTrackVec(
272  getTracks(
274  *roi ),
276  }
277 
279  if( trkAnaDefSvc->useTruth() ) {
280  ATH_CHECK( trkAnaColls.fillTruthPartVec(
281  getTracks(
283  *roi ),
285  }
286 
288  ATH_MSG_DEBUG( "Tracks after RoI selection: " <<
290 
291  return StatusCode::SUCCESS;
292 }
beamspotman.r
def r
Definition: beamspotman.py:676
IDTPM::TrackRoiSelectionTool::getExitPoint
exitPoint_t getExitPoint(float tz0, float teta) const
Geometric utility methods for track-RoI association.
Definition: TrackRoiSelectionTool.cxx:155
IDTPM::TrackAnalysisCollections::fillTrigTrackVec
StatusCode fillTrigTrackVec(const std::vector< const xAOD::TrackParticle * > &vec, Stage stage=FULL)
Trigger tracks.
Definition: TrackAnalysisCollections.cxx:331
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DataVector::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition: DataVector.h:837
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
IDTPM::z0
float z0(const U &p)
Definition: TrackParametersHelper.h:70
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
skel.it
it
Definition: skel.GENtoEVGEN.py:396
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
M_PI
#define M_PI
Definition: ActiveFraction.h:11
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
IDTPM::pTsig
float pTsig(const U &p)
Accessor utility function for getting the value of signed pT.
Definition: TrackParametersHelper.h:35
TrackAnalysisCollections.h
Class to hold for each event collections needed in the TrkAnalsis.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::ReadHandleKey< xAOD::TrackParticleContainer >
IDTPM::TrackRoiSelectionTool::getOuterPhi
float getOuterPhi(float pt, float phi, float r=1000.) const
Definition: TrackRoiSelectionTool.cxx:127
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
IDTPM::TrackRoiSelectionTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: TrackRoiSelectionTool.cxx:37
IDTPM::phi
float phi(const U &p)
Definition: TrackParametersHelper.h:59
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
exitPoint_t::r
float r
Definition: TrackRoiSelectionTool.h:30
exitPoint_t
Definition: TrackRoiSelectionTool.h:28
IDTPM::TrackRoiSelectionTool::getTracks
std::vector< const T * > getTracks(const std::vector< const T * > &tvec, const TrigRoiDescriptor *r) const
track getter function (for offline tracks or truth particles)
Definition: TrackRoiSelectionTool.cxx:198
IDTPM::TrackAnalysisCollections::fillOfflTrackVec
StatusCode fillOfflTrackVec(const std::vector< const xAOD::TrackParticle * > &vec, Stage stage=FULL)
Offline tracks.
Definition: TrackAnalysisCollections.cxx:314
IDTPM::TrackAnalysisCollections::fillTruthPartVec
StatusCode fillTruthPartVec(const std::vector< const xAOD::TruthParticle * > &vec, Stage stage=FULL)
get truth/offline/trigger track vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.cxx:297
exitPoint_t::tantheta
float tantheta
Definition: TrackRoiSelectionTool.h:31
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IDTPM::eta
float eta(const U &p)
Accessor utility function for getting the value of eta.
Definition: TrackParametersHelper.h:41
lumiFormat.i
int i
Definition: lumiFormat.py:85
IDTPM::TrackRoiSelectionTool::accept
bool accept(const T &t, const TrigRoiDescriptor *r) const
geometric RoI filters - for non-trigger tracks (e.g. offline, truth, etc.)
Definition: TrackRoiSelectionTool.cxx:56
IDTPM::TrackRoiSelectionTool::selectTracksInRoI
virtual StatusCode selectTracksInRoI(TrackAnalysisCollections &trkAnaColls, const ElementLink< TrigRoiDescriptorCollection > &roiLink) override
Main Track selection method.
Definition: TrackRoiSelectionTool.cxx:251
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
IDTPM::TrackAnalysisCollections::FS
@ FS
Definition: TrackAnalysisCollections.h:52
exitPoint_t::z
float z
Definition: TrackRoiSelectionTool.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::TrackAnalysisCollections::offlTrackVec
const std::vector< const xAOD::TrackParticle * > & offlTrackVec(Stage stage=FULL)
Definition: TrackAnalysisCollections.h:164
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
getTracks< xAOD::TruthParticle >
template std::vector< const xAOD::TruthParticle * > IDTPM::TrackRoiSelectionTool::getTracks< xAOD::TruthParticle >(const std::vector< const xAOD::TruthParticle * > &tvec, const TrigRoiDescriptor *r) const
getTracks method for truth particles
TrackRoiSelectionTool.h
calibdata.exit
exit
Definition: calibdata.py:236
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
IDTPM::TrackRoiSelectionTool::getTrigTracks
std::vector< const xAOD::TrackParticle * > getTrigTracks(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey, const ElementLink< TrigRoiDescriptorCollection > &roiLink) const
TrigDecTool- and EventView-based getter function for trigger tracks.
Definition: TrackRoiSelectionTool.cxx:231
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:52
IDTPM::TrackAnalysisCollections::truthPartVec
const std::vector< const xAOD::TruthParticle * > & truthPartVec(Stage stage=FULL)
get truth/offline/trigger track vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.h:162
getTracks< xAOD::TrackParticle >
template std::vector< const xAOD::TrackParticle * > IDTPM::TrackRoiSelectionTool::getTracks< xAOD::TrackParticle >(const std::vector< const xAOD::TrackParticle * > &tvec, const TrigRoiDescriptor *r) const
getTracks method for offline tracks
IDTPM::TrackAnalysisCollections::printInfo
std::string printInfo(Stage stage=FULL) const
print Information about tracks in the collection(s)
Definition: TrackAnalysisCollections.cxx:546
TrigRoiDescriptor.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
IDTPM::TrackAnalysisCollections::anaTag
const std::string & anaTag()
— Getter methods —
Definition: TrackAnalysisCollections.h:132
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133
IDTPM::TrackRoiSelectionTool::TrackRoiSelectionTool
TrackRoiSelectionTool(const std::string &name)
Constructor.
Definition: TrackRoiSelectionTool.cxx:29