ATLAS Offline Software
Loading...
Searching...
No Matches
Simulation::LRAVertexPositioner Class Reference

Generates vertex positions based on a LRA histogram. More...

#include <LRAVertexPositioner.h>

Inheritance diagram for Simulation::LRAVertexPositioner:
Collaboration diagram for Simulation::LRAVertexPositioner:

Public Member Functions

 LRAVertexPositioner (const std::string &t, const std::string &n, const IInterface *p)
 Constructor.
virtual ~LRAVertexPositioner ()=default
 Destructor.
virtual StatusCode initialize () override final
 AthAlgTool initialization.
virtual StatusCode finalize () override final
 AthAlgTool finalization.
virtual CLHEP::HepLorentzVector * generate (const EventContext &ctx) const override final
 Generate a vertex position from the LRA input.

Private Types

using IntegralTuple = std::tuple<Int_t, Int_t, Int_t, Double_t>
 Tuple for [xBin, yBin, zBin, Integral].

Private Attributes

Gaudi::Property< std::string > m_FileName {this, "FileName", "<<Unset>>", "LRA input file name."}
 LRA input file name.
Gaudi::Property< std::string > m_HistName {this, "HistName", "<<Unset>>", "LRA input histogram name."}
 LRA input histogram name.
std::unique_ptr< TFile > m_LRAFile
 Owning TFile * to the LRA file.
const TH3F * m_LRAHist = nullptr
 Non-owning TH3F * to the LRA histogram.
ServiceHandle< IAthRNGSvcm_RNGService {this, "RNGService", "AthRNGSvc"}
 Handle to the Athena RNG service.
Gaudi::Property< std::string > m_RNGStream {this, "RNGStream", "LRAVertexPositioner", "Stream name for the RNG service."}
 Stream name for the RNG service.
ATHRNG::RNGWrapper *m_RNGEngine ATLAS_THREAD_SAFE {}
 Non-owning RNGWrapper * to the RNG engine.
std::vector< IntegralTuplem_Integral
 Vector to hold the running integral over bins.
const TAxis * m_xAxis = nullptr
 Non-owning TAxis * to the histograms x-Axis.
const TAxis * m_yAxis = nullptr
 Non-owning TAxis * to the histograms y-Axis.
const TAxis * m_zAxis = nullptr
 Non-owning TAxis * to the histograms z-Axis.

Detailed Description

Generates vertex positions based on a LRA histogram.

Definition at line 26 of file LRAVertexPositioner.h.

Member Typedef Documentation

◆ IntegralTuple

using Simulation::LRAVertexPositioner::IntegralTuple = std::tuple<Int_t, Int_t, Int_t, Double_t>
private

Tuple for [xBin, yBin, zBin, Integral].

Definition at line 62 of file LRAVertexPositioner.h.

Constructor & Destructor Documentation

◆ LRAVertexPositioner()

Simulation::LRAVertexPositioner::LRAVertexPositioner ( const std::string & t,
const std::string & n,
const IInterface * p )

Constructor.

Definition at line 19 of file LRAVertexPositioner.cxx.

20 : base_class(t,n,p)
21 {
22 };

◆ ~LRAVertexPositioner()

virtual Simulation::LRAVertexPositioner::~LRAVertexPositioner ( )
virtualdefault

Destructor.

Member Function Documentation

◆ finalize()

StatusCode Simulation::LRAVertexPositioner::finalize ( )
finaloverridevirtual

AthAlgTool finalization.

Definition at line 121 of file LRAVertexPositioner.cxx.

122 {
123 return StatusCode::SUCCESS;
124 };

◆ generate()

CLHEP::HepLorentzVector * Simulation::LRAVertexPositioner::generate ( const EventContext & ctx) const
finaloverridevirtual

Generate a vertex position from the LRA input.

Definition at line 128 of file LRAVertexPositioner.cxx.

129 {
130 // Set the RNG seed and get the engine for this event.
131 m_RNGEngine->setSeed(name(), ctx);
132 CLHEP::HepRandomEngine *LRAEngine(m_RNGEngine->getEngine(ctx));
133
134 //---
135
136 // Compare the integral of two IntegralTuples.
137 auto Comparison = [](const auto &LHS, const auto &RHS)
138 {
139 // No language place-holders... Yet...
140 auto [lx, ly, lz, i] = LHS;
141 auto [rx, ry, rz, t] = RHS;
142
143 return(i < t);
144 };
145
146 // Get the point a V'th between the bin edges.
147 auto GetCoordinate = [](const auto Axis, const auto Bin, const auto V)
148 {
149 return(Axis->GetBinLowEdge(Bin) + (V * Axis->GetBinWidth(Bin)));
150 };
151
152 // Find the x/y/z bin numbers of the interesting bin.
153 auto [xBin, yBin, zBin, Integral] = *(std::lower_bound(m_Integral.cbegin(),
154 m_Integral.cend(),
155 std::make_tuple(0, 0, 0, CLHEP::RandFlat::shoot(LRAEngine)),
156 Comparison));
157
158 // Return a point in the bin, caller deletes.
159 CLHEP::HepLorentzVector *vertexPosition = new CLHEP::HepLorentzVector(GetCoordinate(m_xAxis, xBin, CLHEP::RandFlat::shoot(LRAEngine)),
160 GetCoordinate(m_yAxis, yBin, CLHEP::RandFlat::shoot(LRAEngine)),
161 GetCoordinate(m_zAxis, zBin, CLHEP::RandFlat::shoot(LRAEngine)),
162 0.0);
163
164 // ToDo: This uses only the TH3 PDF to position the vertex, this should be expanded to include:
165 // x/y/z translations.
166 // Slant angles.
167 // Euler angle/quaternion/something for arbiraty rotations (for non-factorisable PDFs)?
168
169 //---
170
171 return(vertexPosition);
172 };
static Double_t rz
const TAxis * m_zAxis
Non-owning TAxis * to the histograms z-Axis.
const TAxis * m_yAxis
Non-owning TAxis * to the histograms y-Axis.
std::vector< IntegralTuple > m_Integral
Vector to hold the running integral over bins.
const TAxis * m_xAxis
Non-owning TAxis * to the histograms x-Axis.
Axis
Helper type for histogram axis selection.

◆ initialize()

StatusCode Simulation::LRAVertexPositioner::initialize ( )
finaloverridevirtual

AthAlgTool initialization.

Definition at line 26 of file LRAVertexPositioner.cxx.

27 {
28 // Resolve the LRA file name.
29 const auto FilePath = PathResolverFindDataFile(m_FileName);
30 if(FilePath.empty())
31 {
32 ATH_MSG_ERROR("Unable to resolve LRAFile: m_FileName = " << (std::string)m_FileName);
33
34 return StatusCode::FAILURE;
35 };
36
37 // Open the file...
38 m_LRAFile = std::unique_ptr<TFile>(TFile::Open(FilePath.c_str(), "READ"));
39 if(!m_LRAFile)
40 {
41 ATH_MSG_ERROR("Unable to open LRAFile: FilePath = " << FilePath);
42
43 return StatusCode::FAILURE;
44 };
45
46 // ... and get the histogram.
47 // ToDo: We should re-evaluate holding open the TFile, compared to cloaning out the bits of interest.
48 // Requires access to a real LRA file.
49 m_LRAHist = m_LRAFile->Get<TH3F>(((std::string)m_HistName).c_str());
50 if(!m_LRAHist)
51 {
52 ATH_MSG_ERROR("Unable to get LRAHist: FilePath = " << FilePath << ", m_HistName = " << (std::string)m_HistName);
53
54 return StatusCode::FAILURE;
55 };
56
57 // ToDo: In the medium term we should look at cleaning up the Lumi groups code, adding whatever the
58 // BS group needs it to do, and getting that into Athena(_externals). The code above could then
59 // be changed to generate the TH3 dynamicaly (maybe simplyfing the configuration of all the tools),
60 // and the future vdM BSFinder could use the unbinned PDF.
61
62 //---
63
64 // Retrieve the tool handle to the RNG service...
65 ATH_CHECK(m_RNGService.retrieve());
66
67 // ... and get the RNG engine.
68 m_RNGEngine = m_RNGService->getEngine(this, m_RNGStream);
69 if (!m_RNGEngine)
70 {
71 ATH_MSG_ERROR("Unable to get RNGEngine: m_RNGStream = " << (std::string) m_RNGStream);
72
73 return StatusCode::FAILURE;
74 };
75
76 //---
77
78 // Cache the bin counts.
79 const auto nBinsX = m_LRAHist->GetNbinsX();
80 const auto nBinsY = m_LRAHist->GetNbinsY();
81 const auto nBinsZ = m_LRAHist->GetNbinsZ();
82
83 // Pre-allocate the space in the vector.
84 m_Integral.reserve(nBinsX * nBinsY * nBinsZ);
85
86 /*
87 Loop over the bins in the histogram, and store the bin numbers and the running integral into m_Integral.
88
89 Assumes the LRA histograms are "well-formed" PDFs:
90 Unit integral.
91 No probability in under/over-flow bins
92 No negative bins.
93
94 Is ugly, better would be ranges, iota * 3 -> cartesian_product -> for_each, but needs C++23 (No Stinking Loops!!!)
95 */
96 Double_t Integral = 0.0;
97 for(Int_t x = 1; x <= nBinsX; x++)
98 {
99 for(Int_t y = 1; y <= nBinsY; y++)
100 {
101 for(Int_t z = 1; z <= nBinsZ; z++)
102 {
103 Integral += m_LRAHist->GetBinContent(x, y, z);
104
105 m_Integral.emplace_back(std::forward_as_tuple(x, y, z, Integral));
106 };
107 };
108 };
109
110 // Cache the axes.
111 m_xAxis = m_LRAHist->GetXaxis();
112 m_yAxis = m_LRAHist->GetYaxis();
113 m_zAxis = m_LRAHist->GetZaxis();
114
115 //---
116
117 // Happy path...
118 return StatusCode::SUCCESS;
119 };
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
std::string PathResolverFindDataFile(const std::string &logical_file_name)
#define y
#define x
#define z
Gaudi::Property< std::string > m_RNGStream
Stream name for the RNG service.
ServiceHandle< IAthRNGSvc > m_RNGService
Handle to the Athena RNG service.
Gaudi::Property< std::string > m_FileName
LRA input file name.
const TH3F * m_LRAHist
Non-owning TH3F * to the LRA histogram.
Gaudi::Property< std::string > m_HistName
LRA input histogram name.
std::unique_ptr< TFile > m_LRAFile
Owning TFile * to the LRA file.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

ATHRNG::RNGWrapper* m_RNGEngine Simulation::LRAVertexPositioner::ATLAS_THREAD_SAFE {}
private

Non-owning RNGWrapper * to the RNG engine.

Definition at line 58 of file LRAVertexPositioner.h.

58{};

◆ m_FileName

Gaudi::Property<std::string> Simulation::LRAVertexPositioner::m_FileName {this, "FileName", "<<Unset>>", "LRA input file name."}
private

LRA input file name.

Definition at line 48 of file LRAVertexPositioner.h.

48{this, "FileName", "<<Unset>>", "LRA input file name."};

◆ m_HistName

Gaudi::Property<std::string> Simulation::LRAVertexPositioner::m_HistName {this, "HistName", "<<Unset>>", "LRA input histogram name."}
private

LRA input histogram name.

Definition at line 49 of file LRAVertexPositioner.h.

49{this, "HistName", "<<Unset>>", "LRA input histogram name."};

◆ m_Integral

std::vector<IntegralTuple> Simulation::LRAVertexPositioner::m_Integral
private

Vector to hold the running integral over bins.

Definition at line 63 of file LRAVertexPositioner.h.

◆ m_LRAFile

std::unique_ptr<TFile> Simulation::LRAVertexPositioner::m_LRAFile
private

Owning TFile * to the LRA file.

Definition at line 51 of file LRAVertexPositioner.h.

◆ m_LRAHist

const TH3F* Simulation::LRAVertexPositioner::m_LRAHist = nullptr
private

Non-owning TH3F * to the LRA histogram.

Definition at line 52 of file LRAVertexPositioner.h.

◆ m_RNGService

ServiceHandle<IAthRNGSvc> Simulation::LRAVertexPositioner::m_RNGService {this, "RNGService", "AthRNGSvc"}
private

Handle to the Athena RNG service.

Definition at line 56 of file LRAVertexPositioner.h.

56{this, "RNGService", "AthRNGSvc"};

◆ m_RNGStream

Gaudi::Property<std::string> Simulation::LRAVertexPositioner::m_RNGStream {this, "RNGStream", "LRAVertexPositioner", "Stream name for the RNG service."}
private

Stream name for the RNG service.

Definition at line 57 of file LRAVertexPositioner.h.

57{this, "RNGStream", "LRAVertexPositioner", "Stream name for the RNG service."};

◆ m_xAxis

const TAxis* Simulation::LRAVertexPositioner::m_xAxis = nullptr
private

Non-owning TAxis * to the histograms x-Axis.

Definition at line 65 of file LRAVertexPositioner.h.

◆ m_yAxis

const TAxis* Simulation::LRAVertexPositioner::m_yAxis = nullptr
private

Non-owning TAxis * to the histograms y-Axis.

Definition at line 66 of file LRAVertexPositioner.h.

◆ m_zAxis

const TAxis* Simulation::LRAVertexPositioner::m_zAxis = nullptr
private

Non-owning TAxis * to the histograms z-Axis.

Definition at line 67 of file LRAVertexPositioner.h.


The documentation for this class was generated from the following files: