9 #include "../src/TrackTruthSelectionTool.h"
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) {
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) {
81 sort_eta(
const U*
p1,
const U*
p2) {
88 sort_phi(
const U*
p1,
const U*
p2) {
96 m_accept(
"dRMatching"),
99 declareInterface<IAsgSelectionTool>(
this);
111 return StatusCode::FAILURE;
121 m_cuts.emplace_back(
"dRmax",
"Cut on maximal dR between track and truth particle.");
124 m_cuts.emplace_back(
"pTResMax",
125 "Cut on maximal, relativ pT difference between track and truth particle.");
131 ATH_MSG_ERROR(
"Failed to add cut " <<
cut.first <<
" because the AcceptInfo object is full.");
132 return StatusCode::FAILURE;
148 return StatusCode::SUCCESS;
160 "accept(...) function called without needed Truth- or TrackParticleContainer. Please use one of the dRMatchingTool-specific accept methods.");
165 template<
class T,
class U>
168 std::vector< const U* >& vec_pt,
169 std::vector< const U* >& vec_eta,
170 std::vector< const U* >& vec_phi,
171 bool (* selectionTool)(
const U*))
const {
173 for (
const U*
p : *container) {
175 if (selectionTool and !(*selectionTool)(
p)) {
181 vec_eta.push_back(
p);
182 vec_phi.push_back(
p);
186 std::sort(vec_pt.begin(), vec_pt.end(), sort_pt <U>);
187 std::sort(vec_eta.begin(), vec_eta.end(), sort_eta<U>);
188 std::sort(vec_phi.begin(), vec_phi.end(), sort_phi<U>);
239 template<
class U,
class V>
242 std::vector< const V* >& vec_pt,
243 std::vector< const V* >& vec_eta,
244 std::vector< const V* >& vec_phi,
245 float& dRmin)
const {
250 auto it_pt_lower =
m_pTResMax < 0 ? vec_pt.begin() :
251 std::lower_bound(vec_pt.begin(), vec_pt.end(),
253 [](
const V* o,
const float&
val) ->
bool {
257 auto it_pt_upper =
m_pTResMax < 0 ? vec_pt.end() :
258 std::upper_bound(vec_pt.begin(), vec_pt.end(),
260 [](
const float&
val,
const V* o) ->
bool {
264 auto it_eta_lower =
m_dRmax < 0 ? vec_eta.begin() :
265 std::lower_bound(vec_eta.begin(), vec_eta.end(),
267 [](
const V* o,
const float&
val) ->
bool {
271 auto it_eta_upper =
m_dRmax < 0 ? vec_eta.end() :
272 std::upper_bound(vec_eta.begin(), vec_eta.end(),
274 [](
const float&
val,
const V* o) ->
bool {
282 bool wrap = wrapLow or wrapHigh;
284 auto it_phi_lower =
m_dRmax < 0 ? vec_phi.begin() :
285 std::lower_bound(vec_phi.begin(), vec_phi.end(),
287 [](
const V* o,
const float&
val) ->
bool {
291 auto it_phi_upper =
m_dRmax < 0 ? vec_phi.end() :
292 std::upper_bound(vec_phi.begin(), vec_phi.end(),
294 [](
const float&
val,
const V* o) ->
bool {
299 if (
m_pTResMax > 0 and it_pt_upper < it_pt_lower) {
301 }
else if (
m_dRmax > 0 and it_eta_upper < it_eta_lower) {
303 }
else if (
m_dRmax > 0 and((!wrap and it_phi_upper < it_phi_lower)or
304 (wrap and it_phi_upper > it_phi_lower))) {
309 std::vector< const V* >
set(vec_pt);
312 std::sort(
set.begin(),
set.end());
315 std::vector< const V* > subset_pt(it_pt_lower, it_pt_upper);
316 std::vector< const V* > subset_eta(it_eta_lower, it_eta_upper);
317 std::vector< const V* > subset_phi;
319 subset_phi = std::vector< const V* >(it_phi_lower, it_phi_upper);
321 subset_phi = std::vector< const V* >(vec_phi.begin(), it_phi_upper);
322 subset_phi.insert(subset_phi.end(), it_phi_lower, vec_phi.end());
326 std::vector< std::vector< const V* > > subsets;
328 subsets.push_back(subset_pt);
331 subsets.push_back(subset_eta);
332 subsets.push_back(subset_phi);
336 for (std::vector< const V* > subset : subsets) {
338 std::sort(subset.begin(), subset.end());
343 subset.begin(), subset.end(),
356 return set.size() > 0;
362 float dR = comp_deltaR(
p,
other);
376 std::lock_guard<std::mutex> lock{
m_mutex};
377 const EventContext& ctx{Gaudi::Hive::currentContext()};
379 ent->
check(ctx.evt());
403 m_numPassedCuts[
pos]++;
421 std::lock_guard<std::mutex> lock{
m_mutex};
422 const EventContext& ctx{Gaudi::Hive::currentContext()};
424 ent->
check(ctx.evt());
448 m_numPassedCuts[
pos]++;
466 std::lock_guard<std::mutex> lock{
m_mutex};
467 const EventContext& ctx{Gaudi::Hive::currentContext()};
469 ent->
check(ctx.evt());
475 bool passes(
false), passesThis(
false);
480 if (truthSelectionTool and !(*truthSelectionTool)(truth)) {
485 float dR = comp_deltaR(
p, truth);
486 float pTRes = std::fabs(
pt(truth) /
pt(
p) - 1.);
489 std::vector<bool> vecPassesThis(
Ncuts,
false);
492 unsigned int icut = 0;
494 vecPassesThis[icut++] = dR <
m_dRmax;
501 passesThis = std::all_of(vecPassesThis.begin(),
506 passes |= passesThis;
526 m_numPassedCuts[
pos]++;
545 std::lock_guard<std::mutex> lock{
m_mutex};
546 const EventContext& ctx{Gaudi::Hive::currentContext()};
548 ent->
check(ctx.evt());
554 bool passes(
false), passesThis(
false);
559 if (trackSelectionTool and !(*trackSelectionTool)(
track)) {
564 float dR = comp_deltaR(
p,
track);
565 float pTRes = std::fabs(
pt(
track) /
pt(
p) - 1.);
568 std::vector<bool> vecPassesThis(
Ncuts,
false);
571 unsigned int icut = 0;
573 vecPassesThis[icut++] = dR <
m_dRmax;
580 passesThis = std::all_of(vecPassesThis.begin(),
585 passes |= passesThis;
605 m_numPassedCuts[
pos]++;
623 return StatusCode::SUCCESS;
627 <<
"% passed all cuts.");
631 <<
"% passed " <<
cut.first <<
" cut.");
634 return StatusCode::SUCCESS;
639 std::lock_guard<std::mutex> lock{
m_mutex};
640 const EventContext& ctx{Gaudi::Hive::currentContext()};
642 ent->
check(ctx.evt());