ATLAS Offline Software
Loading...
Searching...
No Matches
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
7int 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
20unsigned 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
23 int phiInt = toTopoInteger(phi, TSU::phiIntegerResolution) % 128;
24 return static_cast<unsigned int>(phiInt);
25}
26
30
31
32int 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
40int TSU::toSigned(const std::string& bits) {
41 return TSU::toSigned(std::stoi(bits, nullptr, 2), bits.length());
42}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
double length(const pvec &v)
static constexpr unsigned int phiIntegerResolution
Definition Conversions.h:14
int toTopoEta(float eta)
unsigned int toTopoPhi(float phi)
static constexpr float phiRescaleFactor
Definition Conversions.h:13
int toTopoInteger(float value, unsigned int resolution)
static constexpr unsigned int etaIntegerResolution
Definition Conversions.h:15
int toSigned(unsigned bits, unsigned length)
Definition index.py:1