Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FPGATrackSimFunctions.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 
21 std::vector<std::vector<int>> getComboIndices(std::vector<size_t> const & sizes)
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 }
52 
53 
60 double rms95(TH1 const * h)
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 }
114 
115 
116 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) {
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 }
161 // This is the magnetic field correction for the Hough transform tools
162 // and related algorithms, parametrized by region number.
163 double fieldCorrection(unsigned region, double qpt, double r)
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 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
fieldCorrection
double fieldCorrection(unsigned region, double qpt, double r)
Definition: FPGATrackSimFunctions.cxx:163
index
Definition: index.py:1
TrackCorrType::Second
@ Second
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:144
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
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: FPGATrackSimFunctions.cxx:116
getComboIndices
std::vector< std::vector< int > > getComboIndices(std::vector< size_t > const &sizes)
Given a list of sizes (of arrays), generates a list of all combinations of indices to index one eleme...
Definition: FPGATrackSimFunctions.cxx:21
rms95
double rms95(TH1 const *h)
This function is used to calculate RMS95 value for 1D histograms.
Definition: FPGATrackSimFunctions.cxx:60
FPGATrackSimHit::getZ
float getZ() const
Definition: FPGATrackSimHit.h:142
FPGATrackSimFunctions.h
FPGATrackSimHit::getR
float getR() const
Definition: FPGATrackSimHit.h:143
h
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
entries
double entries
Definition: listroot.cxx:49
TrackCorrType
TrackCorrType
Definition: FPGATrackSimTypes.h:37
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
FPGATrackSimHit::getGCotTheta
float getGCotTheta() const
Definition: FPGATrackSimHit.h:145
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65