ATLAS Offline Software
Loading...
Searching...
No Matches
BeamHaloGenerator Class Referenceabstract

An abstract base class to provide generic beam halo generator functionality. More...

#include <BeamHaloGenerator.h>

Inheritance diagram for BeamHaloGenerator:
Collaboration diagram for BeamHaloGenerator:

Public Member Functions

 BeamHaloGenerator (const std::string &inputFile, const std::vector< std::string > &generatorSettings)
virtual ~BeamHaloGenerator ()
virtual int genInitialize ()
 A function to initialise the generator.
virtual int genFinalize ()
 A function to finalise the generator.
virtual int fillEvt (HepMC::GenEvent *evt, CLHEP::HepRandomEngine *engine)=0
 A function to create one event in HepMC format.
void setInterfacePlane (double interfacePlane)
 Set the position of the interface plane in mm.
void setEnableFlip (bool enableFlip)
 Turn on or off the event flipping code.
void setFlipProbability (float flipProbability)
 Set probability of flipping an event about Z=0.
void setEnableSampling (bool enableSampling)
 Turn on or off sampling from the input ASCII file.
void setBufferFileName (const std::string &bufferFileName)
 Set the name of the binary buffer file, needed for sampling from a converted file.
void setDebugEnable (bool debug)
 A function to turn on or off debug print out.

Protected Types

enum  enumGeneratorProcessIds {
  MARS_READ , MARS_SINGLE , MARS_SHOWER , FLUKA_READ ,
  FLUKA_SINGLE , FLUKA_SHOWER
}
 An enum of generator process identifiers. More...
enum  enumCounters { TOT_READ , TOT_AFTER , TOT_GEN , NUM_COUNTERS }
 An enum of particle counter indices. More...

Protected Member Functions

virtual int readEvent (std::vector< BeamHaloParticle > *beamHaloEvent, CLHEP::HepRandomEngine *engine)=0
 A function to read one event in a simplified format.
virtual int readParticle (BeamHaloParticle *beamHaloParticle)=0
 A function to read one particle from the input ASCII file.
bool flipEvent (CLHEP::HepRandomEngine *engine)
 A member function to check if the event should be flipped.
int convertEvent (std::vector< BeamHaloParticle > *beamHaloEvent, HepMC::GenEvent *evt, CLHEP::HepRandomEngine *engine)
 A member function to convert a vector of beam halo particles into a GenEvent.

Protected Attributes

std::shared_ptr< GenDatam_gendata
 A shared pointer to the GenData helper object.
std::string m_inputFile
 Input file name.
double m_interfacePlane
 The position of the interface plane in mm.
bool m_enableFlip
 Flag for flipping event.
float m_flipProbability
 Flip probability.
bool m_enableSampling
 Flag to enable or disable sampling.
std::string m_bufferFileName
 The name of the binary buffer file, needed for sampling from a converted file.
std::unique_ptr< BeamHaloParticleBufferm_beamHaloParticleBuffer
 Binary particle buffer for caching converted events.
std::unique_ptr< AsciiInputm_asciiInput
 A pointer to an AsciiInput object, used to read data from the Ascii input file.
std::unique_ptr< BeamHaloGeneratorSettingsm_beamHaloGeneratorSettings
 A pointer to a BeamHaloGeneratorSettings object used to filter particles.
long m_eventNumber
 A data member to count the event number.
long m_counters [NUM_COUNTERS]
 Particle or event counters of dimension enumCounters.
double m_wsums [NUM_COUNTERS]
 Sum of weights of particles or events of dimension enumCounters.
bool m_debug
 A flat to turn on or off debug print out.

Private Attributes

std::vector< std::string > m_generatorSettings
 A vector of generator settings in string command form.

Detailed Description

An abstract base class to provide generic beam halo generator functionality.

Author
W. H. Bell W.Bel.nosp@m.l@ce.nosp@m.rn.ch

Definition at line 30 of file BeamHaloGenerator.h.

Member Enumeration Documentation

◆ enumCounters

An enum of particle counter indices.

Enumerator
TOT_READ 
TOT_AFTER 
TOT_GEN 
NUM_COUNTERS 

Definition at line 140 of file BeamHaloGenerator.h.

◆ enumGeneratorProcessIds

An enum of generator process identifiers.

_READ corresponds to no sampling and therefore simple conversion from input file to HepMC record.

Enumerator
MARS_READ 
MARS_SINGLE 
MARS_SHOWER 
FLUKA_READ 
FLUKA_SINGLE 
FLUKA_SHOWER 

Definition at line 85 of file BeamHaloGenerator.h.

Constructor & Destructor Documentation

◆ BeamHaloGenerator()

BeamHaloGenerator::BeamHaloGenerator ( const std::string & inputFile,
const std::vector< std::string > & generatorSettings )

Definition at line 17 of file BeamHaloGenerator.cxx.

19 :
20 m_gendata(std::make_shared<GenData>()),
21 m_inputFile(inputFile),
23 m_enableFlip(false),
25 m_enableSampling(false),
26 m_bufferFileName("buffer.bin"),
28 m_debug(false),
29 m_generatorSettings(generatorSettings) {
30 for(int i=0;i<NUM_COUNTERS;i++) {
31 m_counters[i] = 0;
32 m_wsums[i] = 0.;
33 }
34}
long m_eventNumber
A data member to count the event number.
double m_wsums[NUM_COUNTERS]
Sum of weights of particles or events of dimension enumCounters.
float m_flipProbability
Flip probability.
std::string m_inputFile
Input file name.
bool m_enableFlip
Flag for flipping event.
long m_counters[NUM_COUNTERS]
Particle or event counters of dimension enumCounters.
std::vector< std::string > m_generatorSettings
A vector of generator settings in string command form.
bool m_debug
A flat to turn on or off debug print out.
bool m_enableSampling
Flag to enable or disable sampling.
double m_interfacePlane
The position of the interface plane in mm.
std::string m_bufferFileName
The name of the binary buffer file, needed for sampling from a converted file.
std::shared_ptr< GenData > m_gendata
A shared pointer to the GenData helper object.

◆ ~BeamHaloGenerator()

BeamHaloGenerator::~BeamHaloGenerator ( )
virtual

Definition at line 38 of file BeamHaloGenerator.cxx.

38 {
39}

Member Function Documentation

◆ convertEvent()

int BeamHaloGenerator::convertEvent ( std::vector< BeamHaloParticle > * beamHaloEvent,
HepMC::GenEvent * evt,
CLHEP::HepRandomEngine * engine )
protected

A member function to convert a vector of beam halo particles into a GenEvent.

Definition at line 89 of file BeamHaloGenerator.cxx.

91 {
92 double pz;
93 bool flipFlag = flipEvent(engine);
94 HepMC::GenParticlePtr genParticle;
95 HepMC::GenVertexPtr genVertex;
96 const double c = 2.99792458E+11; // speed of light in mm/s
97
98 std::vector<BeamHaloParticle>::iterator itr = beamHaloEvent->begin();
99 std::vector<BeamHaloParticle>::iterator itr_end = beamHaloEvent->end();
100
101 if(itr != itr_end) {
102 // Take the primary information from the first particle in the event. If the event is more than one
103 // particle, the particles come from the same primary proton.
104 evt->weights().push_back((*itr).weight()); // event weight
105 HepMC::FourVector primaryPosition = (*itr).positionAtPrimary();
106 evt->weights().push_back(primaryPosition.x()); // Starting position of primary particle: x position (cm)
107 evt->weights().push_back(primaryPosition.y()); // Starting position of primary particle: y position (cm)
108 evt->weights().push_back(primaryPosition.z()); // Starting position of primary particle: z position (cm)
109 evt->weights().push_back(primaryPosition.t()); // Starting position of primary particle: t (s)
110 }
111
112 // Append each particle to the GenEvent
113 for(;itr!=itr_end;++itr) {
114 HepMC::FourVector position = (*itr).positionAtScoringPlane();
115 HepMC::FourVector fourVector = (*itr).fourVector();
116
117 if(!flipFlag) {
118 genParticle = HepMC::newGenParticlePtr(fourVector,
119 (*itr).pdgId(),
120 1);
121
123 position.y(),
125 c*position.t() -1.0*std::fabs(m_interfacePlane)),
126 1);
127 }
128 else {
129 pz = fourVector.pz();
130 fourVector.setPz(-pz);
131
132 genParticle = HepMC::newGenParticlePtr(fourVector,
133 (*itr).pdgId(),
134 1);
135
137 position.y(),
138 -1.0*(position.z() + m_interfacePlane),
139 c*position.t() -1.0*std::fabs(m_interfacePlane)),
140 1);
141 }
142
143 genVertex->add_particle_out(genParticle);
144 evt->add_vertex(genVertex);
145 }
146
147 return 0;
148}
bool flipEvent(CLHEP::HepRandomEngine *engine)
A member function to check if the event should be flipped.
HepMC3::FourVector FourVector
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition GenParticle.h:21
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition GenVertex.h:25
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.

◆ fillEvt()

virtual int BeamHaloGenerator::fillEvt ( HepMC::GenEvent * evt,
CLHEP::HepRandomEngine * engine )
pure virtual

A function to create one event in HepMC format.

Implemented in FlukaHaloGenerator, and MarsHaloGenerator.

◆ flipEvent()

bool BeamHaloGenerator::flipEvent ( CLHEP::HepRandomEngine * engine)
protected

A member function to check if the event should be flipped.

Definition at line 75 of file BeamHaloGenerator.cxx.

75 {
76 if(!m_enableFlip) return false;
77
78 // Check to see if the event should be flipped or not
79 if(CLHEP::RandFlat::shoot(engine) <= m_flipProbability) {
80 if(m_debug) std::cout << "Debug: Flipping event" << std::endl;
81 return true;
82 }
83
84 return false;
85}

◆ genFinalize()

int BeamHaloGenerator::genFinalize ( )
virtual

A function to finalise the generator.

Reimplemented in FlukaHaloGenerator, and MarsHaloGenerator.

Definition at line 52 of file BeamHaloGenerator.cxx.

52 {
53
54 std::cout << "=================================================================" << std::endl;
55 std::cout << "| | Total Number | Total Weight |" << std::endl;
56 std::cout << "|---------------------------------------------------------------|" << std::endl;
57 std::cout << "| Particles read from input file | ";
58 std::cout << std::setw(12) << m_counters[TOT_READ] << " | ";
59 std::cout << std::setw(12) << std::setprecision(8) << m_wsums[TOT_READ] << " |" << std::endl;
60 std::cout << "| Particles after cuts | ";
61 std::cout << std::setw(12) << m_counters[TOT_AFTER] << " | ";
62 std::cout << std::setw(12) << std::setprecision(8) << m_wsums[TOT_AFTER] << " |" << std::endl;
63 std::cout << "| Particles generated | ";
64 std::cout << std::setw(12) << m_counters[TOT_GEN] << " | ";
65 std::cout << std::setw(12) << std::setprecision(8) << m_wsums[TOT_GEN] << " |" << std::endl;
66 std::cout << "=================================================================" << std::endl;
67
68 std::cout << std::setprecision(6);
69
70 return 0;
71}

◆ genInitialize()

int BeamHaloGenerator::genInitialize ( )
virtual

A function to initialise the generator.

Reimplemented in FlukaHaloGenerator, and MarsHaloGenerator.

Definition at line 43 of file BeamHaloGenerator.cxx.

43 {
44 m_asciiInput = std::make_unique<AsciiInput>(m_inputFile);
45 m_beamHaloGeneratorSettings = std::make_unique< BeamHaloGeneratorSettings>(m_generatorSettings);
46
47 return 0;
48}
std::unique_ptr< AsciiInput > m_asciiInput
A pointer to an AsciiInput object, used to read data from the Ascii input file.
std::unique_ptr< BeamHaloGeneratorSettings > m_beamHaloGeneratorSettings
A pointer to a BeamHaloGeneratorSettings object used to filter particles.

◆ readEvent()

virtual int BeamHaloGenerator::readEvent ( std::vector< BeamHaloParticle > * beamHaloEvent,
CLHEP::HepRandomEngine * engine )
protectedpure virtual

A function to read one event in a simplified format.

Implemented in FlukaHaloGenerator, and MarsHaloGenerator.

◆ readParticle()

virtual int BeamHaloGenerator::readParticle ( BeamHaloParticle * beamHaloParticle)
protectedpure virtual

A function to read one particle from the input ASCII file.

Implemented in FlukaHaloGenerator, and MarsHaloGenerator.

◆ setBufferFileName()

void BeamHaloGenerator::setBufferFileName ( const std::string & bufferFileName)
inline

Set the name of the binary buffer file, needed for sampling from a converted file.

Definition at line 75 of file BeamHaloGenerator.h.

75{ m_bufferFileName = bufferFileName; }

◆ setDebugEnable()

void BeamHaloGenerator::setDebugEnable ( bool debug)
inline

A function to turn on or off debug print out.

Definition at line 78 of file BeamHaloGenerator.h.

78{ m_debug = debug; }
const bool debug

◆ setEnableFlip()

void BeamHaloGenerator::setEnableFlip ( bool enableFlip)
inline

Turn on or off the event flipping code.

Definition at line 65 of file BeamHaloGenerator.h.

65{ m_enableFlip = enableFlip; }

◆ setEnableSampling()

void BeamHaloGenerator::setEnableSampling ( bool enableSampling)
inline

Turn on or off sampling from the input ASCII file.

Definition at line 71 of file BeamHaloGenerator.h.

71{ m_enableSampling = enableSampling; }

◆ setFlipProbability()

void BeamHaloGenerator::setFlipProbability ( float flipProbability)
inline

Set probability of flipping an event about Z=0.

Definition at line 68 of file BeamHaloGenerator.h.

68{ m_flipProbability = flipProbability; }

◆ setInterfacePlane()

void BeamHaloGenerator::setInterfacePlane ( double interfacePlane)
inline

Set the position of the interface plane in mm.

Definition at line 62 of file BeamHaloGenerator.h.

62{ m_interfacePlane = interfacePlane; }

Member Data Documentation

◆ m_asciiInput

std::unique_ptr<AsciiInput> BeamHaloGenerator::m_asciiInput
protected

A pointer to an AsciiInput object, used to read data from the Ascii input file.

Definition at line 130 of file BeamHaloGenerator.h.

◆ m_beamHaloGeneratorSettings

std::unique_ptr<BeamHaloGeneratorSettings> BeamHaloGenerator::m_beamHaloGeneratorSettings
protected

A pointer to a BeamHaloGeneratorSettings object used to filter particles.

Definition at line 134 of file BeamHaloGenerator.h.

◆ m_beamHaloParticleBuffer

std::unique_ptr<BeamHaloParticleBuffer> BeamHaloGenerator::m_beamHaloParticleBuffer
protected

Binary particle buffer for caching converted events.

Definition at line 126 of file BeamHaloGenerator.h.

◆ m_bufferFileName

std::string BeamHaloGenerator::m_bufferFileName
protected

The name of the binary buffer file, needed for sampling from a converted file.

Definition at line 123 of file BeamHaloGenerator.h.

◆ m_counters

long BeamHaloGenerator::m_counters[NUM_COUNTERS]
protected

Particle or event counters of dimension enumCounters.

Definition at line 147 of file BeamHaloGenerator.h.

◆ m_debug

bool BeamHaloGenerator::m_debug
protected

A flat to turn on or off debug print out.

Definition at line 153 of file BeamHaloGenerator.h.

◆ m_enableFlip

bool BeamHaloGenerator::m_enableFlip
protected

Flag for flipping event.

Definition at line 113 of file BeamHaloGenerator.h.

◆ m_enableSampling

bool BeamHaloGenerator::m_enableSampling
protected

Flag to enable or disable sampling.

Definition at line 119 of file BeamHaloGenerator.h.

◆ m_eventNumber

long BeamHaloGenerator::m_eventNumber
protected

A data member to count the event number.

Definition at line 137 of file BeamHaloGenerator.h.

◆ m_flipProbability

float BeamHaloGenerator::m_flipProbability
protected

Flip probability.

Definition at line 116 of file BeamHaloGenerator.h.

◆ m_gendata

std::shared_ptr<GenData> BeamHaloGenerator::m_gendata
protected

A shared pointer to the GenData helper object.

Definition at line 104 of file BeamHaloGenerator.h.

◆ m_generatorSettings

std::vector<std::string> BeamHaloGenerator::m_generatorSettings
private

A vector of generator settings in string command form.

Definition at line 158 of file BeamHaloGenerator.h.

◆ m_inputFile

std::string BeamHaloGenerator::m_inputFile
protected

Input file name.

Definition at line 107 of file BeamHaloGenerator.h.

◆ m_interfacePlane

double BeamHaloGenerator::m_interfacePlane
protected

The position of the interface plane in mm.

Definition at line 110 of file BeamHaloGenerator.h.

◆ m_wsums

double BeamHaloGenerator::m_wsums[NUM_COUNTERS]
protected

Sum of weights of particles or events of dimension enumCounters.

Definition at line 150 of file BeamHaloGenerator.h.


The documentation for this class was generated from the following files: