From 7fa1981dc04d56896f61ac989e0ac0a54c1b3180 Mon Sep 17 00:00:00 2001
From: christos <christos@cern.ch>
Date: Thu, 4 Oct 2018 16:38:11 +0100
Subject: [PATCH] Start on the Extrapolator , from the std part, counters and
 static

---
 .../TrkExTools/TrkExTools/Extrapolator.h      | 69 +++++++++---------
 .../TrkExTools/src/Extrapolator.cxx           | 72 ++++++++++---------
 2 files changed, 70 insertions(+), 71 deletions(-)

diff --git a/Tracking/TrkExtrapolation/TrkExTools/TrkExTools/Extrapolator.h b/Tracking/TrkExtrapolation/TrkExTools/TrkExTools/Extrapolator.h
index 4a608aaa9ea..a795548a8dc 100755
--- a/Tracking/TrkExtrapolation/TrkExTools/TrkExTools/Extrapolator.h
+++ b/Tracking/TrkExtrapolation/TrkExTools/TrkExTools/Extrapolator.h
@@ -39,8 +39,9 @@
 #include "xAODTracking/TrackParticle.h" 
 #include "xAODTracking/NeutralParticle.h"
 
-class MsgStream;
+#include "GaudiKernel/Counters.h"
 
+class MsgStream;
 namespace Trk {
 
   class Track;
@@ -709,9 +710,7 @@ namespace Trk {
     bool                            m_extendedLayerSearch;           //!< extended layer search
     unsigned int                    m_initialLayerAttempts;          //!< allowed layer intersection attempts at the start of a volume
     unsigned int                    m_successiveLayerAttempts;       //!< layer intersection attemps after one layer has been hit sucessfully
-
     double                          m_tolerance;                    //!< surfacen & volume tolerance
-    
     // ------------------------------------------------------- //      
    
     bool                            m_activeOverlap;                 //!<  consider overlaps between active muon volumes  
@@ -769,44 +768,43 @@ namespace Trk {
     bool                            m_printHelpOutputAtInitialize;
     bool                            m_printRzOutput;
 
-    //------------------------- VALIDATION MODE SECTION ------------------------------------------//
-
-    mutable int                     m_extrapolateCalls;              //!< number of calls: extrapolate() method
-    mutable int                     m_extrapolateBlindlyCalls;       //!< number of calls: extrapolateBlindly() method 
-    mutable int                     m_extrapolateDirectlyCalls;      //!< number of calls: extrapolateDirectly() method
-    mutable int                     m_extrapolateStepwiseCalls;      //!< number of calls: extrapolateStepwise() method
-
-    mutable int                     m_startThroughAssociation;        //!< navigation intialization
-    mutable int                     m_startThroughRecall;             //!< navigation intialization
-    mutable int                     m_startThroughGlobalSearch;       //!< navigation intialization
-    mutable int                     m_destinationThroughAssociation;  //!< navigation intialization
-    mutable int                     m_destinationThroughRecall;       //!< navigation intialization
-    mutable int                     m_destinationThroughGlobalSearch; //!< navigation intialization
-    
-    mutable int                     m_layerSwitched;                 //!< number of layers that have been switched 
-
-    // ----------------------------- navigation validation section -----------------------------------------------------------
-
+    //------------------------- VALIDATION  SECTION ------------------------------------------//
+    //flags
     bool                            m_navigationStatistics;           //!< steer the output for the navigaiton statistics
     bool                            m_navigationBreakDetails;         //!< steer the output for the navigation break details
-    mutable int                     m_navigationBreakLoop;            //!< number of navigation breaks due to loop
+    bool                            m_materialEffectsOnTrackValidation; //!< mat effects on track validation
+    //extrapolation counters
+    mutable Gaudi::Accumulators::Counter<int>                     m_extrapolateCalls;              //!< number of calls: extrapolate() method
+    mutable Gaudi::Accumulators::Counter<int>                     m_extrapolateBlindlyCalls;       //!< number of calls: extrapolateBlindly() method 
+    mutable Gaudi::Accumulators::Counter<int>                     m_extrapolateDirectlyCalls;      //!< number of calls: extrapolateDirectly() method
+    mutable Gaudi::Accumulators::Counter<int>                     m_extrapolateStepwiseCalls;      //!< number of calls: extrapolateStepwise() method
+
+    mutable Gaudi::Accumulators::Counter<int>                     m_startThroughAssociation;        //!< navigation intialization
+    mutable Gaudi::Accumulators::Counter<int>                     m_startThroughRecall;             //!< navigation intialization
+    mutable Gaudi::Accumulators::Counter<int>                     m_startThroughGlobalSearch;       //!< navigation intialization
+    mutable Gaudi::Accumulators::Counter<int>                     m_destinationThroughAssociation;  //!< navigation intialization
+    mutable Gaudi::Accumulators::Counter<int>                     m_destinationThroughRecall;       //!< navigation intialization
+    mutable Gaudi::Accumulators::Counter<int>                     m_destinationThroughGlobalSearch; //!< navigation intialization 
+    mutable Gaudi::Accumulators::Counter<int>                     m_layerSwitched;                 //!< number of layers that have been switched 
+
+    //navigation counters
+    mutable Gaudi::Accumulators::Counter<int>                     m_navigationBreakLoop;            //!< number of navigation breaks due to loop
+    mutable Gaudi::Accumulators::Counter<int>                     m_navigationBreakOscillation;     //!< number of navigation breaks due to oscillation
+    mutable Gaudi::Accumulators::Counter<int>                     m_navigationBreakNoVolume;       //!< number of navigation breaks due no Volume found
+    mutable Gaudi::Accumulators::Counter<int>                     m_navigationBreakDistIncrease;   //!< number of navigation breaks due to distance increase
+    mutable Gaudi::Accumulators::Counter<int>                     m_navigationBreakVolumeSignature;   //!< number of navigation breaks due to distance increase
+    mutable Gaudi::Accumulators::Counter<int>                     m_overlapSurfaceHit;             //!< number of OverlapSurfaces found
+
+    mutable Gaudi::Accumulators::Counter<int>                     m_meotSearchCallsFw;                //!< how often the meot search is called: forward
+    mutable Gaudi::Accumulators::Counter<int>                     m_meotSearchCallsBw;                //!< how often the meot search is called: backward
+    mutable Gaudi::Accumulators::Counter<int>                     m_meotSearchSuccessfulFw;           //!< how often the meot search was successful: forward
+    mutable Gaudi::Accumulators::Counter<int>                     m_meotSearchSuccessfulBw;           //!< how often the meot search was successful: backward
+
     mutable std::map<const Trk::TrackingVolume*,int> m_loopVolumes;   //!< record name of the volumes where oscillation happened
-    mutable int                     m_navigationBreakOscillation;     //!< number of navigation breaks due to oscillation
     mutable std::map<const Trk::TrackingVolume*,int> m_oscillationVolumes;    //!< record name of the volumes where oscillation happened
-    mutable int                     m_navigationBreakNoVolume;       //!< number of navigation breaks due no Volume found
-    mutable std::map<const Trk::TrackingVolume*,int> m_noNextVolumes;         //!< record names of the volumes where no next one is found
-    mutable int                     m_navigationBreakDistIncrease;   //!< number of navigation breaks due to distance increase
     mutable std::map<const Trk::TrackingVolume*,int> m_distIncreaseVolumes;   //!< record name of  the voluems where the distance increases
-    mutable int                     m_navigationBreakVolumeSignature;   //!< number of navigation breaks due to distance increase
+    mutable std::map<const Trk::TrackingVolume*,int> m_noNextVolumes;         //!< record names of the volumes where no next one is found
     mutable std::map<const Trk::TrackingVolume*,int> m_volSignatureVolumes;   //!< record name of  the voluems where the distance increases
-    mutable int                     m_overlapSurfaceHit;             //!< number of OverlapSurfaces found
-
-    bool                            m_materialEffectsOnTrackValidation; //!< mat effects on track validation
-    mutable int                     m_meotSearchCallsFw;                //!< how often the meot search is called: forward
-    mutable int                     m_meotSearchCallsBw;                //!< how often the meot search is called: backward
-    mutable int                     m_meotSearchSuccessfulFw;           //!< how often the meot search was successful: forward
-    mutable int                     m_meotSearchSuccessfulBw;           //!< how often the meot search was successful: backward
-
     // ------------------------------- cache --------------------------------------------------------------------
 
     mutable const Layer*                                       m_lastMaterialLayer; //!< cache layer with last material update
@@ -818,7 +816,6 @@ namespace Trk {
 
 
     // ------------------------------- static members --------------------------------------------------------------------
-    static double                   s_distIncreaseTolerance;         //!< distance increatse tolerance to account for straight line approx.
 
     unsigned int m_maxNavigSurf;
     unsigned int m_maxNavigVol;
diff --git a/Tracking/TrkExtrapolation/TrkExTools/src/Extrapolator.cxx b/Tracking/TrkExtrapolation/TrkExTools/src/Extrapolator.cxx
index 8a0795d11c8..c154e233786 100755
--- a/Tracking/TrkExtrapolation/TrkExTools/src/Extrapolator.cxx
+++ b/Tracking/TrkExtrapolation/TrkExTools/src/Extrapolator.cxx
@@ -50,15 +50,10 @@
 #include "TrkSurfaces/PlaneSurface.h"
 
 #include <memory>
+namespace{
+constexpr double s_distIncreaseTolerance = 100. * Gaudi::Units::millimeter;
+}
 
-// screen output measures
-// "[+] Text describing layer      - with " << layerRZoutput()
-// "[+] Text describing position   -   at " << positionOutput()
-// "[+] Text describing single parameter  - par = "
-
-// reference surface for Blind extrapolation
-// Trk::PlaneSurface Trk::Extrapolator::m_referenceSurface(new Amg::Transform3D(Trk::s_idTransform), 0.,0.);
-double Trk::Extrapolator::s_distIncreaseTolerance = 100. * Gaudi::Units::millimeter;
 // constructor
 Trk::Extrapolator::Extrapolator(const std::string &t, const std::string &n, const IInterface *p) :
   AthAlgTool(t, n, p),
@@ -113,30 +108,30 @@ Trk::Extrapolator::Extrapolator(const std::string &t, const std::string &n, cons
   m_maxMethodSequence(2000),
   m_printHelpOutputAtInitialize(false),
   m_printRzOutput(true),
-  m_extrapolateCalls(0),
-  m_extrapolateBlindlyCalls(0),
-  m_extrapolateDirectlyCalls(0),
-  m_extrapolateStepwiseCalls(0),
-  m_startThroughAssociation(0),
-  m_startThroughRecall(0),
-  m_startThroughGlobalSearch(0),
-  m_destinationThroughAssociation(0),
-  m_destinationThroughRecall(0),
-  m_destinationThroughGlobalSearch(0),
-  m_layerSwitched(0),
   m_navigationStatistics(false),
   m_navigationBreakDetails(false),
-  m_navigationBreakLoop(0),
-  m_navigationBreakOscillation(0),
-  m_navigationBreakNoVolume(0),
-  m_navigationBreakDistIncrease(0),
-  m_navigationBreakVolumeSignature(0),
-  m_overlapSurfaceHit(0),
   m_materialEffectsOnTrackValidation(false),
-  m_meotSearchCallsFw(0),
-  m_meotSearchCallsBw(0),
-  m_meotSearchSuccessfulFw(0),
-  m_meotSearchSuccessfulBw(0),
+  m_extrapolateCalls{},
+  m_extrapolateBlindlyCalls{},
+  m_extrapolateDirectlyCalls{},
+  m_extrapolateStepwiseCalls{},
+  m_startThroughAssociation{},
+  m_startThroughRecall{},
+  m_startThroughGlobalSearch{},
+  m_destinationThroughAssociation{},
+  m_destinationThroughRecall{},
+  m_destinationThroughGlobalSearch{},
+  m_layerSwitched{},
+  m_navigationBreakLoop{},
+  m_navigationBreakOscillation{},
+  m_navigationBreakNoVolume{},
+  m_navigationBreakDistIncrease{},
+  m_navigationBreakVolumeSignature{},
+  m_overlapSurfaceHit{},
+  m_meotSearchCallsFw{},
+  m_meotSearchCallsBw{},
+  m_meotSearchSuccessfulFw{},
+  m_meotSearchSuccessfulBw{},
   m_lastMaterialLayer(0),
   m_cacheLastMatLayer(false),
   m_matstates(nullptr),
@@ -390,10 +385,10 @@ Trk::Extrapolator::finalize() {
       ATH_MSG_INFO("[P] MaterialEffectsOnTrack collection ----------------------------------------------------");
       ATH_MSG_INFO("     -> Forward successful/calls (ratio)           : " << m_meotSearchSuccessfulFw << "/"
                                                                            << m_meotSearchCallsFw << " (" <<
-        double(m_meotSearchSuccessfulFw) / m_meotSearchCallsFw << ")");
+        double(m_meotSearchSuccessfulFw.value()) / m_meotSearchCallsFw.value() << ")");
       ATH_MSG_INFO("     -> Backward successful/calls (ratio)          : " << m_meotSearchSuccessfulBw << "/"
                                                                            << m_meotSearchCallsBw << " (" <<
-        double(m_meotSearchSuccessfulBw) / m_meotSearchCallsBw << ")");
+        double(m_meotSearchSuccessfulBw.value()) / m_meotSearchCallsBw.value() << ")");
       ATH_MSG_INFO(" -----------------------------------------------------------------------------------------");
     }
   }
@@ -598,6 +593,11 @@ Trk::Extrapolator::extrapolate(const IPropagator &prop,
   // one-time-punch-through allows for volume2 - volume1 - volume2 (cosmics)
   bool punchThroughDone = false;
 
+  auto navigationBreakOscillation=m_navigationBreakOscillation.buffer();
+  auto navigationBreakNoVolume= m_navigationBreakNoVolume.buffer();
+  auto navigationBreakDistIncrease=m_navigationBreakDistIncrease.buffer();
+  auto navigationBreakVolumeSignature=m_navigationBreakVolumeSignature.buffer();
+
   while (nextVolume &&
          nextVolume != destVolume &&
          nextVolume != lastVolume &&
@@ -769,7 +769,7 @@ Trk::Extrapolator::extrapolate(const IPropagator &prop,
         ATH_MSG_DEBUG(
           "          - Reason      : Oscillation detected in TrackingVolume '" << nextVolume->volumeName() << "'");
         // statistics
-        ++m_navigationBreakOscillation;
+        ++navigationBreakOscillation;
         // record the oscillation volume -- increase the counter for the volume
         if (m_navigationBreakDetails) {
           ++m_oscillationVolumes[nextVolume];
@@ -792,7 +792,7 @@ Trk::Extrapolator::extrapolate(const IPropagator &prop,
       ATH_MSG_VERBOSE(
         "          - Reason      : No next volume found of TrackingVolume '" << lastVolume->volumeName() << "'");
       // statistics
-      ++m_navigationBreakNoVolume;
+      ++navigationBreakNoVolume;
       // record the "no next" volume -- increase the counter for the (last) volume
       if (m_navigationBreakDetails) {
         ++m_noNextVolumes[lastVolume];
@@ -816,7 +816,7 @@ Trk::Extrapolator::extrapolate(const IPropagator &prop,
                                                                      << "] in TrackingVolume '" << nextVolume->volumeName() <<
         "'");
       // statistics
-      ++m_navigationBreakDistIncrease;
+      ++navigationBreakDistIncrease;
       // record the "dist increase" volume -- increase the counter for the volume
       if (m_navigationBreakDetails) {
         ++m_distIncreaseVolumes[nextVolume];
@@ -3991,6 +3991,8 @@ Trk::Extrapolator::overlapSearch(const IPropagator &prop,
       ATH_MSG_VERBOSE("found " << ncSurfaces << " candidate sensitive surfaces to test.");
       // now loop over the surfaces:
       // the surfaces will be sorted @TODO integrate pathLength propagation into this
+   
+      auto overlapSurfaceHit=m_overlapSurfaceHit.buffer();
       for (auto &csf : cSurfaces) {
         // propagate to the compatible surface, return types are (pathLimit failure is excluded by Trk::anyDirection for
         // the moment):
@@ -4014,7 +4016,7 @@ Trk::Extrapolator::overlapSearch(const IPropagator &prop,
           if (surfaceHit) {
             ATH_MSG_VERBOSE("  [H] Hit with detector surface recorded !");
             // count the overlap Surfaces hit
-            ++m_overlapSurfaceHit;
+            ++overlapSurfaceHit;
             // distinguish whether sorting is needed or not
             reorderDetParametersOnLayer = true;
             // push back into the temporary vector
-- 
GitLab