7 #include "CLHEP/Random/RandFlat.h"
13 const std::vector<double>& intervalUpperBinEdges): m_upperBinEdge(upperBinEdge) {
36 , m_numberOfParticles(0)
39 , m_intervalUpperBinEdges()
40 , m_intervalUpperBinEdge(0)
41 , m_writeFlag(false) {
56 std::cerr <<
"Error: could not open output file" <<
m_fileName << std::endl;
67 std::cerr <<
"Error: the number of particles in the input file is not known." << std::endl;
75 std::cerr <<
"Error: could not open input file" <<
m_fileName << std::endl;
111 std::cerr <<
"Error: the file " <<
m_fileName <<
" is currently open for reading." << std::endl;
116 double px = 0.,
py = 0.,
pz = 0.,
e = 0.,
x = 0.,
y = 0.,
z = 0.,
t = 0.,
weight = 0.;
123 x =
particle->positionAtScoringPlane().x();
124 y =
particle->positionAtScoringPlane().y();
125 z =
particle->positionAtScoringPlane().z();
126 t =
particle->positionAtScoringPlane().t();
172 double generatedWeightSum;
177 std::cerr <<
"Error: the file " <<
m_fileName <<
" is currently open for writing." << std::endl;
182 std::cerr <<
"Error: the RandomEngine pointer is null." << std::endl;
186 long particleIndex = 0;
189 generatedWeightSum = CLHEP::RandFlat::shoot(engine)*
m_upperBinEdge;
197 while(superBinItr!=superBinItr_end && !
found) {
201 if(generatedWeightSum <= (*superBinItr).upperBinEdge()) {
206 particleIndex += (*superBinItr).intervalUpperBinEdges()->size();
212 std::cerr <<
"Could not find an interval for the weight sum " << generatedWeightSum << std::endl;
216 const std::vector<double> *intervalUpperBinEdges = (*superBinItr).intervalUpperBinEdges();
218 double intervalWeightSum = intervalUpperBinEdges->back();
222 generatedWeightSum = CLHEP::RandFlat::shoot(engine)*intervalWeightSum;
227 std::vector<double>::const_iterator intervalItr = intervalUpperBinEdges->begin();
228 std::vector<double>::const_iterator intervalItr_end = intervalUpperBinEdges->end();
230 while(intervalItr!=intervalItr_end && !
found) {
234 if(generatedWeightSum <= (*intervalItr)) {
245 std::cerr <<
"Could not find a particle for the weight sum " << generatedWeightSum << std::endl;
250 std::cerr <<
"Particle index " << particleIndex <<
" is out of range." << std::endl;
257 if(!beamHaloParticle)
return 0;
259 return beamHaloParticle;
266 std::cerr <<
"Error: the file " <<
m_fileName <<
" is current open for writing." << std::endl;
271 double px = 0.,
py = 0.,
pz = 0.,
e = 0.,
x = 0.,
y = 0.,
z = 0.,
t = 0.,
weight = 0.;
284 HepMC::FourVector fourVector(
px,
py,
pz,
e);
285 HepMC::FourVector positionAtScoringPlane(
x,
y,
z,
t);
288 return beamHaloParticle;