ATLAS Offline Software
AmbiCounter.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TrkAmbiguityProcessor_AmbiCounter_icc
6 #define TrkAmbiguityProcessor_AmbiCounter_icc
7 #include <array>
8 #include <vector>
9 #include <string>
10 #include "TrkTrack/Track.h"
11 #include <stdexcept>
12 #include <algorithm>
13 #include <optional>
14 
15 template<class EnumType>
16 class AmbiCounter {
17 public:
18  using Categories = EnumType;
25  };
26  //
27  AmbiCounter(const std::vector<float> &eta_bounds): m_etaBounds(eta_bounds){
28  const std::string errMsgPrefix = "In AmbiCounter.icc, eta_bounds size must be ";
29  if (m_etaBounds.size()!=nRegions) throw std::runtime_error(errMsgPrefix + std::to_string(nRegions) + " elements long.");
30  if (not std::is_sorted(m_etaBounds.begin(), m_etaBounds.end())){
31  throw std::runtime_error(errMsgPrefix + "in ascending order.");
32  }
33  }
34 
35  //convert Category to array index
36  size_t
37  idx(const Categories & categoryIndex) const{
38  return static_cast<size_t>(categoryIndex);
39  }
40 
41  void
43  m_globalCounter.fill(0);
44  }
45 
46  //increment event count
47  void
50  }
51 
52  //return number of events
53  int
54  numberOfEvents() const{
55  return m_globalCounter[nEvents];
56  }
57  // increment one bin
58  void
59  increment(Categories category, unsigned int etaBinIdx) {
60  if ((category>= Categories::kNCounter) or (etaBinIdx >=nRegions)){
61  throw std::out_of_range("in AmbiCounter.icc::increment()");
62  }
63  ++m_counter[idx(category)][etaBinIdx];
64  }
65  //
67  for (unsigned int i=0; i<nGlobalCounters; ++i) {
68  m_globalCounter[i]+= a.m_globalCounter[i];
69  }
70  for (size_t categoryIdx=0; categoryIdx < idx(Categories::kNCounter); ++categoryIdx) {
71  for (unsigned int etaBinIdx=0; etaBinIdx < a.m_counter[categoryIdx].size(); ++etaBinIdx) {
72  m_counter[categoryIdx][etaBinIdx] += a.m_counter[categoryIdx][etaBinIdx];
73  }
74  }
75  return *this;
76 }
77  //
79  // test
80  if (!track) {
82  return;
83  }
84  // use first parameter
85  if (!track->trackParameters()) {
87  } else {
88  std::array<int, nRegions> &nTracks = m_counter.at(idx(categoryIdx));
89  // @TODO make sure that list of track parameters is not empty
90  const double absEta = std::abs(track->trackParameters()->front()->eta());
91  if (const auto &possibleIdx{etaBin(absEta)}){//i.e. if it's within bounds
92  ++nTracks[possibleIdx.value()];
93  }
94  }
95  }
96  //
97  std::string
98  dumpRegions(const std::string & head,Categories categoryIdx, const int iw =9) const {
99  std::stringstream out;
100  out << head;
101  if (categoryIdx >= Categories::kNCounter) throw std::out_of_range("Array index out of range in AmbiCounter::inc by region");
102  const auto & displayedArray = m_counter[idx(categoryIdx)];
103  const auto allRegionCounts = std::accumulate(displayedArray.begin(), displayedArray.end(),0);
104  out << std::setiosflags(std::ios::dec) << std::setw(iw) << allRegionCounts;
105  for (unsigned int etaBinIdx=0; etaBinIdx < nRegions; ++etaBinIdx) {
106  out << std::setiosflags(std::ios::dec) << std::setw(iw) << m_counter[idx(categoryIdx)][etaBinIdx];
107  }
108  out << "\n";
109  return out.str();
110  }
111  //
112  int
114  return m_globalCounter[i];
115  }
116 
117 private:
118  std::array<std::array<int, nRegions>,static_cast<size_t>(Categories::kNCounter)> m_counter{};
119  std::array<int,nGlobalCounters> m_globalCounter{};
120  const std::vector<float> &m_etaBounds;
121  std::optional<size_t>
122  etaBin(const double val){
123  auto pVal = std::lower_bound(m_etaBounds.begin(), m_etaBounds.end(), val);
124  //if it's in bounds, return the value, otherwise return a nullopt
125  return (pVal!=m_etaBounds.end()) ? std::optional<size_t>(std::distance(m_etaBounds.begin(), pVal)):std::nullopt;
126  }
127 };
128 
129 #endif
AmbiCounter::iEndcap
@ iEndcap
Definition: AmbiCounter.h:19
AmbiCounter::iFWD
@ iFWD
Definition: AmbiCounter.h:19
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
AmbiCounter::idx
size_t idx(const Categories &categoryIndex) const
Definition: AmbiCounter.h:37
AmbiCounter::RegionIndex
RegionIndex
Definition: AmbiCounter.h:19
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
AmbiCounter::iForwrd
@ iForwrd
Definition: AmbiCounter.h:19
AmbiCounter::nInvalidTracks
@ nInvalidTracks
Definition: AmbiCounter.h:22
AmbiCounter::incrementCounterByRegion
void incrementCounterByRegion(Categories categoryIdx, const Trk::Track *track)
Definition: AmbiCounter.h:78
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
AmbiCounter::iTransi
@ iTransi
Definition: AmbiCounter.h:19
AmbiCounter::globalCount
int globalCount(GlobalCounterIndices i) const
Definition: AmbiCounter.h:113
AmbiCounter::nRegions
@ nRegions
Definition: AmbiCounter.h:19
Track.h
AmbiCounter::m_globalCounter
std::array< int, nGlobalCounters > m_globalCounter
Definition: AmbiCounter.h:119
AmbiCounter::nTracksWithoutParam
@ nTracksWithoutParam
Definition: AmbiCounter.h:23
AmbiCounter::resetGlobalCounters
void resetGlobalCounters()
Definition: AmbiCounter.h:42
AmbiCounter::GlobalCounterIndices
GlobalCounterIndices
Definition: AmbiCounter.h:20
AmbiCounter::newEvent
void newEvent()
Definition: AmbiCounter.h:48
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReweightUtils.category
category
Definition: ReweightUtils.py:15
AmbiCounter::m_counter
std::array< std::array< int, nRegions >, static_cast< size_t >Categories::kNCounter)> m_counter
Definition: AmbiCounter.h:118
AmbiCounter::etaBin
std::optional< size_t > etaBin(const double val)
Definition: AmbiCounter.h:122
AmbiCounter::numberOfEvents
int numberOfEvents() const
Definition: AmbiCounter.h:54
head
std::string head(std::string s, const std::string &pattern)
head of a string
Definition: computils.cxx:310
AmbiCounter::nGlobalCounters
@ nGlobalCounters
Definition: AmbiCounter.h:24
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AmbiCounter::nEvents
@ nEvents
Definition: AmbiCounter.h:21
AmbiCounter::increment
void increment(Categories category, unsigned int etaBinIdx)
Definition: AmbiCounter.h:59
AmbiCounter::AmbiCounter
AmbiCounter(const std::vector< float > &eta_bounds)
Definition: AmbiCounter.h:27
AmbiCounter::iBarrel
@ iBarrel
Definition: AmbiCounter.h:19
a
TList * a
Definition: liststreamerinfos.cxx:10
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
AmbiCounter::dumpRegions
std::string dumpRegions(const std::string &head, Categories categoryIdx, const int iw=9) const
Definition: AmbiCounter.h:98
AmbiCounter::m_etaBounds
const std::vector< float > & m_etaBounds
eta intervals for internal monitoring
Definition: AmbiCounter.h:120
TauGNNUtils::Variables::absEta
bool absEta(const xAOD::TauJet &tau, double &out)
Definition: TauGNNUtils.cxx:234
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
AmbiCounter::operator+=
AmbiCounter< EnumType > & operator+=(const AmbiCounter< EnumType > &a)
Definition: AmbiCounter.h:66
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
AmbiCounter::Categories
EnumType Categories
Definition: AmbiCounter.h:18
AmbiCounter
Definition: AmbiCounter.h:16