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 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.");
124 ATH_MSG_ERROR(
"Failed to add cut " <<
cut.first <<
" because the AcceptInfo object is full.");
125 return StatusCode::FAILURE;
141 return StatusCode::SUCCESS;
153 "accept(...) function called without needed Truth- or TrackParticleContainer. Please use one of the dRMatchingTool-specific accept methods.");
158 template<
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 {
166 for (
const U*
p : *container) {
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>);
232 template<
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);
305 std::sort(
set.begin(),
set.end());
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) {
331 std::sort(subset.begin(), subset.end());
336 subset.begin(), subset.end(),
349 return set.size() > 0;
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());
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());
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;
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;
598 m_numPassedCuts[
pos]++;
616 return StatusCode::SUCCESS;
620 <<
"% passed all cuts.");
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());