HepMC3 event record library
GenPdfInfo.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file GenPdfInfo.cc
8 * @brief Implementation of \b class GenPdfInfo
9 *
10 */
11#include <array>
12#include <cstdio> // sprintf
13#include <cstdlib> // atoi
14#include <cstring> // memcmp
15
16#include "HepMC3/GenPdfInfo.h"
17
18namespace HepMC3 {
19
20bool GenPdfInfo::from_string(const std::string &att) {
21 const char *cursor = att.data();
22
23 parton_id[0] = atoi(cursor);
24
25 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
26 parton_id[1] = atoi(cursor);
27
28 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
29 x[0] = atof(cursor);
30
31 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
32 x[1] = atof(cursor);
33
34 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
35 scale = atof(cursor);
36
37 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
38 xf[0] = atof(cursor);
39
40 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
41 xf[1] = atof(cursor);
42
43 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
44 pdf_id[0] = atoi(cursor);
45
46 if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
47 pdf_id[1] = atoi(cursor);
48
49 return true;
50}
51
52bool GenPdfInfo::to_string(std::string &att) const {
53 std::array<char, 255> buf;//Note: the format is fixed, so no reason for complicatied tratment
54
55 snprintf(buf.data(), buf.size(), "%i %i %.8e %.8e %.8e %.8e %.8e %i %i",
56 parton_id[0],
57 parton_id[1],
58 x[0],
59 x[1],
60 scale,
61 xf[0],
62 xf[1],
63 pdf_id[0],
64 pdf_id[1]);
65
66 att = buf.data();
67
68 return true;
69}
70
71void GenPdfInfo::set(const int& parton_id1, const int& parton_id2, const double& x1, const double& x2,
72 const double& scale_in, const double& xf1, const double& xf2,
73 const int& pdf_id1, const int& pdf_id2) {
74 parton_id[0] = parton_id1;
75 parton_id[1] = parton_id2;
76 x[0] = x1;
77 x[1] = x2;
78 scale = scale_in;
79 xf[0] = xf1;
80 xf[1] = xf2;
81 pdf_id[0] = pdf_id1;
82 pdf_id[1] = pdf_id2;
83}
84
85bool GenPdfInfo::operator==(const GenPdfInfo& a) const {
86 return ( memcmp( (void*)this, (void*)&a, sizeof(class GenPdfInfo) ) == 0 );
87}
88
89bool GenPdfInfo::operator!=(const GenPdfInfo& a) const {
90 return !( a == *this );
91}
92
94{
95 if ( parton_id[0] != 0 ) { return true; }
96 if ( parton_id[1] != 0 ) { return true; }
97 if ( x[0] != 0 ) { return true; }
98 if ( x[1] != 0 ) { return true; }
99 if ( scale != 0 ) { return true; }
100 if ( xf[0] != 0 ) { return true; }
101 if ( xf[1] != 0 ) { return true; }
102 if ( pdf_id[0] != 0 ) { return true; }
103 if ( pdf_id[1] != 0 ) { return true; }
104
105 return false;
106}
107
108} // namespace HepMC3
Definition of event attribute class GenPdfInfo.
Stores additional information about PDFs.
Definition GenPdfInfo.h:32
int parton_id[2]
Parton PDG ID.
Definition GenPdfInfo.h:38
double xf[2]
PDF value.
Definition GenPdfInfo.h:42
double scale
Factorisation scale (in GEV)
Definition GenPdfInfo.h:40
void set(const int &parton_id1, const int &parton_id2, const double &x1, const double &x2, const double &scale_in, const double &xf1, const double &xf2, const int &pdf_id1=0, const int &pdf_id2=0)
Set all fields.
Definition GenPdfInfo.cc:71
int pdf_id[2]
LHAPDF ID code.
Definition GenPdfInfo.h:39
bool is_valid() const
Verify that the instance contains non-zero information.
Definition GenPdfInfo.cc:93
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
Definition GenPdfInfo.cc:20
double x[2]
Parton momentum fraction.
Definition GenPdfInfo.h:41
bool operator==(const GenPdfInfo &) const
Operator ==.
Definition GenPdfInfo.cc:85
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Definition GenPdfInfo.cc:52
bool operator!=(const GenPdfInfo &) const
Operator !=.
Definition GenPdfInfo.cc:89
HepMC3 main namespace.