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