The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
DigitizationAlg.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 "IRandomGenSvc.h"
14#include "MCHit.h"
15
16#include <Gaudi/Accumulators.h>
18
19#include <random>
20
22
26 class DigitizationAlg : public Functional::Transformer<Hits( EventContext const&, MCHits const& )> {
27 public:
28 DigitizationAlg( const std::string& name, ISvcLocator* pSvcLocator )
29 : Transformer( name, pSvcLocator, { { "MCHitsLocation", "/Event/MCHits" } },
30 { "HitsLocation", "/Event/Hits" } ) {}
31
32 Hits operator()( const EventContext& ctx, MCHits const& mcHits ) const override {
33 Hits hits;
34 hits.reserve( mcHits.size() );
35 std::normal_distribution dist( 0.0f, m_sigmaNoise.value() ); // µ, σ
36 auto engine = m_rndSvc->getEngine( ctx.evt() );
37 for ( auto const& mcHit : mcHits ) {
38 auto nx = mcHit.x + dist( engine );
39 auto ny = mcHit.y + dist( engine );
40 // ignore negative axis.
41 // Simplifies reconstruction and simulate the apperture of the detector
42 if ( nx > 0 ) {
43 hits.emplace_back( nx, ny );
44 ++n_hits;
45 }
46 }
47 return hits;
48 };
49
50 private:
51 ServiceHandle<IRandomGenSvc> m_rndSvc{ this, "RandomGenSvc", "RandomGenSvc",
52 "A service providing a thread safe random number generator" };
53 Gaudi::Property<float> m_sigmaNoise{ this, "SigmaNoise", 1.f,
54 "Sigma of the noise (a normal distribution centered on 0)" };
55 mutable Gaudi::Accumulators::Counter<> n_hits{ this, "Number of Hits" };
56 };
57
58 DECLARE_COMPONENT( DigitizationAlg )
59
60} // namespace Gaudi::Example::TinyExperiment
#define DECLARE_COMPONENT(type)
This class represents an entry point to all the event specific data.
DigitizationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Hits operator()(const EventContext &ctx, MCHits const &mcHits) 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< MCHit > MCHits
Definition MCHit.h:27
std::vector< Hit > Hits
Definition Hit.h:27
A basic integral counter;.