14 #include "GaudiKernel/ThreadLocalContext.h"
45 if(m_svContainerName.empty()) {
46 ATH_MSG_ERROR(
"NonPromptLeptonVertexingAlg::initialize - empty SV container name: \"" << m_svContainerName <<
"\"");
47 return StatusCode::FAILURE;
54 ATH_CHECK(m_leptonContainerKey.initialize());
55 ATH_CHECK(m_primaryVertexContainerName.initialize());
56 ATH_CHECK(m_refittedPriVtxContainerName.initialize());
58 ATH_CHECK(m_svContainerName.initialize());
60 m_decoratorNameIndexVectorDeepMerge =
SG::decorKeyFromKey(m_decoratorNameIndexVector.key()) +
"DeepMerge";
61 ATH_CHECK(m_decoratorNameIndexVector.initialize());
62 ATH_CHECK(m_decoratorNameIndexVectorDeepMerge.initialize());
63 ATH_CHECK(m_decoratorNameSecVtxLinks.initialize());
64 ATH_CHECK(m_decoratorNameDeepMergedSecVtxLinks.initialize());
66 ATH_MSG_DEBUG(
"LeptonContainerName = " << m_leptonContainerKey);
67 ATH_MSG_DEBUG(
"ReFitPriVtxContainerName = " << m_refittedPriVtxContainerName);
69 ATH_MSG_DEBUG(
"IndexVectorName = " << m_decoratorNameIndexVector.key());
83 ATH_MSG_DEBUG(
"maxTrackSharedSiHits = " << m_maxTrackSharedSiHits);
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");
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> >;
192 indexVectorDec (m_decoratorNameIndexVector, ctx);
194 indexVectorDecDeepMerge (m_decoratorNameIndexVectorDeepMerge, ctx);
196 lepSVElementLinksDec (m_decoratorNameSecVtxLinks, ctx);
198 lepDeepMergedSVElementLinksDec (m_decoratorNameDeepMergedSecVtxLinks, ctx);
214 if(passElecCand(*elec) && bestmatchedGSFElTrack) {
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);
263 std::vector<std::unique_ptr<xAOD::Vertex>> twoTrkVertices = prepLepWithTwoTrkSVVec(
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");
294 saveSecondaryVertices(twoTrkVerticesCopy, indexVectorTwoTrk, svLinks, SVContainerRef, svSet);
299 ATH_MSG_DEBUG(
"NonPromptLeptonVertexingAlg::execute --- recording " << deep_merged_result.
vtxsNewMerged.size() <<
" merged multi-track vertices");
300 saveSecondaryVertices(deep_merged_result.
vtxsNewMerged, indexVectorDeepMerged, deepmergeSVLinks, SVContainerRef, svSet);
303 saveSecondaryVertices(deep_merged_result.
vtxsInitPassedNotMerged, indexVectorDeepMerged, deepmergeSVLinks, SVContainerRef, svSet);
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 <<
"___________________________________________________________________________");
317 ATH_MSG_DEBUG(
"SV Vertex container " << m_svContainerName <<
" recorded in store");
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
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;
384 if(tracklep.
p4().DeltaR(
track->p4()) < m_minTrackLeptonDR) {
392 if(tracklep.
p4().DeltaR(
track->p4()) > m_maxTrackLeptonDR) {
396 const double delta_z0 =
track->z0() +
track->vz() - priVtx.
z();
398 const double abs_eta = std::abs(
track->eta());
422 if(
track->pt() < m_minTrackpT)
continue;
423 if(abs_eta > m_maxTrackEta)
continue;
424 if(
Z0Sin > m_maxTrackZ0Sin)
continue;
429 if(NSiHits < m_minTrackSiHits)
continue;
430 if(NSiShHits > m_maxTrackSharedSiHits)
continue;
431 if(NSiHoles > m_maxTrackSiHoles )
continue;
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());
503 if(vdist < m_mergeMinVtxDist) {
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?");