diff --git a/Generator/src/GtBeamBackgroundTool.cpp b/Generator/src/GtBeamBackgroundTool.cpp index 8eea3cf25d503ebace5ee5efeb53c96fcd5819c4..a2d3d983ef4dd49105f894a6595fb71c30d83e63 100644 --- a/Generator/src/GtBeamBackgroundTool.cpp +++ b/Generator/src/GtBeamBackgroundTool.cpp @@ -1,5 +1,6 @@ #include "GtBeamBackgroundTool.h" #include "IBeamBackgroundFileParser.h" +#include "BeamBackgroundFileParserV0.h" DECLARE_COMPONENT(GtBeamBackgroundTool) StatusCode GtBeamBackgroundTool::initialize() { @@ -7,6 +8,17 @@ StatusCode GtBeamBackgroundTool::initialize() { // create the instances of the background parsers + for (auto& [label, inputfn]: m_inputmaps) { + + m_beaminputs[label] = std::make_shared<BeamBackgroundFileParserV0>(inputfn, 11, 125.); + } + + // check the size + if (m_beaminputs.empty()) { + error() << "Empty Beam Background File Parser. " << endmsg; + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; } @@ -16,6 +28,34 @@ StatusCode GtBeamBackgroundTool::finalize() { bool GtBeamBackgroundTool::mutate(MyHepMC::GenEvent& event) { + if (m_beaminputs.empty()) { + return false; + } + // TODO: should sample according to the rates + // dummy: get one and stop to generate + for (auto& [label, parser]: m_beaminputs) { + IBeamBackgroundFileParser::BeamBackgroundData beamdata; + auto isok = parser->load(beamdata); + if (not isok) { + error() << "Failed to load beam background data from the parser " << label << endmsg; + return false; + } + // fill the value + float charge = beamdata.pdgid == 11 ? -1: 1; + + // create the MC particle + edm4hep::MCParticle mcp = event.m_mc_vec.create(); + mcp.setPDG(beamdata.pdgid); + mcp.setGeneratorStatus(1); + mcp.setSimulatorStatus(1); + mcp.setCharge(static_cast<float>(charge)); + mcp.setTime(beamdata.t); + mcp.setMass(beamdata.mass); + mcp.setVertex(edm4hep::Vector3d(beamdata.x,beamdata.y,beamdata.z)); + mcp.setMomentum(edm4hep::Vector3f(beamdata.px,beamdata.py,beamdata.pz)); + + } + return true; } diff --git a/Generator/src/GtBeamBackgroundTool.h b/Generator/src/GtBeamBackgroundTool.h index 4750a96a88c46811132bac8b5b0e2302450fd41e..90fa37f83ee89c7c983de9113853c162696105fe 100644 --- a/Generator/src/GtBeamBackgroundTool.h +++ b/Generator/src/GtBeamBackgroundTool.h @@ -27,11 +27,11 @@ #include <GaudiKernel/AlgTool.h> #include <Gaudi/Property.h> #include "IGenTool.h" +#include "IBeamBackgroundFileParser.h" #include <vector> #include <map> -class IBeamBackgroundFileParser; class GtBeamBackgroundTool: public extends<AlgTool, IGenTool> { public: