ATLAS Offline Software
FPGATrackSimWindowExtensionTool.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 
16 
18 
19 #include <sstream>
20 #include <cmath>
21 #include <algorithm>
22 
23 FPGATrackSimWindowExtensionTool::FPGATrackSimWindowExtensionTool(const std::string& algname, const std::string &name, const IInterface *ifc) :
24  base_class(algname, name, ifc) {
25  declareInterface<IFPGATrackSimTrackExtensionTool>(this);
26 }
27 
28 
30 
31  // Retrieve the mapping service.
32  ATH_CHECK(m_FPGATrackSimMapping.retrieve());
34  m_nLayers_1stStage = m_FPGATrackSimMapping->PlaneMap_1st(0)->getNLogiLayers();
35  m_nLayers_2ndStage = m_FPGATrackSimMapping->PlaneMap_2nd(0)->getNLogiLayers() - m_nLayers_1stStage;
36 
37  // This now needs to be done once for each slice.
38  for (size_t j=0; j<m_FPGATrackSimMapping->GetPlaneMap_2ndSliceSize(); j++){
39  ATH_MSG_INFO("Processing second stage slice " << j);
40  m_phits_atLayer[j] = std::map<unsigned, std::vector<std::shared_ptr<const FPGATrackSimHit>>>();
41  for (unsigned i = m_nLayers_1stStage; i < m_nLayers_2ndStage +m_nLayers_1stStage ; i++) {
42  ATH_MSG_INFO("Processing layer " << i);
43  m_phits_atLayer[j][i] = std::vector<std::shared_ptr<const FPGATrackSimHit>>();
44  }
45  }
46  // Probably need to do something here.
47  return StatusCode::SUCCESS;
48 }
49 
50 StatusCode FPGATrackSimWindowExtensionTool::extendTracks(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits,
51  const std::vector<std::shared_ptr<const FPGATrackSimTrack>> & tracks,
52  std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads) {
53 
54  // Reset the internal second stage roads storage.
55  roads.clear();
56  m_roads.clear();
57  for (auto& sliceEntry : m_phits_atLayer){
58  for (auto& entry : sliceEntry.second) {
59  entry.second.clear();
60  }
61  }
62  const FPGATrackSimRegionMap* rmap_2nd = m_FPGATrackSimMapping->SubRegionMap_2nd();
63  const FPGATrackSimPlaneMap *pmap_2nd = nullptr;
64 
65  // Second stage hits may be unmapped, in which case map them.
66  for (size_t i=0; i<m_FPGATrackSimMapping->GetPlaneMap_2ndSliceSize(); i++){
67  pmap_2nd = m_FPGATrackSimMapping->PlaneMap_2nd(i);
68  for (const std::shared_ptr<const FPGATrackSimHit>& hit : hits) {
69  std::shared_ptr<FPGATrackSimHit> hitCopy = std::make_shared<FPGATrackSimHit>(*hit);
70  pmap_2nd->map(*hitCopy);
71  if (!hitCopy->isMapped()){
72  continue;
73  }
74  if (rmap_2nd->isInRegion(i, *hitCopy)) {
75  m_phits_atLayer[i][hitCopy->getLayer()].push_back(hitCopy);
76  }
77  }
78  }
79  // Now, loop over the tracks.
80  for (std::shared_ptr<const FPGATrackSimTrack> track : tracks) {
81  if (track->passedOR() == 0) {
82  continue;
83  }
84 
85  // Retrieve track parameters.
86  double trackd0 = track->getD0();
87  double trackphi = track->getPhi();
88  double trackz0 = track->getZ0();
89  double tracketa = track->getEta();
90  double cottracktheta = 0.5*(exp(tracketa)-exp(-tracketa));
91  double trackqoverpt = track->getQOverPt();
92 
93  // Copy over the existing hits. We require that the layer assignment in the first stage
94  // is equal to the layer assignment in the second stage.
95  std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> road_hits;
96  road_hits.resize(m_nLayers_1stStage + m_nLayers_2ndStage);
97  layer_bitmask_t hitLayers = 0;
98  int nhit = 0;
99  for (auto hit : track->getFPGATrackSimHits()) {
100  road_hits[hit.getLayer()].push_back(std::make_shared<FPGATrackSimHit>(hit));
101  if (hit.isReal()) {
102  nhit += 1;
103  hitLayers |= 1 << hit.getLayer();
104  }
105  }
106 
107  // At this point we should have copied over all the hits.
108  std::vector<int> numHits(m_nLayers_2ndStage + m_nLayers_1stStage, 0);
109 
110  size_t slice = track->getSubRegion();
111  pmap_2nd = m_FPGATrackSimMapping->PlaneMap_2nd(slice);
113  ATH_MSG_DEBUG("Testing layer " << layer << " with " << m_phits_atLayer[slice][layer].size() << " hit");
114  for (const std::shared_ptr<const FPGATrackSimHit>& hit: m_phits_atLayer[slice][layer]) {
115  // Make sure this hit is in the same subregion as the track. TODO: mapping/slice changes.
116  if (!rmap_2nd->isInRegion(track->getSubRegion(), *hit)) {
117  continue;
118  }
119 
120  double hitphi = hit->getGPhi();
121  double hitr = hit->getR();
122  double hitz = hit->getZ();
123  double pred_hitphi = trackphi - asin(hitr * fpgatracksim::A * 1000 * trackqoverpt - trackd0/hitr);
124  double pred_hitz = trackz0 + hitr*cottracktheta;
125 
126  // Field correction, now pulled from FPGATrackSimFunctions.
127  if (m_fieldCorrection){
128  double fieldCor = fieldCorrection(track->getRegion(), trackqoverpt, hitr);
129  pred_hitphi += fieldCor;
130  }
131 
132  double diff = abs(hitphi-pred_hitphi);
133  double diffz = abs(hitz-pred_hitz);
134 
135  // Apply the actual layer check, only accept hits that fall into a track's window.
136  ATH_MSG_DEBUG("Hit in region, comparing phi: " << diff << " to " << m_windows[layer] << " and z " << diffz << " to " << m_zwindows[layer]);
137  if (diff < m_windows[layer] && diffz < m_zwindows[layer]) {
138  numHits[layer]++;
139  road_hits[layer].push_back(hit);
140  hitLayers |= 1 << hit->getLayer();
141  }
142  }
143  }
144 
145  // now nhit will be equal to the number of layers with hits in the new array.
146  for (auto num: numHits) {
147  if(num > 0) nhit += 1;
148  }
149 
150  // If we have enough hits, create a new road.
151  if (nhit >= m_threshold) {
152  ATH_MSG_DEBUG("Found new road with " << nhit << " hits relative to " << m_threshold);
153  m_roads.emplace_back();
154  FPGATrackSimRoad & road = m_roads.back();
155  road.setRoadID(roads.size() - 1);
156 
157  // Set the "Hough x" and "Hough y" using the track parameters.
158  road.setX(trackphi);
159  road.setY(trackqoverpt);
160  road.setXBin(track->getHoughXBin());
161  road.setYBin(track->getHoughYBin());
162  road.setSubRegion(track->getSubRegion());
163 
164  // figure out bit mask for wild card layers
165  unsigned int wclayers = 0;
166  for (unsigned i = 0; i < numHits.size(); i++){
167  if(numHits[i]==0) wclayers |= (0x1 << i);
168  }
169  road.setWCLayers(wclayers);
170 
171  // set hit layers and hits
172  road.setHitLayers(hitLayers);
173  road.setHits(std::move(road_hits));
174  }
175  }
176 
177  // Copy the roads we found into the output argument and return success.
178  roads.reserve(m_roads.size());
179  for (FPGATrackSimRoad & r : m_roads) {
180  roads.emplace_back(std::make_shared<const FPGATrackSimRoad>(r));
181  }
182  ATH_MSG_DEBUG("Found " << m_roads.size() << " new roads in second stage.");
183 
184  return StatusCode::SUCCESS;
185 }
beamspotman.r
def r
Definition: beamspotman.py:676
getMenu.algname
algname
Definition: getMenu.py:54
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimWindowExtensionTool::m_fieldCorrection
Gaudi::Property< bool > m_fieldCorrection
Definition: FPGATrackSimWindowExtensionTool.h:52
FPGATrackSimHit::getLayer
unsigned getLayer() const
Definition: FPGATrackSimHit.cxx:77
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
FPGATrackSimConstants.h
FPGATrackSimWindowExtensionTool::m_FPGATrackSimBankSvc
ServiceHandle< IFPGATrackSimBankSvc > m_FPGATrackSimBankSvc
Definition: FPGATrackSimWindowExtensionTool.h:45
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
FPGATrackSimWindowExtensionTool::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: FPGATrackSimWindowExtensionTool.cxx:50
FPGATrackSimWindowExtensionTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimWindowExtensionTool.cxx:29
FPGATrackSimWindowExtensionTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimWindowExtensionTool.h:63
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
FPGATrackSimPlaneMap::map
void map(FPGATrackSimHit &hit) const
Definition: FPGATrackSimPlaneMap.cxx:234
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
fieldCorrection
double fieldCorrection(unsigned region, double qpt, double r)
Definition: FPGATrackSimFunctions.cxx:163
FPGATrackSimWindowExtensionTool::m_windows
Gaudi::Property< std::vector< float > > m_windows
Definition: FPGATrackSimWindowExtensionTool.h:50
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGATrackSimRoad::setX
void setX(float v)
Definition: FPGATrackSimRoad.h:76
FPGATrackSimRegionMap::isInRegion
bool isInRegion(uint32_t region, const FPGATrackSimHit &hit) const
Definition: FPGATrackSimRegionMap.cxx:225
FPGATrackSimWindowExtensionTool::FPGATrackSimWindowExtensionTool
FPGATrackSimWindowExtensionTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimWindowExtensionTool.cxx:23
FPGATrackSimWindowExtensionTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimWindowExtensionTool.h:46
FPGATrackSimPlaneMap
Definition: FPGATrackSimPlaneMap.h:62
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimRoad::setSubRegion
void setSubRegion(int v)
Definition: FPGATrackSimRoad.h:73
FPGATrackSimWindowExtensionTool::m_nLayers_2ndStage
unsigned m_nLayers_2ndStage
Definition: FPGATrackSimWindowExtensionTool.h:67
FPGATrackSimWindowExtensionTool::m_nLayers_1stStage
unsigned m_nLayers_1stStage
Definition: FPGATrackSimWindowExtensionTool.h:66
FPGATrackSimWindowExtensionTool::m_phits_atLayer
std::map< unsigned, std::map< unsigned, std::vector< std::shared_ptr< const FPGATrackSimHit > > > > m_phits_atLayer
Definition: FPGATrackSimWindowExtensionTool.h:65
FPGATrackSimWindowExtensionTool::m_threshold
Gaudi::Property< int > m_threshold
Definition: FPGATrackSimWindowExtensionTool.h:49
FPGATrackSimHit::isMapped
bool isMapped() const
Definition: FPGATrackSimHit.cxx:13
FPGATrackSimWindowExtensionTool::m_idealGeoRoads
Gaudi::Property< bool > m_idealGeoRoads
Definition: FPGATrackSimWindowExtensionTool.h:53
FPGATrackSimWindowExtensionTool::m_zwindows
Gaudi::Property< std::vector< float > > m_zwindows
Definition: FPGATrackSimWindowExtensionTool.h:51
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
FPGATrackSimWindowExtensionTool.h
Default track extension algorithm to produce "second stage" roads.
FPGATrackSimRoad::setYBin
void setYBin(unsigned v)
Definition: FPGATrackSimRoad.h:75
FPGATrackSimRegionMap
Definition: FPGATrackSimRegionMap.h:62
FPGATrackSimRoad::setY
void setY(float v)
Definition: FPGATrackSimRoad.h:77
FPGATrackSimRoad::setRoadID
void setRoadID(int roadID)
Definition: FPGATrackSimRoad.h:57
FPGATrackSimRoad::setHitLayers
void setHitLayers(layer_bitmask_t hit_layers)
Definition: FPGATrackSimRoad.h:62
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
FPGATrackSimTypes.h
FPGATrackSimSectorBank.h
This file declares a class that stores the module IDs of the sectors.
FPGATrackSimRoad::setHits
void setHits(std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit >>> &&hits)
Definition: FPGATrackSimRoad.cxx:139
FPGATrackSimRoad
Definition: FPGATrackSimRoad.h:30
FPGATrackSimRoad::setWCLayers
void setWCLayers(layer_bitmask_t wc_layers)
Definition: FPGATrackSimRoad.h:63
FPGATrackSimRoad::setXBin
void setXBin(unsigned v)
Definition: FPGATrackSimRoad.h:74