HepMC3 event record library
GenCrossSection.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5 //
6 #ifndef HEPMC3_CROSS_SECTION_H
7 #define HEPMC3_CROSS_SECTION_H
8 /**
9  * @file GenCrossSection.h
10  * @brief Definition of attribute \b class GenCrossSection
11  *
12  * @class HepMC3::GenCrossSection
13  * @brief Stores additional information about cross-section
14  *
15  * This is an example of event attribute used to store cross-section information
16  *
17  * This class is meant to be used to pass, on an event by event basis,
18  * the current best guess of the total cross section.
19  * It is expected that the final cross section will be stored elsewhere.
20  *
21  * - double cross_section; // cross section in pb.
22  * - double cross_section_error; // error associated with this cross section.
23  * - long accepted_events; ///< The number of events generated so far.
24  * - long attempted_events; ///< The number of events attempted so far.
25  *
26  * In addition, several cross sections and related info can be
27  * included in case of runs with mulltiple weights.
28  *
29  * The units of cross_section and cross_section_error are expected to be pb.
30  *
31  * @ingroup attributes
32  *
33  */
34 #include <iostream>
35 #include <algorithm>
36 #include "HepMC3/Attribute.h"
37 
38 namespace HepMC3 {
39 using namespace std;
40 
41 class GenCrossSection : public Attribute {
42 
43 //
44 // Fields
45 //
46 private:
47 
48  long accepted_events; ///< The number of events generated so far.
49  long attempted_events; ///< The number of events attempted so far.
50 
51  vector<double> cross_sections; ///< Per-weight cross-section.
52  vector<double> cross_section_errors; ///< Per-weight errors.
53 //
54 // Functions
55 //
56 public:
57  /** @brief Implementation of Attribute::from_string */
58  bool from_string(const string &att);
59 
60  /** @brief Implementation of Attribute::to_string */
61  bool to_string(string &att) const;
62 
63  /** @brief Set all fields */
64  void set_cross_section(const double& xs, const double& xs_err,const long& n_acc = -1, const long& n_att = -1);
65 
66  /** @brief Set the number of accepted events
67  */
68  void set_accepted_events(const long& n_acc ) {
69  accepted_events=n_acc;
70  }
71 
72  /** @brief Set the number of attempted events
73  */
74  void set_attempted_events(const long& n_att ) {
75  attempted_events=n_att;
76  }
77 
78  /** @brief Get the number of accepted events
79  */
80  long get_accepted_events() const {
81  return accepted_events;
82  }
83 
84  /** @brief Get the number of attempted events
85  */
86  long get_attempted_events() const {
87  return attempted_events;
88  }
89 
90  /** @brief Set the cross section corresponding to the weight
91  named \a wName.
92  */
93  void set_xsec(const string& wName,const double& xs) {
94  set_xsec(windx(wName), xs);
95  }
96 
97  /** @brief Set the cross section corresponding to the weight with
98  index \a indx.
99  */
100  void set_xsec(const int& indx, const double& xs) {
101  cross_sections[indx] = xs;
102  }
103 
104  /** @brief Set the cross section error corresponding to the weight
105  named \a wName.
106  */
107  void set_xsec_err(const string& wName, const double& xs_err) {
108  set_xsec_err(windx(wName), xs_err);
109  }
110 
111  /** @brief Set the cross section error corresponding to the weight
112  with index \a indx.
113  */
114  void set_xsec_err(const int& indx, const double& xs_err) {
115  cross_section_errors[indx] = xs_err;
116  }
117 
118  /** @brief Get the cross section corresponding to the weight named
119  \a wName.
120  */
121  double xsec(const string& wName) {
122  return xsec(windx(wName));
123  }
124 
125  /** @brief Get the cross section corresponding to the weight with index
126  \a indx.
127  */
128  double xsec(const int& indx = 0) {
129  return cross_sections[indx];
130  }
131 
132  /** @brief Get the cross section error corresponding to the weight
133  named \a wName.
134  */
135  double xsec_err(const string& wName) {
136  return xsec_err(windx(wName));
137  }
138 
139  /** @brief Get the cross section error corresponding to the weight
140  with index \a indx.
141  */
142  double xsec_err(const int& indx = 0) {
143  return cross_section_errors[indx];
144  }
145 
146  bool operator==( const GenCrossSection& ) const; ///< Operator ==
147  bool operator!=( const GenCrossSection& ) const; ///< Operator !=
148  bool is_valid() const; ///< Verify that the instance contains non-zero information
149 
150 private:
151 
152  /** @brief get the weight index given a weight name. */
153  int windx(string wName) const;
154 
155 };
156 
157 
158 } // namespace HepMC3
159 
160 #endif
Forward declaration of GenParticle.
Definition: Attribute.h:45
long get_attempted_events() const
Get the number of attempted events.
void set_xsec(const string &wName, const double &xs)
Set the cross section corresponding to the weight named wName.
long get_accepted_events() const
Get the number of accepted events.
vector< double > cross_sections
Per-weight cross-section.
void set_xsec_err(const int &indx, const double &xs_err)
Set the cross section error 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 int &indx=0)
Get the cross section error corresponding to the weight with index indx.
long attempted_events
The number of events attempted so far.
double xsec(const string &wName)
Get the cross section corresponding to the weight named wName.
vector< double > cross_section_errors
Per-weight errors.
void set_accepted_events(const long &n_acc)
Set the number of accepted events.
void set_xsec_err(const string &wName, const double &xs_err)
Set the cross section error corresponding to the weight named wName.
double xsec(const int &indx=0)
Get the cross section corresponding to the weight with index indx.
Definition of class Attribute, class IntAttribute and class StringAttribute.
long accepted_events
The number of events generated so far.
double xsec_err(const string &wName)
Get the cross section error corresponding to the weight named wName.
Stores additional information about cross-section.
void set_xsec(const int &indx, const double &xs)
Set the cross section corresponding to the weight with index indx.