remage
Simulation framework for HPGe-based experiments
 
Loading...
Searching...
No Matches
RMGGeneratorGPS.hh
1// Copyright (C) 2022 Luigi Pertoldi <https://orcid.org/0000-0002-0467-2571>
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_GPS_HH_
17#define _RMG_GENERATOR_GPS_HH_
18
19#include <memory>
20
21#include "G4AutoLock.hh"
22#include "G4GeneralParticleSource.hh"
23#include "G4ThreeVector.hh"
24
25#include "RMGVGenerator.hh"
26
27class G4Event;
36class RMGGeneratorGPS : public RMGVGenerator {
37
38 public:
39
40 RMGGeneratorGPS() : RMGVGenerator("GPS") {
41 fParticleSource = std::make_unique<G4GeneralParticleSource>();
42 }
43
44 ~RMGGeneratorGPS() = default;
45
47 void GeneratePrimaries(G4Event* event) override {
48 G4AutoLock lock(&fMutex);
49
50 // the GPS is inherently thread-unsafe. only one source can be manipulated/used at a time.
51 // all threads share the same internal global state.
52 if (fVertexPositionSet) {
53 auto n_source = fParticleSource->GetNumberofSource();
54 for (auto i = 0; i < n_source; i++) {
55 fParticleSource->SetCurrentSourceto(i);
56 fParticleSource->GetCurrentSource()->GetPosDist()->SetCentreCoords(fVertexPosition);
57 }
58 }
59 fParticleSource->GeneratePrimaryVertex(event);
60 }
61
63 void SetParticlePosition(G4ThreeVector vec) override {
64 fVertexPosition = vec;
65 fVertexPositionSet = true;
66 }
67
68 private:
69
70 inline static G4Mutex fMutex = G4MUTEX_INITIALIZER;
71
72 bool fVertexPositionSet = false;
73 G4ThreeVector fVertexPosition;
74
75 std::unique_ptr<G4GeneralParticleSource> fParticleSource = nullptr;
76};
77
78#endif
79
80// vim: tabstop=2 shiftwidth=2 expandtab
void SetParticlePosition(G4ThreeVector vec) override
Override the centre coordinates of every GPS source for the next primary vertex.
Definition RMGGeneratorGPS.hh:63
void GeneratePrimaries(G4Event *event) override
Generate a primary vertex from the GPS, optionally overriding the vertex position.
Definition RMGGeneratorGPS.hh:47