From 1c192e3ac0ac90063689caf95be2df31fc37627f Mon Sep 17 00:00:00 2001 From: lintao <lintao51@gmail.com> Date: Tue, 12 Oct 2021 17:50:16 +0800 Subject: [PATCH] parse the data. --- Generator/src/BeamBackgroundFileParserV0.cpp | 59 +++++++++++++++++++- Generator/src/BeamBackgroundFileParserV0.h | 5 +- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Generator/src/BeamBackgroundFileParserV0.cpp b/Generator/src/BeamBackgroundFileParserV0.cpp index 9a5447dc..02593428 100644 --- a/Generator/src/BeamBackgroundFileParserV0.cpp +++ b/Generator/src/BeamBackgroundFileParserV0.cpp @@ -1,10 +1,65 @@ #include "BeamBackgroundFileParserV0.h" +#include <sstream> +#include <cmath> -BeamBackgroundFileParserV0::BeamBackgroundFileParserV0(const std::string& filename) { +BeamBackgroundFileParserV0::BeamBackgroundFileParserV0(const std::string& filename, + int pdgid, + double beam_energy) { m_input.open(filename.c_str()); + m_pdgid = pdgid; + m_beam_energy = beam_energy; } bool BeamBackgroundFileParserV0::load(IBeamBackgroundFileParser::BeamBackgroundData& result) { - return true; + + if (not m_input.good()) { + return false; + } + + // read one record + std::string tmpline; + // the format + double generation_point; + int loss_turn; + double z; // unit: m + double x; // unit: m + double y; // unit: m + double cosx; // + double cosy; // + double dz; // unit: m + double dp; // unit: relative to the E + + while(m_input.good()) { + std::getline(m_input, tmpline); + std::stringstream ss; + ss << tmpline; + ss >> generation_point; if (ss.fail()) { continue; } + ss >> loss_turn; if (ss.fail()) { continue; } + ss >> z; if (ss.fail()) { continue; } + ss >> x; if (ss.fail()) { continue; } + ss >> y; if (ss.fail()) { continue; } + ss >> cosx; if (ss.fail()) { continue; } + ss >> cosy; if (ss.fail()) { continue; } + ss >> dz; if (ss.fail()) { continue; } + ss >> dp; if (ss.fail()) { continue; } + + double p = m_beam_energy*(1+dp); + + // Now, we get a almost valid data + const double m2mm = 1e3; // convert from m to mm + result.pdgid = m_pdgid; + result.x = x * m2mm; + result.y = y * m2mm; + result.z = (z+dz) * m2mm; + + result.px = p * cosx; + result.py = p * cosy; + result.pz = p * std::sqrt(1-cosx*cosx-cosy*cosy); + + result.mass = 0.000511; // assume e-/e+, mass is 0.511 MeV + + return true; + } + return false; } diff --git a/Generator/src/BeamBackgroundFileParserV0.h b/Generator/src/BeamBackgroundFileParserV0.h index 906d5814..3f3037f2 100644 --- a/Generator/src/BeamBackgroundFileParserV0.h +++ b/Generator/src/BeamBackgroundFileParserV0.h @@ -7,11 +7,14 @@ class BeamBackgroundFileParserV0: public IBeamBackgroundFileParser { public: - BeamBackgroundFileParserV0(const std::string& filename); + BeamBackgroundFileParserV0(const std::string& filename, int pdgid, double beam_energy); bool load(IBeamBackgroundFileParser::BeamBackgroundData&); private: std::ifstream m_input; + + int m_pdgid; + double m_beam_energy; }; #endif -- GitLab