ATLAS Offline Software
FPGATrackSimRegionSlices.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
13 
15 
16 #include <string>
17 #include <iostream>
18 #include <fstream>
19 
20 using namespace asg::msgUserCode;
21 
23 // Constructor/Desctructor
25 
26 
27 FPGATrackSimRegionSlices::FPGATrackSimRegionSlices(std::string const & filepath) // old constructor, we read in a file
28 {
29  // Open the file
30  std::ifstream fin(filepath);
31  if (!fin.is_open())
32  {
33  ANA_MSG_ERROR("Couldn't open " << filepath);
34  throw ("FPGATrackSimRegionSlices couldn't open " + filepath);
35  }
36 
37  // Variables to fill
38  unsigned region;
39  std::string line, key;
41 
42  // Parse the file
43  bool ok = true;
44  while (getline(fin, line))
45  {
46  if (line.empty() || line[0] == '#') continue;
47  std::istringstream sline(line);
48 
49  ok = ok && (sline >> key);
50  if (!ok) break;
51  if (key == "region")
52  {
53  ok = ok && (sline >> region);
54  if (ok && region > 0) m_regions.push_back({ min, max });
55  ok = ok && (region == m_regions.size());
56  min = FPGATrackSimTrackPars(); // reset
57  max = FPGATrackSimTrackPars(); // reset
58  }
59  else if (key == "phi") ok = ok && (sline >> min.phi >> max.phi);
60  else if (key == "eta") ok = ok && (sline >> min.eta >> max.eta);
61  else if (key == "qpt") ok = ok && (sline >> min.qOverPt >> max.qOverPt);
62  else if (key == "d0") ok = ok && (sline >> min.d0 >> max.d0);
63  else if (key == "z0") ok = ok && (sline >> min.z0 >> max.z0);
64  else ok = false;
65 
66  if (!ok) break;
67  }
68 
69  if (!ok)
70  {
71  ANA_MSG_ERROR("Found error reading file at line: " << line);
72  throw "FPGATrackSimRegionSlices read error";
73  }
74 
75  m_regions.push_back({ min, max }); // last region still needs to be added
76 }
77 
78 
79 FPGATrackSimRegionSlices::FPGATrackSimRegionSlices(float mind0, float minz0, float minqQverPt,
80  float maxd0, float maxz0, float maxQoverPt) // new constructor, we pass d0,z0,qoverpt and calculate the rest
81 {
83  min.d0 = mind0;
84  min.z0 = minz0;
85  min.qOverPt = minqQverPt;
86  max.d0 = maxd0;
87  max.z0 = maxz0;
88  max.qOverPt = maxQoverPt;
89 
90 
91  for (unsigned i=0; i < 1280; i++) {
92  double phibinSize = M_PI/16;
93  double etabinSize = 0.2;
94  int phibin = i & 0x1f;
95  int etabin = (i >> 6) & 0x1f;
96  int etaside = (i >> 5) & 0x1; // 1 is positive side, 0 negative side
97  min.phi = phibinSize*phibin;
98  max.phi = phibinSize*(phibin+1);
99 
100  // Force these to fall within [-pi, pi].
101  while (min.phi < M_PI) min.phi += 2*M_PI;
102  while (min.phi >= M_PI) min.phi -= 2*M_PI;
103  while (max.phi < M_PI) max.phi += 2*M_PI;
104  while (max.phi >= M_PI) max.phi -= 2*M_PI;
105 
106  if (etaside > 0) {
107  min.eta = etabinSize * etabin;
108  max.eta = etabinSize * (etabin+1);
109  }
110  else {
111  min.eta = -etabinSize * (etabin+1);
112  max.eta = -etabinSize * etabin;
113  }
114  m_regions.push_back({ min, max });
115  }
116 }
117 
118 
119 
120 
122 // Interface Functions
124 
125 
126 bool FPGATrackSimRegionSlices::inRegion(unsigned region, FPGATrackSimTruthTrack const & t) const
127 {
128  if (region >= m_regions.size())
129  {
130  ANA_MSG_WARNING("inRegion() region " << region << " out-of-bounds " << m_regions.size());
131  return false;
132  }
133  FPGATrackSimTrackPars min = m_regions[region].first;
134  FPGATrackSimTrackPars max = m_regions[region].second;
135  FPGATrackSimTrackPars cur = t.getPars();
136 
137  for (unsigned i = 0; i < FPGATrackSimTrackPars::NPARS; i++)
138  {
139  if (cur[i] < min[i]) return false;
140  if (cur[i] > max[i]) return false;
141  }
142 
143  return true;
144 }
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:215
FPGATrackSimRegionSlices.h
Stores slice definitions for FPGATrackSim regions.
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
beamspotman.cur
def cur
Definition: beamspotman.py:667
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
FPGATrackSimRegionSlices::inRegion
bool inRegion(unsigned region, FPGATrackSimTruthTrack const &t) const
Definition: FPGATrackSimRegionSlices.cxx:126
FPGATrackSimTruthTrack
Definition: FPGATrackSimTruthTrack.h:14
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
MessageCheck.h
macros for messaging and checking status codes
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
FPGATrackSimRegionSlices::FPGATrackSimRegionSlices
FPGATrackSimRegionSlices(std::string const &filepath)
Definition: FPGATrackSimRegionSlices.cxx:27
FPGATrackSimTrackPars::NPARS
@ NPARS
Definition: FPGATrackSimTrackPars.h:49
compute_lumi.fin
fin
Definition: compute_lumi.py:19
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37