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/GtBeamBackgroundTool.cpp b/Generator/src/GtBeamBackgroundTool.cpp index 1fe4797b5e42b8ded7f5a049e5d938ecd7e4acd6..fba5b0b4da7c995d8c09ceb7581cfdbf9de79ba0 100644 --- a/Generator/src/GtBeamBackgroundTool.cpp +++ b/Generator/src/GtBeamBackgroundTool.cpp @@ -1,6 +1,8 @@ #include "GtBeamBackgroundTool.h" #include "IBeamBackgroundFileParser.h" + #include "BeamBackgroundFileParserV0.h" +#include "GuineaPigPairsFileParser.h" #include "TVector3.h" // for rotation DECLARE_COMPONENT(GtBeamBackgroundTool) @@ -11,17 +13,21 @@ StatusCode GtBeamBackgroundTool::initialize() { // create the instances of the background parsers for (auto& [label, inputfn]: m_inputmaps) { - double beamE = 120.; - auto itBeamE = m_Ebeammaps.find(label); - if (itBeamE != m_Ebeammaps.end()) { - beamE = itBeamE->second; + std::string format = "BeamBackgroundFileParserV0"; + + auto itFormat = m_formatmaps.find(label); + if (itFormat != m_formatmaps.end()) { + format = itFormat->second; + } + + if (format == "BeamBackgroundFileParserV0") { + init_BeamBackgroundFileParserV0(label, inputfn); + } else if (format == "GuineaPigPairsFileParser") { + init_GuineaPigPairsFileParser(label, inputfn); + } else { + init_BeamBackgroundFileParserV0(label, inputfn); } - info() << "Initializing beam background ... " - << label << " " - << beamE << " " - << inputfn - << endmsg; - m_beaminputs[label] = std::make_shared<BeamBackgroundFileParserV0>(inputfn, 11, beamE); + } // check the size @@ -89,3 +95,28 @@ bool GtBeamBackgroundTool::configure_gentool() { return true; } + +bool GtBeamBackgroundTool::init_BeamBackgroundFileParserV0(const std::string& label, + const std::string& inputfn) { + double beamE = 120.; + auto itBeamE = m_Ebeammaps.find(label); + if (itBeamE != m_Ebeammaps.end()) { + beamE = itBeamE->second; + } + info() << "Initializing beam background ... " + << label << " " + << beamE << " " + << inputfn + << endmsg; + m_beaminputs[label] = std::make_shared<BeamBackgroundFileParserV0>(inputfn, 11, beamE); + + return true; +} + +bool GtBeamBackgroundTool::init_GuineaPigPairsFileParser(const std::string& label, + const std::string& inputfn) { + + m_beaminputs[label] = std::make_shared<GuineaPigPairsFileParser>(inputfn); + + return true; +} diff --git a/Generator/src/GtBeamBackgroundTool.h b/Generator/src/GtBeamBackgroundTool.h index 8e0af8e5777a834e7b42f441f2de5e8766e463bc..632f3851fea0e8468d53d9e63ccc42ad34b65dff 100644 --- a/Generator/src/GtBeamBackgroundTool.h +++ b/Generator/src/GtBeamBackgroundTool.h @@ -46,9 +46,14 @@ public: bool finish() override; bool configure_gentool() override; + +private: + bool init_BeamBackgroundFileParserV0(const std::string& label, const std::string& inputfn); + bool init_GuineaPigPairsFileParser(const std::string& label, const std::string& inputfn); + private: Gaudi::Property<std::map<std::string, std::string>> m_inputmaps{this, "InputFileMap"}; - Gaudi::Property<std::map<std::string, std::string>> m_fomatmaps{this, "InputFormatMap"}; + Gaudi::Property<std::map<std::string, std::string>> m_formatmaps{this, "InputFormatMap"}; Gaudi::Property<std::map<std::string, double>> m_ratemaps {this, "InputRateMap"}; // unit of beam energy: GeV 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 diff --git a/run.sh b/run.sh index 97f7f21509ec4ff0cbb56b23e37431496f4a2a80..bb42b5c8d3b22959ff6e0ffa15306f6fdad1fa19 100755 --- a/run.sh +++ b/run.sh @@ -67,7 +67,7 @@ function run-job() { # The current default platform lcg_platform=x86_64-centos7-gcc8-opt -lcg_version=101.0.0 +lcg_version=101.0.1 bldtool=${CEPCSW_BLDTOOL} # make, ninja # set in env var