ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
EventTPCnv
src
AtlasMcWeight.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
12
#include <iostream>
13
#include <limits>
14
15
#include <cmath>
16
17
#include "
EventTPCnv/AtlasMcWeight.h
"
18
#include "GaudiKernel/StatusCode.h"
19
#include "GaudiKernel/GaudiException.h"
20
21
/* #define AMC_DEBUG 1 */
22
23
namespace
{
24
const
int
NPLACES = int(floor(log10(
double
(std::numeric_limits<AtlasMcWeight::number_type>::max()))));
25
const
int
ONEBILLION = 1000000000;
26
const
int
HUNDREDMIL = 100000000;
27
enum
{ NUMP_EXPP, NUMNOTP_EXPP, NUMP_EXPNOTP, NUMNOTP_EXPNOTP };
28
}
29
30
31
double
32
AtlasMcWeight::decode
(
number_type
binnedWeight) {
33
short
d_pref = (short)(binnedWeight/ONEBILLION);
34
int
d_rest = (int)(binnedWeight % ONEBILLION);
35
short
d_exp = (short)(d_rest/HUNDREDMIL);
36
int
d_prec = d_rest % HUNDREDMIL;
37
38
switch
(d_pref) {
39
case
NUMP_EXPP:
40
break
;
41
case
NUMNOTP_EXPP:
42
d_prec = -d_prec;
43
break
;
44
case
NUMP_EXPNOTP:
45
d_exp = -d_exp;
46
break
;
47
case
NUMNOTP_EXPNOTP:
48
d_prec = -d_prec;
49
d_exp = -d_exp;
50
break
;
51
}
52
double
wt_decode=d_prec*pow(10,d_exp-NPLACES+1);
53
//decoding
54
#ifdef AMC_DEBUG
55
std::cout <<
"d_pref="
<< d_pref << std::endl;
56
std::cout <<
" d_exp="
<< d_exp << std::endl;
57
std::cout <<
"d_prec="
<< d_prec << std::endl;
58
printf(
"decodd=%.8g \n"
,wt_decode);
59
#endif
60
return
wt_decode;
61
}
62
63
64
AtlasMcWeight::number_type
65
AtlasMcWeight::encode
(
double
weight) {
66
int
exponent = int(floor(log10(fabs(weight)))+1);
67
if
( abs(exponent) > 9 ) {
68
throw
GaudiException(
"The MC weight abs value is bigger than 1E9,encoding failed"
,
"AtlasMcWeight"
, StatusCode::FAILURE );
69
}
70
71
number_type
wt_prec = int(fabs(weight)*pow(10,(NPLACES-1-exponent)));
72
number_type
wt_exp = abs(exponent);
73
int
d_sign = ( weight > 0. ? 0 : 1 );
74
int
e_sign = ( exponent > 0. ? 0 : 1 );
75
number_type
wt_pref = d_sign+2*e_sign;
76
77
char
senc[13];
78
snprintf(senc,13,
"%u%u%u"
,wt_pref, wt_exp, wt_prec);
79
number_type
wt_encode=atoll(senc);
80
81
#ifdef AMC_DEBUG
82
std::cout <<
" AtlasMcWeight::encode weight = "
<< weight << std::endl;
83
printf(
"encode parts =%d %d %d \n"
, wt_pref, wt_exp, wt_prec);
84
printf(
"encoded string=%s \n"
, senc);
85
std::cout <<
" weight="
<< weight << std::endl;
86
std::cout <<
" str weight="
<< senc << std::endl;
87
std::cout <<
" exp weight="
<< atoll(senc) << std::endl;
88
std::cout <<
" encoded weight="
<< wt_encode << std::endl;
89
#endif
90
return
wt_encode;
91
}
AtlasMcWeight.h
Helper functions for MC weight insider the namespace AtlasMcWeight.
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition
AtlasMcWeight.cxx:32
AtlasMcWeight::encode
number_type encode(double weight)
Definition
AtlasMcWeight.cxx:65
AtlasMcWeight::number_type
unsigned int number_type
Definition
AtlasMcWeight.h:20
Generated on
for ATLAS Offline Software by
1.17.0