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 
79 
80 StatusCode FPGATrackSimEventSelectionSvc::queryInterface(const InterfaceID& riid, void** ppvIf)
81 {
82  if ( !ppvIf ) return StatusCode::FAILURE;
83 
84  // find indirect interfaces :
85  if (IFPGATrackSimEventSelectionSvc::interfaceID().versionMatch(riid)) {
86  *ppvIf = dynamic_cast<IFPGATrackSimEventSelectionSvc*>(this);
87  } else if (base_class::queryInterface(riid, ppvIf).isSuccess()) {
88  return StatusCode::SUCCESS;
89  } else {
90  // Interface is not directly available: try out a base class
91  return ::AthService::queryInterface(riid, ppvIf);
92  }
93  addRef();
94  return StatusCode::SUCCESS;
95 }
96 
97 
99 {
100  float eta = TMath::ASinH(hit.getGCotTheta());
101  float phi = hit.getGPhi();
102 
103  if (eta >= m_min.eta && eta <= m_max.eta
104  && phi >= m_min.phi && phi <= m_max.phi)
105  return true;
106  else
107  return false;
108 }
109 
111 {
112  if (track.getQOverPt() >= m_trackmin.qOverPt && track.getQOverPt() <= m_trackmax.qOverPt
113  && track.getEta() >= m_trackmin.eta && track.getEta() <= m_trackmax.eta
114  && track.getPhi() >= m_trackmin.phi && track.getPhi() <= m_trackmax.phi
115  && track.getD0() >= m_trackmin.d0 && track.getD0() <= m_trackmax.d0
116  && track.getZ0() >= m_trackmin.z0 && track.getZ0() <= m_trackmax.z0)
117  return true;
118  else
119  return false;
120 }
121 
123 {
124  if (track.getQOverPt() >= m_trackmin.qOverPt && track.getQOverPt() <= m_trackmax.qOverPt)
125  return true;
126  else
127  return false;
128 }
129 
131 {
132  if (track.getEta() >= m_trackmin.eta && track.getEta() <= m_trackmax.eta)
133  return true;
134  else
135  return false;
136 }
137 
139 {
140  if (track.getPhi() >= m_trackmin.phi && track.getPhi() <= m_trackmax.phi)
141  return true;
142  else
143  return false;
144 }
145 
147 {
148  if (track.getD0() >= m_trackmin.d0 && track.getD0() <= m_trackmax.d0)
149  return true;
150  else
151  return false;
152 }
153 
155 {
156  if (track.getZ0() >= m_trackmin.z0 && track.getZ0() <= m_trackmax.z0)
157  return true;
158  else
159  return false;
160 }
161 
163 {
164  if (offlineTrack.getQOverPt() >= m_trackmin.qOverPt && offlineTrack.getQOverPt() <= m_trackmax.qOverPt
165  && offlineTrack.getEta() >= m_trackmin.eta && offlineTrack.getEta() <= m_trackmax.eta
166  && offlineTrack.getPhi() >= m_trackmin.phi && offlineTrack.getPhi() <= m_trackmax.phi
167  && offlineTrack.getD0() >= m_trackmin.d0 && offlineTrack.getD0() <= m_trackmax.d0
168  && offlineTrack.getZ0() >= m_trackmin.z0 && offlineTrack.getZ0() <= m_trackmax.z0)
169  return true;
170  else
171  return false;
172 }
173 
175 {
176  if (offlineTrack.getQOverPt() >= m_trackmin.qOverPt && offlineTrack.getQOverPt() <= m_trackmax.qOverPt)
177  return true;
178  else
179  return false;
180 }
181 
183 {
184  if (offlineTrack.getEta() >= m_trackmin.eta && offlineTrack.getEta() <= m_trackmax.eta)
185  return true;
186  else
187  return false;
188 }
189 
191 {
192  if (offlineTrack.getPhi() >= m_trackmin.phi && offlineTrack.getPhi() <= m_trackmax.phi)
193  return true;
194  else
195  return false;
196 }
197 
199 {
200  if (offlineTrack.getD0() >= m_trackmin.d0 && offlineTrack.getD0() <= m_trackmax.d0)
201  return true;
202  else
203  return false;
204 }
205 
207 {
208  if (offlineTrack.getZ0() >= m_trackmin.z0 && offlineTrack.getZ0() <= m_trackmax.z0)
209  return true;
210  else
211  return false;
212 }
213 
215 {
216  // Want a version that allows us to modify the selection parameters here.
217  // If m_trackmin and m_trackmax are unmodified from the region definitions
218  // this should return exactly the same.
219  FPGATrackSimTrackPars cur = truthTrack.getPars();
220  for (unsigned i = 0; i < FPGATrackSimTrackPars::NPARS; i++)
221  {
222  if (cur[i] < m_trackmin[i]) {
223  return false;
224  }
225  if (cur[i] > m_trackmax[i]) {
226  return false;
227  }
228  }
229 
230  ATH_MSG_DEBUG("Passing it. PDGid = " << truthTrack.getPDGCode() << "; barcode = " << truthTrack.getBarcode());
231  return true;
232 }
233 
235 {
236  if (track.getBarcode() == 0 || track.getBarcode() == std::numeric_limits<long>::max()) return false;
237  if (track.getEventIndex() == std::numeric_limits<long>::max()) return false;
238  if (track.getQOverPt() == 0) return false;
239 
240  return true;
241 }
242 
244 {
245  if (truthTrack.getBarcode() == 0 || truthTrack.getQ() == 0) return false;
246  if ((!m_allowHighBarcode) && m_st != SampleType::skipTruth && HepMC::is_simulation_particle(&truthTrack)) return false;
247  if (!passCuts(truthTrack)) return false;
248 
249  return true;
250 }
251 
253 {
255  return true;
257  const auto& truthTracks = eventHeader->optional().getTruthTracks();
258  return checkTruthTracks(truthTracks);
259  }
260  else if (m_st == SampleType::LLPs) {
261  const auto& truthTracks = eventHeader->optional().getTruthTracks();
262  // Maybe change this later - could be we want LRT selection in all cases but I suspect not
263  if (m_LRT) return checkTruthTracksLRT(truthTracks);
264  else return checkTruthTracks(truthTracks);
265  }
266  else {
267  ATH_MSG_DEBUG("selectEvent(): Error with sampleType property");
268  return false;
269  }
270 }
271 
273 {
275  return true;
277  const auto& truthTracks = eventHeader->optional().getTruthTracks();
278  return checkTruthTracks(truthTracks);
279  }
280  else if (m_st == SampleType::LLPs) {
281  const auto& truthTracks = eventHeader->optional().getTruthTracks();
282  // Maybe change this later - could be we want LRT selection in all cases but I suspect not
283  if (m_LRT) return checkTruthTracksLRT(truthTracks);
284  else return checkTruthTracks(truthTracks);
285  }
286  else {
287  ATH_MSG_DEBUG("selectEvent(): Error with sampleType property");
288  return false;
289  }
290 
291 }
292 
294 {
295  if (!m_regions) createRegions();
296  return m_regions;
297 }
298 
300 {
301  if (!m_regions)
302  {
303  ATH_MSG_INFO("Creating the slices object");
304  MsgStream cmsg(msgSvc(), "FPGATrackSimRegionSlices");
305  cmsg.setLevel(msg().level()); // cause AthMessaging is stupid and doesn't have this function
307  }
308 }
309 
310 bool FPGATrackSimEventSelectionSvc::checkTruthTracks(const std::vector<FPGATrackSimTruthTrack>& truthTracks) const
311 {
312 // find at least one track in the region
313  bool good=false;
314  for (const FPGATrackSimTruthTrack& track : truthTracks){
316  good=true;
317  if (std::abs(track.getPDGCode()) != static_cast<int>(m_st)) {
318  ATH_MSG_WARNING("selectEvent(): TruthTrack PDGCode != sampleType");
319  good=false;
320  }
321  else {
322  ATH_MSG_DEBUG("selectEvent(): found one truth track, in region "
323  <<getRegionID() <<"; track pars: "<< truthTracks.front().getPars());
324  break;
325  }
326  }
327  else {
328  ATH_MSG_DEBUG("selectEvent(): found one truth track over "<<truthTracks.size()<<", out of region "
329  <<getRegionID() <<"; track pars: "<< truthTracks.front().getPars());
330  }
331  }
332  return good;
333 
334 }
335 
336 bool FPGATrackSimEventSelectionSvc::checkTruthTracksLRT(const std::vector<FPGATrackSimTruthTrack>& truthTracks) const
337 {
338  ATH_MSG_DEBUG("selectEvent(): Checking truth tracks with LRT requirements");
339  // Ideally we would make this flexible to use either of two conditions
340  // 1) there is a truth track that passes our region criteria with our modified selections, or
341  // 2) there is a truth track that passes all but the eta and phi requirements, but has
342  // the majority of its associated hits in the region.
343 
344  // Check for 1)
345  for (const auto& truthtrack : truthTracks ) {
346  // If we specified a PDG ID selection, it can go here - but by default this is false
347  if ((m_LRT_pdgID != 0) && (m_LRT_pdgID != truthtrack.getPDGCode())) {
348  if (passCuts(truthtrack)) ANA_MSG_DEBUG("Skipping an otherwise passing track due to wrong PDGID: " << truthtrack.getPDGCode());
349  continue;
350  }
351  if (passCuts(truthtrack)) return true;
352  }
353 
354  // Check for 2)
355  // TODO someday.
356 
357 
358  // Otherwise return false
359  return false;
360 }
FPGATrackSimEventSelectionSvc::passZ0
virtual bool passZ0(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:154
FPGATrackSimEventSelectionSvc::checkTruthTracksLRT
bool checkTruthTracksLRT(const std::vector< FPGATrackSimTruthTrack > &) const
Definition: FPGATrackSimEventSelectionSvc.cxx:336
SampleType::LLPs
@ LLPs
FPGATrackSimTruthTrack::getBarcode
unsigned long getBarcode() const
Definition: FPGATrackSimTruthTrack.h:57
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:310
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
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:50
FPGATrackSimEventSelectionSvc::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIf) override
Definition: FPGATrackSimEventSelectionSvc.cxx:80
FPGATrackSimTrack
Definition: FPGATrackSimTrack.h:16
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:28
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
FPGATrackSimOfflineTrack::getEta
double getEta() const
Definition: FPGATrackSimOfflineTrack.h:25
FPGATrackSimRegionSlices::inRegion
bool inRegion(unsigned region, FPGATrackSimTruthTrack const &t) const
Definition: FPGATrackSimRegionSlices.cxx:85
FPGATrackSimTruthTrack
Definition: FPGATrackSimTruthTrack.h:13
FPGATrackSimOfflineTrack.h
FPGATrackSimOfflineTrack::getPhi
double getPhi() const
Definition: FPGATrackSimOfflineTrack.h:26
FPGATrackSimTrackPars::d0
double d0
Definition: FPGATrackSimTrackPars.h:26
FPGATrackSimEventSelectionSvc::passMatching
virtual bool passMatching(FPGATrackSimTrack const &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:234
FPGATrackSimEventSelectionSvc::m_trackmin
FPGATrackSimTrackPars m_trackmin
Definition: FPGATrackSimEventSelectionSvc.h:87
FPGATrackSimEventSelectionSvc::m_regions
FPGATrackSimRegionSlices * m_regions
Definition: FPGATrackSimEventSelectionSvc.h:83
FPGATrackSimEventSelectionSvc::passQOverPt
virtual bool passQOverPt(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:122
IFPGATrackSimEventSelectionSvc
Definition: IFPGATrackSimEventSelectionSvc.h:22
SampleType::singleElectrons
@ singleElectrons
FPGATrackSimTrackPars::eta
double eta
Definition: FPGATrackSimTrackPars.h:28
FPGATrackSimEventSelectionSvc::passCuts
virtual bool passCuts(const FPGATrackSimHit &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:98
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:38
FPGATrackSimHit::getGPhi
float getGPhi() const
Definition: FPGATrackSimHit.h:129
FPGATrackSimLogicalEventInputHeader::optional
FPGATrackSimOptionalEventInfo const & optional() const
Definition: FPGATrackSimLogicalEventInputHeader.h:32
FPGATrackSimEventSelectionSvc::passD0
virtual bool passD0(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:146
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:138
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:299
FPGATrackSimOfflineTrack::getQOverPt
double getQOverPt() const
Definition: FPGATrackSimOfflineTrack.h:29
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:73
FPGATrackSimEventInputHeader
Definition: FPGATrackSimEventInputHeader.h:22
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
FPGATrackSimOfflineTrack
Definition: FPGATrackSimOfflineTrack.h:12
FPGATrackSimEventSelectionSvc::selectEvent
virtual bool selectEvent(FPGATrackSimEventInputHeader *) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:252
FPGATrackSimEventSelectionSvc::m_max
FPGATrackSimTrackPars m_max
Definition: FPGATrackSimEventSelectionSvc.h:86
SampleType::skipTruth
@ skipTruth
FPGATrackSimEventSelectionSvc::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimEventSelectionSvc.cxx:26
PathResolver.h
FPGATrackSimEventSelectionSvc::m_trackmax
FPGATrackSimTrackPars m_trackmax
Definition: FPGATrackSimEventSelectionSvc.h:88
FPGATrackSimEventInputHeader.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FPGATrackSimTruthTrack::getPDGCode
int getPDGCode() const
Definition: FPGATrackSimTruthTrack.h:54
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:76
FPGATrackSimEventInputHeader::optional
FPGATrackSimOptionalEventInfo const & optional() const
Definition: FPGATrackSimEventInputHeader.h:33
FPGATrackSimEventSelectionSvc::m_regions_path
Gaudi::Property< std::string > m_regions_path
Definition: FPGATrackSimEventSelectionSvc.h:72
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:75
FPGATrackSimEventSelectionSvc::m_LRT_pdgID
Gaudi::Property< int > m_LRT_pdgID
Definition: FPGATrackSimEventSelectionSvc.h:77
ReadBchFromCool.good
good
Definition: ReadBchFromCool.py:433
FPGATrackSimEventSelectionSvc::passEta
virtual bool passEta(const FPGATrackSimTrack &) const override
Definition: FPGATrackSimEventSelectionSvc.cxx:130
FPGATrackSimEventSelectionSvc::m_regionID
Gaudi::Property< unsigned int > m_regionID
Definition: FPGATrackSimEventSelectionSvc.h:71
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
FPGATrackSimEventSelectionSvc::m_st
SampleType m_st
Definition: FPGATrackSimEventSelectionSvc.h:82
FPGATrackSimRegionSlices::getMin
FPGATrackSimTrackPars const & getMin(unsigned region) const
Definition: FPGATrackSimRegionSlices.h:32
FPGATrackSimEventSelectionSvc::m_allowHighBarcode
Gaudi::Property< bool > m_allowHighBarcode
Definition: FPGATrackSimEventSelectionSvc.h:78
FPGATrackSimTrackPars::z0
double z0
Definition: FPGATrackSimTrackPars.h:27
FPGATrackSimOfflineTrack::getD0
double getD0() const
Definition: FPGATrackSimOfflineTrack.h:27
FPGATrackSimTrackPars::NPARS
@ NPARS
Definition: FPGATrackSimTrackPars.h:49
IFPGATrackSimEventSelectionSvc::interfaceID
static const InterfaceID & interfaceID()
Definition: IFPGATrackSimEventSelectionSvc.h:59
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:299
FPGATrackSimTruthTrack::getPars
FPGATrackSimTrackPars getPars() const
Definition: FPGATrackSimTruthTrack.h:64
FPGATrackSimTrack.h
FPGATrackSimEventSelectionSvc::m_withPU
Gaudi::Property< bool > m_withPU
Definition: FPGATrackSimEventSelectionSvc.h:74
FPGATrackSimEventSelectionSvc::getRegions
virtual const FPGATrackSimRegionSlices * getRegions() override
Definition: FPGATrackSimEventSelectionSvc.cxx:293
FPGATrackSimHit::getGCotTheta
float getGCotTheta() const
Definition: FPGATrackSimHit.h:130
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:85
FPGATrackSimEventSelectionSvc::getRegionID
virtual unsigned getRegionID() const override
Definition: FPGATrackSimEventSelectionSvc.h:37