BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSPrimaryGeneratorFileHEPMC.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#ifdef USE_HEPMC3
19
20#ifndef BDSPRIMARYGENERATORHEPMC_H
21#define BDSPRIMARYGENERATORHEPMC_H
22
23#include "BDSEventGeneratorFileType.hh"
24#include "BDSPrimaryGeneratorFile.hh"
25
26#include "globals.hh"
27#include "G4RotationMatrix.hh"
28#include "G4ThreeVector.hh"
29#include "G4VPrimaryGenerator.hh"
30
32class G4Event;
33
34namespace HepMC3
35{
36 class GenEvent;
37 class Reader;
38}
39
55{
56public:
63 BDSPrimaryGeneratorFileHEPMC(const G4String& distrType,
64 const G4String& fileNameIn,
66 G4bool loopFileIn,
67 G4bool removeUnstableWithoutDecayIn = true,
68 G4bool warnAboutSkippedParticlesIn = true);
70
72 inline HepMC3::GenEvent* GetHepMCGenEvent() const {return hepmcEvent;}
73
79 virtual void GeneratePrimaryVertex(G4Event* anEvent);
80
82 virtual void RecreateAdvanceToEvent(G4int eventOffset);
83
84protected:
86 void OpenFile(G4bool usualPrintOut = true);
87
90 void CloseFile();
91
94 G4long CountEventsInFile();
95
98 G4bool ReadSingleEvent();
99
102 void SkipEvents(G4int nEventsToSkip);
103
105 void HepMC2G4(const HepMC3::GenEvent* hepmcevt, G4Event* g4event);
106
107 // Note that the life of HepMC event object must be handled by users.
108 // In the default implementation, a current HepMC event will be
109 // deleted at GeneratePrimaryVertex() in the next event.
110 HepMC3::GenEvent* hepmcEvent; // (care for single event case only)
111
112private:
113 HepMC3::Reader* reader;
114 G4String fileName;
115 G4bool removeUnstableWithoutDecay;
116 G4bool warnAboutSkippedParticles;
118 G4RotationMatrix referenceBeamMomentumOffset;
119};
120
121#endif
122#endif
A wrapper of BDSBunch to include a filter for the events loaded by an event generator.
Loader to use any HepMC3 compatible file.
virtual void RecreateAdvanceToEvent(G4int eventOffset)
Advance to the correct event number in the file for recreation.
BDSPrimaryGeneratorFileHEPMC()=delete
Do not require default constructor.
HepMC3::GenEvent * GetHepMCGenEvent() const
Accessor.
virtual void GeneratePrimaryVertex(G4Event *anEvent)
void HepMC2G4(const HepMC3::GenEvent *hepmcevt, G4Event *g4event)
Conversion from HepMC::GenEvent to G4Event.
void OpenFile(G4bool usualPrintOut=true)
Construct the member "reader" and open the file for reading.
Common interface for any primary generators that are file based.