The Gaudi Framework  master (37c0b60a)
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
Gaudi::Example::TinyExperiment::DigitizationAlg::DigitizationAlg
DigitizationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DigitizationAlg.cpp:28
std::string
STL class.
Gaudi::Example::TinyExperiment::DigitizationAlg::n_hits
Gaudi::Accumulators::Counter n_hits
Definition: DigitizationAlg.cpp:55
std::vector::reserve
T reserve(T... args)
Gaudi::Accumulators::Counter<>
ServiceHandle
Definition: ServiceHandle.h:41
std::vector
STL class.
std::vector::size
T size(T... args)
IRandomGenSvc.h
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::Example::TinyExperiment::DigitizationAlg::m_rndSvc
ServiceHandle< IRandomGenSvc > m_rndSvc
Definition: DigitizationAlg.cpp:51
Gaudi::Example::TinyExperiment::DigitizationAlg
Digitization algorithm returning a set of hits from MCHits, basically adding noise.
Definition: DigitizationAlg.cpp:26
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
std::normal_distribution
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
Transformer.h
MCHit.h
Gaudi::Example::TinyExperiment::DigitizationAlg::m_sigmaNoise
Gaudi::Property< float > m_sigmaNoise
Definition: DigitizationAlg.cpp:53
Hit.h
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::DigitizationAlg::operator()
Hits operator()(const EventContext &ctx, MCHits const &mcHits) const override
Definition: DigitizationAlg.cpp:32
Gaudi::Property< float >