ATLAS Offline Software
Loading...
Searching...
No Matches
MarsHaloGenerator Class Reference

A class to provide conversion from a MARS format ASCII input record into HepMC format, with or without sampling. More...

#include <MarsHaloGenerator.h>

Inheritance diagram for MarsHaloGenerator:
Collaboration diagram for MarsHaloGenerator:

Public Member Functions

 MarsHaloGenerator (const HepPDT::ParticleDataTable *particleTable, const std::string &inputFile, const std::vector< std::string > &generatorSettings)
virtual ~MarsHaloGenerator ()=default
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)
 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)
 A function to read one event in a simplified format.
virtual int readParticle (BeamHaloParticle *beamHaloParticle)
 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

const HepPDT::ParticleDataTable * m_particleTable
 A pointer to the particle data table.
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.
BeamHaloParticleBufferm_beamHaloParticleBuffer
 Binary particle buffer for caching converted events.
AsciiInputm_asciiInput
 A pointer to an AsciiInput object, used to read data from the Ascii input file.
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

A class to provide conversion from a MARS format ASCII input record into HepMC format, with or without sampling.

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

Definition at line 18 of file MarsHaloGenerator.h.

Member Enumeration Documentation

◆ enumCounters

enum BeamHaloGenerator::enumCounters
protectedinherited

An enum of particle counter indices.

Enumerator
TOT_READ 
TOT_AFTER 
TOT_GEN 
NUM_COUNTERS 

Definition at line 141 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 86 of file BeamHaloGenerator.h.

Constructor & Destructor Documentation

◆ MarsHaloGenerator()

MarsHaloGenerator::MarsHaloGenerator ( const HepPDT::ParticleDataTable * particleTable,
const std::string & inputFile,
const std::vector< std::string > & generatorSettings )

Definition at line 16 of file MarsHaloGenerator.cxx.

18 :
19 BeamHaloGenerator(particleTable, inputFile, generatorSettings) {
20}
BeamHaloGenerator(const HepPDT::ParticleDataTable *particleTable, const std::string &inputFile, const std::vector< std::string > &generatorSettings)

◆ ~MarsHaloGenerator()

virtual MarsHaloGenerator::~MarsHaloGenerator ( )
virtualdefault

Member Function Documentation

◆ convertEvent()

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

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

Definition at line 94 of file BeamHaloGenerator.cxx.

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

◆ fillEvt()

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

A function to create one event in HepMC format.

Implements BeamHaloGenerator.

Definition at line 71 of file MarsHaloGenerator.cxx.

72 {
73 std::vector<BeamHaloParticle> beamHaloEvent;
74 int ret_val;
75
76 // Read one MARS event which passes the generator settings.
77 if((ret_val = readEvent(&beamHaloEvent, engine)) != 0) return ret_val;
78
79 // Convert the particles to GenParticles and attach them to the
80 // event. Flip the event if needed.
81 if((ret_val = BeamHaloGenerator::convertEvent(&beamHaloEvent, evt, engine)) != 0) return ret_val;
82
83 // Set the event number
84 evt->set_event_number(m_eventNumber);
85
86 // Clear the values set by the base class convertEvent method
87 evt->weights().clear();
88
89 // Check if sampling has been enabled or not.
90 if(!m_enableSampling) {
92 evt->weights().push_back(beamHaloEvent[0].weight());
93 }
94 else {
96 evt->weights().push_back(1.0);
97 }
98
100
101 return 0;
102}
long m_eventNumber
A data member to count the event number.
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.
bool m_enableSampling
Flag to enable or disable sampling.
virtual int readEvent(std::vector< BeamHaloParticle > *beamHaloEvent, CLHEP::HepRandomEngine *engine)
A function to read one event in a simplified format.
void set_signal_process_id(GenEvent *e, const int i)
Definition GenEvent.h:643

◆ flipEvent()

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

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

Definition at line 80 of file BeamHaloGenerator.cxx.

80 {
81 if(!m_enableFlip) return false;
82
83 // Check to see if the event should be flipped or not
84 if(CLHEP::RandFlat::shoot(engine) <= m_flipProbability) {
85 if(m_debug) std::cout << "Debug: Flipping event" << std::endl;
86 return true;
87 }
88
89 return false;
90}
float m_flipProbability
Flip probability.
bool m_enableFlip
Flag for flipping event.
bool m_debug
A flat to turn on or off debug print out.

◆ genFinalize()

int MarsHaloGenerator::genFinalize ( )
virtual

A function to finalise the generator.

Reimplemented from BeamHaloGenerator.

Definition at line 106 of file MarsHaloGenerator.cxx.

106 {
107 int ret_val;
108
109 // Check if sampling has been enabled or not.
110 if(!m_enableSampling) {
111 m_asciiInput->close();
112 }
113 else {
115 }
116
117 // Finalise base class
118 if((ret_val = BeamHaloGenerator::genFinalize()) != 0) return ret_val;
119
120 return 0;
121}
BeamHaloParticleBuffer * m_beamHaloParticleBuffer
Binary particle buffer for caching converted events.
AsciiInput * m_asciiInput
A pointer to an AsciiInput object, used to read data from the Ascii input file.
virtual int genFinalize()
A function to finalise the generator.

◆ genInitialize()

int MarsHaloGenerator::genInitialize ( )
virtual

A function to initialise the generator.

Reimplemented from BeamHaloGenerator.

Definition at line 24 of file MarsHaloGenerator.cxx.

24 {
25 int ret_val;
26
27 // Initialise base class
28 if((ret_val = BeamHaloGenerator::genInitialize()) != 0) return ret_val;
29
30 if(m_asciiInput->open()) {
31 std::cout << "Error: Could not open ascii input file " << m_inputFile << std::endl;
32 return 1;
33 }
34
35 // Check if sampling is required if sampling is required leave
36 // the ASCII file open for the event loop.
37 if(!m_enableSampling) return 0;
38
39 m_beamHaloParticleBuffer = new BeamHaloParticleBuffer(m_bufferFileName);
40 if(m_beamHaloParticleBuffer->openForWriting()) {
41 std::cout << "Error: Could not open binary buffer file " << m_bufferFileName << " for writing." << std::endl;
42 return 1;
43 }
44
45 std::cout << "Info: Reading ascii input file " << m_inputFile << " into buffer" << std::endl;
46
47 // Loop over all lines in the text file.
48 BeamHaloParticle beamHaloParticle;
49 bool eof = false;
50 while(!eof) {
51 ret_val = readParticle(&beamHaloParticle);
52 if(ret_val < 0) { eof = true; continue; }
53 else if(ret_val > 0) { continue; }
54
55 // Write the BeamHaloParticle into the binary buffer.
56 if(m_beamHaloParticleBuffer->writeParticle(&beamHaloParticle)) {
57 std::cout << "Warning: writeParticle failed." << std::endl;
58 }
59 }
60
61 m_asciiInput->close();
63
64 m_beamHaloParticleBuffer->openForReading();
65
66 return 0;
67}
std::string m_inputFile
Input file name.
virtual int genInitialize()
A function to initialise the generator.
std::string m_bufferFileName
The name of the binary buffer file, needed for sampling from a converted file.
virtual int readParticle(BeamHaloParticle *beamHaloParticle)
A function to read one particle from the input ASCII file.

◆ readEvent()

int MarsHaloGenerator::readEvent ( std::vector< BeamHaloParticle > * beamHaloEvent,
CLHEP::HepRandomEngine * engine )
protectedvirtual

A function to read one event in a simplified format.

Implements BeamHaloGenerator.

Definition at line 163 of file MarsHaloGenerator.cxx.

164 {
165 BeamHaloParticle *beamHaloParticle;
166 int ret_val;
167
168 // Clear the event
169 beamHaloEvent->clear();
170
171 // Check if sampling is required
172 if(!m_enableSampling) {
173 beamHaloParticle = new BeamHaloParticle();
174 bool eof = false, gotParticle = false;
175 while(!eof && !gotParticle) {
176 ret_val = readParticle(beamHaloParticle);
177 if(ret_val < 0) { eof = true; }
178 else if(ret_val == 0) { gotParticle = true; }
179 }
180 }
181 else {
182 // Read one particle at random from the binary buffer. This uses
183 // the particle weights to produce a flat distribution rather than a
184 // weighted one, but may generate the same particle twice.
185 beamHaloParticle = m_beamHaloParticleBuffer->readRandomParticle(engine);
186 if(!beamHaloParticle) {
187 std::cout << "Error: readRandomParticle failed." << std::endl;
188 return 1;
189 }
190 }
191
192 // Increment generated particles information.
194 m_wsums[TOT_GEN]+= beamHaloParticle->weight();
195
196
197 // Copy the BeamHaloParticle into this event
198 beamHaloEvent->push_back(*beamHaloParticle);
199
200 // Delete the pointer to the generated particle.
201 delete beamHaloParticle;
202
203 return 0;
204}
double m_wsums[NUM_COUNTERS]
Sum of weights of particles or events of dimension enumCounters.
long m_counters[NUM_COUNTERS]
Particle or event counters of dimension enumCounters.
double weight() const
A function to return the weight of this particle within the input beam background simulation file.

◆ readParticle()

int MarsHaloGenerator::readParticle ( BeamHaloParticle * beamHaloParticle)
protectedvirtual

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

Implements BeamHaloGenerator.

Definition at line 125 of file MarsHaloGenerator.cxx.

125 {
126 std::vector<std::string> row;
127 MarsParticle marsParticle;
128
129 // Read one row of the ASCII file.
130 row = m_asciiInput->readRow();
131 if(row.size() == 0) return -1; // EOF
132
133 // Fill a MarsParticle with values from the string vector.
134 if(marsParticle.read(&row)) {
135 return 1;
136 }
137
138 // Fill the BeamHaloParticle with the data in the MarsParticle
139 if(beamHaloParticle->fill(m_particleTable, &marsParticle)) {
140 std::cout << "Warning: Conversion from MarsParticle to BeamHaloParticle failed." << std::endl;
141 return 1;
142 }
143
144 // Increment the particles read from file information.
146 m_wsums[TOT_READ]+= beamHaloParticle->weight();
147
148 // Check the generator settings. If this particle fails skip it.
149 if(!m_beamHaloGeneratorSettings->checkParticle(beamHaloParticle)) {
150 if(m_debug) std::cout << "Debug: Particle fails generator settings cuts." << std::endl;
151 return 1;
152 }
153
154 // Increment the particles after cuts information.
156 m_wsums[TOT_AFTER]+= beamHaloParticle->weight();
157
158 return 0;
159}
BeamHaloGeneratorSettings * m_beamHaloGeneratorSettings
A pointer to a BeamHaloGeneratorSettings object used to filter particles.
const HepPDT::ParticleDataTable * m_particleTable
A pointer to the particle data table.
int fill(const HepPDT::ParticleDataTable *particleDataTable, MarsParticle *marsParticle)
A function to fill the data members from an input MarsParticle object.
int read(std::vector< std::string > *eventAsStringVector)
A function to read the values from a single row definition and fill the data members.
row
Appending html table to final .html summary file.

◆ setBufferFileName()

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

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

Definition at line 76 of file BeamHaloGenerator.h.

76{ m_bufferFileName = bufferFileName; }

◆ setDebugEnable()

void BeamHaloGenerator::setDebugEnable ( bool debug)
inlineinherited

A function to turn on or off debug print out.

Definition at line 79 of file BeamHaloGenerator.h.

79{ m_debug = debug; }
const bool debug

◆ setEnableFlip()

void BeamHaloGenerator::setEnableFlip ( bool enableFlip)
inlineinherited

Turn on or off the event flipping code.

Definition at line 66 of file BeamHaloGenerator.h.

66{ m_enableFlip = enableFlip; }

◆ setEnableSampling()

void BeamHaloGenerator::setEnableSampling ( bool enableSampling)
inlineinherited

Turn on or off sampling from the input ASCII file.

Definition at line 72 of file BeamHaloGenerator.h.

72{ m_enableSampling = enableSampling; }

◆ setFlipProbability()

void BeamHaloGenerator::setFlipProbability ( float flipProbability)
inlineinherited

Set probability of flipping an event about Z=0.

Definition at line 69 of file BeamHaloGenerator.h.

◆ setInterfacePlane()

void BeamHaloGenerator::setInterfacePlane ( double interfacePlane)
inlineinherited

Set the position of the interface plane in mm.

Definition at line 63 of file BeamHaloGenerator.h.

Member Data Documentation

◆ m_asciiInput

AsciiInput* BeamHaloGenerator::m_asciiInput
protectedinherited

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

Definition at line 131 of file BeamHaloGenerator.h.

◆ m_beamHaloGeneratorSettings

BeamHaloGeneratorSettings* BeamHaloGenerator::m_beamHaloGeneratorSettings
protectedinherited

A pointer to a BeamHaloGeneratorSettings object used to filter particles.

Definition at line 135 of file BeamHaloGenerator.h.

◆ m_beamHaloParticleBuffer

BeamHaloParticleBuffer* BeamHaloGenerator::m_beamHaloParticleBuffer
protectedinherited

Binary particle buffer for caching converted events.

Definition at line 127 of file BeamHaloGenerator.h.

◆ m_bufferFileName

std::string BeamHaloGenerator::m_bufferFileName
protectedinherited

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

Definition at line 124 of file BeamHaloGenerator.h.

◆ m_counters

long BeamHaloGenerator::m_counters[NUM_COUNTERS]
protectedinherited

Particle or event counters of dimension enumCounters.

Definition at line 148 of file BeamHaloGenerator.h.

◆ m_debug

bool BeamHaloGenerator::m_debug
protectedinherited

A flat to turn on or off debug print out.

Definition at line 154 of file BeamHaloGenerator.h.

◆ m_enableFlip

bool BeamHaloGenerator::m_enableFlip
protectedinherited

Flag for flipping event.

Definition at line 114 of file BeamHaloGenerator.h.

◆ m_enableSampling

bool BeamHaloGenerator::m_enableSampling
protectedinherited

Flag to enable or disable sampling.

Definition at line 120 of file BeamHaloGenerator.h.

◆ m_eventNumber

long BeamHaloGenerator::m_eventNumber
protectedinherited

A data member to count the event number.

Definition at line 138 of file BeamHaloGenerator.h.

◆ m_flipProbability

float BeamHaloGenerator::m_flipProbability
protectedinherited

Flip probability.

Definition at line 117 of file BeamHaloGenerator.h.

◆ m_generatorSettings

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

A vector of generator settings in string command form.

Definition at line 159 of file BeamHaloGenerator.h.

◆ m_inputFile

std::string BeamHaloGenerator::m_inputFile
protectedinherited

Input file name.

Definition at line 108 of file BeamHaloGenerator.h.

◆ m_interfacePlane

double BeamHaloGenerator::m_interfacePlane
protectedinherited

The position of the interface plane in mm.

Definition at line 111 of file BeamHaloGenerator.h.

◆ m_particleTable

const HepPDT::ParticleDataTable* BeamHaloGenerator::m_particleTable
protectedinherited

A pointer to the particle data table.

Definition at line 105 of file BeamHaloGenerator.h.

◆ m_wsums

double BeamHaloGenerator::m_wsums[NUM_COUNTERS]
protectedinherited

Sum of weights of particles or events of dimension enumCounters.

Definition at line 151 of file BeamHaloGenerator.h.


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