BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSPrimaryGeneratorFile.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSPRIMARYGENERATORFILE_H
19#define BDSPRIMARYGENERATORFILE_H
20
21#include "G4ThreeVector.hh"
22#include "G4Types.hh"
23#include "G4VPrimaryGenerator.hh"
24
25class BDSBunch;
27class G4Event;
28class G4VSolid;
29
30namespace GMAD
31{
32 class Beam;
33}
34
48class BDSPrimaryGeneratorFile: public G4VPrimaryGenerator
49{
50public:
51 BDSPrimaryGeneratorFile() = delete;
52 BDSPrimaryGeneratorFile(G4bool loopFileIn,
53 BDSBunchEventGenerator* bunchIn);
55
59 BDSBunch* bunchIn,
60 G4bool recreate,
61 G4int eventOffset,
62 G4bool batchMode);
63
65 G4bool GeneratePrimaryVertexSafe(G4Event* event);
66
68 virtual void RecreateAdvanceToEvent(G4int eventOffset) = 0;
69
72 G4long NEventsInFile() const {return nEventsInFile;}
73
76 G4long NEventsLeftInFile() const;
77
80 G4bool OKToLoopFile() const;
81
84 void SetRecreationOn() {recreate = true;}
85
87 G4long NEventsReadThatPassedFilters() const {return nEventsReadThatPassedFilters;}
88
90 G4long NEventsSkipped() const {return nEventsSkipped;}
91
93 G4bool DistributionIsFinished() const {return endOfFileReached;}
94
98 void ThrowExceptionIfRecreateOffsetTooHigh(G4long eventOffset) const;
99
100protected:
102 G4bool VertexInsideWorld(const G4ThreeVector& pos) const;
103
104 G4bool loopFile;
106 G4bool recreate;
107 G4bool endOfFileReached;
108 G4bool vertexGeneratedSuccessfully;
109 G4long currentFileEventIndex;
110 G4long nEventsInFile;
111 G4long nEventsReadThatPassedFilters;
112 G4long nEventsSkipped;
113 mutable G4VSolid* worldSolid;
114};
115
116#endif
A wrapper of BDSBunch to include a filter for the events loaded by an event generator.
The base class for bunch distribution generators.
Definition BDSBunch.hh:46
Common interface for any primary generators that are file based.
G4long NEventsReadThatPassedFilters() const
Accessor.
G4bool DistributionIsFinished() const
Report whether the distribution is finished generating.
G4bool GeneratePrimaryVertexSafe(G4Event *event)
Return false if not able to generate a primary vertex.
void ThrowExceptionIfRecreateOffsetTooHigh(G4long eventOffset) const
G4bool VertexInsideWorld(const G4ThreeVector &pos) const
Utility function for derived classes to check a position is inside the world.
virtual void RecreateAdvanceToEvent(G4int eventOffset)=0
Advance into the file as required.
static BDSPrimaryGeneratorFile * ConstructGenerator(const GMAD::Beam &beam, BDSBunch *bunchIn, G4bool recreate, G4int eventOffset, G4bool batchMode)
G4long NEventsSkipped() const
Return the offset into the file if any.
Beam loader.
Definition Beam.hh:36
Beam class.
Definition beam.h:43
Parser namespace for GMAD language. Combination of Geant4 and MAD.