diff --git a/Generator/CMakeLists.txt b/Generator/CMakeLists.txt index 6169e415c23b9ec0ea47b9458f8b436a4194932c..e411a4826a6b6973541ef2c8f1d2cf811e79a8ab 100644 --- a/Generator/CMakeLists.txt +++ b/Generator/CMakeLists.txt @@ -18,6 +18,7 @@ gaudi_add_module(GenAlgo # ------- Beam Background ------- src/GtBeamBackgroundTool.cpp src/BeamBackgroundFileParserV0.cpp + src/GuineaPigPairsFileParser.cpp LINK ${ROOT_LIBRARIES} k4FWCore::k4FWCore Gaudi::GaudiAlgLib diff --git a/Generator/src/GuineaPigPairsFileParser.cpp b/Generator/src/GuineaPigPairsFileParser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13df7f2344679e967cdcf765368f96f2316fc165 --- /dev/null +++ b/Generator/src/GuineaPigPairsFileParser.cpp @@ -0,0 +1,62 @@ +#include "GuineaPigPairsFileParser.h" +#include <sstream> +#include <cmath> + +GuineaPigPairsFileParser::GuineaPigPairsFileParser(const std::string& filename) { + m_input.open(filename.c_str()); +} + +bool GuineaPigPairsFileParser::load(IBeamBackgroundFileParser::BeamBackgroundData& result) { + if (not m_input.good()) { + return false; + } + + // read one record + std::string tmpline; + // the format + double energy; // unit: GeV + double vx; // unit: c + double vy; // unit: c + double vz; // unit: c + double x; // unit: nm + double y; // unit: nm + double z; // unit: nm + int process; + + while(m_input.good()) { + std::getline(m_input, tmpline); + std::stringstream ss; + ss << tmpline; + ss >> energy; if (ss.fail()) { continue; } + ss >> vx; if (ss.fail()) { continue; } + ss >> vy; if (ss.fail()) { continue; } + ss >> vz; if (ss.fail()) { continue; } + ss >> x; if (ss.fail()) { continue; } + ss >> y; if (ss.fail()) { continue; } + ss >> z; if (ss.fail()) { continue; } + ss >> process; if (ss.fail()) { continue; } + + int pdgid = 11; // 11: electron; -11: positron + if (energy<0) pdgid = -11; + + double p = std::fabs(energy); + double v = sqrt(vx*vx+vy*vy+vz*vz); + + // Now, we get a almost valid data + const double nm2mm = 1e-6; // convert from nm to mm + result.pdgid = pdgid; + result.x = x * nm2mm; + result.y = y * nm2mm; + result.z = z * nm2mm; + + result.px = p * vx/v; + result.py = p * vy/v; + result.pz = p * vz/v; + + result.mass = 0.000511; // assume e-/e+, mass is 0.511 MeV + + return true; + } + return false; + +} diff --git a/Generator/src/GuineaPigPairsFileParser.h b/Generator/src/GuineaPigPairsFileParser.h new file mode 100644 index 0000000000000000000000000000000000000000..078a38a0c7a62f5dc4fc9ef70e7655353405c306 --- /dev/null +++ b/Generator/src/GuineaPigPairsFileParser.h @@ -0,0 +1,32 @@ +#ifndef GuineaPigPairsFileParser_h +#define GuineaPigPairsFileParser_h + +#include "IBeamBackgroundFileParser.h" +#include <fstream> + +/* Format of Guinea-Pig Pairs: + * + * E vx vy vz x y z process + * + * Notes: + * - E (GeV). If E>0, it is electron. If E<0, it is positron + * - vx/vy/vz (speed of light) + * - x/y/z (nm) + * - process + * - 0: Breit-Wheeler + * - 1: Bethe-Heitler + * - 2: Landau-Lifschitz + * + */ + +class GuineaPigPairsFileParser: public IBeamBackgroundFileParser { +public: + GuineaPigPairsFileParser(const std::string& filename); + + bool load(IBeamBackgroundFileParser::BeamBackgroundData&); + +private: + std::ifstream m_input; +}; + +#endif