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
>
16
#include <
Gaudi/Functional/Transformer.h
>
17
18
#include <cmath>
19
#include <random>
20
21
namespace
Gaudi::Example::TinyExperiment
{
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
Accumulators.h
IRandomGenSvc.h
MCTrack.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
Transformer.h
EventContext
This class represents an entry point to all the event specific data.
Definition
EventContext.h:34
Gaudi::Example::TinyExperiment::GeneratorAlg::m_nbTracksToGenerate
Gaudi::Property< unsigned int > m_nbTracksToGenerate
Definition
GeneratorAlg.cpp:47
Gaudi::Example::TinyExperiment::GeneratorAlg::GeneratorAlg
GeneratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
GeneratorAlg.cpp:28
Gaudi::Example::TinyExperiment::GeneratorAlg::m_rndSvc
ServiceHandle< IRandomGenSvc > m_rndSvc
Definition
GeneratorAlg.cpp:45
Gaudi::Example::TinyExperiment::GeneratorAlg::m_thetas
Gaudi::Accumulators::AveragingCounter m_thetas
Definition
GeneratorAlg.cpp:48
Gaudi::Example::TinyExperiment::GeneratorAlg::operator()
MCTracks operator()(EventContext const &ctx) const override
Definition
GeneratorAlg.cpp:31
Gaudi::Property
Implementation of property with value of concrete type.
Definition
PropertyFwd.h:27
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
ServiceHandle
Handle to be used in lieu of naked pointers to services.
Definition
ServiceHandle.h:38
Gaudi::Example::TinyExperiment
Definition
CheckerAlg.cpp:20
Gaudi::Example::TinyExperiment::MCTracks
std::vector< MCTrack > MCTracks
Definition
MCTrack.h:28
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition
Accumulators.h:970
GaudiExamples
TinyExperiment
src
GeneratorAlg.cpp
Generated on Wed Oct 8 2025 09:53:36 for The Gaudi Framework by
1.13.1