File: GenPdfInfo.cc

package info (click to toggle)
hepmc3 3.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 14,116 kB
  • sloc: fortran: 66,849; cpp: 13,604; ansic: 1,374; xml: 109; sh: 72; makefile: 33
file content (106 lines) | stat: -rw-r--r-- 2,702 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// -*- C++ -*-
//
// This file is part of HepMC
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
//
/**
 *  @file GenPdfInfo.cc
 *  @brief Implementation of \b class GenPdfInfo
 *
 */
#include "HepMC3/GenPdfInfo.h"
#include <cstring> // memcmp
#include <cstdlib> // atoi
#include <cstdio> // sprintf

namespace HepMC3 {

bool GenPdfInfo::from_string(const string &att) {
    const char *cursor = att.data();

    parton_id[0] = atoi(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    parton_id[1] = atoi(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    x[0] = atof(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    x[1] = atof(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    scale = atof(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    xf[0] = atof(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    xf[1] = atof(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    pdf_id[0] = atoi(cursor);

    if( !(cursor = strchr(cursor+1,' ')) ) return false;
    pdf_id[1] = atoi(cursor);

    return true;
}

bool GenPdfInfo::to_string(string &att) const {
    char buf[255];

    sprintf(buf,"%i %i %.8e %.8e %.8e %.8e %.8e %i %i",
            parton_id[0],
            parton_id[1],
            x[0],
            x[1],
            scale,
            xf[0],
            xf[1],
            pdf_id[0],
            pdf_id[1]);

    att = buf;

    return true;
}

void GenPdfInfo::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, const int& pdf_id2) {
    parton_id[0] = parton_id1;
    parton_id[1] = parton_id2;
    x[0]         = x1;
    x[1]         = x2;
    scale        = scale_in;
    xf[0]        = xf1;
    xf[1]        = xf2;
    pdf_id[0]    = pdf_id1;
    pdf_id[1]    = pdf_id2;
}

bool GenPdfInfo::operator==( const GenPdfInfo& a ) const {
    return ( memcmp( (void*)this, (void*)&a, sizeof(class GenPdfInfo) ) == 0 );
}

bool GenPdfInfo::operator!=( const GenPdfInfo& a ) const {
    return !( a == *this );
}

bool GenPdfInfo::is_valid() const
{
    if( parton_id[0] != 0 ) return true;
    if( parton_id[1] != 0 ) return true;
    if( x[0]         != 0 ) return true;
    if( x[1]         != 0 ) return true;
    if( scale        != 0 ) return true;
    if( xf[0]        != 0 ) return true;
    if( xf[1]        != 0 ) return true;
    if( pdf_id[0]    != 0 ) return true;
    if( pdf_id[1]    != 0 ) return true;

    return false;
}

} // namespace HepMC3