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

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

#include <FlukaHaloGenerator.h>

Inheritance diagram for FlukaHaloGenerator:
Collaboration diagram for FlukaHaloGenerator:

Public Member Functions

 FlukaHaloGenerator (int type, const std::string &inputFile, const std::vector< std::string > &generatorSettings)
virtual ~FlukaHaloGenerator ()=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

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

bool m_sameEvent
bool m_firstEvent
FlukaParticle m_flukaParticle
FlukaParticle m_lastFlukaParticle
std::vector< std::string > m_generatorSettings
 A vector of generator settings in string command form.

Detailed Description

A class to provide conversion from a FLUKA 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 FlukaHaloGenerator.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 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

◆ FlukaHaloGenerator()

FlukaHaloGenerator::FlukaHaloGenerator ( int type,
const std::string & inputFile,
const std::vector< std::string > & generatorSettings )

Definition at line 15 of file FlukaHaloGenerator.cxx.

17 :
18 BeamHaloGenerator(inputFile, generatorSettings),
19 m_sameEvent(true),
20 m_firstEvent(true),
21 m_flukaParticle(type),
23}
BeamHaloGenerator(const std::string &inputFile, const std::vector< std::string > &generatorSettings)
FlukaParticle m_lastFlukaParticle
FlukaParticle m_flukaParticle

◆ ~FlukaHaloGenerator()

virtual FlukaHaloGenerator::~FlukaHaloGenerator ( )
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 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}
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.
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()

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

A function to create one event in HepMC format.

Implements BeamHaloGenerator.

Definition at line 47 of file FlukaHaloGenerator.cxx.

48 {
49 std::vector<BeamHaloParticle> beamHaloEvent;
50 int ret_val;
51
52 // Read one FLUKA event which passes the generator settings.
53 if((ret_val = readEvent(&beamHaloEvent, engine)) != 0) return ret_val;
54
55 // Convert the particles to GenParticles and attach them to the
56 // event. Flip the event if needed.
57 if((ret_val = BeamHaloGenerator::convertEvent(&beamHaloEvent, evt, engine)) != 0) return ret_val;
58
59 // Set the event number
60 evt->set_event_number(m_eventNumber);
61
62 // Set the signal process
64
65 // Increment the event number
67
68 return 0;
69}
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.
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=0)
Definition GenEvent.h:580

◆ flipEvent()

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

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}
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 FlukaHaloGenerator::genFinalize ( )
virtual

A function to finalise the generator.

Reimplemented from BeamHaloGenerator.

Definition at line 73 of file FlukaHaloGenerator.cxx.

73 {
74 int ret_val;
75
76 m_asciiInput->close();
77
78 // Finalise base class
79 if((ret_val = BeamHaloGenerator::genFinalize()) != 0) return ret_val;
80
81 return 0;
82}
std::unique_ptr< 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 FlukaHaloGenerator::genInitialize ( )
virtual

A function to initialise the generator.

Reimplemented from BeamHaloGenerator.

Definition at line 28 of file FlukaHaloGenerator.cxx.

28 {
29 int ret_val;
30
31 // Initialise base class
32 if((ret_val = BeamHaloGenerator::genInitialize()) != 0) return ret_val;
33
34 if(m_asciiInput->open() != 0) {
35 std::cout << "Error: Could not open ascii input file " << m_inputFile << std::endl;
36 return 1;
37 }
38
39 std::cout << "Info: Reading ascii input file " << m_inputFile << std::endl;
40
41 return 0;
42}
std::string m_inputFile
Input file name.
virtual int genInitialize()
A function to initialise the generator.

◆ readEvent()

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

A function to read one event in a simplified format.

Implements BeamHaloGenerator.

Definition at line 94 of file FlukaHaloGenerator.cxx.

95 {
96 BeamHaloParticle beamHaloParticle;
97
98 // Clear the event
99 beamHaloEvent->clear();
100
101 // If there was a last event.
102 if(!m_firstEvent) {
103
104 // If the last event caused the same event flag to be set to false
105 // copy the last particle into the vector of those in this event.
106 if(!m_sameEvent) {
107 // Fill the BeamHaloParticle with the data in the FlukaParticle
108 if(beamHaloParticle.fill(&m_lastFlukaParticle)) {
109 std::cout << "Error: Conversion from FlukaParticle to BeamHaloParticle failed." << std::endl;
110 return 1;
111 }
112 // Append the BeamHalo particle to the event.
113 beamHaloEvent->push_back(beamHaloParticle);
114
115 // Set the same event flag to enter the while loop to read the
116 // rest of this event.
117 m_sameEvent = true;
118 }
119 }
120
121 // Loop over the ascii input and read each particle until a new
122 // event is found or there are no more particles.
123 std::vector<std::string> row;
124 bool endOfFile = false;
125 while(m_sameEvent && !endOfFile) {
126 row = m_asciiInput->readRow(); // Read one line of the ascii file.11
127
128 if(row.size() == 0) {
129 endOfFile = true;
130 continue;
131 }
132
133 if(m_flukaParticle.read(&row)) { // Fill the particle from the string vector
134 continue;
135 }
136
137 // Check if there was a last particle.
138 if(!m_firstEvent) {
139
140 m_sameEvent = false;
141
142 // Check if the event id of the last particle is the same as this particle.
144 && (m_lastFlukaParticle.eventId() == m_flukaParticle.eventId())
145 && (m_lastFlukaParticle.partGenNum() == m_flukaParticle.partGenNum())) m_sameEvent = true;
146
148 && (m_lastFlukaParticle.eventId() == m_flukaParticle.eventId())) m_sameEvent = true;
149 }
150 else {
151 // For the first event.
152 m_firstEvent = false;
153 m_sameEvent = true;
154 }
155
156 // If this is the same event copy the particle into the vector for
157 // this event.
158 if(m_sameEvent) {
159
160 // Fill the BeamHaloParticle with the data in the FlukaParticle
161 if(beamHaloParticle.fill(&m_flukaParticle)) {
162 std::cout << "Error: Conversion from FlukaParticle to BeamHaloParticle failed." << std::endl;
163 return 1;
164 }
165
166 // Append the BeamHalo particle to the event.
167 beamHaloEvent->push_back(beamHaloParticle);
168 }
169
170 // Copy this particle into the last particle.
172
173 }
174
175 if(beamHaloEvent->size() == 0) {
176 std::cout << "Error: No particles read from " << m_inputFile << std::endl;
177 return 1;
178 }
179
181 m_wsums[TOT_READ]+= 1.0;
182
183 // Check if one of the particles in the event passes the generator settings.
184 std::vector<BeamHaloParticle>::iterator itr = beamHaloEvent->begin();
185 std::vector<BeamHaloParticle>::iterator itr_end = beamHaloEvent->end();
186 bool passed = false;
187 for(;itr!=itr_end;++itr) {
188 beamHaloParticle = *itr;
189 // Check the generator settings for this particle.
190 if(m_beamHaloGeneratorSettings->checkParticle(&beamHaloParticle)) {
191 passed = true;
192 }
193 else {
194 if(m_debug) std::cout << "Debug: Particle fails generator settings cuts." << std::endl;
195 }
196 }
197
199 m_wsums[TOT_AFTER]+= 1.0;
201 m_wsums[TOT_GEN]+= 1.0;
202
203 // If all of the particles from this event fail read another event.
204 // If there are no more events this function will exit with a
205 // WARNING.
206 if(!passed) {
207 int ret_val;
208 if((ret_val = readEvent(beamHaloEvent, engine)) != 0) return ret_val;
209 }
210
211 return 0;
212}
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
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.
std::unique_ptr< BeamHaloGeneratorSettings > m_beamHaloGeneratorSettings
A pointer to a BeamHaloGeneratorSettings object used to filter particles.
int fill(MarsParticle *marsParticle)
A function to fill the data members from an input MarsParticle object.
row
Appending html table to final .html summary file.

◆ readParticle()

int FlukaHaloGenerator::readParticle ( BeamHaloParticle * beamHaloParticle)
protectedvirtual

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

Implements BeamHaloGenerator.

Definition at line 86 of file FlukaHaloGenerator.cxx.

86 {
87
88 std::cout << "Warning: FlukaHaloGenerator::readParticle is not yet available: "<< beamHaloParticle << std::endl;
89 return 0;
90}

◆ 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 75 of file BeamHaloGenerator.h.

75{ m_bufferFileName = bufferFileName; }
std::string m_bufferFileName
The name of the binary buffer file, needed for sampling from a converted file.

◆ setDebugEnable()

void BeamHaloGenerator::setDebugEnable ( bool debug)
inlineinherited

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)
inlineinherited

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)
inlineinherited

Turn on or off sampling from the input ASCII file.

Definition at line 71 of file BeamHaloGenerator.h.

71{ m_enableSampling = enableSampling; }
bool m_enableSampling
Flag to enable or disable sampling.

◆ setFlipProbability()

void BeamHaloGenerator::setFlipProbability ( float flipProbability)
inlineinherited

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)
inlineinherited

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
protectedinherited

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
protectedinherited

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
protectedinherited

Binary particle buffer for caching converted events.

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

◆ m_counters

long BeamHaloGenerator::m_counters[NUM_COUNTERS]
protectedinherited

Particle or event counters of dimension enumCounters.

Definition at line 147 of file BeamHaloGenerator.h.

◆ m_debug

bool BeamHaloGenerator::m_debug
protectedinherited

A flat to turn on or off debug print out.

Definition at line 153 of file BeamHaloGenerator.h.

◆ m_enableFlip

bool BeamHaloGenerator::m_enableFlip
protectedinherited

Flag for flipping event.

Definition at line 113 of file BeamHaloGenerator.h.

◆ m_enableSampling

bool BeamHaloGenerator::m_enableSampling
protectedinherited

Flag to enable or disable sampling.

Definition at line 119 of file BeamHaloGenerator.h.

◆ m_eventNumber

long BeamHaloGenerator::m_eventNumber
protectedinherited

A data member to count the event number.

Definition at line 137 of file BeamHaloGenerator.h.

◆ m_firstEvent

bool FlukaHaloGenerator::m_firstEvent
private

Definition at line 49 of file FlukaHaloGenerator.h.

◆ m_flipProbability

float BeamHaloGenerator::m_flipProbability
protectedinherited

Flip probability.

Definition at line 116 of file BeamHaloGenerator.h.

◆ m_flukaParticle

FlukaParticle FlukaHaloGenerator::m_flukaParticle
private

Definition at line 50 of file FlukaHaloGenerator.h.

◆ m_gendata

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

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
privateinherited

A vector of generator settings in string command form.

Definition at line 158 of file BeamHaloGenerator.h.

◆ m_inputFile

std::string BeamHaloGenerator::m_inputFile
protectedinherited

Input file name.

Definition at line 107 of file BeamHaloGenerator.h.

◆ m_interfacePlane

double BeamHaloGenerator::m_interfacePlane
protectedinherited

The position of the interface plane in mm.

Definition at line 110 of file BeamHaloGenerator.h.

◆ m_lastFlukaParticle

FlukaParticle FlukaHaloGenerator::m_lastFlukaParticle
private

Definition at line 51 of file FlukaHaloGenerator.h.

◆ m_sameEvent

bool FlukaHaloGenerator::m_sameEvent
private

Definition at line 48 of file FlukaHaloGenerator.h.

◆ m_wsums

double BeamHaloGenerator::m_wsums[NUM_COUNTERS]
protectedinherited

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: