ATLAS Offline Software
FPGATrackSimRawToLogicalHitsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
16 
20 
21 
22 
23 FPGATrackSimRawToLogicalHitsTool::FPGATrackSimRawToLogicalHitsTool(const std::string& algname, const std::string &name, const IInterface *ifc) :
24  AthAlgTool(algname,name,ifc){}
25 
26 
28  ATH_CHECK(m_FPGATrackSimMapping.retrieve());
29  ATH_CHECK(m_EvtSel.retrieve());
30 
31  ATH_MSG_INFO("SaveOptional="<<m_saveOptional);
32  // remove deferensed m_towersToMap.value() in newer releases!
33  if( m_towersToMap.value().empty() ){
34  int maxNtowers = m_FPGATrackSimMapping->RegionMap_2nd()->getNRegions();
35  for (int ireg=0;ireg!=maxNtowers;++ireg) m_towers.push_back(ireg);
36  }else{
37  m_towers = m_towersToMap.value();
38  }
39 
40  ATH_MSG_DEBUG ("Configured to process "<<m_towers.size() << " towers");
41  std::stringstream listOfTowers;
42  for (int ireg: m_towers){
43  listOfTowers<<", "<<ireg;
44  }
45  ATH_MSG_DEBUG ("List of Towers: "<<listOfTowers.str());
46  return StatusCode::SUCCESS;
47 }
48 
49 
51 
52  ATH_MSG_DEBUG ("Mapping " << eventHeader.nHits() << " hits using stage " << stage);
53  FPGATrackSimEventInfo eventinfo = eventHeader.event();
54  ATH_MSG_DEBUG ("Getting Event " << eventinfo);
55  logicEventHeader.newEvent(eventinfo);//this also reset all varaibles
56 
57  // Get correct maps
58  const FPGATrackSimPlaneMap *pmap = nullptr;
59  const FPGATrackSimRegionMap *rmap = nullptr;
60  if (stage == 1)
61  {
62  pmap = m_FPGATrackSimMapping->PlaneMap_1st();
63  rmap = m_FPGATrackSimMapping->RegionMap_1st();
64  }
65  else if (stage == 2)
66  {
67  pmap = m_FPGATrackSimMapping->PlaneMap_2nd();
68  rmap = m_FPGATrackSimMapping->RegionMap_2nd();
69  }
70  else
71  {
72  ATH_MSG_FATAL("convert() must have stage == 1 or 2");
73  }
74 
75  logicEventHeader.reserveTowers(m_towers.size());
76  for (int ireg: m_towers){
77  FPGATrackSimTowerInputHeader tower = FPGATrackSimTowerInputHeader(ireg);//default header, can eventually set eta/phi/deta/dphi
78  logicEventHeader.addTower( tower);
79  }
80 
81  ATH_MSG_DEBUG ("Created "<<logicEventHeader.nTowers()<<" towers. Now map Hits");
82 
83  m_missing_hits.clear(); // reset vector of missing hits
84  m_missing_hit_codes.clear();
85 
86 
87  // fill the towers with mapped hits
88  for (auto hit: eventHeader.hits()) { // hit loop
89  // map to the logical hit, copying across the truth
90  pmap->map(hit);
91 
92  // In the ITk geometry, some of the plane IDs are -1 if the layers are not yet being used.
93  // This causes the code in this hit loop to crash. As a workaround for the moment, we currently
94  // skip over hits in layers that are not included in the FPGATrackSim geometry, with plane = -1
95  if (pmap->getLayerSection(hit.getDetType(), hit.getDetectorZone(), hit.getPhysLayer()).layer == -1)
96  {
97  m_missing_hits.push_back(hit);
98  continue;
99  }
100 
101  bool mapped=false;
102  for (unsigned int ireg=0;ireg!=m_towers.size();++ireg){
103  if (rmap->isInRegion(ireg, hit)) {
104  // if the equivalent hit is compatible with this tower the hit is saved
105  logicEventHeader.getTower( ireg )->addHit(hit);
106  ATH_MSG_VERBOSE ("Hit mapped to tower="<<ireg << ", nHits now=" << logicEventHeader.getTower(ireg)->nHits());
107  mapped=true;
108  }
109  }
110 
111  if (!mapped) {
112  // get unmapped hit's error codes
113  ATH_MSG_DEBUG("Unmapped hit: pixel="<<hit.isPixel()<<" Barrel="<<hit.isBarrel() <<" Layer="<<hit.getLayer() <<" PLayer="<<hit.getPhysLayer() << " section="<<hit.getSection());
114  for (unsigned int ireg=0;ireg!=m_towers.size();++ireg){
115  int code = rmap->getUnmappedID(m_towers[ireg], hit);
116  if (code != 111111) m_missing_hit_codes.push_back(code);
117  }
118  hit.setHitType(HitType::unmapped);
119  m_missing_hits.push_back(hit);
120  }
121  } // end hit loop
122 
123  unsigned int notStoredHits = m_missing_hits.size();
124  if (notStoredHits != 0){
125  ATH_MSG_DEBUG ("Found " << notStoredHits << " missing mapped hits in this event");
126  for (unsigned iter = 0; iter < m_missing_hit_codes.size(); iter+=100) {
127  ATH_MSG_VERBOSE ("Missing Hit Code: " << m_missing_hit_codes[iter]);
128  }
129  }
130 
131  if (stage == 1) {
132  FPGATrackSimOptionalEventInfo op = eventHeader.optional();
133  if (m_saveOptional == 2) {
134  logicEventHeader.setOptional(op);
135  }
136  else if (m_saveOptional == 1) {
137  // save offline tracks
140  for (FPGATrackSimOfflineTrack const & offline_t : op.getOfflineTracks()) newop.addOfflineTrack(offline_t);
141  // save truth in region
142  for (FPGATrackSimTruthTrack const & truth_t : op.getTruthTracks()) {
143  if (m_EvtSel->passMatching(truth_t)) newop.addTruthTrack(truth_t);
144  }
145  ATH_MSG_DEBUG("Selected " << newop.nTruthTracks() << " truth tracks");
146  logicEventHeader.setOptional(newop);
147  }
148  }
149 
150  return StatusCode::SUCCESS;
151 }
152 
153 StatusCode FPGATrackSimRawToLogicalHitsTool::getUnmapped(std::vector<FPGATrackSimHit>& missing_hits) {
154  std::copy(m_missing_hits.begin(), m_missing_hits.end(), back_inserter(missing_hits));
155  return StatusCode::SUCCESS;
156 }
157 
159  return m_FPGATrackSimMapping->PlaneMap_1st();
160 }
161 
FPGATrackSimInputUtils.h
FPGATrackSimRawToLogicalHitsTool::convert
StatusCode convert(unsigned stage, const FPGATrackSimEventInputHeader &header, FPGATrackSimLogicalEventInputHeader &logicheader)
Definition: FPGATrackSimRawToLogicalHitsTool.cxx:50
FPGATrackSimRawToLogicalHitsTool::m_missing_hit_codes
std::vector< int > m_missing_hit_codes
Definition: FPGATrackSimRawToLogicalHitsTool.h:48
getMenu.algname
algname
Definition: getMenu.py:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
FPGATrackSimEventInputHeader::hits
const std::vector< FPGATrackSimHit > & hits() const
Definition: FPGATrackSimEventInputHeader.h:36
FPGATrackSimLogicalEventInputHeader
Definition: FPGATrackSimLogicalEventInputHeader.h:21
FPGATrackSimOptionalEventInfo::getOfflineTracks
const std::vector< FPGATrackSimOfflineTrack > & getOfflineTracks() const
Definition: FPGATrackSimOptionalEventInfo.h:32
python.FPGATrackSimAnalysisConfig.stage
stage
Definition: FPGATrackSimAnalysisConfig.py:604
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimPlaneMap.h
Maps physical layers to logical layers.
FPGATrackSimTowerInputHeader::addHit
void addHit(FPGATrackSimHit s)
Definition: FPGATrackSimTowerInputHeader.h:46
FPGATrackSimTowerInputHeader.h
IFPGATrackSimMappingSvc.h
FPGATrackSimTruthTrack
Definition: FPGATrackSimTruthTrack.h:13
FPGATrackSimOfflineTrack.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
FPGATrackSimPlaneMap::getLayerSection
const LayerSection & getLayerSection(SiliconTech siTech, DetectorZone zone, uint32_t physLayer) const
Definition: FPGATrackSimPlaneMap.h:120
FPGATrackSimOptionalEventInfo::getTruthTracks
const std::vector< FPGATrackSimTruthTrack > & getTruthTracks() const
Definition: FPGATrackSimOptionalEventInfo.h:37
FPGATrackSimOptionalEventInfo::nTruthTracks
size_t nTruthTracks() const
Definition: FPGATrackSimOptionalEventInfo.h:38
FPGATrackSimEventInputHeader::nHits
int nHits() const
Definition: FPGATrackSimEventInputHeader.h:37
FPGATrackSimRegionMap.h
Maps ITK module indices to FPGATrackSim regions.
FPGATrackSimLogicalEventInputHeader::getTower
FPGATrackSimTowerInputHeader * getTower(size_t index)
Definition: FPGATrackSimLogicalEventInputHeader.h:39
FPGATrackSimEventInfo
Definition: FPGATrackSimEventInfo.h:14
FPGATrackSimTowerInputHeader::nHits
int nHits() const
Definition: FPGATrackSimTowerInputHeader.h:45
FPGATrackSimRawToLogicalHitsTool::getPlaneMap_1st
const FPGATrackSimPlaneMap * getPlaneMap_1st()
Definition: FPGATrackSimRawToLogicalHitsTool.cxx:158
FPGATrackSimPlaneMap::map
void map(FPGATrackSimHit &hit) const
Definition: FPGATrackSimPlaneMap.cxx:237
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimEventInfo.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FPGATrackSimRawToLogicalHitsTool.h
FPGATrackSimRawToLogicalHitsTool::m_towers
std::vector< int > m_towers
Definition: FPGATrackSimRawToLogicalHitsTool.h:46
FPGATrackSimOfflineHit.h
FPGATrackSimOptionalEventInfo::addOfflineTrack
void addOfflineTrack(const FPGATrackSimOfflineTrack &t)
Definition: FPGATrackSimOptionalEventInfo.h:34
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGATrackSimEventInputHeader
Definition: FPGATrackSimEventInputHeader.h:22
FPGATrackSimOptionalEventInfo
Definition: FPGATrackSimOptionalEventInfo.h:17
FPGATrackSimLogicalEventInputHeader::newEvent
void newEvent(FPGATrackSimEventInfo &event)
Definition: FPGATrackSimLogicalEventInputHeader.h:29
FPGATrackSimRawToLogicalHitsTool::m_missing_hits
std::vector< FPGATrackSimHit > m_missing_hits
Definition: FPGATrackSimRawToLogicalHitsTool.h:47
FPGATrackSimOfflineTrack
Definition: FPGATrackSimOfflineTrack.h:12
FPGATrackSimEventInputHeader::event
FPGATrackSimEventInfo const & event() const
Definition: FPGATrackSimEventInputHeader.h:32
FPGATrackSimOptionalEventInfo::nOfflineTracks
size_t nOfflineTracks() const
Definition: FPGATrackSimOptionalEventInfo.h:33
FPGATrackSimPlaneMap
Definition: FPGATrackSimPlaneMap.h:62
keylayer_zslicemap.rmap
rmap
Definition: keylayer_zslicemap.py:33
FPGATrackSimRawToLogicalHitsTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimRawToLogicalHitsTool.h:40
pmontree.code
code
Definition: pmontree.py:443
FPGATrackSimEventInputHeader.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
FPGATrackSimRawToLogicalHitsTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimRawToLogicalHitsTool.cxx:27
FPGATrackSimEventInputHeader::optional
FPGATrackSimOptionalEventInfo const & optional() const
Definition: FPGATrackSimEventInputHeader.h:33
FPGATrackSimOptionalEventInfo::addTruthTrack
void addTruthTrack(const FPGATrackSimTruthTrack &t)
Definition: FPGATrackSimOptionalEventInfo.h:39
HitType::mapped
@ mapped
FPGATrackSimRawToLogicalHitsTool::m_EvtSel
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
Definition: FPGATrackSimRawToLogicalHitsTool.h:41
LayerSection::layer
int layer
Definition: FPGATrackSimPlaneMap.h:41
FPGATrackSimLogicalEventInputHeader::addTower
void addTower(FPGATrackSimTowerInputHeader s)
Definition: FPGATrackSimLogicalEventInputHeader.h:38
FPGATrackSimOptionalEventInfo::reserveOfflineTracks
void reserveOfflineTracks(size_t size)
Definition: FPGATrackSimOptionalEventInfo.h:44
FPGATrackSimLogicalEventInputHeader::reserveTowers
void reserveTowers(size_t size)
Definition: FPGATrackSimLogicalEventInputHeader.h:40
FPGATrackSimRawToLogicalHitsTool::m_towersToMap
IntegerArrayProperty m_towersToMap
Definition: FPGATrackSimRawToLogicalHitsTool.h:43
FPGATrackSimRawToLogicalHitsTool::FPGATrackSimRawToLogicalHitsTool
FPGATrackSimRawToLogicalHitsTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimRawToLogicalHitsTool.cxx:23
FPGATrackSimLogicalEventInputHeader::setOptional
void setOptional(const FPGATrackSimOptionalEventInfo &o)
Definition: FPGATrackSimLogicalEventInputHeader.h:33
FPGATrackSimRegionMap
Definition: FPGATrackSimRegionMap.h:62
calibdata.copy
bool copy
Definition: calibdata.py:27
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimTowerInputHeader
Definition: FPGATrackSimTowerInputHeader.h:18
FPGATrackSimLogicalEventInputHeader.h
FPGATrackSimTruthTrack.h
FPGATrackSimRawToLogicalHitsTool::getUnmapped
StatusCode getUnmapped(std::vector< FPGATrackSimHit > &missing_hits)
Definition: FPGATrackSimRawToLogicalHitsTool.cxx:153
FPGATrackSimRawToLogicalHitsTool::m_saveOptional
IntegerProperty m_saveOptional
Definition: FPGATrackSimRawToLogicalHitsTool.h:42
FPGATrackSimOptionalEventInfo.h
HitType::unmapped
@ unmapped
FPGATrackSimLogicalEventInputHeader::nTowers
int nTowers() const
Definition: FPGATrackSimLogicalEventInputHeader.h:37