ATLAS Offline Software
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 
11 namespace 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 
35  unsigned int DummyVertexSelectionTool::findVertexInContainer(const xAOD::VertexContainer * vertexContainer ) const
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 }
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
DummyVertexSelectionTool.h
Trk::DummyVertexSelectionTool::m_randomEngineName
std::string m_randomEngineName
Name of the random number stream.
Definition: DummyVertexSelectionTool.h:62
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::DummyVertexSelectionTool::~DummyVertexSelectionTool
virtual ~DummyVertexSelectionTool()
destructor
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ParamDefs.h
Trk::DummyVertexSelectionTool::finalize
virtual StatusCode finalize() override
EndOfInitialize.
Definition: DummyVertexSelectionTool.cxx:30
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::DummyVertexSelectionTool::DummyVertexSelectionTool
DummyVertexSelectionTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
Definition: DummyVertexSelectionTool.cxx:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
Trk::DummyVertexSelectionTool::findVertexInContainer
virtual unsigned int findVertexInContainer(const xAOD::VertexContainer *) const override
Definition: DummyVertexSelectionTool.cxx:35
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
Trk::DummyVertexSelectionTool::initialize
virtual StatusCode initialize() override
Definition: DummyVertexSelectionTool.cxx:24
ATHRNG::RNGWrapper::evtSeeded
EventContext::ContextEvt_t evtSeeded() const
Return the event count at which the current slot was last seeded.
Definition: RNGWrapper.h:139
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Trk::DummyVertexSelectionTool::m_randomSvc
ServiceHandle< IAthRNGSvc > m_randomSvc
Pointer to the random number generator service.
Definition: DummyVertexSelectionTool.h:61