Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FPGATrackSimBinnedHits.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
16 #include <GaudiKernel/StatusCode.h>
17 #include <nlohmann/json.hpp>
18 
19 
21  // Dump the configuration to make sure it propagated through right
22  const std::vector<Gaudi::Details::PropertyBase*> props = this->getProperties();
23  for( Gaudi::Details::PropertyBase* prop : props ) {
24  if (prop->ownerTypeName()==this->type()) {
25  ATH_MSG_DEBUG("Property:\t" << prop->name() << "\t : \t" << prop->toString());
26  }
27  }
28 
29 
30  ATH_MSG_DEBUG("Retrieving BinTool");
31  ATH_CHECK(m_bintool.retrieve());
32  ATH_MSG_DEBUG("Retrieving EvtSel");
33  ATH_CHECK(m_EvtSel.retrieve());
34  // Compute which bins correspond to track parameters that are in the region
35  // i.e. the pT, eta, phi, z0 and d0 bounds
36  // list of valid bins is extracted from the layer map if its loaded
37  m_bintool->initValidBins();
38  if (m_lyrmapFile.size()==0)
39  {
40  m_bintool->computeValidBins(m_EvtSel.get());
41  } else {
43  }
44  m_bintool->printValidBin(); // also dumps firmware constants
46 
47  return StatusCode::SUCCESS;
48 }
49 
51  m_binnedHitsStep.resize(m_bintool->steps().size());
52  int i = 0;
53  for (auto &step : m_bintool->steps()) {
54  m_binnedHitsStep[i].setsize(step->nBins(), BinEntry());
55  ATH_MSG_INFO("Step" << step->stepName() << " Image Size (full): "
56  << m_binnedHitsStep[i].size());
57  ++i;
58  }
59  resetBins(); // just to be sure
60 }
61 
63  for (auto &stepdata : m_binnedHitsStep) {
65  bin.data().reset();
66  }
67  }
68 }
69 
70 // Put hits in all track parameter bins they could be a part of (binning is defined
71 // by m_binning object)
73  const std::vector<std::shared_ptr<const FPGATrackSimHit>> &hits) {
74  ATH_MSG_DEBUG("In fill");
75 
76  int stepnum = 0;
77  for (const auto &step : m_bintool->steps()) {
78 
79  ATH_MSG_DEBUG("fill binning: step num " << stepnum << " " << step->stepName());
80  for (auto &bin : step->validBinsFull()) {
81 
82  // skip bin if it is invalid
83  if (!bin.data())
84  continue;
85 
86  //ATH_MSG_DEBUG("valid bin");
87  if (stepnum == 0) {
88 
89  // first step, hits from input stream
90  for (const std::shared_ptr<const FPGATrackSimHit> &hit : hits) {
91  StoredHit storedhit(hit);
92  if (m_bintool->binDesc()->hitInBin(*step.get(), bin.idx(),
93  storedhit)) {
94  m_binnedHitsStep[stepnum][bin.idx()].addHit(storedhit);
95  }
96  }
97 
98  } else {
99  // subsequent steps, use hits from previous step
100  for (const auto &hit :
101  m_binnedHitsStep[stepnum - 1][step->convertToPrev(bin.idx())].hits) {
102  StoredHit storedhit(hit);
103  if (m_bintool->binDesc()->hitInBin(*step.get(), bin.idx(),
104  storedhit)) {
105 
106  // One last step, set layer based on layerMap or use default from pmap
107  if (step.get() == m_bintool->lastStep()) {
108  if (m_mod_to_lyr_map.size() != 0) {
109  if (m_mod_to_lyr_map[bin.idx()].contains(hit.hitptr->getIdentifierHash())) {
110  storedhit.layer = m_mod_to_lyr_map[bin.idx()][hit.hitptr->getIdentifierHash()];
111  m_binnedHitsStep[stepnum][bin.idx()].addHit(storedhit);
112  }
113  } else {
114  // TODO is it right to ignore hits that were unmapped?
115  if (hit.hitptr->isMapped()) {
116  storedhit.layer = hit.hitptr->getLayer();
117  m_binnedHitsStep[stepnum][bin.idx()].addHit(storedhit);
118  }
119  }
120  }
121  }
122  }
123  }
124 
125  } // end loop over bins
126 
127  stepnum++;
128  } // end loop over stepsd
129 
130  return StatusCode::SUCCESS;
131 }
132 
134 // Internal Storage Class
135 
137 {
138  hitCnt = 0;
139  lyrhit = 0;
140  hits.clear();
141 }
142 
144 {
145  hitCnt++;
146  if (((lyrhit >> hit.layer) & 0x1) == 0x0)
147  {
148  lyrhit |= (0x1 << hit.layer);
149  }
150  hits.push_back(hit);
151 }
152 
153 unsigned FPGATrackSimBinnedHits::BinEntry::hitsInLyr(unsigned lyr) const {
154  return std::count_if(hits.begin(),hits.end(),[lyr](auto& hit){return hit.layer==lyr;});
155 }
156 
157 
158 //-------------------------------------------------------------------------------
159 //
160 // Layer map implementation
161 //
162 //-------------------------------------------------------------------------------
163 
165  std::ifstream f(filename);
167 
168  m_lyr_to_mod_map.setsize(m_bintool->lastStep()->nBins(),
169  std::vector <std::set<unsigned> >(5,std::set<unsigned>()));
170  m_mod_to_lyr_map.setsize(m_bintool->lastStep()->nBins(),
171  std::map <unsigned,unsigned>());
172 
173  // This sets the number of layer, to the number of layers in the layerMap
174  m_nLayers = 0;
175  for (const auto &binelem : data) {
176  std::vector<unsigned> bin;
177  binelem.at("bin").get_to(bin);
178  auto& lyrmap = binelem["lyrmap"];
179  ATH_MSG_DEBUG("bin = " << bin);
180  ATH_MSG_DEBUG("lyrmap = " << lyrmap);
181  for (auto &lyrelem : lyrmap) {
182  unsigned lyr;
183  lyrelem.at("lyr").get_to(lyr);
184  lyrelem.at("mods").get_to(m_lyr_to_mod_map[bin][lyr]);
185  ATH_MSG_DEBUG("lyr = " << lyr);
186  ATH_MSG_DEBUG("mods = " << m_lyr_to_mod_map[bin][lyr]);
187  for (auto &mod : m_lyr_to_mod_map[bin][lyr]) {
188  m_mod_to_lyr_map[bin][mod]=lyr;
189  }
190  // set valid bins, this expects binning based on the last step
191  m_bintool->setValidBin(bin);
192  }
193  if (m_nLayers == 0) {
195  } else if (m_nLayers != m_lyr_to_mod_map[bin].size()) {
196  ATH_MSG_FATAL("Layer map bins have inconsistent numbers of layers");
197  }
198  }
199 
200 }
FPGATrackSimBinnedHits::m_lyr_to_mod_map
FPGATrackSimBinArray< std::vector< std::set< unsigned > > > m_lyr_to_mod_map
Definition: FPGATrackSimBinnedHits.h:93
FPGATrackSimBinnedHits::m_binnedHitsStep
std::vector< FPGATrackSimBinArray< BinEntry > > m_binnedHitsStep
Definition: FPGATrackSimBinnedHits.h:105
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimBinnedHits::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimBinnedHits.h:113
AthMsgStreamMacros.h
json
nlohmann::json json
Definition: HistogramDef.cxx:9
FPGATrackSimBinnedHits::BinEntry::hitCnt
unsigned int hitCnt
Definition: FPGATrackSimBinnedHits.h:77
FPGATrackSimBinUtil::StoredHit::layer
unsigned layer
Definition: FPGATrackSimBinUtil.h:95
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1080
FPGATrackSimBinnedHits::BinEntry::addHit
void addHit(const StoredHit &hit)
Definition: FPGATrackSimBinnedHits.cxx:143
FPGATrackSimBinnedHits::m_EvtSel
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
Definition: FPGATrackSimBinnedHits.h:102
bin
Definition: BinsDiffFromStripMedian.h:43
FPGATrackSimBinnedHits::fill
StatusCode fill(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimBinnedHits.cxx:72
FPGATrackSimBinnedHits::BinEntry::lyrhit
layer_bitmask_t lyrhit
Definition: FPGATrackSimBinnedHits.h:78
FPGATrackSimBinnedHits::BinEntry::hitsInLyr
unsigned int hitsInLyr(unsigned lyr) const
Definition: FPGATrackSimBinnedHits.cxx:153
FPGATrackSimBinnedHits.h
Binning Classes for GenScanTool.
FPGATrackSimBinStep.h
Binning Classes for BinStep.
FPGATrackSimBinnedHits::BinEntry::hits
std::vector< StoredHit > hits
Definition: FPGATrackSimBinnedHits.h:79
FPGATrackSimBinnedHits::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimBinnedHits.cxx:20
FPGATrackSimBinnedHits::BinEntry::reset
void reset()
Definition: FPGATrackSimBinnedHits.cxx:136
FPGATrackSimBinArray::size
unsigned int size() const
Definition: FPGATrackSimBinArray.h:69
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
FPGATrackSimBinArray::setsize
void setsize(const std::vector< unsigned int > &dims, const T &initval)
Definition: FPGATrackSimBinArray.h:51
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
FPGATrackSimBinnedHits::m_bintool
ToolHandle< FPGATrackSimBinTool > m_bintool
Definition: FPGATrackSimBinnedHits.h:108
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimBinUtil.h
Binning Utilities for GenScanTool.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FPGATrackSimBinnedHits::resetBins
void resetBins()
Definition: FPGATrackSimBinnedHits.cxx:62
FPGATrackSimBinnedHits::m_mod_to_lyr_map
FPGATrackSimBinArray< std::map< unsigned, unsigned > > m_mod_to_lyr_map
Definition: FPGATrackSimBinnedHits.h:94
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:141
FPGATrackSimBinnedHits::BinEntry
Definition: FPGATrackSimBinnedHits.h:71
FPGATrackSimBinUtil::StoredHit
Definition: FPGATrackSimBinUtil.h:90
IFPGATrackSimBinDesc.h
Defines Parameters used for binning.
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
FPGATrackSimBinArray::Iterator
Definition: FPGATrackSimBinArray.h:191
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
LArCellBinning.step
step
Definition: LArCellBinning.py:158
FPGATrackSimBinnedHits::readLayerMap
void readLayerMap(const std::string &filename)
Definition: FPGATrackSimBinnedHits.cxx:164
FPGATrackSimBinnedHits::m_lyrmapFile
Gaudi::Property< std::string > m_lyrmapFile
Definition: FPGATrackSimBinnedHits.h:101
FPGATrackSimBinnedHits::initBinnedDataArrays
void initBinnedDataArrays()
Definition: FPGATrackSimBinnedHits.cxx:50