ATLAS Offline Software
Loading...
Searching...
No Matches
TrackParticleClusterAssociationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
11
13
14
16{
17
18 m_doDetEta = !m_detectorEtaDecor.key().empty();
19
20 ATH_CHECK( m_caloExtKey.initialize() );
22 ATH_CHECK( m_caloClusters.initialize() );
24 ATH_CHECK( m_assocClustersDecor.initialize() );
25 ATH_CHECK( m_sigmaWidthKey.initialize() );
26
28
29 ATH_CHECK( m_vertexContHandle.initialize( !m_vertexContHandle.empty() ) );
30 if(!m_vertexContHandle.empty() ) {
32 }
33
34 ATH_MSG_DEBUG(" cluster decoration = "<< m_assocClustersDecor.key() );
35 return StatusCode::SUCCESS;
36}
37
38StatusCode TrackParticleClusterAssociationAlg::execute(const EventContext& ctx) const
39{
40
41 ATH_MSG_DEBUG("excute()");
42 // get track particles
44 ATH_MSG_DEBUG("retrieved "<< m_trackParticleCollectionHandle.key()<< " size ="<< trackParticles->size() );
45
46 // pre-calculate a width of clusters, set it as dynamica attribute so we don't have to recalculate it
48 ATH_MSG_DEBUG("retrieved "<< m_caloClusters.key() << " size = "<< clusterContainer->size() );
50 //for(const xAOD::CaloCluster *cl : *clusterContainer){
51 for(const xAOD::CaloCluster *cl : *clusterContainer){
52 double rad;
53 cl->retrieveMoment(xAOD::CaloCluster::SECOND_R,rad);
54 double cent;
55 cl->retrieveMoment(xAOD::CaloCluster::CENTER_MAG,cent);
56
57 float cl_eta {99};
58 if (m_doDetEta)
59 {
61 cl_eta = detEta(*cl);
62 }
63 else
64 cl_eta = cl->eta();
65
66 double sigmaWidth = 0.0;
67 if(cent > 0) sigmaWidth = atan(sqrt(rad)/cent)*cosh(cl_eta);
68 sig_dec(*cl) = sigmaWidth;
69 }
70
71
72 // obtain the CaloExtension from the map in the event store
74 ATH_MSG_DEBUG("CaloExtensionCollection "<< m_caloExtKey.key() << " : size="<< caloExts->size() );
75
76 const xAOD::Vertex * pv0 = nullptr;
77 if(!m_vertexContHandle.empty()){
79 if(!vxCont->empty()) pv0=(*vxCont)[0]; // Hard code HS vertex as PV0
80 }
81
83 std::vector<ElementLink<xAOD::CaloClusterContainer>> > assoClustDecor(m_assocClustersDecor, ctx);
84
85 ATH_MSG_DEBUG("will decorate with "<<assoClustDecor.key()<< " and adding trkParam : "<< m_caloEntryParsDecor.key() );
86
87 // ******************************************
88 // main loop over tracks
89 unsigned int ntracks = 0;
90 for( const xAOD::TrackParticle* tp : *trackParticles){
91
92 // retrieve the vector of links to cluster (and creating it )
93 std::vector< ElementLink< xAOD::CaloClusterContainer > > & caloClusterLinks = assoClustDecor(*tp);
94
95 if( tp->pt() < m_ptCut ) continue;
96
97 if( pv0 != nullptr) if(! m_trackvertexassoTool->isCompatible(*tp, *pv0 )) continue;
98
99 ATH_MSG_DEBUG(" Selected track " << tp->index() << " pt " << tp->pt() << " eta " << tp->eta() << " phi " << tp->phi() );
100
101 // IMMPORTANT : this assumes a correspondance between the TrackParticleContainer and the CaloExtensionCollection !
102 const Trk::CaloExtension * caloExtension = (*caloExts)[tp->index() ] ;
103 if (caloExtension == nullptr ) {
104 ATH_MSG_DEBUG(" Selected track "<< tp->index() << " has no caloExtension ");
105 continue;
106 }
107
108 // build the associated clusters
109 std::vector<const xAOD::CaloCluster*> assoClusters = associatedClusters( *caloExtension, *clusterContainer, ctx);
110
111 // translate vector of links to cluster in ElementLink
112
113 caloClusterLinks.reserve( assoClusters.size() );
114 for(const xAOD::CaloCluster* cluster : assoClusters) caloClusterLinks.emplace_back( *clusterContainer,cluster->index() );
115 ntracks++;
116 }// end loop over tracks
117
118 // 2nd loop over track, only to decorate with Track parameter if requested.
119 if (! m_caloEntryParsDecor.empty() ){
120 // we can not do this in the above loop because declaring a WriteDecorHandle requires a non empty key
121 // (otherwise : run-time error).
123 for( const xAOD::TrackParticle* tp : *trackParticles){
124 const Trk::CaloExtension * caloExtension = (*caloExts)[tp->index() ] ;
125 if (caloExtension == nullptr ) trkParamDecor( *tp ) = nullptr ;
126 else trkParamDecor( *tp ) = caloExtension->caloEntryLayerIntersection();
127 }
128 }
129
130 ATH_MSG_DEBUG(" Total number of selected tracks: " << ntracks );
131
132 return StatusCode::SUCCESS;
133}
134
135
136std::vector<const xAOD::CaloCluster* >
138 const EventContext& ctx) const
139{
140 std::vector<const xAOD::CaloCluster* > clusters;
141
142 const Trk::TrackParameters* pars = caloExtension.caloEntryLayerIntersection();
143 if(!pars) {
144 ATH_MSG_WARNING( " NO TrackParameters caloExtension.caloEntryLayerIntersection() ");
145 return clusters;
146 }
147
148 float eta = pars->position().eta();
149 float phi = pars->position().phi();
150
151 double uncertEta = 0.;
152 double uncertPhi = 0.;
153 if(pars->covariance()) {
154 uncertEta = -2.*sin(pars->position().theta()) / (cos(2.*pars->position().theta())-1.) * sqrt((*pars->covariance())(Trk::theta,Trk::theta));
155 uncertPhi = sqrt((*pars->covariance())(Trk::phi,Trk::phi));
156 }
157 double uncertExtrp = uncertEta*uncertEta + uncertPhi*uncertPhi;
158
159 float dr2Cut0 = m_dr*m_dr;
160 // to access the pre-calculated width :
161 static const SG::AuxElement::ConstAccessor<float> sig_acc("sigmaWidth");
162
163 for(const xAOD::CaloCluster * cl : allClusters){
164
165 float dPhi = P4Helpers::deltaPhi( cl->phi(), phi);
166
167 float cl_eta {99};
168 if (m_doDetEta)
169 {
171 cl_eta = detEta(*cl);
172 }
173 else
174 cl_eta = cl->eta();
175
176 float dEta = cl_eta - eta;
177 float dr2 = dPhi*dPhi+ dEta*dEta;
178 float dr2Cut = dr2Cut0;
179
180 if(m_useCovariance) {
181
182 double sigmaWidth = sig_acc(*cl);
183 double uncertClus = 2.*sigmaWidth*sigmaWidth;
184 if(uncertExtrp>uncertClus){
185 ATH_MSG_DEBUG("Extrapolation uncertainty larger than cluster width! Returning without association.");
186 continue;
187 }
188
189 dr2Cut = (sigmaWidth+uncertEta)*(sigmaWidth+uncertEta)+(sigmaWidth+uncertPhi)*(sigmaWidth+uncertPhi);
190 }
191 if( dr2 < dr2Cut ) clusters.push_back( cl );
192 }
193
194 return clusters;
195}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Base class for elements of a container that can have aux data.
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
SG::ReadHandleKey< CaloExtensionCollection > m_caloExtKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_assocClustersDecor
virtual StatusCode execute(const EventContext &ctx) const override
ToolHandle< CP::ITrackVertexAssociationTool > m_trackvertexassoTool
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClusters
SG::ReadDecorHandleKey< xAOD::CaloClusterContainer > m_detectorEtaDecor
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
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleCollectionHandle
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContHandle
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_sigmaWidthKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_caloEntryParsDecor
Tracking class to hold the extrapolation through calorimeter Layers Both the caloEntryLayerIntersecti...
const TrackParameters * caloEntryLayerIntersection() const
access to intersection with the calorimeter entry layer return nullptr if the intersection failed
@ SECOND_R
Second Moment in .
@ CENTER_MAG
Cluster Centroid ( )
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition P4Helpers.h:34
@ theta
Definition ParamDefs.h:66
@ phi
Definition ParamDefs.h:75
ParametersBase< TrackParametersDim, Charged > TrackParameters
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.