main45
Back to index.
// main45.cc is a part of the PYTHIA event generator.
// Copyright (C) 2020 Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.
// Author: Stefan Prestel .
// Keywords:
// LHE file
// Hepmc
// This program (main45.cc) illustrates how a file with HepMC3 events can be
// generated by Pythia8. See main44.cc for how to ouput HepMC2 events instead.
// Note: both main44.cc and main45.cc can use the same main44.cmnd input card.
#include "Pythia8/Pythia.h"
#include "Pythia8Plugins/HepMC3.h"
#include
using namespace Pythia8;
//==========================================================================
// Example main programm to illustrate merging.
int main( int argc, char* argv[] ){
// Check that correct number of command-line arguments
if (argc != 3) {
cerr << " Unexpected number of command-line arguments ("< nAbort) {doAbort = true; break;}
else continue;
}
// Get event weight(s).
double evtweight = pythia.info.weight();
// Do not print zero-weight events.
if ( evtweight == 0. ) continue;
// Create a GenRunInfo object with the necessary weight names. This
// seems to be needed such that the HepMC3 file writer will write
// the weight names on an event-by-event basis, rather than only in
// the first event.
shared_ptr genRunInfo;
genRunInfo = make_shared();
vector weight_names = pythia.info.weightNameVector();
genRunInfo->set_weight_names(weight_names);
// Construct new empty HepMC event.
HepMC3::GenEvent hepmcevt(genRunInfo);
// Work with weighted (LHA strategy=-4) events.
double normhepmc = 1.;
if (abs(pythia.info.lhaStrategy()) == 4)
normhepmc = 1. / double(1e9*nEvent);
// Work with unweighted events.
else
normhepmc = xs / double(1e9*nEvent);
// Set event weight
//hepmcevt.weights().push_back(evtweight*normhepmc);
// Fill HepMC event
toHepMC.fill_next_event( pythia, &hepmcevt );
// Add the weight of the current event to the cross section.
sigmaTotal += evtweight*normhepmc;
sigmaSample += evtweight*normhepmc;
errorTotal += pow2(evtweight*normhepmc);
errorSample += pow2(evtweight*normhepmc);
// Report cross section to hepmc
shared_ptr xsec;
xsec = make_shared();
xsec->set_cross_section( sigmaTotal*1e9, pythia.info.sigmaErr()*1e9 );
hepmcevt.set_cross_section( xsec );
// Unset GenRunInfo object of writer so that event run info is used.
ascii_io.set_run_info(0);
// Write the HepMC event to file. Done with it.
ascii_io.write_event(hepmcevt);
} // end loop over events to generate.
if (doAbort) break;
// print cross section, errors
pythia.stat();
cout << endl << " Contribution of sample " << iRuns
<< " to the inclusive cross section : "
<< scientific << setprecision(8)
<< sigmaSample << " +- " << sqrt(errorSample) << endl;
}
cout << endl << endl << endl;
if (doAbort)
cout << " Run was not completed owing to too many aborted events" << endl;
cout << endl << endl << endl;
// Done
return 0;
}