ATLAS Offline Software
Loading...
Searching...
No Matches
DummyVertexSelectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "CLHEP/Random/RandFlat.h"
9#include <vector>
10
11namespace Trk{
12
13 //constructor
14 DummyVertexSelectionTool::DummyVertexSelectionTool ( const std::string& t, const std::string& n, const IInterface* p )
15 : base_class ( t,n,p ),m_randomEngineName("VertexRnd")
16 {
17 declareProperty("RandomStreamName", m_randomEngineName, "Name of the random number stream");
18 }
19
20 //destructor
22
23//initialize
25 {
26 ATH_CHECK( m_randomSvc.retrieve() );
27 return StatusCode::SUCCESS;
28 }
29
31 {
32 return StatusCode::SUCCESS;
33 }
34
36 {
37 if(vertexContainer->size()>2)
38 {
39
40 // Get the RNG engine. Reseed if a new event.
41 const EventContext& ctx = Gaudi::Hive::currentContext();
42 ATHRNG::RNGWrapper* wrapper = m_randomSvc->getEngine(this, m_randomEngineName);
43 if (wrapper->evtSeeded (ctx) != ctx.evt()) {
44 wrapper->setSeed (name(), ctx);
45 }
46 CLHEP::HepRandomEngine* engine = wrapper->getEngine (ctx);
47
48//only do anything if >1 real vertex is actually present
49 if( CLHEP::RandFlat::shoot(engine)>0.9)
50 {
51//and only in 10% of cases let us randomize the vertex choice
52 unsigned int ivtx = (unsigned int)( CLHEP::RandFlat::shoot(engine) * vertexContainer->size());
53
54 ATH_MSG_VERBOSE("Vertex Selection changed to " << ivtx << "!");
55 return ivtx;
56
57 }//end of random selection
58 ATH_MSG_VERBOSE("Vertex Selection unchanged!");
59
60 }//end of VertexContainer size check
61
62//nothing happened, return the default primary vertex position
63 return 0;
64 }
65
66}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
EventContext::ContextEvt_t evtSeeded() const
Return the event count at which the current slot was last seeded.
Definition RNGWrapper.h:139
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
size_type size() const noexcept
Returns the number of elements in the collection.
virtual StatusCode finalize() override
EndOfInitialize.
std::string m_randomEngineName
Name of the random number stream.
ServiceHandle< IAthRNGSvc > m_randomSvc
Pointer to the random number generator service.
virtual StatusCode initialize() override
virtual ~DummyVertexSelectionTool()
destructor
DummyVertexSelectionTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
virtual unsigned int findVertexInContainer(const xAOD::VertexContainer *) const override
Ensure that the ATLAS eigen extensions are properly loaded.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".