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) Royal Holloway,
3University of London 2001 - 2023.
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#ifdef USE_HEPMC3
20
21#ifndef BDSPRIMARYGENERATORHEPMC_H
22#define BDSPRIMARYGENERATORHEPMC_H
23
24#include "BDSEventGeneratorFileType.hh"
25#include "BDSPrimaryGeneratorFile.hh"
26
27#include "globals.hh"
28#include "G4RotationMatrix.hh"
29#include "G4ThreeVector.hh"
30#include "G4VPrimaryGenerator.hh"
31
33class G4Event;
34
35namespace HepMC3
36{
37 class GenEvent;
38 class Reader;
39}
40
56{
57public:
64 BDSPrimaryGeneratorFileHEPMC(const G4String& distrType,
65 const G4String& fileNameIn,
67 G4bool loopFileIn,
68 G4bool removeUnstableWithoutDecayIn = true,
69 G4bool warnAboutSkippedParticlesIn = true);
71
73 inline HepMC3::GenEvent* GetHepMCGenEvent() const {return hepmcEvent;}
74
80 virtual void GeneratePrimaryVertex(G4Event* anEvent);
81
83 virtual void RecreateAdvanceToEvent(G4int eventOffset);
84
85protected:
87 void OpenFile(G4bool usualPrintOut = true);
88
91 void CloseFile();
92
95 G4long CountEventsInFile();
96
99 G4bool ReadSingleEvent();
100
103 void SkipEvents(G4int nEventsToSkip);
104
106 void HepMC2G4(const HepMC3::GenEvent* hepmcevt, G4Event* g4event);
107
108 // Note that the life of HepMC event object must be handled by users.
109 // In the default implementation, a current HepMC event will be
110 // deleted at GeneratePrimaryVertex() in the next event.
111 HepMC3::GenEvent* hepmcEvent; // (care for single event case only)
112
113private:
114 HepMC3::Reader* reader;
115 G4String fileName;
116 G4bool removeUnstableWithoutDecay;
117 G4bool warnAboutSkippedParticles;
119 G4RotationMatrix referenceBeamMomentumOffset;
120};
121
122#endif
123#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.