ATLAS Offline Software
Typedefs | Functions
AtlasMcWeight Namespace Reference

Typedefs

typedef unsigned int number_type
 

Functions

double decode (number_type binnedWeight)
 Convert weight from unsigned to double. More...
 
number_type encode (double weight)
 

Typedef Documentation

◆ number_type

typedef unsigned int AtlasMcWeight::number_type

Definition at line 20 of file AtlasMcWeight.h.

Function Documentation

◆ decode()

double AtlasMcWeight::decode ( number_type  binnedWeight)

Convert weight from unsigned to double.

Definition at line 32 of file AtlasMcWeight.cxx.

32  {
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 }

◆ encode()

AtlasMcWeight::number_type AtlasMcWeight::encode ( double  weight)

Definition at line 65 of file AtlasMcWeight.cxx.

65  {
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 }
xAOD::short
short
Definition: Vertex_v1.cxx:165
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
Trk::d_sign
double d_sign(double value, double sign)
Definition: TrkVKalUtils.h:33
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200