ATLAS Offline Software
FPGATrackSimEventSelectionSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TMath.h"
6 
19 
20 using namespace asg::msgUserCode;
21 
23  base_class(name,svc)
24 {}
25 
27 {
28  if (!m_regions) createRegions();
29 
32 
33  if (m_sampleType.value() == "skipTruth") m_st = SampleType::skipTruth;
34  else if (m_sampleType.value() == "singleElectrons") m_st = SampleType::singleElectrons;
35  else if (m_sampleType.value() == "singleMuons") m_st = SampleType::singleMuons;
36  else if (m_sampleType.value() == "singlePions") m_st = SampleType::singlePions;
37  else if (m_sampleType.value() == "LLPs") m_st = SampleType::LLPs;
38  else {
39  ATH_MSG_ERROR("initialize(): sampleType doesn't exist. ");
40  return StatusCode::FAILURE;
41  }
42 
43  // If we are doing large-radius tracks, we want to restrict the hits entering the
44  // process as before, but we will accept any track as belonging to this region that has
45  // most of its hits within the region, regardless of eta and phi.
46  // We will also set a minimum pT of 5 GeV.
47  m_trackmin = m_min;
48  m_trackmax = m_max;
49  double pTCutVal = 1./(1000.*m_minLRTpT);
50  if (m_LRT) {
51  m_trackmin.qOverPt = -1*pTCutVal;
52  m_trackmin.d0 = -300;
53  m_trackmin.z0 = -500;
54  m_trackmax.qOverPt = pTCutVal;
55  m_trackmax.d0 = 300;
56  m_trackmax.z0 = 500;
57  }
58 
59  // Should really be printing the full information, but it conflicts with
60  // the requirement that log files be identical .....
61  ATH_MSG_INFO("FPGATrackSimEventSelectionSvc::initialize(): " <<
62  "regionID = " << m_regionID << ", " <<
63  "min = {" << m_min << "}, " <<
64  "max = {" << m_max << "}, " <<
65  "sampleType = " << std::string(m_sampleType) << ", " <<
66  "withPU = " << static_cast<bool>(m_withPU));
67 
68  return StatusCode::SUCCESS;
69 }
70 
72 {
73  if (m_regions) delete m_regions;
74  ATH_MSG_INFO("FPGATrackSimEventSelectionSvc::finalize()");
75 
76  return StatusCode::SUCCESS;
77 }
78 
80 {
81  float eta = TMath::ASinH(hit.getGCotTheta());
82  float phi = hit.getGPhi();
83 
84  if (eta >= m_min.eta && eta <= m_max.eta
85  && phi >= m_min.phi && phi <= m_max.phi)
86  return true;
87  else
88  return false;
89 }
90 
92 {
93  if (track.getQOverPt() >= m_trackmin.qOverPt && track.getQOverPt() <= m_trackmax.qOverPt
94  && track.getEta() >= m_trackmin.eta && track.getEta() <= m_trackmax.eta
95  && track.getPhi() >= m_trackmin.phi && track.getPhi() <= m_trackmax.phi
96  && track.getD0() >= m_trackmin.d0 && track.getD0() <= m_trackmax.d0
97  && track.getZ0() >= m_trackmin.z0 && track.getZ0() <= m_trackmax.z0)
98  return true;
99  else
100  return false;
101 }
102 
104 {
105  if (track.getQOverPt() >= m_trackmin.qOverPt && track.getQOverPt() <= m_trackmax.qOverPt)
106  return true;
107  else
108  return false;
109 }
110 
112 {
113  if (track.getEta() >= m_trackmin.eta && track.getEta() <= m_trackmax.eta)
114  return true;
115  else
116  return false;
117 }
118 
120 {
121  if (track.getPhi() >= m_trackmin.phi && track.getPhi() <= m_trackmax.phi)
122  return true;
123  else
124  return false;
125 }
126 
128 {
129  if (track.getD0() >= m_trackmin.d0 && track.getD0() <= m_trackmax.d0)
130  return true;
131  else
132  return false;
133 }
134 
136 {
137  if (track.getZ0() >= m_trackmin.z0 && track.getZ0() <= m_trackmax.z0)
138  return true;
139  else
140  return false;
141 }
142 
144 {
145  if (offlineTrack.getQOverPt() >= m_trackmin.qOverPt && offlineTrack.getQOverPt() <= m_trackmax.qOverPt
146  && offlineTrack.getEta() >= m_trackmin.eta && offlineTrack.getEta() <= m_trackmax.eta
147  && offlineTrack.getPhi() >= m_trackmin.phi && offlineTrack.getPhi() <= m_trackmax.phi
148  && offlineTrack.getD0() >= m_trackmin.d0 && offlineTrack.getD0() <= m_trackmax.d0
149  && offlineTrack.getZ0() >= m_trackmin.z0 && offlineTrack.getZ0() <= m_trackmax.z0)
150  return true;
151  else
152  return false;
153 }
154 
156 {
157  if (offlineTrack.getQOverPt() >= m_trackmin.qOverPt && offlineTrack.getQOverPt() <= m_trackmax.qOverPt)
158  return true;
159  else
160  return false;
161 }
162 
164 {
165  if (offlineTrack.getEta() >= m_trackmin.eta && offlineTrack.getEta() <= m_trackmax.eta)
166  return true;
167  else
168  return false;
169 }
170 
172 {
173  if (offlineTrack.getPhi() >= m_trackmin.phi && offlineTrack.getPhi() <= m_trackmax.phi)
174  return true;
175  else
176  return false;
177 }
178 
180 {
181  if (offlineTrack.getD0() >= m_trackmin.d0 && offlineTrack.getD0() <= m_trackmax.d0)
182  return true;
183  else
184  return false;
185 }
186 
188 {
189  if (offlineTrack.getZ0() >= m_trackmin.z0 && offlineTrack.getZ0() <= m_trackmax.z0)
190  return true;
191  else
192  return false;
193 }
194 
196 {
197  // Want a version that allows us to modify the selection parameters here.
198  // If m_trackmin and m_trackmax are unmodified from the region definitions
199  // this should return exactly the same.
200  FPGATrackSimTrackPars cur = truthTrack.getPars();
201  for (unsigned i = 0; i < FPGATrackSimTrackPars::NPARS; i++)
202  {
203  if (cur[i] < m_trackmin[i]) {
204  return false;
205  }
206  if (cur[i] > m_trackmax[i]) {
207  return false;
208  }
209  }
210 
211  ATH_MSG_DEBUG("Passing it. PDGid = " << truthTrack.getPDGCode() << "; barcode = " << truthTrack.getBarcode());
212  return true;
213 }
214 
216 {
217  if (track.getBarcode() == 0 || track.getBarcode() == std::numeric_limits<HepMcParticleLink::barcode_type>::max()) return false;
218  if (track.getEventIndex() == std::numeric_limits<long>::max()) return false;
219  if (track.getQOverPt() == 0) return false;
220 
221  return true;
222 }
223 
225 {
226  if (truthTrack.getBarcode() == 0 || truthTrack.getQ() == 0) return false;
227  if ((!m_allowHighBarcode) && m_st != SampleType::skipTruth && HepMC::is_simulation_particle(&truthTrack)) return false;
228  if (!passCuts(truthTrack)) return false;
229 
230  return true;
231 }
232 
234 {
235  bool retval = false;
237  retval = true;
239  const auto& truthTracks = eventHeader->optional().getTruthTracks();
240  retval = checkTruthTracks(truthTracks);
241  }
242  else if (m_st == SampleType::LLPs) {
243  const auto& truthTracks = eventHeader->optional().getTruthTracks();
244  // Maybe change this later - could be we want LRT selection in all cases but I suspect not
245  if (m_LRT) retval = checkTruthTracksLRT(truthTracks);
246  else retval = checkTruthTracks(truthTracks);
247  }
248  else {
249  ATH_MSG_DEBUG("selectEvent(): Error with sampleType property");
250  }
251 
253  return retval;
254 }
255 
257 {
258  bool retval = false;
260  retval = true;
262  const auto& truthTracks = eventHeader->optional().getTruthTracks();
263  retval = checkTruthTracks(truthTracks);
264  }
265  else if (m_st == SampleType::LLPs) {
266  const auto& truthTracks = eventHeader->optional().getTruthTracks();
267  // Maybe change this later - could be we want LRT selection in all cases but I suspect not
268  if (m_LRT) retval = checkTruthTracksLRT(truthTracks);
269  else retval = checkTruthTracks(truthTracks);
270  }
271  else {
272  ATH_MSG_DEBUG("selectEvent(): Error with sampleType property");
273  }
274 
276  return retval;
277 
278 }
279 
281 {
282  if (!m_regions) createRegions();
283  return m_regions;
284 }
285 
287 {
288  if (!m_regions)
289  {
290  ATH_MSG_INFO("Creating the slices object");
291  MsgStream cmsg(msgSvc(), "FPGATrackSimRegionSlices");
292  cmsg.setLevel(msg().level()); // cause AthMessaging is stupid and doesn't have this function
294  }
295 }
296 
297 bool FPGATrackSimEventSelectionSvc::checkTruthTracks(const std::vector<FPGATrackSimTruthTrack>& truthTracks) const
298 {
299 // find at least one track in the region
300  bool good=false;
301  for (const FPGATrackSimTruthTrack& track : truthTracks){
303  good=true;
304  if (std::abs(track.getPDGCode()) != static_cast<int>(m_st)) {
305  ATH_MSG_WARNING("selectEvent(): TruthTrack PDGCode != sampleType");
306  good=false;
307  }
308  else {
309  ATH_MSG_DEBUG("selectEvent(): found one truth track, in region "
310  <<getRegionID() <<"; track pars: "<< track.getPars());
311  break;
312  }
313  }
314  else {
315  ATH_MSG_DEBUG("selectEvent(): found one truth track over "<<truthTracks.size()<<", out of region "
316  <<getRegionID() <<"; track pars: "<< track.getPars());
317  }
318  }
319  return good;
320 
321 }
322 
323 bool FPGATrackSimEventSelectionSvc::checkTruthTracksLRT(const std::vector<FPGATrackSimTruthTrack>& truthTracks) const
324 {
325  ATH_MSG_DEBUG("selectEvent(): Checking truth tracks with LRT requirements");
326  // Ideally we would make this flexible to use either of two conditions
327  // 1) there is a truth track that passes our region criteria with our modified selections, or
328  // 2) there is a truth track that passes all but the eta and phi requirements, but has
329  // the majority of its associated hits in the region.
330 
331  // Check for 1)
332  for (const auto& truthtrack : truthTracks ) {
333  // If we specified a PDG ID selection, it can go here - but by default this is false
334  if ((m_LRT_pdgID != 0) && (m_LRT_pdgID != truthtrack.getPDGCode())) {
335  if (passCuts(truthtrack)) ANA_MSG_DEBUG("Skipping an otherwise passing track due to wrong PDGID: " << truthtrack.getPDGCode());
336  continue;
337  }
338  if (passCuts(truthtrack)) return true;
339  }
340 
341  // Check for 2)
342  // TODO someday.
343 
344 
345  // Otherwise return false
346  return false;
347 }
FPGATrackSimEventSelectionSvc::passZ0
virtual bool passZ0(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:135
FPGATrackSimEventSelectionSvc::checkTruthTracksLRT
bool checkTruthTracksLRT(const std::vector< FPGATrackSimTruthTrack > &) const
Definition: FPGATrackSimEventSelectionSvc.cxx:323
SampleType::LLPs
@ LLPs
FPGATrackSimEventSelectionSvc.h
FPGATrackSimTrackPars::phi
double phi
Definition: FPGATrackSimTrackPars.h:24
FPGATrackSimLogicalEventInputHeader
Definition: FPGATrackSimLogicalEventInputHeader.h:21
FPGATrackSimRegionSlices.h
Stores slice definitions for FPGATrackSim regions.
FPGATrackSimEventSelectionSvc::checkTruthTracks
bool checkTruthTracks(const std::vector< FPGATrackSimTruthTrack > &) const
Definition: FPGATrackSimEventSelectionSvc.cxx:297
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
FPGATrackSimRegionSlices
Definition: FPGATrackSimRegionSlices.h:25
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimTruthTrack::getQ
int getQ() const
Definition: FPGATrackSimTruthTrack.h:53
FPGATrackSimEventSelectionSvc::selectEvent
virtual bool selectEvent(FPGATrackSimEventInputHeader *) override
Definition: FPGATrackSimEventSelectionSvc.cxx:233
FPGATrackSimTrack
Definition: FPGATrackSimTrack.h:18
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
beamspotman.cur
def cur
Definition: beamspotman.py:671
FPGATrackSimTrackPars::qOverPt
double qOverPt
Definition: FPGATrackSimTrackPars.h:25
FPGATrackSimOfflineTrack::getZ0
double getZ0() const
Definition: FPGATrackSimOfflineTrack.h:29
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
FPGATrackSimOfflineTrack::getEta
double getEta() const
Definition: FPGATrackSimOfflineTrack.h:26
FPGATrackSimRegionSlices::inRegion
bool inRegion(unsigned region, FPGATrackSimTruthTrack const &t) const
Definition: FPGATrackSimRegionSlices.cxx:85
FPGATrackSimTruthTrack
Definition: FPGATrackSimTruthTrack.h:14
FPGATrackSimOfflineTrack.h
FPGATrackSimOfflineTrack::getPhi
double getPhi() const
Definition: FPGATrackSimOfflineTrack.h:27
FPGATrackSimTrackPars::d0
double d0
Definition: FPGATrackSimTrackPars.h:26
FPGATrackSimEventSelectionSvc::passMatching
virtual bool passMatching(FPGATrackSimTrack const &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:215
FPGATrackSimEventSelectionSvc::m_trackmin
FPGATrackSimTrackPars m_trackmin
Definition: FPGATrackSimEventSelectionSvc.h:89
FPGATrackSimEventSelectionSvc::m_regions
FPGATrackSimRegionSlices * m_regions
Definition: FPGATrackSimEventSelectionSvc.h:85
FPGATrackSimEventSelectionSvc::passQOverPt
virtual bool passQOverPt(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:103
SampleType::singleElectrons
@ singleElectrons
FPGATrackSimTrackPars::eta
double eta
Definition: FPGATrackSimTrackPars.h:28
FPGATrackSimEventSelectionSvc::passCuts
virtual bool passCuts(const FPGATrackSimHit &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:79
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
FPGATrackSimOptionalEventInfo::getTruthTracks
const std::vector< FPGATrackSimTruthTrack > & getTruthTracks() const
Definition: FPGATrackSimOptionalEventInfo.h:37
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:134
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
FPGATrackSimLogicalEventInputHeader::optional
FPGATrackSimOptionalEventInfo const & optional() const
Definition: FPGATrackSimLogicalEventInputHeader.h:32
FPGATrackSimEventSelectionSvc::passD0
virtual bool passD0(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:127
FPGATrackSimEventSelectionSvc::FPGATrackSimEventSelectionSvc
FPGATrackSimEventSelectionSvc(const std::string &name, ISvcLocator *svc)
Definition: FPGATrackSimEventSelectionSvc.cxx:22
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FPGATrackSimEventSelectionSvc::passPhi
virtual bool passPhi(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:119
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition: MagicNumbers.h:342
FPGATrackSimOfflineTrack::getQOverPt
double getQOverPt() const
Definition: FPGATrackSimOfflineTrack.h:30
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimEventSelectionSvc::m_selectEvent
bool m_selectEvent
Definition: FPGATrackSimEventSelectionSvc.h:98
FPGATrackSimEventSelectionSvc::finalize
virtual StatusCode finalize() override
Definition: FPGATrackSimEventSelectionSvc.cxx:71
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
MessageCheck.h
macros for messaging and checking status codes
FPGATrackSimEventSelectionSvc::m_sampleType
Gaudi::Property< std::string > m_sampleType
Definition: FPGATrackSimEventSelectionSvc.h:75
FPGATrackSimEventInputHeader
Definition: FPGATrackSimEventInputHeader.h:22
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
FPGATrackSimOfflineTrack
Definition: FPGATrackSimOfflineTrack.h:12
FPGATrackSimEventSelectionSvc::m_max
FPGATrackSimTrackPars m_max
Definition: FPGATrackSimEventSelectionSvc.h:88
SampleType::skipTruth
@ skipTruth
FPGATrackSimEventSelectionSvc::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimEventSelectionSvc.cxx:26
PathResolver.h
FPGATrackSimEventSelectionSvc::m_trackmax
FPGATrackSimTrackPars m_trackmax
Definition: FPGATrackSimEventSelectionSvc.h:90
FPGATrackSimEventInputHeader.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
FPGATrackSimTruthTrack::getPDGCode
int getPDGCode() const
Definition: FPGATrackSimTruthTrack.h:57
MagicNumbers.h
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
FPGATrackSimEventSelectionSvc::m_minLRTpT
Gaudi::Property< float > m_minLRTpT
Definition: FPGATrackSimEventSelectionSvc.h:78
FPGATrackSimEventInputHeader::optional
FPGATrackSimOptionalEventInfo const & optional() const
Definition: FPGATrackSimEventInputHeader.h:34
FPGATrackSimEventSelectionSvc::m_regions_path
Gaudi::Property< std::string > m_regions_path
Definition: FPGATrackSimEventSelectionSvc.h:74
FPGATrackSimRegionSlices::getMax
FPGATrackSimTrackPars const & getMax(unsigned region) const
Definition: FPGATrackSimRegionSlices.h:33
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
FPGATrackSimEventSelectionSvc::m_LRT
Gaudi::Property< bool > m_LRT
Definition: FPGATrackSimEventSelectionSvc.h:77
FPGATrackSimEventSelectionSvc::m_LRT_pdgID
Gaudi::Property< int > m_LRT_pdgID
Definition: FPGATrackSimEventSelectionSvc.h:79
ReadBchFromCool.good
good
Definition: ReadBchFromCool.py:433
FPGATrackSimEventSelectionSvc::passEta
virtual bool passEta(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:111
FPGATrackSimEventSelectionSvc::m_regionID
Gaudi::Property< unsigned int > m_regionID
Definition: FPGATrackSimEventSelectionSvc.h:73
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
FPGATrackSimEventSelectionSvc::m_st
SampleType m_st
Definition: FPGATrackSimEventSelectionSvc.h:84
FPGATrackSimRegionSlices::getMin
FPGATrackSimTrackPars const & getMin(unsigned region) const
Definition: FPGATrackSimRegionSlices.h:32
FPGATrackSimEventSelectionSvc::m_allowHighBarcode
Gaudi::Property< bool > m_allowHighBarcode
Definition: FPGATrackSimEventSelectionSvc.h:80
FPGATrackSimTrackPars::z0
double z0
Definition: FPGATrackSimTrackPars.h:27
FPGATrackSimOfflineTrack::getD0
double getD0() const
Definition: FPGATrackSimOfflineTrack.h:28
FPGATrackSimTrackPars::NPARS
@ NPARS
Definition: FPGATrackSimTrackPars.h:49
FPGATrackSimTruthTrack::getBarcode
HepMcParticleLink::barcode_type getBarcode() const
Definition: FPGATrackSimTruthTrack.h:60
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
SampleType::singlePions
@ singlePions
FPGATrackSimLogicalEventInputHeader.h
SampleType::singleMuons
@ singleMuons
FPGATrackSimTypes.h
FPGATrackSimTruthTrack.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
FPGATrackSimEventSelectionSvc::createRegions
void createRegions()
Definition: FPGATrackSimEventSelectionSvc.cxx:286
FPGATrackSimTruthTrack::getPars
FPGATrackSimTrackPars getPars() const
Definition: FPGATrackSimTruthTrack.h:68
FPGATrackSimTrack.h
FPGATrackSimEventSelectionSvc::m_withPU
Gaudi::Property< bool > m_withPU
Definition: FPGATrackSimEventSelectionSvc.h:76
FPGATrackSimEventSelectionSvc::getRegions
virtual const FPGATrackSimRegionSlices * getRegions() override
Definition: FPGATrackSimEventSelectionSvc.cxx:280
FPGATrackSimHit::getGCotTheta
float getGCotTheta() const
Definition: FPGATrackSimHit.h:135
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288
FPGATrackSimEventSelectionSvc::m_min
FPGATrackSimTrackPars m_min
Definition: FPGATrackSimEventSelectionSvc.h:87
FPGATrackSimEventSelectionSvc::getRegionID
virtual unsigned getRegionID() const override
Definition: FPGATrackSimEventSelectionSvc.h:34