Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FPGATrackSimNNPathfinderExtensionTool.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackPATHFINDEREXTENSION_H
4 #define FPGATrackPATHFINDEREXTENSION_H
5 
13 #include "GaudiKernel/ServiceHandle.h"
15 
16 // add public header directory to algorithms for this?
18 
30 #include "GaudiKernel/ITHistSvc.h"
31 
32 #include <vector>
33 
34  // internal object for book-keeping during the tree branching, basically just a vector of hits with helper functions - NOTHING else
35  struct miniRoad {
36 
37  miniRoad() {}
38  miniRoad(unsigned nLayers) {m_hits.resize(nLayers);}
39 
40  // only one objects that we storek a vector of the hits
41  std::vector<std::shared_ptr<const FPGATrackSimHit>> m_hits;
42 
43  // getter functions
44  std::shared_ptr<const FPGATrackSimHit> getHit(size_t layer) const {
45  if (layer < m_hits.size()) return m_hits[layer];
46  const FPGATrackSimHit dummyHit;
47  return std::make_shared<const FPGATrackSimHit>(dummyHit);
48  }
49 
50  std::vector<std::shared_ptr<const FPGATrackSimHit>>& getHits() {
51  return m_hits;
52  }
53 
54  std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> getVecHits() const {
55  std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> vecHits;
56  vecHits.resize(m_hits.size());
57  for (unsigned layer = 0; layer < m_hits.size(); layer++) {
58  std::vector<std::shared_ptr<const FPGATrackSimHit>> thislayerVec;
59  thislayerVec.push_back(m_hits[layer]);
60  vecHits[layer] = thislayerVec;
61  }
62  return vecHits;
63  }
64 
65  unsigned getNHits() const {
66  return m_hits.size();
67  }
68 
69  size_t getNLayers() const { return m_hits.size(); }
70  size_t getNHitLayers() const {
71  return getNLayers() - getNWCLayers();
72  }
73  size_t getNWCLayers() const {
74  size_t nwc = 0;
75  for (auto hit : m_hits) {
76  if (!hit->isReal()) nwc++;
77  }
78  return nwc;
79  }
80 
82  layer_bitmask_t wcLayers = 0;
83  for (unsigned layer = 0; layer < m_hits.size(); layer++)
84  if (!((*m_hits[layer]).isReal()))
85  wcLayers |= (0x1 << layer);
86  return wcLayers;
87  }
88 
90  layer_bitmask_t hitLayers = 0;
91  for (unsigned layer = 0; layer < m_hits.size(); layer++)
92  if ((*m_hits[layer]).isReal())
93  hitLayers |= (0x1 << layer);
94  return hitLayers;
95  }
96 
97 
98  // setters
99  void setNLayers(unsigned layers) { m_hits.resize(layers); }
100  void setHits(std::vector<std::shared_ptr<const FPGATrackSimHit>> &hits) {
101  m_hits = hits;
102  }
103  void addHits(const std::vector<std::shared_ptr<const FPGATrackSimHit>> &hits) {
104  m_hits.insert(m_hits.end(), hits.begin(), hits.end());
105  }
106 
107  void setHit(unsigned layer, const std::shared_ptr<const FPGATrackSimHit> & hit) {
108  if (layer >= m_hits.size()) m_hits.resize(layer + 1);
109  m_hits[layer] = hit;
110  }
111 
112  void addHit(const std::shared_ptr<const FPGATrackSimHit> & hit) {
113  m_hits.push_back(hit);
114  }
115 
116 
118  // Utility
119 
120 
121  };
122 
123 
124 
125 class FPGATrackSimNNPathfinderExtensionTool : public extends <AthAlgTool, IFPGATrackSimTrackExtensionTool>
126 {
127  public:
128 
129  FPGATrackSimNNPathfinderExtensionTool(const std::string&, const std::string&, const IInterface*);
130 
131  virtual StatusCode initialize() override;
132 
133  virtual StatusCode extendTracks(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits,
134  const std::vector<std::shared_ptr<const FPGATrackSimTrack>> & tracks,
135  std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads) override;
136 
137  // We don't have a "union" tool that sits in front of the extension tool, so this is needed here.
138  virtual StatusCode setupSlices(FPGATrackSimLogicalEventInputHeader *slicedHitHeader) override {
139  m_slicedHitHeader = slicedHitHeader;
140  return StatusCode::SUCCESS;
141  };
142 
143 
144  private:
145  ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
146  ServiceHandle<ITHistSvc> m_tHistSvc {this, "THistSvc", "THistSvc"};
147 
148  // We'll definitely need properties, but I don't know which ones.
149  Gaudi::Property<int> m_threshold { this, "threshold", 10, "Minimum number of hits to fire a road"};
150 
151  // Options only needed for sector assignment.
152  // The eta pattern option here should probably be dropped, because we're not using it
153  // and supporting it requires having two sets of eta patterns (one for the first stage, one for the second)
154  // and then running the eta pattern filter a second time.
155  Gaudi::Property<std::vector<float>> m_windowR { this, "windowR", {20.0}, "Window Size to search in for r, either pass one value for all layers or use the number of layers"};
156  Gaudi::Property<std::vector<float>> m_windowZ { this, "windowZ", {20.0}, "Window Size to search in for z, either pass one value for all layers or use the number of layers"};
157  Gaudi::Property <float> m_lowPtValueForWindowRScaling { this, "lowPtValueWindowR", -1, "Value in MeV below which we scale the r window size"};
158  Gaudi::Property <float> m_lowPtWindowRScaling {this, "lowPtRScaling", 1.0, "Scaling factor for low pt in R"};
159  Gaudi::Property <float> m_lowPtValueForWindowZScaling { this, "lowPtValueWindowZ", -1, "Value in MeV below which we scale the r window size"};
160  Gaudi::Property <float> m_lowPtWindowZScaling {this, "lowPtZScaling", 1.0, "Scaling factor for low pt in Z"};
161  Gaudi::Property <float> m_missedHitRScaling {this, "missedHitRScaling", -1, "Amount to scale R window if previous hit was missed. Negative means this is disabled"};
162  Gaudi::Property <float> m_missedHitZScaling {this, "missedHitZScaling", -1, "Amount to scale Z window if previous hit was missed. Negative means this is disabled"};
163  Gaudi::Property <int> m_maxBranches { this, "maxBranches", -1, "Max number of branches before we stop, if negative this is disabled"};
164  Gaudi::Property <bool> m_doOutsideIn { this, "doOutsideIn", true, "Setup the tool so it's doing outside in extrap"};
165  Gaudi::Property <int> m_predictionWindowLength { this, "predictionWindowLength", 3, "Length of hits needed for prediction"};
166 
168  TTree *m_tree = nullptr; // output tree
169  std::vector<unsigned long> m_NcompletedRoads;
170  std::vector<unsigned int> m_missingHitsOnRoad;
171  std::vector<std::vector<unsigned long>> m_predictedHitsFineID;
172  std::vector<std::vector<unsigned int>> m_foundHitITkLayer;
173  std::vector<unsigned int> m_nHitsInSearchWindow;
174  std::vector<std::vector<float>> m_distanceOfPredictedHitToFoundHit;
175  std::vector<std::vector<bool>> m_foundHitIsSP;
176 
177  std::vector<FPGATrackSimRoad> m_roads;
178  unsigned m_nLayers_1stStage = 0;
179  unsigned m_nLayers_2ndStage = 0;
180  unsigned m_maxMiss = 0;
181 
182  static float getXScale() { return 1015.;};
183  static float getYScale() { return 1015.;};
184  static float getZScale() { return 3000.;};
185  bool m_debugEvent = false;
186 
187  // Internal storage for the sliced hits (implemented as a LogicalEventInputHeader,
188  // so we can easily copy to the output ROOT file).
190 
193 
194  StatusCode fillInputTensorForNN(miniRoad& thisRoad, std::vector<float>& inputTensorValues);
195  StatusCode getPredictedHit(std::vector<float>& inputTensorValues, std::vector<float>& outputTensorValues, long& fineID);
196  StatusCode addHitToRoad(miniRoad& newroad, miniRoad& currentRoad, const std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits);
197  StatusCode getFakeHit(miniRoad& currentRoad, std::vector<float>& predhit, const long& fineID, std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits);
198  StatusCode getLastLayer(miniRoad& currentRoad, unsigned& lastHitLayer, std::shared_ptr<const FPGATrackSimHit>& lastHit);
199 
200  StatusCode findHitinNextStripLayer(std::shared_ptr<const FPGATrackSimHit> hit, const std::vector<std::shared_ptr<const FPGATrackSimHit>>& hitList, std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits);
201 
202  void printRoad(miniRoad& currentRoad);
203 
204 
205 };
206 
207 #endif
FPGATrackSimNNPathfinderExtensionTool::findHitinNextStripLayer
StatusCode findHitinNextStripLayer(std::shared_ptr< const FPGATrackSimHit > hit, const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hitList, std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:650
miniRoad::setHit
void setHit(unsigned layer, const std::shared_ptr< const FPGATrackSimHit > &hit)
Definition: FPGATrackSimNNPathfinderExtensionTool.h:107
FPGATrackSimNNPathfinderExtensionTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimNNPathfinderExtensionTool.h:145
miniRoad::getHit
std::shared_ptr< const FPGATrackSimHit > getHit(size_t layer) const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:44
FPGATrackSimLogicalEventInputHeader
Definition: FPGATrackSimLogicalEventInputHeader.h:21
FPGATrackSimNNPathfinderExtensionTool::FPGATrackSimNNPathfinderExtensionTool
FPGATrackSimNNPathfinderExtensionTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:20
FPGATrackSimNNPathfinderExtensionTool::m_missingHitsOnRoad
std::vector< unsigned int > m_missingHitsOnRoad
Definition: FPGATrackSimNNPathfinderExtensionTool.h:170
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
FPGATrackSimNNPathfinderExtensionTool::m_missedHitRScaling
Gaudi::Property< float > m_missedHitRScaling
Definition: FPGATrackSimNNPathfinderExtensionTool.h:161
FPGATrackSimNNPathfinderExtensionTool::m_tree
TTree * m_tree
Definition: FPGATrackSimNNPathfinderExtensionTool.h:168
FPGATrackSimNNPathfinderExtensionTool::m_doOutsideIn
Gaudi::Property< bool > m_doOutsideIn
Definition: FPGATrackSimNNPathfinderExtensionTool.h:164
FPGATrackSimPlaneMap.h
Maps physical layers to logical layers.
FPGATrackSimNNPathfinderExtensionTool::m_tHistSvc
ServiceHandle< ITHistSvc > m_tHistSvc
Definition: FPGATrackSimNNPathfinderExtensionTool.h:146
FPGATrackSimNNPathfinderExtensionTool::printRoad
void printRoad(miniRoad &currentRoad)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:668
FPGATrackSimNNPathfinderExtensionTool::getYScale
static float getYScale()
Definition: FPGATrackSimNNPathfinderExtensionTool.h:183
miniRoad::getWCLayers
layer_bitmask_t getWCLayers() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:81
FPGATrackSimNNTrackTool.h
Utilize NN score to build track candidates.
FPGATrackSimTowerInputHeader.h
miniRoad::getHitLayers
layer_bitmask_t getHitLayers() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:89
FPGATrackSimNNPathfinderExtensionTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:26
IFPGATrackSimMappingSvc.h
module_driven_slicing.layers
layers
Definition: module_driven_slicing.py:114
miniRoad::addHit
void addHit(const std::shared_ptr< const FPGATrackSimHit > &hit)
Definition: FPGATrackSimNNPathfinderExtensionTool.h:112
FPGATrackSimNNPathfinderExtensionTool::m_nLayers_1stStage
unsigned m_nLayers_1stStage
Definition: FPGATrackSimNNPathfinderExtensionTool.h:178
miniRoad::getNHits
unsigned getNHits() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:65
miniRoad::m_hits
std::vector< std::shared_ptr< const FPGATrackSimHit > > m_hits
Definition: FPGATrackSimNNPathfinderExtensionTool.h:41
IFPGATrackSimTrackExtensionTool.h
Interface declaration for track extension tools (tracks + hits -> roads)
FPGATrackSimNNPathfinderExtensionTool::getXScale
static float getXScale()
Definition: FPGATrackSimNNPathfinderExtensionTool.h:182
FPGATrackSimNNPathfinderExtensionTool::m_lowPtWindowRScaling
Gaudi::Property< float > m_lowPtWindowRScaling
Definition: FPGATrackSimNNPathfinderExtensionTool.h:158
FPGATrackSimNNPathfinderExtensionTool::m_slicedHitHeader
FPGATrackSimLogicalEventInputHeader * m_slicedHitHeader
Definition: FPGATrackSimNNPathfinderExtensionTool.h:189
FPGATrackSimNNPathfinderExtensionTool::getLastLayer
StatusCode getLastLayer(miniRoad &currentRoad, unsigned &lastHitLayer, std::shared_ptr< const FPGATrackSimHit > &lastHit)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:703
FPGATrackSimNNPathfinderExtensionTool::m_nLayers_2ndStage
unsigned m_nLayers_2ndStage
Definition: FPGATrackSimNNPathfinderExtensionTool.h:179
FPGATrackSimNNPathfinderExtensionTool::m_foundHitITkLayer
std::vector< std::vector< unsigned int > > m_foundHitITkLayer
Definition: FPGATrackSimNNPathfinderExtensionTool.h:172
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimRegionMap.h
Maps ITK module indices to FPGATrackSim regions.
FPGATrackSimNNPathfinderExtensionTool::m_NcompletedRoads
std::vector< unsigned long > m_NcompletedRoads
Definition: FPGATrackSimNNPathfinderExtensionTool.h:169
FPGATrackSimNNPathfinderExtensionTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimNNPathfinderExtensionTool.h:177
FPGATrackSimNNPathfinderExtensionTool::m_foundHitIsSP
std::vector< std::vector< bool > > m_foundHitIsSP
Definition: FPGATrackSimNNPathfinderExtensionTool.h:175
FPGATrackSimNNPathfinderExtensionTool::m_nHitsInSearchWindow
std::vector< unsigned int > m_nHitsInSearchWindow
Definition: FPGATrackSimNNPathfinderExtensionTool.h:173
miniRoad::getNHitLayers
size_t getNHitLayers() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:70
FPGATrackSimNNPathfinderExtensionTool::m_maxBranches
Gaudi::Property< int > m_maxBranches
Definition: FPGATrackSimNNPathfinderExtensionTool.h:163
FPGATrackSimNNPathfinderExtensionTool::getZScale
static float getZScale()
Definition: FPGATrackSimNNPathfinderExtensionTool.h:184
FPGATrackSimNNPathfinderExtensionTool::getPredictedHit
StatusCode getPredictedHit(std::vector< float > &inputTensorValues, std::vector< float > &outputTensorValues, long &fineID)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:569
FPGATrackSimNNPathfinderExtensionTool::m_lowPtValueForWindowZScaling
Gaudi::Property< float > m_lowPtValueForWindowZScaling
Definition: FPGATrackSimNNPathfinderExtensionTool.h:159
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
AthAlgTool.h
miniRoad::getNLayers
size_t getNLayers() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:69
FPGATrackSimNNPathfinderExtensionTool::m_lowPtValueForWindowRScaling
Gaudi::Property< float > m_lowPtValueForWindowRScaling
Definition: FPGATrackSimNNPathfinderExtensionTool.h:157
FPGATrackSimNNPathfinderExtensionTool::m_windowR
Gaudi::Property< std::vector< float > > m_windowR
Definition: FPGATrackSimNNPathfinderExtensionTool.h:155
FPGATrackSimNNPathfinderExtensionTool
Definition: FPGATrackSimNNPathfinderExtensionTool.h:126
FPGATrackSimNNPathfinderExtensionTool::m_extensionVolNN
OnnxRuntimeBase m_extensionVolNN
Definition: FPGATrackSimNNPathfinderExtensionTool.h:191
FPGATrackSimNNPathfinderExtensionTool::m_threshold
Gaudi::Property< int > m_threshold
Definition: FPGATrackSimNNPathfinderExtensionTool.h:149
FPGATrackSimNNPathfinderExtensionTool::m_distanceOfPredictedHitToFoundHit
std::vector< std::vector< float > > m_distanceOfPredictedHitToFoundHit
Definition: FPGATrackSimNNPathfinderExtensionTool.h:174
FPGATrackSimNNPathfinderExtensionTool::addHitToRoad
StatusCode addHitToRoad(miniRoad &newroad, miniRoad &currentRoad, const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:587
miniRoad::getNWCLayers
size_t getNWCLayers() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:73
miniRoad::getVecHits
std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > getVecHits() const
Definition: FPGATrackSimNNPathfinderExtensionTool.h:54
FPGATrackSimNNPathfinderExtensionTool::setupSlices
virtual StatusCode setupSlices(FPGATrackSimLogicalEventInputHeader *slicedHitHeader) override
Definition: FPGATrackSimNNPathfinderExtensionTool.h:138
miniRoad::setHits
void setHits(std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimNNPathfinderExtensionTool.h:100
OnnxRuntimeBase
Definition: OnnxRuntimeBase.h:13
FPGATrackSimNNPathfinderExtensionTool::m_extensionHitNN
OnnxRuntimeBase m_extensionHitNN
Definition: FPGATrackSimNNPathfinderExtensionTool.h:192
FPGATrackSimFunctions.h
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimNNPathfinderExtensionTool::m_debugEvent
bool m_debugEvent
Definition: FPGATrackSimNNPathfinderExtensionTool.h:185
miniRoad::getHits
std::vector< std::shared_ptr< const FPGATrackSimHit > > & getHits()
Definition: FPGATrackSimNNPathfinderExtensionTool.h:50
FPGATrackSimNNPathfinderExtensionTool::extendTracks
virtual StatusCode extendTracks(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, const std::vector< std::shared_ptr< const FPGATrackSimTrack >> &tracks, std::vector< std::shared_ptr< const FPGATrackSimRoad >> &roads) override
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:81
FPGATrackSimNNPathfinderExtensionTool::fillInputTensorForNN
StatusCode fillInputTensorForNN(miniRoad &thisRoad, std::vector< float > &inputTensorValues)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:470
miniRoad
Definition: FPGATrackSimNNPathfinderExtensionTool.h:35
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
FPGATrackSimNNPathfinderExtensionTool::m_predictedHitsFineID
std::vector< std::vector< unsigned long > > m_predictedHitsFineID
Definition: FPGATrackSimNNPathfinderExtensionTool.h:171
miniRoad::addHits
void addHits(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimNNPathfinderExtensionTool.h:103
IFPGATrackSimBankSvc.h
FPGATrackSimNNPathfinderExtensionTool::m_lowPtWindowZScaling
Gaudi::Property< float > m_lowPtWindowZScaling
Definition: FPGATrackSimNNPathfinderExtensionTool.h:160
miniRoad::setNLayers
void setNLayers(unsigned layers)
Definition: FPGATrackSimNNPathfinderExtensionTool.h:99
FPGATrackSimNNPathfinderExtensionTool::m_predictionWindowLength
Gaudi::Property< int > m_predictionWindowLength
Definition: FPGATrackSimNNPathfinderExtensionTool.h:165
FPGATrackSimRoad.h
Defines a class for roads.
FPGATrackSimNNPathfinderExtensionTool::bookTree
StatusCode bookTree()
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:64
FPGATrackSimNNPathfinderExtensionTool::m_windowZ
Gaudi::Property< std::vector< float > > m_windowZ
Definition: FPGATrackSimNNPathfinderExtensionTool.h:156
miniRoad::miniRoad
miniRoad()
Definition: FPGATrackSimNNPathfinderExtensionTool.h:37
FPGATrackSimTypes.h
FPGATrackSimNNPathfinderExtensionTool::m_maxMiss
unsigned m_maxMiss
Definition: FPGATrackSimNNPathfinderExtensionTool.h:180
FPGATrackSimNNPathfinderExtensionTool::m_missedHitZScaling
Gaudi::Property< float > m_missedHitZScaling
Definition: FPGATrackSimNNPathfinderExtensionTool.h:162
FPGATrackSimTrack.h
FPGATrackSimNNPathfinderExtensionTool::getFakeHit
StatusCode getFakeHit(miniRoad &currentRoad, std::vector< float > &predhit, const long &fineID, std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits)
Definition: FPGATrackSimNNPathfinderExtensionTool.cxx:594
miniRoad::miniRoad
miniRoad(unsigned nLayers)
Definition: FPGATrackSimNNPathfinderExtensionTool.h:38
ServiceHandle< IFPGATrackSimMappingSvc >