remage
Simulation framework for HPGe-based experiments
 
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
28namespace u = CLHEP;
29
30class G4Event;
40class 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 RowData() {}; // NOLINT(modernize-use-equals-default)
76
77 [[nodiscard]] bool IsValid() const {
78 return fG4Pid != -1 && !std::isnan(fEkin) && !std::isnan(fPx) && !std::isnan(fPy) &&
79 !std::isnan(fPz) && !std::isnan(fTime) && fNpart != -1;
80 }
81 };
82
83 static RMGAnalysisReader* fReader;
84 inline static RowData fRowData{};
85
86 std::unique_ptr<G4GenericMessenger> fMessenger = nullptr;
87 void DefineCommands();
88
89 std::string fNtupleDirectoryName = "vtx";
90
91 std::unique_ptr<G4ParticleGun> fGun = nullptr;
92
93 G4ThreeVector fParticlePosition;
94};
95
96#endif
97
98// vim: tabstop=2 shiftwidth=2 expandtab
void OpenFile(std::string &name)
Set the path of the input ntuple file.
Definition RMGGeneratorFromFile.cc:38
void BeginOfRunAction(const G4Run *) override
Open the input file and bind the row reader to the configured ntuple columns.
Definition RMGGeneratorFromFile.cc:56
void SetParticlePosition(G4ThreeVector pos) override
Set the vertex position for the next call to GeneratePrimaries.
Definition RMGGeneratorFromFile.hh:55
void EndOfRunAction(const G4Run *) override
Close the input file.
Definition RMGGeneratorFromFile.cc:99
void GeneratePrimaries(G4Event *) override
Read the next row(s) from the input ntuple and create the primary vertex.
Definition RMGGeneratorFromFile.cc:107