The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
GeneratorAlg.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 "IRandomGenSvc.h"
13#include "MCTrack.h"
14
15#include <Gaudi/Accumulators.h>
17
18#include <cmath>
19#include <random>
20
22
26 class GeneratorAlg : public Functional::Transformer<MCTracks( EventContext const& )> {
27 public:
28 GeneratorAlg( const std::string& name, ISvcLocator* pSvcLocator )
29 : Transformer( name, pSvcLocator, { "MCTracksLocation", "/Event/MCTracks" } ) {}
30
31 MCTracks operator()( EventContext const& ctx ) const override {
32 MCTracks tracks;
33 tracks.reserve( m_nbTracksToGenerate );
34 std::normal_distribution dist( 0.0f, (float)M_PI / 4 ); // µ, σ
35 auto engine = m_rndSvc->getEngine( ctx.evt() );
36 for ( unsigned int i = 0; i < m_nbTracksToGenerate; i++ ) {
37 auto theta = dist( engine );
38 m_thetas += theta;
39 tracks.emplace_back( theta );
40 }
41 return tracks;
42 };
43
44 private:
45 ServiceHandle<IRandomGenSvc> m_rndSvc{ this, "RandomGenSvc", "RandomGenSvc",
46 "A service providing a thread safe random number generator" };
47 Gaudi::Property<unsigned int> m_nbTracksToGenerate{ this, "NbTracksToGenerate", 10 };
48 mutable Gaudi::Accumulators::AveragingCounter<> m_thetas{ this, "Theta values" };
49 };
50
51 DECLARE_COMPONENT( GeneratorAlg )
52
53} // namespace Gaudi::Example::TinyExperiment
#define DECLARE_COMPONENT(type)
This class represents an entry point to all the event specific data.
Gaudi::Property< unsigned int > m_nbTracksToGenerate
GeneratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< IRandomGenSvc > m_rndSvc
Gaudi::Accumulators::AveragingCounter m_thetas
MCTracks operator()(EventContext const &ctx) 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
Handle to be used in lieu of naked pointers to services.
std::vector< MCTrack > MCTracks
Definition MCTrack.h:28
A counter aiming at computing sum and average.