ATLAS Offline Software
TableUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
5 
6 namespace TableUtils {
7 
8  std::size_t computeSum( const std::vector< SummandDefinition > &sum_def,
9  std::size_t eta_offset,
10  std::size_t row_stride,
11  std::size_t seed_i,
12  const std::vector<std::size_t> &stat) {
13  std::size_t sum=0;
14  for (const SummandDefinition &summand : sum_def ) {
15  assert( eta_offset + row_stride * summand.first + seed_i < stat.size() );
16  sum += stat[eta_offset + row_stride * summand.first + seed_i ] * summand.second;
17  }
18  return sum;
19  }
20 
21  std::vector<float> computeRatios(const std::vector<RatioDefinition> &ratio_def,
22  const std::size_t categories,
23  const std::size_t sub_categories,
24  const std::vector< std::size_t> &counter)
25  {
26  std::vector<float> ratio;
27  if (counter.size() % (categories*sub_categories) ) {
28  std::stringstream msg;
29  msg << "Category and sub category dimensions " << categories << " * " << sub_categories
30  << " not a common factor of the input counter vector "
31  << counter.size();
32  throw std::logic_error(msg.str());
33  }
34  std::size_t n_counter = counter.size() / (categories*sub_categories);
35  ratio.resize( categories * ratio_def.size() * sub_categories);
36 
37  std::size_t input_counter_stride=categories;
38  std::size_t input_sub_category_stride = categories * n_counter;
39  std::size_t ratio_stride = categories;
40  std::size_t ratio_sub_category_stride = ratio_stride * ratio_def.size();
41 
42  for (std::size_t sub_category_i=0; sub_category_i < sub_categories; ++sub_category_i) {
43  for (std::size_t ratio_i=0; ratio_i<ratio_def.size(); ++ratio_i) {
44  for (std::size_t category_i=0; category_i<categories; ++category_i) {
45  std::size_t ratio_dest_idx = sub_category_i * ratio_sub_category_stride + ratio_stride * ratio_i + category_i;
46  assert(ratio_dest_idx < ratio.size());
47  assert( sub_category_i * input_sub_category_stride < counter.size() );
48  assert( sub_category_i * input_sub_category_stride + n_counter * input_counter_stride <= counter.size() );
49  ratio[ratio_dest_idx] = computeRatio( ratio_def.at(ratio_i),
50  sub_category_i * input_sub_category_stride,
51  input_counter_stride,
52  category_i,
53  counter);
54  }
55  }
56  }
57  return ratio;
58  }
59 }
TableUtils
Definition: TableUtils.h:22
TableUtils::computeSum
std::size_t computeSum(const std::vector< SummandDefinition > &sum_def, std::size_t eta_offset, std::size_t row_stride, std::size_t seed_i, const std::vector< std::size_t > &stat)
Definition: TableUtils.cxx:8
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
beamspotman.stat
stat
Definition: beamspotman.py:266
mergePhysValFiles.categories
list categories
Definition: PhysicsAnalysis/JetTagging/JetTagValidation/JetTagDQA/scripts/mergePhysValFiles.py:18
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
TableUtils.h
TableUtils::computeRatios
std::vector< float > computeRatios(const std::vector< RatioDefinition > &ratio_def, const std::size_t categories, const std::size_t sub_categories, const std::vector< std::size_t > &counter)
Definition: TableUtils.cxx:21
test_pyathena.counter
counter
Definition: test_pyathena.py:15
TableUtils::SummandDefinition
std::pair< std::size_t, int > SummandDefinition
Definition: TableUtils.h:374
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TableUtils::computeRatio
float computeRatio(std::size_t numerator, std::size_t denominator)
Definition: TableUtils.h:412