MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
cmd_helpers.cc
1
4//
5// This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6//
7// MARLEY is free software: you can redistribute it and/or modify it under the
8// terms of version 3 of the GNU General Public License as published by the
9// Free Software Foundation.
10//
11// For the full text of the license please see COPYING or
12// visit http://opensource.org/licenses/GPL-3.0
13//
14// Please respect the MCnet academic usage guidelines. See GUIDELINES
15// or visit https://www.montecarlonet.org/GUIDELINES for details.
16
17// HepMC3 includes
18#include "HepMC3/GenEvent.h"
19
20// MARLEY includes
21#include "cmd_helpers.hh"
22#include "marley/Error.hh"
23#include "marley/EventFileReader.hh"
24#include "marley/hepmc3_utils.hh"
25
26void for_each_event(
27 const std::vector< std::string >& input_files,
28 std::function< void( HepMC3::GenEvent&, bool,
29 double, const std::shared_ptr< HepMC3::GenRunInfo >& ) > callback )
30{
31 std::shared_ptr< HepMC3::GenRunInfo > first_run_info;
32 double flux_avg_xsec = 0.;
33 bool first_event = true;
34 bool first_file = true;
35
36 for ( const auto& input_file : input_files ) {
37 marley::EventFileReader reader( input_file );
39 while ( reader >> ev ) {
40 if ( !first_run_info ) {
41 first_run_info = ev.run_info();
42 flux_avg_xsec = reader.flux_averaged_xsec( true );
43 }
44 else if ( !first_file ) {
45 std::string issue = marley_hepmc3::check_run_info_compatibility(
46 *first_run_info, *ev.run_info() );
47 if ( !issue.empty() ) {
48 throw marley::Error( "File '" + input_file
49 + "' has incompatible run information: " + issue );
50 }
51 }
52
53 callback( ev, first_event, flux_avg_xsec, first_run_info );
54 first_event = false;
55 }
56 first_file = false;
57 }
58}
Stores event-related information.
Definition GenEvent.h:47
std::shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
Definition GenEvent.h:144
Base class for all exceptions thrown by MARLEY functions.
Definition Error.hh:26
Object that parses MARLEY output files.