ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimFunctions.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * FPGATrackSimFunctions.h
7 *
8 * Declares several generic utility functions.
9 */
10
11#ifndef FPGATrackSimFUNCTIONS_H
12#define FPGATrackSimFUNCTIONS_H
13
14
15#include <TString.h>
16#include <TObjArray.h>
17#include <TH1.h>
18#include <TObjString.h>
19#include <TTreeReader.h>
20#include <TTreeReaderValue.h>
21
24
25
26#include <cmath>
27#include <vector>
28#include <sstream>
29
30
31
32/*****************************************************************************/
33/* Bit Manipulations and Arithmetic
34 *
35 * Avoid using templates because right-shifts will not work correctly if
36 * accidentally called using a signed type.
37 */
38/*****************************************************************************/
39
40// Returns a list of words, each with one bit set for each bit set in x
41// Sorted by LSB to MSB.
42inline std::vector<uint32_t> splitSetBits32(uint32_t x)
43{
44 std::vector<uint32_t> out;
45 uint32_t setbit = 0x1;
46 while (setbit != 0 && x != 0)
47 {
48 if (x & 1) out.push_back(setbit);
49 x = x >> 1;
50 setbit = setbit << 1;
51 }
52 return out;
53}
54
55
56// Returns the first set bit of x, starting from the LSB (0 indexed).
57// Returns -1 if x == 0.
58inline int firstSetBit32(uint32_t x)
59{
60 unsigned bit = 0;
61 while (x)
62 {
63 if (x & 1) return bit;
64 x >>= 1;
65 bit++;
66 }
67 return -1;
68}
69
70
71// Divide x/y, rounding up. x,y can not be 0.
72inline unsigned divUp(unsigned x, unsigned y)
73{
74 // return (x + y - 1) / y; runs risk of overflow
75 return 1 + ((x - 1) / y);
76}
77
78
79// Gray code: https://en.wikipedia.org/wiki/Gray_code#Converting_to_and_from_Gray_code
80inline uint32_t binaryToGray(uint32_t num)
81{
82 return num ^ (num >> 1);
83}
84
85
86inline uint32_t grayToBinary32(uint32_t num)
87{
88 num = num ^ (num >> 16);
89 num = num ^ (num >> 8);
90 num = num ^ (num >> 4);
91 num = num ^ (num >> 2);
92 num = num ^ (num >> 1);
93 return num;
94}
95
96
97
98/*****************************************************************************/
99/* Vectors and Indexing */
100/*****************************************************************************/
101
108std::vector<std::vector<int>> getComboIndices(std::vector<size_t> const & sizes);
109
110
111
112/*****************************************************************************/
113/* RMS95 Value Calculation */
114/*****************************************************************************/
115
122double rms95(TH1 const * h);
123
124// The Hough transform magnetic field correction.
125// Apply correction due to B != 2T everywhere. This correction should be ADDED to track phi.
126double fieldCorrection(unsigned region, double qoverpt, double r);
127
128std::vector<float> computeIdealCoords(const FPGATrackSimHit &hit, const double hough_x, const double hough_y, const double target_r, const bool doDeltaGPhis, const TrackCorrType trackCorrType);
129
130#endif // FPGATrackSimFUNCTIONS_H
std::vector< std::vector< int > > getComboIndices(std::vector< size_t > const &sizes)
Given a vector of sizes (of arrays), generates a vector of all combinations of indices to index one e...
double rms95(TH1 const *h)
This function is used to calculate RMS95 value for 1D histograms.
std::vector< float > computeIdealCoords(const FPGATrackSimHit &hit, const double hough_x, const double hough_y, const double target_r, const bool doDeltaGPhis, const TrackCorrType trackCorrType)
unsigned divUp(unsigned x, unsigned y)
uint32_t grayToBinary32(uint32_t num)
uint32_t binaryToGray(uint32_t num)
int firstSetBit32(uint32_t x)
double fieldCorrection(unsigned region, double qoverpt, double r)
std::vector< uint32_t > splitSetBits32(uint32_t x)
: FPGATrackSim-specific class to represent an hit in the detector.
TrackCorrType
#define y
#define x
Header file for AthHistogramAlgorithm.
int r
Definition globals.cxx:22