The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
TrackingAlg.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 "Hit.h"
13#include "Track.h"
14
15#include <Gaudi/Accumulators.h>
17
18#include <cmath>
19#include <vector>
20
22
26 class TrackingAlg : public Functional::Transformer<Tracks( Hits const& )> {
27 public:
28 TrackingAlg( const std::string& name, ISvcLocator* pSvcLocator )
29 : Transformer( name, pSvcLocator, { { "HitsLocation", "/Event/Hits" } },
30 { "TracksLocation", "/Event/Tracks" } ) {}
31
32 Tracks operator()( Hits const& hits ) const override {
33 // hough transform, actually only computing theta, and not dealing properly with borders of bins
34 std::vector<unsigned int> bins( m_nBins, 0 );
35 for ( auto const& hit : hits ) {
36 auto theta = std::atan( hit.y / hit.x );
37 auto index = static_cast<unsigned int>( ( theta + M_PI / 2 ) / M_PI * m_nBins );
38 ++bins.at( index );
39 }
40 // extract tracks
41 Tracks tracks;
42 tracks.reserve( hits.size() / 10 );
43 for ( unsigned int n = 0; n < m_nBins; n++ ) {
44 if ( bins[n] > 0 ) {}
45 if ( bins[n] >= m_sensibility ) {
46 tracks.emplace_back( -M_PI / 2 + ( M_PI * ( n + 0.5f ) ) / m_nBins );
47 ++n_tracks;
48 }
49 }
50 return tracks;
51 };
52
53 private:
54 Gaudi::Property<unsigned int> m_nBins{ this, "NumberBins", 180, "Number of bins in the Hough Transform for theta" };
56 "How many hits do we want for considering we have a track ?" };
57 mutable Gaudi::Accumulators::Counter<> n_tracks{ this, "Number of Tracks" };
58 };
59
60 DECLARE_COMPONENT( TrackingAlg )
61
62} // namespace Gaudi::Example::TinyExperiment
#define DECLARE_COMPONENT(type)
Gaudi::Property< unsigned int > m_sensibility
Gaudi::Accumulators::Counter n_tracks
TrackingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< unsigned int > m_nBins
Tracks operator()(Hits const &hits) const override
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
std::vector< Track > Tracks
Definition Track.h:28
std::vector< Hit > Hits
Definition Hit.h:27
A basic integral counter;.