ATLAS Offline Software
TrackParticleClusterAssociationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 
10 #include "FourMomUtils/P4Helpers.h"
11 
13 
14 
16 {
17 
18  if (m_detectorEtaDecor.key().empty())
19  m_doDetEta = false;
20  else
21  {
22  m_doDetEta = true;
24  }
25 
26  ATH_CHECK( m_caloExtKey.initialize() );
31  ATH_CHECK( m_sigmaWidthKey.initialize() );
32 
34 
35  ATH_CHECK( m_vertexContHandle.initialize( !m_vertexContHandle.empty() ) );
36  if(!m_vertexContHandle.empty() ) {
37  ATH_CHECK(m_trackvertexassoTool.retrieve() );
38  }
39 
40  ATH_MSG_DEBUG(" cluster decoration = "<< m_assocClustersDecor.key() );
41  return StatusCode::SUCCESS;
42 }
43 
45 {
46 
47  ATH_MSG_DEBUG("excute()");
48  // get track particles
50  ATH_MSG_DEBUG("retrieved "<< m_trackParticleCollectionHandle.key()<< " size ="<< trackParticles->size() );
51 
52  // pre-calculate a width of clusters, set it as dynamica attribute so we don't have to recalculate it
54  ATH_MSG_DEBUG("retrieved "<< m_caloClusters.key() << " size = "<< clusterContainer->size() );
56  //for(const xAOD::CaloCluster *cl : *clusterContainer){
57  for(const xAOD::CaloCluster *cl : *clusterContainer){
58  double rad;
59  cl->retrieveMoment(xAOD::CaloCluster::SECOND_R,rad);
60  double cent;
61  cl->retrieveMoment(xAOD::CaloCluster::CENTER_MAG,cent);
62 
63  float cl_eta {99};
64  if (m_doDetEta)
65  {
67  cl_eta = detEta(*cl);
68  }
69  else
70  cl_eta = cl->eta();
71 
72  double sigmaWidth = 0.0;
73  if(cent > 0) sigmaWidth = atan(sqrt(rad)/cent)*cosh(cl_eta);
74  sig_dec(*cl) = sigmaWidth;
75  }
76 
77 
78  // obtain the CaloExtension from the map in the event store
80  ATH_MSG_DEBUG("CaloExtensionCollection "<< m_caloExtKey.key() << " : size="<< caloExts->size() );
81 
82  const xAOD::Vertex * pv0 = nullptr;
83  if(!m_vertexContHandle.empty()){
85  if(!vxCont->empty()) pv0=(*vxCont)[0]; // Hard code HS vertex as PV0
86  }
87 
89  std::vector<ElementLink<xAOD::CaloClusterContainer>> > assoClustDecor(m_assocClustersDecor, ctx);
90 
91  ATH_MSG_DEBUG("will decorate with "<<assoClustDecor.key()<< " and adding trkParam : "<< m_caloEntryParsDecor.key() );
92 
93  // ******************************************
94  // main loop over tracks
95  unsigned int ntracks = 0;
96  for( const xAOD::TrackParticle* tp : *trackParticles){
97 
98  // retrieve the vector of links to cluster (and creating it )
99  std::vector< ElementLink< xAOD::CaloClusterContainer > > & caloClusterLinks = assoClustDecor(*tp);
100 
101  if( tp->pt() < m_ptCut ) continue;
102 
103  if( pv0 != nullptr) if(! m_trackvertexassoTool->isCompatible(*tp, *pv0 )) continue;
104 
105  ATH_MSG_DEBUG(" Selected track " << tp->index() << " pt " << tp->pt() << " eta " << tp->eta() << " phi " << tp->phi() );
106 
107  // IMMPORTANT : this assumes a correspondance between the TrackParticleContainer and the CaloExtensionCollection !
108  const Trk::CaloExtension * caloExtension = (*caloExts)[tp->index() ] ;
109  if (caloExtension == nullptr ) {
110  ATH_MSG_DEBUG(" Selected track "<< tp->index() << " has no caloExtension ");
111  continue;
112  }
113 
114  // build the associated clusters
115  std::vector<const xAOD::CaloCluster*> assoClusters = associatedClusters( *caloExtension, *clusterContainer, ctx);
116 
117  // translate vector of links to cluster in ElementLink
118 
119  caloClusterLinks.reserve( assoClusters.size() );
120  for(const xAOD::CaloCluster* cluster : assoClusters) caloClusterLinks.emplace_back( *clusterContainer,cluster->index() );
121  ntracks++;
122  }// end loop over tracks
123 
124  // 2nd loop over track, only to decorate with Track parameter if requested.
125  if (! m_caloEntryParsDecor.empty() ){
126  // we can not do this in the above loop because declaring a WriteDecorHandle requires a non empty key
127  // (otherwise : run-time error).
129  for( const xAOD::TrackParticle* tp : *trackParticles){
130  const Trk::CaloExtension * caloExtension = (*caloExts)[tp->index() ] ;
131  if (caloExtension == nullptr ) trkParamDecor( *tp ) = nullptr ;
132  else trkParamDecor( *tp ) = caloExtension->caloEntryLayerIntersection();
133  }
134  }
135 
136  ATH_MSG_DEBUG(" Total number of selected tracks: " << ntracks );
137 
138  return StatusCode::SUCCESS;
139 }
140 
141 
142 std::vector<const xAOD::CaloCluster* >
144  const EventContext& ctx) const
145 {
146  std::vector<const xAOD::CaloCluster* > clusters;
147 
148  const Trk::TrackParameters* pars = caloExtension.caloEntryLayerIntersection();
149  if(!pars) {
150  ATH_MSG_WARNING( " NO TrackParameters caloExtension.caloEntryLayerIntersection() ");
151  return clusters;
152  }
153 
154  float eta = pars->position().eta();
155  float phi = pars->position().phi();
156 
157  double uncertEta = 0.;
158  double uncertPhi = 0.;
159  if(pars->covariance()) {
160  uncertEta = -2.*sin(pars->position().theta()) / (cos(2.*pars->position().theta())-1.) * sqrt((*pars->covariance())(Trk::theta,Trk::theta));
161  uncertPhi = sqrt((*pars->covariance())(Trk::phi,Trk::phi));
162  }
163  double uncertExtrp = uncertEta*uncertEta + uncertPhi*uncertPhi;
164 
165  float dr2Cut0 = m_dr*m_dr;
166  // to access the pre-calculated width :
167  static const SG::AuxElement::ConstAccessor<float> sig_acc("sigmaWidth");
168 
169  for(const xAOD::CaloCluster * cl : allClusters){
170 
171  float dPhi = P4Helpers::deltaPhi( cl->phi(), phi);
172 
173  float cl_eta {99};
174  if (m_doDetEta)
175  {
177  cl_eta = detEta(*cl);
178  }
179  else
180  cl_eta = cl->eta();
181 
182  float dEta = cl_eta - eta;
183  float dr2 = dPhi*dPhi+ dEta*dEta;
184  float dr2Cut = dr2Cut0;
185 
186  if(m_useCovariance) {
187 
188  double sigmaWidth = sig_acc(*cl);
189  double uncertClus = 2.*sigmaWidth*sigmaWidth;
190  if(uncertExtrp>uncertClus){
191  ATH_MSG_DEBUG("Extrapolation uncertainty larger than cluster width! Returning without association.");
192  continue;
193  }
194 
195  dr2Cut = (sigmaWidth+uncertEta)*(sigmaWidth+uncertEta)+(sigmaWidth+uncertPhi)*(sigmaWidth+uncertPhi);
196  }
197  if( dr2 < dr2Cut ) clusters.push_back( cl );
198  }
199 
200  return clusters;
201 }
xAOD::CaloCluster_v1::CENTER_MAG
@ CENTER_MAG
Cluster Centroid ( )
Definition: CaloCluster_v1.h:138
xAOD::CaloCluster_v1::SECOND_R
@ SECOND_R
Second Moment in .
Definition: CaloCluster_v1.h:126
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
TrackParticleClusterAssociationAlg::m_useCovariance
Gaudi::Property< bool > m_useCovariance
Definition: TrackParticleClusterAssociationAlg.h:58
TrackParticleClusterAssociationAlg::m_vertexContHandle
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContHandle
Definition: TrackParticleClusterAssociationAlg.h:72
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
TrackParticleClusterAssociationAlg::m_trackParticleCollectionHandle
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleCollectionHandle
Definition: TrackParticleClusterAssociationAlg.h:63
TrackParticleClusterAssociationAlg::m_assocClustersDecor
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_assocClustersDecor
Definition: TrackParticleClusterAssociationAlg.h:77
Trk::CaloExtension
Tracking class to hold the extrapolation through calorimeter Layers Both the caloEntryLayerIntersecti...
Definition: CaloExtension.h:19
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TrackParticleClusterAssociationAlg::initialize
virtual StatusCode initialize() override
Definition: TrackParticleClusterAssociationAlg.cxx:15
xAOD::TrackParticleContainer
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticleContainer.h:14
ParticleTest.tp
tp
Definition: ParticleTest.py:25
Trk::CaloExtension::caloEntryLayerIntersection
const TrackParameters * caloEntryLayerIntersection() const
access to intersection with the calorimeter entry layer return nullptr if the intersection failed
Definition: CaloExtension.h:51
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
TrackParticleClusterAssociationAlg::m_detectorEtaDecor
SG::ReadDecorHandleKey< xAOD::CaloClusterContainer > m_detectorEtaDecor
Definition: TrackParticleClusterAssociationAlg.h:68
TrackParticleClusterAssociationAlg::m_sigmaWidthKey
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_sigmaWidthKey
Definition: TrackParticleClusterAssociationAlg.h:80
TrackParticleClusterAssociationAlg.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: P4Helpers.h:34
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
TrackParticleClusterAssociationAlg::m_caloEntryParsDecor
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_caloEntryParsDecor
Definition: TrackParticleClusterAssociationAlg.h:78
TrackParticleClusterAssociationAlg::m_dr
Gaudi::Property< float > m_dr
Definition: TrackParticleClusterAssociationAlg.h:57
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
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:549
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
TrackParticleClusterAssociationAlg::m_caloExtKey
SG::ReadHandleKey< CaloExtensionCollection > m_caloExtKey
Definition: TrackParticleClusterAssociationAlg.h:62
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TrackParticleClusterAssociationAlg::m_ptCut
Gaudi::Property< double > m_ptCut
Definition: TrackParticleClusterAssociationAlg.h:59
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
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
python.SystemOfUnits.rad
float rad
Definition: SystemOfUnits.py:126
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
P4Helpers.h
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
ReadDecorHandle.h
Handle class for reading a decoration on an object.
Trk::phi
@ phi
Definition: ParamDefs.h:75
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TrackParticleClusterAssociationAlg::m_trackvertexassoTool
ToolHandle< CP::ITrackVertexAssociationTool > m_trackvertexassoTool
Definition: TrackParticleClusterAssociationAlg.h:73
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:538
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:25
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleClusterAssociationAlg::m_doDetEta
bool m_doDetEta
Definition: TrackParticleClusterAssociationAlg.h:69
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
TrackParticleClusterAssociationAlg::m_caloClusters
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClusters
Definition: TrackParticleClusterAssociationAlg.h:64
AuxElement.h
Base class for elements of a container that can have aux data.
TrackParticleClusterAssociationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrackParticleClusterAssociationAlg.cxx:44
TrackParticleClusterAssociationAlg::associatedClusters
std::vector< const xAOD::CaloCluster * > associatedClusters(const Trk::CaloExtension &caloExtensions, const xAOD::CaloClusterContainer &allClusters, const EventContext &ctx) const
returns the clusters from allClusters which are close enough to caloExtensions
Definition: TrackParticleClusterAssociationAlg.cxx:143