Skip to content
Snippets Groups Projects

WIP: Add TrackPVChecker algorithm

Closed Wouter Hulsbergen requested to merge wh_addTrackPVChecker_20181111 into master
6 unresolved threads

Algorithm to make histograms to compare different PV algorithms. Still a mess. Not ready for merge yet!

Merge request reports

Pipeline #582115 failed

Pipeline failed for 16638466 on wh_addTrackPVChecker_20181111

Approval is optional

Closed by Sebastien PonceSebastien Ponce 5 years ago (Apr 6, 2020 6:36pm UTC)

Merge details

  • The changes were not merged into master.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
30 DeVelo* m_velodet{nullptr} ;
31 size_t m_eventindex{0} ;
32 };
33
34 DECLARE_COMPONENT( TrackPVChecker )
35
36 namespace {
37
38 template<class TrackContainer, class MCParticleContainer>
39 std::vector<std::pair<const LHCb::Track*, const LHCb::MCParticle*> >
40 trackToMCParticle( const TrackContainer& tracks,
41 const MCParticleContainer& mcparticles )
42 {
43 // first collect all MC particles that we could potentially match to tracks
44 std::vector<const LHCb::MCParticle*> mctracks ;
45 const std::vector<int> pids = { 11, 13, 211, 321, 2212 } ;
  • 39 std::vector<std::pair<const LHCb::Track*, const LHCb::MCParticle*> >
    40 trackToMCParticle( const TrackContainer& tracks,
    41 const MCParticleContainer& mcparticles )
    42 {
    43 // first collect all MC particles that we could potentially match to tracks
    44 std::vector<const LHCb::MCParticle*> mctracks ;
    45 const std::vector<int> pids = { 11, 13, 211, 321, 2212 } ;
    46 for( const auto& particle : mcparticles ) {
    47 if( std::find(pids.begin(),pids.end(),std::abs(particle->particleID().pid()))!=pids.end() &&
    48 particle->originVertex() &&
    49 std::abs(particle->originVertex()->position().z()) < 700 * Gaudi::Units::mm ) {
    50 float L2{0} ;
    51 for( const auto& decayvtx : particle->endVertices() ) {
    52 auto thisL2 = (decayvtx->position() - particle->originVertex()->position()).Mag2() ;
    53 if( L2<thisL2 ) L2 = thisL2 ;
    54 }
    • how about:

         const auto& vtxs = particle->endVertices();
         const float L2 = std::accumulate( begin(vtxs), end(vtxs), 0.f,
                                           [&](float l2, const auto& decayvtx) {
                                auto thisL2 = (decayvtx->position() - particle->originVertex()->position()).Mag2() ;
                                return std::max(l2, thisL2);
                           });

      instead?

    • Please register or sign in to reply
  • 71 float dty = s.ty() - mcty ;
    72 if( std::abs(dtx) < 0.01 && std::abs(dty) < 0.01 ) {
    73 const auto mcpos = mcp->originVertex()->position() ;
    74 float dz = s.z() - mcpos.z() ;
    75 float dx = s.x() - (mcpos.x() + mctx*dz ) ;
    76 float dy = s.y() - (mcpos.y() + mcty*dz ) ;
    77 if( std::abs(dx) < 10*Gaudi::Units::mm && std::abs(dy) < 10*Gaudi::Units::mm ) {
    78 // compute the chi2 for the match
    79 Gaudi::Vector4 delta{dx,dy,dtx,dty} ;
    80 double chi2 = ROOT::Math::Similarity(delta,weightmatrix) ;
    81 if( chi2 < bestchi2 ) {
    82 bestmcp = mcp ;
    83 bestchi2 = chi2 ;
    84 }
    85 }
    86 }
    • How about:

      const LHCb::MCParticle *bestmcp = std::accumulate( begin(mctracks), end(mctracks), std::pair{100.,(const LHCb::MCParticle*)nullptr},
                                                         [&](auto prev, const auto& mcp) {
              const float mctx = mcp->momentum().Px() / mcp->momentum().Pz() ;
      	const float mcty = mcp->momentum().Py() / mcp->momentum().Pz() ;
      	float dtx = s.tx() - mctx ;
      	float dty = s.ty() - mcty ;
              if( std::abs(dtx) > 0.01 || std::abs(dty) > 0.01 ) return prev;
      
              const auto mcpos = mcp->originVertex()->position() ;
      	float dz = s.z() - mcpos.z() ;
      	float dx = s.x() - (mcpos.x() + mctx*dz ) ;
      	float dy = s.y() - (mcpos.y() + mcty*dz ) ;
              if ( std::abs(dx) > 10*Gaudi::Units::mm || std::abs(dy) > 10*Gaudi::Units::mm ) return prev;
      
              // compute the chi2 for the match
      	Gaudi::Vector4 delta{dx,dy,dtx,dty} ;
      	double chi2 = ROOT::Math::Similarity(delta,weightmatrix) ;
              if ( chi2 >= pair.first ) return prev;
      
              return std::pair{ chi2, mcp };
      } ).second;

      One loop less, and less indenting...

    • Please register or sign in to reply
  • 97 const LHCb::MCParticle* mother = mcv->mother() ;
    98 if( mcv ) {
    99 // check if the particle has a mother
    100 if( mother && mother->originVertex() ) {
    101 if( std::abs(mcv->position().z() - mother->originVertex()->position().z() ) < 0.002 * Gaudi::Units::mm )
    102 mcv = mcoriginvertex( *mother ) ;
    103 }
    104 } else if( mother ) mcv = mcoriginvertex( *mother ) ;
    105 return mcv ;
    106 }
    107
    108 struct MCVertexWithTracks
    109 {
    110 MCVertexWithTracks(const LHCb::MCVertex* vtx,
    111 const std::vector<const LHCb::Track*>& tracks) :
    112 mcvertex{vtx},recotracks{tracks} { std::sort(std::begin(recotracks),std::end(recotracks)) ; }
    • when you have a 'sink' argument in the constructor, better to pass by value and move. In the case the constructor is then called with a temporary, this then effectively re-uses that temporary. Concretely:

      MCVertexWithTracks(const LHCb::MCVertex* vtx,
      		    const std::vector<const LHCb::Track*> tracks) :
            mcvertex{vtx},recotracks{std::move(tracks)} { std::sort(std::begin(recotracks),std::end(recotracks)) ; }

      or, if you want to be more generic and accept any type of range:

      template <typename RangeOfTracks>
      MCVertexWithTracks(const LHCb::MCVertex* vtx,
      		    RangeOfTracks tracks) :
            mcvertex{vtx},recotracks{std::forward<RangeOfTracks>(tracks)} { std::sort(begin(recotracks),end(recotracks)) ; }
      
      Edited by Gerhard Raven
    • Please register or sign in to reply
  • 137 {
    138 size_t rc(0) ;
    139 while (first1 != last1 && first2 != last2) {
    140 if ( *first1 < *first2 ) {
    141 ++first1;
    142 } else if ( *first2 < *first1 ) {
    143 ++first2;
    144 } else {
    145 ++first1;
    146 ++first2;
    147 ++rc ;
    148 }
    149 }
    150 return rc ;
    151 }
    152 }
  • 44 /// Initialization
    45 StatusCode initialize() override ;
    46 private:
    47 Gaudi::Property<unsigned int> m_minNumTracksPerVertex{this,"MinNumTracksPerVertex",5} ;
    48 Gaudi::Property<float> m_zmin{this,"MinZ",-300*Gaudi::Units::mm,"Min z position of vertex seed"};
    49 Gaudi::Property<float> m_zmax{this,"MaxZ",+300*Gaudi::Units::mm,"Max z position of vertex seed"};
    50 Gaudi::Property<float> m_dz{this,"ZBinSize",0.25*Gaudi::Units::mm,"Z histogram bin size"} ;
    51 Gaudi::Property<float> m_maxTrackZ0Err{this,"MaxTrackZ0Err",1.5*Gaudi::Units::mm,"Maximum z0-error for adding track to histo"};
    52 Gaudi::Property<float> m_minDensity{this,"MinDensity",1.0/Gaudi::Units::mm,"Minimal density at cluster peak (inverse resolution)"};
    53 Gaudi::Property<float> m_minDipDensity{this,"MinDipDensity",2.0/Gaudi::Units::mm,"Minimal depth of a dip to split cluster (inverse resolution)"};
    54 Gaudi::Property<float> m_minTracksInSeed{this,"MinTrackIntegralInSeed",2.5} ;
    55 Gaudi::Property<float> m_maxVertexRho{this,"BeamSpotRCut",0.3*Gaudi::Units::mm,"Maximum distance of vertex to beam line"} ;
    56 Gaudi::Property<unsigned int> m_maxFitIter{this,"MaxFitIter",5,"Maximum number of iterations for vertex fit"} ;
    57 Gaudi::Property<float> m_maxDeltaChi2{this,"MaxDeltaChi2",9,"Maximum chi2 contribution of track to vertex fit"} ;
    58 DeVelo* m_velodet{nullptr} ;
    59 #ifdef TIMINGHISTOGRAMMING
  • Olli Lupton mentioned in merge request !1477 (closed)

    mentioned in merge request !1477 (closed)

  • @wouter Is this still alive ? If yes, please rebase, apply comments, retest and unWIP. If not, please close.

  • @wouter ping. Should we do like for the LHCb MR we've discussed earlier today ? Close the MR and keep the branch in protected mode ? If no answer, I'll close this in a week

  • Agreed.

  • Please register or sign in to reply
    Loading