From 0a758e4ced07625ac82a238c3c5ec0481d9a7969 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus783.cern.ch>
Date: Wed, 15 Jan 2020 23:00:57 +0100
Subject: [PATCH 01/42] PVChecker functional changes

---
 .../src/fromVectorLHCbRecVertexv2.cpp         |   5 +-
 Tr/PatChecker/src/PrimaryVertexChecker.cpp    | 157 +++++++++---------
 Tr/PatChecker/src/PrimaryVertexChecker.h      |  91 +++++-----
 3 files changed, 139 insertions(+), 114 deletions(-)

diff --git a/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp b/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
index 28f094203c7..bc174f3c74f 100644
--- a/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
+++ b/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
@@ -36,7 +36,7 @@ namespace LHCb::Converters::RecVertex::v2 {
         converted_vertex->setCovMatrix( vertex.covMatrix() );
         // Add tracks from keyed container.
         // The following relies on the Velo tracks being created with a key in PrPixelTracking.
-        for ( const auto& weightedTrack : vertex.tracks() ) {
+	/*        for ( const auto& weightedTrack : vertex.tracks() ) {
           auto track_in_keyed_container =
               std::find_if( std::begin( keyed_tracks ), std::end( keyed_tracks ), [&weightedTrack]( const auto& t ) {
                 return ( ( t->nLHCbIDs() == weightedTrack.track->nLHCbIDs() ) &&
@@ -44,7 +44,8 @@ namespace LHCb::Converters::RecVertex::v2 {
               } );
           assert( track_in_keyed_container != std::end( keyed_tracks ) );
           converted_vertex->addToTracks( *track_in_keyed_container, weightedTrack.weight );
-        }
+	  }*/
+
         converted_vertices.add( converted_vertex.release() );
       }
       return converted_vertices;
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 91a1f86b426..8357894d972 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -25,6 +25,7 @@
 #include "VeloDet/DeVelo.h"
 #include <Event/MCTrackInfo.h>
 #include <Linker/LinkedTo.h>
+#include "GaudiAlg/Consumer.h"
 // local
 #include "PrimaryVertexChecker.h"
 
@@ -34,23 +35,20 @@ bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > seco
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
 
+
+
 // Declaration of the Algorithm Factory
-DECLARE_COMPONENT( PrimaryVertexChecker )
+DECLARE_COMPONENT( PrimaryVertexChecker ) 
 
 //=============================================================================
 // Standard constructor, initializes variables
 //=============================================================================
 PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-    : GaudiTupleAlg( name, pSvcLocator ) {
-  declareProperty( "nTracksToBeRecble", m_nTracksToBeRecble = 5 );
-  declareProperty( "produceNtuple", m_produceNtuple = false );
-  declareProperty( "RequireVelo", m_requireVelo = true );
-  declareProperty( "produceHistogram", m_produceHistogram = true );
-  declareProperty( "dzIsolated", m_dzIsolated = 10.0 * Gaudi::Units::mm );
-  declareProperty( "matchByTracks", m_matchByTracks = true );
-  declareProperty( "inputTracksName", m_inputTracksName = LHCb::TrackLocation::Default );
-  declareProperty( "inputVerticesName", m_inputVerticesName = LHCb::RecVertexLocation::Primary );
-}
+      : Consumer( name, pSvcLocator,
+                                      {
+                                          KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                                          KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
+                                      } ) {}
 
 //=============================================================================
 // Initialization
@@ -95,10 +93,13 @@ StatusCode PrimaryVertexChecker::initialize() {
   return StatusCode::SUCCESS;
 }
 
+
 //=============================================================================
 // Main execution
 //=============================================================================
-StatusCode PrimaryVertexChecker::execute() {
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, 
+                   const LHCb::RecVertices& recoVertices) const {
+
   debug() << "==> Execute" << endmsg;
 
   // Event
@@ -107,15 +108,29 @@ StatusCode PrimaryVertexChecker::execute() {
   // Get input
   std::vector<LHCb::Track*>     vecOfTracks;
   std::vector<LHCb::RecVertex*> vecOfVertices;
-  std::string                   trackLoc;
-  bool                          tracks_ok   = getInputTracks( vecOfTracks, trackLoc );
-  bool                          vertices_ok = getInputVertices( vecOfVertices );
+  std::string                   trackLoc = "/Event/Rec/Track/VeloAsTrackV2_v1";
+  bool                          tracks_ok   = true; //getInputTracks( vecOfTracks );
+
+  if ( usedTracks.size() == 0 ) tracks_ok = false;
+
+  std::vector<LHCb::Track*>::const_iterator itT;
+  for ( itT = usedTracks.begin(); usedTracks.end() != itT; itT++ ) {
+    LHCb::Track* ptr = ( *itT );
+    vecOfTracks.push_back( ptr );
+  }
 
   if ( !tracks_ok && m_matchByTracks ) {
-    return StatusCode::SUCCESS; // return SUCCESSS anyway
+    return; // return SUCCESSS anyway
+  }
+
+ // bool                          vertices_ok = getInputVertices( vecOfVertices );
+  std::vector<LHCb::RecVertex*>::const_iterator itVer;
+  for ( itVer = recoVertices.begin(); recoVertices.end() != itVer; itVer++ ) {
+    LHCb::RecVertex* ppv = ( *itVer );
+    vecOfVertices.push_back( ppv );
   }
 
-  if ( !vertices_ok ) { return StatusCode::SUCCESS; }
+//  if ( !vertices_ok ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -653,11 +668,11 @@ StatusCode PrimaryVertexChecker::execute() {
     }
   }
 
-  return StatusCode::SUCCESS;
+  return;
 }
 
 void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
-                                                      std::vector<MCPVInfo>& mcpvvec ) {
+                                                      std::vector<MCPVInfo>& mcpvvec ) const {
 
   LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
   typedef const SmartRefVector<LHCb::Track> PVTRACKS;
@@ -692,7 +707,7 @@ void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPV
 }
 
 void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo,
-                                                        std::vector<MCPVInfo>& mcpvvec ) {
+                                                        std::vector<MCPVInfo>& mcpvvec ) const {
 
   double mindist = 999999.;
   int    indexmc = -1;
@@ -714,7 +729,7 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
 }
 
 std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                                                   std::vector<MCPVInfo>::iterator& itmc ) {
+                                                                   std::vector<MCPVInfo>::iterator& itmc ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
   double                          mindist = 999999.;
@@ -733,7 +748,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 }
 
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
-                                             std::vector<LHCb::MCParticle*>& allprods ) {
+                                             std::vector<LHCb::MCParticle*>& allprods ) const {
 
   SmartRefVector<LHCb::MCParticle>           daughters = mcvtx->products();
   SmartRefVector<LHCb::MCParticle>::iterator idau;
@@ -873,7 +888,7 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
 }
 
 void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-                                                       std::vector<LHCb::Track*>& vecOfTracks, std::string trackLoc ) {
+                                                       std::vector<LHCb::Track*>& vecOfTracks, std::string trackLoc ) const {
 
   LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
 
@@ -923,7 +938,7 @@ int PrimaryVertexChecker::count_velo_tracks( LHCb::RecVertex* RecVtx ) {
   return nVeloTracks;
 }
 
-void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) {
+void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const {
 
   const MCTrackInfo               trInfo = make_MCTrackInfo( eventSvc(), msgSvc() );
   std::vector<MCPVInfo>::iterator itinfomc;
@@ -953,7 +968,7 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     }
   }
 }
-int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::string trackLoc ) {
+int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::string trackLoc ) const {
 
   int         motherPart = 0;
   const auto& tracksIn   = pv->tracks();
@@ -985,65 +1000,59 @@ int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::strin
   return motherPart;
 }
 
-bool PrimaryVertexChecker::getInputTracks( std::vector<LHCb::Track*>& vecOfTracks, std::string& trackLoc ) {
+// bool PrimaryVertexChecker::getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const {
 
-  std::string tracksName = m_inputTracksName;
+//   // std::string tracksName = m_inputTracksName;
 
-  if ( m_inputTracksName == "Offline" ) {
-    tracksName = LHCb::TrackLocation::Default;
-  } else if ( m_inputTracksName == "3D" ) {
-    tracksName = LHCb::TrackLocation::Velo;
-  } else if ( m_inputTracksName == "2D" ) {
-    tracksName = LHCb::TrackLocation::RZVelo;
-  }
+//   // if ( m_inputTracksName == "Offline" ) {
+//   //   tracksName = LHCb::TrackLocation::Default;
+//   // } else if ( m_inputTracksName == "3D" ) {
+//   //   tracksName = LHCb::TrackLocation::Velo;
+//   // } else if ( m_inputTracksName == "2D" ) {
+//   //   tracksName = LHCb::TrackLocation::RZVelo;
+//   // }
 
-  if ( tracksName == "none" ) {
-    debug() << " Tracks not specified " << tracksName << endmsg;
-    return false;
-  }
+//   // if ( tracksName == "none" ) {
+//   //   debug() << " Tracks not specified " << tracksName << endmsg;
+//   //   return false;
+//   // }
 
-  trackLoc = tracksName;
+//   //LHCb::Tracks* usedTracks = getOrCreate<LHCb::Tracks, LHCb::Tracks>( LHCb::TrackLocation::Default );
+//   if ( usedTracks->size() == 0 ) return false;
 
-  LHCb::Tracks* usedTracks;
+//   std::vector<LHCb::Track*>::const_iterator itT;
+//   for ( itT = usedTracks->begin(); usedTracks->end() != itT; itT++ ) {
+//     LHCb::Track* ptr = ( *itT );
+//     vecOfTracks.push_back( ptr );
+//   }
 
-  usedTracks = getOrCreate<LHCb::Tracks, LHCb::Tracks>( tracksName );
-  if ( usedTracks->size() == 0 ) return false;
+//   return true;
+// }
 
-  std::vector<LHCb::Track*>::const_iterator itT;
-  for ( itT = usedTracks->begin(); usedTracks->end() != itT; itT++ ) {
-    LHCb::Track* ptr = ( *itT );
-    vecOfTracks.push_back( ptr );
-  }
+// bool PrimaryVertexChecker::getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const {
 
-  return true;
-}
+//   // std::string verticesName = m_inputVerticesName;
 
-bool PrimaryVertexChecker::getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) {
+//   // if ( m_inputVerticesName == "Offline" ) {
+//   //   verticesName = LHCb::RecVertexLocation::Primary;
+//   // } else if ( m_inputVerticesName == "3D" ) {
+//   //   verticesName = LHCb::RecVertexLocation::Velo3D;
+//   // } else if ( m_inputVerticesName == "2D" ) {
+//   //   verticesName = LHCb::RecVertexLocation::Velo2D;
+//   // }
 
-  std::string verticesName = m_inputVerticesName;
+//   // if ( verticesName == "none" ) {
+//   //   debug() << " Vertices not specified " << verticesName << endmsg;
+//   //   return false;
+//   // }
 
-  if ( m_inputVerticesName == "Offline" ) {
-    verticesName = LHCb::RecVertexLocation::Primary;
-  } else if ( m_inputVerticesName == "3D" ) {
-    verticesName = LHCb::RecVertexLocation::Velo3D;
-  } else if ( m_inputVerticesName == "2D" ) {
-    verticesName = LHCb::RecVertexLocation::Velo2D;
-  }
+//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>( LHCb::RecVertexLocation::Primary );
 
-  if ( verticesName == "none" ) {
-    debug() << " Vertices not specified " << verticesName << endmsg;
-    return false;
-  }
+//   std::vector<LHCb::RecVertex*>::const_iterator itVer;
+//   for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
+//     LHCb::RecVertex* ppv = ( *itVer );
+//     vecOfVertices.push_back( ppv );
+//   }
 
-  LHCb::RecVertices* recoVertices;
-
-  recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>( verticesName );
-
-  std::vector<LHCb::RecVertex*>::const_iterator itVer;
-  for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
-    LHCb::RecVertex* ppv = ( *itVer );
-    vecOfVertices.push_back( ppv );
-  }
-
-  return true;
-}
+//   return true;
+// }
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
index 90fc97e18ba..4cca87285ce 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.h
@@ -53,60 +53,75 @@ public:
   LHCb::RecVertex* pRECPV;        // pointer to REC PV
 } RecPVInfo;
 
-class PrimaryVertexChecker : public GaudiTupleAlg {
+class PrimaryVertexChecker : public Gaudi::Functional::Consumer<
+                             void( const LHCb::Tracks&, 
+                                   const LHCb::RecVertices&),
+          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
 
   StatusCode initialize() override; ///< Algorithm initialization
-  StatusCode execute() override;    ///< Algorithm execution
+  void operator()( const LHCb::Tracks& usedTracks, 
+                   const LHCb::RecVertices& recoVertices) const override;    ///< Algorithm execution
   StatusCode finalize() override;   ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  int         m_nTracksToBeRecble;
-  bool        m_produceHistogram;
-  bool        m_produceNtuple;
-  bool        m_requireVelo;
-  double      m_dzIsolated;
-  bool        m_matchByTracks;
-  std::string m_inputTracksName;
-  std::string m_inputVerticesName;
+  //int         m_nTracksToBeRecble;
+  //bool        m_produceHistogram;
+  //bool        m_produceNtuple;
+  //bool        m_requireVelo;
+  //double      m_dzIsolated;
+  //bool        m_matchByTracks;
+  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
+  Gaudi::Property<bool> m_produceHistogram{this, "produceHistogram", true};
+  Gaudi::Property<bool> m_produceNtuple{this, "produceNtuple", false};
+  Gaudi::Property<bool> m_requireVelo{this, "RequireVelo", true};
+  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
+  Gaudi::Property<bool> m_matchByTracks{this, "matchByTracks", true};
+  // Gaudi::Property<std::string> m_inputTracksName{this, "inputTracksName", LHCb::TrackLocation::Default};
+  // Gaudi::Property<std::string> m_inputVerticesName{this, "inputVerticesName", LHCb::RecVertexLocation::Primary};
 
-  int m_nevt;
-  int m_nMCPV, m_nRecMCPV;
-  int m_nMCPV_isol, m_nRecMCPV_isol;
-  int m_nMCPV_close, m_nRecMCPV_close;
-  int m_nFalsePV, m_nFalsePV_real;
-  int m_nMCPV_1mult, m_nRecMCPV_1mult;
-  int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
-  int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
-  int m_nRecMCPV_wrong_1mult;
-  int m_nMCPV_2mult, m_nRecMCPV_2mult;
-  int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
-  int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
-  int m_nRecMCPV_wrong_2mult;
-  int m_nMCPV_3mult, m_nRecMCPV_3mult;
-  int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
-  int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
-  int m_nRecMCPV_wrong_3mult;
-  int m_nL0PvOfB, m_nRecL0PvOfB;
-  int m_nBFalse, m_nRecBFalse;
+  // std::string m_inputTracksName;
+  // std::string m_inputVerticesName;
 
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, std::vector<MCPVInfo>::iterator& itmc );
+  
 
-  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods );
+  mutable int m_nevt;
+  mutable int m_nMCPV, m_nRecMCPV;
+  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
+  mutable int m_nMCPV_close, m_nRecMCPV_close;
+  mutable int m_nFalsePV, m_nFalsePV_real;
+  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
+  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
+  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
+  mutable int m_nRecMCPV_wrong_1mult;
+  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
+  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
+  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
+  mutable int m_nRecMCPV_wrong_2mult;
+  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
+  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
+  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
+  mutable int m_nRecMCPV_wrong_3mult;
+  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
+  mutable int m_nBFalse, m_nRecBFalse;
+
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, std::vector<MCPVInfo>::iterator& itmc ) const;
+
+  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( std::string mes, int a, int b );
-  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec );
-  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec );
+  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-                                   std::string trackLoc );
+                                   std::string trackLoc ) const;
   int  count_velo_tracks( LHCb::RecVertex* RecVtx );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec );
-  bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks, std::string& trackLoc );
-  bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices );
-  int  check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc );
+  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
+  // bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
+  // bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
+  int  check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
 };
 #endif // PRIMARYVERTEXCHECKER_H
-- 
GitLab


From 6be407e422b2061d8f4b15b480a7d289557b36be Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 15 Jan 2020 22:02:02 +0000
Subject: [PATCH 02/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/6789764
---
 .../src/fromVectorLHCbRecVertexv2.cpp         |  4 +-
 Tr/PatChecker/src/PrimaryVertexChecker.cpp    | 34 ++++++++-------
 Tr/PatChecker/src/PrimaryVertexChecker.h      | 41 +++++++++----------
 3 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp b/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
index bc174f3c74f..9b59e958620 100644
--- a/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
+++ b/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
@@ -36,7 +36,7 @@ namespace LHCb::Converters::RecVertex::v2 {
         converted_vertex->setCovMatrix( vertex.covMatrix() );
         // Add tracks from keyed container.
         // The following relies on the Velo tracks being created with a key in PrPixelTracking.
-	/*        for ( const auto& weightedTrack : vertex.tracks() ) {
+        /*        for ( const auto& weightedTrack : vertex.tracks() ) {
           auto track_in_keyed_container =
               std::find_if( std::begin( keyed_tracks ), std::end( keyed_tracks ), [&weightedTrack]( const auto& t ) {
                 return ( ( t->nLHCbIDs() == weightedTrack.track->nLHCbIDs() ) &&
@@ -44,7 +44,7 @@ namespace LHCb::Converters::RecVertex::v2 {
               } );
           assert( track_in_keyed_container != std::end( keyed_tracks ) );
           converted_vertex->addToTracks( *track_in_keyed_container, weightedTrack.weight );
-	  }*/
+          }*/
 
         converted_vertices.add( converted_vertex.release() );
       }
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 8357894d972..7b12ceafc8b 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -16,6 +16,7 @@
 #include "Event/RecVertex.h"
 #include "Event/State.h"
 #include "Event/Track.h"
+#include "GaudiAlg/Consumer.h"
 #include "GaudiAlg/Tuples.h"
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
@@ -25,7 +26,6 @@
 #include "VeloDet/DeVelo.h"
 #include <Event/MCTrackInfo.h>
 #include <Linker/LinkedTo.h>
-#include "GaudiAlg/Consumer.h"
 // local
 #include "PrimaryVertexChecker.h"
 
@@ -35,20 +35,18 @@ bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > seco
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
 
-
-
 // Declaration of the Algorithm Factory
-DECLARE_COMPONENT( PrimaryVertexChecker ) 
+DECLARE_COMPONENT( PrimaryVertexChecker )
 
 //=============================================================================
 // Standard constructor, initializes variables
 //=============================================================================
 PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-      : Consumer( name, pSvcLocator,
-                                      {
-                                          KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                                          KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
-                                      } ) {}
+    : Consumer( name, pSvcLocator,
+                {
+                    KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                    KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
+                } ) {}
 
 //=============================================================================
 // Initialization
@@ -93,12 +91,10 @@ StatusCode PrimaryVertexChecker::initialize() {
   return StatusCode::SUCCESS;
 }
 
-
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, 
-                   const LHCb::RecVertices& recoVertices) const {
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHCb::RecVertices& recoVertices ) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -108,8 +104,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks,
   // Get input
   std::vector<LHCb::Track*>     vecOfTracks;
   std::vector<LHCb::RecVertex*> vecOfVertices;
-  std::string                   trackLoc = "/Event/Rec/Track/VeloAsTrackV2_v1";
-  bool                          tracks_ok   = true; //getInputTracks( vecOfTracks );
+  std::string                   trackLoc  = "/Event/Rec/Track/VeloAsTrackV2_v1";
+  bool                          tracks_ok = true; // getInputTracks( vecOfTracks );
 
   if ( usedTracks.size() == 0 ) tracks_ok = false;
 
@@ -123,14 +119,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks,
     return; // return SUCCESSS anyway
   }
 
- // bool                          vertices_ok = getInputVertices( vecOfVertices );
+  // bool                          vertices_ok = getInputVertices( vecOfVertices );
   std::vector<LHCb::RecVertex*>::const_iterator itVer;
   for ( itVer = recoVertices.begin(); recoVertices.end() != itVer; itVer++ ) {
     LHCb::RecVertex* ppv = ( *itVer );
     vecOfVertices.push_back( ppv );
   }
 
-//  if ( !vertices_ok ) { return; }
+  //  if ( !vertices_ok ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -888,7 +884,8 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
 }
 
 void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-                                                       std::vector<LHCb::Track*>& vecOfTracks, std::string trackLoc ) const {
+                                                       std::vector<LHCb::Track*>& vecOfTracks,
+                                                       std::string                trackLoc ) const {
 
   LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
 
@@ -1046,7 +1043,8 @@ int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::strin
 //   //   return false;
 //   // }
 
-//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>( LHCb::RecVertexLocation::Primary );
+//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>(
+//   LHCb::RecVertexLocation::Primary );
 
 //   std::vector<LHCb::RecVertex*>::const_iterator itVer;
 //   for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
index 4cca87285ce..9d1329829d9 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.h
@@ -53,43 +53,39 @@ public:
   LHCb::RecVertex* pRECPV;        // pointer to REC PV
 } RecPVInfo;
 
-class PrimaryVertexChecker : public Gaudi::Functional::Consumer<
-                             void( const LHCb::Tracks&, 
-                                   const LHCb::RecVertices&),
-          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, const LHCb::RecVertices& ),
+                                                                Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void operator()( const LHCb::Tracks& usedTracks, 
-                   const LHCb::RecVertices& recoVertices) const override;    ///< Algorithm execution
-  StatusCode finalize() override;   ///< Algorithm finalization
+  void       operator()( const LHCb::Tracks&      usedTracks,
+                   const LHCb::RecVertices& recoVertices ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                                                ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  //int         m_nTracksToBeRecble;
-  //bool        m_produceHistogram;
-  //bool        m_produceNtuple;
-  //bool        m_requireVelo;
-  //double      m_dzIsolated;
-  //bool        m_matchByTracks;
-  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
-  Gaudi::Property<bool> m_produceHistogram{this, "produceHistogram", true};
-  Gaudi::Property<bool> m_produceNtuple{this, "produceNtuple", false};
-  Gaudi::Property<bool> m_requireVelo{this, "RequireVelo", true};
+  // int         m_nTracksToBeRecble;
+  // bool        m_produceHistogram;
+  // bool        m_produceNtuple;
+  // bool        m_requireVelo;
+  // double      m_dzIsolated;
+  // bool        m_matchByTracks;
+  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
+  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
+  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
+  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  Gaudi::Property<bool> m_matchByTracks{this, "matchByTracks", true};
+  Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", true};
   // Gaudi::Property<std::string> m_inputTracksName{this, "inputTracksName", LHCb::TrackLocation::Default};
   // Gaudi::Property<std::string> m_inputVerticesName{this, "inputVerticesName", LHCb::RecVertexLocation::Primary};
 
   // std::string m_inputTracksName;
   // std::string m_inputVerticesName;
 
-  
-
   mutable int m_nevt;
   mutable int m_nMCPV, m_nRecMCPV;
   mutable int m_nMCPV_isol, m_nRecMCPV_isol;
@@ -110,7 +106,8 @@ private:
   mutable int m_nL0PvOfB, m_nRecL0PvOfB;
   mutable int m_nBFalse, m_nRecBFalse;
 
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, std::vector<MCPVInfo>::iterator& itmc ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                               std::vector<MCPVInfo>::iterator& itmc ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( std::string mes, int a, int b );
@@ -122,6 +119,6 @@ private:
   void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
   // bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
   // bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-  int  check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
+  int check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
 };
 #endif // PRIMARYVERTEXCHECKER_H
-- 
GitLab


From a50343050f410baee430cfb3f4b5b83753b704e3 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus711.cern.ch>
Date: Thu, 16 Jan 2020 16:09:44 +0100
Subject: [PATCH 03/42] distance matching, RecoVertex_v2

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 495 +++++++--------------
 Tr/PatChecker/src/PrimaryVertexChecker.h   |  61 ++-
 2 files changed, 199 insertions(+), 357 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 7b12ceafc8b..44a36a7452f 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -12,10 +12,13 @@
 // from Gaudi
 #include "AIDA/IHistogram1D.h"
 #include "DetDesc/Condition.h"
+#include "DetDesc/ConditionAccessorHolder.h"
 #include "Event/L0DUReport.h"
 #include "Event/RecVertex.h"
 #include "Event/State.h"
 #include "Event/Track.h"
+#include "Event/RecVertex_v2.h"
+#include "Event/Track_v2.h"
 #include "GaudiAlg/Consumer.h"
 #include "GaudiAlg/Tuples.h"
 #include "GaudiKernel/PhysicalConstants.h"
@@ -31,6 +34,17 @@
 
 bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
+namespace {
+  struct Beamline_t {
+    double X = std::numeric_limits<double>::signaling_NaN();
+    double Y = std::numeric_limits<double>::signaling_NaN();
+    Beamline_t( Condition const& c )
+      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+      , Y{c.param<double>( "ResolPosY" )} {}
+  };
+
+}
+
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
@@ -45,7 +59,11 @@ PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator
     : Consumer( name, pSvcLocator,
                 {
                     KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                    KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
+                    KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+//                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                    KeyValue{"MCVertexInput",LHCb::MCVertexLocation::Default},
+//                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}
                 } ) {}
 
 //=============================================================================
@@ -94,40 +112,22 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHCb::RecVertices& recoVertices ) const {
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
+                                       std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
+                                       const LHCb::MCVertices& mcvtx,
+//                                       const LHCb::MCParticles& mcps,
+//                                       const LHCb::LinksByKey& linker,
+                                       const LHCb::MCHeader& mcheader ) const {
 
   debug() << "==> Execute" << endmsg;
 
   // Event
   m_nevt++;
 
-  // Get input
-  std::vector<LHCb::Track*>     vecOfTracks;
-  std::vector<LHCb::RecVertex*> vecOfVertices;
-  std::string                   trackLoc  = "/Event/Rec/Track/VeloAsTrackV2_v1";
-  bool                          tracks_ok = true; // getInputTracks( vecOfTracks );
-
-  if ( usedTracks.size() == 0 ) tracks_ok = false;
-
-  std::vector<LHCb::Track*>::const_iterator itT;
-  for ( itT = usedTracks.begin(); usedTracks.end() != itT; itT++ ) {
-    LHCb::Track* ptr = ( *itT );
-    vecOfTracks.push_back( ptr );
+  if ( recoVtx.size()==0) {
+    return;
   }
 
-  if ( !tracks_ok && m_matchByTracks ) {
-    return; // return SUCCESSS anyway
-  }
-
-  // bool                          vertices_ok = getInputVertices( vecOfVertices );
-  std::vector<LHCb::RecVertex*>::const_iterator itVer;
-  for ( itVer = recoVertices.begin(); recoVertices.end() != itVer; itVer++ ) {
-    LHCb::RecVertex* ppv = ( *itVer );
-    vecOfVertices.push_back( ppv );
-  }
-
-  //  if ( !vertices_ok ) { return; }
-
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
   const double xRC = 0.0; // myCond -> paramAsDouble ( "ResolPosRC" ) ;
@@ -138,95 +138,41 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
   double m_beamSpotY = Y;
 
   if ( debugLevel() )
-    debug() << trackLoc << " # tracks: " << vecOfTracks.size() << "  # vertices: " << vecOfVertices.size() << endmsg;
+    debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
   std::vector<RecPVInfo>                  recpvvec;
-  std::vector<LHCb::RecVertex*>::iterator itRecV;
-  for ( itRecV = vecOfVertices.begin(); vecOfVertices.end() != itRecV; itRecV++ ) {
-    LHCb::RecVertex* pv;
-    pv = *itRecV;
+  for ( const auto& pv : recoVtx ) {
     RecPVInfo recinfo;
-    recinfo.pRECPV            = pv;
-    recinfo.position          = pv->position();
-    Gaudi::SymMatrix3x3 covPV = pv->covMatrix();
+    recinfo.pRECPV            = (&pv);
+    recinfo.position          = pv.position();
+    Gaudi::SymMatrix3x3 covPV = pv.covMatrix();
     double              sigx  = sqrt( covPV( 0, 0 ) );
     double              sigy  = sqrt( covPV( 1, 1 ) );
     double              sigz  = sqrt( covPV( 2, 2 ) );
     Gaudi::XYZPoint     a3d( sigx, sigy, sigz );
     recinfo.positionSigma = a3d;
-    recinfo.nTracks       = pv->tracks().size();
-    double minRD          = 99999.;
-    double maxRD          = -99999.;
-    double chi2           = pv->chi2();
-    double nDoF           = pv->nDoF();
-
-    std::string                               container = "container";
-    typedef const SmartRefVector<LHCb::Track> PVTRACKS;
-    PVTRACKS&                                 tracksIn = pv->tracks();
-    PVTRACKS::const_iterator                  itin;
+    recinfo.nTracks       = pv.tracks().size();
+    recinfo.chi2          = pv.chi2();
+    recinfo.nDoF          = pv.nDoF();
+    recinfo.indexMCPVInfo = -1;
 
     int    mother    = 0;
-    int    velo      = 0;
-    int    lg        = 0;
-    double d0        = 0;
-    double mind0     = 99999.0;
-    double maxd0     = -99999.0;
-    double trackChi2 = 0.0;
-    int    tr        = 0;
-
-    for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-      tr++;
-      const LHCb::Track* ptr = *itin;
-
-      if ( ptr->type() == LHCb::Track::Types::Long ) { lg++; }
-      if ( ptr->type() == LHCb::Track::Types::Velo ) { velo++; }
-
-      double           x        = ptr->position().x();
-      double           y        = ptr->position().y();
-      double           r2       = x * x + y * y;
-      Gaudi::XYZVector udir     = ptr->firstState().slopes().Unit();
-      Gaudi::XYZVector distance = ptr->firstState().position() - pv->position();
-      Gaudi::XYZVector d0i      = udir.Cross( distance.Cross( udir ) );
-
-      d0 = d0 + d0i.Mag2();
-      if ( d0i.Mag2() > maxd0 ) { maxd0 = d0i.Mag2(); }
-      if ( d0i.Mag2() < mind0 ) { mind0 = d0i.Mag2(); }
-
-      if ( r2 > maxRD ) { maxRD = r2; }
-      if ( r2 < minRD ) { minRD = r2; }
-
-      double trChi2 = ptr->chi2();
-      trackChi2     = trackChi2 + trChi2;
-    }
+    //if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
 
-    if ( m_matchByTracks ) { mother = check_mother_particle( pv, trackLoc ); }
-
-    recinfo.minTrackRD    = minRD;
-    recinfo.maxTrackRD    = maxRD;
     recinfo.mother        = mother;
-    recinfo.chi2          = chi2;
-    recinfo.nDoF          = nDoF;
-    recinfo.d0            = d0;
-    recinfo.d0nTr         = (double)d0 / (double)tr;
-    recinfo.chi2nTr       = (double)trackChi2 / (double)tr;
-    recinfo.mind0         = mind0;
-    recinfo.maxd0         = maxd0;
-    recinfo.nVeloTracks   = velo;
-    recinfo.nLongTracks   = lg;
     recinfo.indexMCPVInfo = -1;
     recpvvec.push_back( recinfo );
   }
 
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
-  LHCb::MCVertices*     mcvtx = get<LHCb::MCVertices>( LHCb::MCVertexLocation::Default );
-  for ( LHCb::MCVertices::const_iterator itMCV = mcvtx->begin(); mcvtx->end() != itMCV; itMCV++ ) {
-    const LHCb::MCParticle* motherPart = ( *itMCV )->mother();
+  for ( const auto& mcpv : mcvtx ) {
+  const LHCb::MCParticle* motherPart = mcpv->mother();
     if ( 0 == motherPart ) {
-      if ( ( *itMCV )->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
+      if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
-        mcprimvert.pMCPV             = *itMCV;
+        mcprimvert.pMCPV             = mcpv;
         mcprimvert.nRecTracks        = 0;
         mcprimvert.nRecBackTracks    = 0;
         mcprimvert.indexRecPVInfo    = -1;
@@ -242,24 +188,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     }
   }
 
-  const LHCb::MCParticle::Container* mcps = get<LHCb::MCParticle::Container>( LHCb::MCParticleLocation::Default );
-
-  int sMCP = 0;
-  int sTr  = vecOfTracks.size();
-  for ( LHCb::MCParticle::Container::const_iterator imc = mcps->begin(); mcps->end() != imc; ++imc ) {
-    const LHCb::MCParticle* dec = *imc;
-    double                  z   = dec->originVertex()->position().z();
-    if ( dec->particleID().threeCharge() != 0 && ( z < 400.0 && z > -600.0 ) ) { sMCP++; }
-  }
-
-  if ( m_matchByTracks ) {
-
-    count_reconstructed_tracks( mcpvvec, vecOfTracks, trackLoc );
-
-  } else {
-
-    count_reconstructible_mc_particles( mcpvvec );
-  }
+  count_reconstructible_mc_particles( mcpvvec );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
 
@@ -276,15 +205,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
 
-  // match MC and REC PVs
-  if ( m_matchByTracks ) {
-
-    for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_tracks( ipv, recpvvec, rblemcpv ); }
-
-  } else {
-
-    for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
-  }
+  for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
@@ -308,7 +229,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
           << format(
                  " %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
                  ipv, recpvvec[ipv].indexMCPVInfo, recpvvec[ipv].position.x(), recpvvec[ipv].position.y(),
-                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks, recpvvec[ipv].nVeloTracks,
+                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks,
                  recpvvec[ipv].positionSigma.x(), recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(),
                  recpvvec[ipv].pRECPV->chi2PerDoF() )
           << ff << endmsg;
@@ -330,16 +251,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     double erry       = recpvvec[ipv].positionSigma.y();
     double errz       = recpvvec[ipv].positionSigma.z();
     double errr       = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-    double minRDTrack = recpvvec[ipv].minTrackRD;
-    double maxRDTrack = recpvvec[ipv].maxTrackRD;
     int    mother     = recpvvec[ipv].mother;
-    double velo       = recpvvec[ipv].nVeloTracks;
-    double lg         = recpvvec[ipv].nLongTracks;
-    double d0         = recpvvec[ipv].d0;
-    double d0nTr      = recpvvec[ipv].d0nTr;
-    double chi2nTr    = recpvvec[ipv].chi2nTr;
-    double mind0      = recpvvec[ipv].mind0;
-    double maxd0      = recpvvec[ipv].maxd0;
     double chi2       = recpvvec[ipv].chi2;
     double nDoF       = recpvvec[ipv].nDoF;
 
@@ -369,16 +281,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
       myTuple2->column( "errz", double( errz ) );
       myTuple2->column( "errx", double( errx ) );
       myTuple2->column( "erry", double( erry ) );
-      myTuple2->column( "minRDTrack", double( minRDTrack ) );
-      myTuple2->column( "maxRDTrack", double( maxRDTrack ) );
       myTuple2->column( "mother", double( mother ) );
-      myTuple2->column( "velo", double( velo ) );
-      myTuple2->column( "long", double( lg ) );
-      myTuple2->column( "d0", double( d0 ) );
-      myTuple2->column( "d0nTr", double( d0nTr ) );
-      myTuple2->column( "chi2nTr", double( chi2nTr ) );
-      myTuple2->column( "mind0", double( mind0 ) );
-      myTuple2->column( "maxd0", double( maxd0 ) );
       myTuple2->column( "chi2", double( chi2 ) );
       myTuple2->column( "nDoF", double( nDoF ) );
       myTuple2->write();
@@ -541,14 +444,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     double erry              = -99999.;
     double errz              = -99999.;
     double errr              = -99999.;
-    double minRDTrack        = 99999.;
-    double maxRDTrack        = -99999.;
     double chi2              = -999999.;
     double nDoF              = -999999.;
     int    indRec            = itmc->indexRecPVInfo;
     int    reconstructed     = 0;
     int    ntracks_pvrec     = 0;
-    int    nvelotracks_pvrec = 0;
     int    ntracks_pvmc      = 0;
     int    dtrcks            = 0;
     int    pvevt             = 0;
@@ -578,11 +478,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
       errz = recpvvec[indRec].positionSigma.z();
       errr = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
       ntracks_pvrec     = recpvvec[indRec].nTracks;
-      nvelotracks_pvrec = recpvvec[indRec].nVeloTracks;
       ntracks_pvmc      = itmc->pMCPV->products().size();
       dtrcks            = ntracks_pvmc - ntracks_pvrec;
-      minRDTrack        = recpvvec[indRec].minTrackRD;
-      maxRDTrack        = recpvvec[indRec].maxTrackRD;
       mother            = recpvvec[indRec].mother;
       chi2              = recpvvec[indRec].chi2;
       nDoF              = recpvvec[indRec].nDoF;
@@ -603,13 +500,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
         plot( double( ntracks_pvrec ), 1041, "ntracks_pvrec", 0., 150., 50 );
         plot( double( dtrcks ), 1042, "mcrdtracks", 0., 150., 50 );
-        plot( double( nvelotracks_pvrec ), 1043, "nvelotracks_pvrec", 0., 150., 50 );
         if ( pvevt == 1 ) {
           plot( double( recpvvec.size() ), 1051, "nPVperEvt", -0.5, 5.5, 6 );
           for ( int ipvrec = 0; ipvrec < (int)recpvvec.size(); ipvrec++ ) {
             assoctrks = assoctrks + recpvvec[ipvrec].nTracks;
           }
-          nassoctrks = vecOfTracks.size() - assoctrks;
+          nassoctrks = tracks.size() - assoctrks;
           plot( double( nassoctrks ), 1052, "nassoctrks", 0., 150., 50 );
         }
       }
@@ -625,10 +521,10 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
       myTuple->column( "reco", double( reconstructed ) );
       myTuple->column( "isol", double( isolated ) );
       myTuple->column( "ntracks", double( ntracks_pvrec ) );
-      myTuple->column( "nvelotracks", double( nvelotracks_pvrec ) );
       myTuple->column( "nrectrmc", double( itmc->nRecTracks ) );
       myTuple->column( "dzclose", dist_closest );
       myTuple->column( "nmcpv", double( rblemcpv.size() ) );
+      myTuple->column( "mtruemcpv",double(mcheader.numOfPrimaryVertices()));
       myTuple->column( "nmcallpv", double( mcpvvec.size() ) );
       myTuple->column( "nrecpv", double( recpvvec.size() ) );
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
@@ -651,14 +547,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
       myTuple->column( "erry", erry );
       myTuple->column( "errz", errz );
       myTuple->column( "errr", errr );
-      myTuple->column( "minRDTrack", minRDTrack );
-      myTuple->column( "maxRDTrack", maxRDTrack );
       myTuple->column( "mother", double( mother ) );
       myTuple->column( "evtnr", double( m_nevt ) );
       myTuple->column( "chi2", double( chi2 ) );
       myTuple->column( "nDoF", double( nDoF ) );
-      myTuple->column( "size_tracks", double( sTr ) );
-      myTuple->column( "size_mcp", double( sMCP ) );
+      myTuple->column( "size_tracks", double( tracks.size() ) );
+      // myTuple->column( "size_mcp", double( sMCP ) );
       myTuple->column( "mcpvrec", double( nmrc ) );
       myTuple->write();
     }
@@ -667,40 +561,40 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
   return;
 }
 
-void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
-                                                      std::vector<MCPVInfo>& mcpvvec ) const {
-
-  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
-  typedef const SmartRefVector<LHCb::Track> PVTRACKS;
-  PVTRACKS&                                 tracksIn = invtx->tracks();
-  PVTRACKS::const_iterator                  itin;
-
-  int    indexmc  = -1;
-  double ratiomax = 0.;
-  for ( int imc = 0; imc < (int)mcpvvec.size(); imc++ ) {
-    if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
-    int ntrin = 0;
-    for ( std::vector<LHCb::Track*>::iterator itr = mcpvvec[imc].m_recTracksInMCPV.begin();
-          itr != mcpvvec[imc].m_recTracksInMCPV.end(); itr++ ) {
-      for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-        const LHCb::Track* ptr = *itin;
-        if ( ptr == *itr ) {
-          ntrin++;
-          break;
-        }
-      }
-    }
-    double ratio = 1. * ntrin / tracksIn.size();
-    if ( ratio > ratiomax ) {
-      ratiomax = ratio;
-      indexmc  = imc;
-    }
-  } // imc
-  if ( ratiomax > 0.05 ) {
-    rinfo[ipv].indexMCPVInfo        = indexmc;
-    mcpvvec[indexmc].indexRecPVInfo = ipv;
-  }
-}
+//void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
+//                                                      std::vector<MCPVInfo>& mcpvvec ) const {
+//
+//  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
+//  typedef const SmartRefVector<LHCb::Track> PVTRACKS;
+//  PVTRACKS&                                 tracksIn = invtx->tracks();
+//  PVTRACKS::const_iterator                  itin;
+//
+//  int    indexmc  = -1;
+//  double ratiomax = 0.;
+//  for ( int imc = 0; imc < (int)mcpvvec.size(); imc++ ) {
+//    if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
+//    int ntrin = 0;
+//    for ( std::vector<LHCb::Track*>::iterator itr = mcpvvec[imc].m_recTracksInMCPV.begin();
+//          itr != mcpvvec[imc].m_recTracksInMCPV.end(); itr++ ) {
+//      for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
+//        const LHCb::Track* ptr = *itin;
+//        if ( ptr == *itr ) {
+//          ntrin++;
+//          break;
+//        }
+//      }
+//    }
+//    double ratio = 1. * ntrin / tracksIn.size();
+//    if ( ratio > ratiomax ) {
+//      ratiomax = ratio;
+//      indexmc  = imc;
+//    }
+//  } // imc
+//  if ( ratiomax > 0.05 ) {
+//    rinfo[ipv].indexMCPVInfo        = indexmc;
+//    mcpvvec[indexmc].indexRecPVInfo = ipv;
+//  }
+//}
 
 void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo,
                                                         std::vector<MCPVInfo>& mcpvvec ) const {
@@ -773,8 +667,7 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble << "  tracks are reconstructed" << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated << " mm" << endmsg;
-  std::string ff = "by counting tracks";
-  if ( !m_matchByTracks ) ff = "by dz distance";
+  std::string ff = "by dz distance";
   info() << " REC and MC vertices matched:  " << ff << endmsg;
 
   info() << " " << endmsg;
@@ -883,54 +776,52 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
   info() << pmes << format( " %6.3f ( %7d / %8d )", rat, a, b ) << endmsg;
 }
 
-void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-                                                       std::vector<LHCb::Track*>& vecOfTracks,
-                                                       std::string                trackLoc ) const {
-
-  LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
-
-  // Find # of reconstructed tracks of every MC PV
-  std::vector<MCPVInfo>::iterator itinfomc;
-  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
-    LHCb::MCVertex* avtx = itinfomc->pMCPV;
-
-    SmartRefVector<LHCb::MCParticle> parts = avtx->products();
-    std::vector<LHCb::MCParticle*>   allproducts;
-    collectProductss( avtx, avtx, allproducts );
-
-    LHCb::Track*                             recTrack = 0;
-    std::vector<LHCb::MCParticle*>::iterator imcp;
-    for ( imcp = allproducts.begin(); allproducts.end() != imcp; imcp++ ) {
-      LHCb::MCParticle* pmcp   = *imcp;
-      int               isReco = 0;
-      for ( std::vector<LHCb::Track*>::iterator itrec = vecOfTracks.begin(); itrec != vecOfTracks.end(); itrec++ ) {
-        LHCb::MCParticle* partmc = trackMClink.first( ( *itrec )->key() );
-        if ( partmc && partmc == pmcp ) {
-          recTrack = ( *itrec );
-          if ( !m_requireVelo || recTrack->hasVelo() ) {
-            isReco = 1;
-            break;
-          }
-        }
-      }
-      if ( pmcp->particleID().threeCharge() != 0 && isReco ) {
-        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-        if ( dv2 < 0.0001 ) {
-          itinfomc->m_mcPartInMCPV.push_back( pmcp );
-          itinfomc->m_recTracksInMCPV.push_back( recTrack );
-        }
-      }
-    }
-    itinfomc->nRecTracks = itinfomc->m_mcPartInMCPV.size();
-  }
-}
-
-int PrimaryVertexChecker::count_velo_tracks( LHCb::RecVertex* RecVtx ) {
-  SmartRefVector<LHCb::Track> vtx_tracks  = RecVtx->tracks();
+//void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
+//                                                       std::vector<LHCb::Track*>& vecOfTracks,
+//                                                       std::string                trackLoc ) const {
+//
+//  LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
+//
+//  // Find # of reconstructed tracks of every MC PV
+//  std::vector<MCPVInfo>::iterator itinfomc;
+//  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
+//    LHCb::MCVertex* avtx = itinfomc->pMCPV;
+//
+//    SmartRefVector<LHCb::MCParticle> parts = avtx->products();
+//    std::vector<LHCb::MCParticle*>   allproducts;
+//    collectProductss( avtx, avtx, allproducts );
+//
+//    LHCb::Track*                             recTrack = 0;
+//    std::vector<LHCb::MCParticle*>::iterator imcp;
+//    for ( imcp = allproducts.begin(); allproducts.end() != imcp; imcp++ ) {
+//      LHCb::MCParticle* pmcp   = *imcp;
+//      int               isReco = 0;
+//      for ( std::vector<LHCb::Track*>::iterator itrec = vecOfTracks.begin(); itrec != vecOfTracks.end(); itrec++ ) {
+//        LHCb::MCParticle* partmc = trackMClink.first( ( *itrec )->key() );
+//        if ( partmc && partmc == pmcp ) {
+//          recTrack = ( *itrec );
+//          if ( !m_requireVelo || recTrack->hasVelo() ) {
+//            isReco = 1;
+//            break;
+//          }
+//        }
+//      }
+//      if ( pmcp->particleID().threeCharge() != 0 && isReco ) {
+//        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
+//        if ( dv2 < 0.0001 ) {
+//          itinfomc->m_mcPartInMCPV.push_back( pmcp );
+//          itinfomc->m_recTracksInMCPV.push_back( recTrack );
+//        }
+//      }
+//    }
+//    itinfomc->nRecTracks = itinfomc->m_mcPartInMCPV.size();
+//  }
+//}
+
+int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
   int                         nVeloTracks = 0;
-  for ( unsigned int it = 0; it < vtx_tracks.size(); it++ ) {
-    const LHCb::Track* ptr = vtx_tracks[it];
-    if ( ptr->hasVelo() ) nVeloTracks++;
+  for( const auto& track: tracksPV ) {
+    if ( track.track->hasVelo() ) nVeloTracks++;
   }
   return nVeloTracks;
 }
@@ -965,92 +856,48 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     }
   }
 }
-int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::string trackLoc ) const {
-
-  int         motherPart = 0;
-  const auto& tracksIn   = pv->tracks();
-
-  LinkedTo<LHCb::MCParticle, LHCb::Track> link( eventSvc(), msgSvc(), trackLoc );
-  for ( auto itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-    const LHCb::Track* ptr  = *itin;
-    LHCb::MCParticle*  part = nullptr;
-    part                    = link.first( ptr->key() );
-    if ( part != nullptr ) {
-      const LHCb::MCParticle* part1 = part;
-      int                     i     = 0;
-      while ( part1 != nullptr ) {
-        // std::cout<<"X"<<std::endl;
-        const LHCb::MCParticle* mother = part1->mother();
-        if ( mother != nullptr ) {
-          i     = i + 1;
-          part1 = mother;
-          /// std::cout<<i<<": "<<part1->particleID().pid()<<std::endl;
-        } else {
-          break;
-        }
-      }
-
-      if ( part1->particleID().hasBottom() == true ) { motherPart = 2.0; }
-      if ( part1->particleID().hasCharm() == true ) { motherPart = 1.0; }
-    }
-  }
-  return motherPart;
-}
-
-// bool PrimaryVertexChecker::getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const {
-
-//   // std::string tracksName = m_inputTracksName;
-
-//   // if ( m_inputTracksName == "Offline" ) {
-//   //   tracksName = LHCb::TrackLocation::Default;
-//   // } else if ( m_inputTracksName == "3D" ) {
-//   //   tracksName = LHCb::TrackLocation::Velo;
-//   // } else if ( m_inputTracksName == "2D" ) {
-//   //   tracksName = LHCb::TrackLocation::RZVelo;
-//   // }
-
-//   // if ( tracksName == "none" ) {
-//   //   debug() << " Tracks not specified " << tracksName << endmsg;
-//   //   return false;
-//   // }
-
-//   //LHCb::Tracks* usedTracks = getOrCreate<LHCb::Tracks, LHCb::Tracks>( LHCb::TrackLocation::Default );
-//   if ( usedTracks->size() == 0 ) return false;
-
-//   std::vector<LHCb::Track*>::const_iterator itT;
-//   for ( itT = usedTracks->begin(); usedTracks->end() != itT; itT++ ) {
-//     LHCb::Track* ptr = ( *itT );
-//     vecOfTracks.push_back( ptr );
-//   }
-
-//   return true;
-// }
-
-// bool PrimaryVertexChecker::getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const {
-
-//   // std::string verticesName = m_inputVerticesName;
-
-//   // if ( m_inputVerticesName == "Offline" ) {
-//   //   verticesName = LHCb::RecVertexLocation::Primary;
-//   // } else if ( m_inputVerticesName == "3D" ) {
-//   //   verticesName = LHCb::RecVertexLocation::Velo3D;
-//   // } else if ( m_inputVerticesName == "2D" ) {
-//   //   verticesName = LHCb::RecVertexLocation::Velo2D;
-//   // }
-
-//   // if ( verticesName == "none" ) {
-//   //   debug() << " Vertices not specified " << verticesName << endmsg;
-//   //   return false;
-//   // }
-
-//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>(
-//   LHCb::RecVertexLocation::Primary );
 
-//   std::vector<LHCb::RecVertex*>::const_iterator itVer;
-//   for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
-//     LHCb::RecVertex* ppv = ( *itVer );
-//     vecOfVertices.push_back( ppv );
-//   }
+//int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
+//                                                 const LHCb::MCParticles& mcps,
+//                                                 const LHCb::LinksByKey& linker  ) const {
+//
+//  int         motherPart = 0;
+//  for ( const auto& tr : tracksPV ) {
+//
+//    double                  maxWeight{0};
+//    const LHCb::MCParticle* mcp{nullptr};
+//    linker.applyToLinks( tr.track->key(),
+//                        [&maxWeight, &mcp, &mcps]( unsigned int, unsigned int mcPartKey, float weight ) {
+//                          if ( weight > maxWeight ) {
+//                            maxWeight = weight;
+//                            mcp       = static_cast<const LHCb::MCParticle*>( mcps.containedObject( mcPartKey ) );
+//                          }
+//                        } );
+//
+//  LinkedTo<LHCb::MCParticle, LHCb::Track> link( eventSvc(), msgSvc(), trackLoc );
+//  for ( auto itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
+//    const LHCb::Track* ptr  = *itin;
+//    LHCb::MCParticle*  part = nullptr;
+//    part                    = link.first( ptr->key() );
+//    if ( part != nullptr ) {
+//      const LHCb::MCParticle* part1 = part;
+//      int                     i     = 0;
+//      while ( part1 != nullptr ) {
+//        // std::cout<<"X"<<std::endl;
+//        const LHCb::MCParticle* mother = part1->mother();
+//        if ( mother != nullptr ) {
+//          i     = i + 1;
+//          part1 = mother;
+//          /// std::cout<<i<<": "<<part1->particleID().pid()<<std::endl;
+//        } else {
+//          break;
+//        }
+//      }
+//
+//      if ( part1->particleID().hasBottom() == true ) { motherPart = 2.0; }
+//      if ( part1->particleID().hasCharm() == true ) { motherPart = 1.0; }
+//    }
+//  }
+//  return motherPart;
+//}
 
-//   return true;
-// }
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
index 9d1329829d9..0257ed91e50 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.h
@@ -13,6 +13,9 @@
 
 #include "Event/MCVertex.h"
 #include "Event/RecVertex.h"
+#include "Event/MCHeader.h"
+#include "Event/MCParticle.h"
+#include "Event/MCVertex.h"
 #include "Event/Track.h"
 #include "MCInterfaces/IForcedBDecayTool.h"
 
@@ -35,56 +38,47 @@ typedef struct {
 typedef struct {
 public:
   int              nTracks;     // number of tracks
-  int              nVeloTracks; // number of velo tracks in a vertex
-  int              nLongTracks;
-  double           minTrackRD; //
-  double           maxTrackRD; //
   double           chi2;
   double           nDoF;
-  double           d0;
-  double           d0nTr;
-  double           chi2nTr;
-  double           mind0;
-  double           maxd0;
   int              mother;
   Gaudi::XYZPoint  position;      // position
   Gaudi::XYZPoint  positionSigma; // position sigmas
   int              indexMCPVInfo; // index to MCPVInfo
-  LHCb::RecVertex* pRECPV;        // pointer to REC PV
+  const LHCb::Event::v2::RecVertex* pRECPV;
+//  LHCb::RecVertex* pRECPV;        // pointer to REC PV
 } RecPVInfo;
 
-class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, const LHCb::RecVertices& ),
+class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&,
+                                                                      std::vector<LHCb::Event::v2::RecVertex> const& vertices, //const LHCb::RecVertices&,
+                                                                      const LHCb::MCVertices&,
+                                                                      //const LHCb::MCParticles&,
+                                                                      //const LHCb::LinksByKey&,
+                                                                      const LHCb::MCHeader& ),
                                                                 Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks&      usedTracks,
-                   const LHCb::RecVertices& recoVertices ) const override; ///< Algorithm execution
+  void       operator()( const LHCb::Tracks& tracks,
+                         //const LHCb::RecVertices& recoVtx,
+                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
+                         const LHCb::MCVertices& mcvtx,
+                         // const LHCb::MCParticles& mcps,
+                         //const LHCb::LinksByKey& linker,
+                         const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
   StatusCode finalize() override;                                                ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  // int         m_nTracksToBeRecble;
-  // bool        m_produceHistogram;
-  // bool        m_produceNtuple;
-  // bool        m_requireVelo;
-  // double      m_dzIsolated;
-  // bool        m_matchByTracks;
-  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
+  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
   Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
   Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
   Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", true};
-  // Gaudi::Property<std::string> m_inputTracksName{this, "inputTracksName", LHCb::TrackLocation::Default};
-  // Gaudi::Property<std::string> m_inputVerticesName{this, "inputVerticesName", LHCb::RecVertexLocation::Primary};
-
-  // std::string m_inputTracksName;
-  // std::string m_inputVerticesName;
+  // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
   mutable int m_nevt;
   mutable int m_nMCPV, m_nRecMCPV;
@@ -111,14 +105,15 @@ private:
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( std::string mes, int a, int b );
-  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+//  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-                                   std::string trackLoc ) const;
-  int  count_velo_tracks( LHCb::RecVertex* RecVtx );
+//  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
+//                                   std::string trackLoc ) const;
+  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
   void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
-  // bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
-  // bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-  int check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
+//   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
+//   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
+//  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles& mcps, const LHCb::LinksByKey& linker ) const;
 };
 #endif // PRIMARYVERTEXCHECKER_H
+
-- 
GitLab


From f689e8f5a3ee6cf1e5c4fed207e7f53a08aba811 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus724.cern.ch>
Date: Thu, 16 Jan 2020 20:16:39 +0100
Subject: [PATCH 04/42] merged headers into source

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 275 ++++++++++++++-------
 Tr/PatChecker/src/PrimaryVertexChecker.h   | 119 ---------
 2 files changed, 182 insertions(+), 212 deletions(-)
 delete mode 100644 Tr/PatChecker/src/PrimaryVertexChecker.h

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 44a36a7452f..e385d6aca69 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -8,29 +8,140 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-// Include files
-// from Gaudi
+
 #include "AIDA/IHistogram1D.h"
 #include "DetDesc/Condition.h"
 #include "DetDesc/ConditionAccessorHolder.h"
 #include "Event/L0DUReport.h"
+#include "Event/MCHeader.h"
+#include "Event/MCParticle.h"
+#include "Event/MCVertex.h"
 #include "Event/RecVertex.h"
+#include "Event/RecVertex_v2.h"
 #include "Event/State.h"
 #include "Event/Track.h"
-#include "Event/RecVertex_v2.h"
 #include "Event/Track_v2.h"
 #include "GaudiAlg/Consumer.h"
+#include "GaudiAlg/GaudiTupleAlg.h"
 #include "GaudiAlg/Tuples.h"
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
 #include "Linker/AllLinks.h"
 #include "Linker/LinkerWithKey.h"
+#include "MCInterfaces/IForcedBDecayTool.h"
 #include "VeloDet/DeVelo.h"
 #include <Event/MCTrackInfo.h>
 #include <Linker/LinkedTo.h>
-// local
-#include "PrimaryVertexChecker.h"
+
+//-----------------------------------------------------------------------------
+// Implementation file for class : PrimaryVertexChecker
+//-----------------------------------------------------------------------------
+
+typedef struct {
+  LHCb::MCVertex*                pMCPV;             // pointer to MC PV
+  int                            nRecTracks;        // number of reconstructed tracks from this MCPV
+  int                            nRecBackTracks;    // number of reconstructed backward tracks
+  int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
+  int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
+  int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
+  double                         distToClosestMCPV; // distance to closest reconstructible MCPV
+  int                            decayCharm;        // type of mother particle
+  int                            decayBeauty;
+  std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
+  std::vector<LHCb::Track*>      m_recTracksInMCPV;
+} MCPVInfo;
+
+typedef struct {
+public:
+  int                               nTracks; // number of tracks
+  double                            chi2;
+  double                            nDoF;
+  int                               mother;
+  Gaudi::XYZPoint                   position;      // position
+  Gaudi::XYZPoint                   positionSigma; // position sigmas
+  int                               indexMCPVInfo; // index to MCPVInfo
+  const LHCb::Event::v2::RecVertex* pRECPV;
+  //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
+} RecPVInfo;
+
+class PrimaryVertexChecker
+    : public Gaudi::Functional::Consumer<
+          void( const LHCb::Tracks&,
+                std::vector<LHCb::Event::v2::RecVertex> const& vertices, // const LHCb::RecVertices&,
+                const LHCb::MCVertices&,
+                // const LHCb::MCParticles&,
+                // const LHCb::LinksByKey&,
+                const LHCb::MCHeader& ),
+          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+public:
+  /// Standard constructor
+  PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
+      : Consumer{ name,
+                  pSvcLocator,
+                  {KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                  KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                  //                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                  KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                  //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+                  KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}}} {}
+
+  StatusCode initialize() override; ///< Algorithm initialization
+  void       operator()( const LHCb::Tracks& tracks,
+                   // const LHCb::RecVertices& recoVtx,
+                   std::vector<LHCb::Event::v2::RecVertex> const& vertices, const LHCb::MCVertices& mcvtx,
+                   // const LHCb::MCParticles& mcps,
+                   // const LHCb::LinksByKey& linker,
+                   const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                                         ///< Algorithm finalization
+
+protected:
+  bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
+
+private:
+  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
+  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
+  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
+  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
+  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
+  // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
+
+  mutable int m_nevt;
+  mutable int m_nMCPV, m_nRecMCPV;
+  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
+  mutable int m_nMCPV_close, m_nRecMCPV_close;
+  mutable int m_nFalsePV, m_nFalsePV_real;
+  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
+  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
+  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
+  mutable int m_nRecMCPV_wrong_1mult;
+  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
+  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
+  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
+  mutable int m_nRecMCPV_wrong_2mult;
+  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
+  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
+  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
+  mutable int m_nRecMCPV_wrong_3mult;
+  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
+  mutable int m_nBFalse, m_nRecBFalse;
+
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                               std::vector<MCPVInfo>::iterator& itmc ) const;
+
+  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
+  void printRat( std::string mes, int a, int b );
+  //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+  //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
+  //                                   std::string trackLoc ) const;
+  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
+  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
+  //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
+  //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
+  //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
+  //  mcps, const LHCb::LinksByKey& linker ) const;
+};
 
 bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
@@ -39,33 +150,15 @@ namespace {
     double X = std::numeric_limits<double>::signaling_NaN();
     double Y = std::numeric_limits<double>::signaling_NaN();
     Beamline_t( Condition const& c )
-      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
-      , Y{c.param<double>( "ResolPosY" )} {}
+        : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+        , Y{c.param<double>( "ResolPosY" )} {}
   };
 
-}
-
-//-----------------------------------------------------------------------------
-// Implementation file for class : PrimaryVertexChecker
-//-----------------------------------------------------------------------------
+} // namespace
 
 // Declaration of the Algorithm Factory
 DECLARE_COMPONENT( PrimaryVertexChecker )
 
-//=============================================================================
-// Standard constructor, initializes variables
-//=============================================================================
-PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-    : Consumer( name, pSvcLocator,
-                {
-                    KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                    KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-//                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                    KeyValue{"MCVertexInput",LHCb::MCVertexLocation::Default},
-//                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}
-                } ) {}
-
 //=============================================================================
 // Initialization
 //=============================================================================
@@ -112,11 +205,11 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
+void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
                                        std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
-                                       const LHCb::MCVertices& mcvtx,
-//                                       const LHCb::MCParticles& mcps,
-//                                       const LHCb::LinksByKey& linker,
+                                       const LHCb::MCVertices&                        mcvtx,
+                                       // const LHCb::MCParticles& mcps,
+                                       // const LHCb::LinksByKey& linker,
                                        const LHCb::MCHeader& mcheader ) const {
 
   debug() << "==> Execute" << endmsg;
@@ -124,9 +217,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   // Event
   m_nevt++;
 
-  if ( recoVtx.size()==0) {
-    return;
-  }
+  if ( recoVtx.size() == 0 ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -137,14 +228,13 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   double m_beamSpotX = ( xRC + xLA ) / 2;
   double m_beamSpotY = Y;
 
-  if ( debugLevel() )
-    debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
+  if ( debugLevel() ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
-  std::vector<RecPVInfo>                  recpvvec;
+  std::vector<RecPVInfo> recpvvec;
   for ( const auto& pv : recoVtx ) {
     RecPVInfo recinfo;
-    recinfo.pRECPV            = (&pv);
+    recinfo.pRECPV            = ( &pv );
     recinfo.position          = pv.position();
     Gaudi::SymMatrix3x3 covPV = pv.covMatrix();
     double              sigx  = sqrt( covPV( 0, 0 ) );
@@ -157,8 +247,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
     recinfo.nDoF          = pv.nDoF();
     recinfo.indexMCPVInfo = -1;
 
-    int    mother    = 0;
-    //if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
+    int mother = 0;
+    // if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
 
     recinfo.mother        = mother;
     recinfo.indexMCPVInfo = -1;
@@ -168,7 +258,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
   for ( const auto& mcpv : mcvtx ) {
-  const LHCb::MCParticle* motherPart = mcpv->mother();
+    const LHCb::MCParticle* motherPart = mcpv->mother();
     if ( 0 == motherPart ) {
       if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
@@ -229,9 +319,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
           << format(
                  " %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
                  ipv, recpvvec[ipv].indexMCPVInfo, recpvvec[ipv].position.x(), recpvvec[ipv].position.y(),
-                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks,
-                 recpvvec[ipv].positionSigma.x(), recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(),
-                 recpvvec[ipv].pRECPV->chi2PerDoF() )
+                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks, recpvvec[ipv].positionSigma.x(),
+                 recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(), recpvvec[ipv].pRECPV->chi2PerDoF() )
           << ff << endmsg;
     }
     debug() << " -----------------------------------" << endmsg;
@@ -242,18 +331,18 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   int nFalsePV      = 0;
   int nFalsePV_real = 0;
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) {
-    int    fake       = 0;
-    double x          = recpvvec[ipv].position.x();
-    double y          = recpvvec[ipv].position.y();
-    double z          = recpvvec[ipv].position.z();
-    double r          = std::sqrt( x * x + y * y );
-    double errx       = recpvvec[ipv].positionSigma.x();
-    double erry       = recpvvec[ipv].positionSigma.y();
-    double errz       = recpvvec[ipv].positionSigma.z();
-    double errr       = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-    int    mother     = recpvvec[ipv].mother;
-    double chi2       = recpvvec[ipv].chi2;
-    double nDoF       = recpvvec[ipv].nDoF;
+    int    fake   = 0;
+    double x      = recpvvec[ipv].position.x();
+    double y      = recpvvec[ipv].position.y();
+    double z      = recpvvec[ipv].position.z();
+    double r      = std::sqrt( x * x + y * y );
+    double errx   = recpvvec[ipv].positionSigma.x();
+    double erry   = recpvvec[ipv].positionSigma.y();
+    double errz   = recpvvec[ipv].positionSigma.z();
+    double errr   = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
+    int    mother = recpvvec[ipv].mother;
+    double chi2   = recpvvec[ipv].chi2;
+    double nDoF   = recpvvec[ipv].nDoF;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
       nFalsePV++;
@@ -429,32 +518,32 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   int high = 0;
 
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
-    double x                 = -99999.;
-    double y                 = -99999.;
-    double dx                = -99999.;
-    double dy                = -99999.;
-    double dz                = -99999.;
-    double r                 = -99999.;
-    double zMC               = -99999.;
-    double yMC               = -99999.;
-    double xMC               = -99999.;
-    double rMC               = -99999.;
-    double z                 = -99999.;
-    double errx              = -99999.;
-    double erry              = -99999.;
-    double errz              = -99999.;
-    double errr              = -99999.;
-    double chi2              = -999999.;
-    double nDoF              = -999999.;
-    int    indRec            = itmc->indexRecPVInfo;
-    int    reconstructed     = 0;
-    int    ntracks_pvrec     = 0;
-    int    ntracks_pvmc      = 0;
-    int    dtrcks            = 0;
-    int    pvevt             = 0;
-    int    mother            = 0;
-    int    assoctrks         = 0;
-    int    nassoctrks        = 0;
+    double x             = -99999.;
+    double y             = -99999.;
+    double dx            = -99999.;
+    double dy            = -99999.;
+    double dz            = -99999.;
+    double r             = -99999.;
+    double zMC           = -99999.;
+    double yMC           = -99999.;
+    double xMC           = -99999.;
+    double rMC           = -99999.;
+    double z             = -99999.;
+    double errx          = -99999.;
+    double erry          = -99999.;
+    double errz          = -99999.;
+    double errr          = -99999.;
+    double chi2          = -999999.;
+    double nDoF          = -999999.;
+    int    indRec        = itmc->indexRecPVInfo;
+    int    reconstructed = 0;
+    int    ntracks_pvrec = 0;
+    int    ntracks_pvmc  = 0;
+    int    dtrcks        = 0;
+    int    pvevt         = 0;
+    int    mother        = 0;
+    int    assoctrks     = 0;
+    int    nassoctrks    = 0;
 
     zMC = itmc->pMCPV->position().z();
     yMC = itmc->pMCPV->position().y();
@@ -477,12 +566,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
       erry = recpvvec[indRec].positionSigma.y();
       errz = recpvvec[indRec].positionSigma.z();
       errr = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-      ntracks_pvrec     = recpvvec[indRec].nTracks;
-      ntracks_pvmc      = itmc->pMCPV->products().size();
-      dtrcks            = ntracks_pvmc - ntracks_pvrec;
-      mother            = recpvvec[indRec].mother;
-      chi2              = recpvvec[indRec].chi2;
-      nDoF              = recpvvec[indRec].nDoF;
+      ntracks_pvrec = recpvvec[indRec].nTracks;
+      ntracks_pvmc  = itmc->pMCPV->products().size();
+      dtrcks        = ntracks_pvmc - ntracks_pvrec;
+      mother        = recpvvec[indRec].mother;
+      chi2          = recpvvec[indRec].chi2;
+      nDoF          = recpvvec[indRec].nDoF;
 
       // Filling histograms
       if ( m_produceHistogram ) {
@@ -524,7 +613,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
       myTuple->column( "nrectrmc", double( itmc->nRecTracks ) );
       myTuple->column( "dzclose", dist_closest );
       myTuple->column( "nmcpv", double( rblemcpv.size() ) );
-      myTuple->column( "mtruemcpv",double(mcheader.numOfPrimaryVertices()));
+      myTuple->column( "mtruemcpv", double( mcheader.numOfPrimaryVertices() ) );
       myTuple->column( "nmcallpv", double( mcpvvec.size() ) );
       myTuple->column( "nrecpv", double( recpvvec.size() ) );
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
@@ -561,7 +650,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   return;
 }
 
-//void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
+// void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
 //                                                      std::vector<MCPVInfo>& mcpvvec ) const {
 //
 //  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
@@ -776,7 +865,7 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
   info() << pmes << format( " %6.3f ( %7d / %8d )", rat, a, b ) << endmsg;
 }
 
-//void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
+// void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
 //                                                       std::vector<LHCb::Track*>& vecOfTracks,
 //                                                       std::string                trackLoc ) const {
 //
@@ -819,8 +908,8 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
 //}
 
 int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
-  int                         nVeloTracks = 0;
-  for( const auto& track: tracksPV ) {
+  int nVeloTracks = 0;
+  for ( const auto& track : tracksPV ) {
     if ( track.track->hasVelo() ) nVeloTracks++;
   }
   return nVeloTracks;
@@ -857,7 +946,7 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
   }
 }
 
-//int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
+// int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
 //                                                 const LHCb::MCParticles& mcps,
 //                                                 const LHCb::LinksByKey& linker  ) const {
 //
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
deleted file mode 100644
index 0257ed91e50..00000000000
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*****************************************************************************\
-* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration      *
-*                                                                             *
-* This software is distributed under the terms of the GNU General Public      *
-* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
-*                                                                             *
-* In applying this licence, CERN does not waive the privileges and immunities *
-* granted to it by virtue of its status as an Intergovernmental Organization  *
-* or submit itself to any jurisdiction.                                       *
-\*****************************************************************************/
-#ifndef PRIMARYVERTEXCHECKER_H
-#define PRIMARYVERTEXCHECKER_H 1
-
-#include "Event/MCVertex.h"
-#include "Event/RecVertex.h"
-#include "Event/MCHeader.h"
-#include "Event/MCParticle.h"
-#include "Event/MCVertex.h"
-#include "Event/Track.h"
-#include "MCInterfaces/IForcedBDecayTool.h"
-
-#include "GaudiAlg/GaudiTupleAlg.h"
-
-typedef struct {
-  LHCb::MCVertex*                pMCPV;             // pointer to MC PV
-  int                            nRecTracks;        // number of reconstructed tracks from this MCPV
-  int                            nRecBackTracks;    // number of reconstructed backward tracks
-  int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
-  int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
-  int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
-  double                         distToClosestMCPV; // distance to closest reconstructible MCPV
-  int                            decayCharm;        // type of mother particle
-  int                            decayBeauty;
-  std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
-  std::vector<LHCb::Track*>      m_recTracksInMCPV;
-} MCPVInfo;
-
-typedef struct {
-public:
-  int              nTracks;     // number of tracks
-  double           chi2;
-  double           nDoF;
-  int              mother;
-  Gaudi::XYZPoint  position;      // position
-  Gaudi::XYZPoint  positionSigma; // position sigmas
-  int              indexMCPVInfo; // index to MCPVInfo
-  const LHCb::Event::v2::RecVertex* pRECPV;
-//  LHCb::RecVertex* pRECPV;        // pointer to REC PV
-} RecPVInfo;
-
-class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&,
-                                                                      std::vector<LHCb::Event::v2::RecVertex> const& vertices, //const LHCb::RecVertices&,
-                                                                      const LHCb::MCVertices&,
-                                                                      //const LHCb::MCParticles&,
-                                                                      //const LHCb::LinksByKey&,
-                                                                      const LHCb::MCHeader& ),
-                                                                Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
-public:
-  /// Standard constructor
-  PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
-
-  StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks,
-                         //const LHCb::RecVertices& recoVtx,
-                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
-                         const LHCb::MCVertices& mcvtx,
-                         // const LHCb::MCParticles& mcps,
-                         //const LHCb::LinksByKey& linker,
-                         const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
-  StatusCode finalize() override;                                                ///< Algorithm finalization
-
-protected:
-  bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
-
-private:
-  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
-  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
-  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
-  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
-  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
-
-  mutable int m_nevt;
-  mutable int m_nMCPV, m_nRecMCPV;
-  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
-  mutable int m_nMCPV_close, m_nRecMCPV_close;
-  mutable int m_nFalsePV, m_nFalsePV_real;
-  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
-  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
-  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
-  mutable int m_nRecMCPV_wrong_1mult;
-  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
-  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
-  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
-  mutable int m_nRecMCPV_wrong_2mult;
-  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
-  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
-  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
-  mutable int m_nRecMCPV_wrong_3mult;
-  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
-  mutable int m_nBFalse, m_nRecBFalse;
-
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                               std::vector<MCPVInfo>::iterator& itmc ) const;
-
-  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( std::string mes, int a, int b );
-//  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-//  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-//                                   std::string trackLoc ) const;
-  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
-//   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
-//   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-//  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles& mcps, const LHCb::LinksByKey& linker ) const;
-};
-#endif // PRIMARYVERTEXCHECKER_H
-
-- 
GitLab


From 581d1726adb554c6a2e2f2e385e5c978aa269dc4 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus783.cern.ch>
Date: Thu, 23 Jan 2020 14:26:20 +0100
Subject: [PATCH 05/42] refactoring

---
 .../src/fromVectorLHCbRecVertexv2.cpp         |   5 +-
 Tr/PatChecker/src/PrimaryVertexChecker.cpp    | 621 +++++++++---------
 2 files changed, 321 insertions(+), 305 deletions(-)

diff --git a/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp b/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
index 9b59e958620..28f094203c7 100644
--- a/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
+++ b/Pr/PrConverters/src/fromVectorLHCbRecVertexv2.cpp
@@ -36,7 +36,7 @@ namespace LHCb::Converters::RecVertex::v2 {
         converted_vertex->setCovMatrix( vertex.covMatrix() );
         // Add tracks from keyed container.
         // The following relies on the Velo tracks being created with a key in PrPixelTracking.
-        /*        for ( const auto& weightedTrack : vertex.tracks() ) {
+        for ( const auto& weightedTrack : vertex.tracks() ) {
           auto track_in_keyed_container =
               std::find_if( std::begin( keyed_tracks ), std::end( keyed_tracks ), [&weightedTrack]( const auto& t ) {
                 return ( ( t->nLHCbIDs() == weightedTrack.track->nLHCbIDs() ) &&
@@ -44,8 +44,7 @@ namespace LHCb::Converters::RecVertex::v2 {
               } );
           assert( track_in_keyed_container != std::end( keyed_tracks ) );
           converted_vertex->addToTracks( *track_in_keyed_container, weightedTrack.weight );
-          }*/
-
+        }
         converted_vertices.add( converted_vertex.release() );
       }
       return converted_vertices;
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index e385d6aca69..9ca9e9dc103 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -10,35 +10,40 @@
 \*****************************************************************************/
 
 #include "AIDA/IHistogram1D.h"
+
 #include "DetDesc/Condition.h"
 #include "DetDesc/ConditionAccessorHolder.h"
-#include "Event/L0DUReport.h"
+
 #include "Event/MCHeader.h"
 #include "Event/MCParticle.h"
 #include "Event/MCVertex.h"
+#include "Event/MCTrackInfo.h"
+#include "Event/MCProperty.h"
+
 #include "Event/RecVertex.h"
 #include "Event/RecVertex_v2.h"
 #include "Event/State.h"
 #include "Event/Track.h"
 #include "Event/Track_v2.h"
+
 #include "GaudiAlg/Consumer.h"
 #include "GaudiAlg/GaudiTupleAlg.h"
 #include "GaudiAlg/Tuples.h"
+
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
-#include "Linker/AllLinks.h"
-#include "Linker/LinkerWithKey.h"
-#include "MCInterfaces/IForcedBDecayTool.h"
-#include "VeloDet/DeVelo.h"
-#include <Event/MCTrackInfo.h>
-#include <Linker/LinkedTo.h>
 
+#include <tuple>
+#include <string>
+#include <vector>
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
 
-typedef struct {
+namespace {
+
+  struct MCPVInfo{
   LHCb::MCVertex*                pMCPV;             // pointer to MC PV
   int                            nRecTracks;        // number of reconstructed tracks from this MCPV
   int                            nRecBackTracks;    // number of reconstructed backward tracks
@@ -50,10 +55,10 @@ typedef struct {
   int                            decayBeauty;
   std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
   std::vector<LHCb::Track*>      m_recTracksInMCPV;
-} MCPVInfo;
+};
 
-typedef struct {
-public:
+  struct RecPVInfo{
+  public:
   int                               nTracks; // number of tracks
   double                            chi2;
   double                            nDoF;
@@ -63,7 +68,32 @@ public:
   int                               indexMCPVInfo; // index to MCPVInfo
   const LHCb::Event::v2::RecVertex* pRECPV;
   //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
-} RecPVInfo;
+};
+
+  inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
+
+  inline const std::vector<std::string> categories = {"1_all","2_isol","3_close","4_ntracks<X","5_ntracks>=X","6_z<-X","7_zIn(-X,X)","8_z>X"};
+
+  struct Beamline_t {
+    double X = std::numeric_limits<double>::signaling_NaN();
+    double Y = std::numeric_limits<double>::signaling_NaN();
+    Beamline_t( Condition const& c )
+      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+      , Y{c.param<double>( "ResolPosY" )} {}
+  };
+
+  bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
+
+  struct Stats{
+    std::string name;
+    int MCPV;
+    int RecPV;
+    int FalsePV;
+    int notRecPV;
+    int nTracks;
+  };
+}
+
 
 class PrimaryVertexChecker
     : public Gaudi::Functional::Consumer<
@@ -72,7 +102,8 @@ class PrimaryVertexChecker
                 const LHCb::MCVertices&,
                 // const LHCb::MCParticles&,
                 // const LHCb::LinksByKey&,
-                const LHCb::MCHeader& ),
+                const LHCb::MCHeader&,
+                const LHCb::MCProperty&),
           Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
@@ -82,9 +113,12 @@ public:
                   {KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
                   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
                   //                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                  KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                    KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
+                    KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
                   //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-                  KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}}} {}
+
+                      }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
   void       operator()( const LHCb::Tracks& tracks,
@@ -92,7 +126,8 @@ public:
                    std::vector<LHCb::Event::v2::RecVertex> const& vertices, const LHCb::MCVertices& mcvtx,
                    // const LHCb::MCParticles& mcps,
                    // const LHCb::LinksByKey& linker,
-                   const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
+                         const LHCb::MCHeader& mcheader,
+                         const LHCb::MCProperty& flags) const override; ///< Algorithm execution
   StatusCode finalize() override;                                         ///< Algorithm finalization
 
 protected:
@@ -104,58 +139,38 @@ private:
   Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
   Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
+  Gaudi::Property<int>    m_nTracksToPrint{this, "nTracksToPrint", 10.0};
+  Gaudi::Property<double> m_zToPrint{this, "zToPrint", 50.0 * Gaudi::Units::mm};
+  Gaudi::Property<int>    m_multiToPrint{this, "multiToPrint", 5.0};
+
   // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
+  mutable std::vector<Stats> m_stats;
+  mutable std::vector<Stats> m_stats_multi;
   mutable int m_nevt;
-  mutable int m_nMCPV, m_nRecMCPV;
-  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
-  mutable int m_nMCPV_close, m_nRecMCPV_close;
-  mutable int m_nFalsePV, m_nFalsePV_real;
-  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
-  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
-  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
-  mutable int m_nRecMCPV_wrong_1mult;
-  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
-  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
-  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
-  mutable int m_nRecMCPV_wrong_2mult;
-  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
-  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
-  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
-  mutable int m_nRecMCPV_wrong_3mult;
-  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
-  mutable int m_nBFalse, m_nRecBFalse;
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
                                                std::vector<MCPVInfo>::iterator& itmc ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                               const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( std::string mes, int a, int b );
+  void printRat(std::string mes, int rec, int mc, int fal, int notrec, int ntr);
+  void printRes(std::string mes, double x, double y, double z);
+
   //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
   //                                   std::string trackLoc ) const;
   int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
+  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
+  double check_histogram(const AIDA::IHistogram1D* h, bool var);
   //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
   //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
   //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
   //  mcps, const LHCb::LinksByKey& linker ) const;
 };
 
-bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
-
-namespace {
-  struct Beamline_t {
-    double X = std::numeric_limits<double>::signaling_NaN();
-    double Y = std::numeric_limits<double>::signaling_NaN();
-    Beamline_t( Condition const& c )
-        : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
-        , Y{c.param<double>( "ResolPosY" )} {}
-  };
-
-} // namespace
-
 // Declaration of the Algorithm Factory
 DECLARE_COMPONENT( PrimaryVertexChecker )
 
@@ -167,37 +182,30 @@ StatusCode PrimaryVertexChecker::initialize() {
   if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
 
   m_nevt                 = 0;
-  m_nMCPV                = 0;
-  m_nRecMCPV             = 0;
-  m_nMCPV_isol           = 0;
-  m_nRecMCPV_isol        = 0;
-  m_nMCPV_close          = 0;
-  m_nRecMCPV_close       = 0;
-  m_nFalsePV             = 0;
-  m_nFalsePV_real        = 0;
-  m_nMCPV_1mult          = 0;
-  m_nRecMCPV_1mult       = 0;
-  m_nMCPV_isol_1mult     = 0;
-  m_nRecMCPV_isol_1mult  = 0;
-  m_nMCPV_close_1mult    = 0;
-  m_nRecMCPV_close_1mult = 0;
-  m_nMCPV_2mult          = 0;
-  m_nRecMCPV_2mult       = 0;
-  m_nMCPV_isol_2mult     = 0;
-  m_nRecMCPV_isol_2mult  = 0;
-  m_nMCPV_close_2mult    = 0;
-  m_nRecMCPV_close_2mult = 0;
-  m_nMCPV_3mult          = 0;
-  m_nRecMCPV_3mult       = 0;
-  m_nMCPV_isol_3mult     = 0;
-  m_nRecMCPV_isol_3mult  = 0;
-  m_nMCPV_close_3mult    = 0;
-  m_nRecMCPV_close_3mult = 0;
-  // for L0 accepted PV of B signal
-  m_nL0PvOfB    = 0;
-  m_nRecL0PvOfB = 0;
-  m_nBFalse     = 0;
-  m_nRecBFalse  = 0;
+
+  for(const auto& n: categories)
+    {
+      Stats s;
+      s.name = n;
+      s.MCPV = 0;
+      s.RecPV = 0;
+      s.FalsePV = 0;
+      s.notRecPV = 0;
+      s.nTracks = 0;
+      m_stats.push_back(s);
+    }
+
+  for(auto i = 0; i<m_multiToPrint.value(); i++)
+    {
+      Stats s;
+      s.name = format("%d_%dMCPV",categories.size()+i+1,i+1);
+      s.MCPV = 0;
+      s.RecPV = 0;
+      s.FalsePV = 0;
+      s.notRecPV = 0;
+      s.nTracks = 0;
+      m_stats_multi.push_back(s);
+    }
 
   return StatusCode::SUCCESS;
 }
@@ -210,7 +218,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
                                        const LHCb::MCVertices&                        mcvtx,
                                        // const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader& mcheader ) const {
+                                       const LHCb::MCHeader& mcheader,
+                                       const LHCb::MCProperty& flags) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -278,7 +287,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     }
   }
 
-  count_reconstructible_mc_particles( mcpvvec );
+  count_reconstructible_mc_particles( mcpvvec, flags );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
 
@@ -290,7 +299,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
     rblemcpv.push_back( *itmc );
-    if ( itmc->nRecTracks < m_nTracksToBeRecble ) { nmrc++; }
+    if ( itmc->nRecTracks < m_nTracksToBeRecble ) { m_stats[0].notRecPV +=1; }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
@@ -327,8 +336,6 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   }
 
   // find nr of false PV
-
-  int nFalsePV      = 0;
   int nFalsePV_real = 0;
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) {
     int    fake   = 0;
@@ -343,10 +350,46 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     int    mother = recpvvec[ipv].mother;
     double chi2   = recpvvec[ipv].chi2;
     double nDoF   = recpvvec[ipv].nDoF;
+    m_stats[0].nTracks += recpvvec[ipv].nTracks;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
-      nFalsePV++;
+      m_stats[0].FalsePV += 1;
       fake           = 1;
+
+      std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
+      double                          dist = 999999.;
+      if ( cmc != rblemcpv.end() ) {
+          dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
+      }
+
+      if ( dist > m_dzIsolated ) {
+        m_stats[1].FalsePV += 1;
+      }
+      else {
+        m_stats[2].FalsePV += 1;
+      }
+
+      if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
+        m_stats[3].FalsePV += 1;
+      }
+      else {
+        m_stats[4].FalsePV += 1;
+      }
+
+      if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
+        m_stats[5].FalsePV += 1;
+      }
+      else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
+        m_stats[6].FalsePV += 1;
+      }
+      else {
+        m_stats[7].FalsePV += 1;
+      }
+
+      int idx = std::distance(rblemcpv.begin(), cmc);
+      if ( idx < m_multiToPrint ) {
+        m_stats_multi[idx].FalsePV +=1;
+      }
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -390,133 +433,81 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     itmcl->multClosestMCPV   = mult;
   }
 
-  // count non-reconstructible close and isolated PVs
-  int nmrc_isol  = 0;
-  int nmrc_close = 0;
-
-  // Counters
-  int nMCPV                = rblemcpv.size() - nmrc;
-  int nRecMCPV             = 0;
-  int nMCPV_isol           = 0;
-  int nRecMCPV_isol        = 0;
-  int nMCPV_close          = 0;
-  int nRecMCPV_close       = 0;
-  int nMCPV_1mult          = 0;
-  int nRecMCPV_1mult       = 0;
-  int nMCPV_isol_1mult     = 0;
-  int nRecMCPV_isol_1mult  = 0;
-  int nMCPV_close_1mult    = 0;
-  int nRecMCPV_close_1mult = 0;
-  int nRecMCPV_wrong_1mult = 0;
-  int nMCPV_2mult          = 0;
-  int nRecMCPV_2mult       = 0;
-  int nMCPV_isol_2mult     = 0;
-  int nRecMCPV_isol_2mult  = 0;
-  int nMCPV_close_2mult    = 0;
-  int nRecMCPV_close_2mult = 0;
-  int nRecMCPV_wrong_2mult = 0;
-  int nMCPV_3mult          = 0;
-  int nRecMCPV_3mult       = 0;
-  int nMCPV_isol_3mult     = 0;
-  int nRecMCPV_isol_3mult  = 0;
-  int nMCPV_close_3mult    = 0;
-  int nRecMCPV_close_3mult = 0;
-  int nRecMCPV_wrong_3mult = 0;
-
+  m_stats[0].MCPV            += rblemcpv.size();
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
-    if ( itmc->distToClosestMCPV > m_dzIsolated ) nMCPV_isol++;
-    if ( itmc->distToClosestMCPV > m_dzIsolated && itmc->nRecTracks < m_nTracksToBeRecble ) nmrc_isol++;
-    if ( itmc->distToClosestMCPV < m_dzIsolated ) nMCPV_close++;
-    if ( itmc->distToClosestMCPV < m_dzIsolated && itmc->nRecTracks < m_nTracksToBeRecble ) nmrc_close++;
 
-    if ( itmc->indexRecPVInfo > -1 ) {
-      nRecMCPV++;
-      if ( itmc->distToClosestMCPV > m_dzIsolated ) nRecMCPV_isol++;
-      if ( itmc->distToClosestMCPV < m_dzIsolated ) nRecMCPV_close++;
+    if ( itmc->distToClosestMCPV > m_dzIsolated ) {
+      m_stats[1].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
+        m_stats[1].notRecPV+=1;
+      }
     }
-  }
-
-  // rblemcpv is already sorted
-
-  // highest mult
-  if ( rblemcpv.size() > 0 ) {
-    nMCPV_1mult++;
-    double dist = rblemcpv[0].distToClosestMCPV;
-    if ( dist > m_dzIsolated ) nMCPV_isol_1mult++;
-    if ( dist < m_dzIsolated ) nMCPV_close_1mult++;
-    if ( rblemcpv[0].indexRecPVInfo > -1 ) {
-      nRecMCPV_1mult++;
-      if ( dist > m_dzIsolated ) nRecMCPV_isol_1mult++;
-      if ( dist < m_dzIsolated ) nRecMCPV_close_1mult++;
-    } else {
-      nRecMCPV_wrong_1mult++;
+    else {
+      m_stats[2].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
+        m_stats[2].notRecPV+=1;
+      }
     }
-  }
 
-  // second highest
-  if ( rblemcpv.size() > 1 ) {
-    nMCPV_2mult++;
-    double dist = rblemcpv[1].distToClosestMCPV;
-    if ( dist > m_dzIsolated ) nMCPV_isol_2mult++;
-    if ( dist < m_dzIsolated ) nMCPV_close_2mult++;
-    if ( rblemcpv[1].indexRecPVInfo > -1 ) {
-      nRecMCPV_2mult++;
-      if ( dist > m_dzIsolated ) nRecMCPV_isol_2mult++;
-      if ( dist < m_dzIsolated ) nRecMCPV_close_2mult++;
-    } else {
-      nRecMCPV_wrong_2mult++;
+    if ( itmc->nRecTracks >= m_nTracksToBeRecble && itmc->nRecTracks < m_nTracksToPrint ) m_stats[3].MCPV+=1;
+    if ( itmc->nRecTracks >= m_nTracksToPrint ) m_stats[4].MCPV+=1;
+
+    if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
+      m_stats[5].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble) {
+        m_stats[5].notRecPV+=1;
+      }
     }
-  }
-  // third highest
-  if ( rblemcpv.size() > 2 ) {
-    nMCPV_3mult++;
-    double dist = rblemcpv[2].distToClosestMCPV;
-    if ( dist > m_dzIsolated ) nMCPV_isol_3mult++;
-    if ( dist < m_dzIsolated ) nMCPV_close_3mult++;
-    if ( rblemcpv[2].indexRecPVInfo > -1 ) {
-      nRecMCPV_3mult++;
-      if ( dist > m_dzIsolated ) nRecMCPV_isol_3mult++;
-      if ( dist < m_dzIsolated ) nRecMCPV_close_3mult++;
-    } else {
-      nRecMCPV_wrong_3mult++;
+    else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
+      m_stats[6].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble) {
+        m_stats[6].notRecPV+=1;
+      }
+    }
+    else {
+      m_stats[7].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble) {
+        m_stats[7].notRecPV+=1;
+      }
     }
-  }
 
-  nMCPV_isol  = nMCPV_isol - nmrc_isol;
-  nMCPV_close = nMCPV_close - nmrc_close;
-
-  m_nMCPV += nMCPV;
-  m_nRecMCPV += nRecMCPV;
-  m_nMCPV_isol += nMCPV_isol;
-  m_nRecMCPV_isol += nRecMCPV_isol;
-  m_nMCPV_close += nMCPV_close;
-  m_nRecMCPV_close += nRecMCPV_close;
-  m_nFalsePV += nFalsePV;
-  m_nFalsePV_real += nFalsePV_real;
-  m_nMCPV_1mult += nMCPV_1mult;
-  m_nRecMCPV_1mult += nRecMCPV_1mult;
-  m_nMCPV_isol_1mult += nMCPV_isol_1mult;
-  m_nRecMCPV_isol_1mult += nRecMCPV_isol_1mult;
-  m_nMCPV_close_1mult += nMCPV_close_1mult;
-  m_nRecMCPV_close_1mult += nRecMCPV_close_1mult;
-  m_nRecMCPV_wrong_1mult += nRecMCPV_wrong_1mult;
-  m_nMCPV_2mult += nMCPV_2mult;
-  m_nRecMCPV_2mult += nRecMCPV_2mult;
-  m_nMCPV_isol_2mult += nMCPV_isol_2mult;
-  m_nRecMCPV_isol_2mult += nRecMCPV_isol_2mult;
-  m_nMCPV_close_2mult += nMCPV_close_2mult;
-  m_nRecMCPV_wrong_2mult += nRecMCPV_wrong_2mult;
-  m_nRecMCPV_close_2mult += nRecMCPV_close_2mult;
-  m_nMCPV_3mult += nMCPV_3mult;
-  m_nRecMCPV_3mult += nRecMCPV_3mult;
-  m_nMCPV_isol_3mult += nMCPV_isol_3mult;
-  m_nRecMCPV_isol_3mult += nRecMCPV_isol_3mult;
-  m_nMCPV_close_3mult += nMCPV_close_3mult;
-  m_nRecMCPV_close_3mult += nRecMCPV_close_3mult;
-  m_nRecMCPV_wrong_3mult += nRecMCPV_wrong_3mult;
+    if ( itmc->indexRecPVInfo > -1 ) {
+      m_stats[0].RecPV+=1;
+      if ( itmc->distToClosestMCPV > m_dzIsolated ) {
+        m_stats[1].RecPV+=1;
+        m_stats[1].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else {
+        m_stats[2].RecPV+=1;
+        m_stats[2].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
 
-  int high = 0;
+      if ( itmc->nRecTracks >= m_nTracksToPrint ) {
+        m_stats[4].RecPV+=1;
+        m_stats[4].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else {
+        m_stats[3].RecPV+=1;
+        m_stats[3].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+
+      if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
+        m_stats[5].RecPV+=1;
+        m_stats[5].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else if ( itmc->pMCPV->position().z() < m_zToPrint ){
+        m_stats[6].RecPV+=1;
+        m_stats[6].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else {
+        m_stats[7].RecPV+=1;
+        m_stats[7].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+    }
+  }
 
+  int mcpv = 0;
+  int high = 0;
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
     double x             = -99999.;
     double y             = -99999.;
@@ -550,6 +541,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     xMC = itmc->pMCPV->position().x();
     rMC = std::sqrt( ( xMC - m_beamSpotX ) * ( xMC - m_beamSpotX ) + ( yMC - m_beamSpotY ) * ( yMC - m_beamSpotY ) );
 
+    if ( mcpv < m_multiToPrint )
+      {
+        m_stats_multi[mcpv].MCPV += 1;
+        if (itmc->nRecTracks < m_nTracksToBeRecble) { m_stats_multi[mcpv].notRecPV+=1;}
+      }
+
     if ( indRec > -1 ) {
       high++;
       pvevt++;
@@ -573,6 +570,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       chi2          = recpvvec[indRec].chi2;
       nDoF          = recpvvec[indRec].nDoF;
 
+      if ( mcpv < m_multiToPrint )
+        {
+          m_stats_multi[mcpv].RecPV += 1;
+          m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
+        }
       // Filling histograms
       if ( m_produceHistogram ) {
         plot( itmc->pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
@@ -587,6 +589,38 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         plot( dx / errx, 1031, "pullx", -5., 5., 50 );
         plot( dy / erry, 1032, "pully", -5., 5., 50 );
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
+        if ( itmc->nRecTracks < 10){
+          plot( dx, 1101, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1102, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1103, "dz", -0.5, 0.5, 50 );
+        }
+        else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30){
+          plot( dx, 1111, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1112, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1113, "dz", -0.5, 0.5, 50 );
+        }
+        else{
+          plot( dx, 1121, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1122, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1123, "dz", -0.5, 0.5, 50 );
+        }
+
+        if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
+          plot( dx, 1201, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1202, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1203, "dz", -0.5, 0.5, 50 );
+        }
+        else if ( itmc->pMCPV->position().z() < m_zToPrint )    {
+          plot( dx, 1211, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1212, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1213, "dz", -0.5, 0.5, 50 );
+        }
+        else {
+          plot( dx, 1221, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1222, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1223, "dz", -0.5, 0.5, 50 );
+        }
+
         plot( double( ntracks_pvrec ), 1041, "ntracks_pvrec", 0., 150., 50 );
         plot( double( dtrcks ), 1042, "mcrdtracks", 0., 150., 50 );
         if ( pvevt == 1 ) {
@@ -599,6 +633,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         }
       }
     }
+    mcpv++;
 
     int    isolated     = 0;
     double dist_closest = itmc->distToClosestMCPV;
@@ -711,7 +746,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
                                                                    std::vector<MCPVInfo>::iterator& itmc ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
-  double                          mindist = 999999.;
+  double                        mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
@@ -726,6 +761,24 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
+std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                                                   const RecPVInfo& rec ) const {
+
+  std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
+  double                        mindist = 999999.;
+  if ( rblemcpv.size() < 2 ) return itret;
+  std::vector<MCPVInfo>::iterator it;
+  for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
+      double dist = ( it->pMCPV->position() - rec.pRECPV->position() ).R();
+      if ( dist < mindist ) {
+        mindist = dist;
+        itret   = it;
+      }
+  }
+  return itret;
+}
+
+
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
                                              std::vector<LHCb::MCParticle*>& allprods ) const {
 
@@ -749,120 +802,85 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
 
-  info() << " ============================================" << endmsg;
-  info() << " Efficiencies for reconstructible MC vertices: " << endmsg;
-  info() << " ============================================" << endmsg;
+  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed" << endmsg;
+  info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
+  info() << " MC efficiency split by tracks with threshold: ("<< m_nTracksToBeRecble.value()<<","<<m_nTracksToPrint.value()<<"), >= "<<m_nTracksToPrint.value()<<endmsg;
+  info() << " MC efficiency split by z position: <-"<<m_zToPrint.value()<<", (-"<<m_zToPrint.value()<<","<<m_zToPrint.value()<<"), >"<<m_zToPrint.value()<< endmsg;
+  std::string ff = "by distance";
+  info() << " REC and MC vertices matched:  " << ff << endmsg;
+
   info() << " " << endmsg;
 
-  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble << "  tracks are reconstructed" << endmsg;
-  info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated << " mm" << endmsg;
-  std::string ff = "by dz distance";
-  info() << " REC and MC vertices matched:  " << ff << endmsg;
+  for (auto& mstat : m_stats)
+    {
+      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+    }
+  for (auto& mstat : m_stats_multi)
+    {
+      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+    }
+  info() << " " << endmsg;
+
+  printRes("1_res_all",                check_histogram(histo( HistoID( 1021 ) ),true), check_histogram(histo( HistoID( 1022 ) ), true), check_histogram(histo( HistoID( 1023 ) ),true));
+
+  printRes("2_res_ntracks<10",     check_histogram(histo( HistoID( 1101 ) ),true), check_histogram(histo( HistoID( 1102 ) ), true), check_histogram(histo( HistoID( 1103 ) ),true));
+  printRes("3_res_ntracks(10,30)", check_histogram(histo( HistoID( 1111 ) ),true), check_histogram(histo( HistoID( 1112 ) ), true), check_histogram(histo( HistoID( 1113 ) ),true));
+  printRes("4_res_ntracks>30",     check_histogram(histo( HistoID( 1121 ) ),true), check_histogram(histo( HistoID( 1122 ) ), true), check_histogram(histo( HistoID( 1123 ) ),true));
+
+  printRes("5_res_z<-50",     check_histogram(histo( HistoID( 1201 ) ),true), check_histogram(histo( HistoID( 1202 ) ),true), check_histogram(histo( HistoID( 1203 ) ),true));
+  printRes("6_res_z(-50,50)", check_histogram(histo( HistoID( 1211 ) ),true), check_histogram(histo( HistoID( 1212 ) ),true), check_histogram(histo( HistoID( 1213 ) ),true));
+  printRes("7_res_z>50",      check_histogram(histo( HistoID( 1221 ) ),true), check_histogram(histo( HistoID( 1222 ) ),true), check_histogram(histo( HistoID( 1223 ) ),true));
 
   info() << " " << endmsg;
 
-  printRat( "All", m_nRecMCPV, m_nMCPV );
-  printRat( "Isolated", m_nRecMCPV_isol, m_nMCPV_isol );
-  printRat( "Close", m_nRecMCPV_close, m_nMCPV_close );
-  printRat( "False rate", m_nFalsePV, m_nRecMCPV + m_nFalsePV );
-
-  if ( debugLevel() ) { printRat( "Real false rate", m_nFalsePV_real, m_nRecMCPV + m_nFalsePV_real ); }
-
-  info() << endmsg;
-  printRat( "L0 accepted PV of B", m_nRecL0PvOfB, m_nL0PvOfB );
-  printRat( "False PV as B", m_nRecBFalse, m_nBFalse );
-  info() << endmsg;
-
-  info() << "      --------------------------------------------" << endmsg;
-  info() << "           Substatistics: " << endmsg;
-  info() << "      --------------------------------------------" << endmsg;
-  info() << "      1st PV (highest multiplicity): " << endmsg;
-  printRat( "All", m_nRecMCPV_1mult, m_nMCPV_1mult );
-  printRat( "Isolated", m_nRecMCPV_isol_1mult, m_nMCPV_isol_1mult );
-  printRat( "Close", m_nRecMCPV_close_1mult, m_nMCPV_close_1mult );
-
-  info() << "      ---------------------------------------" << endmsg;
-  info() << "      2nd PV: " << endmsg;
-  printRat( "All", m_nRecMCPV_2mult, m_nMCPV_2mult );
-  printRat( "Isolated", m_nRecMCPV_isol_2mult, m_nMCPV_isol_2mult );
-  printRat( "Close", m_nRecMCPV_close_2mult, m_nMCPV_close_2mult );
-
-  info() << "      ---------------------------------------" << endmsg;
-  info() << "      3rd PV: " << endmsg;
-  printRat( "All", m_nRecMCPV_3mult, m_nMCPV_3mult );
-  printRat( "Isolated", m_nRecMCPV_isol_3mult, m_nMCPV_isol_3mult );
-  printRat( "Close", m_nRecMCPV_close_3mult, m_nMCPV_close_3mult );
+  printRes("1_pull_width_all",  check_histogram(histo( HistoID( 1031 ) ),true), check_histogram(histo( HistoID( 1032 ) ),true), check_histogram(histo( HistoID( 1033 ) ),true));
+  printRes("1_pull_mean_all",   check_histogram(histo( HistoID( 1031 ) ),false), check_histogram(histo( HistoID( 1032 ) ),false), check_histogram(histo( HistoID( 1033 ) ),false));
 
   info() << " " << endmsg;
-  if ( debugLevel() ) {
-    info() << " * Real false rate means: no visible MC PV within 5 sigma of REC PV."
-           << " Visible MC PV: 2 tracks reconstructed" << endmsg;
-    info() << " " << endmsg;
-  }
-  const AIDA::IHistogram1D* dx    = histo( HistoID( 1021 ) );
-  const AIDA::IHistogram1D* pullx = histo( HistoID( 1031 ) );
-  const AIDA::IHistogram1D* dy    = histo( HistoID( 1022 ) );
-  const AIDA::IHistogram1D* pully = histo( HistoID( 1032 ) );
-  const AIDA::IHistogram1D* dz    = histo( HistoID( 1023 ) );
-  const AIDA::IHistogram1D* pullz = histo( HistoID( 1033 ) );
-  if ( dx ) {
-    info() << "      ---------------------------------------" << endmsg;
-    info() << "dx:    "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", dx->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( dx ), dx->rms(), Gaudi::Utils::HistoStats::rmsErr( dx ) )
-           << endmsg;
-  }
-  if ( dy ) {
-    info() << "dy:    "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", dy->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( dy ), dy->rms(), Gaudi::Utils::HistoStats::rmsErr( dy ) )
-           << endmsg;
-  }
-  if ( dz ) {
-    info() << "dz:    "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", dz->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( dz ), dz->rms(), Gaudi::Utils::HistoStats::rmsErr( dz ) )
-           << endmsg;
-  }
-  info() << "      ---------------------------------------" << endmsg;
-  if ( pullx ) {
-    info() << "pullx: "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", pullx->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( pullx ), pullx->rms(),
-                      Gaudi::Utils::HistoStats::rmsErr( pullx ) )
-           << endmsg;
-  }
-  if ( pully ) {
-    info() << "pully: "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", pully->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( pully ), pully->rms(),
-                      Gaudi::Utils::HistoStats::rmsErr( pully ) )
-           << endmsg;
-  }
-  if ( pullz ) {
-    info() << "pullz: "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", pullz->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( pullz ), pullz->rms(),
-                      Gaudi::Utils::HistoStats::rmsErr( pullz ) )
-           << endmsg;
-  }
-  info() << " ============================================" << endmsg;
 
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
+void PrimaryVertexChecker::printRat( std::string mes, int rec, int mc, int fal, int notrec, int ntr ) {
 
   double rat = 0.;
-  if ( b > 0 ) rat = 1.0 * a / b;
-
+  double fl = 0.;
+  double all_rec = rec+fal;
+  double av_tr = 0.;
+  if ( (mc-notrec) > 0 ) rat = 100.0 * rec / (mc-notrec);
+  if ( all_rec > 0 ) fl = 100.0 * fal / all_rec;
+  if ( rec > 0 ) av_tr = 1.0*ntr/rec;
   // reformat message
+  unsigned int len  = 15;
+  std::string  pmes = mes;
+  while ( pmes.length() < len ) { pmes += " "; }
+  pmes += " : ";
+
+  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reconstructed %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f",
+                            rec, mc, rat, fal, rec+fal, fl, notrec, av_tr) << endmsg;
+}
+
+void PrimaryVertexChecker::printRes(std::string mes, double x, double y, double z){
   unsigned int len  = 20;
   std::string  pmes = mes;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
+  info() << pmes << format(" x: %+5.3f, y: %+5.3f, z: %+5.3f",
+                           x, y, z) << endmsg;
+}
 
-  info() << pmes << format( " %6.3f ( %7d / %8d )", rat, a, b ) << endmsg;
+double PrimaryVertexChecker::check_histogram(const AIDA::IHistogram1D* h, bool rms) {
+  if ( h ) {
+    if ( rms ) {
+      return h->rms();
+    }
+    else {
+      return h->mean();
+    }
+  }
+  else {
+    return 0.;
+  }
 }
 
 // void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
@@ -915,9 +933,9 @@ int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::
   return nVeloTracks;
 }
 
-void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const {
+void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const {
 
-  const MCTrackInfo               trInfo = make_MCTrackInfo( eventSvc(), msgSvc() );
+  const MCTrackInfo               trInfo = {flags};
   std::vector<MCPVInfo>::iterator itinfomc;
   for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
     LHCb::MCVertex*                  avtx = itinfomc->pMCPV;
@@ -989,4 +1007,3 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
 //  }
 //  return motherPart;
 //}
-
-- 
GitLab


From 86377a71e6d4b1de7e43c30c66e5ddfc55bfff13 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton>
Date: Tue, 4 Feb 2020 12:25:47 +0100
Subject: [PATCH 06/42] refactoring

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 357 ++++++++++++---------
 1 file changed, 204 insertions(+), 153 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 9ca9e9dc103..bbdb2d502ea 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -44,17 +44,18 @@
 namespace {
 
   struct MCPVInfo{
-  LHCb::MCVertex*                pMCPV;             // pointer to MC PV
-  int                            nRecTracks;        // number of reconstructed tracks from this MCPV
-  int                            nRecBackTracks;    // number of reconstructed backward tracks
-  int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
-  int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
-  int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
-  double                         distToClosestMCPV; // distance to closest reconstructible MCPV
-  int                            decayCharm;        // type of mother particle
-  int                            decayBeauty;
-  std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
-  std::vector<LHCb::Track*>      m_recTracksInMCPV;
+    LHCb::MCVertex*                pMCPV;             // pointer to MC PV
+    int                            nRecTracks;        // number of reconstructed tracks from this MCPV
+    int                            nRecBackTracks;    // number of reconstructed backward tracks
+    int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
+    int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
+    int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
+    double                         distToClosestMCPV; // distance to closest reconstructible MCPV
+    bool                           decayCharm;        // type of mother particle
+    bool                           decayBeauty;
+    bool                           decayStrange;
+    std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
+    std::vector<LHCb::Track*>      m_recTracksInMCPV;
 };
 
   struct RecPVInfo{
@@ -72,8 +73,6 @@ namespace {
 
   inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
 
-  inline const std::vector<std::string> categories = {"1_all","2_isol","3_close","4_ntracks<X","5_ntracks>=X","6_z<-X","7_zIn(-X,X)","8_z>X"};
-
   struct Beamline_t {
     double X = std::numeric_limits<double>::signaling_NaN();
     double Y = std::numeric_limits<double>::signaling_NaN();
@@ -91,16 +90,34 @@ namespace {
     int FalsePV;
     int notRecPV;
     int nTracks;
+    int nMCPart;
+  };
+
+  enum class recoAs{
+      all,
+      isolated, close,
+      ntracks_low, ntracks_high,
+      z_low, z_middle, z_high,
+      beauty, charm, strange, other
   };
+  static const recoAs All[] = { recoAs::all,
+                                recoAs::isolated, recoAs::close,
+                                recoAs::ntracks_low, recoAs::ntracks_high,
+                                recoAs::z_low, recoAs::z_middle, recoAs::z_high,
+                                recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+  static const recoAs part[] = { recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+
+  static constexpr int size_recAs = int(recoAs::other) + 1;
+
 }
 
 
 class PrimaryVertexChecker
     : public Gaudi::Functional::Consumer<
           void( const LHCb::Tracks&,
-                std::vector<LHCb::Event::v2::RecVertex> const& vertices, // const LHCb::RecVertices&,
+                std::vector<LHCb::Event::v2::RecVertex> const&,
                 const LHCb::MCVertices&,
-                // const LHCb::MCParticles&,
+                const LHCb::MCParticles&,
                 // const LHCb::LinksByKey&,
                 const LHCb::MCHeader&,
                 const LHCb::MCProperty&),
@@ -110,24 +127,23 @@ public:
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
       : Consumer{ name,
                   pSvcLocator,
-                  {KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                  KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-                  //                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                    KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
-                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
-                    KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
+                  {KeyValue{"inputTracksName",   LHCb::TrackLocation::Default},
+                   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                   KeyValue{"MCVertexInput",     LHCb::MCVertexLocation::Default},
+                   KeyValue{"MCParticleInput",   LHCb::MCParticleLocation::Default},
+                   KeyValue{"MCHeaderLocation",  LHCb::MCHeaderLocation::Default},
+                   KeyValue{"MCPropertyInput",   LHCb::MCPropertyLocation::TrackInfo},
                   //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-
                       }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
   void       operator()( const LHCb::Tracks& tracks,
-                   // const LHCb::RecVertices& recoVtx,
-                   std::vector<LHCb::Event::v2::RecVertex> const& vertices, const LHCb::MCVertices& mcvtx,
-                   // const LHCb::MCParticles& mcps,
+                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
+                         const LHCb::MCVertices&                        mcvtx,
+                         const LHCb::MCParticles&                       mcps,
                    // const LHCb::LinksByKey& linker,
-                         const LHCb::MCHeader& mcheader,
-                         const LHCb::MCProperty& flags) const override; ///< Algorithm execution
+                         const LHCb::MCHeader&                          mcheader,
+                         const LHCb::MCProperty&                        flags) const override; ///< Algorithm execution
   StatusCode finalize() override;                                         ///< Algorithm finalization
 
 protected:
@@ -145,7 +161,7 @@ private:
 
   // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
-  mutable std::vector<Stats> m_stats;
+  mutable std::map<recoAs, Stats> m_stats;
   mutable std::vector<Stats> m_stats_multi;
   mutable int m_nevt;
 
@@ -155,8 +171,10 @@ private:
                                                const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat(std::string mes, int rec, int mc, int fal, int notrec, int ntr);
+  void printRat(const std::string name, const Stats& stat);
   void printRes(std::string mes, double x, double y, double z);
+  std::string toString( const recoAs& n) const;
+  bool checkCondition(const MCPVInfo& MCPV, const recoAs& n) const;
 
   //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
@@ -183,27 +201,28 @@ StatusCode PrimaryVertexChecker::initialize() {
 
   m_nevt                 = 0;
 
-  for(const auto& n: categories)
+  for(const auto& n: All)
     {
       Stats s;
-      s.name = n;
       s.MCPV = 0;
       s.RecPV = 0;
       s.FalsePV = 0;
       s.notRecPV = 0;
       s.nTracks = 0;
-      m_stats.push_back(s);
+      s.nMCPart = 0;
+      m_stats[n];
     }
 
   for(auto i = 0; i<m_multiToPrint.value(); i++)
     {
       Stats s;
-      s.name = format("%d_%dMCPV",categories.size()+i+1,i+1);
+      s.name = format("%d_%dMCPV",size_recAs+i+1,i+1);
       s.MCPV = 0;
       s.RecPV = 0;
       s.FalsePV = 0;
       s.notRecPV = 0;
       s.nTracks = 0;
+      s.nMCPart = 0;
       m_stats_multi.push_back(s);
     }
 
@@ -216,10 +235,10 @@ StatusCode PrimaryVertexChecker::initialize() {
 void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
                                        std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
                                        const LHCb::MCVertices&                        mcvtx,
-                                       // const LHCb::MCParticles& mcps,
+                                       const LHCb::MCParticles&                       mcps,
                                        // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader& mcheader,
-                                       const LHCb::MCProperty& flags) const {
+                                       const LHCb::MCHeader&                          mcheader,
+                                       const LHCb::MCProperty&                        flags) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -278,8 +297,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         mcprimvert.nCorrectTracks    = 0;
         mcprimvert.multClosestMCPV   = 0;
         mcprimvert.distToClosestMCPV = 999999.;
-        mcprimvert.decayBeauty       = 0;
-        mcprimvert.decayCharm        = 0;
+        mcprimvert.decayBeauty       = false;
+        mcprimvert.decayCharm        = false;
+        mcprimvert.decayStrange      = false;
         mcprimvert.m_mcPartInMCPV.clear();
         mcprimvert.m_recTracksInMCPV.clear();
         mcpvvec.push_back( mcprimvert );
@@ -299,7 +319,6 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
     rblemcpv.push_back( *itmc );
-    if ( itmc->nRecTracks < m_nTracksToBeRecble ) { m_stats[0].notRecPV +=1; }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
@@ -350,46 +369,53 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     int    mother = recpvvec[ipv].mother;
     double chi2   = recpvvec[ipv].chi2;
     double nDoF   = recpvvec[ipv].nDoF;
-    m_stats[0].nTracks += recpvvec[ipv].nTracks;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
-      m_stats[0].FalsePV += 1;
       fake           = 1;
-
       std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
-      if ( cmc != rblemcpv.end() ) {
+
+      if ( cmc != rblemcpv.end() )
+        {
           dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
-      }
 
-      if ( dist > m_dzIsolated ) {
-        m_stats[1].FalsePV += 1;
-      }
-      else {
-        m_stats[2].FalsePV += 1;
-      }
+          for(const auto& n: part)
+            {
+              bool cut = false;
+              cut = checkCondition(*cmc,n);
+              if ( cut ) {
+                m_stats[n].FalsePV += 1;
+              }
+            }
+          if ( dist > m_dzIsolated ) {
+            m_stats[recoAs::isolated].FalsePV += 1;
+          }
+          else {
+            m_stats[recoAs::close].FalsePV += 1;
+          }
+          if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
+            m_stats[recoAs::ntracks_high].FalsePV += 1;
+          }
+          else {
+            m_stats[recoAs::ntracks_low].FalsePV += 1;
+          }
 
-      if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
-        m_stats[3].FalsePV += 1;
-      }
-      else {
-        m_stats[4].FalsePV += 1;
-      }
+          if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
+            m_stats[recoAs::z_low].FalsePV += 1;
+          }
+          else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
+            m_stats[recoAs::z_middle].FalsePV += 1;
+          }
+          else {
+            m_stats[recoAs::z_high].FalsePV += 1;
+          }
 
-      if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
-        m_stats[5].FalsePV += 1;
-      }
-      else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
-        m_stats[6].FalsePV += 1;
-      }
-      else {
-        m_stats[7].FalsePV += 1;
-      }
+          int idx = std::distance(rblemcpv.begin(), cmc);
+          if ( idx < m_multiToPrint ) {
+            m_stats_multi[idx].FalsePV +=1;
+          }
+        }
 
-      int idx = std::distance(rblemcpv.begin(), cmc);
-      if ( idx < m_multiToPrint ) {
-        m_stats_multi[idx].FalsePV +=1;
-      }
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -433,77 +459,26 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     itmcl->multClosestMCPV   = mult;
   }
 
-  m_stats[0].MCPV            += rblemcpv.size();
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
 
-    if ( itmc->distToClosestMCPV > m_dzIsolated ) {
-      m_stats[1].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
-        m_stats[1].notRecPV+=1;
-      }
-    }
-    else {
-      m_stats[2].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
-        m_stats[2].notRecPV+=1;
-      }
-    }
-
-    if ( itmc->nRecTracks >= m_nTracksToBeRecble && itmc->nRecTracks < m_nTracksToPrint ) m_stats[3].MCPV+=1;
-    if ( itmc->nRecTracks >= m_nTracksToPrint ) m_stats[4].MCPV+=1;
-
-    if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
-      m_stats[5].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble) {
-        m_stats[5].notRecPV+=1;
-      }
-    }
-    else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
-      m_stats[6].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble) {
-        m_stats[6].notRecPV+=1;
-      }
-    }
-    else {
-      m_stats[7].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble) {
-        m_stats[7].notRecPV+=1;
-      }
-    }
-
-    if ( itmc->indexRecPVInfo > -1 ) {
-      m_stats[0].RecPV+=1;
-      if ( itmc->distToClosestMCPV > m_dzIsolated ) {
-        m_stats[1].RecPV+=1;
-        m_stats[1].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else {
-        m_stats[2].RecPV+=1;
-        m_stats[2].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-
-      if ( itmc->nRecTracks >= m_nTracksToPrint ) {
-        m_stats[4].RecPV+=1;
-        m_stats[4].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else {
-        m_stats[3].RecPV+=1;
-        m_stats[3].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-
-      if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
-        m_stats[5].RecPV+=1;
-        m_stats[5].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else if ( itmc->pMCPV->position().z() < m_zToPrint ){
-        m_stats[6].RecPV+=1;
-        m_stats[6].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else {
-        m_stats[7].RecPV+=1;
-        m_stats[7].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+    for(const auto& n: All)
+      {
+        bool cut = false;
+        cut = checkCondition(*itmc,n);
+        if ( cut ) {
+            m_stats[n].MCPV+=1;
+            if (itmc->nRecTracks < m_nTracksToBeRecble ) {
+              m_stats[n].notRecPV+=1;
+            }
+            else {
+              m_stats[n].nMCPart += itmc->nRecTracks;
+            }
+            if ( itmc->indexRecPVInfo > -1 ) {
+              m_stats[n].RecPV+=1;
+              m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+            }
+        }
       }
-    }
   }
 
   int mcpv = 0;
@@ -544,7 +519,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     if ( mcpv < m_multiToPrint )
       {
         m_stats_multi[mcpv].MCPV += 1;
-        if (itmc->nRecTracks < m_nTracksToBeRecble) { m_stats_multi[mcpv].notRecPV+=1;}
+        if (itmc->nRecTracks < m_nTracksToBeRecble) {
+          m_stats_multi[mcpv].notRecPV+=1;
+        }
+        else {
+          m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
+        }
       }
 
     if ( indRec > -1 ) {
@@ -653,6 +633,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       myTuple->column( "nrecpv", double( recpvvec.size() ) );
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
       myTuple->column( "decayBeauty", double( itmc->decayBeauty ) );
+      myTuple->column( "decayStrange", double( itmc->decayStrange ) );
       myTuple->column( "multi", double( high ) );
       myTuple->column( "dx", dx );
       myTuple->column( "dy", dy );
@@ -676,7 +657,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       myTuple->column( "chi2", double( chi2 ) );
       myTuple->column( "nDoF", double( nDoF ) );
       myTuple->column( "size_tracks", double( tracks.size() ) );
-      // myTuple->column( "size_mcp", double( sMCP ) );
+      myTuple->column( "size_mcp", double( mcps.size() ) );
       myTuple->column( "mcpvrec", double( nmrc ) );
       myTuple->write();
     }
@@ -802,6 +783,9 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
 
+  //categories category = all;
+  //info() << " CATEGORY TEST = " << category << endmsg;
+
   info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed" << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
   info() << " MC efficiency split by tracks with threshold: ("<< m_nTracksToBeRecble.value()<<","<<m_nTracksToPrint.value()<<"), >= "<<m_nTracksToPrint.value()<<endmsg;
@@ -811,13 +795,15 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   info() << " " << endmsg;
 
-  for (auto& mstat : m_stats)
+
+  for (const auto& n: All)
     {
-      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+      printRat(toString(n), m_stats[n] );
     }
+
   for (auto& mstat : m_stats_multi)
     {
-      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+      printRat( mstat.name, mstat );
     }
   info() << " " << endmsg;
 
@@ -841,23 +827,28 @@ StatusCode PrimaryVertexChecker::finalize() {
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( std::string mes, int rec, int mc, int fal, int notrec, int ntr ) {
+void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat ) {
 
   double rat = 0.;
   double fl = 0.;
-  double all_rec = rec+fal;
+  int all_rec = stat.RecPV+stat.FalsePV;
   double av_tr = 0.;
-  if ( (mc-notrec) > 0 ) rat = 100.0 * rec / (mc-notrec);
-  if ( all_rec > 0 ) fl = 100.0 * fal / all_rec;
-  if ( rec > 0 ) av_tr = 1.0*ntr/rec;
+  double av_par = 0.;
+  if ( (stat.MCPV-stat.notRecPV) > 0 ) {
+    rat = 100.0 * stat.RecPV / (stat.MCPV-stat.notRecPV);
+    av_par = 1.0*stat.nMCPart/(stat.MCPV-stat.notRecPV);
+  }
+  if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
+  if ( stat.RecPV > 0 ) av_tr = 1.0*stat.nTracks/stat.RecPV;
+
   // reformat message
-  unsigned int len  = 15;
-  std::string  pmes = mes;
+  unsigned int len  = 25;
+  std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
-  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reconstructed %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f",
-                            rec, mc, rat, fal, rec+fal, fl, notrec, av_tr) << endmsg;
+  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f [MC: %6.2f]",
+                            stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par) << endmsg;
 }
 
 void PrimaryVertexChecker::printRes(std::string mes, double x, double y, double z){
@@ -951,8 +942,9 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
 
       if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
-        if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = 1.0; }
-        if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = 1.0; }
+        if ( pmcp->particleID().hasBottom() )  { itinfomc->decayBeauty  = true; }
+        if ( pmcp->particleID().hasCharm() )   { itinfomc->decayCharm   = true; }
+        if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
         if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
           double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
@@ -964,6 +956,65 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
   }
 }
 
+bool  PrimaryVertexChecker::checkCondition( const  MCPVInfo& MCPV, const recoAs& n) const{
+  switch (n) {
+  case recoAs::all:
+    return true;
+  case recoAs::isolated:
+    return (MCPV.distToClosestMCPV > m_dzIsolated);
+  case recoAs::close:
+    return (MCPV.distToClosestMCPV <= m_dzIsolated);
+  case recoAs::ntracks_low:
+    return (MCPV.nRecTracks >= m_nTracksToBeRecble && MCPV.nRecTracks < m_nTracksToPrint );
+  case recoAs::ntracks_high:
+    return (MCPV.nRecTracks >= m_nTracksToPrint );
+  case recoAs::z_low:
+    return (MCPV.pMCPV->position().z() < -m_zToPrint );
+  case recoAs::z_middle:
+    return (MCPV.pMCPV->position().z() >= -m_zToPrint && MCPV.pMCPV->position().z() < m_zToPrint);
+  case recoAs::z_high:
+    return (MCPV.pMCPV->position().z() >= m_zToPrint);
+  case recoAs::beauty:
+    return (MCPV.decayBeauty);
+  case recoAs::charm:
+    return (MCPV.decayCharm);
+  case recoAs::strange:
+    return (MCPV.decayStrange);
+  case recoAs::other:
+    return ( !(MCPV.decayBeauty) && !(MCPV.decayCharm) && !(MCPV.decayStrange) );
+  default: return false;
+  }
+}
+
+std::string PrimaryVertexChecker::toString( const recoAs& n) const{
+  switch (n) {
+  case recoAs::all:
+    return format("0%d all",int(recoAs::all));
+  case recoAs::isolated:
+    return format("0%d isolated",int(recoAs::isolated));
+  case recoAs::close:
+    return format("0%d close",int(recoAs::close));
+  case recoAs::ntracks_low:
+    return format("0%d ntracks<%d",int(recoAs::ntracks_low),int(m_nTracksToPrint));
+  case recoAs::ntracks_high:
+    return format("0%d ntracks>=%d",int(recoAs::ntracks_high),int(m_nTracksToPrint));
+  case recoAs::z_low:
+    return format("0%d z<%2.1f",int(recoAs::z_low),-m_zToPrint);
+  case recoAs::z_middle:
+    return format("0%d z in (%2.1f, %2.1f)",int(recoAs::z_middle), -m_zToPrint, +m_zToPrint);
+  case recoAs::z_high:
+    return format("0%d z >=%2.1f",int(recoAs::z_high), +m_zToPrint);
+  case recoAs::beauty:
+    return format("0%d beauty",int(recoAs::beauty));
+  case recoAs::charm:
+    return format("0%d charm",int(recoAs::charm));
+  case recoAs::strange:
+    return format("%d strange",int(recoAs::strange));
+  case recoAs::other:
+    return format("%d other",int(recoAs::other));
+  default: return "not defined";
+  }
+}
 // int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
 //                                                 const LHCb::MCParticles& mcps,
 //                                                 const LHCb::LinksByKey& linker  ) const {
-- 
GitLab


From a0756f7e25a5960e3a5f3c2f8331fda85c8ddcfc Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Tue, 4 Feb 2020 11:26:50 +0000
Subject: [PATCH 07/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/7045993
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 518 ++++++++++-----------
 1 file changed, 250 insertions(+), 268 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index bbdb2d502ea..7e8ca467e3d 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -16,9 +16,9 @@
 
 #include "Event/MCHeader.h"
 #include "Event/MCParticle.h"
-#include "Event/MCVertex.h"
-#include "Event/MCTrackInfo.h"
 #include "Event/MCProperty.h"
+#include "Event/MCTrackInfo.h"
+#include "Event/MCVertex.h"
 
 #include "Event/RecVertex.h"
 #include "Event/RecVertex_v2.h"
@@ -34,8 +34,8 @@
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
 
-#include <tuple>
 #include <string>
+#include <tuple>
 #include <vector>
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
@@ -43,7 +43,7 @@
 
 namespace {
 
-  struct MCPVInfo{
+  struct MCPVInfo {
     LHCb::MCVertex*                pMCPV;             // pointer to MC PV
     int                            nRecTracks;        // number of reconstructed tracks from this MCPV
     int                            nRecBackTracks;    // number of reconstructed backward tracks
@@ -56,20 +56,20 @@ namespace {
     bool                           decayStrange;
     std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
     std::vector<LHCb::Track*>      m_recTracksInMCPV;
-};
+  };
 
-  struct RecPVInfo{
+  struct RecPVInfo {
   public:
-  int                               nTracks; // number of tracks
-  double                            chi2;
-  double                            nDoF;
-  int                               mother;
-  Gaudi::XYZPoint                   position;      // position
-  Gaudi::XYZPoint                   positionSigma; // position sigmas
-  int                               indexMCPVInfo; // index to MCPVInfo
-  const LHCb::Event::v2::RecVertex* pRECPV;
-  //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
-};
+    int                               nTracks; // number of tracks
+    double                            chi2;
+    double                            nDoF;
+    int                               mother;
+    Gaudi::XYZPoint                   position;      // position
+    Gaudi::XYZPoint                   positionSigma; // position sigmas
+    int                               indexMCPVInfo; // index to MCPVInfo
+    const LHCb::Event::v2::RecVertex* pRECPV;
+    //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
+  };
 
   inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
 
@@ -77,74 +77,73 @@ namespace {
     double X = std::numeric_limits<double>::signaling_NaN();
     double Y = std::numeric_limits<double>::signaling_NaN();
     Beamline_t( Condition const& c )
-      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
-      , Y{c.param<double>( "ResolPosY" )} {}
+        : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+        , Y{c.param<double>( "ResolPosY" )} {}
   };
 
   bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
-  struct Stats{
+  struct Stats {
     std::string name;
-    int MCPV;
-    int RecPV;
-    int FalsePV;
-    int notRecPV;
-    int nTracks;
-    int nMCPart;
+    int         MCPV;
+    int         RecPV;
+    int         FalsePV;
+    int         notRecPV;
+    int         nTracks;
+    int         nMCPart;
   };
 
-  enum class recoAs{
-      all,
-      isolated, close,
-      ntracks_low, ntracks_high,
-      z_low, z_middle, z_high,
-      beauty, charm, strange, other
+  enum class recoAs {
+    all,
+    isolated,
+    close,
+    ntracks_low,
+    ntracks_high,
+    z_low,
+    z_middle,
+    z_high,
+    beauty,
+    charm,
+    strange,
+    other
   };
-  static const recoAs All[] = { recoAs::all,
-                                recoAs::isolated, recoAs::close,
-                                recoAs::ntracks_low, recoAs::ntracks_high,
-                                recoAs::z_low, recoAs::z_middle, recoAs::z_high,
-                                recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
-  static const recoAs part[] = { recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+  static const recoAs All[]  = {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
+                               recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
+                               recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other};
+  static const recoAs part[] = {recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
 
-  static constexpr int size_recAs = int(recoAs::other) + 1;
-
-}
+  static constexpr int size_recAs = int( recoAs::other ) + 1;
 
+} // namespace
 
 class PrimaryVertexChecker
-    : public Gaudi::Functional::Consumer<
-          void( const LHCb::Tracks&,
-                std::vector<LHCb::Event::v2::RecVertex> const&,
-                const LHCb::MCVertices&,
-                const LHCb::MCParticles&,
-                // const LHCb::LinksByKey&,
-                const LHCb::MCHeader&,
-                const LHCb::MCProperty&),
-          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, std::vector<LHCb::Event::v2::RecVertex> const&,
+                                               const LHCb::MCVertices&, const LHCb::MCParticles&,
+                                               // const LHCb::LinksByKey&,
+                                               const LHCb::MCHeader&, const LHCb::MCProperty& ),
+                                         Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-      : Consumer{ name,
-                  pSvcLocator,
-                  {KeyValue{"inputTracksName",   LHCb::TrackLocation::Default},
-                   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-                   KeyValue{"MCVertexInput",     LHCb::MCVertexLocation::Default},
-                   KeyValue{"MCParticleInput",   LHCb::MCParticleLocation::Default},
-                   KeyValue{"MCHeaderLocation",  LHCb::MCHeaderLocation::Default},
-                   KeyValue{"MCPropertyInput",   LHCb::MCPropertyLocation::TrackInfo},
-                  //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-                      }} {}
+      : Consumer{name,
+                 pSvcLocator,
+                 {
+                     KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                     KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                     KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                     KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                     KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
+                     KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
+                     //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+                 }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks,
-                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
-                         const LHCb::MCVertices&                        mcvtx,
-                         const LHCb::MCParticles&                       mcps,
+  void       operator()( const LHCb::Tracks& tracks, std::vector<LHCb::Event::v2::RecVertex> const& vertices,
+                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                    // const LHCb::LinksByKey& linker,
-                         const LHCb::MCHeader&                          mcheader,
-                         const LHCb::MCProperty&                        flags) const override; ///< Algorithm execution
-  StatusCode finalize() override;                                         ///< Algorithm finalization
+                   const LHCb::MCHeader&   mcheader,
+                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
@@ -162,27 +161,26 @@ private:
   // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
   mutable std::map<recoAs, Stats> m_stats;
-  mutable std::vector<Stats> m_stats_multi;
-  mutable int m_nevt;
+  mutable std::vector<Stats>      m_stats_multi;
+  mutable int                     m_nevt;
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
                                                std::vector<MCPVInfo>::iterator& itmc ) const;
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                               const RecPVInfo& rec ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat(const std::string name, const Stats& stat);
-  void printRes(std::string mes, double x, double y, double z);
-  std::string toString( const recoAs& n) const;
-  bool checkCondition(const MCPVInfo& MCPV, const recoAs& n) const;
+  void printRat( const std::string name, const Stats& stat );
+  void printRes( std::string mes, double x, double y, double z );
+  std::string toString( const recoAs& n ) const;
+  bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
 
   //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
   //                                   std::string trackLoc ) const;
-  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
-  double check_histogram(const AIDA::IHistogram1D* h, bool var);
+  int    count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
+  void   count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
+  double check_histogram( const AIDA::IHistogram1D* h, bool var );
   //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
   //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
   //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
@@ -199,32 +197,30 @@ StatusCode PrimaryVertexChecker::initialize() {
   StatusCode sc = GaudiTupleAlg::initialize(); // Must be executed first
   if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
 
-  m_nevt                 = 0;
-
-  for(const auto& n: All)
-    {
-      Stats s;
-      s.MCPV = 0;
-      s.RecPV = 0;
-      s.FalsePV = 0;
-      s.notRecPV = 0;
-      s.nTracks = 0;
-      s.nMCPart = 0;
-      m_stats[n];
-    }
+  m_nevt = 0;
+
+  for ( const auto& n : All ) {
+    Stats s;
+    s.MCPV     = 0;
+    s.RecPV    = 0;
+    s.FalsePV  = 0;
+    s.notRecPV = 0;
+    s.nTracks  = 0;
+    s.nMCPart  = 0;
+    m_stats[n];
+  }
 
-  for(auto i = 0; i<m_multiToPrint.value(); i++)
-    {
-      Stats s;
-      s.name = format("%d_%dMCPV",size_recAs+i+1,i+1);
-      s.MCPV = 0;
-      s.RecPV = 0;
-      s.FalsePV = 0;
-      s.notRecPV = 0;
-      s.nTracks = 0;
-      s.nMCPart = 0;
-      m_stats_multi.push_back(s);
-    }
+  for ( auto i = 0; i < m_multiToPrint.value(); i++ ) {
+    Stats s;
+    s.name     = format( "%d_%dMCPV", size_recAs + i + 1, i + 1 );
+    s.MCPV     = 0;
+    s.RecPV    = 0;
+    s.FalsePV  = 0;
+    s.notRecPV = 0;
+    s.nTracks  = 0;
+    s.nMCPart  = 0;
+    m_stats_multi.push_back( s );
+  }
 
   return StatusCode::SUCCESS;
 }
@@ -234,11 +230,9 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
                                        std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
-                                       const LHCb::MCVertices&                        mcvtx,
-                                       const LHCb::MCParticles&                       mcps,
+                                       const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader&                          mcheader,
-                                       const LHCb::MCProperty&                        flags) const {
+                                       const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -371,51 +365,41 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     double nDoF   = recpvvec[ipv].nDoF;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
-      fake           = 1;
+      fake                                 = 1;
       std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
 
-      if ( cmc != rblemcpv.end() )
-        {
-          dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
-
-          for(const auto& n: part)
-            {
-              bool cut = false;
-              cut = checkCondition(*cmc,n);
-              if ( cut ) {
-                m_stats[n].FalsePV += 1;
-              }
-            }
-          if ( dist > m_dzIsolated ) {
-            m_stats[recoAs::isolated].FalsePV += 1;
-          }
-          else {
-            m_stats[recoAs::close].FalsePV += 1;
-          }
-          if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
-            m_stats[recoAs::ntracks_high].FalsePV += 1;
-          }
-          else {
-            m_stats[recoAs::ntracks_low].FalsePV += 1;
-          }
+      if ( cmc != rblemcpv.end() ) {
+        dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
 
-          if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
-            m_stats[recoAs::z_low].FalsePV += 1;
-          }
-          else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
-            m_stats[recoAs::z_middle].FalsePV += 1;
-          }
-          else {
-            m_stats[recoAs::z_high].FalsePV += 1;
-          }
+        for ( const auto& n : part ) {
+          bool cut = false;
+          cut      = checkCondition( *cmc, n );
+          if ( cut ) { m_stats[n].FalsePV += 1; }
+        }
+        if ( dist > m_dzIsolated ) {
+          m_stats[recoAs::isolated].FalsePV += 1;
+        } else {
+          m_stats[recoAs::close].FalsePV += 1;
+        }
+        if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
+          m_stats[recoAs::ntracks_high].FalsePV += 1;
+        } else {
+          m_stats[recoAs::ntracks_low].FalsePV += 1;
+        }
 
-          int idx = std::distance(rblemcpv.begin(), cmc);
-          if ( idx < m_multiToPrint ) {
-            m_stats_multi[idx].FalsePV +=1;
-          }
+        if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
+          m_stats[recoAs::z_low].FalsePV += 1;
+        } else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
+          m_stats[recoAs::z_middle].FalsePV += 1;
+        } else {
+          m_stats[recoAs::z_high].FalsePV += 1;
         }
 
+        int idx = std::distance( rblemcpv.begin(), cmc );
+        if ( idx < m_multiToPrint ) { m_stats_multi[idx].FalsePV += 1; }
+      }
+
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -461,24 +445,22 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
 
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
 
-    for(const auto& n: All)
-      {
-        bool cut = false;
-        cut = checkCondition(*itmc,n);
-        if ( cut ) {
-            m_stats[n].MCPV+=1;
-            if (itmc->nRecTracks < m_nTracksToBeRecble ) {
-              m_stats[n].notRecPV+=1;
-            }
-            else {
-              m_stats[n].nMCPart += itmc->nRecTracks;
-            }
-            if ( itmc->indexRecPVInfo > -1 ) {
-              m_stats[n].RecPV+=1;
-              m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-            }
+    for ( const auto& n : All ) {
+      bool cut = false;
+      cut      = checkCondition( *itmc, n );
+      if ( cut ) {
+        m_stats[n].MCPV += 1;
+        if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
+          m_stats[n].notRecPV += 1;
+        } else {
+          m_stats[n].nMCPart += itmc->nRecTracks;
+        }
+        if ( itmc->indexRecPVInfo > -1 ) {
+          m_stats[n].RecPV += 1;
+          m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
         }
       }
+    }
   }
 
   int mcpv = 0;
@@ -516,16 +498,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     xMC = itmc->pMCPV->position().x();
     rMC = std::sqrt( ( xMC - m_beamSpotX ) * ( xMC - m_beamSpotX ) + ( yMC - m_beamSpotY ) * ( yMC - m_beamSpotY ) );
 
-    if ( mcpv < m_multiToPrint )
-      {
-        m_stats_multi[mcpv].MCPV += 1;
-        if (itmc->nRecTracks < m_nTracksToBeRecble) {
-          m_stats_multi[mcpv].notRecPV+=1;
-        }
-        else {
-          m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
-        }
+    if ( mcpv < m_multiToPrint ) {
+      m_stats_multi[mcpv].MCPV += 1;
+      if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
+        m_stats_multi[mcpv].notRecPV += 1;
+      } else {
+        m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
       }
+    }
 
     if ( indRec > -1 ) {
       high++;
@@ -550,11 +530,10 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       chi2          = recpvvec[indRec].chi2;
       nDoF          = recpvvec[indRec].nDoF;
 
-      if ( mcpv < m_multiToPrint )
-        {
-          m_stats_multi[mcpv].RecPV += 1;
-          m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
-        }
+      if ( mcpv < m_multiToPrint ) {
+        m_stats_multi[mcpv].RecPV += 1;
+        m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
+      }
       // Filling histograms
       if ( m_produceHistogram ) {
         plot( itmc->pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
@@ -569,33 +548,29 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         plot( dx / errx, 1031, "pullx", -5., 5., 50 );
         plot( dy / erry, 1032, "pully", -5., 5., 50 );
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
-        if ( itmc->nRecTracks < 10){
+        if ( itmc->nRecTracks < 10 ) {
           plot( dx, 1101, "dx", -0.25, 0.25, 50 );
           plot( dy, 1102, "dy", -0.25, 0.25, 50 );
           plot( dz, 1103, "dz", -0.5, 0.5, 50 );
-        }
-        else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30){
+        } else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30 ) {
           plot( dx, 1111, "dx", -0.25, 0.25, 50 );
           plot( dy, 1112, "dy", -0.25, 0.25, 50 );
           plot( dz, 1113, "dz", -0.5, 0.5, 50 );
-        }
-        else{
+        } else {
           plot( dx, 1121, "dx", -0.25, 0.25, 50 );
           plot( dy, 1122, "dy", -0.25, 0.25, 50 );
           plot( dz, 1123, "dz", -0.5, 0.5, 50 );
         }
 
-        if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
+        if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
           plot( dx, 1201, "dx", -0.25, 0.25, 50 );
           plot( dy, 1202, "dy", -0.25, 0.25, 50 );
           plot( dz, 1203, "dz", -0.5, 0.5, 50 );
-        }
-        else if ( itmc->pMCPV->position().z() < m_zToPrint )    {
+        } else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
           plot( dx, 1211, "dx", -0.25, 0.25, 50 );
           plot( dy, 1212, "dy", -0.25, 0.25, 50 );
           plot( dz, 1213, "dz", -0.5, 0.5, 50 );
-        }
-        else {
+        } else {
           plot( dx, 1221, "dx", -0.25, 0.25, 50 );
           plot( dy, 1222, "dy", -0.25, 0.25, 50 );
           plot( dz, 1223, "dz", -0.5, 0.5, 50 );
@@ -727,7 +702,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
                                                                    std::vector<MCPVInfo>::iterator& itmc ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
-  double                        mindist = 999999.;
+  double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
@@ -742,24 +717,23 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
-std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                                                   const RecPVInfo& rec ) const {
+std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>& rblemcpv,
+                                                                   const RecPVInfo&       rec ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
-  double                        mindist = 999999.;
+  double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
-      double dist = ( it->pMCPV->position() - rec.pRECPV->position() ).R();
-      if ( dist < mindist ) {
-        mindist = dist;
-        itret   = it;
-      }
+    double dist = ( it->pMCPV->position() - rec.pRECPV->position() ).R();
+    if ( dist < mindist ) {
+      mindist = dist;
+      itret   = it;
+    }
   }
   return itret;
 }
 
-
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
                                              std::vector<LHCb::MCParticle*>& allprods ) const {
 
@@ -783,44 +757,49 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
 
-  //categories category = all;
-  //info() << " CATEGORY TEST = " << category << endmsg;
+  // categories category = all;
+  // info() << " CATEGORY TEST = " << category << endmsg;
 
-  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed" << endmsg;
+  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed"
+         << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
-  info() << " MC efficiency split by tracks with threshold: ("<< m_nTracksToBeRecble.value()<<","<<m_nTracksToPrint.value()<<"), >= "<<m_nTracksToPrint.value()<<endmsg;
-  info() << " MC efficiency split by z position: <-"<<m_zToPrint.value()<<", (-"<<m_zToPrint.value()<<","<<m_zToPrint.value()<<"), >"<<m_zToPrint.value()<< endmsg;
+  info() << " MC efficiency split by tracks with threshold: (" << m_nTracksToBeRecble.value() << ","
+         << m_nTracksToPrint.value() << "), >= " << m_nTracksToPrint.value() << endmsg;
+  info() << " MC efficiency split by z position: <-" << m_zToPrint.value() << ", (-" << m_zToPrint.value() << ","
+         << m_zToPrint.value() << "), >" << m_zToPrint.value() << endmsg;
   std::string ff = "by distance";
   info() << " REC and MC vertices matched:  " << ff << endmsg;
 
   info() << " " << endmsg;
 
+  for ( const auto& n : All ) { printRat( toString( n ), m_stats[n] ); }
 
-  for (const auto& n: All)
-    {
-      printRat(toString(n), m_stats[n] );
-    }
-
-  for (auto& mstat : m_stats_multi)
-    {
-      printRat( mstat.name, mstat );
-    }
+  for ( auto& mstat : m_stats_multi ) { printRat( mstat.name, mstat ); }
   info() << " " << endmsg;
 
-  printRes("1_res_all",                check_histogram(histo( HistoID( 1021 ) ),true), check_histogram(histo( HistoID( 1022 ) ), true), check_histogram(histo( HistoID( 1023 ) ),true));
+  printRes( "1_res_all", check_histogram( histo( HistoID( 1021 ) ), true ),
+            check_histogram( histo( HistoID( 1022 ) ), true ), check_histogram( histo( HistoID( 1023 ) ), true ) );
 
-  printRes("2_res_ntracks<10",     check_histogram(histo( HistoID( 1101 ) ),true), check_histogram(histo( HistoID( 1102 ) ), true), check_histogram(histo( HistoID( 1103 ) ),true));
-  printRes("3_res_ntracks(10,30)", check_histogram(histo( HistoID( 1111 ) ),true), check_histogram(histo( HistoID( 1112 ) ), true), check_histogram(histo( HistoID( 1113 ) ),true));
-  printRes("4_res_ntracks>30",     check_histogram(histo( HistoID( 1121 ) ),true), check_histogram(histo( HistoID( 1122 ) ), true), check_histogram(histo( HistoID( 1123 ) ),true));
+  printRes( "2_res_ntracks<10", check_histogram( histo( HistoID( 1101 ) ), true ),
+            check_histogram( histo( HistoID( 1102 ) ), true ), check_histogram( histo( HistoID( 1103 ) ), true ) );
+  printRes( "3_res_ntracks(10,30)", check_histogram( histo( HistoID( 1111 ) ), true ),
+            check_histogram( histo( HistoID( 1112 ) ), true ), check_histogram( histo( HistoID( 1113 ) ), true ) );
+  printRes( "4_res_ntracks>30", check_histogram( histo( HistoID( 1121 ) ), true ),
+            check_histogram( histo( HistoID( 1122 ) ), true ), check_histogram( histo( HistoID( 1123 ) ), true ) );
 
-  printRes("5_res_z<-50",     check_histogram(histo( HistoID( 1201 ) ),true), check_histogram(histo( HistoID( 1202 ) ),true), check_histogram(histo( HistoID( 1203 ) ),true));
-  printRes("6_res_z(-50,50)", check_histogram(histo( HistoID( 1211 ) ),true), check_histogram(histo( HistoID( 1212 ) ),true), check_histogram(histo( HistoID( 1213 ) ),true));
-  printRes("7_res_z>50",      check_histogram(histo( HistoID( 1221 ) ),true), check_histogram(histo( HistoID( 1222 ) ),true), check_histogram(histo( HistoID( 1223 ) ),true));
+  printRes( "5_res_z<-50", check_histogram( histo( HistoID( 1201 ) ), true ),
+            check_histogram( histo( HistoID( 1202 ) ), true ), check_histogram( histo( HistoID( 1203 ) ), true ) );
+  printRes( "6_res_z(-50,50)", check_histogram( histo( HistoID( 1211 ) ), true ),
+            check_histogram( histo( HistoID( 1212 ) ), true ), check_histogram( histo( HistoID( 1213 ) ), true ) );
+  printRes( "7_res_z>50", check_histogram( histo( HistoID( 1221 ) ), true ),
+            check_histogram( histo( HistoID( 1222 ) ), true ), check_histogram( histo( HistoID( 1223 ) ), true ) );
 
   info() << " " << endmsg;
 
-  printRes("1_pull_width_all",  check_histogram(histo( HistoID( 1031 ) ),true), check_histogram(histo( HistoID( 1032 ) ),true), check_histogram(histo( HistoID( 1033 ) ),true));
-  printRes("1_pull_mean_all",   check_histogram(histo( HistoID( 1031 ) ),false), check_histogram(histo( HistoID( 1032 ) ),false), check_histogram(histo( HistoID( 1033 ) ),false));
+  printRes( "1_pull_width_all", check_histogram( histo( HistoID( 1031 ) ), true ),
+            check_histogram( histo( HistoID( 1032 ) ), true ), check_histogram( histo( HistoID( 1033 ) ), true ) );
+  printRes( "1_pull_mean_all", check_histogram( histo( HistoID( 1031 ) ), false ),
+            check_histogram( histo( HistoID( 1032 ) ), false ), check_histogram( histo( HistoID( 1033 ) ), false ) );
 
   info() << " " << endmsg;
 
@@ -829,17 +808,17 @@ StatusCode PrimaryVertexChecker::finalize() {
 
 void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat ) {
 
-  double rat = 0.;
-  double fl = 0.;
-  int all_rec = stat.RecPV+stat.FalsePV;
-  double av_tr = 0.;
-  double av_par = 0.;
-  if ( (stat.MCPV-stat.notRecPV) > 0 ) {
-    rat = 100.0 * stat.RecPV / (stat.MCPV-stat.notRecPV);
-    av_par = 1.0*stat.nMCPart/(stat.MCPV-stat.notRecPV);
+  double rat     = 0.;
+  double fl      = 0.;
+  int    all_rec = stat.RecPV + stat.FalsePV;
+  double av_tr   = 0.;
+  double av_par  = 0.;
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
+    rat    = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV );
+    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
   }
   if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
-  if ( stat.RecPV > 0 ) av_tr = 1.0*stat.nTracks/stat.RecPV;
+  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
   // reformat message
   unsigned int len  = 25;
@@ -847,29 +826,29 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
-  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f [MC: %6.2f]",
-                            stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par) << endmsg;
+  info() << pmes
+         << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: "
+                    "%6.2f [MC: %6.2f]",
+                    stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par )
+         << endmsg;
 }
 
-void PrimaryVertexChecker::printRes(std::string mes, double x, double y, double z){
+void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
   unsigned int len  = 20;
   std::string  pmes = mes;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
-  info() << pmes << format(" x: %+5.3f, y: %+5.3f, z: %+5.3f",
-                           x, y, z) << endmsg;
+  info() << pmes << format( " x: %+5.3f, y: %+5.3f, z: %+5.3f", x, y, z ) << endmsg;
 }
 
-double PrimaryVertexChecker::check_histogram(const AIDA::IHistogram1D* h, bool rms) {
+double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool rms ) {
   if ( h ) {
     if ( rms ) {
       return h->rms();
-    }
-    else {
+    } else {
       return h->mean();
     }
-  }
-  else {
+  } else {
     return 0.;
   }
 }
@@ -924,7 +903,8 @@ int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::
   return nVeloTracks;
 }
 
-void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const {
+void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>&  mcpvvec,
+                                                               const LHCb::MCProperty& flags ) const {
 
   const MCTrackInfo               trInfo = {flags};
   std::vector<MCPVInfo>::iterator itinfomc;
@@ -942,8 +922,8 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
 
       if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
-        if ( pmcp->particleID().hasBottom() )  { itinfomc->decayBeauty  = true; }
-        if ( pmcp->particleID().hasCharm() )   { itinfomc->decayCharm   = true; }
+        if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
+        if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
         if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
         if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
@@ -956,63 +936,65 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
   }
 }
 
-bool  PrimaryVertexChecker::checkCondition( const  MCPVInfo& MCPV, const recoAs& n) const{
-  switch (n) {
+bool PrimaryVertexChecker::checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const {
+  switch ( n ) {
   case recoAs::all:
     return true;
   case recoAs::isolated:
-    return (MCPV.distToClosestMCPV > m_dzIsolated);
+    return ( MCPV.distToClosestMCPV > m_dzIsolated );
   case recoAs::close:
-    return (MCPV.distToClosestMCPV <= m_dzIsolated);
+    return ( MCPV.distToClosestMCPV <= m_dzIsolated );
   case recoAs::ntracks_low:
-    return (MCPV.nRecTracks >= m_nTracksToBeRecble && MCPV.nRecTracks < m_nTracksToPrint );
+    return ( MCPV.nRecTracks >= m_nTracksToBeRecble && MCPV.nRecTracks < m_nTracksToPrint );
   case recoAs::ntracks_high:
-    return (MCPV.nRecTracks >= m_nTracksToPrint );
+    return ( MCPV.nRecTracks >= m_nTracksToPrint );
   case recoAs::z_low:
-    return (MCPV.pMCPV->position().z() < -m_zToPrint );
+    return ( MCPV.pMCPV->position().z() < -m_zToPrint );
   case recoAs::z_middle:
-    return (MCPV.pMCPV->position().z() >= -m_zToPrint && MCPV.pMCPV->position().z() < m_zToPrint);
+    return ( MCPV.pMCPV->position().z() >= -m_zToPrint && MCPV.pMCPV->position().z() < m_zToPrint );
   case recoAs::z_high:
-    return (MCPV.pMCPV->position().z() >= m_zToPrint);
+    return ( MCPV.pMCPV->position().z() >= m_zToPrint );
   case recoAs::beauty:
-    return (MCPV.decayBeauty);
+    return ( MCPV.decayBeauty );
   case recoAs::charm:
-    return (MCPV.decayCharm);
+    return ( MCPV.decayCharm );
   case recoAs::strange:
-    return (MCPV.decayStrange);
+    return ( MCPV.decayStrange );
   case recoAs::other:
-    return ( !(MCPV.decayBeauty) && !(MCPV.decayCharm) && !(MCPV.decayStrange) );
-  default: return false;
+    return ( !( MCPV.decayBeauty ) && !( MCPV.decayCharm ) && !( MCPV.decayStrange ) );
+  default:
+    return false;
   }
 }
 
-std::string PrimaryVertexChecker::toString( const recoAs& n) const{
-  switch (n) {
+std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
+  switch ( n ) {
   case recoAs::all:
-    return format("0%d all",int(recoAs::all));
+    return format( "0%d all", int( recoAs::all ) );
   case recoAs::isolated:
-    return format("0%d isolated",int(recoAs::isolated));
+    return format( "0%d isolated", int( recoAs::isolated ) );
   case recoAs::close:
-    return format("0%d close",int(recoAs::close));
+    return format( "0%d close", int( recoAs::close ) );
   case recoAs::ntracks_low:
-    return format("0%d ntracks<%d",int(recoAs::ntracks_low),int(m_nTracksToPrint));
+    return format( "0%d ntracks<%d", int( recoAs::ntracks_low ), int( m_nTracksToPrint ) );
   case recoAs::ntracks_high:
-    return format("0%d ntracks>=%d",int(recoAs::ntracks_high),int(m_nTracksToPrint));
+    return format( "0%d ntracks>=%d", int( recoAs::ntracks_high ), int( m_nTracksToPrint ) );
   case recoAs::z_low:
-    return format("0%d z<%2.1f",int(recoAs::z_low),-m_zToPrint);
+    return format( "0%d z<%2.1f", int( recoAs::z_low ), -m_zToPrint );
   case recoAs::z_middle:
-    return format("0%d z in (%2.1f, %2.1f)",int(recoAs::z_middle), -m_zToPrint, +m_zToPrint);
+    return format( "0%d z in (%2.1f, %2.1f)", int( recoAs::z_middle ), -m_zToPrint, +m_zToPrint );
   case recoAs::z_high:
-    return format("0%d z >=%2.1f",int(recoAs::z_high), +m_zToPrint);
+    return format( "0%d z >=%2.1f", int( recoAs::z_high ), +m_zToPrint );
   case recoAs::beauty:
-    return format("0%d beauty",int(recoAs::beauty));
+    return format( "0%d beauty", int( recoAs::beauty ) );
   case recoAs::charm:
-    return format("0%d charm",int(recoAs::charm));
+    return format( "0%d charm", int( recoAs::charm ) );
   case recoAs::strange:
-    return format("%d strange",int(recoAs::strange));
+    return format( "%d strange", int( recoAs::strange ) );
   case recoAs::other:
-    return format("%d other",int(recoAs::other));
-  default: return "not defined";
+    return format( "%d other", int( recoAs::other ) );
+  default:
+    return "not defined";
   }
 }
 // int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
-- 
GitLab


From 0ab2f1afb5766de6f7f2abf4f9539ac56a6ab40b Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus752.cern.ch>
Date: Wed, 19 Feb 2020 17:39:35 +0100
Subject: [PATCH 08/42] changing PV class, updating config files and print out,
 fixing a small bug

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 75 ++++++++++++++++------
 1 file changed, 55 insertions(+), 20 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 7e8ca467e3d..abaf1488744 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -117,7 +117,8 @@ namespace {
 } // namespace
 
 class PrimaryVertexChecker
-    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, std::vector<LHCb::Event::v2::RecVertex> const&,
+    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, 
+					       LHCb::Event::v2::RecVertices const&,
                                                const LHCb::MCVertices&, const LHCb::MCParticles&,
                                                // const LHCb::LinksByKey&,
                                                const LHCb::MCHeader&, const LHCb::MCProperty& ),
@@ -138,11 +139,12 @@ public:
                  }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks, std::vector<LHCb::Event::v2::RecVertex> const& vertices,
-                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-                   // const LHCb::LinksByKey& linker,
-                   const LHCb::MCHeader&   mcheader,
-                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+  void       operator()( const LHCb::Tracks& tracks, 
+			 LHCb::Event::v2::RecVertices const& vertices,
+			 const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
+			 // const LHCb::LinksByKey& linker,
+			 const LHCb::MCHeader&   mcheader,
+			 const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
   StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
@@ -170,6 +172,7 @@ private:
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( const std::string name, const Stats& stat );
+  void printAvTracks( const std::string name, const Stats& stat );
   void printRes( std::string mes, double x, double y, double z );
   std::string toString( const recoAs& n ) const;
   bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
@@ -229,7 +232,7 @@ StatusCode PrimaryVertexChecker::initialize() {
 // Main execution
 //=============================================================================
 void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
-                                       std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
+                                       LHCb::Event::v2::RecVertices const& recoVtx,
                                        const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
                                        const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
@@ -239,7 +242,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   // Event
   m_nevt++;
 
-  if ( recoVtx.size() == 0 ) { return; }
+  //  if ( recoVtx.size() == 0 ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -277,11 +280,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     recpvvec.push_back( recinfo );
   }
 
+
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
   for ( const auto& mcpv : mcvtx ) {
-    const LHCb::MCParticle* motherPart = mcpv->mother();
-    if ( 0 == motherPart ) {
+         const LHCb::MCParticle* motherPart = mcpv->mother();
+     if ( 0 == motherPart ) {
       if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
         mcprimvert.pMCPV             = mcpv;
@@ -298,27 +302,36 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         mcprimvert.m_recTracksInMCPV.clear();
         mcpvvec.push_back( mcprimvert );
       }
-    }
+     }
   }
 
+
   count_reconstructible_mc_particles( mcpvvec, flags );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
 
   std::vector<MCPVInfo> rblemcpv;
+  std::vector<MCPVInfo> notrblemcpv;
   std::vector<MCPVInfo> not_rble_but_visible;
   std::vector<MCPVInfo> not_rble;
   int                   nmrc = 0;
 
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
-    rblemcpv.push_back( *itmc );
+    if ( itmc->nRecTracks >= m_nTracksToBeRecble) { 
+      rblemcpv.push_back( *itmc ); 
+    }
+    else {
+      notrblemcpv.push_back( *itmc ); 
+    }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
 
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
+  rblemcpv.insert(rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end());
+
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
     debug() << " ===================================" << endmsg;
@@ -777,6 +790,11 @@ StatusCode PrimaryVertexChecker::finalize() {
   for ( auto& mstat : m_stats_multi ) { printRat( mstat.name, mstat ); }
   info() << " " << endmsg;
 
+  for ( const auto& n : All ) { printAvTracks( toString( n ), m_stats[n] ); }
+
+  for ( auto& mstat : m_stats_multi ) { printAvTracks( mstat.name, mstat ); }
+  info() << " " << endmsg;
+
   printRes( "1_res_all", check_histogram( histo( HistoID( 1021 ) ), true ),
             check_histogram( histo( HistoID( 1022 ) ), true ), check_histogram( histo( HistoID( 1023 ) ), true ) );
 
@@ -811,14 +829,10 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   double rat     = 0.;
   double fl      = 0.;
   int    all_rec = stat.RecPV + stat.FalsePV;
-  double av_tr   = 0.;
-  double av_par  = 0.;
   if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
     rat    = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV );
-    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
   }
   if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
-  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
   // reformat message
   unsigned int len  = 25;
@@ -827,14 +841,35 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   pmes += " : ";
 
   info() << pmes
-         << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: "
-                    "%6.2f [MC: %6.2f]",
-                    stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par )
+         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
+                    stat.RecPV, stat.MCPV-stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV, stat.FalsePV, fl)
+         << endmsg;
+}
+
+void PrimaryVertexChecker::printAvTracks( const std::string name, const Stats& stat ) {
+  double av_tr   = 0.;
+  double av_par  = 0.;
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
+    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
+  }
+   if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
+
+  // reformat message                                                                                                                                                                                                            
+  unsigned int len  = 25;
+  std::string  pmes = name;
+  while ( pmes.length() < len ) { pmes += " "; }
+  pmes += " : ";
+
+  info() << pmes
+         << format( "av. PV tracks: %6.2f [MC: %6.2f]",
+                    av_tr, av_par )
          << endmsg;
+
+
 }
 
 void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
-  unsigned int len  = 20;
+  unsigned int len  = 25;
   std::string  pmes = mes;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
-- 
GitLab


From 3e4a4d322ab29d18a6a8b316b315e3669bd3be15 Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 19 Feb 2020 16:42:13 +0000
Subject: [PATCH 09/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/7269774
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 64 +++++++++-------------
 1 file changed, 25 insertions(+), 39 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index abaf1488744..3933433ec03 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -117,8 +117,7 @@ namespace {
 } // namespace
 
 class PrimaryVertexChecker
-    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, 
-					       LHCb::Event::v2::RecVertices const&,
+    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, LHCb::Event::v2::RecVertices const&,
                                                const LHCb::MCVertices&, const LHCb::MCParticles&,
                                                // const LHCb::LinksByKey&,
                                                const LHCb::MCHeader&, const LHCb::MCProperty& ),
@@ -139,12 +138,11 @@ public:
                  }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks, 
-			 LHCb::Event::v2::RecVertices const& vertices,
-			 const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-			 // const LHCb::LinksByKey& linker,
-			 const LHCb::MCHeader&   mcheader,
-			 const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+  void       operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& vertices,
+                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
+                   // const LHCb::LinksByKey& linker,
+                   const LHCb::MCHeader&   mcheader,
+                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
   StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
@@ -231,8 +229,7 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
-                                       LHCb::Event::v2::RecVertices const& recoVtx,
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& recoVtx,
                                        const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
                                        const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
@@ -280,12 +277,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     recpvvec.push_back( recinfo );
   }
 
-
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
   for ( const auto& mcpv : mcvtx ) {
-         const LHCb::MCParticle* motherPart = mcpv->mother();
-     if ( 0 == motherPart ) {
+    const LHCb::MCParticle* motherPart = mcpv->mother();
+    if ( 0 == motherPart ) {
       if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
         mcprimvert.pMCPV             = mcpv;
@@ -302,10 +298,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         mcprimvert.m_recTracksInMCPV.clear();
         mcpvvec.push_back( mcprimvert );
       }
-     }
+    }
   }
 
-
   count_reconstructible_mc_particles( mcpvvec, flags );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
@@ -318,11 +313,10 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
 
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
-    if ( itmc->nRecTracks >= m_nTracksToBeRecble) { 
-      rblemcpv.push_back( *itmc ); 
-    }
-    else {
-      notrblemcpv.push_back( *itmc ); 
+    if ( itmc->nRecTracks >= m_nTracksToBeRecble ) {
+      rblemcpv.push_back( *itmc );
+    } else {
+      notrblemcpv.push_back( *itmc );
     }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
@@ -330,7 +324,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
 
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
-  rblemcpv.insert(rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end());
+  rblemcpv.insert( rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end() );
 
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
@@ -829,9 +823,7 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   double rat     = 0.;
   double fl      = 0.;
   int    all_rec = stat.RecPV + stat.FalsePV;
-  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
-    rat    = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV );
-  }
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) { rat = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV ); }
   if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
 
   // reformat message
@@ -841,31 +833,25 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   pmes += " : ";
 
   info() << pmes
-         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
-                    stat.RecPV, stat.MCPV-stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV, stat.FalsePV, fl)
+         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ", stat.RecPV,
+                    stat.MCPV - stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV,
+                    stat.FalsePV, fl )
          << endmsg;
 }
 
 void PrimaryVertexChecker::printAvTracks( const std::string name, const Stats& stat ) {
-  double av_tr   = 0.;
-  double av_par  = 0.;
-  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
-    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
-  }
-   if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
+  double av_tr  = 0.;
+  double av_par = 0.;
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) { av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV ); }
+  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
-  // reformat message                                                                                                                                                                                                            
+  // reformat message
   unsigned int len  = 25;
   std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
-  info() << pmes
-         << format( "av. PV tracks: %6.2f [MC: %6.2f]",
-                    av_tr, av_par )
-         << endmsg;
-
-
+  info() << pmes << format( "av. PV tracks: %6.2f [MC: %6.2f]", av_tr, av_par ) << endmsg;
 }
 
 void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
-- 
GitLab


From bff8e1e888b4e12b630d16bd321d116e6255a09a Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus7104.cern.ch>
Date: Wed, 26 Feb 2020 09:23:18 +0100
Subject: [PATCH 10/42] script for efficiency plots, small bugfix for decay
 categories

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 48 +++++++++++-----------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 3933433ec03..991f73abde3 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -616,7 +616,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
       myTuple->column( "decayBeauty", double( itmc->decayBeauty ) );
       myTuple->column( "decayStrange", double( itmc->decayStrange ) );
-      myTuple->column( "multi", double( high ) );
+      myTuple->column( "multirec", double( high ) );
+      myTuple->column( "multimc", double( mcpv ) );
       myTuple->column( "dx", dx );
       myTuple->column( "dy", dy );
       myTuple->column( "dz", dz );
@@ -741,21 +742,6 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
-void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
-                                             std::vector<LHCb::MCParticle*>& allprods ) const {
-
-  SmartRefVector<LHCb::MCParticle>           daughters = mcvtx->products();
-  SmartRefVector<LHCb::MCParticle>::iterator idau;
-  for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) {
-    double dv2 = ( mcpv->position() - ( *idau )->originVertex()->position() ).Mag2();
-    if ( dv2 > ( 100. * Gaudi::Units::mm ) * ( 100. * Gaudi::Units::mm ) ) continue;
-    LHCb::MCParticle* pmcp = *idau;
-    allprods.push_back( pmcp );
-    SmartRefVector<LHCb::MCVertex>           decays = ( *idau )->endVertices();
-    SmartRefVector<LHCb::MCVertex>::iterator ivtx;
-    for ( ivtx = decays.begin(); ivtx != decays.end(); ivtx++ ) { collectProductss( mcpv, *ivtx, allprods ); }
-  }
-}
 
 //=============================================================================
 //  Finalize
@@ -924,6 +910,22 @@ int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::
   return nVeloTracks;
 }
 
+void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
+                                             std::vector<LHCb::MCParticle*>& allprods ) const {
+
+  SmartRefVector<LHCb::MCParticle>           daughters = mcvtx->products();
+  SmartRefVector<LHCb::MCParticle>::iterator idau;
+  for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) {
+    double dv2 = ( mcpv->position() - ( *idau )->originVertex()->position() ).Mag2();
+    if ( dv2 > ( 100. * Gaudi::Units::mm ) * ( 100. * Gaudi::Units::mm ) ) continue;
+    LHCb::MCParticle* pmcp = *idau;
+    allprods.push_back( pmcp );
+    SmartRefVector<LHCb::MCVertex>           decays = ( *idau )->endVertices();
+    SmartRefVector<LHCb::MCVertex>::iterator ivtx;
+    for ( ivtx = decays.begin(); ivtx != decays.end(); ivtx++ ) { collectProductss( mcpv, *ivtx, allprods ); }
+  }
+}
+
 void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>&  mcpvvec,
                                                                const LHCb::MCProperty& flags ) const {
 
@@ -941,17 +943,15 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
 
       LHCb::MCParticle* pmcp = *imcp;
 
-      if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-
+      if ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) {
         if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
         if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
         if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
-        if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-
+        }
+      if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
           double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
           if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
         }
-      }
       itinfomc->nRecTracks = mcPartInMCPV.size();
     }
   }
@@ -1007,11 +1007,11 @@ std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
   case recoAs::z_high:
     return format( "0%d z >=%2.1f", int( recoAs::z_high ), +m_zToPrint );
   case recoAs::beauty:
-    return format( "0%d beauty", int( recoAs::beauty ) );
+    return format( "0%d decayBeauty", int( recoAs::beauty ) );
   case recoAs::charm:
-    return format( "0%d charm", int( recoAs::charm ) );
+    return format( "0%d decayCharm", int( recoAs::charm ) );
   case recoAs::strange:
-    return format( "%d strange", int( recoAs::strange ) );
+    return format( "%d decayStrange", int( recoAs::strange ) );
   case recoAs::other:
     return format( "%d other", int( recoAs::other ) );
   default:
-- 
GitLab


From b47f6826095d73d440718fe2d45ca34f5704f48d Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 26 Feb 2020 08:26:33 +0000
Subject: [PATCH 11/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/7342164
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 991f73abde3..dd753377788 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -742,7 +742,6 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
-
 //=============================================================================
 //  Finalize
 //=============================================================================
@@ -947,11 +946,12 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
         if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
         if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
         if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
-        }
-      if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-          double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-          if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
-        }
+      }
+      if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) &&
+           ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
+        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
+        if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
+      }
       itinfomc->nRecTracks = mcPartInMCPV.size();
     }
   }
-- 
GitLab


From 00c62caa7243a1b07369500153d797e4c5fc9513 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus783.cern.ch>
Date: Wed, 15 Jan 2020 23:00:57 +0100
Subject: [PATCH 12/42] PVChecker functional changes

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 157 +++++++++++----------
 Tr/PatChecker/src/PrimaryVertexChecker.h   |  86 ++++++-----
 2 files changed, 132 insertions(+), 111 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 3be8f5efa7e..7782db2ffb0 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -24,6 +24,7 @@
 #include "VeloDet/DeVelo.h"
 #include <Event/MCTrackInfo.h>
 #include <Linker/LinkedTo.h>
+#include "GaudiAlg/Consumer.h"
 // local
 #include "PrimaryVertexChecker.h"
 
@@ -33,23 +34,20 @@ bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > seco
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
 
+
+
 // Declaration of the Algorithm Factory
-DECLARE_COMPONENT( PrimaryVertexChecker )
+DECLARE_COMPONENT( PrimaryVertexChecker ) 
 
 //=============================================================================
 // Standard constructor, initializes variables
 //=============================================================================
 PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-    : GaudiTupleAlg( name, pSvcLocator ) {
-  declareProperty( "nTracksToBeRecble", m_nTracksToBeRecble = 5 );
-  declareProperty( "produceNtuple", m_produceNtuple = false );
-  declareProperty( "RequireVelo", m_requireVelo = true );
-  declareProperty( "produceHistogram", m_produceHistogram = true );
-  declareProperty( "dzIsolated", m_dzIsolated = 10.0 * Gaudi::Units::mm );
-  declareProperty( "matchByTracks", m_matchByTracks = true );
-  declareProperty( "inputTracksName", m_inputTracksName = LHCb::TrackLocation::Default );
-  declareProperty( "inputVerticesName", m_inputVerticesName = LHCb::RecVertexLocation::Primary );
-}
+      : Consumer( name, pSvcLocator,
+                                      {
+                                          KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                                          KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
+                                      } ) {}
 
 //=============================================================================
 // Initialization
@@ -91,10 +89,13 @@ StatusCode PrimaryVertexChecker::initialize() {
   return StatusCode::SUCCESS;
 }
 
+
 //=============================================================================
 // Main execution
 //=============================================================================
-StatusCode PrimaryVertexChecker::execute() {
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, 
+                   const LHCb::RecVertices& recoVertices) const {
+
   debug() << "==> Execute" << endmsg;
 
   // Event
@@ -103,15 +104,29 @@ StatusCode PrimaryVertexChecker::execute() {
   // Get input
   std::vector<LHCb::Track*>     vecOfTracks;
   std::vector<LHCb::RecVertex*> vecOfVertices;
-  std::string                   trackLoc;
-  bool                          tracks_ok   = getInputTracks( vecOfTracks, trackLoc );
-  bool                          vertices_ok = getInputVertices( vecOfVertices );
+  std::string                   trackLoc = "/Event/Rec/Track/VeloAsTrackV2_v1";
+  bool                          tracks_ok   = true; //getInputTracks( vecOfTracks );
+
+  if ( usedTracks.size() == 0 ) tracks_ok = false;
+
+  std::vector<LHCb::Track*>::const_iterator itT;
+  for ( itT = usedTracks.begin(); usedTracks.end() != itT; itT++ ) {
+    LHCb::Track* ptr = ( *itT );
+    vecOfTracks.push_back( ptr );
+  }
 
   if ( !tracks_ok && m_matchByTracks ) {
-    return StatusCode::SUCCESS; // return SUCCESSS anyway
+    return; // return SUCCESSS anyway
+  }
+
+ // bool                          vertices_ok = getInputVertices( vecOfVertices );
+  std::vector<LHCb::RecVertex*>::const_iterator itVer;
+  for ( itVer = recoVertices.begin(); recoVertices.end() != itVer; itVer++ ) {
+    LHCb::RecVertex* ppv = ( *itVer );
+    vecOfVertices.push_back( ppv );
   }
 
-  if ( !vertices_ok ) { return StatusCode::SUCCESS; }
+//  if ( !vertices_ok ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -652,11 +667,11 @@ StatusCode PrimaryVertexChecker::execute() {
     }
   }
 
-  return StatusCode::SUCCESS;
+  return;
 }
 
 void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
-                                                      std::vector<MCPVInfo>& mcpvvec ) {
+                                                      std::vector<MCPVInfo>& mcpvvec ) const {
 
   LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
   typedef const SmartRefVector<LHCb::Track> PVTRACKS;
@@ -691,7 +706,7 @@ void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPV
 }
 
 void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo,
-                                                        std::vector<MCPVInfo>& mcpvvec ) {
+                                                        std::vector<MCPVInfo>& mcpvvec ) const {
 
   double mindist = 999999.;
   int    indexmc = -1;
@@ -713,7 +728,7 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
 }
 
 std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                                                   std::vector<MCPVInfo>::iterator& itmc ) {
+                                                                   std::vector<MCPVInfo>::iterator& itmc ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
   double                          mindist = 999999.;
@@ -732,7 +747,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 }
 
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
-                                             std::vector<LHCb::MCParticle*>& allprods ) {
+                                             std::vector<LHCb::MCParticle*>& allprods ) const {
 
   SmartRefVector<LHCb::MCParticle>           daughters = mcvtx->products();
   SmartRefVector<LHCb::MCParticle>::iterator idau;
@@ -871,7 +886,7 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
 }
 
 void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-                                                       std::vector<LHCb::Track*>& vecOfTracks, std::string trackLoc ) {
+                                                       std::vector<LHCb::Track*>& vecOfTracks, std::string trackLoc ) const {
 
   LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
 
@@ -921,7 +936,7 @@ int PrimaryVertexChecker::count_velo_tracks( LHCb::RecVertex* RecVtx ) {
   return nVeloTracks;
 }
 
-void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) {
+void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const {
 
   const auto trInfo = MCTrackInfo{*get<LHCb::MCProperty>( LHCb::MCPropertyLocation::TrackInfo )};
   for ( auto itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
@@ -946,7 +961,7 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     }
   }
 }
-int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::string trackLoc ) {
+int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::string trackLoc ) const {
 
   int         motherPart = 0;
   const auto& tracksIn   = pv->tracks();
@@ -978,65 +993,59 @@ int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::strin
   return motherPart;
 }
 
-bool PrimaryVertexChecker::getInputTracks( std::vector<LHCb::Track*>& vecOfTracks, std::string& trackLoc ) {
+// bool PrimaryVertexChecker::getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const {
 
-  std::string tracksName = m_inputTracksName;
+//   // std::string tracksName = m_inputTracksName;
 
-  if ( m_inputTracksName == "Offline" ) {
-    tracksName = LHCb::TrackLocation::Default;
-  } else if ( m_inputTracksName == "3D" ) {
-    tracksName = LHCb::TrackLocation::Velo;
-  } else if ( m_inputTracksName == "2D" ) {
-    tracksName = LHCb::TrackLocation::RZVelo;
-  }
+//   // if ( m_inputTracksName == "Offline" ) {
+//   //   tracksName = LHCb::TrackLocation::Default;
+//   // } else if ( m_inputTracksName == "3D" ) {
+//   //   tracksName = LHCb::TrackLocation::Velo;
+//   // } else if ( m_inputTracksName == "2D" ) {
+//   //   tracksName = LHCb::TrackLocation::RZVelo;
+//   // }
 
-  if ( tracksName == "none" ) {
-    debug() << " Tracks not specified " << tracksName << endmsg;
-    return false;
-  }
+//   // if ( tracksName == "none" ) {
+//   //   debug() << " Tracks not specified " << tracksName << endmsg;
+//   //   return false;
+//   // }
 
-  trackLoc = tracksName;
+//   //LHCb::Tracks* usedTracks = getOrCreate<LHCb::Tracks, LHCb::Tracks>( LHCb::TrackLocation::Default );
+//   if ( usedTracks->size() == 0 ) return false;
 
-  LHCb::Tracks* usedTracks;
+//   std::vector<LHCb::Track*>::const_iterator itT;
+//   for ( itT = usedTracks->begin(); usedTracks->end() != itT; itT++ ) {
+//     LHCb::Track* ptr = ( *itT );
+//     vecOfTracks.push_back( ptr );
+//   }
 
-  usedTracks = getOrCreate<LHCb::Tracks, LHCb::Tracks>( tracksName );
-  if ( usedTracks->size() == 0 ) return false;
+//   return true;
+// }
 
-  std::vector<LHCb::Track*>::const_iterator itT;
-  for ( itT = usedTracks->begin(); usedTracks->end() != itT; itT++ ) {
-    LHCb::Track* ptr = ( *itT );
-    vecOfTracks.push_back( ptr );
-  }
+// bool PrimaryVertexChecker::getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const {
 
-  return true;
-}
+//   // std::string verticesName = m_inputVerticesName;
 
-bool PrimaryVertexChecker::getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) {
+//   // if ( m_inputVerticesName == "Offline" ) {
+//   //   verticesName = LHCb::RecVertexLocation::Primary;
+//   // } else if ( m_inputVerticesName == "3D" ) {
+//   //   verticesName = LHCb::RecVertexLocation::Velo3D;
+//   // } else if ( m_inputVerticesName == "2D" ) {
+//   //   verticesName = LHCb::RecVertexLocation::Velo2D;
+//   // }
 
-  std::string verticesName = m_inputVerticesName;
+//   // if ( verticesName == "none" ) {
+//   //   debug() << " Vertices not specified " << verticesName << endmsg;
+//   //   return false;
+//   // }
 
-  if ( m_inputVerticesName == "Offline" ) {
-    verticesName = LHCb::RecVertexLocation::Primary;
-  } else if ( m_inputVerticesName == "3D" ) {
-    verticesName = LHCb::RecVertexLocation::Velo3D;
-  } else if ( m_inputVerticesName == "2D" ) {
-    verticesName = LHCb::RecVertexLocation::Velo2D;
-  }
+//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>( LHCb::RecVertexLocation::Primary );
 
-  if ( verticesName == "none" ) {
-    debug() << " Vertices not specified " << verticesName << endmsg;
-    return false;
-  }
+//   std::vector<LHCb::RecVertex*>::const_iterator itVer;
+//   for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
+//     LHCb::RecVertex* ppv = ( *itVer );
+//     vecOfVertices.push_back( ppv );
+//   }
 
-  LHCb::RecVertices* recoVertices;
-
-  recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>( verticesName );
-
-  std::vector<LHCb::RecVertex*>::const_iterator itVer;
-  for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
-    LHCb::RecVertex* ppv = ( *itVer );
-    vecOfVertices.push_back( ppv );
-  }
-
-  return true;
-}
+//   return true;
+// }
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
index b5d62bd5029..b6eb7ae0c01 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.h
@@ -53,59 +53,71 @@ public:
   LHCb::RecVertex* pRECPV;        // pointer to REC PV
 } RecPVInfo;
 
-class PrimaryVertexChecker : public GaudiTupleAlg {
+class PrimaryVertexChecker : public Gaudi::Functional::Consumer<
+                             void( const LHCb::Tracks&, 
+                                   const LHCb::RecVertices&),
+          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
 
   StatusCode initialize() override; ///< Algorithm initialization
-  StatusCode execute() override;    ///< Algorithm execution
+  void operator()( const LHCb::Tracks& usedTracks, 
+                   const LHCb::RecVertices& recoVertices) const override;    ///< Algorithm execution
   StatusCode finalize() override;   ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  int         m_nTracksToBeRecble;
-  bool        m_produceHistogram;
-  bool        m_produceNtuple;
-  bool        m_requireVelo;
-  double      m_dzIsolated;
-  bool        m_matchByTracks;
-  std::string m_inputTracksName;
-  std::string m_inputVerticesName;
+  //int         m_nTracksToBeRecble;
+  //bool        m_produceHistogram;
+  //bool        m_produceNtuple;
+  //bool        m_requireVelo;
+  //double      m_dzIsolated;
+  //bool        m_matchByTracks;
+  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
+  Gaudi::Property<bool> m_produceHistogram{this, "produceHistogram", true};
+  Gaudi::Property<bool> m_produceNtuple{this, "produceNtuple", false};
+  Gaudi::Property<bool> m_requireVelo{this, "RequireVelo", true};
+  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
+  Gaudi::Property<bool> m_matchByTracks{this, "matchByTracks", true};
+  // Gaudi::Property<std::string> m_inputTracksName{this, "inputTracksName", LHCb::TrackLocation::Default};
+  // Gaudi::Property<std::string> m_inputVerticesName{this, "inputVerticesName", LHCb::RecVertexLocation::Primary};
 
-  int m_nevt;
-  int m_nMCPV, m_nRecMCPV;
-  int m_nMCPV_isol, m_nRecMCPV_isol;
-  int m_nMCPV_close, m_nRecMCPV_close;
-  int m_nFalsePV, m_nFalsePV_real;
-  int m_nMCPV_1mult, m_nRecMCPV_1mult;
-  int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
-  int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
-  int m_nRecMCPV_wrong_1mult;
-  int m_nMCPV_2mult, m_nRecMCPV_2mult;
-  int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
-  int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
-  int m_nRecMCPV_wrong_2mult;
-  int m_nMCPV_3mult, m_nRecMCPV_3mult;
-  int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
-  int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
-  int m_nRecMCPV_wrong_3mult;
-  int m_nBFalse, m_nRecBFalse;
 
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, std::vector<MCPVInfo>::iterator& itmc );
+  mutable int m_nevt;
+  mutable int m_nMCPV, m_nRecMCPV;
+  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
+  mutable int m_nMCPV_close, m_nRecMCPV_close;
+  mutable int m_nFalsePV, m_nFalsePV_real;
+  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
+  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
+  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
+  mutable int m_nRecMCPV_wrong_1mult;
+  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
+  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
+  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
+  mutable int m_nRecMCPV_wrong_2mult;
+  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
+  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
+  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
+  mutable int m_nRecMCPV_wrong_3mult;
+  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
+  mutable int m_nBFalse, m_nRecBFalse;
 
-  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods );
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, std::vector<MCPVInfo>::iterator& itmc ) const;
+
+  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( std::string mes, int a, int b );
-  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec );
-  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec );
+  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-                                   std::string trackLoc );
+                                   std::string trackLoc ) const;
   int  count_velo_tracks( LHCb::RecVertex* RecVtx );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec );
-  bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks, std::string& trackLoc );
-  bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices );
-  int  check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc );
+  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
+  // bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
+  // bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
+  int  check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
 };
 #endif // PRIMARYVERTEXCHECKER_H
-- 
GitLab


From c66ac95ba48f26f8c53456695198451181344ff8 Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 15 Jan 2020 22:02:02 +0000
Subject: [PATCH 13/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/6789764
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 34 +++++++++---------
 Tr/PatChecker/src/PrimaryVertexChecker.h   | 40 ++++++++++------------
 2 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 7782db2ffb0..cbaf546fe63 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -15,6 +15,7 @@
 #include "Event/RecVertex.h"
 #include "Event/State.h"
 #include "Event/Track.h"
+#include "GaudiAlg/Consumer.h"
 #include "GaudiAlg/Tuples.h"
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
@@ -24,7 +25,6 @@
 #include "VeloDet/DeVelo.h"
 #include <Event/MCTrackInfo.h>
 #include <Linker/LinkedTo.h>
-#include "GaudiAlg/Consumer.h"
 // local
 #include "PrimaryVertexChecker.h"
 
@@ -34,20 +34,18 @@ bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > seco
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
 
-
-
 // Declaration of the Algorithm Factory
-DECLARE_COMPONENT( PrimaryVertexChecker ) 
+DECLARE_COMPONENT( PrimaryVertexChecker )
 
 //=============================================================================
 // Standard constructor, initializes variables
 //=============================================================================
 PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-      : Consumer( name, pSvcLocator,
-                                      {
-                                          KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                                          KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
-                                      } ) {}
+    : Consumer( name, pSvcLocator,
+                {
+                    KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                    KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
+                } ) {}
 
 //=============================================================================
 // Initialization
@@ -89,12 +87,10 @@ StatusCode PrimaryVertexChecker::initialize() {
   return StatusCode::SUCCESS;
 }
 
-
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, 
-                   const LHCb::RecVertices& recoVertices) const {
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHCb::RecVertices& recoVertices ) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -104,8 +100,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks,
   // Get input
   std::vector<LHCb::Track*>     vecOfTracks;
   std::vector<LHCb::RecVertex*> vecOfVertices;
-  std::string                   trackLoc = "/Event/Rec/Track/VeloAsTrackV2_v1";
-  bool                          tracks_ok   = true; //getInputTracks( vecOfTracks );
+  std::string                   trackLoc  = "/Event/Rec/Track/VeloAsTrackV2_v1";
+  bool                          tracks_ok = true; // getInputTracks( vecOfTracks );
 
   if ( usedTracks.size() == 0 ) tracks_ok = false;
 
@@ -119,14 +115,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks,
     return; // return SUCCESSS anyway
   }
 
- // bool                          vertices_ok = getInputVertices( vecOfVertices );
+  // bool                          vertices_ok = getInputVertices( vecOfVertices );
   std::vector<LHCb::RecVertex*>::const_iterator itVer;
   for ( itVer = recoVertices.begin(); recoVertices.end() != itVer; itVer++ ) {
     LHCb::RecVertex* ppv = ( *itVer );
     vecOfVertices.push_back( ppv );
   }
 
-//  if ( !vertices_ok ) { return; }
+  //  if ( !vertices_ok ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -886,7 +882,8 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
 }
 
 void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-                                                       std::vector<LHCb::Track*>& vecOfTracks, std::string trackLoc ) const {
+                                                       std::vector<LHCb::Track*>& vecOfTracks,
+                                                       std::string                trackLoc ) const {
 
   LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
 
@@ -1039,7 +1036,8 @@ int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::strin
 //   //   return false;
 //   // }
 
-//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>( LHCb::RecVertexLocation::Primary );
+//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>(
+//   LHCb::RecVertexLocation::Primary );
 
 //   std::vector<LHCb::RecVertex*>::const_iterator itVer;
 //   for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
index b6eb7ae0c01..7038f606a01 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.h
@@ -53,39 +53,36 @@ public:
   LHCb::RecVertex* pRECPV;        // pointer to REC PV
 } RecPVInfo;
 
-class PrimaryVertexChecker : public Gaudi::Functional::Consumer<
-                             void( const LHCb::Tracks&, 
-                                   const LHCb::RecVertices&),
-          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, const LHCb::RecVertices& ),
+                                                                Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void operator()( const LHCb::Tracks& usedTracks, 
-                   const LHCb::RecVertices& recoVertices) const override;    ///< Algorithm execution
-  StatusCode finalize() override;   ///< Algorithm finalization
+  void       operator()( const LHCb::Tracks&      usedTracks,
+                   const LHCb::RecVertices& recoVertices ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                                                ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  //int         m_nTracksToBeRecble;
-  //bool        m_produceHistogram;
-  //bool        m_produceNtuple;
-  //bool        m_requireVelo;
-  //double      m_dzIsolated;
-  //bool        m_matchByTracks;
-  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
-  Gaudi::Property<bool> m_produceHistogram{this, "produceHistogram", true};
-  Gaudi::Property<bool> m_produceNtuple{this, "produceNtuple", false};
-  Gaudi::Property<bool> m_requireVelo{this, "RequireVelo", true};
+  // int         m_nTracksToBeRecble;
+  // bool        m_produceHistogram;
+  // bool        m_produceNtuple;
+  // bool        m_requireVelo;
+  // double      m_dzIsolated;
+  // bool        m_matchByTracks;
+  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
+  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
+  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
+  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  Gaudi::Property<bool> m_matchByTracks{this, "matchByTracks", true};
+  Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", true};
   // Gaudi::Property<std::string> m_inputTracksName{this, "inputTracksName", LHCb::TrackLocation::Default};
   // Gaudi::Property<std::string> m_inputVerticesName{this, "inputVerticesName", LHCb::RecVertexLocation::Primary};
 
-
   mutable int m_nevt;
   mutable int m_nMCPV, m_nRecMCPV;
   mutable int m_nMCPV_isol, m_nRecMCPV_isol;
@@ -106,7 +103,8 @@ private:
   mutable int m_nL0PvOfB, m_nRecL0PvOfB;
   mutable int m_nBFalse, m_nRecBFalse;
 
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, std::vector<MCPVInfo>::iterator& itmc ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                               std::vector<MCPVInfo>::iterator& itmc ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( std::string mes, int a, int b );
@@ -118,6 +116,6 @@ private:
   void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
   // bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
   // bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-  int  check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
+  int check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
 };
 #endif // PRIMARYVERTEXCHECKER_H
-- 
GitLab


From e70031e4f629ac90c0d5232fa9b222ebeb03c0c8 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus711.cern.ch>
Date: Thu, 16 Jan 2020 16:09:44 +0100
Subject: [PATCH 14/42] distance matching, RecoVertex_v2

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 594 ++++++++-------------
 Tr/PatChecker/src/PrimaryVertexChecker.h   |  59 +-
 2 files changed, 247 insertions(+), 406 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index cbaf546fe63..0a02dbc2d67 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -12,9 +12,13 @@
 // from Gaudi
 #include "AIDA/IHistogram1D.h"
 #include "DetDesc/Condition.h"
+#include "DetDesc/ConditionAccessorHolder.h"
+#include "Event/L0DUReport.h"
 #include "Event/RecVertex.h"
 #include "Event/State.h"
 #include "Event/Track.h"
+#include "Event/RecVertex_v2.h"
+#include "Event/Track_v2.h"
 #include "GaudiAlg/Consumer.h"
 #include "GaudiAlg/Tuples.h"
 #include "GaudiKernel/PhysicalConstants.h"
@@ -30,6 +34,17 @@
 
 bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
+namespace {
+  struct Beamline_t {
+    double X = std::numeric_limits<double>::signaling_NaN();
+    double Y = std::numeric_limits<double>::signaling_NaN();
+    Beamline_t( Condition const& c )
+      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+      , Y{c.param<double>( "ResolPosY" )} {}
+  };
+
+}
+
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
@@ -44,7 +59,11 @@ PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator
     : Consumer( name, pSvcLocator,
                 {
                     KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                    KeyValue{"inputVerticesName", LHCb::RecVertexLocation::Primary},
+                    KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+//                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                    KeyValue{"MCVertexInput",LHCb::MCVertexLocation::Default},
+//                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}
                 } ) {}
 
 //=============================================================================
@@ -90,40 +109,22 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHCb::RecVertices& recoVertices ) const {
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
+                                       std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
+                                       const LHCb::MCVertices& mcvtx,
+//                                       const LHCb::MCParticles& mcps,
+//                                       const LHCb::LinksByKey& linker,
+                                       const LHCb::MCHeader& mcheader ) const {
 
   debug() << "==> Execute" << endmsg;
 
   // Event
   m_nevt++;
 
-  // Get input
-  std::vector<LHCb::Track*>     vecOfTracks;
-  std::vector<LHCb::RecVertex*> vecOfVertices;
-  std::string                   trackLoc  = "/Event/Rec/Track/VeloAsTrackV2_v1";
-  bool                          tracks_ok = true; // getInputTracks( vecOfTracks );
-
-  if ( usedTracks.size() == 0 ) tracks_ok = false;
-
-  std::vector<LHCb::Track*>::const_iterator itT;
-  for ( itT = usedTracks.begin(); usedTracks.end() != itT; itT++ ) {
-    LHCb::Track* ptr = ( *itT );
-    vecOfTracks.push_back( ptr );
-  }
-
-  if ( !tracks_ok && m_matchByTracks ) {
-    return; // return SUCCESSS anyway
-  }
-
-  // bool                          vertices_ok = getInputVertices( vecOfVertices );
-  std::vector<LHCb::RecVertex*>::const_iterator itVer;
-  for ( itVer = recoVertices.begin(); recoVertices.end() != itVer; itVer++ ) {
-    LHCb::RecVertex* ppv = ( *itVer );
-    vecOfVertices.push_back( ppv );
+  if ( recoVtx.size()==0) {
+    return;
   }
 
-  //  if ( !vertices_ok ) { return; }
-
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
   const double xRC = 0.0; // myCond -> paramAsDouble ( "ResolPosRC" ) ;
@@ -134,95 +135,41 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
   double m_beamSpotY = Y;
 
   if ( debugLevel() )
-    debug() << trackLoc << " # tracks: " << vecOfTracks.size() << "  # vertices: " << vecOfVertices.size() << endmsg;
+    debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
   std::vector<RecPVInfo>                  recpvvec;
-  std::vector<LHCb::RecVertex*>::iterator itRecV;
-  for ( itRecV = vecOfVertices.begin(); vecOfVertices.end() != itRecV; itRecV++ ) {
-    LHCb::RecVertex* pv;
-    pv = *itRecV;
+  for ( const auto& pv : recoVtx ) {
     RecPVInfo recinfo;
-    recinfo.pRECPV            = pv;
-    recinfo.position          = pv->position();
-    Gaudi::SymMatrix3x3 covPV = pv->covMatrix();
+    recinfo.pRECPV            = (&pv);
+    recinfo.position          = pv.position();
+    Gaudi::SymMatrix3x3 covPV = pv.covMatrix();
     double              sigx  = sqrt( covPV( 0, 0 ) );
     double              sigy  = sqrt( covPV( 1, 1 ) );
     double              sigz  = sqrt( covPV( 2, 2 ) );
     Gaudi::XYZPoint     a3d( sigx, sigy, sigz );
     recinfo.positionSigma = a3d;
-    recinfo.nTracks       = pv->tracks().size();
-    double minRD          = 99999.;
-    double maxRD          = -99999.;
-    double chi2           = pv->chi2();
-    double nDoF           = pv->nDoF();
-
-    std::string                               container = "container";
-    typedef const SmartRefVector<LHCb::Track> PVTRACKS;
-    PVTRACKS&                                 tracksIn = pv->tracks();
-    PVTRACKS::const_iterator                  itin;
+    recinfo.nTracks       = pv.tracks().size();
+    recinfo.chi2          = pv.chi2();
+    recinfo.nDoF          = pv.nDoF();
+    recinfo.indexMCPVInfo = -1;
 
     int    mother    = 0;
-    int    velo      = 0;
-    int    lg        = 0;
-    double d0        = 0;
-    double mind0     = 99999.0;
-    double maxd0     = -99999.0;
-    double trackChi2 = 0.0;
-    int    tr        = 0;
-
-    for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-      tr++;
-      const LHCb::Track* ptr = *itin;
-
-      if ( ptr->type() == LHCb::Track::Types::Long ) { lg++; }
-      if ( ptr->type() == LHCb::Track::Types::Velo ) { velo++; }
-
-      double           x        = ptr->position().x();
-      double           y        = ptr->position().y();
-      double           r2       = x * x + y * y;
-      Gaudi::XYZVector udir     = ptr->firstState().slopes().Unit();
-      Gaudi::XYZVector distance = ptr->firstState().position() - pv->position();
-      Gaudi::XYZVector d0i      = udir.Cross( distance.Cross( udir ) );
-
-      d0 = d0 + d0i.Mag2();
-      if ( d0i.Mag2() > maxd0 ) { maxd0 = d0i.Mag2(); }
-      if ( d0i.Mag2() < mind0 ) { mind0 = d0i.Mag2(); }
-
-      if ( r2 > maxRD ) { maxRD = r2; }
-      if ( r2 < minRD ) { minRD = r2; }
-
-      double trChi2 = ptr->chi2();
-      trackChi2     = trackChi2 + trChi2;
-    }
-
-    if ( m_matchByTracks ) { mother = check_mother_particle( pv, trackLoc ); }
+    //if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
 
-    recinfo.minTrackRD    = minRD;
-    recinfo.maxTrackRD    = maxRD;
     recinfo.mother        = mother;
-    recinfo.chi2          = chi2;
-    recinfo.nDoF          = nDoF;
-    recinfo.d0            = d0;
-    recinfo.d0nTr         = (double)d0 / (double)tr;
-    recinfo.chi2nTr       = (double)trackChi2 / (double)tr;
-    recinfo.mind0         = mind0;
-    recinfo.maxd0         = maxd0;
-    recinfo.nVeloTracks   = velo;
-    recinfo.nLongTracks   = lg;
     recinfo.indexMCPVInfo = -1;
     recpvvec.push_back( recinfo );
   }
 
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
-  LHCb::MCVertices*     mcvtx = get<LHCb::MCVertices>( LHCb::MCVertexLocation::Default );
-  for ( LHCb::MCVertices::const_iterator itMCV = mcvtx->begin(); mcvtx->end() != itMCV; itMCV++ ) {
-    const LHCb::MCParticle* motherPart = ( *itMCV )->mother();
+  for ( const auto& mcpv : mcvtx ) {
+  const LHCb::MCParticle* motherPart = mcpv->mother();
     if ( 0 == motherPart ) {
-      if ( ( *itMCV )->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
+      if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
-        mcprimvert.pMCPV             = *itMCV;
+        mcprimvert.pMCPV             = mcpv;
         mcprimvert.nRecTracks        = 0;
         mcprimvert.nRecBackTracks    = 0;
         mcprimvert.indexRecPVInfo    = -1;
@@ -238,24 +185,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     }
   }
 
-  const LHCb::MCParticle::Container* mcps = get<LHCb::MCParticle::Container>( LHCb::MCParticleLocation::Default );
-
-  int sMCP = 0;
-  int sTr  = vecOfTracks.size();
-  for ( LHCb::MCParticle::Container::const_iterator imc = mcps->begin(); mcps->end() != imc; ++imc ) {
-    const LHCb::MCParticle* dec = *imc;
-    double                  z   = dec->originVertex()->position().z();
-    if ( dec->particleID().threeCharge() != 0 && ( z < 400.0 && z > -600.0 ) ) { sMCP++; }
-  }
-
-  if ( m_matchByTracks ) {
-
-    count_reconstructed_tracks( mcpvvec, vecOfTracks, trackLoc );
-
-  } else {
-
-    count_reconstructible_mc_particles( mcpvvec );
-  }
+  count_reconstructible_mc_particles( mcpvvec );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
 
@@ -272,15 +202,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
 
-  // match MC and REC PVs
-  if ( m_matchByTracks ) {
-
-    for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_tracks( ipv, recpvvec, rblemcpv ); }
-
-  } else {
-
-    for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
-  }
+  for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
@@ -304,7 +226,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
           << format(
                  " %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
                  ipv, recpvvec[ipv].indexMCPVInfo, recpvvec[ipv].position.x(), recpvvec[ipv].position.y(),
-                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks, recpvvec[ipv].nVeloTracks,
+                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks,
                  recpvvec[ipv].positionSigma.x(), recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(),
                  recpvvec[ipv].pRECPV->chi2PerDoF() )
           << ff << endmsg;
@@ -326,16 +248,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     double erry       = recpvvec[ipv].positionSigma.y();
     double errz       = recpvvec[ipv].positionSigma.z();
     double errr       = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-    double minRDTrack = recpvvec[ipv].minTrackRD;
-    double maxRDTrack = recpvvec[ipv].maxTrackRD;
     int    mother     = recpvvec[ipv].mother;
-    double velo       = recpvvec[ipv].nVeloTracks;
-    double lg         = recpvvec[ipv].nLongTracks;
-    double d0         = recpvvec[ipv].d0;
-    double d0nTr      = recpvvec[ipv].d0nTr;
-    double chi2nTr    = recpvvec[ipv].chi2nTr;
-    double mind0      = recpvvec[ipv].mind0;
-    double maxd0      = recpvvec[ipv].maxd0;
     double chi2       = recpvvec[ipv].chi2;
     double nDoF       = recpvvec[ipv].nDoF;
 
@@ -356,28 +269,19 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     }
     if ( m_produceNtuple ) {
       Tuple myTuple2 = nTuple( 102, "PV_nTuple2", CLID_ColumnWiseTuple );
-      myTuple2->column( "fake", double( fake ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "r", double( r ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "x", double( x ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "y", double( y ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "z", double( z ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "errr", double( errr ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "errz", double( errz ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "errx", double( errx ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "erry", double( erry ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "minRDTrack", double( minRDTrack ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "maxRDTrack", double( maxRDTrack ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "mother", double( mother ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "velo", double( velo ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "long", double( lg ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "d0", double( d0 ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "d0nTr", double( d0nTr ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "chi2nTr", double( chi2nTr ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "mind0", double( mind0 ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "maxd0", double( maxd0 ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "chi2", double( chi2 ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->column( "nDoF", double( nDoF ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple2->write().ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
+      myTuple2->column( "fake", double( fake ) );
+      myTuple2->column( "r", double( r ) );
+      myTuple2->column( "x", double( x ) );
+      myTuple2->column( "y", double( y ) );
+      myTuple2->column( "z", double( z ) );
+      myTuple2->column( "errr", double( errr ) );
+      myTuple2->column( "errz", double( errz ) );
+      myTuple2->column( "errx", double( errx ) );
+      myTuple2->column( "erry", double( erry ) );
+      myTuple2->column( "mother", double( mother ) );
+      myTuple2->column( "chi2", double( chi2 ) );
+      myTuple2->column( "nDoF", double( nDoF ) );
+      myTuple2->write();
     }
   }
   // Fill distance to closest recble MC PV and its multiplicity
@@ -537,14 +441,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     double erry              = -99999.;
     double errz              = -99999.;
     double errr              = -99999.;
-    double minRDTrack        = 99999.;
-    double maxRDTrack        = -99999.;
     double chi2              = -999999.;
     double nDoF              = -999999.;
     int    indRec            = itmc->indexRecPVInfo;
     int    reconstructed     = 0;
     int    ntracks_pvrec     = 0;
-    int    nvelotracks_pvrec = 0;
     int    ntracks_pvmc      = 0;
     int    dtrcks            = 0;
     int    pvevt             = 0;
@@ -574,11 +475,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
       errz = recpvvec[indRec].positionSigma.z();
       errr = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
       ntracks_pvrec     = recpvvec[indRec].nTracks;
-      nvelotracks_pvrec = recpvvec[indRec].nVeloTracks;
       ntracks_pvmc      = itmc->pMCPV->products().size();
       dtrcks            = ntracks_pvmc - ntracks_pvrec;
-      minRDTrack        = recpvvec[indRec].minTrackRD;
-      maxRDTrack        = recpvvec[indRec].maxTrackRD;
       mother            = recpvvec[indRec].mother;
       chi2              = recpvvec[indRec].chi2;
       nDoF              = recpvvec[indRec].nDoF;
@@ -599,13 +497,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
         plot( double( ntracks_pvrec ), 1041, "ntracks_pvrec", 0., 150., 50 );
         plot( double( dtrcks ), 1042, "mcrdtracks", 0., 150., 50 );
-        plot( double( nvelotracks_pvrec ), 1043, "nvelotracks_pvrec", 0., 150., 50 );
         if ( pvevt == 1 ) {
           plot( double( recpvvec.size() ), 1051, "nPVperEvt", -0.5, 5.5, 6 );
           for ( int ipvrec = 0; ipvrec < (int)recpvvec.size(); ipvrec++ ) {
             assoctrks = assoctrks + recpvvec[ipvrec].nTracks;
           }
-          nassoctrks = vecOfTracks.size() - assoctrks;
+          nassoctrks = tracks.size() - assoctrks;
           plot( double( nassoctrks ), 1052, "nassoctrks", 0., 150., 50 );
         }
       }
@@ -614,92 +511,86 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& usedTracks, const LHC
     int    isolated     = 0;
     double dist_closest = itmc->distToClosestMCPV;
     if ( dist_closest > m_dzIsolated ) { isolated = 1; }
-
     // Filling ntuple
     if ( m_produceNtuple ) {
       Tuple myTuple = nTuple( 101, "PV_nTuple", CLID_ColumnWiseTuple );
-      myTuple->column( "reco", double( reconstructed ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "isol", double( isolated ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "ntracks", double( ntracks_pvrec ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "nvelotracks", double( nvelotracks_pvrec ) )
-          .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "nrectrmc", double( itmc->nRecTracks ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "dzclose", dist_closest ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "nmcpv", double( rblemcpv.size() ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "nmcallpv", double( mcpvvec.size() ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "nrecpv", double( recpvvec.size() ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "decayCharm", double( itmc->decayCharm ) )
-          .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "decayBeauty", double( itmc->decayBeauty ) )
-          .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "multi", double( high ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "dx", dx ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "dy", dy ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "dz", dz ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "x", x ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "y", y ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "r", r ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "zMC", zMC ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "yMC", yMC ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "xMC", xMC ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "rMC", rMC ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "z", z ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "xBeam", m_beamSpotX ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "yBeam", m_beamSpotY ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "errx", errx ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "erry", erry ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "errz", errz ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "errr", errr ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "minRDTrack", minRDTrack ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "maxRDTrack", maxRDTrack ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "mother", double( mother ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "evtnr", double( m_nevt ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "chi2", double( chi2 ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "nDoF", double( nDoF ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "size_tracks", double( sTr ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "size_mcp", double( sMCP ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->column( "mcpvrec", double( nmrc ) ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
-      myTuple->write().ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
+      myTuple->column( "reco", double( reconstructed ) );
+      myTuple->column( "isol", double( isolated ) );
+      myTuple->column( "ntracks", double( ntracks_pvrec ) );
+      myTuple->column( "nrectrmc", double( itmc->nRecTracks ) );
+      myTuple->column( "dzclose", dist_closest );
+      myTuple->column( "nmcpv", double( rblemcpv.size() ) );
+      myTuple->column( "mtruemcpv",double(mcheader.numOfPrimaryVertices()));
+      myTuple->column( "nmcallpv", double( mcpvvec.size() ) );
+      myTuple->column( "nrecpv", double( recpvvec.size() ) );
+      myTuple->column( "decayCharm", double( itmc->decayCharm ) );
+      myTuple->column( "decayBeauty", double( itmc->decayBeauty ) );
+      myTuple->column( "multi", double( high ) );
+      myTuple->column( "dx", dx );
+      myTuple->column( "dy", dy );
+      myTuple->column( "dz", dz );
+      myTuple->column( "x", x );
+      myTuple->column( "y", y );
+      myTuple->column( "r", r );
+      myTuple->column( "zMC", zMC );
+      myTuple->column( "yMC", yMC );
+      myTuple->column( "xMC", xMC );
+      myTuple->column( "rMC", rMC );
+      myTuple->column( "z", z );
+      myTuple->column( "xBeam", m_beamSpotX );
+      myTuple->column( "yBeam", m_beamSpotY );
+      myTuple->column( "errx", errx );
+      myTuple->column( "erry", erry );
+      myTuple->column( "errz", errz );
+      myTuple->column( "errr", errr );
+      myTuple->column( "mother", double( mother ) );
+      myTuple->column( "evtnr", double( m_nevt ) );
+      myTuple->column( "chi2", double( chi2 ) );
+      myTuple->column( "nDoF", double( nDoF ) );
+      myTuple->column( "size_tracks", double( tracks.size() ) );
+      // myTuple->column( "size_mcp", double( sMCP ) );
+      myTuple->column( "mcpvrec", double( nmrc ) );
+      myTuple->write();
     }
   }
 
   return;
 }
 
-void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
-                                                      std::vector<MCPVInfo>& mcpvvec ) const {
-
-  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
-  typedef const SmartRefVector<LHCb::Track> PVTRACKS;
-  PVTRACKS&                                 tracksIn = invtx->tracks();
-  PVTRACKS::const_iterator                  itin;
-
-  int    indexmc  = -1;
-  double ratiomax = 0.;
-  for ( int imc = 0; imc < (int)mcpvvec.size(); imc++ ) {
-    if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
-    int ntrin = 0;
-    for ( std::vector<LHCb::Track*>::iterator itr = mcpvvec[imc].m_recTracksInMCPV.begin();
-          itr != mcpvvec[imc].m_recTracksInMCPV.end(); itr++ ) {
-      for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-        const LHCb::Track* ptr = *itin;
-        if ( ptr == *itr ) {
-          ntrin++;
-          break;
-        }
-      }
-    }
-    double ratio = 1. * ntrin / tracksIn.size();
-    if ( ratio > ratiomax ) {
-      ratiomax = ratio;
-      indexmc  = imc;
-    }
-  } // imc
-  if ( ratiomax > 0.05 ) {
-    rinfo[ipv].indexMCPVInfo        = indexmc;
-    mcpvvec[indexmc].indexRecPVInfo = ipv;
-  }
-}
+//void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
+//                                                      std::vector<MCPVInfo>& mcpvvec ) const {
+//
+//  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
+//  typedef const SmartRefVector<LHCb::Track> PVTRACKS;
+//  PVTRACKS&                                 tracksIn = invtx->tracks();
+//  PVTRACKS::const_iterator                  itin;
+//
+//  int    indexmc  = -1;
+//  double ratiomax = 0.;
+//  for ( int imc = 0; imc < (int)mcpvvec.size(); imc++ ) {
+//    if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
+//    int ntrin = 0;
+//    for ( std::vector<LHCb::Track*>::iterator itr = mcpvvec[imc].m_recTracksInMCPV.begin();
+//          itr != mcpvvec[imc].m_recTracksInMCPV.end(); itr++ ) {
+//      for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
+//        const LHCb::Track* ptr = *itin;
+//        if ( ptr == *itr ) {
+//          ntrin++;
+//          break;
+//        }
+//      }
+//    }
+//    double ratio = 1. * ntrin / tracksIn.size();
+//    if ( ratio > ratiomax ) {
+//      ratiomax = ratio;
+//      indexmc  = imc;
+//    }
+//  } // imc
+//  if ( ratiomax > 0.05 ) {
+//    rinfo[ipv].indexMCPVInfo        = indexmc;
+//    mcpvvec[indexmc].indexRecPVInfo = ipv;
+//  }
+//}
 
 void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo,
                                                         std::vector<MCPVInfo>& mcpvvec ) const {
@@ -772,8 +663,7 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble << "  tracks are reconstructed" << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated << " mm" << endmsg;
-  std::string ff = "by counting tracks";
-  if ( !m_matchByTracks ) ff = "by dz distance";
+  std::string ff = "by dz distance";
   info() << " REC and MC vertices matched:  " << ff << endmsg;
 
   info() << " " << endmsg;
@@ -881,54 +771,52 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
   info() << pmes << format( " %6.3f ( %7d / %8d )", rat, a, b ) << endmsg;
 }
 
-void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-                                                       std::vector<LHCb::Track*>& vecOfTracks,
-                                                       std::string                trackLoc ) const {
-
-  LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
-
-  // Find # of reconstructed tracks of every MC PV
-  std::vector<MCPVInfo>::iterator itinfomc;
-  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
-    LHCb::MCVertex* avtx = itinfomc->pMCPV;
-
-    SmartRefVector<LHCb::MCParticle> parts = avtx->products();
-    std::vector<LHCb::MCParticle*>   allproducts;
-    collectProductss( avtx, avtx, allproducts );
-
-    LHCb::Track*                             recTrack = 0;
-    std::vector<LHCb::MCParticle*>::iterator imcp;
-    for ( imcp = allproducts.begin(); allproducts.end() != imcp; imcp++ ) {
-      LHCb::MCParticle* pmcp   = *imcp;
-      int               isReco = 0;
-      for ( std::vector<LHCb::Track*>::iterator itrec = vecOfTracks.begin(); itrec != vecOfTracks.end(); itrec++ ) {
-        LHCb::MCParticle* partmc = trackMClink.first( ( *itrec )->key() );
-        if ( partmc && partmc == pmcp ) {
-          recTrack = ( *itrec );
-          if ( !m_requireVelo || recTrack->hasVelo() ) {
-            isReco = 1;
-            break;
-          }
-        }
-      }
-      if ( pmcp->particleID().threeCharge() != 0 && isReco ) {
-        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-        if ( dv2 < 0.0001 ) {
-          itinfomc->m_mcPartInMCPV.push_back( pmcp );
-          itinfomc->m_recTracksInMCPV.push_back( recTrack );
-        }
-      }
-    }
-    itinfomc->nRecTracks = itinfomc->m_mcPartInMCPV.size();
-  }
-}
-
-int PrimaryVertexChecker::count_velo_tracks( LHCb::RecVertex* RecVtx ) {
-  SmartRefVector<LHCb::Track> vtx_tracks  = RecVtx->tracks();
+//void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
+//                                                       std::vector<LHCb::Track*>& vecOfTracks,
+//                                                       std::string                trackLoc ) const {
+//
+//  LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
+//
+//  // Find # of reconstructed tracks of every MC PV
+//  std::vector<MCPVInfo>::iterator itinfomc;
+//  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
+//    LHCb::MCVertex* avtx = itinfomc->pMCPV;
+//
+//    SmartRefVector<LHCb::MCParticle> parts = avtx->products();
+//    std::vector<LHCb::MCParticle*>   allproducts;
+//    collectProductss( avtx, avtx, allproducts );
+//
+//    LHCb::Track*                             recTrack = 0;
+//    std::vector<LHCb::MCParticle*>::iterator imcp;
+//    for ( imcp = allproducts.begin(); allproducts.end() != imcp; imcp++ ) {
+//      LHCb::MCParticle* pmcp   = *imcp;
+//      int               isReco = 0;
+//      for ( std::vector<LHCb::Track*>::iterator itrec = vecOfTracks.begin(); itrec != vecOfTracks.end(); itrec++ ) {
+//        LHCb::MCParticle* partmc = trackMClink.first( ( *itrec )->key() );
+//        if ( partmc && partmc == pmcp ) {
+//          recTrack = ( *itrec );
+//          if ( !m_requireVelo || recTrack->hasVelo() ) {
+//            isReco = 1;
+//            break;
+//          }
+//        }
+//      }
+//      if ( pmcp->particleID().threeCharge() != 0 && isReco ) {
+//        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
+//        if ( dv2 < 0.0001 ) {
+//          itinfomc->m_mcPartInMCPV.push_back( pmcp );
+//          itinfomc->m_recTracksInMCPV.push_back( recTrack );
+//        }
+//      }
+//    }
+//    itinfomc->nRecTracks = itinfomc->m_mcPartInMCPV.size();
+//  }
+//}
+
+int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
   int                         nVeloTracks = 0;
-  for ( unsigned int it = 0; it < vtx_tracks.size(); it++ ) {
-    const LHCb::Track* ptr = vtx_tracks[it];
-    if ( ptr->hasVelo() ) nVeloTracks++;
+  for( const auto& track: tracksPV ) {
+    if ( track.track->hasVelo() ) nVeloTracks++;
   }
   return nVeloTracks;
 }
@@ -958,92 +846,48 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     }
   }
 }
-int PrimaryVertexChecker::check_mother_particle( LHCb::RecVertex* pv, std::string trackLoc ) const {
-
-  int         motherPart = 0;
-  const auto& tracksIn   = pv->tracks();
-
-  LinkedTo<LHCb::MCParticle, LHCb::Track> link( eventSvc(), msgSvc(), trackLoc );
-  for ( const LHCb::Track* ptr : tracksIn ) {
-
-    LHCb::MCParticle* part = nullptr;
-    part                   = link.first( ptr->key() );
-    if ( part != nullptr ) {
-      const LHCb::MCParticle* part1 = part;
-      int                     i     = 0;
-      while ( part1 != nullptr ) {
-        // std::cout<<"X"<<std::endl;
-        const LHCb::MCParticle* mother = part1->mother();
-        if ( mother != nullptr ) {
-          i     = i + 1;
-          part1 = mother;
-          /// std::cout<<i<<": "<<part1->particleID().pid()<<std::endl;
-        } else {
-          break;
-        }
-      }
-
-      if ( part1->particleID().hasBottom() == true ) { motherPart = 2.0; }
-      if ( part1->particleID().hasCharm() == true ) { motherPart = 1.0; }
-    }
-  }
-  return motherPart;
-}
-
-// bool PrimaryVertexChecker::getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const {
-
-//   // std::string tracksName = m_inputTracksName;
-
-//   // if ( m_inputTracksName == "Offline" ) {
-//   //   tracksName = LHCb::TrackLocation::Default;
-//   // } else if ( m_inputTracksName == "3D" ) {
-//   //   tracksName = LHCb::TrackLocation::Velo;
-//   // } else if ( m_inputTracksName == "2D" ) {
-//   //   tracksName = LHCb::TrackLocation::RZVelo;
-//   // }
-
-//   // if ( tracksName == "none" ) {
-//   //   debug() << " Tracks not specified " << tracksName << endmsg;
-//   //   return false;
-//   // }
-
-//   //LHCb::Tracks* usedTracks = getOrCreate<LHCb::Tracks, LHCb::Tracks>( LHCb::TrackLocation::Default );
-//   if ( usedTracks->size() == 0 ) return false;
-
-//   std::vector<LHCb::Track*>::const_iterator itT;
-//   for ( itT = usedTracks->begin(); usedTracks->end() != itT; itT++ ) {
-//     LHCb::Track* ptr = ( *itT );
-//     vecOfTracks.push_back( ptr );
-//   }
-
-//   return true;
-// }
-
-// bool PrimaryVertexChecker::getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const {
-
-//   // std::string verticesName = m_inputVerticesName;
-
-//   // if ( m_inputVerticesName == "Offline" ) {
-//   //   verticesName = LHCb::RecVertexLocation::Primary;
-//   // } else if ( m_inputVerticesName == "3D" ) {
-//   //   verticesName = LHCb::RecVertexLocation::Velo3D;
-//   // } else if ( m_inputVerticesName == "2D" ) {
-//   //   verticesName = LHCb::RecVertexLocation::Velo2D;
-//   // }
-
-//   // if ( verticesName == "none" ) {
-//   //   debug() << " Vertices not specified " << verticesName << endmsg;
-//   //   return false;
-//   // }
-
-//   //LHCb::RecVertices* recoVertices = getOrCreate<LHCb::RecVertices, LHCb::RecVertices>(
-//   LHCb::RecVertexLocation::Primary );
 
-//   std::vector<LHCb::RecVertex*>::const_iterator itVer;
-//   for ( itVer = recoVertices->begin(); recoVertices->end() != itVer; itVer++ ) {
-//     LHCb::RecVertex* ppv = ( *itVer );
-//     vecOfVertices.push_back( ppv );
-//   }
+//int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
+//                                                 const LHCb::MCParticles& mcps,
+//                                                 const LHCb::LinksByKey& linker  ) const {
+//
+//  int         motherPart = 0;
+//  for ( const auto& tr : tracksPV ) {
+//
+//    double                  maxWeight{0};
+//    const LHCb::MCParticle* mcp{nullptr};
+//    linker.applyToLinks( tr.track->key(),
+//                        [&maxWeight, &mcp, &mcps]( unsigned int, unsigned int mcPartKey, float weight ) {
+//                          if ( weight > maxWeight ) {
+//                            maxWeight = weight;
+//                            mcp       = static_cast<const LHCb::MCParticle*>( mcps.containedObject( mcPartKey ) );
+//                          }
+//                        } );
+//
+//  LinkedTo<LHCb::MCParticle, LHCb::Track> link( eventSvc(), msgSvc(), trackLoc );
+//  for ( auto itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
+//    const LHCb::Track* ptr  = *itin;
+//    LHCb::MCParticle*  part = nullptr;
+//    part                    = link.first( ptr->key() );
+//    if ( part != nullptr ) {
+//      const LHCb::MCParticle* part1 = part;
+//      int                     i     = 0;
+//      while ( part1 != nullptr ) {
+//        // std::cout<<"X"<<std::endl;
+//        const LHCb::MCParticle* mother = part1->mother();
+//        if ( mother != nullptr ) {
+//          i     = i + 1;
+//          part1 = mother;
+//          /// std::cout<<i<<": "<<part1->particleID().pid()<<std::endl;
+//        } else {
+//          break;
+//        }
+//      }
+//
+//      if ( part1->particleID().hasBottom() == true ) { motherPart = 2.0; }
+//      if ( part1->particleID().hasCharm() == true ) { motherPart = 1.0; }
+//    }
+//  }
+//  return motherPart;
+//}
 
-//   return true;
-// }
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
index 7038f606a01..ffbca8242fa 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.h
@@ -13,6 +13,9 @@
 
 #include "Event/MCVertex.h"
 #include "Event/RecVertex.h"
+#include "Event/MCHeader.h"
+#include "Event/MCParticle.h"
+#include "Event/MCVertex.h"
 #include "Event/Track.h"
 #include "MCInterfaces/IForcedBDecayTool.h"
 
@@ -35,54 +38,47 @@ typedef struct {
 typedef struct {
 public:
   int              nTracks;     // number of tracks
-  int              nVeloTracks; // number of velo tracks in a vertex
-  int              nLongTracks;
-  double           minTrackRD; //
-  double           maxTrackRD; //
   double           chi2;
   double           nDoF;
-  double           d0;
-  double           d0nTr;
-  double           chi2nTr;
-  double           mind0;
-  double           maxd0;
   int              mother;
   Gaudi::XYZPoint  position;      // position
   Gaudi::XYZPoint  positionSigma; // position sigmas
   int              indexMCPVInfo; // index to MCPVInfo
-  LHCb::RecVertex* pRECPV;        // pointer to REC PV
+  const LHCb::Event::v2::RecVertex* pRECPV;
+//  LHCb::RecVertex* pRECPV;        // pointer to REC PV
 } RecPVInfo;
 
-class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, const LHCb::RecVertices& ),
+class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&,
+                                                                      std::vector<LHCb::Event::v2::RecVertex> const& vertices, //const LHCb::RecVertices&,
+                                                                      const LHCb::MCVertices&,
+                                                                      //const LHCb::MCParticles&,
+                                                                      //const LHCb::LinksByKey&,
+                                                                      const LHCb::MCHeader& ),
                                                                 Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks&      usedTracks,
-                   const LHCb::RecVertices& recoVertices ) const override; ///< Algorithm execution
+  void       operator()( const LHCb::Tracks& tracks,
+                         //const LHCb::RecVertices& recoVtx,
+                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
+                         const LHCb::MCVertices& mcvtx,
+                         // const LHCb::MCParticles& mcps,
+                         //const LHCb::LinksByKey& linker,
+                         const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
   StatusCode finalize() override;                                                ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  // int         m_nTracksToBeRecble;
-  // bool        m_produceHistogram;
-  // bool        m_produceNtuple;
-  // bool        m_requireVelo;
-  // double      m_dzIsolated;
-  // bool        m_matchByTracks;
-  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 5};
+  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
   Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
   Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
   Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", true};
-  // Gaudi::Property<std::string> m_inputTracksName{this, "inputTracksName", LHCb::TrackLocation::Default};
-  // Gaudi::Property<std::string> m_inputVerticesName{this, "inputVerticesName", LHCb::RecVertexLocation::Primary};
-
+  
   mutable int m_nevt;
   mutable int m_nMCPV, m_nRecMCPV;
   mutable int m_nMCPV_isol, m_nRecMCPV_isol;
@@ -108,14 +104,15 @@ private:
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( std::string mes, int a, int b );
-  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+//  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-                                   std::string trackLoc ) const;
-  int  count_velo_tracks( LHCb::RecVertex* RecVtx );
+//  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
+//                                   std::string trackLoc ) const;
+  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
   void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
-  // bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
-  // bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-  int check_mother_particle( LHCb::RecVertex* RecVtx, std::string trackLoc ) const;
+//   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
+//   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
+//  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles& mcps, const LHCb::LinksByKey& linker ) const;
 };
 #endif // PRIMARYVERTEXCHECKER_H
+
-- 
GitLab


From 9dbfa2dab6b26daefd69307370937a67d1465c16 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus724.cern.ch>
Date: Thu, 16 Jan 2020 20:16:39 +0100
Subject: [PATCH 15/42] merged headers into source

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 275 ++++++++++++++-------
 Tr/PatChecker/src/PrimaryVertexChecker.h   | 118 ---------
 2 files changed, 182 insertions(+), 211 deletions(-)
 delete mode 100644 Tr/PatChecker/src/PrimaryVertexChecker.h

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 0a02dbc2d67..19aac0836ee 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -8,29 +8,140 @@
 * granted to it by virtue of its status as an Intergovernmental Organization  *
 * or submit itself to any jurisdiction.                                       *
 \*****************************************************************************/
-// Include files
-// from Gaudi
+
 #include "AIDA/IHistogram1D.h"
 #include "DetDesc/Condition.h"
 #include "DetDesc/ConditionAccessorHolder.h"
 #include "Event/L0DUReport.h"
+#include "Event/MCHeader.h"
+#include "Event/MCParticle.h"
+#include "Event/MCVertex.h"
 #include "Event/RecVertex.h"
+#include "Event/RecVertex_v2.h"
 #include "Event/State.h"
 #include "Event/Track.h"
-#include "Event/RecVertex_v2.h"
 #include "Event/Track_v2.h"
 #include "GaudiAlg/Consumer.h"
+#include "GaudiAlg/GaudiTupleAlg.h"
 #include "GaudiAlg/Tuples.h"
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
 #include "Linker/AllLinks.h"
 #include "Linker/LinkerWithKey.h"
+#include "MCInterfaces/IForcedBDecayTool.h"
 #include "VeloDet/DeVelo.h"
 #include <Event/MCTrackInfo.h>
 #include <Linker/LinkedTo.h>
-// local
-#include "PrimaryVertexChecker.h"
+
+//-----------------------------------------------------------------------------
+// Implementation file for class : PrimaryVertexChecker
+//-----------------------------------------------------------------------------
+
+typedef struct {
+  LHCb::MCVertex*                pMCPV;             // pointer to MC PV
+  int                            nRecTracks;        // number of reconstructed tracks from this MCPV
+  int                            nRecBackTracks;    // number of reconstructed backward tracks
+  int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
+  int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
+  int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
+  double                         distToClosestMCPV; // distance to closest reconstructible MCPV
+  int                            decayCharm;        // type of mother particle
+  int                            decayBeauty;
+  std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
+  std::vector<LHCb::Track*>      m_recTracksInMCPV;
+} MCPVInfo;
+
+typedef struct {
+public:
+  int                               nTracks; // number of tracks
+  double                            chi2;
+  double                            nDoF;
+  int                               mother;
+  Gaudi::XYZPoint                   position;      // position
+  Gaudi::XYZPoint                   positionSigma; // position sigmas
+  int                               indexMCPVInfo; // index to MCPVInfo
+  const LHCb::Event::v2::RecVertex* pRECPV;
+  //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
+} RecPVInfo;
+
+class PrimaryVertexChecker
+    : public Gaudi::Functional::Consumer<
+          void( const LHCb::Tracks&,
+                std::vector<LHCb::Event::v2::RecVertex> const& vertices, // const LHCb::RecVertices&,
+                const LHCb::MCVertices&,
+                // const LHCb::MCParticles&,
+                // const LHCb::LinksByKey&,
+                const LHCb::MCHeader& ),
+          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+public:
+  /// Standard constructor
+  PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
+      : Consumer{ name,
+                  pSvcLocator,
+                  {KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                  KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                  //                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                  KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                  //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+                  KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}}} {}
+
+  StatusCode initialize() override; ///< Algorithm initialization
+  void       operator()( const LHCb::Tracks& tracks,
+                   // const LHCb::RecVertices& recoVtx,
+                   std::vector<LHCb::Event::v2::RecVertex> const& vertices, const LHCb::MCVertices& mcvtx,
+                   // const LHCb::MCParticles& mcps,
+                   // const LHCb::LinksByKey& linker,
+                   const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                                         ///< Algorithm finalization
+
+protected:
+  bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
+
+private:
+  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
+  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
+  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
+  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
+  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
+  // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
+
+  mutable int m_nevt;
+  mutable int m_nMCPV, m_nRecMCPV;
+  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
+  mutable int m_nMCPV_close, m_nRecMCPV_close;
+  mutable int m_nFalsePV, m_nFalsePV_real;
+  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
+  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
+  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
+  mutable int m_nRecMCPV_wrong_1mult;
+  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
+  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
+  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
+  mutable int m_nRecMCPV_wrong_2mult;
+  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
+  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
+  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
+  mutable int m_nRecMCPV_wrong_3mult;
+  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
+  mutable int m_nBFalse, m_nRecBFalse;
+
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                               std::vector<MCPVInfo>::iterator& itmc ) const;
+
+  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
+  void printRat( std::string mes, int a, int b );
+  //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
+  //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
+  //                                   std::string trackLoc ) const;
+  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
+  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
+  //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
+  //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
+  //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
+  //  mcps, const LHCb::LinksByKey& linker ) const;
+};
 
 bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
@@ -39,33 +150,15 @@ namespace {
     double X = std::numeric_limits<double>::signaling_NaN();
     double Y = std::numeric_limits<double>::signaling_NaN();
     Beamline_t( Condition const& c )
-      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
-      , Y{c.param<double>( "ResolPosY" )} {}
+        : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+        , Y{c.param<double>( "ResolPosY" )} {}
   };
 
-}
-
-//-----------------------------------------------------------------------------
-// Implementation file for class : PrimaryVertexChecker
-//-----------------------------------------------------------------------------
+} // namespace
 
 // Declaration of the Algorithm Factory
 DECLARE_COMPONENT( PrimaryVertexChecker )
 
-//=============================================================================
-// Standard constructor, initializes variables
-//=============================================================================
-PrimaryVertexChecker::PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-    : Consumer( name, pSvcLocator,
-                {
-                    KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                    KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-//                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                    KeyValue{"MCVertexInput",LHCb::MCVertexLocation::Default},
-//                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}
-                } ) {}
-
 //=============================================================================
 // Initialization
 //=============================================================================
@@ -109,11 +202,11 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
+void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
                                        std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
-                                       const LHCb::MCVertices& mcvtx,
-//                                       const LHCb::MCParticles& mcps,
-//                                       const LHCb::LinksByKey& linker,
+                                       const LHCb::MCVertices&                        mcvtx,
+                                       // const LHCb::MCParticles& mcps,
+                                       // const LHCb::LinksByKey& linker,
                                        const LHCb::MCHeader& mcheader ) const {
 
   debug() << "==> Execute" << endmsg;
@@ -121,9 +214,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   // Event
   m_nevt++;
 
-  if ( recoVtx.size()==0) {
-    return;
-  }
+  if ( recoVtx.size() == 0 ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -134,14 +225,13 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   double m_beamSpotX = ( xRC + xLA ) / 2;
   double m_beamSpotY = Y;
 
-  if ( debugLevel() )
-    debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
+  if ( debugLevel() ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
-  std::vector<RecPVInfo>                  recpvvec;
+  std::vector<RecPVInfo> recpvvec;
   for ( const auto& pv : recoVtx ) {
     RecPVInfo recinfo;
-    recinfo.pRECPV            = (&pv);
+    recinfo.pRECPV            = ( &pv );
     recinfo.position          = pv.position();
     Gaudi::SymMatrix3x3 covPV = pv.covMatrix();
     double              sigx  = sqrt( covPV( 0, 0 ) );
@@ -154,8 +244,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
     recinfo.nDoF          = pv.nDoF();
     recinfo.indexMCPVInfo = -1;
 
-    int    mother    = 0;
-    //if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
+    int mother = 0;
+    // if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
 
     recinfo.mother        = mother;
     recinfo.indexMCPVInfo = -1;
@@ -165,7 +255,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
   for ( const auto& mcpv : mcvtx ) {
-  const LHCb::MCParticle* motherPart = mcpv->mother();
+    const LHCb::MCParticle* motherPart = mcpv->mother();
     if ( 0 == motherPart ) {
       if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
@@ -226,9 +316,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
           << format(
                  " %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
                  ipv, recpvvec[ipv].indexMCPVInfo, recpvvec[ipv].position.x(), recpvvec[ipv].position.y(),
-                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks,
-                 recpvvec[ipv].positionSigma.x(), recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(),
-                 recpvvec[ipv].pRECPV->chi2PerDoF() )
+                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks, recpvvec[ipv].positionSigma.x(),
+                 recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(), recpvvec[ipv].pRECPV->chi2PerDoF() )
           << ff << endmsg;
     }
     debug() << " -----------------------------------" << endmsg;
@@ -239,18 +328,18 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   int nFalsePV      = 0;
   int nFalsePV_real = 0;
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) {
-    int    fake       = 0;
-    double x          = recpvvec[ipv].position.x();
-    double y          = recpvvec[ipv].position.y();
-    double z          = recpvvec[ipv].position.z();
-    double r          = std::sqrt( x * x + y * y );
-    double errx       = recpvvec[ipv].positionSigma.x();
-    double erry       = recpvvec[ipv].positionSigma.y();
-    double errz       = recpvvec[ipv].positionSigma.z();
-    double errr       = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-    int    mother     = recpvvec[ipv].mother;
-    double chi2       = recpvvec[ipv].chi2;
-    double nDoF       = recpvvec[ipv].nDoF;
+    int    fake   = 0;
+    double x      = recpvvec[ipv].position.x();
+    double y      = recpvvec[ipv].position.y();
+    double z      = recpvvec[ipv].position.z();
+    double r      = std::sqrt( x * x + y * y );
+    double errx   = recpvvec[ipv].positionSigma.x();
+    double erry   = recpvvec[ipv].positionSigma.y();
+    double errz   = recpvvec[ipv].positionSigma.z();
+    double errr   = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
+    int    mother = recpvvec[ipv].mother;
+    double chi2   = recpvvec[ipv].chi2;
+    double nDoF   = recpvvec[ipv].nDoF;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
       nFalsePV++;
@@ -426,32 +515,32 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   int high = 0;
 
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
-    double x                 = -99999.;
-    double y                 = -99999.;
-    double dx                = -99999.;
-    double dy                = -99999.;
-    double dz                = -99999.;
-    double r                 = -99999.;
-    double zMC               = -99999.;
-    double yMC               = -99999.;
-    double xMC               = -99999.;
-    double rMC               = -99999.;
-    double z                 = -99999.;
-    double errx              = -99999.;
-    double erry              = -99999.;
-    double errz              = -99999.;
-    double errr              = -99999.;
-    double chi2              = -999999.;
-    double nDoF              = -999999.;
-    int    indRec            = itmc->indexRecPVInfo;
-    int    reconstructed     = 0;
-    int    ntracks_pvrec     = 0;
-    int    ntracks_pvmc      = 0;
-    int    dtrcks            = 0;
-    int    pvevt             = 0;
-    int    mother            = 0;
-    int    assoctrks         = 0;
-    int    nassoctrks        = 0;
+    double x             = -99999.;
+    double y             = -99999.;
+    double dx            = -99999.;
+    double dy            = -99999.;
+    double dz            = -99999.;
+    double r             = -99999.;
+    double zMC           = -99999.;
+    double yMC           = -99999.;
+    double xMC           = -99999.;
+    double rMC           = -99999.;
+    double z             = -99999.;
+    double errx          = -99999.;
+    double erry          = -99999.;
+    double errz          = -99999.;
+    double errr          = -99999.;
+    double chi2          = -999999.;
+    double nDoF          = -999999.;
+    int    indRec        = itmc->indexRecPVInfo;
+    int    reconstructed = 0;
+    int    ntracks_pvrec = 0;
+    int    ntracks_pvmc  = 0;
+    int    dtrcks        = 0;
+    int    pvevt         = 0;
+    int    mother        = 0;
+    int    assoctrks     = 0;
+    int    nassoctrks    = 0;
 
     zMC = itmc->pMCPV->position().z();
     yMC = itmc->pMCPV->position().y();
@@ -474,12 +563,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
       erry = recpvvec[indRec].positionSigma.y();
       errz = recpvvec[indRec].positionSigma.z();
       errr = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-      ntracks_pvrec     = recpvvec[indRec].nTracks;
-      ntracks_pvmc      = itmc->pMCPV->products().size();
-      dtrcks            = ntracks_pvmc - ntracks_pvrec;
-      mother            = recpvvec[indRec].mother;
-      chi2              = recpvvec[indRec].chi2;
-      nDoF              = recpvvec[indRec].nDoF;
+      ntracks_pvrec = recpvvec[indRec].nTracks;
+      ntracks_pvmc  = itmc->pMCPV->products().size();
+      dtrcks        = ntracks_pvmc - ntracks_pvrec;
+      mother        = recpvvec[indRec].mother;
+      chi2          = recpvvec[indRec].chi2;
+      nDoF          = recpvvec[indRec].nDoF;
 
       // Filling histograms
       if ( m_produceHistogram ) {
@@ -520,7 +609,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
       myTuple->column( "nrectrmc", double( itmc->nRecTracks ) );
       myTuple->column( "dzclose", dist_closest );
       myTuple->column( "nmcpv", double( rblemcpv.size() ) );
-      myTuple->column( "mtruemcpv",double(mcheader.numOfPrimaryVertices()));
+      myTuple->column( "mtruemcpv", double( mcheader.numOfPrimaryVertices() ) );
       myTuple->column( "nmcallpv", double( mcpvvec.size() ) );
       myTuple->column( "nrecpv", double( recpvvec.size() ) );
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
@@ -557,7 +646,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks,
   return;
 }
 
-//void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
+// void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
 //                                                      std::vector<MCPVInfo>& mcpvvec ) const {
 //
 //  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
@@ -771,7 +860,7 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
   info() << pmes << format( " %6.3f ( %7d / %8d )", rat, a, b ) << endmsg;
 }
 
-//void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
+// void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
 //                                                       std::vector<LHCb::Track*>& vecOfTracks,
 //                                                       std::string                trackLoc ) const {
 //
@@ -814,8 +903,8 @@ void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
 //}
 
 int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
-  int                         nVeloTracks = 0;
-  for( const auto& track: tracksPV ) {
+  int nVeloTracks = 0;
+  for ( const auto& track : tracksPV ) {
     if ( track.track->hasVelo() ) nVeloTracks++;
   }
   return nVeloTracks;
@@ -847,7 +936,7 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
   }
 }
 
-//int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
+// int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
 //                                                 const LHCb::MCParticles& mcps,
 //                                                 const LHCb::LinksByKey& linker  ) const {
 //
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.h b/Tr/PatChecker/src/PrimaryVertexChecker.h
deleted file mode 100644
index ffbca8242fa..00000000000
--- a/Tr/PatChecker/src/PrimaryVertexChecker.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*****************************************************************************\
-* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration      *
-*                                                                             *
-* This software is distributed under the terms of the GNU General Public      *
-* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
-*                                                                             *
-* In applying this licence, CERN does not waive the privileges and immunities *
-* granted to it by virtue of its status as an Intergovernmental Organization  *
-* or submit itself to any jurisdiction.                                       *
-\*****************************************************************************/
-#ifndef PRIMARYVERTEXCHECKER_H
-#define PRIMARYVERTEXCHECKER_H 1
-
-#include "Event/MCVertex.h"
-#include "Event/RecVertex.h"
-#include "Event/MCHeader.h"
-#include "Event/MCParticle.h"
-#include "Event/MCVertex.h"
-#include "Event/Track.h"
-#include "MCInterfaces/IForcedBDecayTool.h"
-
-#include "GaudiAlg/GaudiTupleAlg.h"
-
-typedef struct {
-  LHCb::MCVertex*                pMCPV;             // pointer to MC PV
-  int                            nRecTracks;        // number of reconstructed tracks from this MCPV
-  int                            nRecBackTracks;    // number of reconstructed backward tracks
-  int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
-  int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
-  int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
-  double                         distToClosestMCPV; // distance to closest reconstructible MCPV
-  int                            decayCharm;        // type of mother particle
-  int                            decayBeauty;
-  std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
-  std::vector<LHCb::Track*>      m_recTracksInMCPV;
-} MCPVInfo;
-
-typedef struct {
-public:
-  int              nTracks;     // number of tracks
-  double           chi2;
-  double           nDoF;
-  int              mother;
-  Gaudi::XYZPoint  position;      // position
-  Gaudi::XYZPoint  positionSigma; // position sigmas
-  int              indexMCPVInfo; // index to MCPVInfo
-  const LHCb::Event::v2::RecVertex* pRECPV;
-//  LHCb::RecVertex* pRECPV;        // pointer to REC PV
-} RecPVInfo;
-
-class PrimaryVertexChecker : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&,
-                                                                      std::vector<LHCb::Event::v2::RecVertex> const& vertices, //const LHCb::RecVertices&,
-                                                                      const LHCb::MCVertices&,
-                                                                      //const LHCb::MCParticles&,
-                                                                      //const LHCb::LinksByKey&,
-                                                                      const LHCb::MCHeader& ),
-                                                                Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
-public:
-  /// Standard constructor
-  PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator );
-
-  StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks,
-                         //const LHCb::RecVertices& recoVtx,
-                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
-                         const LHCb::MCVertices& mcvtx,
-                         // const LHCb::MCParticles& mcps,
-                         //const LHCb::LinksByKey& linker,
-                         const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
-  StatusCode finalize() override;                                                ///< Algorithm finalization
-
-protected:
-  bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
-
-private:
-  Gaudi::Property<int> m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
-  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
-  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
-  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
-  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  
-  mutable int m_nevt;
-  mutable int m_nMCPV, m_nRecMCPV;
-  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
-  mutable int m_nMCPV_close, m_nRecMCPV_close;
-  mutable int m_nFalsePV, m_nFalsePV_real;
-  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
-  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
-  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
-  mutable int m_nRecMCPV_wrong_1mult;
-  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
-  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
-  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
-  mutable int m_nRecMCPV_wrong_2mult;
-  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
-  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
-  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
-  mutable int m_nRecMCPV_wrong_3mult;
-  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
-  mutable int m_nBFalse, m_nRecBFalse;
-
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                               std::vector<MCPVInfo>::iterator& itmc ) const;
-
-  void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( std::string mes, int a, int b );
-//  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-//  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-//                                   std::string trackLoc ) const;
-  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
-//   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
-//   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-//  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles& mcps, const LHCb::LinksByKey& linker ) const;
-};
-#endif // PRIMARYVERTEXCHECKER_H
-
-- 
GitLab


From b15c6d810a6528553cd714f9c45f0e5bf1c0fb35 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus783.cern.ch>
Date: Thu, 23 Jan 2020 14:26:20 +0100
Subject: [PATCH 16/42] refactoring

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 620 +++++++++++----------
 1 file changed, 321 insertions(+), 299 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 19aac0836ee..8568e79ccbc 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -10,35 +10,40 @@
 \*****************************************************************************/
 
 #include "AIDA/IHistogram1D.h"
+
 #include "DetDesc/Condition.h"
 #include "DetDesc/ConditionAccessorHolder.h"
-#include "Event/L0DUReport.h"
+
 #include "Event/MCHeader.h"
 #include "Event/MCParticle.h"
 #include "Event/MCVertex.h"
+#include "Event/MCTrackInfo.h"
+#include "Event/MCProperty.h"
+
 #include "Event/RecVertex.h"
 #include "Event/RecVertex_v2.h"
 #include "Event/State.h"
 #include "Event/Track.h"
 #include "Event/Track_v2.h"
+
 #include "GaudiAlg/Consumer.h"
 #include "GaudiAlg/GaudiTupleAlg.h"
 #include "GaudiAlg/Tuples.h"
+
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
-#include "Linker/AllLinks.h"
-#include "Linker/LinkerWithKey.h"
-#include "MCInterfaces/IForcedBDecayTool.h"
-#include "VeloDet/DeVelo.h"
-#include <Event/MCTrackInfo.h>
-#include <Linker/LinkedTo.h>
 
+#include <tuple>
+#include <string>
+#include <vector>
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
 
-typedef struct {
+namespace {
+
+  struct MCPVInfo{
   LHCb::MCVertex*                pMCPV;             // pointer to MC PV
   int                            nRecTracks;        // number of reconstructed tracks from this MCPV
   int                            nRecBackTracks;    // number of reconstructed backward tracks
@@ -50,10 +55,10 @@ typedef struct {
   int                            decayBeauty;
   std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
   std::vector<LHCb::Track*>      m_recTracksInMCPV;
-} MCPVInfo;
+};
 
-typedef struct {
-public:
+  struct RecPVInfo{
+  public:
   int                               nTracks; // number of tracks
   double                            chi2;
   double                            nDoF;
@@ -63,7 +68,32 @@ public:
   int                               indexMCPVInfo; // index to MCPVInfo
   const LHCb::Event::v2::RecVertex* pRECPV;
   //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
-} RecPVInfo;
+};
+
+  inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
+
+  inline const std::vector<std::string> categories = {"1_all","2_isol","3_close","4_ntracks<X","5_ntracks>=X","6_z<-X","7_zIn(-X,X)","8_z>X"};
+
+  struct Beamline_t {
+    double X = std::numeric_limits<double>::signaling_NaN();
+    double Y = std::numeric_limits<double>::signaling_NaN();
+    Beamline_t( Condition const& c )
+      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+      , Y{c.param<double>( "ResolPosY" )} {}
+  };
+
+  bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
+
+  struct Stats{
+    std::string name;
+    int MCPV;
+    int RecPV;
+    int FalsePV;
+    int notRecPV;
+    int nTracks;
+  };
+}
+
 
 class PrimaryVertexChecker
     : public Gaudi::Functional::Consumer<
@@ -72,7 +102,8 @@ class PrimaryVertexChecker
                 const LHCb::MCVertices&,
                 // const LHCb::MCParticles&,
                 // const LHCb::LinksByKey&,
-                const LHCb::MCHeader& ),
+                const LHCb::MCHeader&,
+                const LHCb::MCProperty&),
           Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
@@ -82,9 +113,12 @@ public:
                   {KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
                   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
                   //                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                  KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                    KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
+                    KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
                   //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-                  KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default}}} {}
+
+                      }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
   void       operator()( const LHCb::Tracks& tracks,
@@ -92,7 +126,8 @@ public:
                    std::vector<LHCb::Event::v2::RecVertex> const& vertices, const LHCb::MCVertices& mcvtx,
                    // const LHCb::MCParticles& mcps,
                    // const LHCb::LinksByKey& linker,
-                   const LHCb::MCHeader& mcheader ) const override; ///< Algorithm execution
+                         const LHCb::MCHeader& mcheader,
+                         const LHCb::MCProperty& flags) const override; ///< Algorithm execution
   StatusCode finalize() override;                                         ///< Algorithm finalization
 
 protected:
@@ -104,58 +139,38 @@ private:
   Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
   Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
+  Gaudi::Property<int>    m_nTracksToPrint{this, "nTracksToPrint", 10.0};
+  Gaudi::Property<double> m_zToPrint{this, "zToPrint", 50.0 * Gaudi::Units::mm};
+  Gaudi::Property<int>    m_multiToPrint{this, "multiToPrint", 5.0};
+
   // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
+  mutable std::vector<Stats> m_stats;
+  mutable std::vector<Stats> m_stats_multi;
   mutable int m_nevt;
-  mutable int m_nMCPV, m_nRecMCPV;
-  mutable int m_nMCPV_isol, m_nRecMCPV_isol;
-  mutable int m_nMCPV_close, m_nRecMCPV_close;
-  mutable int m_nFalsePV, m_nFalsePV_real;
-  mutable int m_nMCPV_1mult, m_nRecMCPV_1mult;
-  mutable int m_nMCPV_isol_1mult, m_nRecMCPV_isol_1mult;
-  mutable int m_nMCPV_close_1mult, m_nRecMCPV_close_1mult;
-  mutable int m_nRecMCPV_wrong_1mult;
-  mutable int m_nMCPV_2mult, m_nRecMCPV_2mult;
-  mutable int m_nMCPV_isol_2mult, m_nRecMCPV_isol_2mult;
-  mutable int m_nMCPV_close_2mult, m_nRecMCPV_close_2mult;
-  mutable int m_nRecMCPV_wrong_2mult;
-  mutable int m_nMCPV_3mult, m_nRecMCPV_3mult;
-  mutable int m_nMCPV_isol_3mult, m_nRecMCPV_isol_3mult;
-  mutable int m_nMCPV_close_3mult, m_nRecMCPV_close_3mult;
-  mutable int m_nRecMCPV_wrong_3mult;
-  mutable int m_nL0PvOfB, m_nRecL0PvOfB;
-  mutable int m_nBFalse, m_nRecBFalse;
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
                                                std::vector<MCPVInfo>::iterator& itmc ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                               const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( std::string mes, int a, int b );
+  void printRat(std::string mes, int rec, int mc, int fal, int notrec, int ntr);
+  void printRes(std::string mes, double x, double y, double z);
+
   //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
   //                                   std::string trackLoc ) const;
   int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const;
+  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
+  double check_histogram(const AIDA::IHistogram1D* h, bool var);
   //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
   //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
   //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
   //  mcps, const LHCb::LinksByKey& linker ) const;
 };
 
-bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
-
-namespace {
-  struct Beamline_t {
-    double X = std::numeric_limits<double>::signaling_NaN();
-    double Y = std::numeric_limits<double>::signaling_NaN();
-    Beamline_t( Condition const& c )
-        : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
-        , Y{c.param<double>( "ResolPosY" )} {}
-  };
-
-} // namespace
-
 // Declaration of the Algorithm Factory
 DECLARE_COMPONENT( PrimaryVertexChecker )
 
@@ -167,34 +182,30 @@ StatusCode PrimaryVertexChecker::initialize() {
   if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
 
   m_nevt                 = 0;
-  m_nMCPV                = 0;
-  m_nRecMCPV             = 0;
-  m_nMCPV_isol           = 0;
-  m_nRecMCPV_isol        = 0;
-  m_nMCPV_close          = 0;
-  m_nRecMCPV_close       = 0;
-  m_nFalsePV             = 0;
-  m_nFalsePV_real        = 0;
-  m_nMCPV_1mult          = 0;
-  m_nRecMCPV_1mult       = 0;
-  m_nMCPV_isol_1mult     = 0;
-  m_nRecMCPV_isol_1mult  = 0;
-  m_nMCPV_close_1mult    = 0;
-  m_nRecMCPV_close_1mult = 0;
-  m_nMCPV_2mult          = 0;
-  m_nRecMCPV_2mult       = 0;
-  m_nMCPV_isol_2mult     = 0;
-  m_nRecMCPV_isol_2mult  = 0;
-  m_nMCPV_close_2mult    = 0;
-  m_nRecMCPV_close_2mult = 0;
-  m_nMCPV_3mult          = 0;
-  m_nRecMCPV_3mult       = 0;
-  m_nMCPV_isol_3mult     = 0;
-  m_nRecMCPV_isol_3mult  = 0;
-  m_nMCPV_close_3mult    = 0;
-  m_nRecMCPV_close_3mult = 0;
-  m_nBFalse              = 0;
-  m_nRecBFalse           = 0;
+
+  for(const auto& n: categories)
+    {
+      Stats s;
+      s.name = n;
+      s.MCPV = 0;
+      s.RecPV = 0;
+      s.FalsePV = 0;
+      s.notRecPV = 0;
+      s.nTracks = 0;
+      m_stats.push_back(s);
+    }
+
+  for(auto i = 0; i<m_multiToPrint.value(); i++)
+    {
+      Stats s;
+      s.name = format("%d_%dMCPV",categories.size()+i+1,i+1);
+      s.MCPV = 0;
+      s.RecPV = 0;
+      s.FalsePV = 0;
+      s.notRecPV = 0;
+      s.nTracks = 0;
+      m_stats_multi.push_back(s);
+    }
 
   return StatusCode::SUCCESS;
 }
@@ -207,7 +218,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
                                        const LHCb::MCVertices&                        mcvtx,
                                        // const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader& mcheader ) const {
+                                       const LHCb::MCHeader& mcheader,
+                                       const LHCb::MCProperty& flags) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -275,7 +287,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     }
   }
 
-  count_reconstructible_mc_particles( mcpvvec );
+  count_reconstructible_mc_particles( mcpvvec, flags );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
 
@@ -287,7 +299,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
     rblemcpv.push_back( *itmc );
-    if ( itmc->nRecTracks < m_nTracksToBeRecble ) { nmrc++; }
+    if ( itmc->nRecTracks < m_nTracksToBeRecble ) { m_stats[0].notRecPV +=1; }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
@@ -324,8 +336,6 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   }
 
   // find nr of false PV
-
-  int nFalsePV      = 0;
   int nFalsePV_real = 0;
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) {
     int    fake   = 0;
@@ -340,10 +350,46 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     int    mother = recpvvec[ipv].mother;
     double chi2   = recpvvec[ipv].chi2;
     double nDoF   = recpvvec[ipv].nDoF;
+    m_stats[0].nTracks += recpvvec[ipv].nTracks;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
-      nFalsePV++;
+      m_stats[0].FalsePV += 1;
       fake           = 1;
+
+      std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
+      double                          dist = 999999.;
+      if ( cmc != rblemcpv.end() ) {
+          dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
+      }
+
+      if ( dist > m_dzIsolated ) {
+        m_stats[1].FalsePV += 1;
+      }
+      else {
+        m_stats[2].FalsePV += 1;
+      }
+
+      if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
+        m_stats[3].FalsePV += 1;
+      }
+      else {
+        m_stats[4].FalsePV += 1;
+      }
+
+      if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
+        m_stats[5].FalsePV += 1;
+      }
+      else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
+        m_stats[6].FalsePV += 1;
+      }
+      else {
+        m_stats[7].FalsePV += 1;
+      }
+
+      int idx = std::distance(rblemcpv.begin(), cmc);
+      if ( idx < m_multiToPrint ) {
+        m_stats_multi[idx].FalsePV +=1;
+      }
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -387,133 +433,81 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     itmcl->multClosestMCPV   = mult;
   }
 
-  // count non-reconstructible close and isolated PVs
-  int nmrc_isol  = 0;
-  int nmrc_close = 0;
-
-  // Counters
-  int nMCPV                = rblemcpv.size() - nmrc;
-  int nRecMCPV             = 0;
-  int nMCPV_isol           = 0;
-  int nRecMCPV_isol        = 0;
-  int nMCPV_close          = 0;
-  int nRecMCPV_close       = 0;
-  int nMCPV_1mult          = 0;
-  int nRecMCPV_1mult       = 0;
-  int nMCPV_isol_1mult     = 0;
-  int nRecMCPV_isol_1mult  = 0;
-  int nMCPV_close_1mult    = 0;
-  int nRecMCPV_close_1mult = 0;
-  int nRecMCPV_wrong_1mult = 0;
-  int nMCPV_2mult          = 0;
-  int nRecMCPV_2mult       = 0;
-  int nMCPV_isol_2mult     = 0;
-  int nRecMCPV_isol_2mult  = 0;
-  int nMCPV_close_2mult    = 0;
-  int nRecMCPV_close_2mult = 0;
-  int nRecMCPV_wrong_2mult = 0;
-  int nMCPV_3mult          = 0;
-  int nRecMCPV_3mult       = 0;
-  int nMCPV_isol_3mult     = 0;
-  int nRecMCPV_isol_3mult  = 0;
-  int nMCPV_close_3mult    = 0;
-  int nRecMCPV_close_3mult = 0;
-  int nRecMCPV_wrong_3mult = 0;
-
+  m_stats[0].MCPV            += rblemcpv.size();
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
-    if ( itmc->distToClosestMCPV > m_dzIsolated ) nMCPV_isol++;
-    if ( itmc->distToClosestMCPV > m_dzIsolated && itmc->nRecTracks < m_nTracksToBeRecble ) nmrc_isol++;
-    if ( itmc->distToClosestMCPV < m_dzIsolated ) nMCPV_close++;
-    if ( itmc->distToClosestMCPV < m_dzIsolated && itmc->nRecTracks < m_nTracksToBeRecble ) nmrc_close++;
 
-    if ( itmc->indexRecPVInfo > -1 ) {
-      nRecMCPV++;
-      if ( itmc->distToClosestMCPV > m_dzIsolated ) nRecMCPV_isol++;
-      if ( itmc->distToClosestMCPV < m_dzIsolated ) nRecMCPV_close++;
+    if ( itmc->distToClosestMCPV > m_dzIsolated ) {
+      m_stats[1].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
+        m_stats[1].notRecPV+=1;
+      }
     }
-  }
-
-  // rblemcpv is already sorted
-
-  // highest mult
-  if ( rblemcpv.size() > 0 ) {
-    nMCPV_1mult++;
-    double dist = rblemcpv[0].distToClosestMCPV;
-    if ( dist > m_dzIsolated ) nMCPV_isol_1mult++;
-    if ( dist < m_dzIsolated ) nMCPV_close_1mult++;
-    if ( rblemcpv[0].indexRecPVInfo > -1 ) {
-      nRecMCPV_1mult++;
-      if ( dist > m_dzIsolated ) nRecMCPV_isol_1mult++;
-      if ( dist < m_dzIsolated ) nRecMCPV_close_1mult++;
-    } else {
-      nRecMCPV_wrong_1mult++;
+    else {
+      m_stats[2].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
+        m_stats[2].notRecPV+=1;
+      }
     }
-  }
 
-  // second highest
-  if ( rblemcpv.size() > 1 ) {
-    nMCPV_2mult++;
-    double dist = rblemcpv[1].distToClosestMCPV;
-    if ( dist > m_dzIsolated ) nMCPV_isol_2mult++;
-    if ( dist < m_dzIsolated ) nMCPV_close_2mult++;
-    if ( rblemcpv[1].indexRecPVInfo > -1 ) {
-      nRecMCPV_2mult++;
-      if ( dist > m_dzIsolated ) nRecMCPV_isol_2mult++;
-      if ( dist < m_dzIsolated ) nRecMCPV_close_2mult++;
-    } else {
-      nRecMCPV_wrong_2mult++;
+    if ( itmc->nRecTracks >= m_nTracksToBeRecble && itmc->nRecTracks < m_nTracksToPrint ) m_stats[3].MCPV+=1;
+    if ( itmc->nRecTracks >= m_nTracksToPrint ) m_stats[4].MCPV+=1;
+
+    if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
+      m_stats[5].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble) {
+        m_stats[5].notRecPV+=1;
+      }
     }
-  }
-  // third highest
-  if ( rblemcpv.size() > 2 ) {
-    nMCPV_3mult++;
-    double dist = rblemcpv[2].distToClosestMCPV;
-    if ( dist > m_dzIsolated ) nMCPV_isol_3mult++;
-    if ( dist < m_dzIsolated ) nMCPV_close_3mult++;
-    if ( rblemcpv[2].indexRecPVInfo > -1 ) {
-      nRecMCPV_3mult++;
-      if ( dist > m_dzIsolated ) nRecMCPV_isol_3mult++;
-      if ( dist < m_dzIsolated ) nRecMCPV_close_3mult++;
-    } else {
-      nRecMCPV_wrong_3mult++;
+    else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
+      m_stats[6].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble) {
+        m_stats[6].notRecPV+=1;
+      }
+    }
+    else {
+      m_stats[7].MCPV+=1;
+      if (itmc->nRecTracks < m_nTracksToBeRecble) {
+        m_stats[7].notRecPV+=1;
+      }
     }
-  }
 
-  nMCPV_isol  = nMCPV_isol - nmrc_isol;
-  nMCPV_close = nMCPV_close - nmrc_close;
-
-  m_nMCPV += nMCPV;
-  m_nRecMCPV += nRecMCPV;
-  m_nMCPV_isol += nMCPV_isol;
-  m_nRecMCPV_isol += nRecMCPV_isol;
-  m_nMCPV_close += nMCPV_close;
-  m_nRecMCPV_close += nRecMCPV_close;
-  m_nFalsePV += nFalsePV;
-  m_nFalsePV_real += nFalsePV_real;
-  m_nMCPV_1mult += nMCPV_1mult;
-  m_nRecMCPV_1mult += nRecMCPV_1mult;
-  m_nMCPV_isol_1mult += nMCPV_isol_1mult;
-  m_nRecMCPV_isol_1mult += nRecMCPV_isol_1mult;
-  m_nMCPV_close_1mult += nMCPV_close_1mult;
-  m_nRecMCPV_close_1mult += nRecMCPV_close_1mult;
-  m_nRecMCPV_wrong_1mult += nRecMCPV_wrong_1mult;
-  m_nMCPV_2mult += nMCPV_2mult;
-  m_nRecMCPV_2mult += nRecMCPV_2mult;
-  m_nMCPV_isol_2mult += nMCPV_isol_2mult;
-  m_nRecMCPV_isol_2mult += nRecMCPV_isol_2mult;
-  m_nMCPV_close_2mult += nMCPV_close_2mult;
-  m_nRecMCPV_wrong_2mult += nRecMCPV_wrong_2mult;
-  m_nRecMCPV_close_2mult += nRecMCPV_close_2mult;
-  m_nMCPV_3mult += nMCPV_3mult;
-  m_nRecMCPV_3mult += nRecMCPV_3mult;
-  m_nMCPV_isol_3mult += nMCPV_isol_3mult;
-  m_nRecMCPV_isol_3mult += nRecMCPV_isol_3mult;
-  m_nMCPV_close_3mult += nMCPV_close_3mult;
-  m_nRecMCPV_close_3mult += nRecMCPV_close_3mult;
-  m_nRecMCPV_wrong_3mult += nRecMCPV_wrong_3mult;
+    if ( itmc->indexRecPVInfo > -1 ) {
+      m_stats[0].RecPV+=1;
+      if ( itmc->distToClosestMCPV > m_dzIsolated ) {
+        m_stats[1].RecPV+=1;
+        m_stats[1].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else {
+        m_stats[2].RecPV+=1;
+        m_stats[2].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
 
-  int high = 0;
+      if ( itmc->nRecTracks >= m_nTracksToPrint ) {
+        m_stats[4].RecPV+=1;
+        m_stats[4].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else {
+        m_stats[3].RecPV+=1;
+        m_stats[3].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+
+      if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
+        m_stats[5].RecPV+=1;
+        m_stats[5].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else if ( itmc->pMCPV->position().z() < m_zToPrint ){
+        m_stats[6].RecPV+=1;
+        m_stats[6].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+      else {
+        m_stats[7].RecPV+=1;
+        m_stats[7].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+      }
+    }
+  }
 
+  int mcpv = 0;
+  int high = 0;
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
     double x             = -99999.;
     double y             = -99999.;
@@ -547,6 +541,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     xMC = itmc->pMCPV->position().x();
     rMC = std::sqrt( ( xMC - m_beamSpotX ) * ( xMC - m_beamSpotX ) + ( yMC - m_beamSpotY ) * ( yMC - m_beamSpotY ) );
 
+    if ( mcpv < m_multiToPrint )
+      {
+        m_stats_multi[mcpv].MCPV += 1;
+        if (itmc->nRecTracks < m_nTracksToBeRecble) { m_stats_multi[mcpv].notRecPV+=1;}
+      }
+
     if ( indRec > -1 ) {
       high++;
       pvevt++;
@@ -570,6 +570,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       chi2          = recpvvec[indRec].chi2;
       nDoF          = recpvvec[indRec].nDoF;
 
+      if ( mcpv < m_multiToPrint )
+        {
+          m_stats_multi[mcpv].RecPV += 1;
+          m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
+        }
       // Filling histograms
       if ( m_produceHistogram ) {
         plot( itmc->pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
@@ -584,6 +589,38 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         plot( dx / errx, 1031, "pullx", -5., 5., 50 );
         plot( dy / erry, 1032, "pully", -5., 5., 50 );
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
+        if ( itmc->nRecTracks < 10){
+          plot( dx, 1101, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1102, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1103, "dz", -0.5, 0.5, 50 );
+        }
+        else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30){
+          plot( dx, 1111, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1112, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1113, "dz", -0.5, 0.5, 50 );
+        }
+        else{
+          plot( dx, 1121, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1122, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1123, "dz", -0.5, 0.5, 50 );
+        }
+
+        if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
+          plot( dx, 1201, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1202, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1203, "dz", -0.5, 0.5, 50 );
+        }
+        else if ( itmc->pMCPV->position().z() < m_zToPrint )    {
+          plot( dx, 1211, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1212, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1213, "dz", -0.5, 0.5, 50 );
+        }
+        else {
+          plot( dx, 1221, "dx", -0.25, 0.25, 50 );
+          plot( dy, 1222, "dy", -0.25, 0.25, 50 );
+          plot( dz, 1223, "dz", -0.5, 0.5, 50 );
+        }
+
         plot( double( ntracks_pvrec ), 1041, "ntracks_pvrec", 0., 150., 50 );
         plot( double( dtrcks ), 1042, "mcrdtracks", 0., 150., 50 );
         if ( pvevt == 1 ) {
@@ -596,6 +633,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         }
       }
     }
+    mcpv++;
 
     int    isolated     = 0;
     double dist_closest = itmc->distToClosestMCPV;
@@ -707,7 +745,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
                                                                    std::vector<MCPVInfo>::iterator& itmc ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
-  double                          mindist = 999999.;
+  double                        mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
@@ -722,6 +760,24 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
+std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
+                                                                   const RecPVInfo& rec ) const {
+
+  std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
+  double                        mindist = 999999.;
+  if ( rblemcpv.size() < 2 ) return itret;
+  std::vector<MCPVInfo>::iterator it;
+  for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
+      double dist = ( it->pMCPV->position() - rec.pRECPV->position() ).R();
+      if ( dist < mindist ) {
+        mindist = dist;
+        itret   = it;
+      }
+  }
+  return itret;
+}
+
+
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
                                              std::vector<LHCb::MCParticle*>& allprods ) const {
 
@@ -745,119 +801,85 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
 
-  info() << " ============================================" << endmsg;
-  info() << " Efficiencies for reconstructible MC vertices: " << endmsg;
-  info() << " ============================================" << endmsg;
+  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed" << endmsg;
+  info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
+  info() << " MC efficiency split by tracks with threshold: ("<< m_nTracksToBeRecble.value()<<","<<m_nTracksToPrint.value()<<"), >= "<<m_nTracksToPrint.value()<<endmsg;
+  info() << " MC efficiency split by z position: <-"<<m_zToPrint.value()<<", (-"<<m_zToPrint.value()<<","<<m_zToPrint.value()<<"), >"<<m_zToPrint.value()<< endmsg;
+  std::string ff = "by distance";
+  info() << " REC and MC vertices matched:  " << ff << endmsg;
+
   info() << " " << endmsg;
 
-  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble << "  tracks are reconstructed" << endmsg;
-  info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated << " mm" << endmsg;
-  std::string ff = "by dz distance";
-  info() << " REC and MC vertices matched:  " << ff << endmsg;
+  for (auto& mstat : m_stats)
+    {
+      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+    }
+  for (auto& mstat : m_stats_multi)
+    {
+      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+    }
+  info() << " " << endmsg;
+
+  printRes("1_res_all",                check_histogram(histo( HistoID( 1021 ) ),true), check_histogram(histo( HistoID( 1022 ) ), true), check_histogram(histo( HistoID( 1023 ) ),true));
+
+  printRes("2_res_ntracks<10",     check_histogram(histo( HistoID( 1101 ) ),true), check_histogram(histo( HistoID( 1102 ) ), true), check_histogram(histo( HistoID( 1103 ) ),true));
+  printRes("3_res_ntracks(10,30)", check_histogram(histo( HistoID( 1111 ) ),true), check_histogram(histo( HistoID( 1112 ) ), true), check_histogram(histo( HistoID( 1113 ) ),true));
+  printRes("4_res_ntracks>30",     check_histogram(histo( HistoID( 1121 ) ),true), check_histogram(histo( HistoID( 1122 ) ), true), check_histogram(histo( HistoID( 1123 ) ),true));
+
+  printRes("5_res_z<-50",     check_histogram(histo( HistoID( 1201 ) ),true), check_histogram(histo( HistoID( 1202 ) ),true), check_histogram(histo( HistoID( 1203 ) ),true));
+  printRes("6_res_z(-50,50)", check_histogram(histo( HistoID( 1211 ) ),true), check_histogram(histo( HistoID( 1212 ) ),true), check_histogram(histo( HistoID( 1213 ) ),true));
+  printRes("7_res_z>50",      check_histogram(histo( HistoID( 1221 ) ),true), check_histogram(histo( HistoID( 1222 ) ),true), check_histogram(histo( HistoID( 1223 ) ),true));
 
   info() << " " << endmsg;
 
-  printRat( "All", m_nRecMCPV, m_nMCPV );
-  printRat( "Isolated", m_nRecMCPV_isol, m_nMCPV_isol );
-  printRat( "Close", m_nRecMCPV_close, m_nMCPV_close );
-  printRat( "False rate", m_nFalsePV, m_nRecMCPV + m_nFalsePV );
-
-  if ( debugLevel() ) { printRat( "Real false rate", m_nFalsePV_real, m_nRecMCPV + m_nFalsePV_real ); }
-
-  info() << endmsg;
-  printRat( "False PV as B", m_nRecBFalse, m_nBFalse );
-  info() << endmsg;
-
-  info() << "      --------------------------------------------" << endmsg;
-  info() << "           Substatistics: " << endmsg;
-  info() << "      --------------------------------------------" << endmsg;
-  info() << "      1st PV (highest multiplicity): " << endmsg;
-  printRat( "All", m_nRecMCPV_1mult, m_nMCPV_1mult );
-  printRat( "Isolated", m_nRecMCPV_isol_1mult, m_nMCPV_isol_1mult );
-  printRat( "Close", m_nRecMCPV_close_1mult, m_nMCPV_close_1mult );
-
-  info() << "      ---------------------------------------" << endmsg;
-  info() << "      2nd PV: " << endmsg;
-  printRat( "All", m_nRecMCPV_2mult, m_nMCPV_2mult );
-  printRat( "Isolated", m_nRecMCPV_isol_2mult, m_nMCPV_isol_2mult );
-  printRat( "Close", m_nRecMCPV_close_2mult, m_nMCPV_close_2mult );
-
-  info() << "      ---------------------------------------" << endmsg;
-  info() << "      3rd PV: " << endmsg;
-  printRat( "All", m_nRecMCPV_3mult, m_nMCPV_3mult );
-  printRat( "Isolated", m_nRecMCPV_isol_3mult, m_nMCPV_isol_3mult );
-  printRat( "Close", m_nRecMCPV_close_3mult, m_nMCPV_close_3mult );
+  printRes("1_pull_width_all",  check_histogram(histo( HistoID( 1031 ) ),true), check_histogram(histo( HistoID( 1032 ) ),true), check_histogram(histo( HistoID( 1033 ) ),true));
+  printRes("1_pull_mean_all",   check_histogram(histo( HistoID( 1031 ) ),false), check_histogram(histo( HistoID( 1032 ) ),false), check_histogram(histo( HistoID( 1033 ) ),false));
 
   info() << " " << endmsg;
-  if ( debugLevel() ) {
-    info() << " * Real false rate means: no visible MC PV within 5 sigma of REC PV."
-           << " Visible MC PV: 2 tracks reconstructed" << endmsg;
-    info() << " " << endmsg;
-  }
-  const AIDA::IHistogram1D* dx    = histo( HistoID( 1021 ) );
-  const AIDA::IHistogram1D* pullx = histo( HistoID( 1031 ) );
-  const AIDA::IHistogram1D* dy    = histo( HistoID( 1022 ) );
-  const AIDA::IHistogram1D* pully = histo( HistoID( 1032 ) );
-  const AIDA::IHistogram1D* dz    = histo( HistoID( 1023 ) );
-  const AIDA::IHistogram1D* pullz = histo( HistoID( 1033 ) );
-  if ( dx ) {
-    info() << "      ---------------------------------------" << endmsg;
-    info() << "dx:    "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", dx->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( dx ), dx->rms(), Gaudi::Utils::HistoStats::rmsErr( dx ) )
-           << endmsg;
-  }
-  if ( dy ) {
-    info() << "dy:    "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", dy->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( dy ), dy->rms(), Gaudi::Utils::HistoStats::rmsErr( dy ) )
-           << endmsg;
-  }
-  if ( dz ) {
-    info() << "dz:    "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", dz->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( dz ), dz->rms(), Gaudi::Utils::HistoStats::rmsErr( dz ) )
-           << endmsg;
-  }
-  info() << "      ---------------------------------------" << endmsg;
-  if ( pullx ) {
-    info() << "pullx: "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", pullx->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( pullx ), pullx->rms(),
-                      Gaudi::Utils::HistoStats::rmsErr( pullx ) )
-           << endmsg;
-  }
-  if ( pully ) {
-    info() << "pully: "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", pully->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( pully ), pully->rms(),
-                      Gaudi::Utils::HistoStats::rmsErr( pully ) )
-           << endmsg;
-  }
-  if ( pullz ) {
-    info() << "pullz: "
-           << format( "mean =  %5.3f +/- %5.3f, RMS =  %5.3f +/- %5.3f", pullz->mean(),
-                      Gaudi::Utils::HistoStats::meanErr( pullz ), pullz->rms(),
-                      Gaudi::Utils::HistoStats::rmsErr( pullz ) )
-           << endmsg;
-  }
-  info() << " ============================================" << endmsg;
 
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( std::string mes, int a, int b ) {
+void PrimaryVertexChecker::printRat( std::string mes, int rec, int mc, int fal, int notrec, int ntr ) {
 
   double rat = 0.;
-  if ( b > 0 ) rat = 1.0 * a / b;
-
+  double fl = 0.;
+  double all_rec = rec+fal;
+  double av_tr = 0.;
+  if ( (mc-notrec) > 0 ) rat = 100.0 * rec / (mc-notrec);
+  if ( all_rec > 0 ) fl = 100.0 * fal / all_rec;
+  if ( rec > 0 ) av_tr = 1.0*ntr/rec;
   // reformat message
+  unsigned int len  = 15;
+  std::string  pmes = mes;
+  while ( pmes.length() < len ) { pmes += " "; }
+  pmes += " : ";
+
+  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reconstructed %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f",
+                            rec, mc, rat, fal, rec+fal, fl, notrec, av_tr) << endmsg;
+}
+
+void PrimaryVertexChecker::printRes(std::string mes, double x, double y, double z){
   unsigned int len  = 20;
   std::string  pmes = mes;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
+  info() << pmes << format(" x: %+5.3f, y: %+5.3f, z: %+5.3f",
+                           x, y, z) << endmsg;
+}
 
-  info() << pmes << format( " %6.3f ( %7d / %8d )", rat, a, b ) << endmsg;
+double PrimaryVertexChecker::check_histogram(const AIDA::IHistogram1D* h, bool rms) {
+  if ( h ) {
+    if ( rms ) {
+      return h->rms();
+    }
+    else {
+      return h->mean();
+    }
+  }
+  else {
+    return 0.;
+  }
 }
 
 // void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
@@ -910,10 +932,11 @@ int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::
   return nVeloTracks;
 }
 
-void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec ) const {
+void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const {
 
-  const auto trInfo = MCTrackInfo{*get<LHCb::MCProperty>( LHCb::MCPropertyLocation::TrackInfo )};
-  for ( auto itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
+  const MCTrackInfo               trInfo = {flags};
+  std::vector<MCPVInfo>::iterator itinfomc;
+  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
     LHCb::MCVertex*                  avtx = itinfomc->pMCPV;
     std::vector<LHCb::MCParticle*>   mcPartInMCPV;
     SmartRefVector<LHCb::MCParticle> parts = avtx->products();
@@ -979,4 +1002,3 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
 //  }
 //  return motherPart;
 //}
-
-- 
GitLab


From df9bbd705273621a62b3d68cc9cff5c5ffb94161 Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton>
Date: Tue, 4 Feb 2020 12:25:47 +0100
Subject: [PATCH 17/42] refactoring

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 357 ++++++++++++---------
 1 file changed, 204 insertions(+), 153 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 8568e79ccbc..3f722d21445 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -44,17 +44,18 @@
 namespace {
 
   struct MCPVInfo{
-  LHCb::MCVertex*                pMCPV;             // pointer to MC PV
-  int                            nRecTracks;        // number of reconstructed tracks from this MCPV
-  int                            nRecBackTracks;    // number of reconstructed backward tracks
-  int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
-  int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
-  int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
-  double                         distToClosestMCPV; // distance to closest reconstructible MCPV
-  int                            decayCharm;        // type of mother particle
-  int                            decayBeauty;
-  std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
-  std::vector<LHCb::Track*>      m_recTracksInMCPV;
+    LHCb::MCVertex*                pMCPV;             // pointer to MC PV
+    int                            nRecTracks;        // number of reconstructed tracks from this MCPV
+    int                            nRecBackTracks;    // number of reconstructed backward tracks
+    int                            indexRecPVInfo;    // index to reconstructed PVInfo (-1 if not reco)
+    int                            nCorrectTracks;    // correct tracks belonging to reconstructed PV
+    int                            multClosestMCPV;   // multiplicity of closest reconstructable MCPV
+    double                         distToClosestMCPV; // distance to closest reconstructible MCPV
+    bool                           decayCharm;        // type of mother particle
+    bool                           decayBeauty;
+    bool                           decayStrange;
+    std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
+    std::vector<LHCb::Track*>      m_recTracksInMCPV;
 };
 
   struct RecPVInfo{
@@ -72,8 +73,6 @@ namespace {
 
   inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
 
-  inline const std::vector<std::string> categories = {"1_all","2_isol","3_close","4_ntracks<X","5_ntracks>=X","6_z<-X","7_zIn(-X,X)","8_z>X"};
-
   struct Beamline_t {
     double X = std::numeric_limits<double>::signaling_NaN();
     double Y = std::numeric_limits<double>::signaling_NaN();
@@ -91,16 +90,34 @@ namespace {
     int FalsePV;
     int notRecPV;
     int nTracks;
+    int nMCPart;
+  };
+
+  enum class recoAs{
+      all,
+      isolated, close,
+      ntracks_low, ntracks_high,
+      z_low, z_middle, z_high,
+      beauty, charm, strange, other
   };
+  static const recoAs All[] = { recoAs::all,
+                                recoAs::isolated, recoAs::close,
+                                recoAs::ntracks_low, recoAs::ntracks_high,
+                                recoAs::z_low, recoAs::z_middle, recoAs::z_high,
+                                recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+  static const recoAs part[] = { recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+
+  static constexpr int size_recAs = int(recoAs::other) + 1;
+
 }
 
 
 class PrimaryVertexChecker
     : public Gaudi::Functional::Consumer<
           void( const LHCb::Tracks&,
-                std::vector<LHCb::Event::v2::RecVertex> const& vertices, // const LHCb::RecVertices&,
+                std::vector<LHCb::Event::v2::RecVertex> const&,
                 const LHCb::MCVertices&,
-                // const LHCb::MCParticles&,
+                const LHCb::MCParticles&,
                 // const LHCb::LinksByKey&,
                 const LHCb::MCHeader&,
                 const LHCb::MCProperty&),
@@ -110,24 +127,23 @@ public:
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
       : Consumer{ name,
                   pSvcLocator,
-                  {KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                  KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-                  //                    KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                    KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
-                    KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
-                    KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
+                  {KeyValue{"inputTracksName",   LHCb::TrackLocation::Default},
+                   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                   KeyValue{"MCVertexInput",     LHCb::MCVertexLocation::Default},
+                   KeyValue{"MCParticleInput",   LHCb::MCParticleLocation::Default},
+                   KeyValue{"MCHeaderLocation",  LHCb::MCHeaderLocation::Default},
+                   KeyValue{"MCPropertyInput",   LHCb::MCPropertyLocation::TrackInfo},
                   //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-
                       }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
   void       operator()( const LHCb::Tracks& tracks,
-                   // const LHCb::RecVertices& recoVtx,
-                   std::vector<LHCb::Event::v2::RecVertex> const& vertices, const LHCb::MCVertices& mcvtx,
-                   // const LHCb::MCParticles& mcps,
+                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
+                         const LHCb::MCVertices&                        mcvtx,
+                         const LHCb::MCParticles&                       mcps,
                    // const LHCb::LinksByKey& linker,
-                         const LHCb::MCHeader& mcheader,
-                         const LHCb::MCProperty& flags) const override; ///< Algorithm execution
+                         const LHCb::MCHeader&                          mcheader,
+                         const LHCb::MCProperty&                        flags) const override; ///< Algorithm execution
   StatusCode finalize() override;                                         ///< Algorithm finalization
 
 protected:
@@ -145,7 +161,7 @@ private:
 
   // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
-  mutable std::vector<Stats> m_stats;
+  mutable std::map<recoAs, Stats> m_stats;
   mutable std::vector<Stats> m_stats_multi;
   mutable int m_nevt;
 
@@ -155,8 +171,10 @@ private:
                                                const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat(std::string mes, int rec, int mc, int fal, int notrec, int ntr);
+  void printRat(const std::string name, const Stats& stat);
   void printRes(std::string mes, double x, double y, double z);
+  std::string toString( const recoAs& n) const;
+  bool checkCondition(const MCPVInfo& MCPV, const recoAs& n) const;
 
   //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
@@ -183,27 +201,28 @@ StatusCode PrimaryVertexChecker::initialize() {
 
   m_nevt                 = 0;
 
-  for(const auto& n: categories)
+  for(const auto& n: All)
     {
       Stats s;
-      s.name = n;
       s.MCPV = 0;
       s.RecPV = 0;
       s.FalsePV = 0;
       s.notRecPV = 0;
       s.nTracks = 0;
-      m_stats.push_back(s);
+      s.nMCPart = 0;
+      m_stats[n];
     }
 
   for(auto i = 0; i<m_multiToPrint.value(); i++)
     {
       Stats s;
-      s.name = format("%d_%dMCPV",categories.size()+i+1,i+1);
+      s.name = format("%d_%dMCPV",size_recAs+i+1,i+1);
       s.MCPV = 0;
       s.RecPV = 0;
       s.FalsePV = 0;
       s.notRecPV = 0;
       s.nTracks = 0;
+      s.nMCPart = 0;
       m_stats_multi.push_back(s);
     }
 
@@ -216,10 +235,10 @@ StatusCode PrimaryVertexChecker::initialize() {
 void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
                                        std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
                                        const LHCb::MCVertices&                        mcvtx,
-                                       // const LHCb::MCParticles& mcps,
+                                       const LHCb::MCParticles&                       mcps,
                                        // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader& mcheader,
-                                       const LHCb::MCProperty& flags) const {
+                                       const LHCb::MCHeader&                          mcheader,
+                                       const LHCb::MCProperty&                        flags) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -278,8 +297,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         mcprimvert.nCorrectTracks    = 0;
         mcprimvert.multClosestMCPV   = 0;
         mcprimvert.distToClosestMCPV = 999999.;
-        mcprimvert.decayBeauty       = 0;
-        mcprimvert.decayCharm        = 0;
+        mcprimvert.decayBeauty       = false;
+        mcprimvert.decayCharm        = false;
+        mcprimvert.decayStrange      = false;
         mcprimvert.m_mcPartInMCPV.clear();
         mcprimvert.m_recTracksInMCPV.clear();
         mcpvvec.push_back( mcprimvert );
@@ -299,7 +319,6 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
     rblemcpv.push_back( *itmc );
-    if ( itmc->nRecTracks < m_nTracksToBeRecble ) { m_stats[0].notRecPV +=1; }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
@@ -350,46 +369,53 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     int    mother = recpvvec[ipv].mother;
     double chi2   = recpvvec[ipv].chi2;
     double nDoF   = recpvvec[ipv].nDoF;
-    m_stats[0].nTracks += recpvvec[ipv].nTracks;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
-      m_stats[0].FalsePV += 1;
       fake           = 1;
-
       std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
-      if ( cmc != rblemcpv.end() ) {
+
+      if ( cmc != rblemcpv.end() )
+        {
           dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
-      }
 
-      if ( dist > m_dzIsolated ) {
-        m_stats[1].FalsePV += 1;
-      }
-      else {
-        m_stats[2].FalsePV += 1;
-      }
+          for(const auto& n: part)
+            {
+              bool cut = false;
+              cut = checkCondition(*cmc,n);
+              if ( cut ) {
+                m_stats[n].FalsePV += 1;
+              }
+            }
+          if ( dist > m_dzIsolated ) {
+            m_stats[recoAs::isolated].FalsePV += 1;
+          }
+          else {
+            m_stats[recoAs::close].FalsePV += 1;
+          }
+          if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
+            m_stats[recoAs::ntracks_high].FalsePV += 1;
+          }
+          else {
+            m_stats[recoAs::ntracks_low].FalsePV += 1;
+          }
 
-      if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
-        m_stats[3].FalsePV += 1;
-      }
-      else {
-        m_stats[4].FalsePV += 1;
-      }
+          if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
+            m_stats[recoAs::z_low].FalsePV += 1;
+          }
+          else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
+            m_stats[recoAs::z_middle].FalsePV += 1;
+          }
+          else {
+            m_stats[recoAs::z_high].FalsePV += 1;
+          }
 
-      if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
-        m_stats[5].FalsePV += 1;
-      }
-      else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
-        m_stats[6].FalsePV += 1;
-      }
-      else {
-        m_stats[7].FalsePV += 1;
-      }
+          int idx = std::distance(rblemcpv.begin(), cmc);
+          if ( idx < m_multiToPrint ) {
+            m_stats_multi[idx].FalsePV +=1;
+          }
+        }
 
-      int idx = std::distance(rblemcpv.begin(), cmc);
-      if ( idx < m_multiToPrint ) {
-        m_stats_multi[idx].FalsePV +=1;
-      }
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -433,77 +459,26 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     itmcl->multClosestMCPV   = mult;
   }
 
-  m_stats[0].MCPV            += rblemcpv.size();
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
 
-    if ( itmc->distToClosestMCPV > m_dzIsolated ) {
-      m_stats[1].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
-        m_stats[1].notRecPV+=1;
-      }
-    }
-    else {
-      m_stats[2].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble ) {
-        m_stats[2].notRecPV+=1;
-      }
-    }
-
-    if ( itmc->nRecTracks >= m_nTracksToBeRecble && itmc->nRecTracks < m_nTracksToPrint ) m_stats[3].MCPV+=1;
-    if ( itmc->nRecTracks >= m_nTracksToPrint ) m_stats[4].MCPV+=1;
-
-    if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
-      m_stats[5].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble) {
-        m_stats[5].notRecPV+=1;
-      }
-    }
-    else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
-      m_stats[6].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble) {
-        m_stats[6].notRecPV+=1;
-      }
-    }
-    else {
-      m_stats[7].MCPV+=1;
-      if (itmc->nRecTracks < m_nTracksToBeRecble) {
-        m_stats[7].notRecPV+=1;
-      }
-    }
-
-    if ( itmc->indexRecPVInfo > -1 ) {
-      m_stats[0].RecPV+=1;
-      if ( itmc->distToClosestMCPV > m_dzIsolated ) {
-        m_stats[1].RecPV+=1;
-        m_stats[1].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else {
-        m_stats[2].RecPV+=1;
-        m_stats[2].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-
-      if ( itmc->nRecTracks >= m_nTracksToPrint ) {
-        m_stats[4].RecPV+=1;
-        m_stats[4].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else {
-        m_stats[3].RecPV+=1;
-        m_stats[3].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-
-      if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
-        m_stats[5].RecPV+=1;
-        m_stats[5].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else if ( itmc->pMCPV->position().z() < m_zToPrint ){
-        m_stats[6].RecPV+=1;
-        m_stats[6].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-      }
-      else {
-        m_stats[7].RecPV+=1;
-        m_stats[7].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+    for(const auto& n: All)
+      {
+        bool cut = false;
+        cut = checkCondition(*itmc,n);
+        if ( cut ) {
+            m_stats[n].MCPV+=1;
+            if (itmc->nRecTracks < m_nTracksToBeRecble ) {
+              m_stats[n].notRecPV+=1;
+            }
+            else {
+              m_stats[n].nMCPart += itmc->nRecTracks;
+            }
+            if ( itmc->indexRecPVInfo > -1 ) {
+              m_stats[n].RecPV+=1;
+              m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+            }
+        }
       }
-    }
   }
 
   int mcpv = 0;
@@ -544,7 +519,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     if ( mcpv < m_multiToPrint )
       {
         m_stats_multi[mcpv].MCPV += 1;
-        if (itmc->nRecTracks < m_nTracksToBeRecble) { m_stats_multi[mcpv].notRecPV+=1;}
+        if (itmc->nRecTracks < m_nTracksToBeRecble) {
+          m_stats_multi[mcpv].notRecPV+=1;
+        }
+        else {
+          m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
+        }
       }
 
     if ( indRec > -1 ) {
@@ -652,6 +632,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       myTuple->column( "nrecpv", double( recpvvec.size() ) );
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
       myTuple->column( "decayBeauty", double( itmc->decayBeauty ) );
+      myTuple->column( "decayStrange", double( itmc->decayStrange ) );
       myTuple->column( "multi", double( high ) );
       myTuple->column( "dx", dx );
       myTuple->column( "dy", dy );
@@ -675,7 +656,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       myTuple->column( "chi2", double( chi2 ) );
       myTuple->column( "nDoF", double( nDoF ) );
       myTuple->column( "size_tracks", double( tracks.size() ) );
-      // myTuple->column( "size_mcp", double( sMCP ) );
+      myTuple->column( "size_mcp", double( mcps.size() ) );
       myTuple->column( "mcpvrec", double( nmrc ) );
       myTuple->write();
     }
@@ -801,6 +782,9 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
 
+  //categories category = all;
+  //info() << " CATEGORY TEST = " << category << endmsg;
+
   info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed" << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
   info() << " MC efficiency split by tracks with threshold: ("<< m_nTracksToBeRecble.value()<<","<<m_nTracksToPrint.value()<<"), >= "<<m_nTracksToPrint.value()<<endmsg;
@@ -810,13 +794,15 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   info() << " " << endmsg;
 
-  for (auto& mstat : m_stats)
+
+  for (const auto& n: All)
     {
-      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+      printRat(toString(n), m_stats[n] );
     }
+
   for (auto& mstat : m_stats_multi)
     {
-      printRat( mstat.name, mstat.RecPV, mstat.MCPV, mstat.FalsePV, mstat.notRecPV, mstat.nTracks );
+      printRat( mstat.name, mstat );
     }
   info() << " " << endmsg;
 
@@ -840,23 +826,28 @@ StatusCode PrimaryVertexChecker::finalize() {
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( std::string mes, int rec, int mc, int fal, int notrec, int ntr ) {
+void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat ) {
 
   double rat = 0.;
   double fl = 0.;
-  double all_rec = rec+fal;
+  int all_rec = stat.RecPV+stat.FalsePV;
   double av_tr = 0.;
-  if ( (mc-notrec) > 0 ) rat = 100.0 * rec / (mc-notrec);
-  if ( all_rec > 0 ) fl = 100.0 * fal / all_rec;
-  if ( rec > 0 ) av_tr = 1.0*ntr/rec;
+  double av_par = 0.;
+  if ( (stat.MCPV-stat.notRecPV) > 0 ) {
+    rat = 100.0 * stat.RecPV / (stat.MCPV-stat.notRecPV);
+    av_par = 1.0*stat.nMCPart/(stat.MCPV-stat.notRecPV);
+  }
+  if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
+  if ( stat.RecPV > 0 ) av_tr = 1.0*stat.nTracks/stat.RecPV;
+
   // reformat message
-  unsigned int len  = 15;
-  std::string  pmes = mes;
+  unsigned int len  = 25;
+  std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
-  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reconstructed %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f",
-                            rec, mc, rat, fal, rec+fal, fl, notrec, av_tr) << endmsg;
+  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f [MC: %6.2f]",
+                            stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par) << endmsg;
 }
 
 void PrimaryVertexChecker::printRes(std::string mes, double x, double y, double z){
@@ -946,8 +937,9 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     for ( LHCb::MCParticle* pmcp : allproducts ) {
       if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
-        if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = 1.0; }
-        if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = 1.0; }
+        if ( pmcp->particleID().hasBottom() )  { itinfomc->decayBeauty  = true; }
+        if ( pmcp->particleID().hasCharm() )   { itinfomc->decayCharm   = true; }
+        if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
         if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
           double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
@@ -959,6 +951,65 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
   }
 }
 
+bool  PrimaryVertexChecker::checkCondition( const  MCPVInfo& MCPV, const recoAs& n) const{
+  switch (n) {
+  case recoAs::all:
+    return true;
+  case recoAs::isolated:
+    return (MCPV.distToClosestMCPV > m_dzIsolated);
+  case recoAs::close:
+    return (MCPV.distToClosestMCPV <= m_dzIsolated);
+  case recoAs::ntracks_low:
+    return (MCPV.nRecTracks >= m_nTracksToBeRecble && MCPV.nRecTracks < m_nTracksToPrint );
+  case recoAs::ntracks_high:
+    return (MCPV.nRecTracks >= m_nTracksToPrint );
+  case recoAs::z_low:
+    return (MCPV.pMCPV->position().z() < -m_zToPrint );
+  case recoAs::z_middle:
+    return (MCPV.pMCPV->position().z() >= -m_zToPrint && MCPV.pMCPV->position().z() < m_zToPrint);
+  case recoAs::z_high:
+    return (MCPV.pMCPV->position().z() >= m_zToPrint);
+  case recoAs::beauty:
+    return (MCPV.decayBeauty);
+  case recoAs::charm:
+    return (MCPV.decayCharm);
+  case recoAs::strange:
+    return (MCPV.decayStrange);
+  case recoAs::other:
+    return ( !(MCPV.decayBeauty) && !(MCPV.decayCharm) && !(MCPV.decayStrange) );
+  default: return false;
+  }
+}
+
+std::string PrimaryVertexChecker::toString( const recoAs& n) const{
+  switch (n) {
+  case recoAs::all:
+    return format("0%d all",int(recoAs::all));
+  case recoAs::isolated:
+    return format("0%d isolated",int(recoAs::isolated));
+  case recoAs::close:
+    return format("0%d close",int(recoAs::close));
+  case recoAs::ntracks_low:
+    return format("0%d ntracks<%d",int(recoAs::ntracks_low),int(m_nTracksToPrint));
+  case recoAs::ntracks_high:
+    return format("0%d ntracks>=%d",int(recoAs::ntracks_high),int(m_nTracksToPrint));
+  case recoAs::z_low:
+    return format("0%d z<%2.1f",int(recoAs::z_low),-m_zToPrint);
+  case recoAs::z_middle:
+    return format("0%d z in (%2.1f, %2.1f)",int(recoAs::z_middle), -m_zToPrint, +m_zToPrint);
+  case recoAs::z_high:
+    return format("0%d z >=%2.1f",int(recoAs::z_high), +m_zToPrint);
+  case recoAs::beauty:
+    return format("0%d beauty",int(recoAs::beauty));
+  case recoAs::charm:
+    return format("0%d charm",int(recoAs::charm));
+  case recoAs::strange:
+    return format("%d strange",int(recoAs::strange));
+  case recoAs::other:
+    return format("%d other",int(recoAs::other));
+  default: return "not defined";
+  }
+}
 // int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
 //                                                 const LHCb::MCParticles& mcps,
 //                                                 const LHCb::LinksByKey& linker  ) const {
-- 
GitLab


From e64f2630fa66f8ef4ff2b2806b91b5f9ac86001e Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Tue, 4 Feb 2020 11:26:50 +0000
Subject: [PATCH 18/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/7045993
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 518 ++++++++++-----------
 1 file changed, 250 insertions(+), 268 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 3f722d21445..3115e17661f 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -16,9 +16,9 @@
 
 #include "Event/MCHeader.h"
 #include "Event/MCParticle.h"
-#include "Event/MCVertex.h"
-#include "Event/MCTrackInfo.h"
 #include "Event/MCProperty.h"
+#include "Event/MCTrackInfo.h"
+#include "Event/MCVertex.h"
 
 #include "Event/RecVertex.h"
 #include "Event/RecVertex_v2.h"
@@ -34,8 +34,8 @@
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
 
-#include <tuple>
 #include <string>
+#include <tuple>
 #include <vector>
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
@@ -43,7 +43,7 @@
 
 namespace {
 
-  struct MCPVInfo{
+  struct MCPVInfo {
     LHCb::MCVertex*                pMCPV;             // pointer to MC PV
     int                            nRecTracks;        // number of reconstructed tracks from this MCPV
     int                            nRecBackTracks;    // number of reconstructed backward tracks
@@ -56,20 +56,20 @@ namespace {
     bool                           decayStrange;
     std::vector<LHCb::MCParticle*> m_mcPartInMCPV;
     std::vector<LHCb::Track*>      m_recTracksInMCPV;
-};
+  };
 
-  struct RecPVInfo{
+  struct RecPVInfo {
   public:
-  int                               nTracks; // number of tracks
-  double                            chi2;
-  double                            nDoF;
-  int                               mother;
-  Gaudi::XYZPoint                   position;      // position
-  Gaudi::XYZPoint                   positionSigma; // position sigmas
-  int                               indexMCPVInfo; // index to MCPVInfo
-  const LHCb::Event::v2::RecVertex* pRECPV;
-  //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
-};
+    int                               nTracks; // number of tracks
+    double                            chi2;
+    double                            nDoF;
+    int                               mother;
+    Gaudi::XYZPoint                   position;      // position
+    Gaudi::XYZPoint                   positionSigma; // position sigmas
+    int                               indexMCPVInfo; // index to MCPVInfo
+    const LHCb::Event::v2::RecVertex* pRECPV;
+    //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
+  };
 
   inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
 
@@ -77,74 +77,73 @@ namespace {
     double X = std::numeric_limits<double>::signaling_NaN();
     double Y = std::numeric_limits<double>::signaling_NaN();
     Beamline_t( Condition const& c )
-      : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
-      , Y{c.param<double>( "ResolPosY" )} {}
+        : X{( c.param<double>( "ResolPosRC" ) + c.param<double>( "ResolPosLA" ) ) / 2}
+        , Y{c.param<double>( "ResolPosY" )} {}
   };
 
   bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
-  struct Stats{
+  struct Stats {
     std::string name;
-    int MCPV;
-    int RecPV;
-    int FalsePV;
-    int notRecPV;
-    int nTracks;
-    int nMCPart;
+    int         MCPV;
+    int         RecPV;
+    int         FalsePV;
+    int         notRecPV;
+    int         nTracks;
+    int         nMCPart;
   };
 
-  enum class recoAs{
-      all,
-      isolated, close,
-      ntracks_low, ntracks_high,
-      z_low, z_middle, z_high,
-      beauty, charm, strange, other
+  enum class recoAs {
+    all,
+    isolated,
+    close,
+    ntracks_low,
+    ntracks_high,
+    z_low,
+    z_middle,
+    z_high,
+    beauty,
+    charm,
+    strange,
+    other
   };
-  static const recoAs All[] = { recoAs::all,
-                                recoAs::isolated, recoAs::close,
-                                recoAs::ntracks_low, recoAs::ntracks_high,
-                                recoAs::z_low, recoAs::z_middle, recoAs::z_high,
-                                recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
-  static const recoAs part[] = { recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+  static const recoAs All[]  = {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
+                               recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
+                               recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other};
+  static const recoAs part[] = {recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
 
-  static constexpr int size_recAs = int(recoAs::other) + 1;
-
-}
+  static constexpr int size_recAs = int( recoAs::other ) + 1;
 
+} // namespace
 
 class PrimaryVertexChecker
-    : public Gaudi::Functional::Consumer<
-          void( const LHCb::Tracks&,
-                std::vector<LHCb::Event::v2::RecVertex> const&,
-                const LHCb::MCVertices&,
-                const LHCb::MCParticles&,
-                // const LHCb::LinksByKey&,
-                const LHCb::MCHeader&,
-                const LHCb::MCProperty&),
-          Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, std::vector<LHCb::Event::v2::RecVertex> const&,
+                                               const LHCb::MCVertices&, const LHCb::MCParticles&,
+                                               // const LHCb::LinksByKey&,
+                                               const LHCb::MCHeader&, const LHCb::MCProperty& ),
+                                         Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
-      : Consumer{ name,
-                  pSvcLocator,
-                  {KeyValue{"inputTracksName",   LHCb::TrackLocation::Default},
-                   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-                   KeyValue{"MCVertexInput",     LHCb::MCVertexLocation::Default},
-                   KeyValue{"MCParticleInput",   LHCb::MCParticleLocation::Default},
-                   KeyValue{"MCHeaderLocation",  LHCb::MCHeaderLocation::Default},
-                   KeyValue{"MCPropertyInput",   LHCb::MCPropertyLocation::TrackInfo},
-                  //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
-                      }} {}
+      : Consumer{name,
+                 pSvcLocator,
+                 {
+                     KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                     KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                     KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                     KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                     KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
+                     KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
+                     //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+                 }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks,
-                         std::vector<LHCb::Event::v2::RecVertex> const& vertices,
-                         const LHCb::MCVertices&                        mcvtx,
-                         const LHCb::MCParticles&                       mcps,
+  void       operator()( const LHCb::Tracks& tracks, std::vector<LHCb::Event::v2::RecVertex> const& vertices,
+                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                    // const LHCb::LinksByKey& linker,
-                         const LHCb::MCHeader&                          mcheader,
-                         const LHCb::MCProperty&                        flags) const override; ///< Algorithm execution
-  StatusCode finalize() override;                                         ///< Algorithm finalization
+                   const LHCb::MCHeader&   mcheader,
+                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
@@ -162,27 +161,26 @@ private:
   // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
 
   mutable std::map<recoAs, Stats> m_stats;
-  mutable std::vector<Stats> m_stats_multi;
-  mutable int m_nevt;
+  mutable std::vector<Stats>      m_stats_multi;
+  mutable int                     m_nevt;
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
                                                std::vector<MCPVInfo>::iterator& itmc ) const;
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                               const RecPVInfo& rec ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat(const std::string name, const Stats& stat);
-  void printRes(std::string mes, double x, double y, double z);
-  std::string toString( const recoAs& n) const;
-  bool checkCondition(const MCPVInfo& MCPV, const recoAs& n) const;
+  void printRat( const std::string name, const Stats& stat );
+  void printRes( std::string mes, double x, double y, double z );
+  std::string toString( const recoAs& n ) const;
+  bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
 
   //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
   //                                   std::string trackLoc ) const;
-  int  count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
-  void count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
-  double check_histogram(const AIDA::IHistogram1D* h, bool var);
+  int    count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
+  void   count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
+  double check_histogram( const AIDA::IHistogram1D* h, bool var );
   //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
   //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
   //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
@@ -199,32 +197,30 @@ StatusCode PrimaryVertexChecker::initialize() {
   StatusCode sc = GaudiTupleAlg::initialize(); // Must be executed first
   if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
 
-  m_nevt                 = 0;
-
-  for(const auto& n: All)
-    {
-      Stats s;
-      s.MCPV = 0;
-      s.RecPV = 0;
-      s.FalsePV = 0;
-      s.notRecPV = 0;
-      s.nTracks = 0;
-      s.nMCPart = 0;
-      m_stats[n];
-    }
+  m_nevt = 0;
+
+  for ( const auto& n : All ) {
+    Stats s;
+    s.MCPV     = 0;
+    s.RecPV    = 0;
+    s.FalsePV  = 0;
+    s.notRecPV = 0;
+    s.nTracks  = 0;
+    s.nMCPart  = 0;
+    m_stats[n];
+  }
 
-  for(auto i = 0; i<m_multiToPrint.value(); i++)
-    {
-      Stats s;
-      s.name = format("%d_%dMCPV",size_recAs+i+1,i+1);
-      s.MCPV = 0;
-      s.RecPV = 0;
-      s.FalsePV = 0;
-      s.notRecPV = 0;
-      s.nTracks = 0;
-      s.nMCPart = 0;
-      m_stats_multi.push_back(s);
-    }
+  for ( auto i = 0; i < m_multiToPrint.value(); i++ ) {
+    Stats s;
+    s.name     = format( "%d_%dMCPV", size_recAs + i + 1, i + 1 );
+    s.MCPV     = 0;
+    s.RecPV    = 0;
+    s.FalsePV  = 0;
+    s.notRecPV = 0;
+    s.nTracks  = 0;
+    s.nMCPart  = 0;
+    m_stats_multi.push_back( s );
+  }
 
   return StatusCode::SUCCESS;
 }
@@ -234,11 +230,9 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
                                        std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
-                                       const LHCb::MCVertices&                        mcvtx,
-                                       const LHCb::MCParticles&                       mcps,
+                                       const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader&                          mcheader,
-                                       const LHCb::MCProperty&                        flags) const {
+                                       const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
 
   debug() << "==> Execute" << endmsg;
 
@@ -371,51 +365,41 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     double nDoF   = recpvvec[ipv].nDoF;
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
-      fake           = 1;
+      fake                                 = 1;
       std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
 
-      if ( cmc != rblemcpv.end() )
-        {
-          dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
-
-          for(const auto& n: part)
-            {
-              bool cut = false;
-              cut = checkCondition(*cmc,n);
-              if ( cut ) {
-                m_stats[n].FalsePV += 1;
-              }
-            }
-          if ( dist > m_dzIsolated ) {
-            m_stats[recoAs::isolated].FalsePV += 1;
-          }
-          else {
-            m_stats[recoAs::close].FalsePV += 1;
-          }
-          if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
-            m_stats[recoAs::ntracks_high].FalsePV += 1;
-          }
-          else {
-            m_stats[recoAs::ntracks_low].FalsePV += 1;
-          }
+      if ( cmc != rblemcpv.end() ) {
+        dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
 
-          if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
-            m_stats[recoAs::z_low].FalsePV += 1;
-          }
-          else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
-            m_stats[recoAs::z_middle].FalsePV += 1;
-          }
-          else {
-            m_stats[recoAs::z_high].FalsePV += 1;
-          }
+        for ( const auto& n : part ) {
+          bool cut = false;
+          cut      = checkCondition( *cmc, n );
+          if ( cut ) { m_stats[n].FalsePV += 1; }
+        }
+        if ( dist > m_dzIsolated ) {
+          m_stats[recoAs::isolated].FalsePV += 1;
+        } else {
+          m_stats[recoAs::close].FalsePV += 1;
+        }
+        if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
+          m_stats[recoAs::ntracks_high].FalsePV += 1;
+        } else {
+          m_stats[recoAs::ntracks_low].FalsePV += 1;
+        }
 
-          int idx = std::distance(rblemcpv.begin(), cmc);
-          if ( idx < m_multiToPrint ) {
-            m_stats_multi[idx].FalsePV +=1;
-          }
+        if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
+          m_stats[recoAs::z_low].FalsePV += 1;
+        } else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
+          m_stats[recoAs::z_middle].FalsePV += 1;
+        } else {
+          m_stats[recoAs::z_high].FalsePV += 1;
         }
 
+        int idx = std::distance( rblemcpv.begin(), cmc );
+        if ( idx < m_multiToPrint ) { m_stats_multi[idx].FalsePV += 1; }
+      }
+
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -461,24 +445,22 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
 
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
 
-    for(const auto& n: All)
-      {
-        bool cut = false;
-        cut = checkCondition(*itmc,n);
-        if ( cut ) {
-            m_stats[n].MCPV+=1;
-            if (itmc->nRecTracks < m_nTracksToBeRecble ) {
-              m_stats[n].notRecPV+=1;
-            }
-            else {
-              m_stats[n].nMCPart += itmc->nRecTracks;
-            }
-            if ( itmc->indexRecPVInfo > -1 ) {
-              m_stats[n].RecPV+=1;
-              m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
-            }
+    for ( const auto& n : All ) {
+      bool cut = false;
+      cut      = checkCondition( *itmc, n );
+      if ( cut ) {
+        m_stats[n].MCPV += 1;
+        if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
+          m_stats[n].notRecPV += 1;
+        } else {
+          m_stats[n].nMCPart += itmc->nRecTracks;
+        }
+        if ( itmc->indexRecPVInfo > -1 ) {
+          m_stats[n].RecPV += 1;
+          m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
         }
       }
+    }
   }
 
   int mcpv = 0;
@@ -516,16 +498,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     xMC = itmc->pMCPV->position().x();
     rMC = std::sqrt( ( xMC - m_beamSpotX ) * ( xMC - m_beamSpotX ) + ( yMC - m_beamSpotY ) * ( yMC - m_beamSpotY ) );
 
-    if ( mcpv < m_multiToPrint )
-      {
-        m_stats_multi[mcpv].MCPV += 1;
-        if (itmc->nRecTracks < m_nTracksToBeRecble) {
-          m_stats_multi[mcpv].notRecPV+=1;
-        }
-        else {
-          m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
-        }
+    if ( mcpv < m_multiToPrint ) {
+      m_stats_multi[mcpv].MCPV += 1;
+      if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
+        m_stats_multi[mcpv].notRecPV += 1;
+      } else {
+        m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
       }
+    }
 
     if ( indRec > -1 ) {
       high++;
@@ -550,11 +530,10 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
       chi2          = recpvvec[indRec].chi2;
       nDoF          = recpvvec[indRec].nDoF;
 
-      if ( mcpv < m_multiToPrint )
-        {
-          m_stats_multi[mcpv].RecPV += 1;
-          m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
-        }
+      if ( mcpv < m_multiToPrint ) {
+        m_stats_multi[mcpv].RecPV += 1;
+        m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
+      }
       // Filling histograms
       if ( m_produceHistogram ) {
         plot( itmc->pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
@@ -569,33 +548,29 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         plot( dx / errx, 1031, "pullx", -5., 5., 50 );
         plot( dy / erry, 1032, "pully", -5., 5., 50 );
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
-        if ( itmc->nRecTracks < 10){
+        if ( itmc->nRecTracks < 10 ) {
           plot( dx, 1101, "dx", -0.25, 0.25, 50 );
           plot( dy, 1102, "dy", -0.25, 0.25, 50 );
           plot( dz, 1103, "dz", -0.5, 0.5, 50 );
-        }
-        else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30){
+        } else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30 ) {
           plot( dx, 1111, "dx", -0.25, 0.25, 50 );
           plot( dy, 1112, "dy", -0.25, 0.25, 50 );
           plot( dz, 1113, "dz", -0.5, 0.5, 50 );
-        }
-        else{
+        } else {
           plot( dx, 1121, "dx", -0.25, 0.25, 50 );
           plot( dy, 1122, "dy", -0.25, 0.25, 50 );
           plot( dz, 1123, "dz", -0.5, 0.5, 50 );
         }
 
-        if ( itmc->pMCPV->position().z() < -m_zToPrint )    {
+        if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
           plot( dx, 1201, "dx", -0.25, 0.25, 50 );
           plot( dy, 1202, "dy", -0.25, 0.25, 50 );
           plot( dz, 1203, "dz", -0.5, 0.5, 50 );
-        }
-        else if ( itmc->pMCPV->position().z() < m_zToPrint )    {
+        } else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
           plot( dx, 1211, "dx", -0.25, 0.25, 50 );
           plot( dy, 1212, "dy", -0.25, 0.25, 50 );
           plot( dz, 1213, "dz", -0.5, 0.5, 50 );
-        }
-        else {
+        } else {
           plot( dx, 1221, "dx", -0.25, 0.25, 50 );
           plot( dy, 1222, "dy", -0.25, 0.25, 50 );
           plot( dz, 1223, "dz", -0.5, 0.5, 50 );
@@ -726,7 +701,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
                                                                    std::vector<MCPVInfo>::iterator& itmc ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
-  double                        mindist = 999999.;
+  double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
@@ -741,24 +716,23 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
-std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                                                   const RecPVInfo& rec ) const {
+std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>& rblemcpv,
+                                                                   const RecPVInfo&       rec ) const {
 
   std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
-  double                        mindist = 999999.;
+  double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
-      double dist = ( it->pMCPV->position() - rec.pRECPV->position() ).R();
-      if ( dist < mindist ) {
-        mindist = dist;
-        itret   = it;
-      }
+    double dist = ( it->pMCPV->position() - rec.pRECPV->position() ).R();
+    if ( dist < mindist ) {
+      mindist = dist;
+      itret   = it;
+    }
   }
   return itret;
 }
 
-
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
                                              std::vector<LHCb::MCParticle*>& allprods ) const {
 
@@ -782,44 +756,49 @@ StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
 
-  //categories category = all;
-  //info() << " CATEGORY TEST = " << category << endmsg;
+  // categories category = all;
+  // info() << " CATEGORY TEST = " << category << endmsg;
 
-  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed" << endmsg;
+  info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed"
+         << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
-  info() << " MC efficiency split by tracks with threshold: ("<< m_nTracksToBeRecble.value()<<","<<m_nTracksToPrint.value()<<"), >= "<<m_nTracksToPrint.value()<<endmsg;
-  info() << " MC efficiency split by z position: <-"<<m_zToPrint.value()<<", (-"<<m_zToPrint.value()<<","<<m_zToPrint.value()<<"), >"<<m_zToPrint.value()<< endmsg;
+  info() << " MC efficiency split by tracks with threshold: (" << m_nTracksToBeRecble.value() << ","
+         << m_nTracksToPrint.value() << "), >= " << m_nTracksToPrint.value() << endmsg;
+  info() << " MC efficiency split by z position: <-" << m_zToPrint.value() << ", (-" << m_zToPrint.value() << ","
+         << m_zToPrint.value() << "), >" << m_zToPrint.value() << endmsg;
   std::string ff = "by distance";
   info() << " REC and MC vertices matched:  " << ff << endmsg;
 
   info() << " " << endmsg;
 
+  for ( const auto& n : All ) { printRat( toString( n ), m_stats[n] ); }
 
-  for (const auto& n: All)
-    {
-      printRat(toString(n), m_stats[n] );
-    }
-
-  for (auto& mstat : m_stats_multi)
-    {
-      printRat( mstat.name, mstat );
-    }
+  for ( auto& mstat : m_stats_multi ) { printRat( mstat.name, mstat ); }
   info() << " " << endmsg;
 
-  printRes("1_res_all",                check_histogram(histo( HistoID( 1021 ) ),true), check_histogram(histo( HistoID( 1022 ) ), true), check_histogram(histo( HistoID( 1023 ) ),true));
+  printRes( "1_res_all", check_histogram( histo( HistoID( 1021 ) ), true ),
+            check_histogram( histo( HistoID( 1022 ) ), true ), check_histogram( histo( HistoID( 1023 ) ), true ) );
 
-  printRes("2_res_ntracks<10",     check_histogram(histo( HistoID( 1101 ) ),true), check_histogram(histo( HistoID( 1102 ) ), true), check_histogram(histo( HistoID( 1103 ) ),true));
-  printRes("3_res_ntracks(10,30)", check_histogram(histo( HistoID( 1111 ) ),true), check_histogram(histo( HistoID( 1112 ) ), true), check_histogram(histo( HistoID( 1113 ) ),true));
-  printRes("4_res_ntracks>30",     check_histogram(histo( HistoID( 1121 ) ),true), check_histogram(histo( HistoID( 1122 ) ), true), check_histogram(histo( HistoID( 1123 ) ),true));
+  printRes( "2_res_ntracks<10", check_histogram( histo( HistoID( 1101 ) ), true ),
+            check_histogram( histo( HistoID( 1102 ) ), true ), check_histogram( histo( HistoID( 1103 ) ), true ) );
+  printRes( "3_res_ntracks(10,30)", check_histogram( histo( HistoID( 1111 ) ), true ),
+            check_histogram( histo( HistoID( 1112 ) ), true ), check_histogram( histo( HistoID( 1113 ) ), true ) );
+  printRes( "4_res_ntracks>30", check_histogram( histo( HistoID( 1121 ) ), true ),
+            check_histogram( histo( HistoID( 1122 ) ), true ), check_histogram( histo( HistoID( 1123 ) ), true ) );
 
-  printRes("5_res_z<-50",     check_histogram(histo( HistoID( 1201 ) ),true), check_histogram(histo( HistoID( 1202 ) ),true), check_histogram(histo( HistoID( 1203 ) ),true));
-  printRes("6_res_z(-50,50)", check_histogram(histo( HistoID( 1211 ) ),true), check_histogram(histo( HistoID( 1212 ) ),true), check_histogram(histo( HistoID( 1213 ) ),true));
-  printRes("7_res_z>50",      check_histogram(histo( HistoID( 1221 ) ),true), check_histogram(histo( HistoID( 1222 ) ),true), check_histogram(histo( HistoID( 1223 ) ),true));
+  printRes( "5_res_z<-50", check_histogram( histo( HistoID( 1201 ) ), true ),
+            check_histogram( histo( HistoID( 1202 ) ), true ), check_histogram( histo( HistoID( 1203 ) ), true ) );
+  printRes( "6_res_z(-50,50)", check_histogram( histo( HistoID( 1211 ) ), true ),
+            check_histogram( histo( HistoID( 1212 ) ), true ), check_histogram( histo( HistoID( 1213 ) ), true ) );
+  printRes( "7_res_z>50", check_histogram( histo( HistoID( 1221 ) ), true ),
+            check_histogram( histo( HistoID( 1222 ) ), true ), check_histogram( histo( HistoID( 1223 ) ), true ) );
 
   info() << " " << endmsg;
 
-  printRes("1_pull_width_all",  check_histogram(histo( HistoID( 1031 ) ),true), check_histogram(histo( HistoID( 1032 ) ),true), check_histogram(histo( HistoID( 1033 ) ),true));
-  printRes("1_pull_mean_all",   check_histogram(histo( HistoID( 1031 ) ),false), check_histogram(histo( HistoID( 1032 ) ),false), check_histogram(histo( HistoID( 1033 ) ),false));
+  printRes( "1_pull_width_all", check_histogram( histo( HistoID( 1031 ) ), true ),
+            check_histogram( histo( HistoID( 1032 ) ), true ), check_histogram( histo( HistoID( 1033 ) ), true ) );
+  printRes( "1_pull_mean_all", check_histogram( histo( HistoID( 1031 ) ), false ),
+            check_histogram( histo( HistoID( 1032 ) ), false ), check_histogram( histo( HistoID( 1033 ) ), false ) );
 
   info() << " " << endmsg;
 
@@ -828,17 +807,17 @@ StatusCode PrimaryVertexChecker::finalize() {
 
 void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat ) {
 
-  double rat = 0.;
-  double fl = 0.;
-  int all_rec = stat.RecPV+stat.FalsePV;
-  double av_tr = 0.;
-  double av_par = 0.;
-  if ( (stat.MCPV-stat.notRecPV) > 0 ) {
-    rat = 100.0 * stat.RecPV / (stat.MCPV-stat.notRecPV);
-    av_par = 1.0*stat.nMCPart/(stat.MCPV-stat.notRecPV);
+  double rat     = 0.;
+  double fl      = 0.;
+  int    all_rec = stat.RecPV + stat.FalsePV;
+  double av_tr   = 0.;
+  double av_par  = 0.;
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
+    rat    = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV );
+    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
   }
   if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
-  if ( stat.RecPV > 0 ) av_tr = 1.0*stat.nTracks/stat.RecPV;
+  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
   // reformat message
   unsigned int len  = 25;
@@ -846,29 +825,29 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
-  info() << pmes << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: %6.2f [MC: %6.2f]",
-                            stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par) << endmsg;
+  info() << pmes
+         << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: "
+                    "%6.2f [MC: %6.2f]",
+                    stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par )
+         << endmsg;
 }
 
-void PrimaryVertexChecker::printRes(std::string mes, double x, double y, double z){
+void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
   unsigned int len  = 20;
   std::string  pmes = mes;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
-  info() << pmes << format(" x: %+5.3f, y: %+5.3f, z: %+5.3f",
-                           x, y, z) << endmsg;
+  info() << pmes << format( " x: %+5.3f, y: %+5.3f, z: %+5.3f", x, y, z ) << endmsg;
 }
 
-double PrimaryVertexChecker::check_histogram(const AIDA::IHistogram1D* h, bool rms) {
+double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool rms ) {
   if ( h ) {
     if ( rms ) {
       return h->rms();
-    }
-    else {
+    } else {
       return h->mean();
     }
-  }
-  else {
+  } else {
     return 0.;
   }
 }
@@ -923,7 +902,8 @@ int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::
   return nVeloTracks;
 }
 
-void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const {
+void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>&  mcpvvec,
+                                                               const LHCb::MCProperty& flags ) const {
 
   const MCTrackInfo               trInfo = {flags};
   std::vector<MCPVInfo>::iterator itinfomc;
@@ -937,8 +917,8 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     for ( LHCb::MCParticle* pmcp : allproducts ) {
       if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
-        if ( pmcp->particleID().hasBottom() )  { itinfomc->decayBeauty  = true; }
-        if ( pmcp->particleID().hasCharm() )   { itinfomc->decayCharm   = true; }
+        if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
+        if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
         if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
         if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
 
@@ -951,63 +931,65 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
   }
 }
 
-bool  PrimaryVertexChecker::checkCondition( const  MCPVInfo& MCPV, const recoAs& n) const{
-  switch (n) {
+bool PrimaryVertexChecker::checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const {
+  switch ( n ) {
   case recoAs::all:
     return true;
   case recoAs::isolated:
-    return (MCPV.distToClosestMCPV > m_dzIsolated);
+    return ( MCPV.distToClosestMCPV > m_dzIsolated );
   case recoAs::close:
-    return (MCPV.distToClosestMCPV <= m_dzIsolated);
+    return ( MCPV.distToClosestMCPV <= m_dzIsolated );
   case recoAs::ntracks_low:
-    return (MCPV.nRecTracks >= m_nTracksToBeRecble && MCPV.nRecTracks < m_nTracksToPrint );
+    return ( MCPV.nRecTracks >= m_nTracksToBeRecble && MCPV.nRecTracks < m_nTracksToPrint );
   case recoAs::ntracks_high:
-    return (MCPV.nRecTracks >= m_nTracksToPrint );
+    return ( MCPV.nRecTracks >= m_nTracksToPrint );
   case recoAs::z_low:
-    return (MCPV.pMCPV->position().z() < -m_zToPrint );
+    return ( MCPV.pMCPV->position().z() < -m_zToPrint );
   case recoAs::z_middle:
-    return (MCPV.pMCPV->position().z() >= -m_zToPrint && MCPV.pMCPV->position().z() < m_zToPrint);
+    return ( MCPV.pMCPV->position().z() >= -m_zToPrint && MCPV.pMCPV->position().z() < m_zToPrint );
   case recoAs::z_high:
-    return (MCPV.pMCPV->position().z() >= m_zToPrint);
+    return ( MCPV.pMCPV->position().z() >= m_zToPrint );
   case recoAs::beauty:
-    return (MCPV.decayBeauty);
+    return ( MCPV.decayBeauty );
   case recoAs::charm:
-    return (MCPV.decayCharm);
+    return ( MCPV.decayCharm );
   case recoAs::strange:
-    return (MCPV.decayStrange);
+    return ( MCPV.decayStrange );
   case recoAs::other:
-    return ( !(MCPV.decayBeauty) && !(MCPV.decayCharm) && !(MCPV.decayStrange) );
-  default: return false;
+    return ( !( MCPV.decayBeauty ) && !( MCPV.decayCharm ) && !( MCPV.decayStrange ) );
+  default:
+    return false;
   }
 }
 
-std::string PrimaryVertexChecker::toString( const recoAs& n) const{
-  switch (n) {
+std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
+  switch ( n ) {
   case recoAs::all:
-    return format("0%d all",int(recoAs::all));
+    return format( "0%d all", int( recoAs::all ) );
   case recoAs::isolated:
-    return format("0%d isolated",int(recoAs::isolated));
+    return format( "0%d isolated", int( recoAs::isolated ) );
   case recoAs::close:
-    return format("0%d close",int(recoAs::close));
+    return format( "0%d close", int( recoAs::close ) );
   case recoAs::ntracks_low:
-    return format("0%d ntracks<%d",int(recoAs::ntracks_low),int(m_nTracksToPrint));
+    return format( "0%d ntracks<%d", int( recoAs::ntracks_low ), int( m_nTracksToPrint ) );
   case recoAs::ntracks_high:
-    return format("0%d ntracks>=%d",int(recoAs::ntracks_high),int(m_nTracksToPrint));
+    return format( "0%d ntracks>=%d", int( recoAs::ntracks_high ), int( m_nTracksToPrint ) );
   case recoAs::z_low:
-    return format("0%d z<%2.1f",int(recoAs::z_low),-m_zToPrint);
+    return format( "0%d z<%2.1f", int( recoAs::z_low ), -m_zToPrint );
   case recoAs::z_middle:
-    return format("0%d z in (%2.1f, %2.1f)",int(recoAs::z_middle), -m_zToPrint, +m_zToPrint);
+    return format( "0%d z in (%2.1f, %2.1f)", int( recoAs::z_middle ), -m_zToPrint, +m_zToPrint );
   case recoAs::z_high:
-    return format("0%d z >=%2.1f",int(recoAs::z_high), +m_zToPrint);
+    return format( "0%d z >=%2.1f", int( recoAs::z_high ), +m_zToPrint );
   case recoAs::beauty:
-    return format("0%d beauty",int(recoAs::beauty));
+    return format( "0%d beauty", int( recoAs::beauty ) );
   case recoAs::charm:
-    return format("0%d charm",int(recoAs::charm));
+    return format( "0%d charm", int( recoAs::charm ) );
   case recoAs::strange:
-    return format("%d strange",int(recoAs::strange));
+    return format( "%d strange", int( recoAs::strange ) );
   case recoAs::other:
-    return format("%d other",int(recoAs::other));
-  default: return "not defined";
+    return format( "%d other", int( recoAs::other ) );
+  default:
+    return "not defined";
   }
 }
 // int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
-- 
GitLab


From 641a588dace506ac272578a2e78e357630a0d77e Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus752.cern.ch>
Date: Wed, 19 Feb 2020 17:39:35 +0100
Subject: [PATCH 19/42] changing PV class, updating config files and print out,
 fixing a small bug

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 75 ++++++++++++++++------
 1 file changed, 55 insertions(+), 20 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 3115e17661f..bc1f7e44666 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -117,7 +117,8 @@ namespace {
 } // namespace
 
 class PrimaryVertexChecker
-    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, std::vector<LHCb::Event::v2::RecVertex> const&,
+    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, 
+					       LHCb::Event::v2::RecVertices const&,
                                                const LHCb::MCVertices&, const LHCb::MCParticles&,
                                                // const LHCb::LinksByKey&,
                                                const LHCb::MCHeader&, const LHCb::MCProperty& ),
@@ -138,11 +139,12 @@ public:
                  }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks, std::vector<LHCb::Event::v2::RecVertex> const& vertices,
-                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-                   // const LHCb::LinksByKey& linker,
-                   const LHCb::MCHeader&   mcheader,
-                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+  void       operator()( const LHCb::Tracks& tracks, 
+			 LHCb::Event::v2::RecVertices const& vertices,
+			 const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
+			 // const LHCb::LinksByKey& linker,
+			 const LHCb::MCHeader&   mcheader,
+			 const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
   StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
@@ -170,6 +172,7 @@ private:
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
   void printRat( const std::string name, const Stats& stat );
+  void printAvTracks( const std::string name, const Stats& stat );
   void printRes( std::string mes, double x, double y, double z );
   std::string toString( const recoAs& n ) const;
   bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
@@ -229,7 +232,7 @@ StatusCode PrimaryVertexChecker::initialize() {
 // Main execution
 //=============================================================================
 void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
-                                       std::vector<LHCb::Event::v2::RecVertex> const& recoVtx,
+                                       LHCb::Event::v2::RecVertices const& recoVtx,
                                        const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
                                        const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
@@ -239,7 +242,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
   // Event
   m_nevt++;
 
-  if ( recoVtx.size() == 0 ) { return; }
+  //  if ( recoVtx.size() == 0 ) { return; }
 
   std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
   //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
@@ -277,11 +280,12 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     recpvvec.push_back( recinfo );
   }
 
+
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
   for ( const auto& mcpv : mcvtx ) {
-    const LHCb::MCParticle* motherPart = mcpv->mother();
-    if ( 0 == motherPart ) {
+         const LHCb::MCParticle* motherPart = mcpv->mother();
+     if ( 0 == motherPart ) {
       if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
         mcprimvert.pMCPV             = mcpv;
@@ -298,27 +302,36 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         mcprimvert.m_recTracksInMCPV.clear();
         mcpvvec.push_back( mcprimvert );
       }
-    }
+     }
   }
 
+
   count_reconstructible_mc_particles( mcpvvec, flags );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
 
   std::vector<MCPVInfo> rblemcpv;
+  std::vector<MCPVInfo> notrblemcpv;
   std::vector<MCPVInfo> not_rble_but_visible;
   std::vector<MCPVInfo> not_rble;
   int                   nmrc = 0;
 
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
-    rblemcpv.push_back( *itmc );
+    if ( itmc->nRecTracks >= m_nTracksToBeRecble) { 
+      rblemcpv.push_back( *itmc ); 
+    }
+    else {
+      notrblemcpv.push_back( *itmc ); 
+    }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
 
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
+  rblemcpv.insert(rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end());
+
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
     debug() << " ===================================" << endmsg;
@@ -776,6 +789,11 @@ StatusCode PrimaryVertexChecker::finalize() {
   for ( auto& mstat : m_stats_multi ) { printRat( mstat.name, mstat ); }
   info() << " " << endmsg;
 
+  for ( const auto& n : All ) { printAvTracks( toString( n ), m_stats[n] ); }
+
+  for ( auto& mstat : m_stats_multi ) { printAvTracks( mstat.name, mstat ); }
+  info() << " " << endmsg;
+
   printRes( "1_res_all", check_histogram( histo( HistoID( 1021 ) ), true ),
             check_histogram( histo( HistoID( 1022 ) ), true ), check_histogram( histo( HistoID( 1023 ) ), true ) );
 
@@ -810,14 +828,10 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   double rat     = 0.;
   double fl      = 0.;
   int    all_rec = stat.RecPV + stat.FalsePV;
-  double av_tr   = 0.;
-  double av_par  = 0.;
   if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
     rat    = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV );
-    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
   }
   if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
-  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
   // reformat message
   unsigned int len  = 25;
@@ -826,14 +840,35 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   pmes += " : ";
 
   info() << pmes
-         << format( "%8d from %8d [ %5.2f %], false %8d from reco. %8d [ %5.2f %], not recble %8d, av. PV tracks: "
-                    "%6.2f [MC: %6.2f]",
-                    stat.RecPV, stat.MCPV, rat, stat.FalsePV, all_rec, fl, stat.notRecPV, av_tr, av_par )
+         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
+                    stat.RecPV, stat.MCPV-stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV, stat.FalsePV, fl)
+         << endmsg;
+}
+
+void PrimaryVertexChecker::printAvTracks( const std::string name, const Stats& stat ) {
+  double av_tr   = 0.;
+  double av_par  = 0.;
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
+    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
+  }
+   if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
+
+  // reformat message                                                                                                                                                                                                            
+  unsigned int len  = 25;
+  std::string  pmes = name;
+  while ( pmes.length() < len ) { pmes += " "; }
+  pmes += " : ";
+
+  info() << pmes
+         << format( "av. PV tracks: %6.2f [MC: %6.2f]",
+                    av_tr, av_par )
          << endmsg;
+
+
 }
 
 void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
-  unsigned int len  = 20;
+  unsigned int len  = 25;
   std::string  pmes = mes;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
-- 
GitLab


From 04166468232e035d56ba268a31f54f3efd44be98 Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 19 Feb 2020 16:42:13 +0000
Subject: [PATCH 20/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/7269774
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 64 +++++++++-------------
 1 file changed, 25 insertions(+), 39 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index bc1f7e44666..3e54d5ade67 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -117,8 +117,7 @@ namespace {
 } // namespace
 
 class PrimaryVertexChecker
-    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, 
-					       LHCb::Event::v2::RecVertices const&,
+    : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, LHCb::Event::v2::RecVertices const&,
                                                const LHCb::MCVertices&, const LHCb::MCParticles&,
                                                // const LHCb::LinksByKey&,
                                                const LHCb::MCHeader&, const LHCb::MCProperty& ),
@@ -139,12 +138,11 @@ public:
                  }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
-  void       operator()( const LHCb::Tracks& tracks, 
-			 LHCb::Event::v2::RecVertices const& vertices,
-			 const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-			 // const LHCb::LinksByKey& linker,
-			 const LHCb::MCHeader&   mcheader,
-			 const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+  void       operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& vertices,
+                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
+                   // const LHCb::LinksByKey& linker,
+                   const LHCb::MCHeader&   mcheader,
+                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
   StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
@@ -231,8 +229,7 @@ StatusCode PrimaryVertexChecker::initialize() {
 //=============================================================================
 // Main execution
 //=============================================================================
-void PrimaryVertexChecker::operator()( const LHCb::Tracks&                            tracks,
-                                       LHCb::Event::v2::RecVertices const& recoVtx,
+void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& recoVtx,
                                        const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        // const LHCb::LinksByKey& linker,
                                        const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
@@ -280,12 +277,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
     recpvvec.push_back( recinfo );
   }
 
-
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
   for ( const auto& mcpv : mcvtx ) {
-         const LHCb::MCParticle* motherPart = mcpv->mother();
-     if ( 0 == motherPart ) {
+    const LHCb::MCParticle* motherPart = mcpv->mother();
+    if ( 0 == motherPart ) {
       if ( mcpv->type() == LHCb::MCVertex::MCVertexType::ppCollision ) {
         MCPVInfo mcprimvert;
         mcprimvert.pMCPV             = mcpv;
@@ -302,10 +298,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
         mcprimvert.m_recTracksInMCPV.clear();
         mcpvvec.push_back( mcprimvert );
       }
-     }
+    }
   }
 
-
   count_reconstructible_mc_particles( mcpvvec, flags );
 
   std::sort( mcpvvec.begin(), mcpvvec.end(), sortmlt );
@@ -318,11 +313,10 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
 
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
-    if ( itmc->nRecTracks >= m_nTracksToBeRecble) { 
-      rblemcpv.push_back( *itmc ); 
-    }
-    else {
-      notrblemcpv.push_back( *itmc ); 
+    if ( itmc->nRecTracks >= m_nTracksToBeRecble ) {
+      rblemcpv.push_back( *itmc );
+    } else {
+      notrblemcpv.push_back( *itmc );
     }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks > 1 ) { not_rble_but_visible.push_back( *itmc ); }
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
@@ -330,7 +324,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks&
 
   for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
-  rblemcpv.insert(rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end());
+  rblemcpv.insert( rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end() );
 
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
@@ -828,9 +822,7 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   double rat     = 0.;
   double fl      = 0.;
   int    all_rec = stat.RecPV + stat.FalsePV;
-  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
-    rat    = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV );
-  }
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) { rat = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV ); }
   if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
 
   // reformat message
@@ -840,31 +832,25 @@ void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat )
   pmes += " : ";
 
   info() << pmes
-         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
-                    stat.RecPV, stat.MCPV-stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV, stat.FalsePV, fl)
+         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ", stat.RecPV,
+                    stat.MCPV - stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV,
+                    stat.FalsePV, fl )
          << endmsg;
 }
 
 void PrimaryVertexChecker::printAvTracks( const std::string name, const Stats& stat ) {
-  double av_tr   = 0.;
-  double av_par  = 0.;
-  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) {
-    av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV );
-  }
-   if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
+  double av_tr  = 0.;
+  double av_par = 0.;
+  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) { av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV ); }
+  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
-  // reformat message                                                                                                                                                                                                            
+  // reformat message
   unsigned int len  = 25;
   std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
-  info() << pmes
-         << format( "av. PV tracks: %6.2f [MC: %6.2f]",
-                    av_tr, av_par )
-         << endmsg;
-
-
+  info() << pmes << format( "av. PV tracks: %6.2f [MC: %6.2f]", av_tr, av_par ) << endmsg;
 }
 
 void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
-- 
GitLab


From e37cf6fbed3ed4666cc0dedba46614c4cc1d13c6 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus7104.cern.ch>
Date: Wed, 26 Feb 2020 09:23:18 +0100
Subject: [PATCH 21/42] script for efficiency plots, small bugfix for decay
 categories

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 49 +++++++++++-----------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 3e54d5ade67..4604e216d71 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -615,7 +615,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       myTuple->column( "decayCharm", double( itmc->decayCharm ) );
       myTuple->column( "decayBeauty", double( itmc->decayBeauty ) );
       myTuple->column( "decayStrange", double( itmc->decayStrange ) );
-      myTuple->column( "multi", double( high ) );
+      myTuple->column( "multirec", double( high ) );
+      myTuple->column( "multimc", double( mcpv ) );
       myTuple->column( "dx", dx );
       myTuple->column( "dy", dy );
       myTuple->column( "dz", dz );
@@ -740,21 +741,6 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
-void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
-                                             std::vector<LHCb::MCParticle*>& allprods ) const {
-
-  SmartRefVector<LHCb::MCParticle>           daughters = mcvtx->products();
-  SmartRefVector<LHCb::MCParticle>::iterator idau;
-  for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) {
-    double dv2 = ( mcpv->position() - ( *idau )->originVertex()->position() ).Mag2();
-    if ( dv2 > ( 100. * Gaudi::Units::mm ) * ( 100. * Gaudi::Units::mm ) ) continue;
-    LHCb::MCParticle* pmcp = *idau;
-    allprods.push_back( pmcp );
-    SmartRefVector<LHCb::MCVertex>           decays = ( *idau )->endVertices();
-    SmartRefVector<LHCb::MCVertex>::iterator ivtx;
-    for ( ivtx = decays.begin(); ivtx != decays.end(); ivtx++ ) { collectProductss( mcpv, *ivtx, allprods ); }
-  }
-}
 
 //=============================================================================
 //  Finalize
@@ -923,6 +909,22 @@ int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::
   return nVeloTracks;
 }
 
+void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
+                                             std::vector<LHCb::MCParticle*>& allprods ) const {
+
+  SmartRefVector<LHCb::MCParticle>           daughters = mcvtx->products();
+  SmartRefVector<LHCb::MCParticle>::iterator idau;
+  for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) {
+    double dv2 = ( mcpv->position() - ( *idau )->originVertex()->position() ).Mag2();
+    if ( dv2 > ( 100. * Gaudi::Units::mm ) * ( 100. * Gaudi::Units::mm ) ) continue;
+    LHCb::MCParticle* pmcp = *idau;
+    allprods.push_back( pmcp );
+    SmartRefVector<LHCb::MCVertex>           decays = ( *idau )->endVertices();
+    SmartRefVector<LHCb::MCVertex>::iterator ivtx;
+    for ( ivtx = decays.begin(); ivtx != decays.end(); ivtx++ ) { collectProductss( mcpv, *ivtx, allprods ); }
+  }
+}
+
 void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>&  mcpvvec,
                                                                const LHCb::MCProperty& flags ) const {
 
@@ -935,18 +937,15 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     std::vector<LHCb::MCParticle*>   allproducts;
     collectProductss( avtx, avtx, allproducts );
 
-    for ( LHCb::MCParticle* pmcp : allproducts ) {
-      if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-
+      if ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) {
         if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
         if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
         if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
-        if ( pmcp->particleID().threeCharge() != 0 && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-
+        }
+      if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
           double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
           if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
         }
-      }
       itinfomc->nRecTracks = mcPartInMCPV.size();
     }
   }
@@ -1002,11 +1001,11 @@ std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
   case recoAs::z_high:
     return format( "0%d z >=%2.1f", int( recoAs::z_high ), +m_zToPrint );
   case recoAs::beauty:
-    return format( "0%d beauty", int( recoAs::beauty ) );
+    return format( "0%d decayBeauty", int( recoAs::beauty ) );
   case recoAs::charm:
-    return format( "0%d charm", int( recoAs::charm ) );
+    return format( "0%d decayCharm", int( recoAs::charm ) );
   case recoAs::strange:
-    return format( "%d strange", int( recoAs::strange ) );
+    return format( "%d decayStrange", int( recoAs::strange ) );
   case recoAs::other:
     return format( "%d other", int( recoAs::other ) );
   default:
-- 
GitLab


From 0c065f50488fa933e4b3e5e4131ba238912bc707 Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 26 Feb 2020 08:26:33 +0000
Subject: [PATCH 22/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/7342164
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 4604e216d71..7e105a0e6e3 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -741,7 +741,6 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
   return itret;
 }
 
-
 //=============================================================================
 //  Finalize
 //=============================================================================
@@ -941,11 +940,12 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
         if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
         if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
         if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
-        }
-      if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) && ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-          double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-          if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
-        }
+      }
+      if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) &&
+           ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
+        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
+        if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
+      }
       itinfomc->nRecTracks = mcPartInMCPV.size();
     }
   }
-- 
GitLab


From 72cf9083af0e509bfec3788e492f67291defad6a Mon Sep 17 00:00:00 2001
From: Tomasz Wojton <twojton@lxplus752.cern.ch>
Date: Tue, 13 Oct 2020 19:20:40 +0200
Subject: [PATCH 23/42] added ignore()

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 106 +++++++++++----------
 1 file changed, 54 insertions(+), 52 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 567c967d5f2..922277c9d77 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -421,19 +421,19 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     }
     if ( m_produceNtuple ) {
       Tuple myTuple2 = nTuple( 102, "PV_nTuple2", CLID_ColumnWiseTuple );
-      myTuple2->column( "fake", double( fake ) );
-      myTuple2->column( "r", double( r ) );
-      myTuple2->column( "x", double( x ) );
-      myTuple2->column( "y", double( y ) );
-      myTuple2->column( "z", double( z ) );
-      myTuple2->column( "errr", double( errr ) );
-      myTuple2->column( "errz", double( errz ) );
-      myTuple2->column( "errx", double( errx ) );
-      myTuple2->column( "erry", double( erry ) );
-      myTuple2->column( "mother", double( mother ) );
-      myTuple2->column( "chi2", double( chi2 ) );
-      myTuple2->column( "nDoF", double( nDoF ) );
-      myTuple2->write();
+      myTuple2->column( "fake", double( fake ) ).ignore();
+      myTuple2->column( "r", double( r ) ).ignore();
+      myTuple2->column( "x", double( x ) ).ignore();
+      myTuple2->column( "y", double( y ) ).ignore();
+      myTuple2->column( "z", double( z ) ).ignore();
+      myTuple2->column( "errr", double( errr ) ).ignore();
+      myTuple2->column( "errz", double( errz ) ).ignore();
+      myTuple2->column( "errx", double( errx ) ).ignore();
+      myTuple2->column( "erry", double( erry ) ).ignore();
+      myTuple2->column( "mother", double( mother ) ).ignore();
+      myTuple2->column( "chi2", double( chi2 ) ).ignore();
+      myTuple2->column( "nDoF", double( nDoF ) ).ignore();
+      myTuple2->write().ignore();
     }
   }
   // Fill distance to closest recble MC PV and its multiplicity
@@ -600,48 +600,49 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     int    isolated     = 0;
     double dist_closest = itmc->distToClosestMCPV;
     if ( dist_closest > m_dzIsolated ) { isolated = 1; }
+
     // Filling ntuple
     if ( m_produceNtuple ) {
       Tuple myTuple = nTuple( 101, "PV_nTuple", CLID_ColumnWiseTuple );
-      myTuple->column( "reco", double( reconstructed ) );
-      myTuple->column( "isol", double( isolated ) );
-      myTuple->column( "ntracks", double( ntracks_pvrec ) );
-      myTuple->column( "nrectrmc", double( itmc->nRecTracks ) );
-      myTuple->column( "dzclose", dist_closest );
-      myTuple->column( "nmcpv", double( rblemcpv.size() ) );
-      myTuple->column( "mtruemcpv", double( mcheader.numOfPrimaryVertices() ) );
-      myTuple->column( "nmcallpv", double( mcpvvec.size() ) );
-      myTuple->column( "nrecpv", double( recpvvec.size() ) );
-      myTuple->column( "decayCharm", double( itmc->decayCharm ) );
-      myTuple->column( "decayBeauty", double( itmc->decayBeauty ) );
-      myTuple->column( "decayStrange", double( itmc->decayStrange ) );
-      myTuple->column( "multirec", double( high ) );
-      myTuple->column( "multimc", double( mcpv ) );
-      myTuple->column( "dx", dx );
-      myTuple->column( "dy", dy );
-      myTuple->column( "dz", dz );
-      myTuple->column( "x", x );
-      myTuple->column( "y", y );
-      myTuple->column( "r", r );
-      myTuple->column( "zMC", zMC );
-      myTuple->column( "yMC", yMC );
-      myTuple->column( "xMC", xMC );
-      myTuple->column( "rMC", rMC );
-      myTuple->column( "z", z );
-      myTuple->column( "xBeam", m_beamSpotX );
-      myTuple->column( "yBeam", m_beamSpotY );
-      myTuple->column( "errx", errx );
-      myTuple->column( "erry", erry );
-      myTuple->column( "errz", errz );
-      myTuple->column( "errr", errr );
-      myTuple->column( "mother", double( mother ) );
-      myTuple->column( "evtnr", double( m_nevt ) );
-      myTuple->column( "chi2", double( chi2 ) );
-      myTuple->column( "nDoF", double( nDoF ) );
-      myTuple->column( "size_tracks", double( tracks.size() ) );
-      myTuple->column( "size_mcp", double( mcps.size() ) );
-      myTuple->column( "mcpvrec", double( nmrc ) );
-      myTuple->write();
+      myTuple->column( "reco", double( reconstructed ) ).ignore();
+      myTuple->column( "isol", double( isolated ) ).ignore();
+      myTuple->column( "ntracks", double( ntracks_pvrec ) ).ignore();
+      myTuple->column( "nrectrmc", double( itmc->nRecTracks ) ).ignore();
+      myTuple->column( "dzclose", dist_closest ).ignore();
+      myTuple->column( "nmcpv", double( rblemcpv.size() ) ).ignore();
+      myTuple->column( "mtruemcpv", double( mcheader.numOfPrimaryVertices() ) ).ignore();
+      myTuple->column( "nmcallpv", double( mcpvvec.size() ) ).ignore();
+      myTuple->column( "nrecpv", double( recpvvec.size() ) ).ignore();
+      myTuple->column( "decayCharm", double( itmc->decayCharm ) ).ignore();
+      myTuple->column( "decayBeauty", double( itmc->decayBeauty ) ).ignore();
+      myTuple->column( "decayStrange", double( itmc->decayStrange ) ).ignore();
+      myTuple->column( "multirec", double( high ) ).ignore();
+      myTuple->column( "multimc", double( mcpv ) ).ignore();
+      myTuple->column( "dx", dx ).ignore();
+      myTuple->column( "dy", dy ).ignore();
+      myTuple->column( "dz", dz ).ignore();
+      myTuple->column( "x", x ).ignore();
+      myTuple->column( "y", y ).ignore();
+      myTuple->column( "r", r ).ignore();
+      myTuple->column( "zMC", zMC ).ignore();
+      myTuple->column( "yMC", yMC ).ignore();
+      myTuple->column( "xMC", xMC ).ignore();
+      myTuple->column( "rMC", rMC ).ignore();
+      myTuple->column( "z", z ).ignore();
+      myTuple->column( "xBeam", m_beamSpotX ).ignore();
+      myTuple->column( "yBeam", m_beamSpotY ).ignore();
+      myTuple->column( "errx", errx ).ignore();
+      myTuple->column( "erry", erry ).ignore();
+      myTuple->column( "errz", errz ).ignore();
+      myTuple->column( "errr", errr ).ignore();
+      myTuple->column( "mother", double( mother ) ).ignore();
+      myTuple->column( "evtnr", double( m_nevt ) ).ignore();
+      myTuple->column( "chi2", double( chi2 ) ).ignore();
+      myTuple->column( "nDoF", double( nDoF ) ).ignore();
+      myTuple->column( "size_tracks", double( tracks.size() ) ).ignore();
+      myTuple->column( "size_mcp", double( mcps.size() ) ).ignore();
+      myTuple->column( "mcpvrec", double( nmrc ) ).ignore();
+      myTuple->write().ignore();
     }
   }
 
@@ -1060,3 +1061,4 @@ std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
 //  }
 //  return motherPart;
 //}
+
-- 
GitLab


From 79cb0ebc3cde1837907b9dc292db825fdc62cce4 Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Tue, 13 Oct 2020 17:21:23 +0000
Subject: [PATCH 24/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/10391129
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 922277c9d77..752777a8f23 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -1061,4 +1061,3 @@ std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
 //  }
 //  return motherPart;
 //}
-
-- 
GitLab


From 007d321c86ce8134a4980035faaa8bb71f66942e Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus722.cern.ch>
Date: Tue, 1 Dec 2020 17:31:01 +0100
Subject: [PATCH 25/42] fixing tests

---
 Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py b/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
index 4860bc6c27f..29c6cdfa653 100755
--- a/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
+++ b/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
@@ -288,12 +288,12 @@ def PrUpgradeChecking(defTracks={},
         seq.Members += [trassociator]
         GaudiSequencer("MCLinksTrSeq").Members += [seq]
 
-    from Configurables import LHCb__Converters__RecVertex__v2__fromVectorLHCbRecVertex as FromVectorLHCbRecVertex
-    vertexConverter = FromVectorLHCbRecVertex("VertexConverter")
-    vertexConverter.InputVerticesName = "Rec/Vertex/Vector/Primary"
-    vertexConverter.InputTracksName = defTracksConverted["Velo"]["Location"]
-    vertexConverter.OutputVerticesName = "Rec/Vertex/Primary"
-    GaudiSequencer("MCLinksTrSeq").Members += [vertexConverter]
+    #from Configurables import LHCb__Converters__RecVertex__v2__fromVectorLHCbRecVertex as FromVectorLHCbRecVertex
+    #vertexConverter = FromVectorLHCbRecVertex("VertexConverter")
+    #vertexConverter.InputVerticesName = "Rec/Vertex/Vector/Primary"
+    #vertexConverter.InputTracksName = defTracksConverted["Velo"]["Location"]
+    #vertexConverter.OutputVerticesName = "Rec/Vertex/Primary"
+    #GaudiSequencer("MCLinksTrSeq").Members += [vertexConverter]
 
     from Configurables import PrTrackChecker, PrUTHitChecker
     from Configurables import LoKi__Hybrid__MCTool
@@ -466,9 +466,7 @@ def PrUpgradeChecking(defTracks={},
         from Configurables import PrimaryVertexChecker
         PVCheck = PrimaryVertexChecker("PVChecker")
         if not PVCheck.isPropertySet('inputVerticesName'):
-            PVCheck.inputVerticesName = "Rec/Vertex/Primary"
-        if not PVCheck.isPropertySet('matchByTracks'):
-            PVCheck.matchByTracks = False
+            PVCheck.inputVerticesName = "Rec/Vertex/Vector/Primary" 
         if not PVCheck.isPropertySet('nTracksToBeRecble'):
             PVCheck.nTracksToBeRecble = 4
         if not PVCheck.isPropertySet('inputTracksName'):
-- 
GitLab


From 42c0d8dfb16c50ac4039f77142154b054bdfddb7 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus752.cern.ch>
Date: Tue, 1 Dec 2020 17:41:06 +0100
Subject: [PATCH 26/42] removing commented lines

---
 Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py b/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
index 29c6cdfa653..6f856f1c170 100755
--- a/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
+++ b/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
@@ -288,13 +288,6 @@ def PrUpgradeChecking(defTracks={},
         seq.Members += [trassociator]
         GaudiSequencer("MCLinksTrSeq").Members += [seq]
 
-    #from Configurables import LHCb__Converters__RecVertex__v2__fromVectorLHCbRecVertex as FromVectorLHCbRecVertex
-    #vertexConverter = FromVectorLHCbRecVertex("VertexConverter")
-    #vertexConverter.InputVerticesName = "Rec/Vertex/Vector/Primary"
-    #vertexConverter.InputTracksName = defTracksConverted["Velo"]["Location"]
-    #vertexConverter.OutputVerticesName = "Rec/Vertex/Primary"
-    #GaudiSequencer("MCLinksTrSeq").Members += [vertexConverter]
-
     from Configurables import PrTrackChecker, PrUTHitChecker
     from Configurables import LoKi__Hybrid__MCTool
     MCHybridFactory = LoKi__Hybrid__MCTool("MCHybridFactory")
@@ -466,7 +459,7 @@ def PrUpgradeChecking(defTracks={},
         from Configurables import PrimaryVertexChecker
         PVCheck = PrimaryVertexChecker("PVChecker")
         if not PVCheck.isPropertySet('inputVerticesName'):
-            PVCheck.inputVerticesName = "Rec/Vertex/Vector/Primary" 
+            PVCheck.inputVerticesName = "Rec/Vertex/Vector/Primary"
         if not PVCheck.isPropertySet('nTracksToBeRecble'):
             PVCheck.nTracksToBeRecble = 4
         if not PVCheck.isPropertySet('inputTracksName'):
-- 
GitLab


From adac384ba1a4f77b3c61214816705104d40e2c0b Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus768.cern.ch>
Date: Wed, 16 Dec 2020 10:17:59 +0100
Subject: [PATCH 27/42] update to Gaudi counters, adding beamline condition and
 other small fixed

---
 Tr/PatChecker/CMakeLists.txt               |   5 +-
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 458 +++++++--------------
 2 files changed, 160 insertions(+), 303 deletions(-)

diff --git a/Tr/PatChecker/CMakeLists.txt b/Tr/PatChecker/CMakeLists.txt
index 257b46b2ce2..dee8005e0bd 100644
--- a/Tr/PatChecker/CMakeLists.txt
+++ b/Tr/PatChecker/CMakeLists.txt
@@ -13,7 +13,8 @@
 ################################################################################
 gaudi_subdir(PatChecker v3r16p1)
 
-gaudi_depends_on_subdirs(Event/DigiEvent
+gaudi_depends_on_subdirs(Det/VeloDet
+	                 Event/DigiEvent
                          Event/LinkerEvent
                          Event/MCEvent
                          Event/PhysEvent
@@ -32,5 +33,5 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS})
 gaudi_add_module(PatChecker
                  src/*.cpp
                  INCLUDE_DIRS AIDA GSL Event/DigiEvent Kernel/MCInterfaces Tf/TfKernel
-                 LINK_LIBRARIES GSL LinkerEvent MCEvent PhysEvent GaudiAlgLib GaudiKernel)
+                 LINK_LIBRARIES GSL LinkerEvent MCEvent PhysEvent GaudiAlgLib GaudiKernel VeloDetLib)
 
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 752777a8f23..6cdb26a0008 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -68,7 +68,6 @@ namespace {
     Gaudi::XYZPoint                   positionSigma; // position sigmas
     int                               indexMCPVInfo; // index to MCPVInfo
     const LHCb::Event::v2::RecVertex* pRECPV;
-    //  LHCb::RecVertex* pRECPV;        // pointer to REC PV
   };
 
   inline const std::string beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
@@ -83,16 +82,6 @@ namespace {
 
   bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
 
-  struct Stats {
-    std::string name;
-    int         MCPV;
-    int         RecPV;
-    int         FalsePV;
-    int         notRecPV;
-    int         nTracks;
-    int         nMCPart;
-  };
-
   enum class recoAs {
     all,
     isolated,
@@ -105,155 +94,132 @@ namespace {
     beauty,
     charm,
     strange,
-    other
+    other,
+    first,
+    second,
+    third,
+    fourth,
+    fifth
   };
-  static const recoAs All[]  = {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
-                               recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
-                               recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other};
-  static const recoAs part[] = {recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
 
-  static constexpr int size_recAs = int( recoAs::other ) + 1;
+  std::array<recoAs, 17> All{ {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
+	                      recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
+	                      recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other,
+	                      recoAs::first,        recoAs::second,   recoAs::third,    recoAs::fourth, recoAs::fifth } 
+  }; 
+
+  std::array<recoAs, 5> Part{ {recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other}}; 
+  std::array<recoAs, 12> Basic{ {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
+	recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
+	recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other}
+  }; 
+
+  constexpr int size_basic = static_cast<int>( recoAs::other ) + 1;
+  constexpr int size_recoAs = static_cast<int>( recoAs::fifth ) + 1;
+  constexpr int size_multi = size_recoAs - size_basic; 
+  constexpr int begin_multi = static_cast<int>( recoAs::first );
 
 } // namespace
 
 class PrimaryVertexChecker
     : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, LHCb::Event::v2::RecVertices const&,
                                                const LHCb::MCVertices&, const LHCb::MCParticles&,
-                                               // const LHCb::LinksByKey&,
-                                               const LHCb::MCHeader&, const LHCb::MCProperty& ),
-                                         Gaudi::Functional::Traits::BaseClass_t<GaudiTupleAlg>> {
+                                               const LHCb::MCHeader&, const LHCb::MCProperty&,
+					       const Beamline_t&),					 
+                                               LHCb::DetDesc::usesBaseAndConditions<GaudiTupleAlg, Beamline_t>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
       : Consumer{name,
                  pSvcLocator,
                  {
-                     KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-                     KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-                     KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
-                     KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-                     KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
-                     KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
-                     //                    KeyValue{"LinkerLocation", "Link/Pr/LHCbID"},
+		   KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+		   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+		   KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+		   KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+		   KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
+		   KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
+		   KeyValue{"BeamSpotLocation", "AlgorithmSpecific-" + name + "-beamspot"},
                  }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
   void       operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& vertices,
-                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-                   // const LHCb::LinksByKey& linker,
-                   const LHCb::MCHeader&   mcheader,
-                   const LHCb::MCProperty& flags ) const override; ///< Algorithm execution
+			 const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
+			 const LHCb::MCHeader&   mcheader,
+			 const LHCb::MCProperty& flags,
+			 const Beamline_t&) const override; ///< Algorithm execution
   StatusCode finalize() override;                                        ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};
-  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};
-  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};
-  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};
-  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm};
-  Gaudi::Property<int>    m_nTracksToPrint{this, "nTracksToPrint", 10.0};
-  Gaudi::Property<double> m_zToPrint{this, "zToPrint", 50.0 * Gaudi::Units::mm};
-  Gaudi::Property<int>    m_multiToPrint{this, "multiToPrint", 5.0};
-
-  // Gaudi::Property<bool>   m_matchByTracks{this, "matchByTracks", false};
-
-  mutable std::map<recoAs, Stats> m_stats;
-  mutable std::vector<Stats>      m_stats_multi;
-  mutable int                     m_nevt;
+  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};         // min number of tracks in PV
+  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};        // producing histograms (light version)
+  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};             // producing NTuples (full version)
+  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};                  // requiring VELO for tracks
+  Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm}; // split close/isolated PVs
+  Gaudi::Property<int>    m_nTracksToPrint{this, "nTracksToPrint", 10};              // split low/high multiplicity PVs
+  Gaudi::Property<double> m_zToPrint{this, "zToPrint", 50.0 * Gaudi::Units::mm};     // split in z 
+
+  mutable Gaudi::Accumulators::Counter<>   m_nevt{this, "nEvents"};
+  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_false;     // False PVs vs Reco PVs
+  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_eff;       // MC reconstructible vs Reconstructed 
+  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_mcpv;      // MC vs MC reconstrucible   
+  mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_mcp;    // average mc particles in MCPV
+  mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_tracks; // average tracks in RecoPV 
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
                                                std::vector<MCPVInfo>::iterator& itmc ) const;
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( const std::string name, const Stats& stat );
-  void printAvTracks( const std::string name, const Stats& stat );
+  void printRat( const std::string name,
+		 const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
+		 const Gaudi::Accumulators::BinomialCounter<> m_eff,
+		 const Gaudi::Accumulators::BinomialCounter<> m_false);
+  void printAvTracks( const std::string name,
+		      const Gaudi::Accumulators::AveragingCounter<> m_av_tracks,
+		      const Gaudi::Accumulators::AveragingCounter<> m_av_mcp  );
   void printRes( std::string mes, double x, double y, double z );
   std::string toString( const recoAs& n ) const;
   bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
 
-  //  void match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-  void match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
-  //  void count_reconstructed_tracks( std::vector<MCPVInfo>& mcpvvec, std::vector<LHCb::Track*>& vecOfTracks,
-  //                                   std::string trackLoc ) const;
+  void   match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo, std::vector<MCPVInfo>& mcpvvec ) const;
   int    count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
   void   count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
   double check_histogram( const AIDA::IHistogram1D* h, bool var );
-  //   bool getInputTracks( std::vector<LHCb::Track*>& vecOfTracks ) const;
-  //   bool getInputVertices( std::vector<LHCb::RecVertex*>& vecOfVertices ) const;
-  //  int check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV, const LHCb::MCParticles&
-  //  mcps, const LHCb::LinksByKey& linker ) const;
+
 };
 
 // Declaration of the Algorithm Factory
-DECLARE_COMPONENT( PrimaryVertexChecker )
+DECLARE_COMPONENT_WITH_ID(PrimaryVertexChecker, "PrimaryVertexChecker") 
 
-//=============================================================================
-// Initialization
-//=============================================================================
 StatusCode PrimaryVertexChecker::initialize() {
-  StatusCode sc = GaudiTupleAlg::initialize(); // Must be executed first
-  if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
-
-  m_nevt = 0;
-
-  for ( const auto& n : All ) {
-    Stats s;
-    s.MCPV     = 0;
-    s.RecPV    = 0;
-    s.FalsePV  = 0;
-    s.notRecPV = 0;
-    s.nTracks  = 0;
-    s.nMCPart  = 0;
-    m_stats[n];
-  }
-
-  for ( auto i = 0; i < m_multiToPrint.value(); i++ ) {
-    Stats s;
-    s.name     = format( "%d_%dMCPV", size_recAs + i + 1, i + 1 );
-    s.MCPV     = 0;
-    s.RecPV    = 0;
-    s.FalsePV  = 0;
-    s.notRecPV = 0;
-    s.nTracks  = 0;
-    s.nMCPart  = 0;
-    m_stats_multi.push_back( s );
-  }
+  auto sc = Consumer::initialize().andThen([&] { addConditionDerivation<Beamline_t( Condition const& )>({beamSpotCond}, inputLocation<Beamline_t>() ); } );
 
+  if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
   return StatusCode::SUCCESS;
-}
+  }
 
 //=============================================================================
 // Main execution
 //=============================================================================
 void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& recoVtx,
                                        const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-                                       // const LHCb::LinksByKey& linker,
-                                       const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags ) const {
+                                       const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags,
+				       const Beamline_t&  beamline) const {
 
   debug() << "==> Execute" << endmsg;
-
   // Event
   m_nevt++;
-
-  //  if ( recoVtx.size() == 0 ) { return; }
-
-  std::string m_beamSpotCond = "/dd/Conditions/Online/Velo/MotionSystem";
-  //  Condition *myCond =  get<Condition>(detSvc(), m_beamSpotCond );
-  const double xRC = 0.0; // myCond -> paramAsDouble ( "ResolPosRC" ) ;
-  const double xLA = 0.0; // myCond -> paramAsDouble ( "ResolPosLA" ) ;
-  const double Y   = 0.0; // myCond -> paramAsDouble ( "ResolPosY"  ) ;
-
-  double m_beamSpotX = ( xRC + xLA ) / 2;
-  double m_beamSpotY = Y;
-
+  
   if ( debugLevel() ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
-
+  
   // Fill reconstucted PV info
   std::vector<RecPVInfo> recpvvec;
+  recpvvec.reserve(recoVtx.size()); 
+
   for ( const auto& pv : recoVtx ) {
     RecPVInfo recinfo;
     recinfo.pRECPV            = ( &pv );
@@ -270,8 +236,6 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     recinfo.indexMCPVInfo = -1;
 
     int mother = 0;
-    // if ( m_matchByTracks ) { mother = check_mother_particle( pv.tracks(), mcps, linker ); } //not accesible yet
-
     recinfo.mother        = mother;
     recinfo.indexMCPVInfo = -1;
     recpvvec.push_back( recinfo );
@@ -279,6 +243,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
+  mcpvvec.reserve(mcvtx.size()); 
+
   for ( const auto& mcpv : mcvtx ) {
     const LHCb::MCParticle* motherPart = mcpv->mother();
     if ( 0 == motherPart ) {
@@ -309,7 +275,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   std::vector<MCPVInfo> notrblemcpv;
   std::vector<MCPVInfo> not_rble_but_visible;
   std::vector<MCPVInfo> not_rble;
-  int                   nmrc = 0;
+  int  nmrc = 0;
 
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
@@ -322,14 +288,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
 
-  for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
+  for ( int ipv = 0; ipv < static_cast<int>(recpvvec.size()); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
 
   rblemcpv.insert( rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end() );
 
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
     debug() << " ===================================" << endmsg;
-    for ( int imcpv = 0; imcpv < (int)rblemcpv.size(); imcpv++ ) {
+    for ( int imcpv = 0; imcpv < static_cast<int>(rblemcpv.size()); imcpv++ ) {
       std::string     ff   = " ";
       LHCb::MCVertex* mcpv = rblemcpv[imcpv].pMCPV;
       if ( rblemcpv[imcpv].indexRecPVInfo < 0 ) ff = "  NOTRECO";
@@ -341,7 +307,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
     debug() << endmsg << " REC vertices " << endmsg;
     debug() << " ===================================" << endmsg;
-    for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) {
+    for ( int ipv = 0; ipv < static_cast<int>(recpvvec.size()); ipv++ ) {
       std::string ff = " ";
       if ( recpvvec[ipv].indexMCPVInfo < 0 ) ff = "  FALSE  ";
       debug()
@@ -357,7 +323,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
   // find nr of false PV
   int nFalsePV_real = 0;
-  for ( int ipv = 0; ipv < (int)recpvvec.size(); ipv++ ) {
+  for ( int ipv = 0; ipv < static_cast<int>(recpvvec.size()); ipv++ ) {
     int    fake   = 0;
     double x      = recpvvec[ipv].position.x();
     double y      = recpvvec[ipv].position.y();
@@ -376,37 +342,40 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
 
+      
       if ( cmc != rblemcpv.end() ) {
         dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
 
-        for ( const auto& n : part ) {
+        for ( const auto& n : Part ) {
           bool cut = false;
           cut      = checkCondition( *cmc, n );
-          if ( cut ) { m_stats[n].FalsePV += 1; }
+	  if ( cut ) { m_false[n] += true; }
         }
-        if ( dist > m_dzIsolated ) {
-          m_stats[recoAs::isolated].FalsePV += 1;
+        if ( dist > m_dzIsolated.value() ) {
+          m_false[recoAs::isolated]+= true;
         } else {
-          m_stats[recoAs::close].FalsePV += 1;
+	  m_false[recoAs::close]+= true;
         }
-        if ( recpvvec[ipv].nTracks >= m_nTracksToPrint ) {
-          m_stats[recoAs::ntracks_high].FalsePV += 1;
+        if ( recpvvec[ipv].nTracks >= m_nTracksToPrint.value() ) {
+          m_false[recoAs::ntracks_high]+= true;
         } else {
-          m_stats[recoAs::ntracks_low].FalsePV += 1;
+	  m_false[recoAs::ntracks_low]+= true;
         }
 
-        if ( recpvvec[ipv].position.z() < -m_zToPrint ) {
-          m_stats[recoAs::z_low].FalsePV += 1;
-        } else if ( recpvvec[ipv].position.z() < m_zToPrint ) {
-          m_stats[recoAs::z_middle].FalsePV += 1;
+        if ( recpvvec[ipv].position.z() < -m_zToPrint.value() ) {
+          m_false[recoAs::z_low]+=true;
+        } else if ( recpvvec[ipv].position.z() < m_zToPrint.value() ) {
+          m_false[recoAs::z_middle]+= true;
         } else {
-          m_stats[recoAs::z_high].FalsePV += 1;
+	  m_false[recoAs::z_high]+= true;
         }
 
         int idx = std::distance( rblemcpv.begin(), cmc );
-        if ( idx < m_multiToPrint ) { m_stats_multi[idx].FalsePV += 1; }
+        if ( idx < size_multi ) {
+	  m_false[All[begin_multi+idx]] += true;
+	}
       }
-
+      
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -451,20 +420,25 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   }
 
   for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
-
-    for ( const auto& n : All ) {
+    for ( const auto& n : Basic ) {
       bool cut = false;
       cut      = checkCondition( *itmc, n );
       if ( cut ) {
-        m_stats[n].MCPV += 1;
         if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
-          m_stats[n].notRecPV += 1;
+	  m_mcpv[n] += false;
         } else {
-          m_stats[n].nMCPart += itmc->nRecTracks;
-        }
+	  m_mcpv[n] += true;
+	  m_av_mcp[n] += itmc->nRecTracks; 
+	if ( itmc->indexRecPVInfo < 0 ) {
+	  m_eff[n] += false;
+	}
+	else {
+	  m_eff[n] += true;
+	  m_false[n]+= false;
+	}
+	}
         if ( itmc->indexRecPVInfo > -1 ) {
-          m_stats[n].RecPV += 1;
-          m_stats[n].nTracks += recpvvec[itmc->indexRecPVInfo].nTracks;
+	  m_av_tracks[n] += recpvvec[itmc->indexRecPVInfo].nTracks; 
         }
       }
     }
@@ -503,14 +477,21 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     zMC = itmc->pMCPV->position().z();
     yMC = itmc->pMCPV->position().y();
     xMC = itmc->pMCPV->position().x();
-    rMC = std::sqrt( ( xMC - m_beamSpotX ) * ( xMC - m_beamSpotX ) + ( yMC - m_beamSpotY ) * ( yMC - m_beamSpotY ) );
+    rMC = std::sqrt( ( xMC - beamline.X ) * ( xMC - beamline.X ) + ( yMC - beamline.Y ) * ( yMC - beamline.Y ) );
 
-    if ( mcpv < m_multiToPrint ) {
-      m_stats_multi[mcpv].MCPV += 1;
+    if ( mcpv < size_multi ) {
       if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
-        m_stats_multi[mcpv].notRecPV += 1;
+	m_mcpv[All[begin_multi+mcpv]] += false;
       } else {
-        m_stats_multi[mcpv].nMCPart += itmc->nRecTracks;
+	m_mcpv[All[begin_multi+mcpv]] += true;
+	m_av_mcp[All[begin_multi+mcpv]] += itmc->nRecTracks; 
+	if ( itmc->indexRecPVInfo < 0 ) {
+          m_eff[All[begin_multi+mcpv]] += false;
+        }
+        else {
+          m_eff[All[begin_multi+mcpv]] += true;
+	  m_false[All[begin_multi+mcpv]]+= false;
+        }
       }
     }
 
@@ -524,8 +505,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       x             = recpvvec[indRec].position.x();
       y             = recpvvec[indRec].position.y();
       z             = recpvvec[indRec].position.z();
-      // zMC = itmc->pMCPV->position().z();
-      r    = std::sqrt( ( x - m_beamSpotX ) * ( x - m_beamSpotX ) + ( y - m_beamSpotY ) * ( y - m_beamSpotY ) );
+      r    = std::sqrt( ( x - beamline.X ) * ( x - beamline.X ) + ( y - beamline.Y ) * ( y - beamline.Y ) );
       errx = recpvvec[indRec].positionSigma.x();
       erry = recpvvec[indRec].positionSigma.y();
       errz = recpvvec[indRec].positionSigma.z();
@@ -537,9 +517,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       chi2          = recpvvec[indRec].chi2;
       nDoF          = recpvvec[indRec].nDoF;
 
-      if ( mcpv < m_multiToPrint ) {
-        m_stats_multi[mcpv].RecPV += 1;
-        m_stats_multi[mcpv].nTracks += recpvvec[indRec].nTracks;
+      if ( mcpv < size_multi ) {
+	m_av_tracks[All[begin_multi+mcpv]] += recpvvec[indRec].nTracks;
       }
       // Filling histograms
       if ( m_produceHistogram ) {
@@ -599,7 +578,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
     int    isolated     = 0;
     double dist_closest = itmc->distToClosestMCPV;
-    if ( dist_closest > m_dzIsolated ) { isolated = 1; }
+    if ( dist_closest > m_dzIsolated.value() ) { isolated = 1; }
 
     // Filling ntuple
     if ( m_produceNtuple ) {
@@ -629,14 +608,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       myTuple->column( "xMC", xMC ).ignore();
       myTuple->column( "rMC", rMC ).ignore();
       myTuple->column( "z", z ).ignore();
-      myTuple->column( "xBeam", m_beamSpotX ).ignore();
-      myTuple->column( "yBeam", m_beamSpotY ).ignore();
+      myTuple->column( "xBeam", beamline.X ).ignore();
+      myTuple->column( "yBeam", beamline.Y ).ignore();
       myTuple->column( "errx", errx ).ignore();
       myTuple->column( "erry", erry ).ignore();
       myTuple->column( "errz", errz ).ignore();
       myTuple->column( "errr", errr ).ignore();
       myTuple->column( "mother", double( mother ) ).ignore();
-      myTuple->column( "evtnr", double( m_nevt ) ).ignore();
+      myTuple->column( "evtnr", double( m_nevt.nEntries() ) ).ignore();
       myTuple->column( "chi2", double( chi2 ) ).ignore();
       myTuple->column( "nDoF", double( nDoF ) ).ignore();
       myTuple->column( "size_tracks", double( tracks.size() ) ).ignore();
@@ -649,48 +628,13 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   return;
 }
 
-// void PrimaryVertexChecker::match_mc_vertex_by_tracks( int ipv, std::vector<RecPVInfo>& rinfo,
-//                                                      std::vector<MCPVInfo>& mcpvvec ) const {
-//
-//  LHCb::RecVertex*                          invtx = rinfo[ipv].pRECPV;
-//  typedef const SmartRefVector<LHCb::Track> PVTRACKS;
-//  PVTRACKS&                                 tracksIn = invtx->tracks();
-//  PVTRACKS::const_iterator                  itin;
-//
-//  int    indexmc  = -1;
-//  double ratiomax = 0.;
-//  for ( int imc = 0; imc < (int)mcpvvec.size(); imc++ ) {
-//    if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
-//    int ntrin = 0;
-//    for ( std::vector<LHCb::Track*>::iterator itr = mcpvvec[imc].m_recTracksInMCPV.begin();
-//          itr != mcpvvec[imc].m_recTracksInMCPV.end(); itr++ ) {
-//      for ( itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-//        const LHCb::Track* ptr = *itin;
-//        if ( ptr == *itr ) {
-//          ntrin++;
-//          break;
-//        }
-//      }
-//    }
-//    double ratio = 1. * ntrin / tracksIn.size();
-//    if ( ratio > ratiomax ) {
-//      ratiomax = ratio;
-//      indexmc  = imc;
-//    }
-//  } // imc
-//  if ( ratiomax > 0.05 ) {
-//    rinfo[ipv].indexMCPVInfo        = indexmc;
-//    mcpvvec[indexmc].indexRecPVInfo = ipv;
-//  }
-//}
-
 void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<RecPVInfo>& rinfo,
                                                         std::vector<MCPVInfo>& mcpvvec ) const {
 
   double mindist = 999999.;
   int    indexmc = -1;
 
-  for ( int imc = 0; imc < (int)mcpvvec.size(); imc++ ) {
+  for ( int imc = 0; imc < static_cast<int>(mcpvvec.size()); imc++ ) {
     if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
     double dist = fabs( mcpvvec[imc].pMCPV->position().z() - rinfo[ipv].position.z() );
     if ( dist < mindist ) {
@@ -748,10 +692,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
-
-  // categories category = all;
-  // info() << " CATEGORY TEST = " << category << endmsg;
-
+  info() << "     ************************************ "<<endmsg;
   info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed"
          << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
@@ -762,16 +703,10 @@ StatusCode PrimaryVertexChecker::finalize() {
   std::string ff = "by distance";
   info() << " REC and MC vertices matched:  " << ff << endmsg;
 
+  info() << " " << endmsg;  
+  for ( const auto& n : All ) { printRat( toString( n ), m_mcpv[n], m_eff[n], m_false[n] ); }
   info() << " " << endmsg;
-
-  for ( const auto& n : All ) { printRat( toString( n ), m_stats[n] ); }
-
-  for ( auto& mstat : m_stats_multi ) { printRat( mstat.name, mstat ); }
-  info() << " " << endmsg;
-
-  for ( const auto& n : All ) { printAvTracks( toString( n ), m_stats[n] ); }
-
-  for ( auto& mstat : m_stats_multi ) { printAvTracks( mstat.name, mstat ); }
+  for ( const auto& n : All ) { printAvTracks( toString( n ), m_av_tracks[n], m_av_mcp[n] );}
   info() << " " << endmsg;
 
   printRes( "1_res_all", check_histogram( histo( HistoID( 1021 ) ), true ),
@@ -803,40 +738,34 @@ StatusCode PrimaryVertexChecker::finalize() {
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( const std::string name, const Stats& stat ) {
-
-  double rat     = 0.;
-  double fl      = 0.;
-  int    all_rec = stat.RecPV + stat.FalsePV;
-  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) { rat = 100.0 * stat.RecPV / ( stat.MCPV - stat.notRecPV ); }
-  if ( all_rec > 0 ) fl = 100.0 * stat.FalsePV / all_rec;
 
-  // reformat message
+void PrimaryVertexChecker::printRat( const std::string name,
+				     const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
+				     const Gaudi::Accumulators::BinomialCounter<> m_eff,
+				     const Gaudi::Accumulators::BinomialCounter<> m_false) {
   unsigned int len  = 25;
   std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
   info() << pmes
-         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ", stat.RecPV,
-                    stat.MCPV - stat.notRecPV, stat.MCPV, stat.notRecPV, rat, stat.FalsePV, all_rec, stat.RecPV,
-                    stat.FalsePV, fl )
+         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ", 
+                    m_eff.nTrueEntries(), m_eff.nEntries(), m_mcpv.nEntries(), m_mcpv.nFalseEntries(), m_eff.efficiency()*100, 
+		    m_false.nTrueEntries(), m_false.nEntries(),  m_false.nFalseEntries(), m_false.nTrueEntries(), m_false.efficiency()*100
+		    )
          << endmsg;
-}
 
-void PrimaryVertexChecker::printAvTracks( const std::string name, const Stats& stat ) {
-  double av_tr  = 0.;
-  double av_par = 0.;
-  if ( ( stat.MCPV - stat.notRecPV ) > 0 ) { av_par = 1.0 * stat.nMCPart / ( stat.MCPV - stat.notRecPV ); }
-  if ( stat.RecPV > 0 ) av_tr = 1.0 * stat.nTracks / stat.RecPV;
 
-  // reformat message
+}
+
+void PrimaryVertexChecker::printAvTracks( const std::string name, 
+					  const Gaudi::Accumulators::AveragingCounter<> m_av_tracks, 
+					  const Gaudi::Accumulators::AveragingCounter<> m_av_mcp  ) {
   unsigned int len  = 25;
   std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
-
-  info() << pmes << format( "av. PV tracks: %6.2f [MC: %6.2f]", av_tr, av_par ) << endmsg;
+  info() << pmes << format( "av. PV tracks: %6.2f [MC: %6.2f]", m_av_tracks.mean(), m_av_mcp.mean() ) << endmsg;
 }
 
 void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double z ) {
@@ -859,48 +788,6 @@ double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool
   }
 }
 
-// void PrimaryVertexChecker::count_reconstructed_tracks( std::vector<MCPVInfo>&     mcpvvec,
-//                                                       std::vector<LHCb::Track*>& vecOfTracks,
-//                                                       std::string                trackLoc ) const {
-//
-//  LinkedTo<LHCb::MCParticle> trackMClink( eventSvc(), msgSvc(), trackLoc );
-//
-//  // Find # of reconstructed tracks of every MC PV
-//  std::vector<MCPVInfo>::iterator itinfomc;
-//  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
-//    LHCb::MCVertex* avtx = itinfomc->pMCPV;
-//
-//    SmartRefVector<LHCb::MCParticle> parts = avtx->products();
-//    std::vector<LHCb::MCParticle*>   allproducts;
-//    collectProductss( avtx, avtx, allproducts );
-//
-//    LHCb::Track*                             recTrack = 0;
-//    std::vector<LHCb::MCParticle*>::iterator imcp;
-//    for ( imcp = allproducts.begin(); allproducts.end() != imcp; imcp++ ) {
-//      LHCb::MCParticle* pmcp   = *imcp;
-//      int               isReco = 0;
-//      for ( std::vector<LHCb::Track*>::iterator itrec = vecOfTracks.begin(); itrec != vecOfTracks.end(); itrec++ ) {
-//        LHCb::MCParticle* partmc = trackMClink.first( ( *itrec )->key() );
-//        if ( partmc && partmc == pmcp ) {
-//          recTrack = ( *itrec );
-//          if ( !m_requireVelo || recTrack->hasVelo() ) {
-//            isReco = 1;
-//            break;
-//          }
-//        }
-//      }
-//      if ( pmcp->particleID().threeCharge() != 0 && isReco ) {
-//        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-//        if ( dv2 < 0.0001 ) {
-//          itinfomc->m_mcPartInMCPV.push_back( pmcp );
-//          itinfomc->m_recTracksInMCPV.push_back( recTrack );
-//        }
-//      }
-//    }
-//    itinfomc->nRecTracks = itinfomc->m_mcPartInMCPV.size();
-//  }
-//}
-
 int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
   int nVeloTracks = 0;
   for ( const auto& track : tracksPV ) {
@@ -1014,50 +901,19 @@ std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
     return format( "%d decayStrange", int( recoAs::strange ) );
   case recoAs::other:
     return format( "%d other", int( recoAs::other ) );
+  case recoAs::first:
+    return format( "%d 1MCPV", int( recoAs::first ) );
+  case recoAs::second:
+    return format( "%d 2MCPV", int( recoAs::second ) );
+  case recoAs::third:
+    return format( "%d 3MCPV", int( recoAs::third ) );
+  case recoAs::fourth:
+    return format( "%d 4MCPV", int( recoAs::fourth ) );
+  case recoAs::fifth:
+    return format( "%d 5MCPV", int( recoAs::fifth ) );  
   default:
     return "not defined";
   }
+
+  
 }
-// int PrimaryVertexChecker::check_mother_particle( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV,
-//                                                 const LHCb::MCParticles& mcps,
-//                                                 const LHCb::LinksByKey& linker  ) const {
-//
-//  int         motherPart = 0;
-//  for ( const auto& tr : tracksPV ) {
-//
-//    double                  maxWeight{0};
-//    const LHCb::MCParticle* mcp{nullptr};
-//    linker.applyToLinks( tr.track->key(),
-//                        [&maxWeight, &mcp, &mcps]( unsigned int, unsigned int mcPartKey, float weight ) {
-//                          if ( weight > maxWeight ) {
-//                            maxWeight = weight;
-//                            mcp       = static_cast<const LHCb::MCParticle*>( mcps.containedObject( mcPartKey ) );
-//                          }
-//                        } );
-//
-//  LinkedTo<LHCb::MCParticle, LHCb::Track> link( eventSvc(), msgSvc(), trackLoc );
-//  for ( auto itin = tracksIn.begin(); itin != tracksIn.end(); itin++ ) {
-//    const LHCb::Track* ptr  = *itin;
-//    LHCb::MCParticle*  part = nullptr;
-//    part                    = link.first( ptr->key() );
-//    if ( part != nullptr ) {
-//      const LHCb::MCParticle* part1 = part;
-//      int                     i     = 0;
-//      while ( part1 != nullptr ) {
-//        // std::cout<<"X"<<std::endl;
-//        const LHCb::MCParticle* mother = part1->mother();
-//        if ( mother != nullptr ) {
-//          i     = i + 1;
-//          part1 = mother;
-//          /// std::cout<<i<<": "<<part1->particleID().pid()<<std::endl;
-//        } else {
-//          break;
-//        }
-//      }
-//
-//      if ( part1->particleID().hasBottom() == true ) { motherPart = 2.0; }
-//      if ( part1->particleID().hasCharm() == true ) { motherPart = 1.0; }
-//    }
-//  }
-//  return motherPart;
-//}
-- 
GitLab


From 91f47fccd91f7b549c91ead3e2d32b7ea522c433 Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Wed, 16 Dec 2020 09:19:46 +0000
Subject: [PATCH 28/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/11361932
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 231 ++++++++++-----------
 1 file changed, 106 insertions(+), 125 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 6cdb26a0008..01c0fd1af0c 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -102,85 +102,79 @@ namespace {
     fifth
   };
 
-  std::array<recoAs, 17> All{ {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
-	                      recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
-	                      recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other,
-	                      recoAs::first,        recoAs::second,   recoAs::third,    recoAs::fourth, recoAs::fifth } 
-  }; 
-
-  std::array<recoAs, 5> Part{ {recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other}}; 
-  std::array<recoAs, 12> Basic{ {recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
-	recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
-	recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other}
-  }; 
-
-  constexpr int size_basic = static_cast<int>( recoAs::other ) + 1;
+  std::array<recoAs, 17> All{{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
+                              recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
+                              recoAs::strange, recoAs::other, recoAs::first, recoAs::second, recoAs::third,
+                              recoAs::fourth, recoAs::fifth}};
+
+  std::array<recoAs, 5>  Part{{recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other}};
+  std::array<recoAs, 12> Basic{{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
+                                recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
+                                recoAs::strange, recoAs::other}};
+
+  constexpr int size_basic  = static_cast<int>( recoAs::other ) + 1;
   constexpr int size_recoAs = static_cast<int>( recoAs::fifth ) + 1;
-  constexpr int size_multi = size_recoAs - size_basic; 
+  constexpr int size_multi  = size_recoAs - size_basic;
   constexpr int begin_multi = static_cast<int>( recoAs::first );
 
 } // namespace
 
 class PrimaryVertexChecker
     : public Gaudi::Functional::Consumer<void( const LHCb::Tracks&, LHCb::Event::v2::RecVertices const&,
-                                               const LHCb::MCVertices&, const LHCb::MCParticles&,
-                                               const LHCb::MCHeader&, const LHCb::MCProperty&,
-					       const Beamline_t&),					 
-                                               LHCb::DetDesc::usesBaseAndConditions<GaudiTupleAlg, Beamline_t>> {
+                                               const LHCb::MCVertices&, const LHCb::MCParticles&, const LHCb::MCHeader&,
+                                               const LHCb::MCProperty&, const Beamline_t& ),
+                                         LHCb::DetDesc::usesBaseAndConditions<GaudiTupleAlg, Beamline_t>> {
 public:
   /// Standard constructor
   PrimaryVertexChecker( const std::string& name, ISvcLocator* pSvcLocator )
       : Consumer{name,
                  pSvcLocator,
                  {
-		   KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
-		   KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
-		   KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
-		   KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
-		   KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
-		   KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
-		   KeyValue{"BeamSpotLocation", "AlgorithmSpecific-" + name + "-beamspot"},
+                     KeyValue{"inputTracksName", LHCb::TrackLocation::Default},
+                     KeyValue{"inputVerticesName", LHCb::Event::v2::RecVertexLocation::Primary},
+                     KeyValue{"MCVertexInput", LHCb::MCVertexLocation::Default},
+                     KeyValue{"MCParticleInput", LHCb::MCParticleLocation::Default},
+                     KeyValue{"MCHeaderLocation", LHCb::MCHeaderLocation::Default},
+                     KeyValue{"MCPropertyInput", LHCb::MCPropertyLocation::TrackInfo},
+                     KeyValue{"BeamSpotLocation", "AlgorithmSpecific-" + name + "-beamspot"},
                  }} {}
 
   StatusCode initialize() override; ///< Algorithm initialization
   void       operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& vertices,
-			 const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
-			 const LHCb::MCHeader&   mcheader,
-			 const LHCb::MCProperty& flags,
-			 const Beamline_t&) const override; ///< Algorithm execution
-  StatusCode finalize() override;                                        ///< Algorithm finalization
+                   const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps, const LHCb::MCHeader& mcheader,
+                   const LHCb::MCProperty& flags,
+                   const Beamline_t& ) const override; ///< Algorithm execution
+  StatusCode finalize() override;                            ///< Algorithm finalization
 
 protected:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};         // min number of tracks in PV
-  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true};        // producing histograms (light version)
-  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};             // producing NTuples (full version)
-  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};                  // requiring VELO for tracks
+  Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};  // min number of tracks in PV
+  Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true}; // producing histograms (light version)
+  Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};      // producing NTuples (full version)
+  Gaudi::Property<bool>   m_requireVelo{this, "RequireVelo", true};           // requiring VELO for tracks
   Gaudi::Property<double> m_dzIsolated{this, "dzIsolated", 10.0 * Gaudi::Units::mm}; // split close/isolated PVs
   Gaudi::Property<int>    m_nTracksToPrint{this, "nTracksToPrint", 10};              // split low/high multiplicity PVs
-  Gaudi::Property<double> m_zToPrint{this, "zToPrint", 50.0 * Gaudi::Units::mm};     // split in z 
+  Gaudi::Property<double> m_zToPrint{this, "zToPrint", 50.0 * Gaudi::Units::mm};     // split in z
 
-  mutable Gaudi::Accumulators::Counter<>   m_nevt{this, "nEvents"};
+  mutable Gaudi::Accumulators::Counter<>                            m_nevt{this, "nEvents"};
   mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_false;     // False PVs vs Reco PVs
-  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_eff;       // MC reconstructible vs Reconstructed 
-  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_mcpv;      // MC vs MC reconstrucible   
+  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_eff;       // MC reconstructible vs Reconstructed
+  mutable std::map<recoAs, Gaudi::Accumulators::BinomialCounter<>>  m_mcpv;      // MC vs MC reconstrucible
   mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_mcp;    // average mc particles in MCPV
-  mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_tracks; // average tracks in RecoPV 
+  mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_tracks; // average tracks in RecoPV
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
                                                std::vector<MCPVInfo>::iterator& itmc ) const;
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( const std::string name,
-		 const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
-		 const Gaudi::Accumulators::BinomialCounter<> m_eff,
-		 const Gaudi::Accumulators::BinomialCounter<> m_false);
-  void printAvTracks( const std::string name,
-		      const Gaudi::Accumulators::AveragingCounter<> m_av_tracks,
-		      const Gaudi::Accumulators::AveragingCounter<> m_av_mcp  );
+  void printRat( const std::string name, const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
+                 const Gaudi::Accumulators::BinomialCounter<> m_eff,
+                 const Gaudi::Accumulators::BinomialCounter<> m_false );
+  void printAvTracks( const std::string name, const Gaudi::Accumulators::AveragingCounter<> m_av_tracks,
+                      const Gaudi::Accumulators::AveragingCounter<> m_av_mcp );
   void printRes( std::string mes, double x, double y, double z );
   std::string toString( const recoAs& n ) const;
   bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
@@ -189,18 +183,18 @@ private:
   int    count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV );
   void   count_reconstructible_mc_particles( std::vector<MCPVInfo>& mcpvvec, const LHCb::MCProperty& flags ) const;
   double check_histogram( const AIDA::IHistogram1D* h, bool var );
-
 };
 
 // Declaration of the Algorithm Factory
-DECLARE_COMPONENT_WITH_ID(PrimaryVertexChecker, "PrimaryVertexChecker") 
+DECLARE_COMPONENT_WITH_ID( PrimaryVertexChecker, "PrimaryVertexChecker" )
 
 StatusCode PrimaryVertexChecker::initialize() {
-  auto sc = Consumer::initialize().andThen([&] { addConditionDerivation<Beamline_t( Condition const& )>({beamSpotCond}, inputLocation<Beamline_t>() ); } );
+  auto sc = Consumer::initialize().andThen(
+      [&] { addConditionDerivation<Beamline_t( Condition const& )>( {beamSpotCond}, inputLocation<Beamline_t>() ); } );
 
   if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
   return StatusCode::SUCCESS;
-  }
+}
 
 //=============================================================================
 // Main execution
@@ -208,17 +202,17 @@ StatusCode PrimaryVertexChecker::initialize() {
 void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::v2::RecVertices const& recoVtx,
                                        const LHCb::MCVertices& mcvtx, const LHCb::MCParticles& mcps,
                                        const LHCb::MCHeader& mcheader, const LHCb::MCProperty& flags,
-				       const Beamline_t&  beamline) const {
+                                       const Beamline_t& beamline ) const {
 
   debug() << "==> Execute" << endmsg;
   // Event
   m_nevt++;
-  
+
   if ( debugLevel() ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
-  
+
   // Fill reconstucted PV info
   std::vector<RecPVInfo> recpvvec;
-  recpvvec.reserve(recoVtx.size()); 
+  recpvvec.reserve( recoVtx.size() );
 
   for ( const auto& pv : recoVtx ) {
     RecPVInfo recinfo;
@@ -235,7 +229,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     recinfo.nDoF          = pv.nDoF();
     recinfo.indexMCPVInfo = -1;
 
-    int mother = 0;
+    int mother            = 0;
     recinfo.mother        = mother;
     recinfo.indexMCPVInfo = -1;
     recpvvec.push_back( recinfo );
@@ -243,7 +237,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
   // Fill MC PV info
   std::vector<MCPVInfo> mcpvvec;
-  mcpvvec.reserve(mcvtx.size()); 
+  mcpvvec.reserve( mcvtx.size() );
 
   for ( const auto& mcpv : mcvtx ) {
     const LHCb::MCParticle* motherPart = mcpv->mother();
@@ -275,7 +269,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   std::vector<MCPVInfo> notrblemcpv;
   std::vector<MCPVInfo> not_rble_but_visible;
   std::vector<MCPVInfo> not_rble;
-  int  nmrc = 0;
+  int                   nmrc = 0;
 
   std::vector<MCPVInfo>::iterator itmc;
   for ( itmc = mcpvvec.begin(); mcpvvec.end() != itmc; itmc++ ) {
@@ -288,14 +282,16 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     if ( itmc->nRecTracks < m_nTracksToBeRecble && itmc->nRecTracks < 2 ) { not_rble.push_back( *itmc ); }
   }
 
-  for ( int ipv = 0; ipv < static_cast<int>(recpvvec.size()); ipv++ ) { match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv ); }
+  for ( int ipv = 0; ipv < static_cast<int>( recpvvec.size() ); ipv++ ) {
+    match_mc_vertex_by_distance( ipv, recpvvec, rblemcpv );
+  }
 
   rblemcpv.insert( rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end() );
 
   if ( debugLevel() ) {
     debug() << endmsg << " MC vertices " << endmsg;
     debug() << " ===================================" << endmsg;
-    for ( int imcpv = 0; imcpv < static_cast<int>(rblemcpv.size()); imcpv++ ) {
+    for ( int imcpv = 0; imcpv < static_cast<int>( rblemcpv.size() ); imcpv++ ) {
       std::string     ff   = " ";
       LHCb::MCVertex* mcpv = rblemcpv[imcpv].pMCPV;
       if ( rblemcpv[imcpv].indexRecPVInfo < 0 ) ff = "  NOTRECO";
@@ -307,7 +303,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
     debug() << endmsg << " REC vertices " << endmsg;
     debug() << " ===================================" << endmsg;
-    for ( int ipv = 0; ipv < static_cast<int>(recpvvec.size()); ipv++ ) {
+    for ( int ipv = 0; ipv < static_cast<int>( recpvvec.size() ); ipv++ ) {
       std::string ff = " ";
       if ( recpvvec[ipv].indexMCPVInfo < 0 ) ff = "  FALSE  ";
       debug()
@@ -323,7 +319,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
   // find nr of false PV
   int nFalsePV_real = 0;
-  for ( int ipv = 0; ipv < static_cast<int>(recpvvec.size()); ipv++ ) {
+  for ( int ipv = 0; ipv < static_cast<int>( recpvvec.size() ); ipv++ ) {
     int    fake   = 0;
     double x      = recpvvec[ipv].position.x();
     double y      = recpvvec[ipv].position.y();
@@ -342,40 +338,37 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
 
-      
       if ( cmc != rblemcpv.end() ) {
         dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
 
         for ( const auto& n : Part ) {
           bool cut = false;
           cut      = checkCondition( *cmc, n );
-	  if ( cut ) { m_false[n] += true; }
+          if ( cut ) { m_false[n] += true; }
         }
         if ( dist > m_dzIsolated.value() ) {
-          m_false[recoAs::isolated]+= true;
+          m_false[recoAs::isolated] += true;
         } else {
-	  m_false[recoAs::close]+= true;
+          m_false[recoAs::close] += true;
         }
         if ( recpvvec[ipv].nTracks >= m_nTracksToPrint.value() ) {
-          m_false[recoAs::ntracks_high]+= true;
+          m_false[recoAs::ntracks_high] += true;
         } else {
-	  m_false[recoAs::ntracks_low]+= true;
+          m_false[recoAs::ntracks_low] += true;
         }
 
         if ( recpvvec[ipv].position.z() < -m_zToPrint.value() ) {
-          m_false[recoAs::z_low]+=true;
+          m_false[recoAs::z_low] += true;
         } else if ( recpvvec[ipv].position.z() < m_zToPrint.value() ) {
-          m_false[recoAs::z_middle]+= true;
+          m_false[recoAs::z_middle] += true;
         } else {
-	  m_false[recoAs::z_high]+= true;
+          m_false[recoAs::z_high] += true;
         }
 
         int idx = std::distance( rblemcpv.begin(), cmc );
-        if ( idx < size_multi ) {
-	  m_false[All[begin_multi+idx]] += true;
-	}
+        if ( idx < size_multi ) { m_false[All[begin_multi + idx]] += true; }
       }
-      
+
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
@@ -425,21 +418,18 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       cut      = checkCondition( *itmc, n );
       if ( cut ) {
         if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
-	  m_mcpv[n] += false;
+          m_mcpv[n] += false;
         } else {
-	  m_mcpv[n] += true;
-	  m_av_mcp[n] += itmc->nRecTracks; 
-	if ( itmc->indexRecPVInfo < 0 ) {
-	  m_eff[n] += false;
-	}
-	else {
-	  m_eff[n] += true;
-	  m_false[n]+= false;
-	}
-	}
-        if ( itmc->indexRecPVInfo > -1 ) {
-	  m_av_tracks[n] += recpvvec[itmc->indexRecPVInfo].nTracks; 
+          m_mcpv[n] += true;
+          m_av_mcp[n] += itmc->nRecTracks;
+          if ( itmc->indexRecPVInfo < 0 ) {
+            m_eff[n] += false;
+          } else {
+            m_eff[n] += true;
+            m_false[n] += false;
+          }
         }
+        if ( itmc->indexRecPVInfo > -1 ) { m_av_tracks[n] += recpvvec[itmc->indexRecPVInfo].nTracks; }
       }
     }
   }
@@ -481,16 +471,15 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
     if ( mcpv < size_multi ) {
       if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
-	m_mcpv[All[begin_multi+mcpv]] += false;
+        m_mcpv[All[begin_multi + mcpv]] += false;
       } else {
-	m_mcpv[All[begin_multi+mcpv]] += true;
-	m_av_mcp[All[begin_multi+mcpv]] += itmc->nRecTracks; 
-	if ( itmc->indexRecPVInfo < 0 ) {
-          m_eff[All[begin_multi+mcpv]] += false;
-        }
-        else {
-          m_eff[All[begin_multi+mcpv]] += true;
-	  m_false[All[begin_multi+mcpv]]+= false;
+        m_mcpv[All[begin_multi + mcpv]] += true;
+        m_av_mcp[All[begin_multi + mcpv]] += itmc->nRecTracks;
+        if ( itmc->indexRecPVInfo < 0 ) {
+          m_eff[All[begin_multi + mcpv]] += false;
+        } else {
+          m_eff[All[begin_multi + mcpv]] += true;
+          m_false[All[begin_multi + mcpv]] += false;
         }
       }
     }
@@ -505,11 +494,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       x             = recpvvec[indRec].position.x();
       y             = recpvvec[indRec].position.y();
       z             = recpvvec[indRec].position.z();
-      r    = std::sqrt( ( x - beamline.X ) * ( x - beamline.X ) + ( y - beamline.Y ) * ( y - beamline.Y ) );
-      errx = recpvvec[indRec].positionSigma.x();
-      erry = recpvvec[indRec].positionSigma.y();
-      errz = recpvvec[indRec].positionSigma.z();
-      errr = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
+      r             = std::sqrt( ( x - beamline.X ) * ( x - beamline.X ) + ( y - beamline.Y ) * ( y - beamline.Y ) );
+      errx          = recpvvec[indRec].positionSigma.x();
+      erry          = recpvvec[indRec].positionSigma.y();
+      errz          = recpvvec[indRec].positionSigma.z();
+      errr          = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
       ntracks_pvrec = recpvvec[indRec].nTracks;
       ntracks_pvmc  = itmc->pMCPV->products().size();
       dtrcks        = ntracks_pvmc - ntracks_pvrec;
@@ -517,9 +506,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       chi2          = recpvvec[indRec].chi2;
       nDoF          = recpvvec[indRec].nDoF;
 
-      if ( mcpv < size_multi ) {
-	m_av_tracks[All[begin_multi+mcpv]] += recpvvec[indRec].nTracks;
-      }
+      if ( mcpv < size_multi ) { m_av_tracks[All[begin_multi + mcpv]] += recpvvec[indRec].nTracks; }
       // Filling histograms
       if ( m_produceHistogram ) {
         plot( itmc->pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
@@ -634,7 +621,7 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
   double mindist = 999999.;
   int    indexmc = -1;
 
-  for ( int imc = 0; imc < static_cast<int>(mcpvvec.size()); imc++ ) {
+  for ( int imc = 0; imc < static_cast<int>( mcpvvec.size() ); imc++ ) {
     if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
     double dist = fabs( mcpvvec[imc].pMCPV->position().z() - rinfo[ipv].position.z() );
     if ( dist < mindist ) {
@@ -692,7 +679,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 StatusCode PrimaryVertexChecker::finalize() {
 
   debug() << "==> Finalize" << endmsg;
-  info() << "     ************************************ "<<endmsg;
+  info() << "     ************************************ " << endmsg;
   info() << " MC PV is reconstructible if at least " << m_nTracksToBeRecble.value() << "  tracks are reconstructed"
          << endmsg;
   info() << " MC PV is isolated if dz to closest reconstructible MC PV >  " << m_dzIsolated.value() << " mm" << endmsg;
@@ -703,10 +690,10 @@ StatusCode PrimaryVertexChecker::finalize() {
   std::string ff = "by distance";
   info() << " REC and MC vertices matched:  " << ff << endmsg;
 
-  info() << " " << endmsg;  
+  info() << " " << endmsg;
   for ( const auto& n : All ) { printRat( toString( n ), m_mcpv[n], m_eff[n], m_false[n] ); }
   info() << " " << endmsg;
-  for ( const auto& n : All ) { printAvTracks( toString( n ), m_av_tracks[n], m_av_mcp[n] );}
+  for ( const auto& n : All ) { printAvTracks( toString( n ), m_av_tracks[n], m_av_mcp[n] ); }
   info() << " " << endmsg;
 
   printRes( "1_res_all", check_histogram( histo( HistoID( 1021 ) ), true ),
@@ -738,29 +725,25 @@ StatusCode PrimaryVertexChecker::finalize() {
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-
-void PrimaryVertexChecker::printRat( const std::string name,
-				     const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
-				     const Gaudi::Accumulators::BinomialCounter<> m_eff,
-				     const Gaudi::Accumulators::BinomialCounter<> m_false) {
+void PrimaryVertexChecker::printRat( const std::string name, const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
+                                     const Gaudi::Accumulators::BinomialCounter<> m_eff,
+                                     const Gaudi::Accumulators::BinomialCounter<> m_false ) {
   unsigned int len  = 25;
   std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
   info() << pmes
-         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ", 
-                    m_eff.nTrueEntries(), m_eff.nEntries(), m_mcpv.nEntries(), m_mcpv.nFalseEntries(), m_eff.efficiency()*100, 
-		    m_false.nTrueEntries(), m_false.nEntries(),  m_false.nFalseEntries(), m_false.nTrueEntries(), m_false.efficiency()*100
-		    )
+         << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
+                    m_eff.nTrueEntries(), m_eff.nEntries(), m_mcpv.nEntries(), m_mcpv.nFalseEntries(),
+                    m_eff.efficiency() * 100, m_false.nTrueEntries(), m_false.nEntries(), m_false.nFalseEntries(),
+                    m_false.nTrueEntries(), m_false.efficiency() * 100 )
          << endmsg;
-
-
 }
 
-void PrimaryVertexChecker::printAvTracks( const std::string name, 
-					  const Gaudi::Accumulators::AveragingCounter<> m_av_tracks, 
-					  const Gaudi::Accumulators::AveragingCounter<> m_av_mcp  ) {
+void PrimaryVertexChecker::printAvTracks( const std::string                             name,
+                                          const Gaudi::Accumulators::AveragingCounter<> m_av_tracks,
+                                          const Gaudi::Accumulators::AveragingCounter<> m_av_mcp ) {
   unsigned int len  = 25;
   std::string  pmes = name;
   while ( pmes.length() < len ) { pmes += " "; }
@@ -910,10 +893,8 @@ std::string PrimaryVertexChecker::toString( const recoAs& n ) const {
   case recoAs::fourth:
     return format( "%d 4MCPV", int( recoAs::fourth ) );
   case recoAs::fifth:
-    return format( "%d 5MCPV", int( recoAs::fifth ) );  
+    return format( "%d 5MCPV", int( recoAs::fifth ) );
   default:
     return "not defined";
   }
-
-  
 }
-- 
GitLab


From 0ff1e6972a1a4871be81dedfd8147a133ccb2a90 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus768.cern.ch>
Date: Wed, 16 Dec 2020 10:31:15 +0100
Subject: [PATCH 29/42] fixing formatting

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 01c0fd1af0c..56c9ac1796c 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -106,7 +106,6 @@ namespace {
                               recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
                               recoAs::strange, recoAs::other, recoAs::first, recoAs::second, recoAs::third,
                               recoAs::fourth, recoAs::fifth}};
-
   std::array<recoAs, 5>  Part{{recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other}};
   std::array<recoAs, 12> Basic{{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
                                 recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
-- 
GitLab


From c4117fe02bafd57833d366657934015b4603ddec Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:03:02 +0000
Subject: [PATCH 30/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 56c9ac1796c..9790582cb21 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -80,7 +80,7 @@ namespace {
         , Y{c.param<double>( "ResolPosY" )} {}
   };
 
-  bool sortmlt( MCPVInfo first, MCPVInfo second ) { return first.nRecTracks > second.nRecTracks; }
+  bool sortmlt( MCPVInfo const& first, MCPVInfo const& second ) { return first.nRecTracks > second.nRecTracks; }
 
   enum class recoAs {
     all,
-- 
GitLab


From 2cb72ba7b85fef7a32ad55aac2d996db8b05080f Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:03:07 +0000
Subject: [PATCH 31/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 9790582cb21..72b60af1650 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -145,7 +145,7 @@ public:
                    const Beamline_t& ) const override; ///< Algorithm execution
   StatusCode finalize() override;                            ///< Algorithm finalization
 
-protected:
+private:
   bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
 private:
-- 
GitLab


From 57b96b31ac7a62dfc8005903dbf17270d091700d Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:04:21 +0000
Subject: [PATCH 32/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 72b60af1650..91ae8d1b64d 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -188,11 +188,8 @@ private:
 DECLARE_COMPONENT_WITH_ID( PrimaryVertexChecker, "PrimaryVertexChecker" )
 
 StatusCode PrimaryVertexChecker::initialize() {
-  auto sc = Consumer::initialize().andThen(
+  return Consumer::initialize().andThen(
       [&] { addConditionDerivation<Beamline_t( Condition const& )>( {beamSpotCond}, inputLocation<Beamline_t>() ); } );
-
-  if ( sc.isFailure() ) debug() << "==> Initialize" << endmsg;
-  return StatusCode::SUCCESS;
 }
 
 //=============================================================================
-- 
GitLab


From 2bcef19c689771b2d0babb1873b630325131cff2 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:04:44 +0000
Subject: [PATCH 33/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 91ae8d1b64d..d857e1a8a7c 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -204,7 +204,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   // Event
   m_nevt++;
 
-  if ( debugLevel() ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
+  if ( msgLevel(Msg::DEBUG) ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
   std::vector<RecPVInfo> recpvvec;
-- 
GitLab


From 94cd0f25f3d5e990101fe88e2be1c5162413dbd0 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:05:03 +0000
Subject: [PATCH 34/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index d857e1a8a7c..fbd974ed7cf 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -331,7 +331,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
       fake                                 = 1;
-      std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
+      auto cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
       double                          dist = 999999.;
 
       if ( cmc != rblemcpv.end() ) {
-- 
GitLab


From c7b8cc99e3cf349aad819166c7f7e376f3227092 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:06:14 +0000
Subject: [PATCH 35/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index fbd974ed7cf..536df06190f 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -655,7 +655,7 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>& rblemcpv,
                                                                    const RecPVInfo&       rec ) const {
 
-  std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
+  auto itret   = rblemcpv.end();
   double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
-- 
GitLab


From 8b0f24c921241b3be13f1a40a4e882cfb9401588 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <agnieszka.dziurda@cern.ch>
Date: Mon, 18 Jan 2021 10:07:00 +0000
Subject: [PATCH 36/42] Apply 1 suggestion(s) to 1 file(s)

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 536df06190f..34d0fe86eb0 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -726,7 +726,7 @@ void PrimaryVertexChecker::printRat( const std::string name, const Gaudi::Accumu
                                      const Gaudi::Accumulators::BinomialCounter<> m_false ) {
   unsigned int len  = 25;
   std::string  pmes = name;
-  while ( pmes.length() < len ) { pmes += " "; }
+  if ( pmes.size() < len ) pmes.resize( len, " "; 
   pmes += " : ";
 
   info() << pmes
-- 
GitLab


From 8208425ca31414bbf9710861ede9a2aae7c8c996 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus759.cern.ch>
Date: Mon, 18 Jan 2021 11:29:49 +0100
Subject: [PATCH 37/42] fixing automatic suggestions

---
 Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py | 4 ++--
 Tr/PatChecker/src/PrimaryVertexChecker.cpp       | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py b/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
index 6f856f1c170..b153d52f0f7 100755
--- a/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
+++ b/Tf/TrackSys/python/TrackSys/PrUpgradeChecking.py
@@ -214,11 +214,11 @@ def PrUpgradeChecking(defTracks={},
 
     prLHCbID2MCParticle = PrLHCbID2MCParticle()
     prLHCbID2MCParticle.VPFullClustersLocation = 'Raw/VP/FullClusters'
-    prLHCbID2MCParticle.VPFullClustersLinkLocation = 'Link/' + prLHCbID2MCParticle.VPFullClustersLocation
+    prLHCbID2MCParticle.VPFullClustersLinkLocation = 'Link/' + str(prLHCbID2MCParticle.VPFullClustersLocation)
     prLHCbID2MCParticle.UTHitsLocation = 'UT/UTHits'
     prLHCbID2MCParticle.UTHitsLinkLocation = 'Link/Raw/UT/Clusters'
     prLHCbID2MCParticle.FTLiteClustersLocation = 'Raw/FT/LiteClusters'
-    prLHCbID2MCParticle.FTLiteClustersLinkLocation = 'Link/' + prLHCbID2MCParticle.FTLiteClustersLocation
+    prLHCbID2MCParticle.FTLiteClustersLinkLocation = 'Link/' + str(prLHCbID2MCParticle.FTLiteClustersLocation)
     if "Truth" in trackTypes:
         truthSeq = GaudiSequencer("RecoTruthSeq")
         truthSeq.Members = [UnpackMCParticle(), UnpackMCVertex()]
diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 34d0fe86eb0..dccc702c119 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -204,7 +204,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   // Event
   m_nevt++;
 
-  if ( msgLevel(Msg::DEBUG) ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
+  if ( msgLevel(MSG::DEBUG) ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
   std::vector<RecPVInfo> recpvvec;
@@ -726,7 +726,7 @@ void PrimaryVertexChecker::printRat( const std::string name, const Gaudi::Accumu
                                      const Gaudi::Accumulators::BinomialCounter<> m_false ) {
   unsigned int len  = 25;
   std::string  pmes = name;
-  if ( pmes.size() < len ) pmes.resize( len, " "; 
+  while ( pmes.length() < len ) { pmes += " "; }
   pmes += " : ";
 
   info() << pmes
-- 
GitLab


From c0f8ed827d4e50c41be5a38ef4bb773351247ecf Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus791.cern.ch>
Date: Mon, 1 Feb 2021 17:31:18 +0100
Subject: [PATCH 38/42] resolving Gerhard's comments

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 287 ++++++++++-----------
 1 file changed, 137 insertions(+), 150 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index dccc702c119..1e3d24c655f 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -30,6 +30,7 @@
 #include "GaudiAlg/GaudiTupleAlg.h"
 #include "GaudiAlg/Tuples.h"
 
+#include "Kernel/STLExtensions.h"
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
@@ -102,14 +103,14 @@ namespace {
     fifth
   };
 
-  std::array<recoAs, 17> All{{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
-                              recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
-                              recoAs::strange, recoAs::other, recoAs::first, recoAs::second, recoAs::third,
-                              recoAs::fourth, recoAs::fifth}};
-  std::array<recoAs, 5>  Part{{recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other}};
-  std::array<recoAs, 12> Basic{{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
-                                recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
-                                recoAs::strange, recoAs::other}};
+  constexpr auto All = std::array{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
+                                  recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
+                                  recoAs::strange, recoAs::other, recoAs::first, recoAs::second, recoAs::third,
+                                  recoAs::fourth, recoAs::fifth};
+  constexpr auto Part = std::array{recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+  constexpr auto Basic = std::array{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
+                                    recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
+                                    recoAs::strange, recoAs::other};
 
   constexpr int size_basic  = static_cast<int>( recoAs::other ) + 1;
   constexpr int size_recoAs = static_cast<int>( recoAs::fifth ) + 1;
@@ -146,9 +147,8 @@ public:
   StatusCode finalize() override;                            ///< Algorithm finalization
 
 private:
-  bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
+  //bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
-private:
   Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};  // min number of tracks in PV
   Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true}; // producing histograms (light version)
   Gaudi::Property<bool>   m_produceNtuple{this, "produceNtuple", false};      // producing NTuples (full version)
@@ -165,15 +165,18 @@ private:
   mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_tracks; // average tracks in RecoPV
 
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                               std::vector<MCPVInfo>::iterator& itmc ) const;
+					       const MCPVInfo& mc ) const;
+					       // std::vector<MCPVInfo>::iterator& itmc ) const;
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( const std::string name, const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
-                 const Gaudi::Accumulators::BinomialCounter<> m_eff,
-                 const Gaudi::Accumulators::BinomialCounter<> m_false );
-  void printAvTracks( const std::string name, const Gaudi::Accumulators::AveragingCounter<> m_av_tracks,
-                      const Gaudi::Accumulators::AveragingCounter<> m_av_mcp );
+  void printRat( const std::string name, 
+		 const Gaudi::Accumulators::BinomialCounter<> &m_mcpv,
+                 const Gaudi::Accumulators::BinomialCounter<> &m_eff,
+                 const Gaudi::Accumulators::BinomialCounter<> &m_false );
+  void printAvTracks( const std::string name, 
+		      const Gaudi::Accumulators::AveragingCounter<> &m_av_tracks,
+                      const Gaudi::Accumulators::AveragingCounter<> &m_av_mcp );
   void printRes( std::string mes, double x, double y, double z );
   std::string toString( const recoAs& n ) const;
   bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
@@ -284,80 +287,75 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
   rblemcpv.insert( rblemcpv.end(), notrblemcpv.begin(), notrblemcpv.end() );
 
-  if ( debugLevel() ) {
-    debug() << endmsg << " MC vertices " << endmsg;
-    debug() << " ===================================" << endmsg;
-    for ( int imcpv = 0; imcpv < static_cast<int>( rblemcpv.size() ); imcpv++ ) {
-      std::string     ff   = " ";
-      LHCb::MCVertex* mcpv = rblemcpv[imcpv].pMCPV;
-      if ( rblemcpv[imcpv].indexRecPVInfo < 0 ) ff = "  NOTRECO";
-      debug() << format( " %3d %3d  xyz ( %7.4f %7.4f %8.3f )   nrec = %4d", imcpv, rblemcpv[imcpv].indexRecPVInfo,
-                         mcpv->position().x(), mcpv->position().y(), mcpv->position().z(), rblemcpv[imcpv].nRecTracks )
-              << ff << endmsg;
-    }
-    debug() << " -----------------------------------" << endmsg << endmsg;
-
-    debug() << endmsg << " REC vertices " << endmsg;
-    debug() << " ===================================" << endmsg;
-    for ( int ipv = 0; ipv < static_cast<int>( recpvvec.size() ); ipv++ ) {
-      std::string ff = " ";
-      if ( recpvvec[ipv].indexMCPVInfo < 0 ) ff = "  FALSE  ";
-      debug()
-          << format(
-                 " %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
-                 ipv, recpvvec[ipv].indexMCPVInfo, recpvvec[ipv].position.x(), recpvvec[ipv].position.y(),
-                 recpvvec[ipv].position.z(), recpvvec[ipv].nTracks, recpvvec[ipv].positionSigma.x(),
-                 recpvvec[ipv].positionSigma.y(), recpvvec[ipv].positionSigma.z(), recpvvec[ipv].pRECPV->chi2PerDoF() )
-          << ff << endmsg;
-    }
-    debug() << " -----------------------------------" << endmsg;
+  debug() << endmsg << " MC vertices " << endmsg;
+  debug() << " ===================================" << endmsg;
+  for ( const auto& [ ipv, rmcpv ] : LHCb::range::enumerate( rblemcpv ) ) {
+    std::string     ff   = " ";
+    LHCb::MCVertex* mcpv =  rmcpv.pMCPV;
+    if ( rmcpv.indexRecPVInfo < 0 ) ff = "  NOTRECO";
+    debug() << format( " %3d %3d  xyz ( %7.4f %7.4f %8.3f )   nrec = %4d", ipv, rmcpv.indexRecPVInfo,
+		       mcpv->position().x(), mcpv->position().y(), mcpv->position().z(), rmcpv.nRecTracks )
+	    << ff << endmsg;
   }
-
+    
+  debug() << " -----------------------------------" << endmsg << endmsg;
+  
+  debug() << endmsg << " REC vertices " << endmsg;
+  debug() << " ===================================" << endmsg;
+  for ( const auto& [ ipv, recpv ] : LHCb::range::enumerate( recpvvec ) ) {
+    std::string ff = " ";
+    if ( recpvvec[ipv].indexMCPVInfo < 0 ) ff = "  FALSE  ";
+    debug()
+      << format(
+		" %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
+		ipv, recpv.indexMCPVInfo, recpv.position.x(), recpv.position.y(),
+		recpv.position.z(), recpv.nTracks, recpv.positionSigma.x(),
+		recpv.positionSigma.y(), recpv.positionSigma.z(), recpv.pRECPV->chi2PerDoF() )
+      << ff << endmsg;
+  }
+  debug() << " -----------------------------------" << endmsg;
+  
   // find nr of false PV
   int nFalsePV_real = 0;
-  for ( int ipv = 0; ipv < static_cast<int>( recpvvec.size() ); ipv++ ) {
+  for ( const auto& [ ipv, recpv ] : LHCb::range::enumerate( recpvvec ) ) {
     int    fake   = 0;
-    double x      = recpvvec[ipv].position.x();
-    double y      = recpvvec[ipv].position.y();
-    double z      = recpvvec[ipv].position.z();
+    double x      = recpv.position.x();
+    double y      = recpv.position.y();
+    double z      = recpv.position.z();
     double r      = std::sqrt( x * x + y * y );
-    double errx   = recpvvec[ipv].positionSigma.x();
-    double erry   = recpvvec[ipv].positionSigma.y();
-    double errz   = recpvvec[ipv].positionSigma.z();
+    double errx   = recpv.positionSigma.x();
+    double erry   = recpv.positionSigma.y();
+    double errz   = recpv.positionSigma.z();
     double errr   = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
-    int    mother = recpvvec[ipv].mother;
-    double chi2   = recpvvec[ipv].chi2;
-    double nDoF   = recpvvec[ipv].nDoF;
+    int    mother = recpv.mother;
+    double chi2   = recpv.chi2;
+    double nDoF   = recpv.nDoF;
 
-    if ( recpvvec[ipv].indexMCPVInfo < 0 ) {
+    if ( recpv.indexMCPVInfo < 0 ) {
       fake                                 = 1;
-      auto cmc  = closestMCPV( rblemcpv, recpvvec[ipv] );
+      auto cmc  = closestMCPV( rblemcpv, recpv );
       double                          dist = 999999.;
 
       if ( cmc != rblemcpv.end() ) {
-        dist = ( cmc->pMCPV->position() - recpvvec[ipv].pRECPV->position() ).R();
+        dist = ( cmc->pMCPV->position() - recpv.pRECPV->position() ).R();
+
+	for ( const auto& n : Part ) m_false[n] += checkCondition( *cmc, n );
 
-        for ( const auto& n : Part ) {
-          bool cut = false;
-          cut      = checkCondition( *cmc, n );
-          if ( cut ) { m_false[n] += true; }
-        }
         if ( dist > m_dzIsolated.value() ) {
           m_false[recoAs::isolated] += true;
         } else {
           m_false[recoAs::close] += true;
         }
-        if ( recpvvec[ipv].nTracks >= m_nTracksToPrint.value() ) {
+        if ( recpv.nTracks >= m_nTracksToPrint.value() ) {
           m_false[recoAs::ntracks_high] += true;
         } else {
           m_false[recoAs::ntracks_low] += true;
         }
-
-        if ( recpvvec[ipv].position.z() < -m_zToPrint.value() ) {
+	if ( recpv.position.z() < -m_zToPrint.value() ) {
           m_false[recoAs::z_low] += true;
-        } else if ( recpvvec[ipv].position.z() < m_zToPrint.value() ) {
+        } else if ( recpv.position.z() < m_zToPrint.value() ) {
           m_false[recoAs::z_middle] += true;
-        } else {
+	} else {
           m_false[recoAs::z_high] += true;
         }
 
@@ -368,14 +366,17 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       bool vis_found = false;
       for ( unsigned int imc = 0; imc < not_rble_but_visible.size(); imc++ ) {
         if ( not_rble_but_visible[imc].indexRecPVInfo > -1 ) continue;
-        double dist = fabs( mcpvvec[imc].pMCPV->position().z() - recpvvec[ipv].position.z() );
-        if ( dist < 5.0 * recpvvec[ipv].positionSigma.z() ) {
+        double dist = fabs( mcpvvec[imc].pMCPV->position().z() - recpv.position.z() );
+        if ( dist < 5.0 * recpv.positionSigma.z() ) {
           vis_found                                = true;
           not_rble_but_visible[imc].indexRecPVInfo = 10;
           break;
         }
-      } // imc
+      } // imc                                                                                                                                                                                             
+
       if ( !vis_found ) nFalsePV_real++;
+
+
     }
     if ( m_produceNtuple ) {
       Tuple myTuple2 = nTuple( 102, "PV_nTuple2", CLID_ColumnWiseTuple );
@@ -396,43 +397,44 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   }
   // Fill distance to closest recble MC PV and its multiplicity
   std::vector<MCPVInfo>::iterator itmcl;
-  for ( itmcl = rblemcpv.begin(); rblemcpv.end() != itmcl; itmcl++ ) {
-    std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, itmcl );
+  for (auto& mcpv : rblemcpv ) {
+    std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, mcpv );
     double                          dist = 999999.;
     int                             mult = 0;
     if ( cmc != rblemcpv.end() ) {
-      dist = ( cmc->pMCPV->position() - itmcl->pMCPV->position() ).R();
+      dist = ( cmc->pMCPV->position() - mcpv.pMCPV->position() ).R();
       mult = cmc->nRecTracks;
     }
-    itmcl->distToClosestMCPV = dist;
-    itmcl->multClosestMCPV   = mult;
+    mcpv.distToClosestMCPV = dist;
+    mcpv.multClosestMCPV   = mult;
   }
 
-  for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
+  for ( const auto& itmc : rblemcpv ) {
     for ( const auto& n : Basic ) {
       bool cut = false;
-      cut      = checkCondition( *itmc, n );
+      cut      = checkCondition( itmc, n );
       if ( cut ) {
-        if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
+        if ( itmc.nRecTracks < m_nTracksToBeRecble ) {
           m_mcpv[n] += false;
         } else {
           m_mcpv[n] += true;
-          m_av_mcp[n] += itmc->nRecTracks;
-          if ( itmc->indexRecPVInfo < 0 ) {
+          m_av_mcp[n] += itmc.nRecTracks;
+          if ( itmc.indexRecPVInfo < 0 ) {
             m_eff[n] += false;
           } else {
             m_eff[n] += true;
             m_false[n] += false;
           }
         }
-        if ( itmc->indexRecPVInfo > -1 ) { m_av_tracks[n] += recpvvec[itmc->indexRecPVInfo].nTracks; }
+        if ( itmc.indexRecPVInfo > -1 ) { m_av_tracks[n] += recpvvec[itmc.indexRecPVInfo].nTracks; }
       }
     }
   }
 
   int mcpv = 0;
   int high = 0;
-  for ( itmc = rblemcpv.begin(); rblemcpv.end() != itmc; itmc++ ) {
+
+  for (auto& itmc : rblemcpv ) {
     double x             = -99999.;
     double y             = -99999.;
     double dx            = -99999.;
@@ -450,7 +452,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     double errr          = -99999.;
     double chi2          = -999999.;
     double nDoF          = -999999.;
-    int    indRec        = itmc->indexRecPVInfo;
+    int    indRec        = itmc.indexRecPVInfo;
     int    reconstructed = 0;
     int    ntracks_pvrec = 0;
     int    ntracks_pvmc  = 0;
@@ -460,18 +462,18 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     int    assoctrks     = 0;
     int    nassoctrks    = 0;
 
-    zMC = itmc->pMCPV->position().z();
-    yMC = itmc->pMCPV->position().y();
-    xMC = itmc->pMCPV->position().x();
+    zMC = itmc.pMCPV->position().z();
+    yMC = itmc.pMCPV->position().y();
+    xMC = itmc.pMCPV->position().x();
     rMC = std::sqrt( ( xMC - beamline.X ) * ( xMC - beamline.X ) + ( yMC - beamline.Y ) * ( yMC - beamline.Y ) );
 
     if ( mcpv < size_multi ) {
-      if ( itmc->nRecTracks < m_nTracksToBeRecble ) {
+      if ( itmc.nRecTracks < m_nTracksToBeRecble ) {
         m_mcpv[All[begin_multi + mcpv]] += false;
       } else {
         m_mcpv[All[begin_multi + mcpv]] += true;
-        m_av_mcp[All[begin_multi + mcpv]] += itmc->nRecTracks;
-        if ( itmc->indexRecPVInfo < 0 ) {
+        m_av_mcp[All[begin_multi + mcpv]] += itmc.nRecTracks;
+        if ( itmc.indexRecPVInfo < 0 ) {
           m_eff[All[begin_multi + mcpv]] += false;
         } else {
           m_eff[All[begin_multi + mcpv]] += true;
@@ -484,9 +486,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       high++;
       pvevt++;
       reconstructed = 1;
-      dx            = recpvvec[indRec].position.x() - itmc->pMCPV->position().x();
-      dy            = recpvvec[indRec].position.y() - itmc->pMCPV->position().y();
-      dz            = recpvvec[indRec].position.z() - itmc->pMCPV->position().z();
+      dx            = recpvvec[indRec].position.x() - itmc.pMCPV->position().x();
+      dy            = recpvvec[indRec].position.y() - itmc.pMCPV->position().y();
+      dz            = recpvvec[indRec].position.z() - itmc.pMCPV->position().z();
       x             = recpvvec[indRec].position.x();
       y             = recpvvec[indRec].position.y();
       z             = recpvvec[indRec].position.z();
@@ -496,7 +498,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       errz          = recpvvec[indRec].positionSigma.z();
       errr          = std::sqrt( ( ( x * errx ) * ( x * errx ) + ( y * erry ) * ( y * erry ) ) / ( x * x + y * y ) );
       ntracks_pvrec = recpvvec[indRec].nTracks;
-      ntracks_pvmc  = itmc->pMCPV->products().size();
+      ntracks_pvmc  = itmc.pMCPV->products().size();
       dtrcks        = ntracks_pvmc - ntracks_pvrec;
       mother        = recpvvec[indRec].mother;
       chi2          = recpvvec[indRec].chi2;
@@ -505,9 +507,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       if ( mcpv < size_multi ) { m_av_tracks[All[begin_multi + mcpv]] += recpvvec[indRec].nTracks; }
       // Filling histograms
       if ( m_produceHistogram ) {
-        plot( itmc->pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
-        plot( itmc->pMCPV->position().y(), 1002, "ymc", -0.25, 0.25, 50 );
-        plot( itmc->pMCPV->position().z(), 1003, "zmc", -20, 20, 50 );
+        plot( itmc.pMCPV->position().x(), 1001, "xmc", -0.25, 0.25, 50 );
+        plot( itmc.pMCPV->position().y(), 1002, "ymc", -0.25, 0.25, 50 );
+        plot( itmc.pMCPV->position().z(), 1003, "zmc", -20, 20, 50 );
         plot( recpvvec[indRec].position.x(), 1011, "xrd", -0.25, 0.25, 50 );
         plot( recpvvec[indRec].position.y(), 1012, "yrd", -0.25, 0.25, 50 );
         plot( recpvvec[indRec].position.z(), 1013, "zrd", -20, 20, 50 );
@@ -517,11 +519,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
         plot( dx / errx, 1031, "pullx", -5., 5., 50 );
         plot( dy / erry, 1032, "pully", -5., 5., 50 );
         plot( dz / errz, 1033, "pullz", -5., 5., 50 );
-        if ( itmc->nRecTracks < 10 ) {
+        if ( itmc.nRecTracks < 10 ) {
           plot( dx, 1101, "dx", -0.25, 0.25, 50 );
           plot( dy, 1102, "dy", -0.25, 0.25, 50 );
           plot( dz, 1103, "dz", -0.5, 0.5, 50 );
-        } else if ( itmc->nRecTracks >= 10 && itmc->nRecTracks < 30 ) {
+        } else if ( itmc.nRecTracks >= 10 && itmc.nRecTracks < 30 ) {
           plot( dx, 1111, "dx", -0.25, 0.25, 50 );
           plot( dy, 1112, "dy", -0.25, 0.25, 50 );
           plot( dz, 1113, "dz", -0.5, 0.5, 50 );
@@ -531,11 +533,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
           plot( dz, 1123, "dz", -0.5, 0.5, 50 );
         }
 
-        if ( itmc->pMCPV->position().z() < -m_zToPrint ) {
+        if ( itmc.pMCPV->position().z() < -m_zToPrint ) {
           plot( dx, 1201, "dx", -0.25, 0.25, 50 );
           plot( dy, 1202, "dy", -0.25, 0.25, 50 );
           plot( dz, 1203, "dz", -0.5, 0.5, 50 );
-        } else if ( itmc->pMCPV->position().z() < m_zToPrint ) {
+        } else if ( itmc.pMCPV->position().z() < m_zToPrint ) {
           plot( dx, 1211, "dx", -0.25, 0.25, 50 );
           plot( dy, 1212, "dy", -0.25, 0.25, 50 );
           plot( dz, 1213, "dz", -0.5, 0.5, 50 );
@@ -560,7 +562,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     mcpv++;
 
     int    isolated     = 0;
-    double dist_closest = itmc->distToClosestMCPV;
+    double dist_closest = itmc.distToClosestMCPV;
     if ( dist_closest > m_dzIsolated.value() ) { isolated = 1; }
 
     // Filling ntuple
@@ -569,15 +571,15 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
       myTuple->column( "reco", double( reconstructed ) ).ignore();
       myTuple->column( "isol", double( isolated ) ).ignore();
       myTuple->column( "ntracks", double( ntracks_pvrec ) ).ignore();
-      myTuple->column( "nrectrmc", double( itmc->nRecTracks ) ).ignore();
+      myTuple->column( "nrectrmc", double( itmc.nRecTracks ) ).ignore();
       myTuple->column( "dzclose", dist_closest ).ignore();
       myTuple->column( "nmcpv", double( rblemcpv.size() ) ).ignore();
       myTuple->column( "mtruemcpv", double( mcheader.numOfPrimaryVertices() ) ).ignore();
       myTuple->column( "nmcallpv", double( mcpvvec.size() ) ).ignore();
       myTuple->column( "nrecpv", double( recpvvec.size() ) ).ignore();
-      myTuple->column( "decayCharm", double( itmc->decayCharm ) ).ignore();
-      myTuple->column( "decayBeauty", double( itmc->decayBeauty ) ).ignore();
-      myTuple->column( "decayStrange", double( itmc->decayStrange ) ).ignore();
+      myTuple->column( "decayCharm", double( itmc.decayCharm ) ).ignore();
+      myTuple->column( "decayBeauty", double( itmc.decayBeauty ) ).ignore();
+      myTuple->column( "decayStrange", double( itmc.decayStrange ) ).ignore();
       myTuple->column( "multirec", double( high ) ).ignore();
       myTuple->column( "multimc", double( mcpv ) ).ignore();
       myTuple->column( "dx", dx ).ignore();
@@ -617,9 +619,9 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
   double mindist = 999999.;
   int    indexmc = -1;
 
-  for ( int imc = 0; imc < static_cast<int>( mcpvvec.size() ); imc++ ) {
-    if ( mcpvvec[imc].indexRecPVInfo > -1 ) continue;
-    double dist = fabs( mcpvvec[imc].pMCPV->position().z() - rinfo[ipv].position.z() );
+  for ( const auto& [ imc , mcpv ] : LHCb::range::enumerate( mcpvvec ) ) {
+    if ( mcpv.indexRecPVInfo > -1 ) continue;
+    double dist = fabs( mcpv.pMCPV->position().z() - rinfo[ipv].position.z() );
     if ( dist < mindist ) {
       mindist = dist;
       indexmc = imc;
@@ -634,15 +636,15 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
 }
 
 std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-                                                                   std::vector<MCPVInfo>::iterator& itmc ) const {
+								   const MCPVInfo& mc ) const { 
 
-  std::vector<MCPVInfo>::iterator itret   = rblemcpv.end();
+  auto itret   = rblemcpv.end();
   double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
-    if ( it->pMCPV != itmc->pMCPV ) {
-      double dist = ( it->pMCPV->position() - itmc->pMCPV->position() ).R();
+    if ( it->pMCPV != mc.pMCPV ) {
+      double dist = ( it->pMCPV->position() - mc.pMCPV->position() ).R();
       if ( dist < mindist ) {
         mindist = dist;
         itret   = it;
@@ -654,7 +656,6 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 
 std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>& rblemcpv,
                                                                    const RecPVInfo&       rec ) const {
-
   auto itret   = rblemcpv.end();
   double                          mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
@@ -721,14 +722,14 @@ StatusCode PrimaryVertexChecker::finalize() {
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( const std::string name, const Gaudi::Accumulators::BinomialCounter<> m_mcpv,
-                                     const Gaudi::Accumulators::BinomialCounter<> m_eff,
-                                     const Gaudi::Accumulators::BinomialCounter<> m_false ) {
+void PrimaryVertexChecker::printRat( const std::string name, 
+				     const Gaudi::Accumulators::BinomialCounter<> &m_mcpv,
+                                     const Gaudi::Accumulators::BinomialCounter<> &m_eff,
+                                     const Gaudi::Accumulators::BinomialCounter<> &m_false ) {
   unsigned int len  = 25;
   std::string  pmes = name;
-  while ( pmes.length() < len ) { pmes += " "; }
+  if ( pmes.size() < len ) pmes.resize( len, ' '); 
   pmes += " : ";
-
   info() << pmes
          << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
                     m_eff.nTrueEntries(), m_eff.nEntries(), m_mcpv.nEntries(), m_mcpv.nFalseEntries(),
@@ -738,11 +739,11 @@ void PrimaryVertexChecker::printRat( const std::string name, const Gaudi::Accumu
 }
 
 void PrimaryVertexChecker::printAvTracks( const std::string                             name,
-                                          const Gaudi::Accumulators::AveragingCounter<> m_av_tracks,
-                                          const Gaudi::Accumulators::AveragingCounter<> m_av_mcp ) {
+                                          const Gaudi::Accumulators::AveragingCounter<> &m_av_tracks,
+                                          const Gaudi::Accumulators::AveragingCounter<> &m_av_mcp ) {
   unsigned int len  = 25;
   std::string  pmes = name;
-  while ( pmes.length() < len ) { pmes += " "; }
+  if ( pmes.size() < len ) pmes.resize( len, ' ');
   pmes += " : ";
   info() << pmes << format( "av. PV tracks: %6.2f [MC: %6.2f]", m_av_tracks.mean(), m_av_mcp.mean() ) << endmsg;
 }
@@ -755,24 +756,12 @@ void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double
   info() << pmes << format( " x: %+5.3f, y: %+5.3f, z: %+5.3f", x, y, z ) << endmsg;
 }
 
-double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool rms ) {
-  if ( h ) {
-    if ( rms ) {
-      return h->rms();
-    } else {
-      return h->mean();
-    }
-  } else {
-    return 0.;
-  }
+double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool rms ) { 
+  return h ? ( rms ? h->rms() : h->mean() ) : 0. ;
 }
 
 int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
-  int nVeloTracks = 0;
-  for ( const auto& track : tracksPV ) {
-    if ( track.track->hasVelo() ) nVeloTracks++;
-  }
-  return nVeloTracks;
+  return std::count_if( tracksPV.begin(), tracksPV.end(), []( const auto& t ) { return t.track->hasVelo(); }) ;
 }
 
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
@@ -796,29 +785,27 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
 
   const MCTrackInfo               trInfo = {flags};
   std::vector<MCPVInfo>::iterator itinfomc;
-  for ( itinfomc = mcpvvec.begin(); mcpvvec.end() != itinfomc; itinfomc++ ) {
-    LHCb::MCVertex*                  avtx = itinfomc->pMCPV;
+
+  for ( auto& itinfomc : mcpvvec ) {
+    LHCb::MCVertex*                  avtx = itinfomc.pMCPV;
     std::vector<LHCb::MCParticle*>   mcPartInMCPV;
     SmartRefVector<LHCb::MCParticle> parts = avtx->products();
     std::vector<LHCb::MCParticle*>   allproducts;
     collectProductss( avtx, avtx, allproducts );
     std::vector<LHCb::MCParticle*>::iterator imcp;
-
-    for ( imcp = allproducts.begin(); allproducts.end() != imcp; imcp++ ) {
-
-      LHCb::MCParticle* pmcp = *imcp;
-
+    
+    for( const auto pmcp : allproducts ) {
       if ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) {
-        if ( pmcp->particleID().hasBottom() ) { itinfomc->decayBeauty = true; }
-        if ( pmcp->particleID().hasCharm() ) { itinfomc->decayCharm = true; }
-        if ( pmcp->particleID().hasStrange() ) { itinfomc->decayStrange = true; }
+	if ( pmcp->particleID().hasBottom() )  { itinfomc.decayBeauty = true; }
+	if ( pmcp->particleID().hasCharm() )   { itinfomc.decayCharm = true; }
+	if ( pmcp->particleID().hasStrange() ) { itinfomc.decayStrange = true; }
       }
       if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) &&
-           ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-        if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
+	   ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
+	double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
+	if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
       }
-      itinfomc->nRecTracks = mcPartInMCPV.size();
+      itinfomc.nRecTracks = mcPartInMCPV.size();
     }
   }
 }
-- 
GitLab


From 2cee190e623bd02a8e6d4334eef3c8b42541b74a Mon Sep 17 00:00:00 2001
From: Gitlab CI <noreply@cern.ch>
Date: Mon, 1 Feb 2021 16:32:38 +0000
Subject: [PATCH 39/42] Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/11913209
---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 144 ++++++++++-----------
 1 file changed, 69 insertions(+), 75 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 1e3d24c655f..efd405623af 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -30,10 +30,10 @@
 #include "GaudiAlg/GaudiTupleAlg.h"
 #include "GaudiAlg/Tuples.h"
 
-#include "Kernel/STLExtensions.h"
 #include "GaudiKernel/PhysicalConstants.h"
 #include "GaudiKernel/SystemOfUnits.h"
 #include "GaudiUtils/HistoStats.h"
+#include "Kernel/STLExtensions.h"
 
 #include <string>
 #include <tuple>
@@ -103,14 +103,14 @@ namespace {
     fifth
   };
 
-  constexpr auto All = std::array{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
-                                  recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
-                                  recoAs::strange, recoAs::other, recoAs::first, recoAs::second, recoAs::third,
-                                  recoAs::fourth, recoAs::fifth};
-  constexpr auto Part = std::array{recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
-  constexpr auto Basic = std::array{recoAs::all, recoAs::isolated, recoAs::close, recoAs::ntracks_low, recoAs::ntracks_high,
-                                    recoAs::z_low, recoAs::z_middle, recoAs::z_high, recoAs::beauty, recoAs::charm,
-                                    recoAs::strange, recoAs::other};
+  constexpr auto All = std::array{
+      recoAs::all,      recoAs::isolated, recoAs::close,  recoAs::ntracks_low, recoAs::ntracks_high, recoAs::z_low,
+      recoAs::z_middle, recoAs::z_high,   recoAs::beauty, recoAs::charm,       recoAs::strange,      recoAs::other,
+      recoAs::first,    recoAs::second,   recoAs::third,  recoAs::fourth,      recoAs::fifth};
+  constexpr auto Part  = std::array{recoAs::all, recoAs::beauty, recoAs::charm, recoAs::strange, recoAs::other};
+  constexpr auto Basic = std::array{recoAs::all,          recoAs::isolated, recoAs::close,    recoAs::ntracks_low,
+                                    recoAs::ntracks_high, recoAs::z_low,    recoAs::z_middle, recoAs::z_high,
+                                    recoAs::beauty,       recoAs::charm,    recoAs::strange,  recoAs::other};
 
   constexpr int size_basic  = static_cast<int>( recoAs::other ) + 1;
   constexpr int size_recoAs = static_cast<int>( recoAs::fifth ) + 1;
@@ -147,7 +147,7 @@ public:
   StatusCode finalize() override;                            ///< Algorithm finalization
 
 private:
-  //bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
+  // bool debugLevel() const { return msgLevel( MSG::DEBUG ) || msgLevel( MSG::VERBOSE ); }
 
   Gaudi::Property<int>    m_nTracksToBeRecble{this, "nTracksToBeRecble", 4};  // min number of tracks in PV
   Gaudi::Property<bool>   m_produceHistogram{this, "produceHistogram", true}; // producing histograms (light version)
@@ -164,19 +164,16 @@ private:
   mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_mcp;    // average mc particles in MCPV
   mutable std::map<recoAs, Gaudi::Accumulators::AveragingCounter<>> m_av_tracks; // average tracks in RecoPV
 
-  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-					       const MCPVInfo& mc ) const;
-					       // std::vector<MCPVInfo>::iterator& itmc ) const;
+  std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const MCPVInfo& mc ) const;
+  // std::vector<MCPVInfo>::iterator& itmc ) const;
   std::vector<MCPVInfo>::iterator closestMCPV( std::vector<MCPVInfo>& rblemcpv, const RecPVInfo& rec ) const;
 
   void collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx, std::vector<LHCb::MCParticle*>& allprods ) const;
-  void printRat( const std::string name, 
-		 const Gaudi::Accumulators::BinomialCounter<> &m_mcpv,
-                 const Gaudi::Accumulators::BinomialCounter<> &m_eff,
-                 const Gaudi::Accumulators::BinomialCounter<> &m_false );
-  void printAvTracks( const std::string name, 
-		      const Gaudi::Accumulators::AveragingCounter<> &m_av_tracks,
-                      const Gaudi::Accumulators::AveragingCounter<> &m_av_mcp );
+  void printRat( const std::string name, const Gaudi::Accumulators::BinomialCounter<>& m_mcpv,
+                 const Gaudi::Accumulators::BinomialCounter<>& m_eff,
+                 const Gaudi::Accumulators::BinomialCounter<>& m_false );
+  void printAvTracks( const std::string name, const Gaudi::Accumulators::AveragingCounter<>& m_av_tracks,
+                      const Gaudi::Accumulators::AveragingCounter<>& m_av_mcp );
   void printRes( std::string mes, double x, double y, double z );
   std::string toString( const recoAs& n ) const;
   bool        checkCondition( const MCPVInfo& MCPV, const recoAs& n ) const;
@@ -207,7 +204,8 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   // Event
   m_nevt++;
 
-  if ( msgLevel(MSG::DEBUG) ) debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
+  if ( msgLevel( MSG::DEBUG ) )
+    debug() << " # tracks: " << tracks.size() << "  # vertices: " << recoVtx.size() << endmsg;
 
   // Fill reconstucted PV info
   std::vector<RecPVInfo> recpvvec;
@@ -289,35 +287,34 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
 
   debug() << endmsg << " MC vertices " << endmsg;
   debug() << " ===================================" << endmsg;
-  for ( const auto& [ ipv, rmcpv ] : LHCb::range::enumerate( rblemcpv ) ) {
+  for ( const auto& [ipv, rmcpv] : LHCb::range::enumerate( rblemcpv ) ) {
     std::string     ff   = " ";
-    LHCb::MCVertex* mcpv =  rmcpv.pMCPV;
+    LHCb::MCVertex* mcpv = rmcpv.pMCPV;
     if ( rmcpv.indexRecPVInfo < 0 ) ff = "  NOTRECO";
     debug() << format( " %3d %3d  xyz ( %7.4f %7.4f %8.3f )   nrec = %4d", ipv, rmcpv.indexRecPVInfo,
-		       mcpv->position().x(), mcpv->position().y(), mcpv->position().z(), rmcpv.nRecTracks )
-	    << ff << endmsg;
+                       mcpv->position().x(), mcpv->position().y(), mcpv->position().z(), rmcpv.nRecTracks )
+            << ff << endmsg;
   }
-    
+
   debug() << " -----------------------------------" << endmsg << endmsg;
-  
+
   debug() << endmsg << " REC vertices " << endmsg;
   debug() << " ===================================" << endmsg;
-  for ( const auto& [ ipv, recpv ] : LHCb::range::enumerate( recpvvec ) ) {
+  for ( const auto& [ipv, recpv] : LHCb::range::enumerate( recpvvec ) ) {
     std::string ff = " ";
     if ( recpvvec[ipv].indexMCPVInfo < 0 ) ff = "  FALSE  ";
-    debug()
-      << format(
-		" %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
-		ipv, recpv.indexMCPVInfo, recpv.position.x(), recpv.position.y(),
-		recpv.position.z(), recpv.nTracks, recpv.positionSigma.x(),
-		recpv.positionSigma.y(), recpv.positionSigma.z(), recpv.pRECPV->chi2PerDoF() )
-      << ff << endmsg;
+    debug() << format(
+                   " %3d %3d  xyz ( %7.4f %7.4f %8.3f )  ntra = %4d   sigxyz ( %7.4f %7.4f %8.4f )   chi2/NDF = %7.2f",
+                   ipv, recpv.indexMCPVInfo, recpv.position.x(), recpv.position.y(), recpv.position.z(), recpv.nTracks,
+                   recpv.positionSigma.x(), recpv.positionSigma.y(), recpv.positionSigma.z(),
+                   recpv.pRECPV->chi2PerDoF() )
+            << ff << endmsg;
   }
   debug() << " -----------------------------------" << endmsg;
-  
+
   // find nr of false PV
   int nFalsePV_real = 0;
-  for ( const auto& [ ipv, recpv ] : LHCb::range::enumerate( recpvvec ) ) {
+  for ( const auto& [ipv, recpv] : LHCb::range::enumerate( recpvvec ) ) {
     int    fake   = 0;
     double x      = recpv.position.x();
     double y      = recpv.position.y();
@@ -332,14 +329,14 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     double nDoF   = recpv.nDoF;
 
     if ( recpv.indexMCPVInfo < 0 ) {
-      fake                                 = 1;
-      auto cmc  = closestMCPV( rblemcpv, recpv );
-      double                          dist = 999999.;
+      fake        = 1;
+      auto   cmc  = closestMCPV( rblemcpv, recpv );
+      double dist = 999999.;
 
       if ( cmc != rblemcpv.end() ) {
         dist = ( cmc->pMCPV->position() - recpv.pRECPV->position() ).R();
 
-	for ( const auto& n : Part ) m_false[n] += checkCondition( *cmc, n );
+        for ( const auto& n : Part ) m_false[n] += checkCondition( *cmc, n );
 
         if ( dist > m_dzIsolated.value() ) {
           m_false[recoAs::isolated] += true;
@@ -351,11 +348,11 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
         } else {
           m_false[recoAs::ntracks_low] += true;
         }
-	if ( recpv.position.z() < -m_zToPrint.value() ) {
+        if ( recpv.position.z() < -m_zToPrint.value() ) {
           m_false[recoAs::z_low] += true;
         } else if ( recpv.position.z() < m_zToPrint.value() ) {
           m_false[recoAs::z_middle] += true;
-	} else {
+        } else {
           m_false[recoAs::z_high] += true;
         }
 
@@ -372,11 +369,9 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
           not_rble_but_visible[imc].indexRecPVInfo = 10;
           break;
         }
-      } // imc                                                                                                                                                                                             
+      } // imc
 
       if ( !vis_found ) nFalsePV_real++;
-
-
     }
     if ( m_produceNtuple ) {
       Tuple myTuple2 = nTuple( 102, "PV_nTuple2", CLID_ColumnWiseTuple );
@@ -397,7 +392,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   }
   // Fill distance to closest recble MC PV and its multiplicity
   std::vector<MCPVInfo>::iterator itmcl;
-  for (auto& mcpv : rblemcpv ) {
+  for ( auto& mcpv : rblemcpv ) {
     std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, mcpv );
     double                          dist = 999999.;
     int                             mult = 0;
@@ -434,7 +429,7 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
   int mcpv = 0;
   int high = 0;
 
-  for (auto& itmc : rblemcpv ) {
+  for ( auto& itmc : rblemcpv ) {
     double x             = -99999.;
     double y             = -99999.;
     double dx            = -99999.;
@@ -619,7 +614,7 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
   double mindist = 999999.;
   int    indexmc = -1;
 
-  for ( const auto& [ imc , mcpv ] : LHCb::range::enumerate( mcpvvec ) ) {
+  for ( const auto& [imc, mcpv] : LHCb::range::enumerate( mcpvvec ) ) {
     if ( mcpv.indexRecPVInfo > -1 ) continue;
     double dist = fabs( mcpv.pMCPV->position().z() - rinfo[ipv].position.z() );
     if ( dist < mindist ) {
@@ -635,11 +630,11 @@ void PrimaryVertexChecker::match_mc_vertex_by_distance( int ipv, std::vector<Rec
   }
 }
 
-std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>&           rblemcpv,
-								   const MCPVInfo& mc ) const { 
+std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>& rblemcpv,
+                                                                   const MCPVInfo&        mc ) const {
 
-  auto itret   = rblemcpv.end();
-  double                          mindist = 999999.;
+  auto   itret   = rblemcpv.end();
+  double mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
@@ -656,8 +651,8 @@ std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<M
 
 std::vector<MCPVInfo>::iterator PrimaryVertexChecker::closestMCPV( std::vector<MCPVInfo>& rblemcpv,
                                                                    const RecPVInfo&       rec ) const {
-  auto itret   = rblemcpv.end();
-  double                          mindist = 999999.;
+  auto   itret   = rblemcpv.end();
+  double mindist = 999999.;
   if ( rblemcpv.size() < 2 ) return itret;
   std::vector<MCPVInfo>::iterator it;
   for ( it = rblemcpv.begin(); it != rblemcpv.end(); it++ ) {
@@ -722,13 +717,12 @@ StatusCode PrimaryVertexChecker::finalize() {
   return GaudiTupleAlg::finalize(); // Must be called after all other actions
 }
 
-void PrimaryVertexChecker::printRat( const std::string name, 
-				     const Gaudi::Accumulators::BinomialCounter<> &m_mcpv,
-                                     const Gaudi::Accumulators::BinomialCounter<> &m_eff,
-                                     const Gaudi::Accumulators::BinomialCounter<> &m_false ) {
+void PrimaryVertexChecker::printRat( const std::string name, const Gaudi::Accumulators::BinomialCounter<>& m_mcpv,
+                                     const Gaudi::Accumulators::BinomialCounter<>& m_eff,
+                                     const Gaudi::Accumulators::BinomialCounter<>& m_false ) {
   unsigned int len  = 25;
   std::string  pmes = name;
-  if ( pmes.size() < len ) pmes.resize( len, ' '); 
+  if ( pmes.size() < len ) pmes.resize( len, ' ' );
   pmes += " : ";
   info() << pmes
          << format( "%8d from %8d (%8d-%-8d) [ %5.2f %], false %4d from reco. %8d (%8d+%-4d) [ %5.2f %] ",
@@ -738,12 +732,12 @@ void PrimaryVertexChecker::printRat( const std::string name,
          << endmsg;
 }
 
-void PrimaryVertexChecker::printAvTracks( const std::string                             name,
-                                          const Gaudi::Accumulators::AveragingCounter<> &m_av_tracks,
-                                          const Gaudi::Accumulators::AveragingCounter<> &m_av_mcp ) {
+void PrimaryVertexChecker::printAvTracks( const std::string                              name,
+                                          const Gaudi::Accumulators::AveragingCounter<>& m_av_tracks,
+                                          const Gaudi::Accumulators::AveragingCounter<>& m_av_mcp ) {
   unsigned int len  = 25;
   std::string  pmes = name;
-  if ( pmes.size() < len ) pmes.resize( len, ' ');
+  if ( pmes.size() < len ) pmes.resize( len, ' ' );
   pmes += " : ";
   info() << pmes << format( "av. PV tracks: %6.2f [MC: %6.2f]", m_av_tracks.mean(), m_av_mcp.mean() ) << endmsg;
 }
@@ -756,12 +750,12 @@ void PrimaryVertexChecker::printRes( std::string mes, double x, double y, double
   info() << pmes << format( " x: %+5.3f, y: %+5.3f, z: %+5.3f", x, y, z ) << endmsg;
 }
 
-double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool rms ) { 
-  return h ? ( rms ? h->rms() : h->mean() ) : 0. ;
+double PrimaryVertexChecker::check_histogram( const AIDA::IHistogram1D* h, bool rms ) {
+  return h ? ( rms ? h->rms() : h->mean() ) : 0.;
 }
 
 int PrimaryVertexChecker::count_velo_tracks( const std::vector<LHCb::Event::v2::WeightedTrack>& tracksPV ) {
-  return std::count_if( tracksPV.begin(), tracksPV.end(), []( const auto& t ) { return t.track->hasVelo(); }) ;
+  return std::count_if( tracksPV.begin(), tracksPV.end(), []( const auto& t ) { return t.track->hasVelo(); } );
 }
 
 void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVertex* mcvtx,
@@ -793,17 +787,17 @@ void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVI
     std::vector<LHCb::MCParticle*>   allproducts;
     collectProductss( avtx, avtx, allproducts );
     std::vector<LHCb::MCParticle*>::iterator imcp;
-    
-    for( const auto pmcp : allproducts ) {
+
+    for ( const auto pmcp : allproducts ) {
       if ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) {
-	if ( pmcp->particleID().hasBottom() )  { itinfomc.decayBeauty = true; }
-	if ( pmcp->particleID().hasCharm() )   { itinfomc.decayCharm = true; }
-	if ( pmcp->particleID().hasStrange() ) { itinfomc.decayStrange = true; }
+        if ( pmcp->particleID().hasBottom() ) { itinfomc.decayBeauty = true; }
+        if ( pmcp->particleID().hasCharm() ) { itinfomc.decayCharm = true; }
+        if ( pmcp->particleID().hasStrange() ) { itinfomc.decayStrange = true; }
       }
       if ( ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) &&
-	   ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
-	double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
-	if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
+           ( !m_requireVelo || trInfo.hasVelo( pmcp ) ) ) {
+        double dv2 = ( avtx->position() - pmcp->originVertex()->position() ).Mag2();
+        if ( dv2 < 0.0000001 && pmcp->p() > 100. * Gaudi::Units::MeV ) { mcPartInMCPV.push_back( pmcp ); }
       }
       itinfomc.nRecTracks = mcPartInMCPV.size();
     }
-- 
GitLab


From 030f00c4197e6e5018fde630e58161211286130b Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus791.cern.ch>
Date: Mon, 1 Feb 2021 17:35:46 +0100
Subject: [PATCH 40/42] fixing formatting

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index efd405623af..36c882fb0c6 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -38,6 +38,7 @@
 #include <string>
 #include <tuple>
 #include <vector>
+
 //-----------------------------------------------------------------------------
 // Implementation file for class : PrimaryVertexChecker
 //-----------------------------------------------------------------------------
-- 
GitLab


From f712bad537f9ec6a9bc8cbba026327a63d8c7f78 Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus779.cern.ch>
Date: Tue, 23 Mar 2021 17:09:17 +0100
Subject: [PATCH 41/42] move from VeloDet to VPDet

---
 Tr/PatChecker/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Tr/PatChecker/CMakeLists.txt b/Tr/PatChecker/CMakeLists.txt
index dee8005e0bd..812a343f44c 100644
--- a/Tr/PatChecker/CMakeLists.txt
+++ b/Tr/PatChecker/CMakeLists.txt
@@ -13,7 +13,7 @@
 ################################################################################
 gaudi_subdir(PatChecker v3r16p1)
 
-gaudi_depends_on_subdirs(Det/VeloDet
+gaudi_depends_on_subdirs(Det/VPDet
 	                 Event/DigiEvent
                          Event/LinkerEvent
                          Event/MCEvent
@@ -33,5 +33,5 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS})
 gaudi_add_module(PatChecker
                  src/*.cpp
                  INCLUDE_DIRS AIDA GSL Event/DigiEvent Kernel/MCInterfaces Tf/TfKernel
-                 LINK_LIBRARIES GSL LinkerEvent MCEvent PhysEvent GaudiAlgLib GaudiKernel VeloDetLib)
+                 LINK_LIBRARIES GSL LinkerEvent MCEvent PhysEvent GaudiAlgLib GaudiKernel VPDetLib)
 
-- 
GitLab


From a0b246d5b2eee0e827bafbd79087733a5f87385d Mon Sep 17 00:00:00 2001
From: Agnieszka Dziurda <adudziak@lxplus7122.cern.ch>
Date: Wed, 24 Mar 2021 11:52:23 +0100
Subject: [PATCH 42/42] fixing warnings

---
 Tr/PatChecker/src/PrimaryVertexChecker.cpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/Tr/PatChecker/src/PrimaryVertexChecker.cpp b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
index 36c882fb0c6..0e3b53b9a19 100644
--- a/Tr/PatChecker/src/PrimaryVertexChecker.cpp
+++ b/Tr/PatChecker/src/PrimaryVertexChecker.cpp
@@ -392,7 +392,6 @@ void PrimaryVertexChecker::operator()( const LHCb::Tracks& tracks, LHCb::Event::
     }
   }
   // Fill distance to closest recble MC PV and its multiplicity
-  std::vector<MCPVInfo>::iterator itmcl;
   for ( auto& mcpv : rblemcpv ) {
     std::vector<MCPVInfo>::iterator cmc  = closestMCPV( rblemcpv, mcpv );
     double                          dist = 999999.;
@@ -778,16 +777,13 @@ void PrimaryVertexChecker::collectProductss( LHCb::MCVertex* mcpv, LHCb::MCVerte
 void PrimaryVertexChecker::count_reconstructible_mc_particles( std::vector<MCPVInfo>&  mcpvvec,
                                                                const LHCb::MCProperty& flags ) const {
 
-  const MCTrackInfo               trInfo = {flags};
-  std::vector<MCPVInfo>::iterator itinfomc;
-
+  const MCTrackInfo trInfo = {flags};
   for ( auto& itinfomc : mcpvvec ) {
     LHCb::MCVertex*                  avtx = itinfomc.pMCPV;
     std::vector<LHCb::MCParticle*>   mcPartInMCPV;
     SmartRefVector<LHCb::MCParticle> parts = avtx->products();
     std::vector<LHCb::MCParticle*>   allproducts;
     collectProductss( avtx, avtx, allproducts );
-    std::vector<LHCb::MCParticle*>::iterator imcp;
 
     for ( const auto pmcp : allproducts ) {
       if ( pmcp->particleID().isMeson() || pmcp->particleID().isBaryon() ) {
-- 
GitLab