ATLAS Offline Software
Conversions.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 int TSU::toTopoInteger(float value, unsigned int resolution) {
8  float tmp = value*resolution;
9  float index;
10  if ( (abs(tmp)-0.5)/2. == std::round((abs(tmp)-0.5)/2.) ) {
11  if ( tmp>0 ) { index = std::floor(tmp); }
12  else { index = std::ceil(tmp); }
13  } else {
14  index = std::round(tmp);
15  }
16 
17  return static_cast<int>(index);
18 }
19 
20 unsigned int TSU::toTopoPhi(float phi) {
21  if (phi < 0) { phi += 2*M_PI; } //Convert to [0,2pi) range so phi can eventually be treated as unsigned
22  phi *= TSU::phiRescaleFactor;
23  int phiInt = toTopoInteger(phi, TSU::phiIntegerResolution) % 128;
24  return static_cast<unsigned int>(phiInt);
25 }
26 
27 int TSU::toTopoEta(float eta) {
28  return toTopoInteger(eta, TSU::etaIntegerResolution);
29 }
30 
31 
32 int TSU::toSigned(unsigned bits, unsigned length) {
33  if ( ((bits >> (length-1)) & 1) == 0) { //sign bit not set
34  return bits & ((1<<length)-1);
35  }
36  //sign bit set, convert assuming twos complement
37  return (bits & ((1<<length)-1)) - (1<<length);
38 }
39 
40 int TSU::toSigned(const std::string& bits) {
41  return TSU::toSigned(std::stoi(bits, nullptr, 2), bits.length());
42 }
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
TSU::toSigned
int toSigned(unsigned bits, unsigned length)
Definition: Conversions.cxx:32
index
Definition: index.py:1
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
TSU::toTopoEta
int toTopoEta(float eta)
Definition: Conversions.cxx:27
M_PI
#define M_PI
Definition: ActiveFraction.h:11
athena.value
value
Definition: athena.py:124
Dedxcorrection::resolution
double resolution[nGasTypes][nParametersResolution]
Definition: TRT_ToT_Corrections.h:46
Conversions.h
TSU::toTopoInteger
int toTopoInteger(float value, unsigned int resolution)
Definition: Conversions.cxx:7
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
DeMoScan.index
string index
Definition: DeMoScan.py:364
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
TSU::toTopoPhi
unsigned int toTopoPhi(float phi)
Definition: Conversions.cxx:20