diff --git a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/CMakeLists.txt b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/CMakeLists.txt index b80a8b0b6652b66c15dd57344b7dddce6184e216..362e9962a104683f891fe00a0f20237b7738150d 100644 --- a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/CMakeLists.txt +++ b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/CMakeLists.txt @@ -11,6 +11,7 @@ atlas_depends_on_subdirs( PUBLIC GaudiKernel PRIVATE Control/AthenaBaseComps + Control/CxxUtils Event/EventInfo Event/xAOD/xAODEventInfo InnerDetector/InDetConditions/BeamSpotConditionsData @@ -40,12 +41,12 @@ atlas_add_library( InDetBeamSpotFinderLib PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} DEFINITIONS ${CLHEP_DEFINITIONS} LINK_LIBRARIES ${CLHEP_LIBRARIES} xAODTracking GaudiKernel TrigAnalysisInterfaces - PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps EventInfo xAODEventInfo TrkEventPrimitives VxVertex AtlasDetDescr Identifier TrkFitterInterfaces TrkFitterUtils TrkParameters TrkPseudoMeasurementOnTrack TrkRIO_OnTrack TrkTrack TrkVertexFitterInterfaces ) + PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps CxxUtils EventInfo xAODEventInfo TrkEventPrimitives VxVertex AtlasDetDescr Identifier TrkFitterInterfaces TrkFitterUtils TrkParameters TrkPseudoMeasurementOnTrack TrkRIO_OnTrack TrkTrack TrkVertexFitterInterfaces ) atlas_add_component( InDetBeamSpotFinder src/components/*.cxx INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} xAODTracking GaudiKernel AthenaBaseComps EventInfo xAODEventInfo TrkEventPrimitives VxVertex AtlasDetDescr Identifier TrkFitterInterfaces TrkFitterUtils TrkParameters TrkPseudoMeasurementOnTrack TrkRIO_OnTrack TrkTrack TrkVertexFitterInterfaces InDetBeamSpotFinderLib ) + LINK_LIBRARIES ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} xAODTracking GaudiKernel AthenaBaseComps CxxUtils EventInfo xAODEventInfo TrkEventPrimitives VxVertex AtlasDetDescr Identifier TrkFitterInterfaces TrkFitterUtils TrkParameters TrkPseudoMeasurementOnTrack TrkRIO_OnTrack TrkTrack TrkVertexFitterInterfaces InDetBeamSpotFinderLib ) # Install files from the package: atlas_install_joboptions( share/*.py ) diff --git a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/InDetBeamSpotFinder/ATLAS_CHECK_THREAD_SAFETY b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/InDetBeamSpotFinder/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..23b7ee599a776ff4c099f32b1f7c47ef0f859d06 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/InDetBeamSpotFinder/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder diff --git a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotFinder.cxx b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotFinder.cxx index bceb21714d8d9a5f4f9573ea029c2067ec0e8046..1e1d303a001587190440c636b49fd832e3dadc17 100644 --- a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotFinder.cxx +++ b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotFinder.cxx @@ -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 */ #include "InDetBeamSpotFinder.h" @@ -109,7 +109,7 @@ BeamSpot::Event InDet::InDetBeamSpotFinder::readEvent(const xAOD::EventInfo & ev event.eventTime = eventInfo.timeStamp(); event.eventTime_NS = eventInfo.timeStampNSOffset(); event.eventNumber = eventInfo.eventNumber(); - const DataHandle<EventInfo> BSeventInfo; + const EventInfo* BSeventInfo; //This is required for pseudo lumiblocks if( evtStore()->retrieve(BSeventInfo) != StatusCode::SUCCESS){ ATH_MSG_ERROR("Cannot get event info."); diff --git a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.cxx b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.cxx index d364e694928b014275a4e21eeb1c6bfb2438ed2b..c87bff1107f1923c20ce05c31a1677cf6b34c97b 100644 --- a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.cxx +++ b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.cxx @@ -4,17 +4,19 @@ #include "InDetBeamSpotVertex.h" #include "GaudiKernel/ITHistSvc.h" - +#include "CxxUtils/checker_macros.h" #include "VxVertex/VxCandidate.h" #include "VxVertex/VxContainer.h" #include <random> #include <cmath> #include <algorithm> +#include <mutex> using namespace InDet; namespace BeamSpot { - const std::vector< BeamSpot::VrtHolder > * vertexData; + std::mutex mutex; + const std::vector< BeamSpot::VrtHolder > * vertexData ATLAS_THREAD_SAFE; void myFCN_LLsolver( Int_t &, Double_t *, Double_t &, Double_t *, Int_t); // FCN for LL void myFCN_LLsolverNorm( Int_t &, Double_t *, Double_t &, Double_t *, Int_t); // FCN for LL double norm_xMin(-1e8), norm_xMax(1e8), norm_yMin(-1e8), norm_yMax(1e8) , norm_zMin(-1e8), norm_zMax(1e8); @@ -369,7 +371,7 @@ bool InDetBeamSpotVertex::solveLL() { arglist[0] = 2; minuit->mnexcm("SET STR",arglist,1,errFlag); - + std::lock_guard<std::mutex> lock(BeamSpot::mutex); // To protect global BeamSpot::vertexData // Insert the likelihood function // need to make the data accessible to it BeamSpot::vertexData = &m_vertexData; @@ -511,7 +513,6 @@ bool InDetBeamSpotVertex::applyOutlierRemoval() { ATH_MSG_INFO( "No vertices found" ); return false; } - static int rCount(0); // counter used for recussive mode // determine simple means @@ -728,7 +729,7 @@ bool InDetBeamSpotVertex::applyOutlierRemoval() { m_getLLres = llSolve; // allow the log-likelihood accessor values to returned, if sucessful } - if ( llSolve and rCount > 0 ) { + if ( llSolve and m_rCount > 0 ) { ATH_MSG_INFO( "Log-Likelihood fit converged in outlier removal. Exiting outlier removal." ); return true; } @@ -858,7 +859,7 @@ bool InDetBeamSpotVertex::applyOutlierRemoval() { } // for // if no vertices removed and ll fit still fails, then we continue to have a problem ... - if (fCount == 0 && m_useLL && !llSolve && rCount !=0 ) { // if first iteration, we have another iteration later. + if (fCount == 0 && m_useLL && !llSolve && m_rCount !=0 ) { // if first iteration, we have another iteration later. ATH_MSG_WARNING( "No vertices removed and fit still fails - most likely final result will fail" ); // this is our 'last-ditch approach'. Split the collection of vertices into two 'random' sets and solve for each. @@ -946,19 +947,19 @@ bool InDetBeamSpotVertex::applyOutlierRemoval() { // recursive mode - ATH_MSG_DEBUG( " Recursive debug: Loop: " << rCount << ". Number of failed vertices: " << fCount ); + ATH_MSG_DEBUG( " Recursive debug: Loop: " << m_rCount << ". Number of failed vertices: " << fCount ); - ++rCount; - if ( fCount > 0 || ( fCount == 0 && rCount == 1 && !llSolve)) { // if failed vertices or, no failed, first iteration, and no succesful fit - if ( rCount > m_maxOutlierLoops) { - ATH_MSG_WARNING( "OutlierRemoval: Reached maximum number of recursive loops: " << rCount + ++m_rCount; + if ( fCount > 0 || ( fCount == 0 && m_rCount == 1 && !llSolve)) { // if failed vertices or, no failed, first iteration, and no succesful fit + if ( m_rCount > m_maxOutlierLoops) { + ATH_MSG_WARNING( "OutlierRemoval: Reached maximum number of recursive loops: " << m_rCount << ". No more iterations performed." ); } else { - ATH_MSG_DEBUG( "OutlierRemoval: Entering recursive loop: " << rCount ); + ATH_MSG_DEBUG( "OutlierRemoval: Entering recursive loop: " << m_rCount ); applyOutlierRemoval(); } // if entering loop } // if fails > 0 - --rCount; + --m_rCount; return true; } // outlier removal diff --git a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.h b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.h index 3b9c719d8d386df1c10b58c8f6d5327be399ee33..e9a6265a077149e73974692b9c250c2b3e1e1873 100644 --- a/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.h +++ b/InnerDetector/InDetCalibAlgs/InDetBeamSpotFinder/src/InDetBeamSpotVertex.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef INDET_INDETBEAMSPOTVERTEX_H @@ -19,6 +19,7 @@ #include "TMinuit.h" #include "TMath.h" #include "TTree.h" +#include <atomic> #include <string> #include <vector> #include <map> @@ -199,6 +200,7 @@ namespace InDet { int m_nUsed; + mutable std::atomic<int> m_rCount{0}; // counter used for recussive mode }; } #endif