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