remage
Simulation framework for HPGe-based experiments
Toggle main menu visibility
Loading...
Searching...
No Matches
RMGGeneratorFromFile.hh
1
// Copyright (C) 2024 Manuel Huber <https://orcid.org/0009-0000-5212-2999>
2
//
3
// This program is free software: you can redistribute it and/or modify it under
4
// the terms of the GNU Lesser General Public License as published by the Free
5
// Software Foundation, either version 3 of the License, or (at your option) any
6
// later version.
7
//
8
// This program is distributed in the hope that it will be useful, but WITHOUT
9
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11
// details.
12
//
13
// You should have received a copy of the GNU Lesser General Public License
14
// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16
#ifndef _RMG_GENERATOR_FROM_FILE_HH_
17
#define _RMG_GENERATOR_FROM_FILE_HH_
18
19
#include <memory>
20
21
#include "CLHEP/Units/SystemOfUnits.h"
22
#include "G4GenericMessenger.hh"
23
#include "G4ParticleGun.hh"
24
25
#include "RMGAnalysisReader.hh"
26
#include "RMGVGenerator.hh"
27
28
namespace
u
=
CLHEP
;
29
30
class
G4Event
;
40
class
RMGGeneratorFromFile :
public
RMGVGenerator {
41
42
public
:
43
44
RMGGeneratorFromFile();
45
~RMGGeneratorFromFile() =
default
;
46
47
RMGGeneratorFromFile(RMGGeneratorFromFile
const
&) =
delete
;
48
RMGGeneratorFromFile& operator=(RMGGeneratorFromFile
const
&) =
delete
;
49
RMGGeneratorFromFile(RMGGeneratorFromFile&&) =
delete
;
50
RMGGeneratorFromFile& operator=(RMGGeneratorFromFile&&) =
delete
;
51
53
void
GeneratePrimaries
(
G4Event
*)
override
;
55
void
SetParticlePosition
(G4ThreeVector pos)
override
{ fParticlePosition = pos; }
56
58
void
BeginOfRunAction
(
const
G4Run
*)
override
;
60
void
EndOfRunAction
(
const
G4Run
*)
override
;
61
63
void
OpenFile
(std::string& name);
64
65
private
:
66
67
struct
RowData {
68
int
fG4Pid = -1;
69
double
fEkin = NAN;
70
double
fPx = NAN;
71
double
fPy = NAN;
72
double
fPz = NAN;
73
double
fTime = NAN;
74
int
fNpart = -1;
75
double
fXpos = NAN;
76
double
fYpos = NAN;
77
double
fZpos = NAN;
78
RowData() {};
// NOLINT(modernize-use-equals-default)
79
80
[[nodiscard]]
bool
IsValid(
bool
include_pos)
const
{
81
bool
kin_valid = fG4Pid != -1 && !std::isnan(fEkin) && !std::isnan(fPx) &&
82
!std::isnan(fPy) && !std::isnan(fPz) && !std::isnan(fTime) &&
83
fNpart != -1;
84
bool
pos_valid = !include_pos ||
85
(!std::isnan(fXpos) && !std::isnan(fYpos) && !std::isnan(fZpos));
86
return
kin_valid && pos_valid;
87
}
88
};
89
90
static
RMGAnalysisReader* fReader;
91
inline
static
RowData fRowData{};
92
93
bool
fIncludePosition =
false
;
94
95
std::unique_ptr<G4GenericMessenger> fMessenger =
nullptr
;
96
void
DefineCommands();
97
98
std::string fNtupleDirectoryName =
"vtx"
;
99
100
std::unique_ptr<G4ParticleGun> fGun =
nullptr
;
101
102
G4ThreeVector fParticlePosition;
103
};
104
105
#endif
106
107
// vim: tabstop=2 shiftwidth=2 expandtab
CLHEP
G4Event
G4Run
RMGGeneratorFromFile::OpenFile
void OpenFile(std::string &name)
Set the path of the input ntuple file.
Definition
RMGGeneratorFromFile.cc:38
RMGGeneratorFromFile::BeginOfRunAction
void BeginOfRunAction(const G4Run *) override
Open the input file and bind the row reader to the configured ntuple columns.
Definition
RMGGeneratorFromFile.cc:76
RMGGeneratorFromFile::SetParticlePosition
void SetParticlePosition(G4ThreeVector pos) override
Set the vertex position for the next call to GeneratePrimaries.
Definition
RMGGeneratorFromFile.hh:55
RMGGeneratorFromFile::EndOfRunAction
void EndOfRunAction(const G4Run *) override
Close the input file.
Definition
RMGGeneratorFromFile.cc:119
RMGGeneratorFromFile::GeneratePrimaries
void GeneratePrimaries(G4Event *) override
Read the next row(s) from the input ntuple and create the primary vertex.
Definition
RMGGeneratorFromFile.cc:127
include
RMGGeneratorFromFile.hh
Generated by
1.17.0