ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimMapMakerAlg.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef FPGATRACKSIM_MAPMAKERALG_H
6#define FPGATRACKSIM_MAPMAKERALG_H
7
8/*
9 * Produce Map files from wrappers.
10 */
11
12#include "AthenaBaseComps/AthAlgorithm.h" //inheritance
13#include "GaudiKernel/ToolHandle.h" //member
14#include "FPGATrackSimObjects/FPGATrackSimTypes.h" //enum classes (e.g. SiliconTech, DetectorZone) in global namespace :-(
16#include "FPGATrackSimInput/IFPGATrackSimEventInputHeaderTool.h" //tool handle template param
19
20#include <fstream> //ofstream members
21#include <tuple> //typedef
22#include <map> //member
23#include <set> //member
24#include <vector> //member
25
26
28class FPGATrackSimHit;
29class TFile;
30
31
32
34{
35 public:
36 typedef std::tuple<SiliconTech, DetectorZone, int, int, int> FPGATrackSimModuleId;
37 //
38 FPGATrackSimMapMakerAlg(const std::string& name, ISvcLocator* pSvcLocator);
39 virtual ~FPGATrackSimMapMakerAlg() = default;
40
41 StatusCode initialize() override;
42 StatusCode execute() override;
43 StatusCode finalize() override;
44
45 private:
46 // Handles
47 ToolHandle<IFPGATrackSimEventInputHeaderTool> m_hitInputTool { this, "InputTool", "FPGATrackSimSGToRawHitsTool/FPGATrackSimInputTool", "HitInput Tool" };
48 ToolHandle<IFPGATrackSimInputTool> m_hitSGInputTool {this, "SGInputTool", "", "Input tool from SG"};
49
50 ServiceHandle<IFPGATrackSimEventSelectionSvc> m_evtSel {this, "eventSelector", "", "Event selection Svc"};
51
53
54 struct Module {
57 int lyr{};
58 int eta{};
59 int phi{};
60 std::vector<int> numTracks; // used for trimming, indexed by slice
61 int plane{-1};
62 Module() = default;
65 return std::tie(det,bec,lyr,eta,phi);
66 }
67 bool operator==(const Module& m) const
68 {
69 return std::tie(det,bec,lyr,eta,phi) == std::tie(m.det,m.bec,m.lyr,m.eta,m.phi);
70 }
71 bool operator<(const Module & m) const
72 {
73 return std::tie(det,bec,lyr,eta,phi) < std::tie(m.det,m.bec,m.lyr,m.eta,m.phi);
74 }
75 bool operator>(const Module & m) const
76 {
77 return std::tie(det,bec,lyr,eta,phi) > std::tie(m.det,m.bec,m.lyr,m.eta,m.phi);
78 }
79 };
80
81 // Flags
82 Gaudi::Property<int> m_maxEvents {this, "maxEvents", 10000, "Max Events"};
83 Gaudi::Property<int> m_region {this, "region", 0, "Region"};
84 Gaudi::Property<float> m_trim {this, "trim", 0.1, "trim modules with less than given percent of tracks"};
85 Gaudi::Property<std::string> m_outFileName {this, "OutFileName", "", "naming convention for maps"};
86 Gaudi::Property<std::string> m_keystring {this, "KeyString", "strip,barrel,2", "key layer to use for subrmap"};
87 Gaudi::Property<std::string> m_keystring2 {this, "KeyString2", "", "second key layer for 2D slicing"};
88 Gaudi::Property<int> m_nSlices {this, "nSlices", -1, "default is full granularity/maximum number of slices possible"};
89 Gaudi::Property<float> m_globalTrim {this, "globalTrim", 0.1, "Trimming applied globally to the key layer before determining slice boundaries"};
90 Gaudi::Property<std::string> m_description {this, "description", "", "tag description"};
91 Gaudi::Property<std::string> m_geoTag {this, "GeometryVersion", "ATLAS-P2-ITK-22-02-00", "Geometry tag that this set of maps is for. TODO can we store/read from wrappers?"};
92 Gaudi::Property<bool> m_remapModules {this, "remapModules", false, "Allow maps to be drawn that slice modules more finely, by remapping module indices"};
93 Gaudi::Property<bool> m_drawSlices {this, "drawSlices", false, "Draw the huge 2D slice histograms"};
94
95 // Instance of the module remap object.
97
98 // For Subregion map making (zslice map)
99 std::map<FPGATrackSimModuleId, Module> m_modules;
100 std::map<int, std::vector<Module*>> m_track2modules, m_slice2modules;
101 std::map<int, int> m_track2slice;
102
103 // Event storage
104 std::vector<FPGATrackSimHit> m_pbHits, m_peHits, m_sbHits, m_seHits, m_allHits;
105
106 int m_pbmax = -1; // pixel barrel largest layer index
107 int m_sbmax = -1;
108 std::vector<int> m_pemax = {-1,-1}; // [positive endcap maxLayer, negative endcap maxLayer]
109 std::vector<int> m_semax = {-1,-1};
110
111
112 /* 3D vector that assigns planes for pmap. indices are [reg][plane][physical layers]
113 -> first two chars are DetType and DetZone, pb = pixel barrel, se = strip endcap
114 -> then the layer number is given, followed by a +/- if positive/negative endcap
115 -> -1 means the layer is not used
116 -> Example: se67+ = Strip Positve Endcap layer 67
117 */
118 const std::vector<std::vector<std::string>>* m_planes{};
119 const std::vector<std::vector<std::string>>* m_planes2{};
120
121 // Fully generic "logical layers". these assign all pixel layers -> first stage and all strip layers -> second stage.
122 // This won't scale well for the parts of the forward region that actually need to extrapolate into the second stage, but
123 // it's good enough for now.
124 const std::vector<std::vector<std::string>> m_planes_generic = {
125 {"pb0", "pe0+","pe1+","pe2+","pe3+","pe4+","pe5+", "pe6+", "pe7+", "pe8+", "pe9+","pe10+","pe11+", "pe12+", "pe13+", "pe14+", "pe15+", "pe16+", },
126 {"pb1", "pe19+", "pe23+", "pe25+", },
127 {"pb2", "pe31+", "pe32+", "pe33+", "pe34+", "pe35+", "pe36+", "pe37+", "pe38+", "pe39+", "pe40+",
128 "pe41+", "pe42+", "pe43+", "pe44+", "pe45+", "pe46+",
129 "pe47+", "pe48+", "pe49+", "pe50+", "pe51+", "pe52+", "pe53+", "pe54+", "pe55+", "pe56+", },
130 {"pb3", "pe57+","pe58+","pe59+", "pe60+", "pe61+", "pe62+", "pe63+", "pe64+", "pe65+", "pe66+","pe67+","pe68+","pe69+"},
131 {"pb4", "pe70+","pe71+","pe72+", "pe73+", "pe74+", "pe75+", "pe76+", "pe77+", "pe78+", "pe79+",
132 "pe80+","pe81+","pe82+", "pe83+", "pe84+", "pe85+", "pe86+", "pe87+", "pe88+", "pe89+",}
133 };
134
135 // This is the second stage version.
136 const std::vector<std::vector<std::string>> m_planes2_generic = {
137 {"pb0", "pe0+","pe1+","pe2+","pe3+","pe4+","pe5+", "pe6+", "pe7+", "pe8+", "pe9+","pe10+","pe11+", "pe12+", "pe13+", "pe14+", "pe15+", "pe16+", },
138 {"pb1", "pe19+", "pe23+", "pe25+", },
139 {"pb2", "pe31+", "pe32+", "pe33+", "pe34+", "pe35+", "pe36+", "pe37+", "pe38+", "pe39+", "pe40+",
140 "pe41+", "pe42+", "pe43+", "pe44+", "pe45+", "pe46+",
141 "pe47+", "pe48+", "pe49+", "pe50+", "pe51+", "pe52+", "pe53+", "pe54+", "pe55+", "pe56+", },
142 {"pb3", "pe57+","pe58+","pe59+", "pe60+", "pe61+", "pe62+", "pe63+", "pe64+", "pe65+", "pe66+","pe67+","pe68+","pe69+"},
143 {"pb4", "pe70+","pe71+","pe72+", "pe73+", "pe74+", "pe75+", "pe76+", "pe77+", "pe78+", "pe79+",
144 "pe80+","pe81+","pe82+", "pe83+", "pe84+", "pe85+", "pe86+", "pe87+", "pe88+", "pe89+",},
145 {"sb0", "se4+", "se0+"},
146 {"sb1", "se5+", "se1+"},
147 {"sb2", "se6+", "se2+"},
148 {"sb3", "se7+", "se3+"},
149 {"sb4", "se8+"},
150 {"sb5", "se9+"},
151 {"sb6", "se10+"},
152 {"sb7", "se11+"}
153 };
154
155 // The generic assignments are the defaults-- but these are actually controlled from python.
156 Gaudi::Property<std::vector<std::vector<std::string>>> m_overridePlanes {this, "planes", m_planes_generic, "Logical layer assignments" };
157 Gaudi::Property<std::vector<std::vector<std::string>>> m_overridePlanes2 {this, "planes2", m_planes2_generic, "Logical layer assignments" };
158
159 std::map <std::string, std::set<int>> m_keylayer; // key layer used in z-slicing, defined by user with KeyString run arg and set using parseKeyString()
160 std::map <std::string, std::set<int>> m_keylayer2; // for 2D slicing
161
162 bool m_key2 = false;
163 std::map <int, int> m_key_etamods; // eta module values of the key layer. each etamod = 1 slice for full granulatiy slicing
164 std::set <int> m_key_etamods2; // for 2D slicing
165 std::set <int> m_usedTracks; // tracks that hit the key layer
166 std::vector <std::vector < std::vector<float> > > m_radii; // used to calculate mean radii per layer for each slice, [slice][plane][hit]
167 std::vector <std::vector < std::vector<float> > > m_z; // used to calculate median z per layer for each slice, [slice][plane][hit]
168 // output map files and monitoring
170 std::unique_ptr<TFile> m_monitorFile{};
171
172
173 // TODO make automatic
174 const std::vector<uint32_t> m_diskIndex = {0,17,47,58,66}; // number of disks per layer in ATLAS-P2-ITK-22-02-00: [17, 30, 11, 8, 9] --> [0,17,47,58,66]
175
176 StatusCode readInputs(bool & done);
177 StatusCode writePmapAndRmap(std::vector<FPGATrackSimHit> const & pbHits, std::vector<FPGATrackSimHit> const & peHits, std::vector<FPGATrackSimHit> const & sbHits, std::vector<FPGATrackSimHit> const & seHits, int region);
178 StatusCode writeSubrmap(std::vector<FPGATrackSimHit> const & allHits);
179 StatusCode writeEtaPatterns(); // writes txt file used in the FPGATrackSimEtaPatternFilterTool to filter roads based on eta module
180 StatusCode writeRadiiFile(std::vector<FPGATrackSimHit> const & allHits); // writes txt file with mean radii per layer for each slice, used in 1D Hough Transform
181 StatusCode writeMedianZFile(std::vector<FPGATrackSimHit> const & allHits); // writes txt file with median z per layer for each slice, used in 1D Hough Transform
182
183 // Helpers
184 void drawSlices(std::vector<FPGATrackSimHit> const & allHits);
185 std::map <std::string, SiliconTech> m_det2tech = { {"pixel",SiliconTech::pixel}, {"strip",SiliconTech::strip} }; // for parsing KeyString
186 std::map <std::string, DetectorZone> m_bec2zone = { {"barrel",DetectorZone::barrel}, {"posEndcap",DetectorZone::posEndcap}, {"negEndcap",DetectorZone::negEndcap} };
187 bool isOnKeyLayer(int keynum, SiliconTech det, DetectorZone bec, int lyr); // returns if hit is on a key layer or not. keynum is either 1 or 2 for the first or second keylayer (if using 2D slicing)
188 int findPlane(const std::vector<std::vector<std::string>>* planes, const std::string& test);
189 std::string makeRmapLines(std::vector<FPGATrackSimHit> const & hits, SiliconTech det, DetectorZone bec, int max);
190 std::string makeSubrmapLines(std::vector<Module*> const & allmods, SiliconTech det, DetectorZone bec, int max);
191 void parseKeyString(); // sets m_keylayer and m_keylayer2 based on the Keystring and Keystring2 run args
192
193};
194
195#endif // FPGATRACKSIMMAPMAKERALG_H
SiliconTech
DetectorZone
This declares a basic interface for input tools which provide the FPGATrackSimEventInputHeader data t...
#define max(a, b)
Definition cfImp.cxx:41
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
std::unique_ptr< TFile > m_monitorFile
StatusCode writePmapAndRmap(std::vector< FPGATrackSimHit > const &pbHits, std::vector< FPGATrackSimHit > const &peHits, std::vector< FPGATrackSimHit > const &sbHits, std::vector< FPGATrackSimHit > const &seHits, int region)
Gaudi::Property< float > m_trim
std::string makeSubrmapLines(std::vector< Module * > const &allmods, SiliconTech det, DetectorZone bec, int max)
const std::vector< std::vector< std::string > > m_planes2_generic
StatusCode writeRadiiFile(std::vector< FPGATrackSimHit > const &allHits)
ToolHandle< IFPGATrackSimInputTool > m_hitSGInputTool
std::vector< std::vector< std::vector< float > > > m_radii
FPGATrackSimMapMakerAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::string makeRmapLines(std::vector< FPGATrackSimHit > const &hits, SiliconTech det, DetectorZone bec, int max)
bool isOnKeyLayer(int keynum, SiliconTech det, DetectorZone bec, int lyr)
std::map< std::string, std::set< int > > m_keylayer2
virtual ~FPGATrackSimMapMakerAlg()=default
std::map< std::string, std::set< int > > m_keylayer
Gaudi::Property< std::string > m_description
std::vector< FPGATrackSimHit > m_sbHits
std::tuple< SiliconTech, DetectorZone, int, int, int > FPGATrackSimModuleId
const std::vector< uint32_t > m_diskIndex
Gaudi::Property< float > m_globalTrim
std::map< FPGATrackSimModuleId, Module > m_modules
FPGATrackSimEventInputHeader m_eventHeader
std::map< std::string, SiliconTech > m_det2tech
std::vector< FPGATrackSimHit > m_seHits
std::vector< FPGATrackSimHit > m_pbHits
Gaudi::Property< std::string > m_keystring2
Gaudi::Property< std::string > m_outFileName
const std::vector< std::vector< std::string > > * m_planes
std::map< int, int > m_track2slice
ToolHandle< IFPGATrackSimEventInputHeaderTool > m_hitInputTool
int findPlane(const std::vector< std::vector< std::string > > *planes, const std::string &test)
const std::vector< std::vector< std::string > > m_planes_generic
Gaudi::Property< std::string > m_keystring
std::map< int, std::vector< Module * > > m_track2modules
Gaudi::Property< std::vector< std::vector< std::string > > > m_overridePlanes
StatusCode writeMedianZFile(std::vector< FPGATrackSimHit > const &allHits)
Gaudi::Property< bool > m_remapModules
const std::vector< std::vector< std::string > > * m_planes2
Gaudi::Property< bool > m_drawSlices
FPGATrackSimModuleRelabel * m_moduleRelabel
Gaudi::Property< int > m_region
std::vector< std::vector< std::vector< float > > > m_z
std::map< int, int > m_key_etamods
Gaudi::Property< std::vector< std::vector< std::string > > > m_overridePlanes2
std::vector< FPGATrackSimHit > m_peHits
Gaudi::Property< std::string > m_geoTag
std::map< int, std::vector< Module * > > m_slice2modules
std::map< std::string, DetectorZone > m_bec2zone
std::vector< FPGATrackSimHit > m_allHits
StatusCode readInputs(bool &done)
StatusCode writeSubrmap(std::vector< FPGATrackSimHit > const &allHits)
Gaudi::Property< int > m_maxEvents
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_evtSel
void drawSlices(std::vector< FPGATrackSimHit > const &allHits)
Gaudi::Property< int > m_nSlices
Module(SiliconTech det, DetectorZone bec, int lyr, int eta, int phi)
bool operator<(const Module &m) const
FPGATrackSimModuleId moduleId() const
bool operator==(const Module &m) const
bool operator>(const Module &m) const