BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSROOTSamplerReader.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSROOTSAMPLERREADER_H
20#define BDSROOTSAMPLERREADER_H
21
22#include "globals.hh"
23#include "G4RotationMatrix.hh"
24#include "G4ThreeVector.hh"
25#include "G4VPrimaryGenerator.hh"
26
27#include <vector>
28
31class G4Event;
32class G4PrimaryParticle;
33class G4PrimaryVertex;
34class G4VSolid;
35
42class BDSROOTSamplerReader: public G4VPrimaryGenerator
43{
44public:
51 BDSROOTSamplerReader(const G4String& distrType,
52 const G4String& fileNameIn,
54 G4bool removeUnstableWithoutDecayIn = true,
55 G4bool warnAboutSkippedParticlesIn = true);
56 virtual ~BDSROOTSamplerReader();
57
59 virtual void GeneratePrimaryVertex(G4Event* anEvent);
60
62 virtual void RecreateAdvanceToEvent(G4int eventOffset);
63
65 {
66 G4ThreeVector xyz;
67 G4PrimaryParticle* vertex;
68 };
69
70protected:
72 void ReadSingleEvent(G4long index);
73
75 //void HepMC2G4(const HepMC3::GenEvent* hepmcevt, G4Event* g4event);
76
77 // We have to take care for the position of primaries because
78 // primary vertices outside the world volume would give rise to a G4Exception.
79 virtual G4bool VertexInsideWorld(const G4ThreeVector& pos) const;
80
81 void ReadPrimaryParticlesFloat(G4long index);
82 void ReadPrimaryParticlesDouble(G4long index);
83
84private:
85 G4long currentFileEventIndex;
86 G4long nEventsInFile;
88 G4String fileName;
89 G4String samplerName;
91 G4bool removeUnstableWithoutDecay;
92 G4bool warnAboutSkippedParticles;
93 G4RotationMatrix referenceBeamMomentumOffset;
94 mutable G4VSolid* worldSolid;
95
100
102 std::vector<DisplacedVertex> vertices;
103
104 std::vector<G4PrimaryVertex*> currentVertices;
105};
106
107#endif
A wrapper of BDSBunch to include a filter for the events loaded by an event generator.
Loader of ROOT Event output for receating events.
Loader to read a specific sampler from a BDSIM ROOT output file.
virtual void GeneratePrimaryVertex(G4Event *anEvent)
Read the next non-empty sampler entry from the file.
virtual void RecreateAdvanceToEvent(G4int eventOffset)
Advance to the correct event number in the file for recreation.
std::vector< DisplacedVertex > vertices
Used for transiently loading information.
void ReadSingleEvent(G4long index)
Clear the hepmcEvent object, reallocate and read a single event and fill that member.
virtual G4bool VertexInsideWorld(const G4ThreeVector &pos) const
Conversion from HepMC::GenEvent to G4Event.
BDSROOTSamplerReader()=delete
Do not require default constructor.