The Gaudi Framework  master (37c0b60a)
CheckerAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 
12 #include "MCTrack.h"
13 #include "Track.h"
14 
15 #include <Gaudi/Accumulators.h>
17 
18 #include <climits>
19 
21 
25  class CheckerAlg : public Functional::Consumer<void( MCTracks const&, Tracks const& )> {
26  public:
27  CheckerAlg( const std::string& name, ISvcLocator* pSvcLocator )
28  : Consumer(
29  name, pSvcLocator,
30  { KeyValue{ "MCTracksLocation", "/Event/MCTracks" }, KeyValue{ "TracksLocation", "/Event/Tracks" } } ) {}
31 
32  void operator()( MCTracks const& mcTracks, Tracks const& tracks ) const override {
33  for ( auto const& track : tracks ) {
34  MCTracks selection;
35  selection.reserve( 10 );
36  std::copy_if( mcTracks.begin(), mcTracks.end(), std::back_inserter( selection ),
37  [track, this]( MCTrack mcTrack ) { return almostEqual( track.theta, mcTrack.theta ); } );
38  if ( selection.size() == 0 ) {
39  ++n_ghostTracks;
40  } else {
41  ++n_foundTracks;
42  }
43  }
44  for ( auto const& mcTrack : mcTracks ) {
45  Tracks selection;
46  selection.reserve( 10 );
47  std::copy_if( tracks.begin(), tracks.end(), std::back_inserter( selection ),
48  [mcTrack, this]( Track track ) { return almostEqual( track.theta, mcTrack.theta ); } );
49  if ( selection.size() == 0 ) {
50  ++n_lostTracks;
51  } else if ( selection.size() > 1 ) {
53  }
54  }
55  }
56 
57  private:
58  bool almostEqual( float a, float b ) const { return std::abs( a - b ) <= m_maxDeltaTheta; }
59 
60  Gaudi::Property<float> m_maxDeltaTheta{ this, "DeltaThetaMax", 0.001,
61  "(Relative) maximum delta theta to consider 2 tracks as identical" };
62  mutable Gaudi::Accumulators::Counter<> n_foundTracks{ this, "Number of Tracks properly reconstructed" };
63  mutable Gaudi::Accumulators::Counter<> n_ghostTracks{ this, "Number of ghost Tracks" };
64  mutable Gaudi::Accumulators::Counter<> n_duplicatedTracks{ this, "Number of Tracks reconstructed twice" };
65  mutable Gaudi::Accumulators::Counter<> n_lostTracks{ this, "Number of Tracks missing after reconstruction" };
66  };
67 
68  DECLARE_COMPONENT( CheckerAlg )
69 
70 } // namespace Gaudi::Example::TinyExperiment
Gaudi::Functional::Consumer
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition: Consumer.h:69
std::string
STL class.
Gaudi::Example::TinyExperiment::CheckerAlg::almostEqual
bool almostEqual(float a, float b) const
Definition: CheckerAlg.cpp:58
std::vector::reserve
T reserve(T... args)
Gaudi::Accumulators::Counter<>
Gaudi::Example::TinyExperiment::CheckerAlg::operator()
void operator()(MCTracks const &mcTracks, Tracks const &tracks) const override
Definition: CheckerAlg.cpp:32
std::vector
STL class.
std::vector::size
T size(T... args)
ISvcLocator
Definition: ISvcLocator.h:46
std::back_inserter
T back_inserter(T... args)
Gaudi::Example::TinyExperiment::CheckerAlg::n_ghostTracks
Gaudi::Accumulators::Counter n_ghostTracks
Definition: CheckerAlg.cpp:63
Gaudi::Example::TinyExperiment::CheckerAlg::m_maxDeltaTheta
Gaudi::Property< float > m_maxDeltaTheta
Definition: CheckerAlg.cpp:60
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition: ParticleID.h:191
Gaudi::Example::TinyExperiment::CheckerAlg::n_lostTracks
Gaudi::Accumulators::Counter n_lostTracks
Definition: CheckerAlg.cpp:65
Gaudi::Example::TinyExperiment::CheckerAlg::CheckerAlg
CheckerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CheckerAlg.cpp:27
Gaudi::Functional::details::Consumer
Definition: Consumer.h:24
Consumer.h
Gaudi::Example::TinyExperiment::CheckerAlg::n_duplicatedTracks
Gaudi::Accumulators::Counter n_duplicatedTracks
Definition: CheckerAlg.cpp:64
std::copy_if
T copy_if(T... args)
MCTrack.h
Accumulators.h
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::vector::begin
T begin(T... args)
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Example::TinyExperiment::CheckerAlg::n_foundTracks
Gaudi::Accumulators::Counter n_foundTracks
Definition: CheckerAlg.cpp:62
Gaudi::Example::TinyExperiment
Definition: CheckerAlg.cpp:20
Track.h
Gaudi::Example::TinyExperiment::MCTrack
most simple MC Track ever : in 2D space, starting from the origin and thus fully defined by an angle ...
Definition: MCTrack.h:21
Gaudi::Example::TinyExperiment::CheckerAlg
Comparison of Reconstructed Tracks and MCTracks.
Definition: CheckerAlg.cpp:25
std::vector::end
T end(T... args)
Gaudi::Example::TinyExperiment::Track
most simple Track ever : in 2D space, starting from the origin and thus fully defined by an angle the...
Definition: Track.h:21
Gaudi::Property< float >