// -*- C++ -*- // // This file is part of HepMC // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details) // /** * @file GenCrossSection.cc * @brief Implementation of \b class GenCrossSection * */ #include "HepMC3/GenCrossSection.h" #include "HepMC3/GenEvent.h" #include // memcmp #include // atoi #include #include namespace HepMC3 { int GenCrossSection::windx(std::string wName) const { if ( !event() || !event()->run_info() ) return 0; return event()->run_info()->weight_index(wName); } void GenCrossSection::set_cross_section(const double& xs, const double& xs_err,const long& n_acc, const long& n_att ) { double cross_section = xs; double cross_section_error = xs_err; accepted_events = n_acc; attempted_events = n_att; size_t N=1; if ( event() ) N=std::max(event()->weights().size(),N); cross_sections = std::vector(N, cross_section); cross_section_errors = std::vector(N, cross_section_error); } bool GenCrossSection::from_string(const std::string &att) { const char *cursor = att.data(); cross_sections.clear(); cross_section_errors.clear(); double cross_section = atof(cursor); cross_sections.push_back(cross_section); if( !(cursor = strchr(cursor+1,' ')) ) return false; double cross_section_error = atof(cursor); cross_section_errors.push_back(cross_section_error); if( !(cursor = strchr(cursor+1,' ')) ) {accepted_events = -1; attempted_events = -1;} else { accepted_events = atoi(cursor); if( !(cursor = strchr(cursor+1,' ')) ) attempted_events = -1; else attempted_events = atoi(cursor); } size_t N=1; if ( event() ) N=std::max(event()->weights().size(),N); const size_t max_n_cross_sections=1000; while (cross_sections.size()=max_n_cross_sections) HEPMC3_WARNING( "GenCrossSection::from_string: too many optional cross-sections N="<