GetFlavourTaggingParticles.cpp 3.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*****************************************************************************\
* (c) Copyright 2000-2021 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.                                       *
\*****************************************************************************/

#include "GetFlavourTaggingParticles.h"

// Declaration of the Algorithm Factory
DECLARE_COMPONENT( GetFlavourTaggingParticles )

17
LHCb::Particle::Selection GetFlavourTaggingParticles::operator()( const LHCb::Particle::Range& bCandidates,
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
                                                                  const LHCb::Particle::Range& taggingParticles,
                                                                  const LHCb::RecVertices&     primaryVertices,
                                                                  const DetectorElement&       lhcbDetector ) const {
  auto& geometry = *lhcbDetector.geometry();

  LHCb::Particle::Selection selectedParticles;

  for ( const auto& particle : taggingParticles ) {
    const LHCb::VertexBase* bestParticlePV = m_relatedPVTool->relatedPV( particle, primaryVertices );

    for ( const auto& bCand : bCandidates ) {
      const LHCb::VertexBase* bestbCandPV = m_relatedPVTool->relatedPV( bCand, primaryVertices );
      if ( bestbCandPV == bestParticlePV ) {
        selectedParticles.insert( particle );
        break;
      }

      auto minIpChi2 = calcMinIpChi2( *particle, primaryVertices, geometry );
      if ( minIpChi2.has_value() ) {
        if ( minIpChi2.value() > m_minIpChi2 ) {
          selectedParticles.insert( particle );
          break;
        }
      }
    }
  }

  m_inCount += taggingParticles.size();
  m_outCount += selectedParticles.size();
  return selectedParticles;
}

std::optional<double> GetFlavourTaggingParticles::calcMinIpChi2( const LHCb::Particle&    part,
                                                                 const LHCb::RecVertices& vertices,
                                                                 const IGeometryInfo&     geometry ) const {
  double minIpChi2 = std::numeric_limits<double>::max();

  for ( auto const* vertex : vertices ) {
    auto tempIpChi2 = calcIpChi2( part, *vertex, geometry );
    if ( tempIpChi2.has_value() ) {
      if ( tempIpChi2.value() < minIpChi2 ) { minIpChi2 = tempIpChi2.value(); }
    }
  }
  if ( minIpChi2 < std::numeric_limits<double>::max() ) return minIpChi2;
  return std::nullopt;
}

std::optional<double> GetFlavourTaggingParticles::calcIpChi2( const LHCb::Particle&   part,
                                                              const LHCb::VertexBase& vertex,
                                                              const IGeometryInfo&    geometry ) const {
  double     ip     = -100.0;
  double     ipChi2 = 0;
  StatusCode sc     = m_distCalcTool->distance( &part, &vertex, ip, ipChi2, geometry );
  if ( sc ) return ipChi2;
  return std::nullopt;
}