Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HitSummaryDataUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ACTSTRK_HITSUMMARYDATAUTILS_H
6 #define ACTSTRK_HITSUMMARYDATAUTILS_H
7 
10 #include "InDetIdentifier/SCT_ID.h"
11 
12 #include <vector>
13 #include <cmath>
14 #include <array>
15 #include <tuple>
16 
17 namespace InDetDD {
18  class SiDetectorElementCollection;
19 }
20 
21 namespace ActsTrk::detail {
24  template <typename T_EnumClass >
25  constexpr typename std::underlying_type<T_EnumClass>::type to_underlying(T_EnumClass an_enum) {
26  return static_cast<typename std::underlying_type<T_EnumClass>::type>(an_enum);
27  }
28 
29  namespace HitCategory {
33  N
34  };
35  }
36 
40  public:
49  unknown = 5,
53  Total = 9
54  };
55 
56  constexpr static unsigned short LAYER_REGION_MASK = 0x1FF; // bits 0-8
57  constexpr static unsigned short REGION_BITS = 3; // bits 0-2
58  constexpr static unsigned short REGION_MASK = 0x7; // 3 bits
59  constexpr static unsigned short LAYER_BITS = 6; // bits 3-8
60  constexpr static unsigned short LAYER_MASK = 0x3F; // 6 bits
61  constexpr static unsigned short SIGNED_ETA_MOD_BITS = 7; // bits 9-14 + 15(sign)
62  constexpr static unsigned short SIGNED_ETA_MOD_MASK = 0x7F; // 6 + 1(sign) bit
63 
69  constexpr static unsigned short makeKey(unsigned short region, unsigned short layer, int eta_mod) {
70  // 3 bits region : 0-7 : pixelBarrelFlat - unknown
71  // 6 bits layer : 0-63
72  // 1+6 bits eta_mod : +- 0-63
73  // @TODO endcap side A/C ?
74  assert(region < (1<<REGION_BITS) );
75  assert(layer < (1<<LAYER_BITS));
76  assert( std::abs(eta_mod) < (1<<(SIGNED_ETA_MOD_BITS-1)) );
77  if (region != stripBarrel && region != pixelBarrelFlat) {
78  layer |= (static_cast<uint8_t>(eta_mod) & SIGNED_ETA_MOD_MASK) << LAYER_BITS ;
79  }
80  return static_cast<uint8_t>(region) | (layer<<REGION_BITS);
81  }
82 
85  constexpr static DetectorRegion regionFromKey(unsigned short key) {
86  return static_cast<DetectorRegion>(key & REGION_MASK); // bits 0-2
87  }
88 
91  constexpr static uint8_t layerFromKey(unsigned short key) {
92  return (key>>REGION_BITS) & LAYER_MASK; // bits 3-8
93  }
94 
95  // To select, hits, outliers or both.
97  Hit = 1,
98  Outlier = 2,
99  HitAndOutlier = 3
100  };
101 
104  void reset() {
105  m_stat.clear();
106  std::fill(m_hits.begin(),m_hits.end(), 0u);
107  std::fill(m_outlierHits.begin(),m_outlierHits.end(), 0u);
108  std::fill(m_layers.begin(),m_layers.end(), 0u);
109  }
110 
118  bool addHit(const InDetDD::SiDetectorElementCollection *detector_elements, unsigned int id_hash, EHitSelection hit_selection) {
119  if (!detector_elements || id_hash>=detector_elements->size() || !(*detector_elements)[id_hash]) {
120  return false;
121  }
122  const InDetDD::SiDetectorElement *detEl=(*detector_elements)[id_hash];
123  DetectorRegion region = unknown;
124  uint8_t layer = 255;
125  int eta_module = 0;
126  if (detEl->isPixel()) {
127  InDetDD::DetectorType type = detEl->design().type();
129  else if(type==InDetDD::PixelBarrel) region = pixelBarrelFlat;
130  else region = pixelEndcap;
131 
132  const PixelID* pixel_id = static_cast<const PixelID *>(detEl->getIdHelper());
133  layer = pixel_id->layer_disk(detEl->identify());
134  eta_module = pixel_id->eta_module(detEl->identify());
135  }
136  else if (detEl->isSCT()) {
137  region = (detEl->isBarrel() ? stripBarrel : stripEndcap);
138 
139  const SCT_ID* sct_id = static_cast<const SCT_ID *>(detEl->getIdHelper());
140  layer = sct_id->layer_disk(detEl->identify());
141  eta_module = sct_id->eta_module(detEl->identify());
142  }
143 
144  unsigned short key = makeKey(region, layer, eta_module);
145  for (auto &[stat_key, stat_hits, stat_outlier_hits] : m_stat) {
146  if (stat_key == key) {
147  stat_hits += ((hit_selection & HitSummaryData::Hit)!=0);
148  stat_outlier_hits += ((hit_selection & HitSummaryData::Outlier)!=0);
149  return true;
150  }
151  }
152  m_stat.emplace_back( std::make_tuple(key,
153  ((hit_selection & HitSummaryData::Hit)!=0),
154  ((hit_selection & HitSummaryData::Outlier)!=0)) );
155  return true;
156  }
157 
162  for (const auto &[stat_key, stat_hits, stat_outlier_hits] : m_stat) {
163  unsigned short region=regionFromKey(stat_key);
164  m_hits.at(region) += stat_hits;
165  m_outlierHits.at(region) += stat_outlier_hits;
166  ++m_layers.at(region);
167  }
168  for (unsigned int region_i=0; region_i<unknown+1; ++region_i) {
169  m_hits.at(s_type.at(region_i)) += m_hits[region_i];
170  m_outlierHits.at(s_type.at(region_i)) += m_outlierHits[region_i];
171  m_layers.at(s_type.at(region_i)) += m_layers[region_i];
172  m_hits.at(Total) += m_hits[region_i];
173  m_outlierHits.at(Total) += m_outlierHits[region_i];
174  m_layers.at(Total) += m_layers[region_i];
175  }
176  }
177 
183  return m_layers.at(region);
184  }
185 
191  return m_hits.at(region);
192  }
193 
199  return m_outlierHits.at(region);
200  }
201 
202 
207  template <unsigned short HIT_SELECTION>
209  uint8_t total=0u;
210  unsigned short key = makeKey(region, layer, 0);
211  for (auto &[stat_key, stat_hits, stat_outlier_hits] : m_stat) {
212  if ((stat_key & LAYER_REGION_MASK) == key) {
213  if constexpr(HIT_SELECTION & HitSummaryData::Hit) {
214  total += stat_hits;
215  }
216  if constexpr(HIT_SELECTION & HitSummaryData::Outlier) {
217  total += stat_outlier_hits;
218  }
219  }
220  }
221  return total;
222  }
223 
224  private:
225  std::vector< std::tuple<unsigned short, uint8_t, uint8_t> > m_stat;
226  std::array<uint8_t, Total+1> m_hits;
227  std::array<uint8_t, Total+1> m_outlierHits;
228  std::array<uint8_t, Total+1> m_layers;
229  static constexpr std::array<uint8_t, unknown+1> s_type
231  };
232 
235  class SumOfValues {
236  private:
237  double m_sum = 0.;
238  double m_sum2 = 0.;
239  unsigned int m_n =0u;
240  public:
241  void reset() {
242  m_sum=0.;
243  m_sum2=0.;
244  m_n=0u;
245  }
246  void add(double value) {
247  m_sum += value;
248  m_sum2 += value * value;
249  ++m_n;
250  }
251  std::array<double,2> meanAndBiasedVariance() const {
252  double inv_n = m_n>0 ? 1/m_n : 0 ;
253  double mean = m_sum * inv_n;
254  return std::array<double, 2> { mean, (m_sum2 - m_sum * mean) * inv_n };
255  }
256  double biasedVariance() const {
257  double inv_n = m_n>0 ? 1./m_n : 0 ;
258  return (m_sum2 - m_sum * m_sum *inv_n) * inv_n;
259  }
260  };
261 
272  void gatherTrackSummaryData(const ActsTrk::TrackContainer &tracksContainer,
273  const typename ActsTrk::TrackContainer::ConstTrackProxy &track,
277  &measurement_to_summary_type,
278  SumOfValues &chi2_stat_out,
279  HitSummaryData &hit_info_out,
280  std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType > &param_state_idx_out,
282  to_underlying(xAOD::UncalibMeasType::nTypes)> &special_hit_counts_out);
283 
284 }
285 #endif
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
ActsTrk::detail::HitSummaryData::computeSummaries
void computeSummaries()
Compute the varius summaries.
Definition: HitSummaryDataUtils.h:161
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
ActsTrk::TrackContainer
Definition: TrackContainer.h:31
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
ActsTrk::detail::SumOfValues
Helper class to gather statistics and compute the biased variance.
Definition: HitSummaryDataUtils.h:235
ActsTrk::detail::gatherTrackSummaryData
void gatherTrackSummaryData(const ActsTrk::TrackContainer &tracksContainer, const typename ActsTrk::TrackContainer::ConstTrackProxy &track, const std::array< const InDetDD::SiDetectorElementCollection *, to_underlying(xAOD::UncalibMeasType::nTypes)> &siDetEleColl, const std::array< unsigned short, to_underlying(xAOD::UncalibMeasType::nTypes)> &measurement_to_summary_type, SumOfValues &chi2_stat_out, HitSummaryData &hit_info_out, std::vector< ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType > &param_state_idx_out, std::array< std::array< uint8_t, to_underlying(HitCategory::N)>, to_underlying(xAOD::UncalibMeasType::nTypes)> &special_hit_counts_out)
Helper to gather track summary information from the track states of the specified track.
Definition: HitSummaryDataUtils.cxx:16
ActsTrk::detail::HitSummaryData::contributingHits
uint8_t contributingHits(DetectorRegion region) const
return the number of hits in a certain detector region.
Definition: HitSummaryDataUtils.h:190
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
ActsTrk::detail::to_underlying
constexpr std::underlying_type< T_EnumClass >::type to_underlying(T_EnumClass an_enum)
Helper to convert class enum into an integer.
Definition: HitSummaryDataUtils.h:25
ActsTrk::detail::HitSummaryData::EHitSelection
EHitSelection
Definition: HitSummaryDataUtils.h:96
ActsTrk::detail::HitSummaryData::Hit
@ Hit
Definition: HitSummaryDataUtils.h:97
ActsTrk::detail::HitSummaryData::Outlier
@ Outlier
Definition: HitSummaryDataUtils.h:98
ActsTrk::detail::HitSummaryData::pixelEndcap
@ pixelEndcap
Definition: HitSummaryDataUtils.h:46
ActsTrk::detail::HitSummaryData::LAYER_REGION_MASK
constexpr static unsigned short LAYER_REGION_MASK
Definition: HitSummaryDataUtils.h:56
athena.value
value
Definition: athena.py:124
ActsTrk::detail::HitCategory::DeadSensor
@ DeadSensor
Definition: HitSummaryDataUtils.h:31
ActsTrk::detail::HitSummaryData::SIGNED_ETA_MOD_MASK
constexpr static unsigned short SIGNED_ETA_MOD_MASK
Definition: HitSummaryDataUtils.h:62
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
ActsTrk::detail::HitSummaryData::makeKey
constexpr static unsigned short makeKey(unsigned short region, unsigned short layer, int eta_mod)
Compute a counter key for the given region, layer and module eta module index.
Definition: HitSummaryDataUtils.h:69
InDetDD::SolidStateDetectorElementBase::getIdHelper
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline)
InDetDD::PixelInclined
@ PixelInclined
Definition: DetectorDesign.h:46
ActsTrk::detail::HitSummaryData::s_type
static constexpr std::array< uint8_t, unknown+1 > s_type
Definition: HitSummaryDataUtils.h:230
ActsTrk::detail::HitSummaryData::REGION_MASK
constexpr static unsigned short REGION_MASK
Definition: HitSummaryDataUtils.h:58
ActsTrk::detail::HitSummaryData::m_outlierHits
std::array< uint8_t, Total+1 > m_outlierHits
Definition: HitSummaryDataUtils.h:227
Hit
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloGpu/ISF_FastCaloGpu/Hit.h:16
ActsTrk::detail::HitSummaryData::SIGNED_ETA_MOD_BITS
constexpr static unsigned short SIGNED_ETA_MOD_BITS
Definition: HitSummaryDataUtils.h:61
ActsTrk::detail::HitSummaryData
Helper class to gather hit summary information for e.g.
Definition: HitSummaryDataUtils.h:39
ActsTrk::detail::HitSummaryData::contributingOutlierHits
uint8_t contributingOutlierHits(DetectorRegion region) const
return the number of outliers in a certain detector region.
Definition: HitSummaryDataUtils.h:198
ActsTrk::detail::HitSummaryData::addHit
bool addHit(const InDetDD::SiDetectorElementCollection *detector_elements, unsigned int id_hash, EHitSelection hit_selection)
update summaries to take the given hit into account.
Definition: HitSummaryDataUtils.h:118
InDetDD::DetectorType
DetectorType
Definition: DetectorDesign.h:45
ActsTrk::detail::HitSummaryData::m_hits
std::array< uint8_t, Total+1 > m_hits
Definition: HitSummaryDataUtils.h:226
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
ActsTrk::detail::HitSummaryData::contributingLayers
uint8_t contributingLayers(DetectorRegion region) const
return the number of layers contributing to the hit collection in the given detector region.
Definition: HitSummaryDataUtils.h:182
ActsTrk::detail::HitCategory::N
@ N
Definition: HitSummaryDataUtils.h:33
ActsTrk::detail::HitSummaryData::unknown
@ unknown
Definition: HitSummaryDataUtils.h:49
InDetDD::DetectorDesign::type
virtual DetectorType type() const
Type of element.
Definition: DetectorDesign.cxx:101
ActsTrk::detail::HitSummaryData::Total
@ Total
Definition: HitSummaryDataUtils.h:53
ActsTrk::detail::HitSummaryData::pixelBarrelFlat
@ pixelBarrelFlat
Definition: HitSummaryDataUtils.h:44
ActsTrk::detail::HitSummaryData::layerFromKey
constexpr static uint8_t layerFromKey(unsigned short key)
extract the layer index from the given key.
Definition: HitSummaryDataUtils.h:91
ActsTrk::detail::HitCategory::ESpecialHitCategories
ESpecialHitCategories
Definition: HitSummaryDataUtils.h:30
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
InDetDD::SiDetectorElement::isPixel
bool isPixel() const
lumiFormat.array
array
Definition: lumiFormat.py:91
ActsTrk::detail::HitSummaryData::sum
uint8_t sum(DetectorRegion region, uint8_t layer) const
return the total number of hits, outliers or hits+outliers in the givrn detector region and layer.
Definition: HitSummaryDataUtils.h:208
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
xAOD::UncalibMeasType::nTypes
@ nTypes
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
InDetDD::PixelBarrel
@ PixelBarrel
Definition: DetectorDesign.h:46
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
ActsTrk::detail::HitSummaryData::LAYER_MASK
constexpr static unsigned short LAYER_MASK
Definition: HitSummaryDataUtils.h:60
InDetDD::SiDetectorElement::isBarrel
bool isBarrel() const
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:194
SiDetectorElement.h
ActsTrk::detail::HitSummaryData::HitAndOutlier
@ HitAndOutlier
Definition: HitSummaryDataUtils.h:99
ActsTrk::detail::HitSummaryData::stripTotal
@ stripTotal
Definition: HitSummaryDataUtils.h:51
ActsTrk::detail::HitSummaryData::pixelBarrelInclined
@ pixelBarrelInclined
Definition: HitSummaryDataUtils.h:45
ActsTrk::detail::HitSummaryData::REGION_BITS
constexpr static unsigned short REGION_BITS
Definition: HitSummaryDataUtils.h:57
ActsTrk::detail::HitSummaryData::stripBarrel
@ stripBarrel
Definition: HitSummaryDataUtils.h:47
SCT_ID
Definition: SCT_ID.h:68
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
ActsTrk::detail::SumOfValues::biasedVariance
double biasedVariance() const
Definition: HitSummaryDataUtils.h:256
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
ActsTrk::detail::HitSummaryData::m_layers
std::array< uint8_t, Total+1 > m_layers
Definition: HitSummaryDataUtils.h:228
ActsTrk::detail::HitSummaryData::regionFromKey
constexpr static DetectorRegion regionFromKey(unsigned short key)
extract the region index from the given key.
Definition: HitSummaryDataUtils.h:85
InDetDD::SiDetectorElement::isSCT
bool isSCT() const
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ActsTrk::detail::HitSummaryData::LAYER_BITS
constexpr static unsigned short LAYER_BITS
Definition: HitSummaryDataUtils.h:59
ActsTrk::detail
Definition: Decoration.h:15
ActsTrk::detail::HitCategory::Hole
@ Hole
Definition: HitSummaryDataUtils.h:32
ActsTrk::detail::HitSummaryData::pixelTotal
@ pixelTotal
Definition: HitSummaryDataUtils.h:50
ActsTrk::detail::SumOfValues::reset
void reset()
Definition: HitSummaryDataUtils.h:241
ActsTrk::detail::SumOfValues::m_sum
double m_sum
Definition: HitSummaryDataUtils.h:237
InDetDD::SiDetectorElement::design
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
ActsTrk::detail::HitSummaryData::DetectorRegion
DetectorRegion
Regions for which hit counts are computed.
Definition: HitSummaryDataUtils.h:43
ActsTrk::detail::HitSummaryData::stripEndcap
@ stripEndcap
Definition: HitSummaryDataUtils.h:48
PixelID
Definition: PixelID.h:67
ActsTrk::detail::HitSummaryData::unknownTotal
@ unknownTotal
Definition: HitSummaryDataUtils.h:52
ActsTrk::detail::SumOfValues::m_sum2
double m_sum2
Definition: HitSummaryDataUtils.h:238
ActsTrk::detail::SumOfValues::add
void add(double value)
Definition: HitSummaryDataUtils.h:246
ActsTrk::detail::HitSummaryData::m_stat
std::vector< std::tuple< unsigned short, uint8_t, uint8_t > > m_stat
Definition: HitSummaryDataUtils.h:225
InDetDD::SolidStateDetectorElementBase::identify
virtual Identifier identify() const override final
identifier of this detector element (inline)
ActsTrk::detail::SumOfValues::m_n
unsigned int m_n
Definition: HitSummaryDataUtils.h:239
ActsTrk::detail::HitSummaryData::reset
void reset()
reset all summary counters to zero.
Definition: HitSummaryDataUtils.h:104
ActsTrk::detail::SumOfValues::meanAndBiasedVariance
std::array< double, 2 > meanAndBiasedVariance() const
Definition: HitSummaryDataUtils.h:251
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37