The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
SimulationAlg.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 "MCHit.h"
13#include "MCTrack.h"
14
15#include <Gaudi/Accumulators.h>
17
18#include <cmath>
19
20namespace {
21 std::pair<float, float> sincos( float arg ) { return { std::sin( arg ), std::cos( arg ) }; }
22} // namespace
23
25
29 class SimulationAlg : public Functional::Transformer<MCHits( MCTracks const& )> {
30 public:
31 SimulationAlg( const std::string& name, ISvcLocator* pSvcLocator )
32 : Transformer( name, pSvcLocator, { { "MCTracksLocation", "/Event/MCTracks" } },
33 { "MCHitsLocation", "/Event/MCHits" } ) {}
34
35 MCHits operator()( MCTracks const& tracks ) const override {
36 MCHits hits;
37 hits.reserve( tracks.size() * m_nbHitsPerTrack );
38 for ( auto const& track : tracks ) {
39 auto [s, c] = sincos( track.theta );
40 for ( unsigned int i = 0; i < m_nbHitsPerTrack; i++ ) {
41 hits.emplace_back( i * c, i * s );
42 ++n_hits;
43 }
44 }
45 return hits;
46 };
47
48 private:
49 Gaudi::Property<unsigned int> m_nbHitsPerTrack{ this, "NbHitsPerTrack", 10 };
50 mutable Gaudi::Accumulators::Counter<> n_hits{ this, "Number of MCHits" };
51 };
52
53 DECLARE_COMPONENT( SimulationAlg )
54
55} // namespace Gaudi::Example::TinyExperiment
#define DECLARE_COMPONENT(type)
SimulationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< unsigned int > m_nbHitsPerTrack
MCHits operator()(MCTracks const &tracks) 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< MCTrack > MCTracks
Definition MCTrack.h:28
std::vector< MCHit > MCHits
Definition MCHit.h:27
A basic integral counter;.