14#include "GaudiKernel/ThreadLocalContext.h"
47 return StatusCode::FAILURE;
87 return StatusCode::SUCCESS;
103 return StatusCode::SUCCESS;
114 const EventContext& ctx = Gaudi::Hive::currentContext();
123 ATH_MSG_FATAL(
"execute - failed to find the InDetTrackParticles");
124 return StatusCode::FAILURE;
132 std::set< xAOD::Vertex* > svSet;
136 std::make_unique< xAOD::VertexContainer>(), std::make_unique< xAOD::VertexAuxContainer>()
147 ATH_MSG_DEBUG (
"NonPromptLeptonVertexingAlg::execute - Read " << vertices->size() <<
" primary vertices");
148 ATH_MSG_DEBUG (
"NonPromptLeptonVertexingAlg::execute - Read " << refittedVertices->size() <<
" refitted primary vertices");
157 fittingInput.
priVtx = vertex;
162 if(!fittingInput.
priVtx) {
163 ATH_MSG_INFO(
"Failed to find primary vertex - skip this event");
165 return StatusCode::SUCCESS;
172 short refittedVertexType = 0;
186 ATH_MSG_DEBUG(
"\n\t\t\t Size of lepton container: " << leptonContainer ->size());
190 using VecElemVtx_t = std::vector<ElementLink<xAOD::VertexContainer> >;
219 if(
passMuonCand(*muon) && muon->inDetTrackParticleLink().isValid()) {
220 tracklep = *(muon->inDetTrackParticleLink());
224 ATH_MSG_WARNING(
"NonPromptLeptonVertexingAlg::execute - failed to find electron or muon: should never happen!");
228 lepSVElementLinksDec (*lepton).clear();
229 lepDeepMergedSVElementLinksDec(*lepton).clear();
230 indexVectorDec (*lepton).clear();
231 indexVectorDecDeepMerge (*lepton).clear();
233 ATH_MSG_DEBUG(
"NonPromptLeptonVertexingAlg::execute - cannot find muon->inDetTrackParticleLink() nor electron->trackParticle()");
237 ATH_MSG_DEBUG(
"NonPromptLeptonVertexingAlg::execute - process new lepton track " << tracklep);
250 ATH_MSG_DEBUG(
"DecorateSecondaryVertex - found refitted primary vertex without lepton: "
258 std::vector<const xAOD::TrackParticle* > ifitTracks =
findNearbyTracks(*tracklep, inDetTracks, *fittingInput.
priVtx);
264 fittingInput, tracklep, ifitTracks
269 std::vector<std::unique_ptr<xAOD::Vertex>> twoTrkVerticesCopy;
270 for (std::unique_ptr<xAOD::Vertex> &vtx : twoTrkVertices) {
271 std::unique_ptr<xAOD::Vertex> newVtx = std::make_unique<xAOD::Vertex>(*vtx);
272 twoTrkVerticesCopy.push_back(std::move(newVtx));
277 ATH_MSG_DEBUG(
"Starting with " << twoTrkVertices.size() <<
" 2-track vertices");
279 fittingInput, tracklep, twoTrkVertices, ifitTracks);
284 std::vector<ElementLink<xAOD::VertexContainer> > svLinks;
285 std::vector<ElementLink<xAOD::VertexContainer> > deepmergeSVLinks;
287 std::vector<int> indexVectorTwoTrk;
288 std::vector<int> indexVectorDeepMerged;
293 ATH_MSG_DEBUG(
"NonPromptLeptonVertexingAlg::execute --- recording " << twoTrkVerticesCopy.size() <<
" 2-track and simple merged vertices");
299 ATH_MSG_DEBUG(
"NonPromptLeptonVertexingAlg::execute --- recording " << deep_merged_result.
vtxsNewMerged.size() <<
" merged multi-track vertices");
305 ATH_MSG_DEBUG (
"NonPromptLeptonVertexingAlg::execute -- number of two-track SV = " << twoTrkVertices.size());
306 ATH_MSG_DEBUG (
"NonPromptLeptonVertexingAlg::execute -- number of deep merged SV = " << deep_merged_result.
vtxsNewMerged.size());
308 lepSVElementLinksDec (*lepton) = std::move(svLinks);
309 lepDeepMergedSVElementLinksDec(*lepton) = std::move(deepmergeSVLinks);
310 indexVectorDec (*lepton) = std::move(indexVectorTwoTrk);
311 indexVectorDecDeepMerge (*lepton) = std::move(indexVectorDeepMerged);
313 ATH_MSG_DEBUG(
"NonPromptLeptonVertexingAlg - done with lepton pT=" << tracklep->
pt() <<
", " <<
truthAsStr(*lepton) << endl
314 <<
"___________________________________________________________________________");
319 ATH_MSG_DEBUG(
" NonPromptLeptonVertexingAlg::execute - done with this event" << endl
320 <<
"___________________________________________________________________________");
322 return StatusCode::SUCCESS;
336 <<
"pT=" << elec.
pt() <<
", eta=" << elec.
eta() <<
", phi=" << elec.
phi() << std::endl
337 <<
" DFCommonElectronsLHLoose = " <<
int(lh_loose) << std::endl
353 const bool combined = (muon.muonType() == xAOD::Muon::Combined);
356 <<
"pT=" << muon.pt() <<
", eta=" << muon.eta() <<
", phi=" << muon.phi() << std::endl
357 <<
" Type = " << muon.muonType() << std::endl
358 <<
" Combined = " << combined << std::endl
373 std::vector<const xAOD::TrackParticle *> mytracks;
396 const double delta_z0 = track->z0() + track->vz() - priVtx.
z();
397 const double Z0Sin = std::abs(delta_z0*std::sin(track->theta()));
398 const double abs_eta = std::abs(track->eta());
400 uint8_t numberOfPixelHits = 0;
401 uint8_t numberOfSCTHits = 0;
402 uint8_t numberOfPixelHoles = 0;
403 uint8_t numberOfSCTHoles = 0;
404 uint8_t numberOfPixelSharedHits = 0;
405 uint8_t numberOfSCTSharedHits = 0;
414 const uint8_t NSiHits = numberOfPixelHits + numberOfSCTHits;
415 const uint8_t NSiHoles = numberOfPixelHoles + numberOfSCTHoles;
416 const float NSiShHits = float(numberOfPixelSharedHits) + float(numberOfSCTSharedHits)/2.0;
435 mytracks.push_back(track);
445 const std::vector<const xAOD::TrackParticle*> &tracks
452 std::vector<std::unique_ptr<xAOD::Vertex>> twoTrkVertices;
453 std::vector<const xAOD::TrackParticle*> tracksForFit;
456 ATH_MSG_WARNING(
"prepLepWithTwoTrkSVVec -- invalid primary vertex: nothing to do");
457 return twoTrkVertices;
461 tracksForFit.clear();
462 tracksForFit.push_back(tracklep);
463 tracksForFit.push_back(selectedtrack);
465 std::unique_ptr<xAOD::Vertex> newSecondaryVertex =
m_vertexFitterTool->fitVertexWithPrimarySeed(
469 if(!newSecondaryVertex) {
470 ATH_MSG_DEBUG(
"prepLepWithTwoTrkSVVec -- failed to fit 2-track vertex");
474 twoTrkVertices.push_back(std::move(newSecondaryVertex));
477 return twoTrkVertices;
482 std::vector<std::unique_ptr<xAOD::Vertex>> &clusterVtxs,
483 std::vector<std::unique_ptr<xAOD::Vertex>> &inputVtxs
486 ATH_MSG_DEBUG(
"makeVertexCluster - before: clusterVtxs.size()=" << clusterVtxs.size() <<
", inputVtxs.size()=" << inputVtxs.size());
488 std::vector<std::unique_ptr<xAOD::Vertex>>::iterator vit = inputVtxs.begin();
490 while(vit != inputVtxs.end()) {
493 for(std::vector<std::unique_ptr<xAOD::Vertex>>::const_iterator cit = clusterVtxs.begin(); cit != clusterVtxs.end(); ++cit) {
494 if(vit->get() == cit->get()) {
495 ATH_MSG_DEBUG(
"makeVertexCluster - logic error - found the same vertex twice: " << ((*vit).get()));
499 const double vdist =
getDistance((*vit)->position(), (*cit)->position());
510 clusterVtxs.push_back(std::move(*vit));
511 inputVtxs.erase(vit);
513 vit = inputVtxs.begin();
520 ATH_MSG_DEBUG(
"makeVertexCluster - after: clusterVtxs.size()=" << clusterVtxs.size() <<
", inputVtxs.size()=" << inputVtxs.size());
525 std::vector<std::unique_ptr<xAOD::Vertex>> &vtxs,
526 std::vector<int> &indexVector,
529 std::set< xAOD::Vertex* >& svSet
535 ATH_MSG_DEBUG(
"saveSecondaryVertices - will save " << vtxs.size() <<
" vertexes");
537 for(std::unique_ptr<xAOD::Vertex> &vtx: vtxs) {
540 indexVector.push_back(
index);
543 ATH_MSG_WARNING(
"saveSecondaryVertices - missing \"SecondaryVertexIndex\" variable");
546 if(svSet.insert(vtx.get()).second) {
552 svLinks.push_back(svLink);
554 ATH_MSG_ERROR(
"saveSecondaryVertices --- the same vertex has been encountered more than once! Is this a logic error?");
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Some common helper functions used by decoration handles.
Handle class for adding a decoration to an object.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
ElementLink implementation for ROOT usage.
bool isValid() const
Test to see if the link can be dereferenced.
Gaudi::Property< std::string > m_linkNameRefittedPriVtxWithoutLepton
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoratorNameIndexVector
Gaudi::Property< float > m_minTrackLeptonDR
Gaudi::Property< float > m_maxTrackSharedSiHits
SG::WriteHandleKey< xAOD::VertexContainer > m_svContainerName
virtual StatusCode execute() override
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoratorNameIndexVectorDeepMerge
void saveSecondaryVertices(std::vector< std::unique_ptr< xAOD::Vertex > > &vtxs, std::vector< int > &indexVector, std::vector< ElementLink< xAOD::VertexContainer > > &svLinks, xAOD::VertexContainer &SVContainer, std::set< xAOD::Vertex * > &svSet)
ToolHandle< Prompt::IVertexMergingTool > m_vertexMerger
Gaudi::Property< float > m_maxTrackEta
virtual StatusCode initialize() override
ToolHandle< Prompt::VertexFittingTool > m_vertexFitterTool
Gaudi::Property< double > m_mergeMinVtxDist
Gaudi::Property< float > m_maxTrackLeptonDR
Gaudi::Property< unsigned > m_maxTrackSiHoles
Gaudi::Property< float > m_minTrackpT
std::vector< std::unique_ptr< xAOD::Vertex > > prepLepWithTwoTrkSVVec(const FittingInput &input, const xAOD::TrackParticle *tracklep, const std::vector< const xAOD::TrackParticle * > &tracks)
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoratorNameSecVtxLinks
virtual StatusCode finalize() override
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVertexContainerName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inDetTracksKey
bool passMuonCand(const xAOD::Muon &muon) const
Gaudi::Property< bool > m_printTime
SG::ReadHandleKey< xAOD::IParticleContainer > m_leptonContainerKey
Gaudi::Property< unsigned > m_maxTrackPixHoles
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoratorNameDeepMergedSecVtxLinks
Gaudi::Property< bool > m_selectTracks
Gaudi::Property< float > m_maxTrackZ0Sin
void makeVertexCluster(std::vector< std::unique_ptr< xAOD::Vertex > > &clusterVtxs, std::vector< std::unique_ptr< xAOD::Vertex > > &inputVtxs)
bool passElecCand(const xAOD::Electron &elec) const
Gaudi::Property< unsigned > m_minTrackSiHits
Gaudi::Property< double > m_mergeChi2OverDoF
std::vector< const xAOD::TrackParticle * > findNearbyTracks(const xAOD::TrackParticle &tracklep, const xAOD::TrackParticleContainer &inDetTracks, const xAOD::Vertex &priVtx) const
Gaudi::Property< std::string > m_refittedVertexTypeName
NonPromptLeptonVertexingAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::VertexContainer > m_refittedPriVtxContainerName
SG::ConstAccessor< T, ALLOC > ConstAccessor
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
const xAOD::TrackParticle * trackParticle(size_t index=0) const
Pointer to the xAOD::TrackParticle/s that match the electron candidate.
Class providing the definition of the 4-vector interface.
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
float z() const
Returns the z position.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
bool GetAuxVar(const T1 &obj, T2 &value, const std::string &var_name)
std::string PrintResetStopWatch(TStopwatch &watch)
std::string truthAsStr(const xAOD::IParticle &particle)
bool getVar(T1 &obj, T2 &value, const std::string &var_name)
double getDistance(const xAOD::Vertex *vtx1, const xAOD::Vertex *vtx2)
std::string decorKeyFromKey(const std::string &key, const std::string &deflt)
Extract the decoration part of key.
const xAOD::TrackParticle * getOriginalTrackParticleFromGSF(const xAOD::TrackParticle *trkPar)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the GSF Track Particle...
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version:
@ numberOfPixelHoles
number of pixel layers on track with absence of hits [unit8_t].
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
@ numberOfPixelSharedHits
number of Pixel all-layer hits shared by several tracks [unit8_t].
@ numberOfSCTSharedHits
number of SCT hits shared by several tracks [unit8_t].
@ numberOfSCTHoles
number of SCT holes [unit8_t].
Electron_v1 Electron
Definition of the current "egamma version".
std::vector< std::unique_ptr< xAOD::Vertex > > vtxsInitPassedNotMerged
std::vector< std::unique_ptr< xAOD::Vertex > > vtxsNewMerged