ATLAS Offline Software
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 
index
Definition: index.py:1
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
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
FPGATrackSimFunctions.h
h
TH1
Definition: rootspy.cxx:268
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
entries
double entries
Definition: listroot.cxx:49