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
GenCrossSection.h
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_CROSS_SECTION_H
7#define HEPMC3_CROSS_SECTION_H
34#include <iostream>
35#include <algorithm>
36#include "HepMC3/Attribute.h"
37
38namespace HepMC3 {
40using namespace std;
41
42class GenCrossSection : public Attribute {
43
44//
45// Fields
46//
47private:
48
49 long accepted_events;
50 long attempted_events;
51
52 std::vector<double> cross_sections;
53 std::vector<double> cross_section_errors;
54//
55// Functions
56//
57public:
59 bool from_string(const std::string &att) override;
60
62 bool to_string(std::string &att) const override;
65
73 void set_cross_section(const double& xs, const double& xs_err,const long& n_acc = -1, const long& n_att = -1);
74
76
77 void set_cross_section(const std::vector<double>& xs, const std::vector<double>& xs_err,const long& n_acc = -1, const long& n_att = -1);
78
81 const std::vector<double>& xsecs() const { return cross_sections; }
82
85 const std::vector<double>& xsec_errs() const { return cross_section_errors; }
86
87
90 void set_accepted_events(const long& n_acc ) {
91 accepted_events=n_acc;
92 }
93
96 void set_attempted_events(const long& n_att ) {
97 attempted_events=n_att;
98 }
99
102 long get_accepted_events() const {
103 return accepted_events;
104 }
105
108 long get_attempted_events() const {
109 return attempted_events;
110 }
111
115 void set_xsec(const std::string& wName,const double& xs) {
116 int pos = windx(wName);
117 if ( pos < 0 ) throw std::runtime_error("GenCrossSection::set_xsec(const std::string&,const double&): no weight with given name in this run");
118 set_xsec(pos, xs);
119 }
120
124 void set_xsec(const unsigned long& index, const double& xs) {
125 if ( index >= cross_sections.size() ) {throw std::runtime_error("GenCrossSection::set_xsec(const unsigned long&): index outside of range");}
126 cross_sections[index] = xs;
127 }
128
132 void set_xsec_err(const std::string& wName, const double& xs_err) {
133 int pos = windx(wName);
134 if ( pos < 0 ) throw std::runtime_error("GenCrossSection::set_xsec_err(const std::string&,const double&): no weight with given name in this run");
135 set_xsec_err(pos, xs_err);
136 }
137
141 void set_xsec_err(const unsigned long& index, const double& xs_err) {
142 if ( index >= cross_section_errors.size() ) {throw std::runtime_error("GenCrossSection::set_xsec_err(const unsigned long&): index outside of range");}
143 cross_section_errors[index] = xs_err;
144 }
145
149 double xsec(const std::string& wName) const {
150 int pos = windx(wName);
151 if ( pos < 0 ) throw std::runtime_error("GenCrossSection::xsec(const std::string&): no weight with given name in this run");
152 return xsec(pos);
153 }
154
158 double xsec(const unsigned long& index = 0) const {
159 if ( index < cross_sections.size() ) { return cross_sections.at(index); }
160 else { throw std::runtime_error("GenCrossSection::xsec(const unsigned long&): index outside of range");}
161 return 0.0;
162 }
163
167 double xsec_err(const std::string& wName) const {
168 int pos = windx(wName);
169 if ( pos < 0 ) throw std::runtime_error("GenCrossSection::xsec_err(const std::string&): no weight with given name in this run");
170 return xsec_err(pos);
171 }
172
176 double xsec_err(const unsigned long& index = 0) const {
177 if ( index < cross_section_errors.size() ) {return cross_section_errors.at(index);}
178 else { throw std::runtime_error("GenCrossSection::xsec_err(const unsigned long&): index outside of range");}
179 return 0.0;
180 }
181
182 bool operator==( const GenCrossSection& ) const;
183 bool operator!=( const GenCrossSection& ) const;
184 bool is_valid() const;
185
186private:
187
189 int windx(const std::string& wName) const;
190
191};
192
193} // namespace HepMC3
194
195#endif
Attribute()
Default constructor.
Definition Attribute.h:51
Stores additional information about cross-section.
const std::vector< double > & xsec_errs() const
Get the cross-section errors.
void set_xsec(const unsigned long &index, const double &xs)
Set the cross section corresponding to the weight with index indx.
void set_attempted_events(const long &n_att)
Set the number of attempted events.
double xsec_err(const unsigned long &index=0) const
Get the cross section error corresponding to the weight with index indx.
bool is_valid() const
Verify that the instance contains non-zero information.
bool operator==(const GenCrossSection &) const
Operator ==.
long get_attempted_events() const
Get the number of attempted events.
void set_xsec(const std::string &wName, const double &xs)
Set the cross section corresponding to the weight named wName.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
void set_accepted_events(const long &n_acc)
Set the number of accepted events.
bool operator!=(const GenCrossSection &) const
Operator !=.
void set_cross_section(const std::vector< double > &xs, const std::vector< double > &xs_err, const long &n_acc=-1, const long &n_att=-1)
Set all fields.
double xsec_err(const std::string &wName) const
Get the cross section error corresponding to the weight named wName.
void set_xsec_err(const std::string &wName, const double &xs_err)
Set the cross section error corresponding to the weight named wName.
void set_cross_section(const double &xs, const double &xs_err, const long &n_acc=-1, const long &n_att=-1)
Set all fields.
double xsec(const std::string &wName) const
Get the cross section corresponding to the weight named wName.
const std::vector< double > & xsecs() const
Get the cross-sections.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
double xsec(const unsigned long &index=0) const
Get the cross section corresponding to the weight with index indx.
long get_accepted_events() const
Get the number of accepted events.
void set_xsec_err(const unsigned long &index, const double &xs_err)
Set the cross section error corresponding to the weight with index indx.