ATLAS Offline Software
FPGATrackSimRoad.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
11 #include <vector>
12 
15 
16 using namespace std;
17 
18 //FPGATrackSimRoad::~FPGATrackSimRoad() { }
19 
21 {
22  size_t n = 0;
23  for (const auto& l : m_hits_trans) n += l.size();
24  return n;
25 }
26 
27 std::vector<size_t> FPGATrackSimRoad::getNHits_layer() const
28 {
29  std::vector<size_t> out;
30  out.reserve(m_hits_trans.size());
31  for (const auto& l : m_hits_trans) out.push_back(l.size());
32  return out;
33 }
34 
36 {
37  size_t combos = 1;
38  size_t l = m_hits_trans.size();
39  std::vector<unsigned int> skipindices;
40 
41  // figure out indices of outer layers of stereo layers, where inner layer is also present to not
42  // double count spacepoints
43  for (size_t i = 1; i < l; ++i) {
44  if (m_hits_trans[i - 1].size() > 0 && m_hits_trans[i].size() > 0) {
45  if ((m_hits_trans[i - 1][0]->isStrip() && m_hits_trans[i][0]->isStrip()) &&
46  (m_hits_trans[i - 1][0]->getPhysLayer() % 2 == 0) &&
47  (m_hits_trans[i][0]->getPhysLayer() - m_hits_trans[i - 1][0]->getPhysLayer() == 1)) {
48  skipindices.push_back(i);
49  ++i;
50  }
51  }
52  }
53 
54  // calculate number of combinations
55  for (size_t i = 0; i < l; ++i) {
56  size_t n = 0;
57  for (size_t j = 0; j < m_hits_trans[i].size(); ++j) {
58  // extra handling of spacepoints in combination calculation
59  if (m_hits_trans[i][j]->getHitType() == HitType::spacepoint) {
60  bool skip = false;
61  size_t skipsize = skipindices.size();
62  for (size_t k = 0; k < skipsize; ++k)
63  if (i == skipindices[k]) skip = true;
64 
65  if (skip) continue;
66  }
67  ++n;
68  }
69  if (n > 0) combos *= n;
70  }
71 
72  return combos;
73 }
74 
75 
77 {
78  // get number of pixel layers from hits. Assumes strips follow pixels,
79  // and all hits in a layer share the same det type
80  unsigned nPixel;
81  for (nPixel = 0; nPixel < m_hits_trans.size(); nPixel++)
82  if (!m_hits_trans[nPixel].empty() && m_hits_trans[nPixel].front()->isStrip())
83  break;
84 
85  std::map<FPGATrackSimMultiTruth::Barcode, layer_bitmask_t> layer_map;
86 
87  for (auto const& hits : m_hits_trans)
88  for (auto const &h : hits)
89  for (auto const& x : h->getTruth())
90  layer_map[x.first] |= (1 << h->getLayer());
91 
93  for (auto const& x : layer_map)
94  {
95  int w = 0, n = 0;
96  for (unsigned i = 0; i < m_hits_trans.size(); i++)
97  {
98  if (!m_hits_trans[i].empty())
99  n += (i < nPixel) ? 2 : 1; // double weight pixels
100  if (x.second & (1 << i))
101  w += (i < nPixel) ? 2 : 1; // double weight pixels
102  }
103  if (n == 0){
104  throw std::range_error("divide by zero in FPGATrackSimRoad::getTruth");
105  }
106  mt.add(x.first, static_cast<float>(w) / n);
107  }
108 
109  return mt;
110 }
111 
112 
113 std::unordered_set<std::shared_ptr<const FPGATrackSimHit>> FPGATrackSimRoad::getHits_flat() const {
114  std::unordered_set<std::shared_ptr<const FPGATrackSimHit>> hits;
115  for (const auto& layerHits : m_hits_trans)
116  for (auto const& hit : layerHits)
117  hits.insert(hit);
118  // for (const auto& x : m_hits) hits.insert(x.begin(), x.end());
119  return hits;
120 }
121 
122 void FPGATrackSimRoad::repopulateTransHits() { // this is needed if trying to read the hits from the road in a stored output file, call this first, otherwise not in Athena
123  m_hits_trans.resize(m_hits.size());
124  for (unsigned ilayer = 0; ilayer < m_hits.size(); ilayer++) {
125  m_hits_trans[ilayer].resize(m_hits[ilayer].size());
126  for (unsigned ihit = 0; ihit < m_hits[ilayer].size(); ihit++) {
127  m_hits_trans[ilayer][ihit] = std::make_shared<const FPGATrackSimHit>(m_hits[ilayer][ihit]);
128  }
129  }
130 }
131 
132 void FPGATrackSimRoad::setHits(unsigned layer, std::vector<std::shared_ptr<const FPGATrackSimHit>> && hits) {
133  m_hits_trans[layer] = std::move(hits);
134  m_hits[layer].clear();
135  for (const auto& hit : m_hits_trans[layer])
136  m_hits[layer].push_back(*hit);
137 } // ensure setNLayers is called first
138 
139 void FPGATrackSimRoad::setHits(std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> &&hits){
140  if (hits.size() != m_hits_trans.size()) setNLayers(hits.size());
141  for (unsigned i = 0;i < hits.size();++i)
142  setHits(i,std::move(hits[i]));
143 }
144 
145 
146 ostream& operator<<(ostream& os, const FPGATrackSimRoad& road)
147 {
148  os << "road " << road.m_roadID
149  << ": PID " << road.m_pid
150  << ", sector " << road.m_sector
151  << " hitLayers " << std::showbase << std::hex << road.m_hit_layers
152  << " wcLayers " << std::showbase << std::hex << road.m_wildcard_layers
153  << ", nHits " << road.getNHits();
154  /*
155  for (size_t l=0; l < road.m_hits.size(); l++)
156  {
157  for (FPGATrackSimHit const * hit : road.m_hits[l])
158  os << "\n\t" << *hit;
159  }
160  */
161 
162  return os;
163 }
164 
FPGATrackSimRoad::repopulateTransHits
void repopulateTransHits()
Definition: FPGATrackSimRoad.cxx:122
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
FPGATrackSimRoad::getTruth
FPGATrackSimMultiTruth getTruth() const
Definition: FPGATrackSimRoad.cxx:76
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
HitType::spacepoint
@ spacepoint
FPGATrackSimRoad::m_pid
pid_t m_pid
Definition: FPGATrackSimRoad.h:121
x
#define x
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
FPGATrackSimRoad::m_wildcard_layers
layer_bitmask_t m_wildcard_layers
Definition: FPGATrackSimRoad.h:126
FPGATrackSimRoad::getNHits_layer
std::vector< size_t > getNHits_layer() const
Definition: FPGATrackSimRoad.cxx:27
FPGATrackSimRoad::getNHits
size_t getNHits() const
Definition: FPGATrackSimRoad.cxx:20
operator<<
ostream & operator<<(ostream &os, const FPGATrackSimRoad &road)
Definition: FPGATrackSimRoad.cxx:146
FPGATrackSimConstants.h
FPGATrackSimRoad::m_hit_layers
layer_bitmask_t m_hit_layers
Definition: FPGATrackSimRoad.h:125
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
FPGATrackSimRoad::getHits_flat
std::unordered_set< std::shared_ptr< const FPGATrackSimHit > > getHits_flat() const
Definition: FPGATrackSimRoad.cxx:113
lumiFormat.i
int i
Definition: lumiFormat.py:85
h
beamspotman.n
n
Definition: beamspotman.py:731
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FPGATrackSimMultiTruth::add
void add(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
Definition: FPGATrackSimMultiTruth.cxx:22
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
dumpTgcDigiThreshold.isStrip
list isStrip
Definition: dumpTgcDigiThreshold.py:33
FPGATrackSimMultiTruth
Definition: FPGATrackSimMultiTruth.h:46
FPGATrackSimRoad::m_roadID
int m_roadID
Definition: FPGATrackSimRoad.h:120
FPGATrackSimRoad::getNHitCombos
size_t getNHitCombos() const
Definition: FPGATrackSimRoad.cxx:35
FPGATrackSimRoad.h
Defines a class for roads.
skip
bool skip
Definition: TrigGlobEffCorrValidation.cxx:190
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
FPGATrackSimRoad::m_sector
sector_t m_sector
Definition: FPGATrackSimRoad.h:122
FPGATrackSimRoad::setHits
void setHits(std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit >>> &&hits)
Definition: FPGATrackSimRoad.cxx:139
FPGATrackSimRoad
Definition: FPGATrackSimRoad.h:30
fitman.k
k
Definition: fitman.py:528