28 return(phiAcc.isAvailable(*p) ? phiAcc(*p) :
p->phi());
38 return(etaAcc.isAvailable(*p) ? etaAcc(*p) :
p->eta());
42 template<
class U,
class V>
44 comp_deltaPhi(
const U* p1,
const V* p2) {
46 float dphi =
phi(p1) -
phi(p2);
48 while (dphi >=
M_PI) {
51 while (dphi < -
M_PI) {
54 return std::fabs(dphi);
58 template<
class U,
class V>
60 comp_deltaEta(
const U* p1,
const V* p2) {
65 template<
class U,
class V>
67 comp_deltaR(
const U* p1,
const V* p2) {
68 return sqrt(
pow(comp_deltaPhi(p1, p2), 2.) +
pow(comp_deltaEta(p1, p2), 2.));
74 sort_pt(
const U* p1,
const U* p2) {
75 return pt(p1) <
pt(p2);
81 sort_eta(
const U* p1,
const U* p2) {
88 sort_phi(
const U* p1,
const U* p2) {
96 declareInterface<IAsgSelectionTool>(
this);
104 return StatusCode::FAILURE;
114 m_cuts.emplace_back(
"dRmax",
"Cut on maximal dR between track and truth particle.");
117 m_cuts.emplace_back(
"pTResMax",
118 "Cut on maximal, relativ pT difference between track and truth particle.");
122 for (
const auto& cut :
m_cuts) {
123 if (
m_accept.addCut(cut.first, cut.second) < 0) {
124 ATH_MSG_ERROR(
"Failed to add cut " << cut.first <<
" because the AcceptInfo object is full.");
125 return StatusCode::FAILURE;
130 m_numPassedCuts.resize(
m_accept.getNCuts(), 0);
138 m_accept.addCut(
"nop",
"Forcing to have length 1.");
141 return StatusCode::SUCCESS;
153 "accept(...) function called without needed Truth- or TrackParticleContainer. Please use one of the dRMatchingTool-specific accept methods.");
158template<
class T,
class U>
161 std::vector< const U* >& vec_pt,
162 std::vector< const U* >& vec_eta,
163 std::vector< const U* >& vec_phi,
164 bool (* selectionTool)(
const U*))
const {
168 if (selectionTool and !(*selectionTool)(p)) {
174 vec_eta.push_back(p);
175 vec_phi.push_back(p);
179 std::sort(vec_pt.begin(), vec_pt.end(), sort_pt <U>);
180 std::sort(vec_eta.begin(), vec_eta.end(), sort_eta<U>);
181 std::sort(vec_phi.begin(), vec_phi.end(), sort_phi<U>);
232template<
class U,
class V>
235 std::vector< const V* >& vec_pt,
236 std::vector< const V* >& vec_eta,
237 std::vector< const V* >& vec_phi,
238 float&
dRmin)
const {
243 auto it_pt_lower =
m_pTResMax < 0 ? vec_pt.begin() :
244 std::lower_bound(vec_pt.begin(), vec_pt.end(),
246 [](
const V* o,
const float& val) ->
bool {
250 auto it_pt_upper =
m_pTResMax < 0 ? vec_pt.end() :
251 std::upper_bound(vec_pt.begin(), vec_pt.end(),
253 [](
const float& val,
const V* o) ->
bool {
257 auto it_eta_lower =
m_dRmax < 0 ? vec_eta.begin() :
258 std::lower_bound(vec_eta.begin(), vec_eta.end(),
260 [](
const V* o,
const float& val) ->
bool {
264 auto it_eta_upper =
m_dRmax < 0 ? vec_eta.end() :
265 std::upper_bound(vec_eta.begin(), vec_eta.end(),
267 [](
const float& val,
const V* o) ->
bool {
275 bool wrap = wrapLow or wrapHigh;
277 auto it_phi_lower =
m_dRmax < 0 ? vec_phi.begin() :
278 std::lower_bound(vec_phi.begin(), vec_phi.end(),
280 [](
const V* o,
const float& val) ->
bool {
284 auto it_phi_upper =
m_dRmax < 0 ? vec_phi.end() :
285 std::upper_bound(vec_phi.begin(), vec_phi.end(),
287 [](
const float& val,
const V* o) ->
bool {
292 if (
m_pTResMax > 0 and it_pt_upper < it_pt_lower) {
294 }
else if (
m_dRmax > 0 and it_eta_upper < it_eta_lower) {
296 }
else if (
m_dRmax > 0 and((!wrap and it_phi_upper < it_phi_lower)or
297 (wrap and it_phi_upper > it_phi_lower))) {
302 std::vector< const V* >
set(vec_pt);
308 std::vector< const V* > subset_pt(it_pt_lower, it_pt_upper);
309 std::vector< const V* > subset_eta(it_eta_lower, it_eta_upper);
310 std::vector< const V* > subset_phi;
312 subset_phi = std::vector< const V* >(it_phi_lower, it_phi_upper);
314 subset_phi = std::vector< const V* >(vec_phi.begin(), it_phi_upper);
315 subset_phi.insert(subset_phi.end(), it_phi_lower, vec_phi.end());
319 std::vector< std::vector< const V* > > subsets;
321 subsets.push_back(subset_pt);
324 subsets.push_back(subset_eta);
325 subsets.push_back(subset_phi);
329 for (std::vector< const V* > subset : subsets) {
335 std::set_intersection(
set.begin(),
set.end(),
336 subset.begin(), subset.end(),
349 return set.size() > 0;
354 for (
const V* other :
set) {
355 float dR = comp_deltaR(p, other);
369 std::lock_guard<std::mutex> lock{
m_mutex};
370 const EventContext& ctx{Gaudi::Hive::currentContext()};
372 ent->
check(ctx.evt());
393 for (
const auto& cut :
m_cuts) {
396 m_numPassedCuts[pos]++;
414 std::lock_guard<std::mutex> lock{
m_mutex};
415 const EventContext& ctx{Gaudi::Hive::currentContext()};
417 ent->
check(ctx.evt());
438 for (
const auto& cut :
m_cuts) {
441 m_numPassedCuts[pos]++;
459 std::lock_guard<std::mutex> lock{
m_mutex};
460 const EventContext& ctx{Gaudi::Hive::currentContext()};
462 ent->
check(ctx.evt());
468 bool passes(
false), passesThis(
false);
473 if (truthSelectionTool and !(*truthSelectionTool)(truth)) {
478 float dR = comp_deltaR(p, truth);
479 float pTRes = std::fabs(pt(truth) / pt(p) - 1.);
482 std::vector<bool> vecPassesThis(
Ncuts,
false);
485 unsigned int icut = 0;
487 vecPassesThis[icut++] = dR <
m_dRmax;
494 passesThis = std::all_of(vecPassesThis.begin(),
499 passes |= passesThis;
516 for (
const auto& cut :
m_cuts) {
519 m_numPassedCuts[pos]++;
538 std::lock_guard<std::mutex> lock{
m_mutex};
539 const EventContext& ctx{Gaudi::Hive::currentContext()};
541 ent->
check(ctx.evt());
547 bool passes(
false), passesThis(
false);
552 if (trackSelectionTool and !(*trackSelectionTool)(track)) {
557 float dR = comp_deltaR(p, track);
558 float pTRes = std::fabs(pt(track) / pt(p) - 1.);
561 std::vector<bool> vecPassesThis(
Ncuts,
false);
564 unsigned int icut = 0;
566 vecPassesThis[icut++] = dR <
m_dRmax;
573 passesThis = std::all_of(vecPassesThis.begin(),
578 passes |= passesThis;
595 for (
const auto& cut :
m_cuts) {
598 m_numPassedCuts[pos]++;
616 return StatusCode::SUCCESS;
620 <<
"% passed all cuts.");
621 for (
const auto& cut :
m_cuts) {
622 ULong64_t numPassed = m_numPassedCuts.at(
m_accept.getCutPosition(cut.first));
624 <<
"% passed " << cut.first <<
" cut.");
627 return StatusCode::SUCCESS;
632 std::lock_guard<std::mutex> lock{
m_mutex};
633 const EventContext& ctx{Gaudi::Hive::currentContext()};
635 ent->
check(ctx.evt());
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Helper class to provide constant type-safe access to aux data.
constexpr int pow(int base, int exp) noexcept
Helper class to provide constant type-safe access to aux data.
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
unsigned int getCutPosition(const std::string &cutName) const
Get the bit position of a cut.
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Class providing the definition of the 4-vector interface.
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
std::vector< const xAOD::TrackParticle * > m_trackParticlesSortedPt
std::vector< const xAOD::TrackParticle * > m_trackParticlesSortedEta
xAOD::TruthParticleContainer m_baseTruthContainer
std::vector< const xAOD::TruthParticle * > m_truthParticlesSortedEta
void check(EventContext::ContextEvt_t evt)
std::vector< const xAOD::TrackParticle * > m_trackParticlesSortedPhi
std::vector< const xAOD::TruthParticle * > m_truthParticlesSortedPt
std::vector< const xAOD::TruthParticle * > m_truthParticlesSortedPhi
xAOD::TrackParticleContainer m_baseTrackContainer