ATLAS Offline Software
TrackParticleClusterAssociationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 
10 #include "FourMomUtils/P4Helpers.h"
11 
13 
14 
16  AthAlgorithm(name,pSvcLocator), m_doDetEta{false} { }
17 
19 {
20 
21  if (m_detectorEtaDecor.key().empty())
22  m_doDetEta = false;
23  else
24  {
25  m_doDetEta = true;
27  }
28 
29  ATH_CHECK( m_caloExtKey.initialize() );
34 
36 
37  ATH_CHECK( m_vertexContHandle.initialize( !m_vertexContHandle.empty() ) );
38  if(!m_vertexContHandle.empty() ) {
39  ATH_CHECK(m_trackvertexassoTool.retrieve() );
40  }
41 
42  ATH_MSG_DEBUG(" cluster decoration = "<< m_assocClustersDecor.key() );
43  return StatusCode::SUCCESS;
44 }
45 
47 {
48 
49  ATH_MSG_DEBUG("excute()");
50  // get track particles
52  ATH_MSG_DEBUG("retrieved "<< m_trackParticleCollectionHandle.key()<< " size ="<< trackParticles->size() );
53 
54  // pre-calculate a width of clusters, set it as dynamica attribute so we don't have to recalculate it
56  ATH_MSG_DEBUG("retrieved "<< m_caloClusters.key() << " size = "<< clusterContainer->size() );
57  static const SG::AuxElement::Decorator<float> sig_dec("sigmaWidth");
58  //for(const xAOD::CaloCluster *cl : *clusterContainer){
59  for(const xAOD::CaloCluster *cl : *clusterContainer){
60  double rad;
61  cl->retrieveMoment(xAOD::CaloCluster::SECOND_R,rad);
62  double cent;
63  cl->retrieveMoment(xAOD::CaloCluster::CENTER_MAG,cent);
64 
65  float cl_eta {99};
66  if (m_doDetEta)
67  {
69  cl_eta = detEta(*cl);
70  }
71  else
72  cl_eta = cl->eta();
73 
74  double sigmaWidth = 0.0;
75  if(cent > 0) sigmaWidth = atan(sqrt(rad)/cent)*cosh(cl_eta);
76  sig_dec(*cl) = sigmaWidth;
77  }
78 
79 
80  // obtain the CaloExtension from the map in the event store
82  ATH_MSG_DEBUG("CaloExtensionCollection "<< m_caloExtKey.key() << " : size="<< caloExts->size() );
83 
84  const xAOD::Vertex * pv0 = nullptr;
85  if(!m_vertexContHandle.empty()){
87  if(!vxCont->empty()) pv0=(*vxCont)[0]; // Hard code HS vertex as PV0
88  }
89 
91  std::vector<ElementLink<xAOD::CaloClusterContainer>> > assoClustDecor(m_assocClustersDecor);
92 
93  ATH_MSG_DEBUG("will decorate with "<<assoClustDecor.key()<< " and adding trkParam : "<< m_caloEntryParsDecor.key() );
94 
95  // ******************************************
96  // main loop over tracks
97  unsigned int ntracks = 0;
98  for( const xAOD::TrackParticle* tp : *trackParticles){
99 
100  // retrieve the vector of links to cluster (and creating it )
101  std::vector< ElementLink< xAOD::CaloClusterContainer > > & caloClusterLinks = assoClustDecor(*tp);
102 
103  if( tp->pt() < m_ptCut ) continue;
104 
105  if( pv0 != nullptr) if(! m_trackvertexassoTool->isCompatible(*tp, *pv0 )) continue;
106 
107  ATH_MSG_DEBUG(" Selected track " << tp->index() << " pt " << tp->pt() << " eta " << tp->eta() << " phi " << tp->phi() );
108 
109  // IMMPORTANT : this assumes a correspondance between the TrackParticleContainer and the CaloExtensionCollection !
110  const Trk::CaloExtension * caloExtension = (*caloExts)[tp->index() ] ;
111  if (caloExtension == nullptr ) {
112  ATH_MSG_DEBUG(" Selected track "<< tp->index() << " has no caloExtension ");
113  continue;
114  }
115 
116  // build the associated clusters
117  std::vector<const xAOD::CaloCluster*> assoClusters = associatedClusters( *caloExtension, *clusterContainer);
118 
119  // translate vector of links to cluster in ElementLink
120 
121  caloClusterLinks.reserve( assoClusters.size() );
122  for(const xAOD::CaloCluster* cluster : assoClusters) caloClusterLinks.emplace_back( *clusterContainer,cluster->index() );
123  ntracks++;
124  }// end loop over tracks
125 
126  // 2nd loop over track, only to decorate with Track parameter if requested.
127  if (! m_caloEntryParsDecor.empty() ){
128  // we can not do this in the above loop because declaring a WriteDecorHandle requires a non empty key
129  // (otherwise : run-time error).
131  for( const xAOD::TrackParticle* tp : *trackParticles){
132  const Trk::CaloExtension * caloExtension = (*caloExts)[tp->index() ] ;
133  if (caloExtension == nullptr ) trkParamDecor( *tp ) = nullptr ;
134  else trkParamDecor( *tp ) = caloExtension->caloEntryLayerIntersection();
135  }
136  }
137 
138  ATH_MSG_DEBUG(" Total number of selected tracks: " << ntracks );
139 
140  return StatusCode::SUCCESS;
141 }
142 
143 
144 std::vector<const xAOD::CaloCluster* > TrackParticleClusterAssociationAlg::associatedClusters(const Trk::CaloExtension & caloExtension, const xAOD::CaloClusterContainer & allClusters ){
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:135
xAOD::CaloCluster_v1::SECOND_R
@ SECOND_R
Second Moment in .
Definition: CaloCluster_v1.h:123
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
TrackParticleClusterAssociationAlg::m_useCovariance
Gaudi::Property< bool > m_useCovariance
Definition: TrackParticleClusterAssociationAlg.h:56
TrackParticleClusterAssociationAlg::m_vertexContHandle
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContHandle
Definition: TrackParticleClusterAssociationAlg.h:70
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
TrackParticleClusterAssociationAlg::m_trackParticleCollectionHandle
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleCollectionHandle
Definition: TrackParticleClusterAssociationAlg.h:61
TrackParticleClusterAssociationAlg::m_assocClustersDecor
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_assocClustersDecor
Definition: TrackParticleClusterAssociationAlg.h:75
Trk::CaloExtension
Tracking class to hold the extrapolation from a particle from the ID to the muon system (or the other...
Definition: CaloExtension.h:18
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrackParticleClusterAssociationAlg::initialize
StatusCode initialize() override
Definition: TrackParticleClusterAssociationAlg.cxx:18
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 NULL if the intersection failed
Definition: CaloExtension.h:64
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
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:66
TrackParticleClusterAssociationAlg.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: P4Helpers.h:29
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
TrackParticleClusterAssociationAlg::m_caloEntryParsDecor
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_caloEntryParsDecor
Definition: TrackParticleClusterAssociationAlg.h:76
TrackParticleClusterAssociationAlg::m_dr
Gaudi::Property< float > m_dr
Definition: TrackParticleClusterAssociationAlg.h:55
Trk::theta
@ theta
Definition: ParamDefs.h:72
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:530
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
TrackParticleClusterAssociationAlg::TrackParticleClusterAssociationAlg
TrackParticleClusterAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackParticleClusterAssociationAlg.cxx:15
TrackParticleClusterAssociationAlg::m_caloExtKey
SG::ReadHandleKey< CaloExtensionCollection > m_caloExtKey
Definition: TrackParticleClusterAssociationAlg.h:60
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TrackParticleClusterAssociationAlg::m_ptCut
Gaudi::Property< double > m_ptCut
Definition: TrackParticleClusterAssociationAlg.h:57
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
P4Helpers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrackParticleClusterAssociationAlg::associatedClusters
std::vector< const xAOD::CaloCluster * > associatedClusters(const Trk::CaloExtension &caloExtensions, const xAOD::CaloClusterContainer &allClusters)
returns the clusters from allClusters which are close enough to caloExtensions
Definition: TrackParticleClusterAssociationAlg.cxx:144
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:81
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TrackParticleClusterAssociationAlg::m_trackvertexassoTool
ToolHandle< CP::ITrackVertexAssociationTool > m_trackvertexassoTool
Definition: TrackParticleClusterAssociationAlg.h:71
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:525
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleClusterAssociationAlg::m_doDetEta
bool m_doDetEta
Definition: TrackParticleClusterAssociationAlg.h:67
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:62
python.SystemOfUnits.rad
int rad
Definition: SystemOfUnits.py:111
AuxElement.h
Base class for elements of a container that can have aux data.
TrackParticleClusterAssociationAlg::execute
StatusCode execute() override
Definition: TrackParticleClusterAssociationAlg.cxx:46