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