diff --git a/Tracking/TrkVertexFitter/TrkVertexFitterInterfaces/TrkVertexFitterInterfaces/IVertexWeightCalculator.h b/Tracking/TrkVertexFitter/TrkVertexFitterInterfaces/TrkVertexFitterInterfaces/IVertexWeightCalculator.h index 53dca2f118c0e0597d3affeb1f0cc16b85f04215..d259a567a4851ba2b5f877a7d36192c9a01175a9 100755 --- a/Tracking/TrkVertexFitter/TrkVertexFitterInterfaces/TrkVertexFitterInterfaces/IVertexWeightCalculator.h +++ b/Tracking/TrkVertexFitter/TrkVertexFitterInterfaces/TrkVertexFitterInterfaces/IVertexWeightCalculator.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// @@ -11,44 +11,48 @@ #include "GaudiKernel/IAlgTool.h" -//xAOD include -#include "xAODTracking/VertexFwd.h" -#include "xAODTracking/VertexAuxContainer.h" +// xAOD include #include "xAODTracking/TrackParticleFwd.h" +#include "xAODTracking/VertexAuxContainer.h" +#include "xAODTracking/VertexFwd.h" -namespace Trk -{ - static const InterfaceID IID_IVertexWeightCalculator("IVertexWeightCalculator", 1, 0); - - /** - @class IVertexWeightCalculaculator - @brief Interface class for signal vertex selection. - - For more detailed information, take a look at the header file of the actual - implementation files. - - --------------------------------------------------- - Changes: +namespace Trk { +static const InterfaceID IID_IVertexWeightCalculator("IVertexWeightCalculator", + 1, + 0); - David Shope <david.richard.shope@cern.ch> (2016-06-01) +/** + @class IVertexWeightCalculaculator + @brief Interface class for signal vertex selection. - EDM Migration to xAOD - remove method using VxCandidate + For more detailed information, take a look at the header file of the actual + implementation files. - */ + --------------------------------------------------- + Changes: - class IVertexWeightCalculator : virtual public IAlgTool { + David Shope <david.richard.shope@cern.ch> (2016-06-01) + EDM Migration to xAOD - remove method using VxCandidate - public: - /** Virtual destructor */ - virtual ~IVertexWeightCalculator(){}; +*/ - /** AlgTool interface methods */ - static const InterfaceID& interfaceID() { return IID_IVertexWeightCalculator; }; +class IVertexWeightCalculator : virtual public IAlgTool +{ - /** Interface for @c xAOD::Vertex */ - virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex) = 0; +public: + /** Virtual destructor */ + virtual ~IVertexWeightCalculator() = default; + /** AlgTool interface methods */ + static const InterfaceID& interfaceID() + { + return IID_IVertexWeightCalculator; }; + + /** Interface for @c xAOD::Vertex */ + virtual double estimateSignalCompatibility( + const xAOD::Vertex& vertex) const = 0; +}; } #endif diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/CMakeLists.txt b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/CMakeLists.txt index 884aa25c094365c6ace327053ccc063410f26068..5d0cf006c09892b27015c15ceddc9c760d2c2b6f 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/CMakeLists.txt +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/CMakeLists.txt @@ -27,7 +27,8 @@ atlas_add_component( TrkVertexWeightCalculators src/*.cxx src/components/*.cxx INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives xAODTracking GaudiKernel TrkVertexFitterInterfaces GeneratorObjects TrkParameters VxVertex TrkNeuralNetworkUtilsLib ) + LINK_LIBRARIES ${ROOT_LIBRARIES} ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives xAODTracking GaudiKernel TrkVertexFitterInterfaces + GeneratorObjects TrkParameters VxVertex TrkNeuralNetworkUtilsLib) # Install files from the package: atlas_install_headers( TrkVertexWeightCalculators ) diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/ATLAS_CHECK_THREAD_SAFETY b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..702d27a445a9954b35551772baea0ce3783bd031 --- /dev/null +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +Tracking/TrkVertexFitter/TrkVertexWeightCalculators diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/NNVertexWeightCalculator.h b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/NNVertexWeightCalculator.h index 61e68a51981d38569302a8817b99e04e230e22a8..405f28870517a9f4a75c15624df6860e47ce97ca 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/NNVertexWeightCalculator.h +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/NNVertexWeightCalculator.h @@ -1,78 +1,81 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TrkVertexWeightCalculator_NNVertexWeightCalculator_H #define TrkVertexWeightCalculator_NNVertexWeightCalculator_H - + #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ToolHandle.h" #include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" -#include <vector> #include <TString.h> - -//xAOD include -#include "xAODTracking/VertexFwd.h" -#include "xAODTracking/VertexAuxContainer.h" +#include <vector> +#include <memory> +// xAOD include #include "xAODTracking/TrackParticleFwd.h" +#include "xAODTracking/VertexAuxContainer.h" +#include "xAODTracking/VertexFwd.h" - /** - * @class Trk::NNVertexWeightCalculator - * - * @author Johanna Bronner, April 2009 - * - * --------------------------------------------------- - * Changes: - * - * David Shope <david.richard.shope@cern.ch> (2016-06-01) - * - * EDM Migration to xAOD - remove method using VxCandidate - * - */ +#include "TrkNeuralNetworkUtils/NeuralNetworkToHistoTool.h" +#include "TrkNeuralNetworkUtils/TTrainedNetwork.h" +/** + * @class Trk::NNVertexWeightCalculator + * + * @author Johanna Bronner, April 2009 + * + * --------------------------------------------------- + * Changes: + * + * David Shope <david.richard.shope@cern.ch> (2016-06-01) + * + * EDM Migration to xAOD - remove method using VxCandidate + * + */ -class TTrainedNetwork; class TH1; class ITHistSvc; - namespace Trk - { - class NeuralNetworkToHistoTool; - - class NNVertexWeightCalculator : public AthAlgTool, virtual public IVertexWeightCalculator - { - public: - StatusCode initialize(); - StatusCode finalize(); - - /** - * constructor - */ - NNVertexWeightCalculator(const std::string& t, const std::string& n, const IInterface* p); - - /** - * destructor - */ - virtual ~NNVertexWeightCalculator(); - - /** - * WeightCalculator - */ - virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex); - - private: +namespace Trk { + +class NNVertexWeightCalculator + : public AthAlgTool + , virtual public IVertexWeightCalculator +{ +public: + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + + /** + * constructor + */ + NNVertexWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p); + + /** + * destructor + */ + virtual ~NNVertexWeightCalculator() = default; + + /** + * WeightCalculator + */ + virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex) const override final; + +private: + double mEstimateSignalCompatibility( + const std::vector<const Trk::TrackParameters*>& tpList) const; - double mEstimateSignalCompatibility(const std::vector<const Trk::TrackParameters*>& tpList); - - ToolHandle<Trk::NeuralNetworkToHistoTool> m_networkToHistoTool; - TTrainedNetwork *m_NN; - int m_NLayers; - ITHistSvc* m_iTHistSvc; - std::string m_directoryName; - std::vector <TH1*> m_NNhistos; - double sphericityFunc(std::vector <std::vector<double> > v_P); - double LogFunc(double value); + double sphericityFunc(std::vector<std::vector<double>> v_P) const; + double LogFunc(double value) const; - }; //end of class description - }//end of namespace definition + ToolHandle<Trk::NeuralNetworkToHistoTool> m_networkToHistoTool; + std::unique_ptr<TTrainedNetwork> m_NN; + int m_NLayers; + ITHistSvc* m_iTHistSvc; + std::string m_directoryName; + std::vector<TH1*> m_NNhistos; +}; // end of class description +} // end of namespace definition - #endif +#endif diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/SumPtVertexWeightCalculator.h b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/SumPtVertexWeightCalculator.h index 11307c520f653fd4f944e70718fbd00bfab1a287..4439cd65c97a500f66647b3ecc0c66fa80f7b010 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/SumPtVertexWeightCalculator.h +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/SumPtVertexWeightCalculator.h @@ -1,72 +1,70 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - #ifndef TrkVertexWeightCalculator_SumPtVertexWeightCalculator_H - #define TrkVertexWeightCalculator_SumPtVertexWeightCalculator_H - - #include "AthenaBaseComps/AthAlgTool.h" - #include "GaudiKernel/ToolHandle.h" - #include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" - -//xAOD include -#include "xAODTracking/VertexFwd.h" -#include "xAODTracking/VertexAuxContainer.h" +#ifndef TrkVertexWeightCalculator_SumPtVertexWeightCalculator_H +#define TrkVertexWeightCalculator_SumPtVertexWeightCalculator_H + +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" +#include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" + +// xAOD include #include "xAODTracking/TrackParticleFwd.h" +#include "xAODTracking/VertexAuxContainer.h" +#include "xAODTracking/VertexFwd.h" + +/** + * @class Trk::SumPtVertexWeightCalculator + * + * @author Johanna Bronner, November 2009 + * + * --------------------------------------------------- + * Changes: + * + * David Shope <david.richard.shope@cern.ch> (2016-06-01) + * + * EDM Migration to xAOD - remove method using VxCandidate + * + */ + +namespace Trk { + +class SumPtVertexWeightCalculator + : public AthAlgTool + , virtual public IVertexWeightCalculator +{ +public: + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + + /** + * constructor + */ + + SumPtVertexWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p); + + /** + * destructor + */ + + virtual ~SumPtVertexWeightCalculator() = default; + + /** + * WeightCalculator + */ + + virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex) const override final; + +private: + /** + * Flag to Set SumPt^2 not SumPt as selection criteria + */ + bool m_doSumPt2Selection; - /** - * @class Trk::SumPtVertexWeightCalculator - * - * @author Johanna Bronner, November 2009 - * - * --------------------------------------------------- - * Changes: - * - * David Shope <david.richard.shope@cern.ch> (2016-06-01) - * - * EDM Migration to xAOD - remove method using VxCandidate - * - */ - - - namespace Trk - { - - class SumPtVertexWeightCalculator : public AthAlgTool, virtual public IVertexWeightCalculator - { - public: - StatusCode initialize(); - StatusCode finalize(); - - /** - * constructor - */ - - SumPtVertexWeightCalculator(const std::string& t, const std::string& n, const IInterface* p); - - /** - * destructor - */ - - virtual ~SumPtVertexWeightCalculator(); - - /** - * WeightCalculator - */ - - virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex); - - - private: - - /** - * Flag to Set SumPt^2 not SumPt as selection criteria - */ - bool m_doSumPt2Selection; - +}; // end of class description +} // end of namespace definition - - }; //end of class description - }//end of namespace definition - - #endif +#endif diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/TrueVertexDistanceWeightCalculator.h b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/TrueVertexDistanceWeightCalculator.h index 4d5bd1832332e4de9a4b356b7ec1608e1c1fd8d5..6284a5d148e504018d341661f900647e67a68227 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/TrueVertexDistanceWeightCalculator.h +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/TrueVertexDistanceWeightCalculator.h @@ -1,72 +1,78 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - #ifndef TrkVertexWeightCalculator_TrueVertexDistanceWeightCalculator_H - #define TrkVertexWeightCalculator_TrueVertexDistanceWeightCalculator_H - - #include "AthenaBaseComps/AthAlgTool.h" - #include "GaudiKernel/ToolHandle.h" - #include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" - #include "GeoPrimitives/GeoPrimitives.h" - -//xAOD include -#include "xAODTracking/VertexFwd.h" -#include "xAODTracking/VertexAuxContainer.h" -#include "xAODTracking/TrackParticleFwd.h" +#ifndef TrkVertexWeightCalculator_TrueVertexDistanceWeightCalculator_H +#define TrkVertexWeightCalculator_TrueVertexDistanceWeightCalculator_H + +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" +#include "GeoPrimitives/GeoPrimitives.h" +#include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" + +// xAOD include #include "GeneratorObjects/McEventCollection.h" +#include "xAODTracking/TrackParticleFwd.h" +#include "xAODTracking/VertexAuxContainer.h" +#include "xAODTracking/VertexFwd.h" + +/** + * @class Trk::TrueVertexDistanceWeightCalculator + * + * @author Giacinto Piacquadio, August 2010 + * + * --------------------------------------------------- + * Changes: + * + * David Shope <david.richard.shope@cern.ch> (2016-06-01) + * + * EDM Migration to xAOD - remove method using VxCandidate + * + */ - /** - * @class Trk::TrueVertexDistanceWeightCalculator - * - * @author Giacinto Piacquadio, August 2010 - * - * --------------------------------------------------- - * Changes: - * - * David Shope <david.richard.shope@cern.ch> (2016-06-01) - * - * EDM Migration to xAOD - remove method using VxCandidate - * - */ - class McEventCollection; - - namespace Trk - { - - class TrueVertexDistanceWeightCalculator : public AthAlgTool, virtual public IVertexWeightCalculator - { - public: - StatusCode initialize(); - StatusCode finalize(); - - /** - * constructor - */ - - TrueVertexDistanceWeightCalculator(const std::string& t, const std::string& n, const IInterface* p); - - /** - * destructor - */ - - virtual ~TrueVertexDistanceWeightCalculator(); - - /** - * WeightCalculator - */ - - virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex); - - - private: - SG::ReadHandleKey<McEventCollection> m_mcEventCollectionKey { this, "McTruthCollection", "TruthEvent", - "key to retrieve MC truth" }; - - double mEstimateSignalCompatibility(const Amg::Vector3D& vtxPosition); - - }; //end of class description - }//end of namespace definition - - #endif + +namespace Trk { + +class TrueVertexDistanceWeightCalculator + : public AthAlgTool + , virtual public IVertexWeightCalculator +{ +public: + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + + /** + * constructor + */ + + TrueVertexDistanceWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p); + + /** + * destructor + */ + + virtual ~TrueVertexDistanceWeightCalculator() = default; + + /** + * WeightCalculator + */ + + virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex) const override final; + +private: + SG::ReadHandleKey<McEventCollection> m_mcEventCollectionKey{ + this, + "McTruthCollection", + "TruthEvent", + "key to retrieve MC truth" + }; + + double mEstimateSignalCompatibility(const Amg::Vector3D& vtxPosition) const; + +}; // end of class description +} // end of namespace definition + +#endif diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/VxProbVertexWeightCalculator.h b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/VxProbVertexWeightCalculator.h index a2e346a6b97c7cd73a2a6d781f9c287112eb2904..e28c89548c05f21665a3b3316156f6a188f91ead 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/VxProbVertexWeightCalculator.h +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/TrkVertexWeightCalculators/VxProbVertexWeightCalculator.h @@ -1,71 +1,69 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TrkVertexWeightCalculator_VxProbVertexWeightCalculator_H #define TrkVertexWeightCalculator_VxProbVertexWeightCalculator_H - #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ToolHandle.h" #include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" - -//xAOD include -#include "xAODTracking/VertexFwd.h" -#include "xAODTracking/VertexAuxContainer.h" + +// xAOD include #include "xAODTracking/TrackParticleFwd.h" +#include "xAODTracking/VertexAuxContainer.h" +#include "xAODTracking/VertexFwd.h" + +/** + * @class Trk::VxProbVertexWeightCalculator + * + * @author Johanna Bronner, April 2009 + * + * --------------------------------------------------- + * Changes: + * + * David Shope <david.richard.shope@cern.ch> (2016-06-01) + * + * EDM Migration to xAOD - remove method using VxCandidate + * + */ - /** - * @class Trk::VxProbVertexWeightCalculator - * - * @author Johanna Bronner, April 2009 - * - * --------------------------------------------------- - * Changes: - * - * David Shope <david.richard.shope@cern.ch> (2016-06-01) - * - * EDM Migration to xAOD - remove method using VxCandidate - * - */ - class TH1; class ITHistSvc; +namespace Trk { + +class VxProbVertexWeightCalculator + : public AthAlgTool + , virtual public IVertexWeightCalculator +{ +public: + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + /** + * constructor + */ + VxProbVertexWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p); + + /** + * destructor + */ + virtual ~VxProbVertexWeightCalculator() = default; + + /** + * WeightCalculator + */ + + virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex) const override final; + +private: + TH1* m_hMinBiasPt; + std::string m_HistoFileLocation; + ITHistSvc* m_iTHistSvc; - namespace Trk - { - - class VxProbVertexWeightCalculator : public AthAlgTool, virtual public IVertexWeightCalculator - { - public: - StatusCode initialize(); - StatusCode finalize(); - - /** - * constructor - */ - VxProbVertexWeightCalculator(const std::string& t, const std::string& n, const IInterface* p); - - /** - * destructor - */ - virtual ~VxProbVertexWeightCalculator(); - - /** - * WeightCalculator - */ - - virtual double estimateSignalCompatibility(const xAOD::Vertex& vertex); +}; // end of class description +} // end of namespace definition - - private: - - TH1 *m_hMinBiasPt; - std::string m_HistoFileLocation; - ITHistSvc* m_iTHistSvc; - - }; //end of class description - }//end of namespace definition - - #endif +#endif diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/NNVertexWeightCalculator.cxx b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/NNVertexWeightCalculator.cxx index 972b1b05e223bc7be32a40a7e8536c5e8125225f..4fafdd5d0a60bd1533a0f9c42e3483ee0cff5565 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/NNVertexWeightCalculator.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/NNVertexWeightCalculator.cxx @@ -1,288 +1,272 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "TrkVertexWeightCalculators/NNVertexWeightCalculator.h" -#include "VxVertex/VxTrackAtVertex.h" #include "TrkParameters/TrackParameters.h" +#include "VxVertex/VxTrackAtVertex.h" -#include "xAODTracking/Vertex.h" #include "xAODTracking/TrackParticle.h" +#include "xAODTracking/Vertex.h" +#include "FuncMeanRMS.h" #include "GaudiKernel/ITHistSvc.h" -#include "FuncMeanRMS.h" +#include "GaudiKernel/SystemOfUnits.h" #include <TH1.h> #include <TMath.h> #include <TMatrixD.h> #include <TMatrixDEigen.h> -#include <TVectorT.h> -#include <vector> #include <TString.h> +#include <TVectorT.h> #include <string> +#include <vector> #include "TrkNeuralNetworkUtils/TTrainedNetwork.h" -#include "TrkNeuralNetworkUtils/NeuralNetworkToHistoTool.h" - -namespace Trk{ - - //usual tool related methods - StatusCode NNVertexWeightCalculator::initialize() - { - StatusCode sc = AthAlgTool::initialize(); - - //initializing the AlgTool itself - if(sc.isFailure()) - { - msg(MSG::ERROR)<<" Unable to initialize the AlgTool"<<endmsg; - return StatusCode::FAILURE; - } - (TString)m_directoryName; - - sc = m_networkToHistoTool.retrieve(); - if (sc.isFailure()) - { - msg(MSG::FATAL) << " Could not retrieve " << m_networkToHistoTool << ". Aborting..." << endmsg; - return sc; - } - else msg(MSG::INFO) << " Retrieved: " << m_networkToHistoTool << ". " << endmsg; - - - if (!service("THistSvc",m_iTHistSvc , true).isSuccess()) - { - msg(MSG::ERROR) << "Unable to locate THistSvc" << endmsg; - return StatusCode::FAILURE; - } - - TString LayerInfo = "LayersInfo"; - sc = m_iTHistSvc->regHist(std::string((const char*)(m_directoryName+LayerInfo))); - if (sc.isFailure()) - { - msg(MSG::ERROR) << "Unable to locate THistSvc" << endmsg; - return StatusCode::FAILURE; - } - - m_NNhistos.push_back(0); - - sc = m_iTHistSvc->getHist(std::string((const char*)(m_directoryName+LayerInfo)),m_NNhistos[0]); - - if (sc.isFailure()) - { - msg(MSG::ERROR) << "Unable to locate THistSvc" << endmsg; - return StatusCode::FAILURE; - } +namespace Trk { - for (int i = 0; i < m_NLayers - 1; i++) - { - TString weightName("Layer"); - weightName +=i; - weightName +="_weights"; - - TString thresholdName("Layer"); - thresholdName +=i; - thresholdName +="_thresholds"; - - sc = m_iTHistSvc->regHist(std::string((const char*)(m_directoryName+weightName))); - if (sc.isFailure()) - { - msg(MSG::ERROR) << "Unable to locate THistSvc" << endmsg; - return StatusCode::FAILURE; - } - m_NNhistos.push_back(0); - sc = m_iTHistSvc->getHist(std::string((const char*)(m_directoryName+weightName)),m_NNhistos[2*i + 1]); - - sc = m_iTHistSvc->regHist(std::string((const char*)(m_directoryName+thresholdName))); - if (sc.isFailure()) - { - msg(MSG::ERROR)<< "Unable to locate THistSvc" << endmsg; - return StatusCode::FAILURE; - } - m_NNhistos.push_back(0); - sc = m_iTHistSvc->getHist(std::string((const char*)(m_directoryName+thresholdName)),m_NNhistos[2*i + 2]); - } - - msg(MSG::INFO)<<"Initialization successfull"<<endmsg; - return StatusCode::SUCCESS; - }//end of initialize method - - - StatusCode NNVertexWeightCalculator::finalize() - { - msg(MSG::INFO)<< "Finalize successful" << endmsg; - return StatusCode::SUCCESS; +// usual tool related methods +StatusCode +NNVertexWeightCalculator::initialize() +{ + + (TString) m_directoryName; + StatusCode sc = m_networkToHistoTool.retrieve(); + if (sc.isFailure()) { + ATH_MSG_FATAL(" Could not retrieve " << m_networkToHistoTool + << ". Aborting..."); + return sc; + } + + if (!service("THistSvc", m_iTHistSvc, true).isSuccess()) { + ATH_MSG_ERROR("Unable to locate THistSvc"); + return StatusCode::FAILURE; } - - //class constructor implementation - NNVertexWeightCalculator::NNVertexWeightCalculator(const std::string& t, const std::string& n, const IInterface* p): - AthAlgTool(t,n,p), - m_networkToHistoTool("Trk::NeuralNetworkToHistoTool"), - m_NN(0), - m_NLayers(3), - m_iTHistSvc(0), - m_directoryName("/NNHisto/") - { - declareProperty("HistoFilePath",m_directoryName ); - declareProperty("NeuralNetworkToHistoTool",m_networkToHistoTool); - - declareInterface<IVertexWeightCalculator>(this); + + TString LayerInfo = "LayersInfo"; + ATH_CHECK(m_iTHistSvc->regHist( + std::string((const char*)(m_directoryName + LayerInfo)))); + m_NNhistos.push_back(nullptr); + + ATH_CHECK(m_iTHistSvc->getHist( + std::string((const char*)(m_directoryName + LayerInfo)), m_NNhistos[0])); + + + for (int i = 0; i < m_NLayers - 1; i++) { + TString weightName("Layer"); + weightName += i; + weightName += "_weights"; + + TString thresholdName("Layer"); + thresholdName += i; + thresholdName += "_thresholds"; + + ATH_CHECK(m_iTHistSvc->regHist( + std::string((const char*)(m_directoryName + weightName)))); + m_NNhistos.push_back(nullptr); + + ATH_CHECK(m_iTHistSvc->getHist( + std::string((const char*)(m_directoryName + weightName)), + m_NNhistos[2 * i + 1])); + + ATH_CHECK(m_iTHistSvc->regHist( + std::string((const char*)(m_directoryName + thresholdName)))); + + m_NNhistos.push_back(nullptr); + ATH_CHECK(m_iTHistSvc->getHist( + std::string((const char*)(m_directoryName + thresholdName)), + m_NNhistos[2 * i + 2])); } - - //destructor - NNVertexWeightCalculator::~NNVertexWeightCalculator(){} - -double NNVertexWeightCalculator::estimateSignalCompatibility(const xAOD::Vertex& vertex) + m_NN.reset(m_networkToHistoTool->fromHistoToTrainedNetwork(m_NNhistos)); + return StatusCode::SUCCESS; +} // end of initialize method + +StatusCode +NNVertexWeightCalculator::finalize() +{ + return StatusCode::SUCCESS; +} + +// class constructor implementation +NNVertexWeightCalculator::NNVertexWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p) + : AthAlgTool(t, n, p) + , m_networkToHistoTool("Trk::NeuralNetworkToHistoTool") + , m_NN(nullptr) + , m_NLayers(3) + , m_iTHistSvc(nullptr) + , m_directoryName("/NNHisto/") +{ + declareProperty("HistoFilePath", m_directoryName); + declareProperty("NeuralNetworkToHistoTool", m_networkToHistoTool); + declareInterface<IVertexWeightCalculator>(this); +} + + +double +NNVertexWeightCalculator::estimateSignalCompatibility( + const xAOD::Vertex& vertex) const { std::vector<const Trk::TrackParameters*> tpList; - - for(const auto& elTrackParticle : vertex.trackParticleLinks()) { - + + for (const auto& elTrackParticle : vertex.trackParticleLinks()) { + if (not elTrackParticle.isValid()) { - ATH_MSG_WARNING("No valid link to tracks in xAOD::Vertex object. Skipping track for signal compatibility (may be serious)."); + ATH_MSG_WARNING( + "No valid link to tracks in xAOD::Vertex object. Skipping track for " + "signal compatibility (may be serious)."); continue; } - const Trk::Perigee& perigee = (*elTrackParticle.cptr())->perigeeParameters(); + const Trk::Perigee& perigee = + (*elTrackParticle.cptr())->perigeeParameters(); tpList.push_back(static_cast<const Trk::TrackParameters*>(&perigee)); - } + } return mEstimateSignalCompatibility(tpList); - } -double NNVertexWeightCalculator::mEstimateSignalCompatibility(const std::vector<const Trk::TrackParameters*>& tpList) +double +NNVertexWeightCalculator::mEstimateSignalCompatibility( + const std::vector<const Trk::TrackParameters*>& tpList) const { - double NTrks = (double)tpList.size(); - - double st1Moment = 0; - double st2Moment = 0; - double st3Moment = 0; - double st4Moment = 0; - double st5Moment = 0; - double st6Moment = 0; - double st7Moment = 0; - double st8Moment = 0; - double st9Moment = 0; - double st10Moment = 0; - - double Sphericity = 0; - - if (tpList.size()>0) - { - for(const Trk::TrackParameters* perigee : tpList) { - double p_T = std::fabs(1./perigee->parameters()[Trk::qOverP])*sin(perigee->parameters()[Trk::theta])/1000.; - st1Moment += p_T; - } - st1Moment = st1Moment/NTrks; - std::vector <std::vector<double> > v_allPs; - - for(const Trk::TrackParameters* perigee : tpList) { - double p_T = std::fabs(1./perigee->parameters()[Trk::qOverP])*sin(perigee->parameters()[Trk::theta])/1000.; - - st2Moment = st2Moment + TMath::Power(p_T - st1Moment,2); - st3Moment = st3Moment + TMath::Power(p_T - st1Moment,3); - st4Moment = st4Moment + TMath::Power(p_T - st1Moment,4); - st5Moment = st5Moment + TMath::Power(p_T - st1Moment,5); - st6Moment = st6Moment + TMath::Power(p_T - st1Moment,6); - st7Moment = st7Moment + TMath::Power(p_T - st1Moment,7); - st8Moment = st8Moment + TMath::Power(p_T - st1Moment,8); - st9Moment = st9Moment + TMath::Power(p_T - st1Moment,9); - st10Moment = st10Moment + TMath::Power(p_T - st1Moment,10); - - double thisPx = perigee->parameters()[Trk::qOverP]*sin(perigee->parameters()[Trk::theta])*cos(perigee->parameters()[Trk::phi])/1000.; - double thisPy= perigee->parameters()[Trk::qOverP]*sin(perigee->parameters()[Trk::theta])*sin(perigee->parameters()[Trk::phi])/1000.; - double thisPz= perigee->parameters()[Trk::qOverP]*cos(perigee->parameters()[Trk::theta])/1000.; - - std::vector <double> V_PxPyPz; - V_PxPyPz.push_back(thisPx); - V_PxPyPz.push_back(thisPy); - V_PxPyPz.push_back(thisPz); - - v_allPs.push_back(V_PxPyPz); - - } - Sphericity = sphericityFunc(v_allPs); - - st2Moment = st2Moment/NTrks; - st3Moment = st3Moment/NTrks; - st4Moment = st4Moment/NTrks; - st5Moment = st5Moment/NTrks; - st6Moment = st6Moment/NTrks; - st7Moment = st7Moment/NTrks; - st8Moment = st8Moment/NTrks; - st9Moment = st9Moment/NTrks; - st10Moment =st10Moment/NTrks; - - std::vector <double> NNinput; - NNinput.push_back(Norm_NTrks(((int)NTrks))); - NNinput.push_back(Norm_st1Mom(LogFunc(st1Moment))); - NNinput.push_back(Norm_st2Mom(LogFunc(st2Moment))); - NNinput.push_back(Norm_st3Mom(LogFunc(st3Moment))); - NNinput.push_back(Norm_st4Mom(LogFunc(st4Moment))); - NNinput.push_back(Norm_st5Mom(LogFunc(st5Moment))); - NNinput.push_back(Norm_st6Mom(LogFunc(st6Moment))); - NNinput.push_back(Norm_st7Mom(LogFunc(st7Moment))); - NNinput.push_back(Norm_st8Mom(LogFunc(st8Moment))); - NNinput.push_back(Norm_st9Mom(LogFunc(st9Moment))); - NNinput.push_back(Norm_st10Mom(LogFunc(st10Moment))); - NNinput.push_back(Norm_Sphere((Sphericity))); - - m_NN = m_networkToHistoTool->fromHistoToTrainedNetwork(m_NNhistos); - - return m_NN->calculateOutputValues(NNinput).at(0); - } //at least one track - + double NTrks = (double)tpList.size(); + + double st1Moment = 0; + double st2Moment = 0; + double st3Moment = 0; + double st4Moment = 0; + double st5Moment = 0; + double st6Moment = 0; + double st7Moment = 0; + double st8Moment = 0; + double st9Moment = 0; + double st10Moment = 0; + + double Sphericity = 0; + + if (!tpList.empty()) { + for (const Trk::TrackParameters* perigee : tpList) { + double p_T = std::fabs(1. / perigee->parameters()[Trk::qOverP]) * + sin(perigee->parameters()[Trk::theta]) / Gaudi::Units::GeV; + st1Moment += p_T; + } + st1Moment = st1Moment / NTrks; + std::vector<std::vector<double>> v_allPs; + + for (const Trk::TrackParameters* perigee : tpList) { + double p_T = std::fabs(1. / perigee->parameters()[Trk::qOverP]) * + sin(perigee->parameters()[Trk::theta]) / Gaudi::Units::GeV; + + st2Moment = st2Moment + TMath::Power(p_T - st1Moment, 2); + st3Moment = st3Moment + TMath::Power(p_T - st1Moment, 3); + st4Moment = st4Moment + TMath::Power(p_T - st1Moment, 4); + st5Moment = st5Moment + TMath::Power(p_T - st1Moment, 5); + st6Moment = st6Moment + TMath::Power(p_T - st1Moment, 6); + st7Moment = st7Moment + TMath::Power(p_T - st1Moment, 7); + st8Moment = st8Moment + TMath::Power(p_T - st1Moment, 8); + st9Moment = st9Moment + TMath::Power(p_T - st1Moment, 9); + st10Moment = st10Moment + TMath::Power(p_T - st1Moment, 10); + + double thisPx = perigee->parameters()[Trk::qOverP] * + sin(perigee->parameters()[Trk::theta]) * + cos(perigee->parameters()[Trk::phi]) / Gaudi::Units::GeV; + double thisPy = perigee->parameters()[Trk::qOverP] * + sin(perigee->parameters()[Trk::theta]) * + sin(perigee->parameters()[Trk::phi]) / Gaudi::Units::GeV; + double thisPz = perigee->parameters()[Trk::qOverP] * + cos(perigee->parameters()[Trk::theta]) / Gaudi::Units::GeV; + + std::vector<double> V_PxPyPz; + V_PxPyPz.push_back(thisPx); + V_PxPyPz.push_back(thisPy); + V_PxPyPz.push_back(thisPz); + + v_allPs.push_back(V_PxPyPz); + } + Sphericity = sphericityFunc(v_allPs); + + st2Moment = st2Moment / NTrks; + st3Moment = st3Moment / NTrks; + st4Moment = st4Moment / NTrks; + st5Moment = st5Moment / NTrks; + st6Moment = st6Moment / NTrks; + st7Moment = st7Moment / NTrks; + st8Moment = st8Moment / NTrks; + st9Moment = st9Moment / NTrks; + st10Moment = st10Moment / NTrks; + + std::vector<double> NNinput; + NNinput.push_back(Norm_NTrks(((int)NTrks))); + NNinput.push_back(Norm_st1Mom(LogFunc(st1Moment))); + NNinput.push_back(Norm_st2Mom(LogFunc(st2Moment))); + NNinput.push_back(Norm_st3Mom(LogFunc(st3Moment))); + NNinput.push_back(Norm_st4Mom(LogFunc(st4Moment))); + NNinput.push_back(Norm_st5Mom(LogFunc(st5Moment))); + NNinput.push_back(Norm_st6Mom(LogFunc(st6Moment))); + NNinput.push_back(Norm_st7Mom(LogFunc(st7Moment))); + NNinput.push_back(Norm_st8Mom(LogFunc(st8Moment))); + NNinput.push_back(Norm_st9Mom(LogFunc(st9Moment))); + NNinput.push_back(Norm_st10Mom(LogFunc(st10Moment))); + NNinput.push_back(Norm_Sphere((Sphericity))); + + return m_NN->calculateOutputValues(NNinput).at(0); + } // at least one track + return 0; } -double NNVertexWeightCalculator::sphericityFunc(std::vector <std::vector<double> > v_allPs) +double +NNVertexWeightCalculator::sphericityFunc( + std::vector<std::vector<double>> v_allPs) const { - TMatrixD a_P(2,2); - - for (int a=0; a<2; a++) - { - for (int b=0; b<2; b++) - { + TMatrixD a_P(2, 2); + + for (int a = 0; a < 2; a++) { + for (int b = 0; b < 2; b++) { double SumAbsP = 0; double SumPaPb = 0; - - for (unsigned int i=0; i < v_allPs.size(); i++) - { - double AbsP = TMath::Abs(v_allPs.at(i).at(0)*v_allPs.at(i).at(0) + v_allPs.at(i).at(1)*v_allPs.at(i).at(1)); + + for (unsigned int i = 0; i < v_allPs.size(); i++) { + double AbsP = TMath::Abs(v_allPs.at(i).at(0) * v_allPs.at(i).at(0) + + v_allPs.at(i).at(1) * v_allPs.at(i).at(1)); SumAbsP = SumAbsP + AbsP; - double PaPb = v_allPs.at(i).at(a)*v_allPs.at(i).at(b); + double PaPb = v_allPs.at(i).at(a) * v_allPs.at(i).at(b); SumPaPb = SumPaPb + PaPb; } - a_P[a][b]=SumPaPb/SumAbsP; - } + a_P[a][b] = SumPaPb / SumAbsP; + } } TVectorT<double> EigVal; - + a_P.EigenVectors(EigVal); - double smallL =0; - - if ( EigVal[0]< EigVal[1]) - smallL = EigVal[0]; + double smallL = 0; + + if (EigVal[0] < EigVal[1]) + smallL = EigVal[0]; else - smallL = EigVal[1]; - - return smallL*2; + smallL = EigVal[1]; + + return smallL * 2; } -double NNVertexWeightCalculator::LogFunc(double value) +double +NNVertexWeightCalculator::LogFunc(double value) const { double x0 = 0.05e-3; - double a = 20000.;//f1_strich->Eval(x0); - double y = -9.90349;// f1->Eval(x0); - double y0 = y - a*x0; - + double a = 20000.; // f1_strich->Eval(x0); + double y = -9.90349; // f1->Eval(x0); + double y0 = y - a * x0; + if (value <= -x0) - return -TMath::Log(-value) + 2*y0; - else if ((value > -x0) && (value < x0)) - return y0 + a*value; - else if (value >= x0) - return TMath::Log(value); - + return -TMath::Log(-value) + 2 * y0; + if ((value > -x0) && (value < x0)) + return y0 + a * value; + if (value >= x0) + return TMath::Log(value); + return 0; - } +} -} //end namespace Trk +} // end namespace Trk diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/SumPtVertexWeightCalculator.cxx b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/SumPtVertexWeightCalculator.cxx index 68cc4beeff32bb6cdf9f888fafe1562928fdc300..c746640a46a2aada8c6f8638166d9fda19eecb4f 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/SumPtVertexWeightCalculator.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/SumPtVertexWeightCalculator.cxx @@ -1,74 +1,68 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - #include "TrkVertexWeightCalculators/SumPtVertexWeightCalculator.h" - #include "VxVertex/VxTrackAtVertex.h" - #include "TrkParameters/TrackParameters.h" +#include "TrkVertexWeightCalculators/SumPtVertexWeightCalculator.h" +#include "TrkParameters/TrackParameters.h" +#include "VxVertex/VxTrackAtVertex.h" - #include "xAODTracking/Vertex.h" - #include "xAODTracking/TrackParticle.h" - -namespace Trk{ - - StatusCode SumPtVertexWeightCalculator::initialize() - { - StatusCode sc = AthAlgTool::initialize(); - - //initializing the AlgTool itself - if(sc.isFailure()) - { - msg(MSG::ERROR)<<" Unable to initialize the AlgTool"<<endmsg; - return StatusCode::FAILURE; - } - - msg(MSG::INFO)<<"Initialization successfull"<<endmsg; - return StatusCode::SUCCESS; - }//end of initialize method - - StatusCode SumPtVertexWeightCalculator::finalize() - { - MsgStream log(msgSvc(), name()); - msg(MSG::INFO) << "Finalize successful" << endmsg; - return StatusCode::SUCCESS; - } - - //class constructor implementation - SumPtVertexWeightCalculator::SumPtVertexWeightCalculator(const std::string& t, const std::string& n, const IInterface* p): - AthAlgTool(t,n,p), - m_doSumPt2Selection(true) - { - declareProperty("DoSumPt2Selection",m_doSumPt2Selection); - declareInterface<IVertexWeightCalculator>(this); - } - - //destructor - SumPtVertexWeightCalculator::~SumPtVertexWeightCalculator(){} - - double SumPtVertexWeightCalculator::estimateSignalCompatibility(const xAOD::Vertex& vertex) - { - double total_pt=0; - ATH_MSG_DEBUG("Estimating vertex sorting score from " << vertex.nTrackParticles() << " tracks at vertex."); - for(const auto& elTrackParticle : vertex.trackParticleLinks()) { +#include "xAODTracking/TrackParticle.h" +#include "xAODTracking/Vertex.h" + +namespace Trk { + +StatusCode +SumPtVertexWeightCalculator::initialize() +{ + return StatusCode::SUCCESS; +} // end of initialize method - if (not elTrackParticle.isValid()) { - ATH_MSG_WARNING("No valid link to tracks in xAOD::Vertex object. Skipping track for signal compatibility (may be serious)."); - continue; - } +StatusCode +SumPtVertexWeightCalculator::finalize() +{ + return StatusCode::SUCCESS; +} - const Trk::Perigee& perigee = (*elTrackParticle.cptr())->perigeeParameters(); - if (m_doSumPt2Selection) - { - total_pt+=std::pow(1./perigee.parameters()[Trk::qOverP]*sin(perigee.parameters()[Trk::theta])/1000.,2); - } - else - { - total_pt+= std::fabs(1./perigee.parameters()[Trk::qOverP])*sin(perigee.parameters()[Trk::theta])/1000.; - } +// class constructor implementation +SumPtVertexWeightCalculator::SumPtVertexWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p) + : AthAlgTool(t, n, p) + , m_doSumPt2Selection(true) +{ + declareProperty("DoSumPt2Selection", m_doSumPt2Selection); + declareInterface<IVertexWeightCalculator>(this); +} + +double +SumPtVertexWeightCalculator::estimateSignalCompatibility( + const xAOD::Vertex& vertex) const +{ + double total_pt = 0; + ATH_MSG_DEBUG("Estimating vertex sorting score from " + << vertex.nTrackParticles() << " tracks at vertex."); + for (const auto& elTrackParticle : vertex.trackParticleLinks()) { + + if (not elTrackParticle.isValid()) { + ATH_MSG_WARNING( + "No valid link to tracks in xAOD::Vertex object. Skipping track for " + "signal compatibility (may be serious)."); + continue; + } + + const Trk::Perigee& perigee = + (*elTrackParticle.cptr())->perigeeParameters(); + if (m_doSumPt2Selection) { + total_pt += std::pow(1. / perigee.parameters()[Trk::qOverP] * + sin(perigee.parameters()[Trk::theta]) / 1000., + 2); + } else { + total_pt += std::fabs(1. / perigee.parameters()[Trk::qOverP]) * + sin(perigee.parameters()[Trk::theta]) / 1000.; } - return total_pt; } - - - }///End!!! + return total_pt; +} + +} /// End!!! diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/TrueVertexDistanceWeightCalculator.cxx b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/TrueVertexDistanceWeightCalculator.cxx index 4b47d9b84a353055ba63e5154b14b346e4ffab3d..82f33e61661cc42291829b50679d9c62668d1273 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/TrueVertexDistanceWeightCalculator.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/TrueVertexDistanceWeightCalculator.cxx @@ -1,89 +1,83 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - #include "TrkVertexWeightCalculators/TrueVertexDistanceWeightCalculator.h" - #include "VxVertex/VxTrackAtVertex.h" +#include "TrkVertexWeightCalculators/TrueVertexDistanceWeightCalculator.h" +#include "VxVertex/VxTrackAtVertex.h" -#include "xAODTracking/Vertex.h" #include "xAODTracking/TrackParticle.h" +#include "xAODTracking/Vertex.h" -namespace Trk{ - - StatusCode TrueVertexDistanceWeightCalculator::initialize() - { - ATH_CHECK( m_mcEventCollectionKey.initialize() ); - //initializing the AlgTool itself - ATH_CHECK( AthAlgTool::initialize() ); - msg(MSG::INFO)<<"Initialization successfull"<<endmsg; - - return StatusCode::SUCCESS; - }//end of initialize method - - StatusCode TrueVertexDistanceWeightCalculator::finalize() - { - MsgStream log(msgSvc(), name()); - msg(MSG::INFO) << "Finalize successful" << endmsg; - return StatusCode::SUCCESS; - } - - //class constructor implementation - TrueVertexDistanceWeightCalculator::TrueVertexDistanceWeightCalculator(const std::string& t, const std::string& n, const IInterface* p): - AthAlgTool(t,n,p) - { - declareInterface<IVertexWeightCalculator>(this); +namespace Trk { + +StatusCode +TrueVertexDistanceWeightCalculator::initialize() +{ + ATH_CHECK(m_mcEventCollectionKey.initialize()); + return StatusCode::SUCCESS; +} + +StatusCode +TrueVertexDistanceWeightCalculator::finalize() +{ + return StatusCode::SUCCESS; +} + +// class constructor implementation +TrueVertexDistanceWeightCalculator::TrueVertexDistanceWeightCalculator( + const std::string& t, + const std::string& n, + const IInterface* p) + : AthAlgTool(t, n, p) +{ + declareInterface<IVertexWeightCalculator>(this); +} + +double +TrueVertexDistanceWeightCalculator::estimateSignalCompatibility( + const xAOD::Vertex& vertex) const +{ + return mEstimateSignalCompatibility(vertex.position()); +} + +double +TrueVertexDistanceWeightCalculator::mEstimateSignalCompatibility( + const Amg::Vector3D& vtxPosition) const +{ + SG::ReadHandle<McEventCollection> mcColl(m_mcEventCollectionKey); + + if (!mcColl.isValid()) { + ATH_MSG_WARNING("Could not retrieve McEventCollection " + << m_mcEventCollectionKey.key() + << " from StoreGate. Returning 0 distance."); + return 0; } - - //destructor - TrueVertexDistanceWeightCalculator::~TrueVertexDistanceWeightCalculator(){} - - double TrueVertexDistanceWeightCalculator::estimateSignalCompatibility(const xAOD::Vertex& vertex) - { - return mEstimateSignalCompatibility(vertex.position()); + + McEventCollection::const_iterator itr = mcColl->begin(); + const HepMC::GenEvent* myEvent = (*itr); + if (!myEvent) { + ATH_MSG_ERROR(" Cannot find truth event... Returning 0 distance... "); + return 0; } - double TrueVertexDistanceWeightCalculator::mEstimateSignalCompatibility(const Amg::Vector3D& vtxPosition) - { - SG::ReadHandle<McEventCollection> mcColl( m_mcEventCollectionKey ); - - if ( !mcColl.isValid() ) - { - ATH_MSG_WARNING("Could not retrieve McEventCollection " << m_mcEventCollectionKey.key() - << " from StoreGate. Returning 0 distance."); - return 0; - } - - McEventCollection::const_iterator itr = mcColl->begin(); - const HepMC::GenEvent* myEvent=(*itr); - if (!myEvent) - { - msg(MSG::ERROR) << " Cannot find truth event... Returning 0 distance... " << endmsg; - return 0; - } - - HepMC::GenEvent::vertex_const_iterator Vert = myEvent->vertices_begin(); - ATH_MSG_DEBUG("Resulting MC seed: x: " << (*Vert)->position().x() << - " y: " << (*Vert)->position().y() << - " z: " << (*Vert)->position().z()); - double ztrue=(*Vert)->position().z(); - - double z_vtx_pos=vtxPosition.z(); - - double distance = fabs(z_vtx_pos - ztrue); - - ATH_MSG_DEBUG("Distance of pV from truth:" << distance); - - if (distance==0.) - { - ATH_MSG_WARNING(" Suspicious 0 distance."); - return 1./0.000001; - } - - ATH_MSG_DEBUG(" Returning distance: " << 1./distance); - - return 1./distance; + HepMC::GenEvent::vertex_const_iterator Vert = myEvent->vertices_begin(); + ATH_MSG_DEBUG("Resulting MC seed: x: " << (*Vert)->position().x() + << " y: " << (*Vert)->position().y() + << " z: " << (*Vert)->position().z()); + double ztrue = (*Vert)->position().z(); + + double z_vtx_pos = vtxPosition.z(); + + double distance = fabs(z_vtx_pos - ztrue); + + ATH_MSG_DEBUG("Distance of pV from truth:" << distance); + if (distance == 0.) { + ATH_MSG_WARNING(" Suspicious 0 distance."); + return 1. / 0.000001; } - -}///End!!! + ATH_MSG_DEBUG(" Returning distance: " << 1. / distance); + return 1. / distance; +} +} diff --git a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/VxProbVertexWeightCalculator.cxx b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/VxProbVertexWeightCalculator.cxx index d4d7456ad3b53e26131443aebc7aee534328c4e5..769620c2a13ad3100e0858797e38a68016263e24 100644 --- a/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/VxProbVertexWeightCalculator.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexWeightCalculators/src/VxProbVertexWeightCalculator.cxx @@ -1,85 +1,97 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "TrkVertexWeightCalculators/VxProbVertexWeightCalculator.h" -#include "VxVertex/VxTrackAtVertex.h" -#include "TrkParameters/TrackParameters.h" #include "GaudiKernel/ITHistSvc.h" +#include "TrkParameters/TrackParameters.h" +#include "VxVertex/VxTrackAtVertex.h" #include <TH1.h> #include <TMath.h> -#include "xAODTracking/Vertex.h" #include "xAODTracking/TrackParticle.h" - - namespace Trk{ - - StatusCode VxProbVertexWeightCalculator::initialize() - { - ATH_CHECK( AthAlgTool::initialize()); - ATH_CHECK(service("THistSvc",m_iTHistSvc , true)); - ATH_CHECK( m_iTHistSvc->regHist(m_HistoFileLocation)); - ATH_CHECK( m_iTHistSvc->getHist(m_HistoFileLocation,m_hMinBiasPt )); - ATH_MSG_DEBUG("Initialization successful"); - return StatusCode::SUCCESS; - }//end of initialize method - - - StatusCode VxProbVertexWeightCalculator::finalize() - { - ATH_MSG_VERBOSE( "Finalize successful"); - return StatusCode::SUCCESS; - } - - //class constructor implementation - VxProbVertexWeightCalculator::VxProbVertexWeightCalculator(const std::string& t, const std::string& n, const IInterface* p): - AthAlgTool(t,n,p), - m_hMinBiasPt(0), - m_HistoFileLocation("/VxProbHisto/h_sTrkPdfminBias"), - m_iTHistSvc() - { - declareProperty("HistogramPath",m_HistoFileLocation ); - declareInterface<IVertexWeightCalculator>(this); - } - - //destructor - VxProbVertexWeightCalculator::~VxProbVertexWeightCalculator(){} - - double VxProbVertexWeightCalculator::estimateSignalCompatibility(const xAOD::Vertex& vertex) - { - double P0 = 1.; - //bool pTtooBig = false; - for(const auto& elTrackParticle : vertex.trackParticleLinks()) { - if (not elTrackParticle.isValid()) { - ATH_MSG_WARNING("No valid link to tracks in xAOD::Vertex object. Skipping track for signal compatibility (may be serious)."); - continue; - } - const Trk::Perigee& perigee = (*elTrackParticle.cptr())->perigeeParameters(); - double p_T = std::fabs(1./perigee.parameters()[Trk::qOverP])*sin(perigee.parameters()[Trk::theta])/1000.; - TH1F* myHisto = dynamic_cast<TH1F*>(m_hMinBiasPt); - if (myHisto == 0) { - ATH_MSG_WARNING("VxProbHisto is an empty pointer. Signal compatibility failed and returning 0.0"); - return 0; - } - double IntPt = (myHisto->Integral(myHisto->FindBin(p_T),myHisto->GetNbinsX() + 1) - + myHisto->Integral(myHisto->FindBin(p_T)+1,myHisto->GetNbinsX() + 1))/2.; - // --- Markus Elsing: fake high pt tracks, limit the integral - if (IntPt < 0.0001) IntPt = 0.0001; - P0 = P0 *IntPt; +#include "xAODTracking/Vertex.h" + +namespace Trk { + +StatusCode +VxProbVertexWeightCalculator::initialize() +{ + ATH_CHECK(service("THistSvc", m_iTHistSvc, true)); + ATH_CHECK(m_iTHistSvc->regHist(m_HistoFileLocation)); + ATH_CHECK(m_iTHistSvc->getHist(m_HistoFileLocation, m_hMinBiasPt)); + ATH_MSG_DEBUG("Initialization successful"); + return StatusCode::SUCCESS; +} // end of initialize method + +StatusCode +VxProbVertexWeightCalculator::finalize() +{ + ATH_MSG_VERBOSE("Finalize successful"); + return StatusCode::SUCCESS; +} + +// class constructor implementation +VxProbVertexWeightCalculator::VxProbVertexWeightCalculator(const std::string& t, + const std::string& n, + const IInterface* p) + : AthAlgTool(t, n, p) + , m_hMinBiasPt(nullptr) + , m_HistoFileLocation("/VxProbHisto/h_sTrkPdfminBias") + , m_iTHistSvc() +{ + declareProperty("HistogramPath", m_HistoFileLocation); + declareInterface<IVertexWeightCalculator>(this); +} + + +double +VxProbVertexWeightCalculator::estimateSignalCompatibility( + const xAOD::Vertex& vertex) const +{ + double P0 = 1.; + // bool pTtooBig = false; + for (const auto& elTrackParticle : vertex.trackParticleLinks()) { + if (not elTrackParticle.isValid()) { + ATH_MSG_WARNING( + "No valid link to tracks in xAOD::Vertex object. Skipping track for " + "signal compatibility (may be serious)."); + continue; + } + const Trk::Perigee& perigee = + (*elTrackParticle.cptr())->perigeeParameters(); + double p_T = std::fabs(1. / perigee.parameters()[Trk::qOverP]) * + sin(perigee.parameters()[Trk::theta]) / 1000.; + TH1F* myHisto = dynamic_cast<TH1F*>(m_hMinBiasPt); + if (myHisto == nullptr) { + ATH_MSG_WARNING("VxProbHisto is an empty pointer. Signal compatibility " + "failed and returning 0.0"); + return 0; } - double VxProb = 0.; - const int sizeOfTPColl = vertex.trackParticleLinks().size(); - if (sizeOfTPColl > 0) { - for (int j = 0; j < sizeOfTPColl; ++j) { - /** @todo Given that you are looping from zero, the 'Power' and 'Factorial' - * could be speeded up by using a simple multiplication on each loop (sroe) - **/ - VxProb = VxProb + (TMath::Power(-TMath::Log(P0),j)/TMath::Factorial(j)); - } - VxProb = -TMath::Log(VxProb*P0); + double IntPt = + (myHisto->Integral(myHisto->FindBin(p_T), myHisto->GetNbinsX() + 1) + + myHisto->Integral(myHisto->FindBin(p_T) + 1, myHisto->GetNbinsX() + 1)) / + 2.; + // --- Markus Elsing: fake high pt tracks, limit the integral + if (IntPt < 0.0001) + IntPt = 0.0001; + P0 = P0 * IntPt; + } + double VxProb = 0.; + const int sizeOfTPColl = vertex.trackParticleLinks().size(); + if (sizeOfTPColl > 0) { + for (int j = 0; j < sizeOfTPColl; ++j) { + /** @todo Given that you are looping from zero, the 'Power' and + *'Factorial' could be speeded up by using a simple multiplication on each + *loop (sroe) + **/ + VxProb = + VxProb + (TMath::Power(-TMath::Log(P0), j) / TMath::Factorial(j)); } - return VxProb; - } + VxProb = -TMath::Log(VxProb * P0); + } + return VxProb; +} - }//Namespace +} // Namespace