ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterVertexFractionMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// in contrary to CaloClusterVertexFractionMakerAthAlg this is a CaloClusterCollectionProcessor and not an Athena Algorithm
7
14
17
19
21
22#include <cmath>
23
25
26
27CaloClusterVertexFractionMaker::CaloClusterVertexFractionMaker(const std::string& type, const std::string& name, const IInterface* parent)
28 : AthAlgTool(type, name, parent),
29 m_CALO_INNER_R(1450.), // millimeter
30 m_CALO_INNER_Z(3641.), // millimeter
31 m_dRMatchMax(0.1),
32 m_dR2MatchMax(0.), // will be overwritten in initialize
33 m_maxClusterEta(2.5),
34 m_extrapolator("Trk::Extrapolator/AtlasExtrapolator"),
35 m_vxContainerName("VxPrimaryCandidate")
36{
37 declareProperty ( "Extrapolator", m_extrapolator );
38 declareProperty ( "VxContainerName", m_vxContainerName );
39 declareProperty ( "dRMatchMax", m_dRMatchMax );
40 declareProperty ( "maxClusterEta", m_maxClusterEta );
41}
42
44{
45 // all delete statements are in finalize (otherwise genconf crashes .. no idea why)
46}
47
49{
50 ATH_MSG_INFO( "Initializing " << name() );
51 ATH_MSG_INFO( "Only considering clusters with |eta| < " << m_maxClusterEta << "\tdRMatchMax Cluster-Track = " << m_dRMatchMax );
52
54
55 /* Get the extrapolator */
56 ATH_CHECK( m_extrapolator.retrieve() );
57 ATH_MSG_INFO( "Retrieved tool " << m_extrapolator );
58
59 // a surface at the entrance to the calorimeter
60// HepGeom::TranslateZ3D* translateAlongPositiveZ = new HepGeom::TranslateZ3D(m_CALO_INNER_Z);
61// HepGeom::TranslateZ3D* translateAlongNegativeZ = new HepGeom::TranslateZ3D(-m_CALO_INNER_Z);
62 Amg::Transform3D translateAlongPositiveZ = Amg::Transform3D(Amg::Vector3D(0.,0.,m_CALO_INNER_Z));
63 Amg::Transform3D translateAlongNegativeZ = Amg::Transform3D(Amg::Vector3D(0.,0.,m_CALO_INNER_Z));
64
65 m_cylinderSurface_atCaloEntrance = std::make_unique<Trk::CylinderSurface>(m_CALO_INNER_R, 8000.);
66 m_discSurface_atCaloEntrance_positiveZ = std::make_unique<Trk::DiscSurface>(translateAlongPositiveZ, 0., 10000.);
67 m_discSurface_atCaloEntrance_negativeZ = std::make_unique<Trk::DiscSurface>(translateAlongNegativeZ, 0., 10000.);
68
69 return StatusCode::SUCCESS;
70}
71
72StatusCode
74 xAOD::CaloClusterContainer* caloClusterContainer) const
75{
76 const VxContainer* primcontainer(nullptr);
78 {
79 if ( evtStore()->retrieve ( primcontainer, m_vxContainerName ).isFailure() )
80 {
81 ATH_MSG_WARNING( "Could not retrieve collection " << m_vxContainerName << " in StoreGate, but contains<> says it is there." );
82 return StatusCode::FAILURE;
83 }
84 } else {
85 ATH_MSG_WARNING( "No collection " << m_vxContainerName << " in StoreGate." );
86 return StatusCode::FAILURE;
87 }
88
89 // loop over vertices, extrapolate tracks to calo, remember num tracks per vertex (for cluster vertex fraction calculation later)
90 std::vector<unsigned int> numTracksPerVertex(primcontainer->size()-1, 0);
91 std::vector<float> trkParticlePt_atOrigin;
92 std::vector<float> trkParticleEta_atCaloEntrance;
93 std::vector<float> trkParticlePhi_atCaloEntrance;
94
95 for (unsigned int v = 0 ; v < primcontainer->size()-1; ++v)
96 {
97 const std::vector<Trk::VxTrackAtVertex*>* vxTrackAtVertex = primcontainer->at(v)->vxTrackAtVertex();
98 for (std::vector<Trk::VxTrackAtVertex*>::const_iterator vxTrkItr = vxTrackAtVertex->begin(); vxTrkItr != vxTrackAtVertex->end(); ++vxTrkItr)
99 {
101 Trk::ITrackLink* trklink = (*vxTrkItr)->trackOrParticleLink();
102 Trk::LinkToTrackParticleBase* linkToTrackParticle = dynamic_cast<Trk::LinkToTrackParticleBase*>(trklink);
103 if (linkToTrackParticle != nullptr && linkToTrackParticle->isValid()) {
104 const Rec::TrackParticle* theTrackParticle = dynamic_cast<const Rec::TrackParticle*>(linkToTrackParticle->cachedElement());
105 if (theTrackParticle != nullptr)
106 {
107 const Trk::TrackParameters* trackParameters_atCaloEntrance(nullptr);
108 numTracksPerVertex.at(v)++;
109 trkParticlePt_atOrigin.push_back (theTrackParticle->pt()/1.e3);
110
111 const Trk::TrackParameters* lastTrackParametersInID(nullptr);
112 const std::vector< const Trk::TrackParameters * >& trackParametersVector = theTrackParticle->trackParameters();
113 if (trackParametersVector.size() > 1) lastTrackParametersInID = trackParametersVector.at(trackParametersVector.size()-2);
114 else lastTrackParametersInID = trackParametersVector.at(0); // the perigee
115
116 // very simplified way for now to decide to extrapolate a track to barrel or endcap
117 if (theTrackParticle->eta() >
118 1.35) // track most likely in endcap A, extrapolate track to a
119 // disc at ID exist in positive z direction
120 {
121 trackParameters_atCaloEntrance =
122 dynamic_cast<const Trk::AtaDisc*>(m_extrapolator->extrapolate(
123 ctx,
124 *lastTrackParametersInID,
127 true,
128 Trk::pion).release());
129 } else if (theTrackParticle->eta() <
130 -1.35) // track most likely in endcap C, extrapolate track
131 // to a disc at ID exist in negative z direction
132 {
133 trackParameters_atCaloEntrance =
134 dynamic_cast<const Trk::AtaDisc*>(m_extrapolator->extrapolate(
135 ctx,
136 *lastTrackParametersInID,
139 true,
140 Trk::pion).release());
141 } else // track is in barrel, extrapolate to cylinder at ID exit
142 {
143 trackParameters_atCaloEntrance =
144 dynamic_cast<const Trk::AtaCylinder*>(
145 m_extrapolator->extrapolate(ctx,
146 *lastTrackParametersInID,
149 true,
150 Trk::pion).release());
151 }
152 if (trackParameters_atCaloEntrance != nullptr) {
153 trkParticleEta_atCaloEntrance.push_back(trackParameters_atCaloEntrance->position().eta());
154 trkParticlePhi_atCaloEntrance.push_back(trackParameters_atCaloEntrance->position().phi());
155 ATH_MSG_DEBUG( "At calo entrance R(1150mm) " << *trackParameters_atCaloEntrance );
156 ATH_MSG_DEBUG( "TrkParticle eta/phi/pt[GeV] at calo " << trackParameters_atCaloEntrance->position().eta() << "\t"
157 << trackParameters_atCaloEntrance->position().phi() << "\t"
158 << trackParameters_atCaloEntrance->position().perp()/1.e3 );
159 delete trackParameters_atCaloEntrance;
160 } else {
161 trkParticleEta_atCaloEntrance.push_back(999.);
162 trkParticlePhi_atCaloEntrance.push_back(999.);
163 }
164 }
165 }
166 }
167 }
168
169 double fabs_Dphi(9999.);
170 double fabs_Deta(9999.);
171 double dR2(9999.);
172 std::vector<float> sumPtOfMatchedTracksPerVertex(numTracksPerVertex.size(), 0.);
173
174 for (xAOD::CaloClusterContainer::iterator clItr = caloClusterContainer->begin(); clItr != caloClusterContainer->end(); ++clItr)
175 {
176 xAOD::CaloCluster* theCluster = (*clItr);
177// double cl_theta = 2.*atan(exp(-theCluster->eta()));
178// double cl_et = theCluster->e()/1.e3*sin(cl_theta);
179 if (std::fabs(theCluster->eta()) < 2.5)
180 {
181 // Calculation of Cluster Vertex Fraction
182 std::vector<unsigned int>::iterator numTrksPerVertexItr = numTracksPerVertex.begin();
183 std::vector<unsigned int>::iterator numTrksPerVertexItrE = numTracksPerVertex.end();
184 unsigned int vertexCounter(0);
185 unsigned int totalTrackCounter(0);
186 for ( ; numTrksPerVertexItr != numTrksPerVertexItrE ; ++numTrksPerVertexItr, vertexCounter++)
187 {
188 sumPtOfMatchedTracksPerVertex.at(vertexCounter) = 0.;
189 for (unsigned int track = 0; track < (*numTrksPerVertexItr); ++track, totalTrackCounter++)
190 {
191 if (trkParticleEta_atCaloEntrance.at(totalTrackCounter) < 900.) // no need to check phi as well (not extrapolated eta is set to 999.)
192 {
193 fabs_Dphi = calculateDPhi(trkParticlePhi_atCaloEntrance.at(totalTrackCounter), theCluster->phi());
194 fabs_Deta = fabs(trkParticleEta_atCaloEntrance.at(totalTrackCounter) - theCluster->eta());
195 dR2 = fabs_Deta * fabs_Deta + fabs_Dphi * fabs_Dphi;
196 if (dR2 < m_dR2MatchMax) {
197 sumPtOfMatchedTracksPerVertex.at(vertexCounter) += trkParticlePt_atOrigin.at(totalTrackCounter);
198 }
199 }
200 }
201 }
202 double totalSumPtOfMatchedTracksWhichWereAlsoUsedInAVertex(0.);
203 for (unsigned int mTpV = 0; mTpV < sumPtOfMatchedTracksPerVertex.size(); ++mTpV) {
204 totalSumPtOfMatchedTracksWhichWereAlsoUsedInAVertex += sumPtOfMatchedTracksPerVertex.at(mTpV);
205 //std::cout << "CaloClusterVertexFractionMakerAOD: " << mTpV << "\t" << sumPtOfMatchedTracksPerVertex.at(mTpV) << std::endl;
206 }
207
208 double cvf(-1.);
209 double ncvf(-1.);
210 if (totalSumPtOfMatchedTracksWhichWereAlsoUsedInAVertex > 0.)
211 {
212 double sumPtInPrimary = sumPtOfMatchedTracksPerVertex.at(0);
213 cvf = sumPtOfMatchedTracksPerVertex.at(0)/totalSumPtOfMatchedTracksWhichWereAlsoUsedInAVertex;
214 std::sort(sumPtOfMatchedTracksPerVertex.begin(), sumPtOfMatchedTracksPerVertex.end());
215 double highestSumPt = sumPtOfMatchedTracksPerVertex.at(sumPtOfMatchedTracksPerVertex.size()-1);
216 if (highestSumPt > 0) ncvf = sumPtInPrimary/highestSumPt;
217 }
218 //std::cout << "CaloClusterVertexFractionMakerAOD: cvf " << cvf << "\tncvf " << ncvf << std::endl;
219 theCluster->insertMoment(xAOD::CaloCluster::VERTEX_FRACTION, cvf); // false at the end writes the moment into the moment store of the cluster directly (the moment is then written to AOD as well)
220 theCluster->insertMoment(xAOD::CaloCluster::NVERTEX_FRACTION, ncvf); // false at the end writes the moment into the moment store of the cluster directly (the moment is then written to AOD as well)
221 } else {
222 theCluster->insertMoment(xAOD::CaloCluster::VERTEX_FRACTION, -1.); // false at the end writes the moment into the moment store of the cluster directly (the moment is then written to AOD as well)
223 theCluster->insertMoment(xAOD::CaloCluster::NVERTEX_FRACTION, -1.); // false at the end writes the moment into the moment store of the cluster directly (the moment is then written to AOD as well)
224 }
225 }
226
227 return StatusCode::SUCCESS;
228}
229
230double CaloClusterVertexFractionMaker::calculateDPhi(double phi1, double phi2)
231{
232 double dPhi = std::fabs(phi1 - phi2);
233 if (dPhi > M_PI) dPhi = 2.*M_PI - dPhi;
234// if (dPhi > 3.1415926535897931) dPhi = 6.2831853071795862 - dPhi;
235 return dPhi;
236}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
std::unique_ptr< Trk::Surface > m_discSurface_atCaloEntrance_positiveZ
std::unique_ptr< Trk::Surface > m_cylinderSurface_atCaloEntrance
ToolHandle< Trk::IExtrapolator > m_extrapolator
std::unique_ptr< Trk::Surface > m_discSurface_atCaloEntrance_negativeZ
static double calculateDPhi(double phi1, double phi2)
CaloClusterVertexFractionMaker(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *theClusColl) const override
Execute on an entire collection of clusters.
const T * at(size_type n) const
Access an element, as an rvalue.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual double pt() const =0
transverse momentum
virtual double eta() const =0
pseudo rapidity
const Amg::Vector3D & position() const
Access method for the position.
const std::vector< const TrackParameters * > & trackParameters() const
Returns the track parameters.
std::vector< Trk::VxTrackAtVertex * > * vxTrackAtVertex(void)
Unconst pointer to the vector of tracks Required by some of the vertex fitters.
virtual double eta() const
The pseudorapidity ( ) of the particle.
void insertMoment(MomentType type, double value)
virtual double phi() const
The azimuthal angle ( ) of the particle.
@ VERTEX_FRACTION
Vertex fraction of this cluster wrt.
@ NVERTEX_FRACTION
slightly updated vertex fraction more pile up independent (similar to nJVF)
static std::string release
Definition computils.h:50
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
ParametersT< TrackParametersDim, Charged, DiscSurface > AtaDisc
@ alongMomentum
ParametersBase< TrackParametersDim, Charged > TrackParameters
ParametersT< TrackParametersDim, Charged, CylinderSurface > AtaCylinder
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.