ATLAS Offline Software
Loading...
Searching...
No Matches
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
13
14#include <vector>
15#include <cmath>
16#include <array>
17#include <tuple>
18#include <type_traits>
19
20namespace ActsTrk::detail {
21 enum class HitCategory: std::uint8_t {
25 };
26
30 public:
45
46 constexpr static unsigned short LAYER_REGION_MASK = 0x1FF; // bits 0-8
47 constexpr static unsigned short REGION_BITS = 3; // bits 0-2
48 constexpr static unsigned short REGION_MASK = 0x7; // 3 bits
49 constexpr static unsigned short LAYER_BITS = 6; // bits 3-8
50 constexpr static unsigned short LAYER_MASK = 0x3F; // 6 bits
51 constexpr static unsigned short SIGNED_ETA_MOD_BITS = 7; // bits 9-14 + 15(sign)
52 constexpr static unsigned short SIGNED_ETA_MOD_MASK = 0x7F; // 6 + 1(sign) bit
53
59 constexpr static unsigned short makeKey(unsigned short region, unsigned short layer, int eta_mod) {
60 // 3 bits region : 0-7 : pixelBarrelFlat - unknown
61 // 6 bits layer : 0-63
62 // 1+6 bits eta_mod : +- 0-63
63 // @TODO endcap side A/C ?
64 assert(region < (1<<REGION_BITS) );
65 assert(layer < (1<<LAYER_BITS));
66 assert( std::abs(eta_mod) < (1<<(SIGNED_ETA_MOD_BITS-1)) );
67 if (region != stripBarrel && region != pixelBarrelFlat) {
68 layer |= (static_cast<uint8_t>(eta_mod) & SIGNED_ETA_MOD_MASK) << LAYER_BITS ;
69 }
70 return static_cast<uint8_t>(region) | (layer<<REGION_BITS);
71 }
72
75 constexpr static DetectorRegion regionFromKey(unsigned short key) {
76 return static_cast<DetectorRegion>(key & REGION_MASK); // bits 0-2
77 }
78
81 constexpr static uint8_t layerFromKey(unsigned short key) {
82 return (key>>REGION_BITS) & LAYER_MASK; // bits 3-8
83 }
84
85 // To select, hits, outliers, and/or shared hits.
92
95 void reset() {
96 m_stat.clear();
97 std::fill(m_hits.begin(),m_hits.end(), 0u);
98 std::fill(m_outlierHits.begin(),m_outlierHits.end(), 0u);
99 std::fill(m_sharedHits.begin(),m_sharedHits.end(), 0u);
100 std::fill(m_layers.begin(),m_layers.end(), 0u);
101 }
102
111 EHitSelection hit_selection) {
112 if (!detEl) {
113 return false;
114 }
115 DetectorRegion region = unknown;
116 uint8_t layer = 255;
117 int eta_module = 0;
118 if (detEl->isPixel()) {
121 else if(type==InDetDD::PixelBarrel) region = pixelBarrelFlat;
122 else region = pixelEndcap;
123
124 const PixelID* pixel_id = static_cast<const PixelID *>(detEl->getIdHelper());
125 layer = pixel_id->layer_disk(detEl->identify());
126 eta_module = pixel_id->eta_module(detEl->identify());
127 }
128 else if (detEl->isSCT()) {
129 region = (detEl->isBarrel() ? stripBarrel : stripEndcap);
130
131 const SCT_ID* sct_id = static_cast<const SCT_ID *>(detEl->getIdHelper());
132 layer = sct_id->layer_disk(detEl->identify());
133 eta_module = sct_id->eta_module(detEl->identify());
134 }
135
136 unsigned short key = makeKey(region, layer, eta_module);
137 for (auto &[stat_key, stat_hits, stat_outlier_hits, stat_shared_hits] : m_stat) {
138 if (stat_key == key) {
139 stat_hits += ((hit_selection & HitSummaryData::Hit)!=0);
140 stat_outlier_hits += ((hit_selection & HitSummaryData::Outlier)!=0);
141 stat_shared_hits += ((hit_selection & HitSummaryData::SharedHit)!=0);
142 return true;
143 }
144 }
145 m_stat.emplace_back( std::make_tuple(key,
146 ((hit_selection & HitSummaryData::Hit)!=0),
147 ((hit_selection & HitSummaryData::Outlier)!=0),
148 ((hit_selection & HitSummaryData::SharedHit)!=0)) );
149 return true;
150 }
151
156 for (const auto &[stat_key, stat_hits, stat_outlier_hits, stat_shared_hits] : m_stat) {
157 unsigned short region=regionFromKey(stat_key);
158 m_hits.at(region) += stat_hits;
159 m_outlierHits.at(region) += stat_outlier_hits;
160 m_sharedHits.at(region) += stat_shared_hits;
161 ++m_layers.at(region);
162 }
163 for (unsigned int region_i=0; region_i<unknown+1; ++region_i) {
164 m_hits.at(s_type.at(region_i)) += m_hits[region_i];
165 m_outlierHits.at(s_type.at(region_i)) += m_outlierHits[region_i];
166 m_sharedHits.at(s_type.at(region_i)) += m_sharedHits[region_i];
167 m_layers.at(s_type.at(region_i)) += m_layers[region_i];
168 m_hits.at(Total) += m_hits[region_i];
169 m_outlierHits.at(Total) += m_outlierHits[region_i];
170 m_sharedHits.at(Total) += m_sharedHits[region_i];
171 m_layers.at(Total) += m_layers[region_i];
172 }
173 }
174
179 uint8_t contributingLayers(DetectorRegion region) const {
180 return m_layers.at(region);
181 }
182
187 uint8_t contributingHits(DetectorRegion region) const {
188 return m_hits.at(region);
189 }
190
196 return m_outlierHits.at(region);
197 }
198
204 return m_sharedHits.at(region);
205 }
206
207
212 template <unsigned short HIT_SELECTION>
213 uint8_t sum(DetectorRegion region, uint8_t layer) const {
214 uint8_t total=0u;
215 unsigned short key = makeKey(region, layer, 0);
216 for (const auto &[stat_key, stat_hits, stat_outlier_hits, stat_shared_hits] : m_stat) {
217 if ((stat_key & LAYER_REGION_MASK) == key) {
218 if constexpr(HIT_SELECTION & HitSummaryData::Hit) {
219 total += stat_hits;
220 }
221 if constexpr(HIT_SELECTION & HitSummaryData::Outlier) {
222 total += stat_outlier_hits;
223 }
224 if constexpr(HIT_SELECTION & HitSummaryData::SharedHit) {
225 total += stat_shared_hits;
226 }
227 }
228 }
229 return total;
230 }
231
232 private:
233 std::vector< std::tuple<unsigned short, uint8_t, uint8_t, uint8_t> > m_stat;
234 std::array<uint8_t, Total+1> m_hits;
235 std::array<uint8_t, Total+1> m_outlierHits;
236 std::array<uint8_t, Total+1> m_sharedHits;
237 std::array<uint8_t, Total+1> m_layers;
238 static constexpr std::array<uint8_t, unknown+1> s_type
240 };
241
245 private:
246 double m_sum = 0.;
247 double m_sum2 = 0.;
248 unsigned int m_n =0u;
249 public:
250 void reset() {
251 m_sum=0.;
252 m_sum2=0.;
253 m_n=0u;
254 }
255 void add(double value) {
256 m_sum += value;
257 m_sum2 += value * value;
258 ++m_n;
259 }
260 std::array<double,2> meanAndBiasedVariance() const {
261 double inv_n = m_n>0 ? 1/m_n : 0 ;
262 double mean = m_sum * inv_n;
263 return std::array<double, 2> { mean, (m_sum2 - m_sum * mean) * inv_n };
264 }
265 double biasedVariance() const {
266 double inv_n = m_n>0 ? 1./m_n : 0 ;
267 return (m_sum2 - m_sum * m_sum *inv_n) * inv_n;
268 }
269 };
270
279 void gatherTrackSummaryData(const typename ActsTrk::TrackContainer::ConstTrackProxy &track,
280 const std::array<unsigned short,Acts::toUnderlying(xAOD::UncalibMeasType::nTypes)>
281 &measurement_to_summary_type,
282 SumOfValues &chi2_stat_out,
283 HitSummaryData &hit_info_out,
284 std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType > &param_state_idx_out,
285 std::array<std::array<uint8_t,Acts::toUnderlying(HitCategory::N)>,
286 Acts::toUnderlying(xAOD::UncalibMeasType::nTypes)> &special_hit_counts_out);
287
288}
289#endif
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
Helper class to gather hit summary information for e.g.
void reset()
reset all summary counters to zero.
static constexpr unsigned short REGION_MASK
std::array< uint8_t, Total+1 > m_layers
static constexpr DetectorRegion regionFromKey(unsigned short key)
extract the region index from the given key.
DetectorRegion
Regions for which hit counts are computed.
static constexpr unsigned short LAYER_BITS
static constexpr std::array< uint8_t, unknown+1 > s_type
uint8_t contributingSharedHits(DetectorRegion region) const
return the number of shared hits in a certain detector region.
static constexpr unsigned short SIGNED_ETA_MOD_MASK
std::array< uint8_t, Total+1 > m_hits
void computeSummaries()
Compute the varius summaries.
bool addHit(const InDetDD::SiDetectorElement *detEl, EHitSelection hit_selection)
update summaries to take the given hit into account.
static constexpr unsigned short REGION_BITS
static constexpr unsigned short LAYER_MASK
static constexpr uint8_t layerFromKey(unsigned short key)
extract the layer index from the given key.
static constexpr 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.
uint8_t sum(DetectorRegion region, uint8_t layer) const
return the total number of hits, outliers, and/or shared hits in the givrn detector region and layer.
uint8_t contributingOutlierHits(DetectorRegion region) const
return the number of outliers in a certain detector region.
uint8_t contributingHits(DetectorRegion region) const
return the number of hits in a certain detector region.
std::vector< std::tuple< unsigned short, uint8_t, uint8_t, uint8_t > > m_stat
std::array< uint8_t, Total+1 > m_outlierHits
static constexpr unsigned short LAYER_REGION_MASK
static constexpr unsigned short SIGNED_ETA_MOD_BITS
std::array< uint8_t, Total+1 > m_sharedHits
uint8_t contributingLayers(DetectorRegion region) const
return the number of layers contributing to the hit collection in the given detector region.
Helper class to gather statistics and compute the biased variance.
std::array< double, 2 > meanAndBiasedVariance() const
virtual DetectorType type() const
Type of element.
Class to hold geometrical description of a silicon detector element.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
virtual Identifier identify() const override final
identifier of this detector element (inline)
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline).
This is an Identifier helper class for the Pixel subdetector.
Definition PixelID.h:69
int layer_disk(const Identifier &id) const
Definition PixelID.h:602
int eta_module(const Identifier &id) const
Definition PixelID.h:627
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
int layer_disk(const Identifier &id) const
Definition SCT_ID.h:687
int eta_module(const Identifier &id) const
Definition SCT_ID.h:699
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="")
Athena definition of the Eigen plugin.
void gatherTrackSummaryData(const typename ActsTrk::TrackContainer::ConstTrackProxy &track, const std::array< unsigned short, Acts::toUnderlying(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, Acts::toUnderlying(HitCategory::N)>, Acts::toUnderlying(xAOD::UncalibMeasType::nTypes)> &special_hit_counts_out)
Helper to gather track summary information from the track states of the specified track.