The Gaudi Framework  master (37c0b60a)
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
std::string
STL class.
Gaudi::Example::TinyExperiment::GeneratorAlg::m_thetas
Gaudi::Accumulators::AveragingCounter m_thetas
Definition: GeneratorAlg.cpp:48
std::vector::reserve
T reserve(T... args)
ServiceHandle
Definition: ServiceHandle.h:41
std::vector
STL class.
IRandomGenSvc.h
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::Example::TinyExperiment::GeneratorAlg::operator()
MCTracks operator()(EventContext const &ctx) const override
Definition: GeneratorAlg.cpp:31
Gaudi::Example::TinyExperiment::GeneratorAlg
Generator algorithm returning a set of random tracks.
Definition: GeneratorAlg.cpp:26
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition: Accumulators.h:983
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
std::normal_distribution
Transformer.h
Gaudi::Example::TinyExperiment::GeneratorAlg::GeneratorAlg
GeneratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GeneratorAlg.cpp:28
MCTrack.h
Gaudi::Example::TinyExperiment::GeneratorAlg::m_rndSvc
ServiceHandle< IRandomGenSvc > m_rndSvc
Definition: GeneratorAlg.cpp:45
Accumulators.h
std::vector::emplace_back
T emplace_back(T... args)
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
EventContext
Definition: EventContext.h:34
Gaudi::Example::TinyExperiment
Definition: CheckerAlg.cpp:20
Gaudi ::Functional::Transformer
details::Transformer< Signature, Traits_, details::isLegacy< Traits_ > > Transformer
Definition: Transformer.h:237
Gaudi::Example::TinyExperiment::GeneratorAlg::m_nbTracksToGenerate
Gaudi::Property< unsigned int > m_nbTracksToGenerate
Definition: GeneratorAlg.cpp:47
Gaudi::Property< unsigned int >