ATLAS Offline Software
PufitUtils.icc
Go to the documentation of this file.
1 /**
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 namespace HLT
6 {
7  namespace MET
8  {
9  namespace PufitUtils
10  {
11  template <std::size_t N>
12  void trimmedMeanAndVariance(
13  const PufitMultiGrid<N> &grid,
14  std::size_t type,
15  double trimFraction,
16  double &mean,
17  double &variance)
18  {
19  // Construct a list of sorted tower energies
20  std::vector<double> sorted;
21  sorted.reserve(grid.nTowers());
22  for (const typename PufitMultiGrid<N>::Tower &tower : grid)
23  {
24  double sumEt = tower.sumEt(type);
25  sorted.insert(
26  std::lower_bound(sorted.begin(), sorted.end(), sumEt),
27  sumEt);
28  }
29  trimmedMeanAndVariance(sorted, trimFraction, mean, variance);
30  }
31 
32  template <std::size_t N>
33  void unmaskedMeanAndVariance(
34  const PufitMultiGrid<N> &grid, std::size_t type, double &mean, double &variance)
35  {
36  double sum = 0;
37  double squaredSum = 0;
38  std::size_t n = 0;
39  for (const typename PufitMultiGrid<N>::Tower &tower : grid)
40  {
41  if (tower.masked())
42  continue;
43  ++n;
44  double sumEt = tower.sumEt(type);
45  sum += sumEt;
46  squaredSum += sumEt * sumEt;
47  }
48  mean = sum / n;
49  variance = squaredSum / n - mean * mean;
50  }
51 
52  template <typename Grid>
53  GridDisplacement selectGrid(
54  const PufitMultiGridSet<Grid> &grids, std::size_t type)
55  {
56  GridDisplacement maximum = NoDisplacement;
57  double maxSum = 0;
58  for (std::size_t d = 0; d < 4; ++d)
59  {
60  double sum = 0;
61  for (const typename Grid::Tower &tower : grids[GridDisplacement(d)])
62  if (tower.masked())
63  sum += tower.sumEt(type);
64  if (sum > maxSum)
65  {
66  maximum = GridDisplacement(d);
67  maxSum = sum;
68  }
69  }
70  return maximum;
71  }
72  } // namespace PufitUtils
73  } // namespace MET
74 } // namespace HLT