ATLAS Offline Software
Functions
FPGATrackSimFunctions.h File Reference
#include <TString.h>
#include <TObjArray.h>
#include <TH1.h>
#include <TObjString.h>
#include <TTreeReader.h>
#include <TTreeReaderValue.h>
#include "FPGATrackSimObjects/FPGATrackSimTypes.h"
#include "FPGATrackSimObjects/FPGATrackSimHit.h"
#include <cmath>
#include <vector>
#include <sstream>

Go to the source code of this file.

Functions

std::vector< uint32_t > splitSetBits32 (uint32_t x)
 
int firstSetBit32 (uint32_t x)
 
unsigned divUp (unsigned x, unsigned y)
 
uint32_t binaryToGray (uint32_t num)
 
uint32_t grayToBinary32 (uint32_t num)
 
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 element from each array. More...
 
double rms95 (TH1 const *h)
 This function is used to calculate RMS95 value for 1D histograms. More...
 
double fieldCorrection (unsigned region, double qpt, double r)
 
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)
 

Function Documentation

◆ binaryToGray()

uint32_t binaryToGray ( uint32_t  num)
inline

Definition at line 80 of file FPGATrackSimFunctions.h.

81 {
82  return num ^ (num >> 1);
83 }

◆ computeIdealCoords()

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 
)

Definition at line 116 of file FPGATrackSimFunctions.cxx.

116  {
117 
118  std::vector<float> idealized_coordinates;
119 
120  float hitGPhi = (float) hit.getGPhi();
121  float hitZ = (float) hit.getZ();
122 
123  // rho = 0.33 m * (pT / GeV) / (B/T)
124  // B = 2 T so
125  // rho = 0.33 m * (pT / GeV) / (2)
126  double houghRho = 0.0003 * hough_y; //A*q/pT
127 
128  hitGPhi += (hit.getR() - target_r) * houghRho; //first order
129 
130  if (trackCorrType == TrackCorrType::Second) {
131  hitGPhi += (pow(hit.getR() * houghRho, 3.0) / 6.0); //higher order
132  }
133 
134  if (hit.getR() > 1e-8) {
135  hitZ -= hit.getGCotTheta() * (hit.getR() - target_r); //first order
136  if (trackCorrType == TrackCorrType::Second)
137  hitZ -= (hit.getGCotTheta() * std::pow(hit.getR(), 3.0) * houghRho * houghRho) / 6.0; //higher order
138  }
139 
140  idealized_coordinates.push_back(hitZ);
141 
142  if (doDeltaGPhis) {
143  double expectedGPhi = hough_x;
144 
145  expectedGPhi -= target_r * houghRho; //first order
146 
147  if (trackCorrType == TrackCorrType::Second) {
148  expectedGPhi -= (std::pow(target_r * houghRho, 3.0) / 6.0); //higher order
149  }
150 
151  idealized_coordinates.push_back(hitGPhi - expectedGPhi);
152  }
153  else {
154  idealized_coordinates.push_back(hitGPhi);
155  }
156 
157 
158  return idealized_coordinates;
159 
160 }

◆ divUp()

unsigned divUp ( unsigned  x,
unsigned  y 
)
inline

Definition at line 72 of file FPGATrackSimFunctions.h.

73 {
74  // return (x + y - 1) / y; runs risk of overflow
75  return 1 + ((x - 1) / y);
76 }

◆ fieldCorrection()

double fieldCorrection ( unsigned  region,
double  qpt,
double  r 
)

Definition at line 163 of file FPGATrackSimFunctions.cxx.

164 {
165  r = r / 1000; // convert to meters
166  if (region == 3)
167  {
168  double cor = 0.1216 * r * r - 0.0533 * r + 0.0069;
169  return -cor * qpt;
170  }
171  else if (region == 4)
172  {
173  double cor = 0.4265 * r * r - 0.0662 * r + 0.0036;
174  return -cor * qpt;
175  }
176  else return 0;
177 }

◆ firstSetBit32()

int firstSetBit32 ( uint32_t  x)
inline

Definition at line 58 of file FPGATrackSimFunctions.h.

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 }

◆ getComboIndices()

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 element from each array.

For example, given [2 3], generates [(0 0) (1 0) (0 1) (1 1) (0 2) (1 2)].

Given a vector of sizes (of arrays), generates a vector of all combinations of indices to index one element from each array.

For example, given [2 3], generates [(0 0) (1 0) (0 1) (1 1) (0 2) (1 2)].

This basically amounts to a positional number system of where each digit has its own base. The number of digits is sizes.size(), and the base of digit i is sizes[i]. Then all combinations can be uniquely represented just by counting from [0, nCombs).

For a decimal number like 1357, you get the thousands digit with n / 1000 = n / (10 * 10 * 10). So here, you get the 0th digit with n / (base_1 * base_2 * base_3);

Definition at line 21 of file FPGATrackSimFunctions.cxx.

22 {
23  size_t nCombs = 1;
24  std::vector<size_t> nCombs_prior(sizes.size());
25  std::vector<int> temp(sizes.size(), 0);
26 
27  for (size_t i = 0; i < sizes.size(); i++)
28  {
29  if (sizes[i] > 0)
30  {
31  nCombs_prior[i] = nCombs;
32  nCombs *= sizes[i];
33  }
34  else temp[i] = -1;
35  }
36 
37  std::vector<std::vector<int>> combos(nCombs, temp);
38 
39  for (size_t icomb = 0; icomb < nCombs; icomb++)
40  {
41  size_t index = icomb;
42  for (size_t isize = sizes.size() - 1; isize < sizes.size(); isize--)
43  {
44  if (sizes[isize] == 0) continue;
45  combos[icomb][isize] = static_cast<int>(index / nCombs_prior[isize]);
46  index = index % nCombs_prior[isize];
47  }
48  }
49 
50  return combos;
51 }

◆ grayToBinary32()

uint32_t grayToBinary32 ( uint32_t  num)
inline

Definition at line 86 of file FPGATrackSimFunctions.h.

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 }

◆ rms95()

double rms95 ( TH1 const h)

This function is used to calculate RMS95 value for 1D histograms.

It was ported from https://gitlab.cern.ch:8443/fpastore/l1tracksim/-/blob/master/PatRec/macros/FraMacros/Functions.cxx#L253 See more details there.

Definition at line 60 of file FPGATrackSimFunctions.cxx.

61 {
62  double const frac = 0.95;
63  double entries = h->Integral(0, h->GetNbinsX() + 1);
64 
65  // Not enough entries for this fraction, i.e. we want 0.95 then need 5% to be 1 events, so need at least 20 events.
66  if ((1.0 - frac) * entries < 1 || entries == 0) return h->GetRMS();
67 
68  TH1* h_tmp = dynamic_cast<TH1*>(h->Clone());
69  if (not h_tmp){
70  throw "dynamic_cast failure in FPGATrackSimFunctions rms95(TH1*)";
71  }
72  h_tmp->GetXaxis()->SetRange(1, h_tmp->GetNbinsX());
73 
74  int meanbin = h->GetXaxis()->FindBin(h_tmp->GetMean());
75  int lowerbin = meanbin;
76  int upperbin = meanbin;
77 
78  double sum = h->GetBinContent(meanbin);
79  double lowerfrac = 0;
80  double upperfrac = 0;
81 
82  int i = 1;
83  while (true) {
84  int this_lowerbin = meanbin - i;
85  int this_upperbin = meanbin + i;
86  if (this_lowerbin < 1 || this_upperbin > h->GetNbinsX()) break;
87 
88  sum += h_tmp->GetBinContent(this_lowerbin) + h_tmp->GetBinContent(this_upperbin);
89  if (sum >= entries * frac) break;
90 
91  lowerfrac = sum / entries;
92  lowerbin = this_lowerbin;
93  upperbin = this_upperbin;
94 
95  i++;
96  }
97  upperfrac = sum / entries;
98 
99  if (upperfrac == lowerfrac) return h->GetRMS();
100 
101  double rms_lower = 0;
102  double rms_upper = 0;
103 
104  h_tmp->GetXaxis()->SetRange(lowerbin, upperbin);
105  rms_lower = h_tmp->GetRMS();
106 
107  h_tmp->GetXaxis()->SetRange(lowerbin - 1, upperbin + 1);
108  rms_upper = h_tmp->GetRMS();
109 
110  double rms = rms_lower + (frac - lowerfrac) * (rms_upper - rms_lower) / (upperfrac - lowerfrac);
111 
112  return rms * 1.1479538518;
113 }

◆ splitSetBits32()

std::vector<uint32_t> splitSetBits32 ( uint32_t  x)
inline

Definition at line 42 of file FPGATrackSimFunctions.h.

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 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
TrackCorrType::Second
@ Second
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
x
#define x
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:141
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:85
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:259
FPGATrackSimHit::getZ
float getZ() const
Definition: FPGATrackSimHit.h:139
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
FPGATrackSimHit::getR
float getR() const
Definition: FPGATrackSimHit.h:140
y
#define y
h
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
entries
double entries
Definition: listroot.cxx:49
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
readCCLHist.float
float
Definition: readCCLHist.py:83
FPGATrackSimHit::getGCotTheta
float getGCotTheta() const
Definition: FPGATrackSimHit.h:142