From 4ac59bce94ecd4fe9c47470091b516cfd0e6f6be Mon Sep 17 00:00:00 2001
From: abarton <Adam.Edward.Barton@cern.ch>
Date: Thu, 7 Jun 2018 10:24:50 +0100
Subject: [PATCH] Some improvements to FourMuonTool

Former-commit-id: d082076ccee4841f5a81d025433b7a45a358cecc
---
 .../DerivationFrameworkBPhys/FourMuonTool.h   |  8 ++-
 .../src/FourMuonTool.cxx                      | 52 ++++---------------
 2 files changed, 13 insertions(+), 47 deletions(-)

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/FourMuonTool.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/FourMuonTool.h
index d4b9d629a732..ff4ba8c3c72e 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/FourMuonTool.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/FourMuonTool.h
@@ -17,7 +17,6 @@
 #include "TrkVKalVrtFitter/TrkVKalVrtFitter.h"
 #include "DataModel/DataVector.h"
 #include "InDetConversionFinderTools/InDetConversionFinderTools.h"
-#include "HepPDT/ParticleDataTable.hh"
 
 #include "xAODMuon/Muon.h"
 
@@ -154,7 +153,7 @@ namespace DerivationFramework {
         //Doing Calculation and inline functions
         StatusCode performSearch(xAOD::VertexContainer*& pairVxContainer, xAOD::VertexAuxContainer*& pairVxAuxContainer,
                                  xAOD::VertexContainer*& quadVxContainer, xAOD::VertexAuxContainer*& quadVxAuxContainer, bool &acceptEvent);
-        xAOD::Vertex* fit(std::vector<const xAOD::TrackParticle*>,const xAOD::TrackParticleContainer* importedTrackCollection, Amg::Vector3D beamSpot);
+        xAOD::Vertex* fit(const std::vector<const xAOD::TrackParticle*>& ,const xAOD::TrackParticleContainer* importedTrackCollection, const Amg::Vector3D &beamSpot);
         std::vector<std::vector<unsigned int> > getQuadIndices(unsigned int length);
         std::vector<std::pair<unsigned int, unsigned int> > getPairIndices(unsigned int length);
         std::vector<std::vector<unsigned int> > mFromN(unsigned int m, unsigned int n);
@@ -163,15 +162,14 @@ namespace DerivationFramework {
                            std::vector<unsigned int> &combination,
                            std::vector<unsigned int> &mainList,
                            std::vector<std::vector<unsigned int> > &allCombinations);
-        void buildCombinations(std::vector<const xAOD::Muon*> muonsIn,
+        void buildCombinations(const std::vector<const xAOD::Muon*> &muonsIn,
                                std::vector<Combination> &pairs,
                                std::vector<Combination> &quadruplets,
                                unsigned int nSelectedMuons);
-        bool passesQuadSelection(std::vector<const xAOD::Muon*> muonsIn);
+        bool passesQuadSelection(const std::vector<const xAOD::Muon*> &muonsIn);
         //-------------------------------------------------------------------------------------
         
     private:
-        const HepPDT::ParticleDataTable *m_particleDataTable;
         double m_ptCut;
         double m_etaCut;
         bool m_useV0Fitter;
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/src/FourMuonTool.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/src/FourMuonTool.cxx
index 0f5dc2e6fab9..07158b99ba4a 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/src/FourMuonTool.cxx
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/src/FourMuonTool.cxx
@@ -107,7 +107,6 @@ namespace DerivationFramework {
         
     }
     FourMuonTool::FourMuonTool(const std::string& t, const std::string& n, const IInterface* p)  : AthAlgTool(t,n,p),
-    m_particleDataTable(0),
     m_ptCut(0.0),
     m_etaCut(0.0),
     m_useV0Fitter(false),
@@ -324,9 +323,9 @@ namespace DerivationFramework {
     // fit - does the fit
     // ---------------------------------------------------------------------------------
     
-    xAOD::Vertex* FourMuonTool::fit(std::vector<const xAOD::TrackParticle*> inputTracks,
+    xAOD::Vertex* FourMuonTool::fit(const std::vector<const xAOD::TrackParticle*> &inputTracks,
                                     const xAOD::TrackParticleContainer* importedTrackCollection,
-                                    Amg::Vector3D beamSpot) {
+                                    const Amg::Vector3D &beamSpot) {
         
         Trk::TrkV0VertexFitter* concreteVertexFitter=0;
         if (m_useV0Fitter) {
@@ -343,48 +342,17 @@ namespace DerivationFramework {
         //Amg::Vector3D startingPoint = m_vertexEstimator->getCirclesIntersectionPoint(&aPerigee1,&aPerigee2,sflag,errorcode);
         //startingPoint(0) = 0.0; startingPoint(1) = 0.0; startingPoint(2) = 0.0;}
         //Trk::Vertex vertex(beamSpot);
+
+        xAOD::Vertex* myVxCandidate = nullptr;
         if (m_useV0Fitter) {
-            xAOD::Vertex* myVxCandidate = concreteVertexFitter->fit(inputTracks, beamSpot /*vertex startingPoint*/ );
-            
-            // Added by ASC
-            if(myVxCandidate != 0){
-                std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
-                for(unsigned int i=0; i< myVxCandidate->trackParticleLinks().size(); i++)
-                { ElementLink<DataVector<xAOD::TrackParticle> > mylink=myVxCandidate->trackParticleLinks()[i]; //makes a copy (non-const)
-                    mylink.setStorableObject(*importedTrackCollection, true);
-                    mylink.index(); // Use index (should be faster)
-                    newLinkVector.push_back( mylink ); }
-                
-                myVxCandidate->clearTracks();
-                myVxCandidate->setTrackParticleLinks( newLinkVector );
-            }
-            
-            
-            
-            return myVxCandidate;
+            myVxCandidate = concreteVertexFitter->fit(inputTracks, beamSpot /*vertex startingPoint*/ );
         } else {
-            xAOD::Vertex* myVxCandidate = m_iVertexFitter->fit(inputTracks, beamSpot /*vertex startingPoint*/ );
-            
-            // Added by ASC
-            if(myVxCandidate != 0){
-                std::vector<ElementLink<DataVector<xAOD::TrackParticle> > > newLinkVector;
-                for(unsigned int i=0; i< myVxCandidate->trackParticleLinks().size(); i++)
-                { ElementLink<DataVector<xAOD::TrackParticle> > mylink=myVxCandidate->trackParticleLinks()[i]; //makes a copy (non-const)
-                    mylink.setStorableObject(*importedTrackCollection, true);
-                    mylink.index(); // Use index (should be faster)
-                    newLinkVector.push_back( mylink ); }
-                
-                myVxCandidate->clearTracks();
-                myVxCandidate->setTrackParticleLinks( newLinkVector );
-            }
-            
-            
-            return myVxCandidate;
+            myVxCandidate = m_iVertexFitter->fit(inputTracks, beamSpot /*vertex startingPoint*/ );
         }
         
+        BPhysPVTools::PrepareVertexLinks(myVxCandidate, importedTrackCollection);
         
-        
-        return NULL;
+        return myVxCandidate;
         
     } // End of fit method
     
@@ -459,7 +427,7 @@ namespace DerivationFramework {
     // buildCombinations: forms up the quadruplet of muons/tracks
     // ---------------------------------------------------------------------------------
     
-    void FourMuonTool::buildCombinations(std::vector<const xAOD::Muon*> muonsIn,
+    void FourMuonTool::buildCombinations(const std::vector<const xAOD::Muon*> &muonsIn,
                                          std::vector<Combination> &pairs,
                                          std::vector<Combination> &quadruplets,
                                          unsigned int nSelectedMuons) {
@@ -501,7 +469,7 @@ namespace DerivationFramework {
     // passesQuadSelection: 4-muon selection
     // ---------------------------------------------------------------------------------
     
-    bool FourMuonTool::passesQuadSelection(std::vector<const xAOD::Muon*> muons) {
+    bool FourMuonTool::passesQuadSelection(const std::vector<const xAOD::Muon*> &muons) {
         bool accept(false);
         bool charges(true);
         bool quality(false);
-- 
GitLab