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 <cmath>
#include <vector>
#include <sstream>
This graph shows which files directly or indirectly include this file:

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...
 

Function Documentation

◆ binaryToGray()

uint32_t binaryToGray ( uint32_t  num)
inline

Definition at line 78 of file FPGATrackSimFunctions.h.

79 {
80  return num ^ (num >> 1);
81 }

◆ divUp()

unsigned divUp ( unsigned  x,
unsigned  y 
)
inline

Definition at line 70 of file FPGATrackSimFunctions.h.

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

◆ firstSetBit32()

int firstSetBit32 ( uint32_t  x)
inline

Definition at line 56 of file FPGATrackSimFunctions.h.

57 {
58  unsigned bit = 0;
59  while (x)
60  {
61  if (x & 1) return bit;
62  x >>= 1;
63  bit++;
64  }
65  return -1;
66 }

◆ 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 84 of file FPGATrackSimFunctions.h.

85 {
86  num = num ^ (num >> 16);
87  num = num ^ (num >> 8);
88  num = num ^ (num >> 4);
89  num = num ^ (num >> 2);
90  num = num ^ (num >> 1);
91  return num;
92 }

◆ 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 40 of file FPGATrackSimFunctions.h.

41 {
42  std::vector<uint32_t> out;
43  uint32_t setbit = 0x1;
44  while (setbit != 0 && x != 0)
45  {
46  if (x & 1) out.push_back(setbit);
47  x = x >> 1;
48  setbit = setbit << 1;
49  }
50  return out;
51 }
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
x
#define x
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:92
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:256
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
y
#define y
h
TH1
Definition: rootspy.cxx:268
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
entries
double entries
Definition: listroot.cxx:49