1717#define PWGEM_PHOTONMESON_CORE_EMCPHOTONCUT_H_
1818
1919#include " PWGEM/PhotonMeson/Core/EMBitFlags.h"
20+ #include " PWGEM/PhotonMeson/DataModel/EventTables.h" // IWYU pragma: keep
2021#include " PWGEM/PhotonMeson/DataModel/gammaTables.h"
2122
2223#include < CommonConstants/MathConstants.h>
2930
3031#include < sys/types.h>
3132
33+ #include < array>
3234#include < cmath>
3335#include < concepts>
3436#include < cstddef>
@@ -61,7 +63,7 @@ concept IsNonLinContainer = o2::soa::is_table<T> && requires(T t) {
6163};
6264
6365template <typename T>
64- concept IsTrackIterator = o2::soa::is_iterator<T> && requires (T t) {
66+ concept IsFullTrackIterator = o2::soa::is_iterator<T> && !o2::soa::is_filtered_iterator <T> && requires (T t) {
6567 // Check that the *elements* of the container have the required methods:
6668 { t.deltaEta () } -> std::same_as<float >;
6769 { t.deltaPhi () } -> std::same_as<float >;
@@ -70,7 +72,7 @@ concept IsTrackIterator = o2::soa::is_iterator<T> && requires(T t) {
7072};
7173
7274template <typename T>
73- concept IsTrackContainer = o2::soa::is_table<T> && requires (T t) {
75+ concept IsFullTrackContainer = o2::soa::is_table<T> && o2::soa::is_not_filtered_table <T> && requires (T t) {
7476 // Check that the *elements* of the container have the required methods:
7577 { t.begin ().deltaEta () } -> std::same_as<float >;
7678 { t.begin ().deltaPhi () } -> std::same_as<float >;
@@ -134,7 +136,7 @@ class EMCPhotonCut
134136 const std::string& getName () const { return name; }
135137 const std::string& getTitle () const { return title; }
136138
137- static std::array<std::string, static_cast <std::size_t >(EMCPhotonCut::EMCPhotonCuts::kNCuts )> mCutNames ;
139+ static const std::array<std::string, static_cast <std::size_t >(EMCPhotonCut::EMCPhotonCuts::kNCuts )> mCutNames ;
138140
139141 static constexpr auto getClusterId (o2::soa::is_iterator auto const & t)
140142 {
@@ -198,26 +200,26 @@ class EMCPhotonCut
198200 // / \brief performs check if track is matched with given cluster
199201 // / \param cluster cluster to be checked
200202 // / \param emcmatchedtrack matched track iterator
201- // / \param emcmatchedtrackEnd matched track end iterator
203+ // / \param nMatchedTracks number of matched tracks
202204 // / \param GetEtaCut lambda to get the eta cut value
203205 // / \param GetPhiCut lambda to get the phi cut value
204206 // / \param applyEoverP bool to check if E/p should be checked (for secondaries we do not check this!)
205- bool checkTrackMatching (o2::soa::is_iterator auto const & cluster, IsTrackIterator auto & emcmatchedtrack, o2::soa::RowViewSentinel const emcmatchedtrackEnd , bool applyEoverP, auto GetEtaCut, auto GetPhiCut, o2::framework::HistogramRegistry* fRegistry = nullptr , TrackType trackType = TrackType::kPrimary ) const
207+ bool checkTrackMatching (o2::soa::is_iterator auto const & cluster, IsFullTrackIterator auto & emcmatchedtrack, int64_t const nMatchedTracks , bool applyEoverP, auto GetEtaCut, auto GetPhiCut, o2::framework::HistogramRegistry* fRegistry = nullptr , TrackType trackType = TrackType::kPrimary ) const
206208 {
207209 // advance to cluster
208- while (emcmatchedtrack != emcmatchedtrackEnd && getClusterId (emcmatchedtrack) < cluster.globalIndex ()) {
210+ while (emcmatchedtrack. globalIndex () < nMatchedTracks && getClusterId (emcmatchedtrack) < cluster.globalIndex ()) {
209211 ++emcmatchedtrack;
210212 }
211213 // all matched tracks have been checked
212- if (emcmatchedtrack == emcmatchedtrackEnd ) {
214+ if (emcmatchedtrack. globalIndex () >= nMatchedTracks ) {
213215 return true ;
214216 }
215217 // if all remaining tracks are beyond this cluster, it survives
216218 if (getClusterId (emcmatchedtrack) > cluster.globalIndex ()) {
217219 return true ;
218220 }
219221 // iterate over tracks belonging to this cluster
220- while (emcmatchedtrack != emcmatchedtrackEnd && getClusterId (emcmatchedtrack) == cluster.globalIndex ()) {
222+ while (emcmatchedtrack. globalIndex () < nMatchedTracks && getClusterId (emcmatchedtrack) == cluster.globalIndex ()) {
221223 const auto dEta = emcmatchedtrack.deltaEta ();
222224 const auto dPhi = emcmatchedtrack.deltaPhi ();
223225 const auto fdEta = std::fabs (emcmatchedtrack.deltaEta ());
@@ -286,18 +288,18 @@ class EMCPhotonCut
286288 // / \brief check if given clusters survives all cuts
287289 // / \param flags EMBitFlags where results will be stored
288290 // / \param cluster cluster table to check
289- // / \param matchedTracks matched primary tracks table
290- // / \param matchedSecondaries matched secondary tracks table
291+ // / \param matchedTracks matched primary tracks table. HAS TO BE FULL TABLE!
292+ // / \param matchedSecondaries matched secondary tracks table. HAS TO BE FULL TABLE!
291293 // / \param fRegistry o2::framework::HistogramRegistry pointer of the main task
292- void AreSelectedRunning (EMBitFlags& flags, o2::soa::is_table auto const & clusters, IsTrackContainer auto const & emcmatchedtracks, IsTrackContainer auto const & secondaries, o2::framework::HistogramRegistry* fRegistry = nullptr ) const
294+ void AreSelectedRunning (EMBitFlags& flags, o2::soa::is_table auto const & clusters, IsFullTrackContainer auto const & emcmatchedtracks, IsFullTrackContainer auto const & secondaries, o2::framework::HistogramRegistry* fRegistry = nullptr ) const
293295 {
294296 if (clusters.size () <= 0 ) {
295297 return ;
296298 }
297299 auto emcmatchedtrackIter = emcmatchedtracks.begin ();
298- auto emcmatchedtrackEnd = emcmatchedtracks.end ();
300+ int64_t nMatchedTracks = emcmatchedtracks.size ();
299301 auto secondaryIter = secondaries.begin ();
300- auto secondaryEnd = secondaries.end ();
302+ int64_t nSecondaryTracks = secondaries.size ();
301303 size_t iCluster = 0 ;
302304
303305 const bool doQA = mDoQA && fRegistry != nullptr ;
@@ -309,7 +311,7 @@ class EMCPhotonCut
309311 if (doQA) {
310312 fillBeforeClusterHistogram (cluster, fRegistry );
311313 }
312- if (!IsSelectedRunning (cluster, emcmatchedtrackIter, emcmatchedtrackEnd , secondaryIter, secondaryEnd , fRegistry )) {
314+ if (!IsSelectedRunning (cluster, emcmatchedtrackIter, nMatchedTracks , secondaryIter, nSecondaryTracks , fRegistry )) {
313315 flags.set (iCluster);
314316 } else if (doQA) {
315317 fillAfterClusterHistogram (cluster, fRegistry );
@@ -329,11 +331,11 @@ class EMCPhotonCut
329331 // / \brief check if given cluster survives all cuts
330332 // / \param cluster cluster to check
331333 // / \param emcmatchedtrackIter current iterator of matched primary tracks
332- // / \param emcmatchedtrackEnd end iterator of matched primary tracks
334+ // / \param nMatchedTracks number of matched primary tracks
333335 // / \param secondaryIter current iterator of matched secondary tracks
334- // / \param secondaryEnd end iterator of matched secondary tracks
336+ // / \param nSecondaryTracks number of matched secondary tracks
335337 // / \return true if cluster survives all cuts else false
336- bool IsSelectedRunning (o2::soa::is_iterator auto const & cluster, IsTrackIterator auto & emcmatchedtrackIter, o2::soa::RowViewSentinel const emcmatchedtrackEnd, IsTrackIterator auto & secondaryIter, o2::soa::RowViewSentinel const secondaryEnd , o2::framework::HistogramRegistry* fRegistry = nullptr ) const
338+ bool IsSelectedRunning (o2::soa::is_iterator auto const & cluster, IsFullTrackIterator auto & emcmatchedtrackIter, int64_t const nMatchedTracks, IsFullTrackIterator auto & secondaryIter, int64_t const nSecondaryTracks , o2::framework::HistogramRegistry* fRegistry = nullptr ) const
337339 {
338340 const bool doQA = mDoQA && fRegistry != nullptr ;
339341 if (!IsSelectedEMCalRunning (EMCPhotonCuts::kDefinition , cluster)) {
@@ -366,13 +368,13 @@ class EMCPhotonCut
366368 }
367369 return false ;
368370 }
369- if (mUseTM && (!IsSelectedEMCalRunning (EMCPhotonCuts::kTM , cluster, emcmatchedtrackIter, emcmatchedtrackEnd , fRegistry ))) {
371+ if (mUseTM && (!IsSelectedEMCalRunning (EMCPhotonCuts::kTM , cluster, emcmatchedtrackIter, nMatchedTracks , fRegistry ))) {
370372 if (doQA) {
371373 fRegistry ->fill (HIST (" QA/Cluster/hClusterQualityCuts" ), static_cast <int >(EMCPhotonCuts::kTM ) + 1 , cluster.e ());
372374 }
373375 return false ;
374376 }
375- if (mUseSecondaryTM && (!IsSelectedEMCalRunning (EMCPhotonCuts::kSecondaryTM , cluster, secondaryIter, secondaryEnd , fRegistry ))) {
377+ if (mUseSecondaryTM && (!IsSelectedEMCalRunning (EMCPhotonCuts::kSecondaryTM , cluster, secondaryIter, nSecondaryTracks , fRegistry ))) {
376378 if (doQA) {
377379 fRegistry ->fill (HIST (" QA/Cluster/hClusterQualityCuts" ), static_cast <int >(EMCPhotonCuts::kSecondaryTM ) + 1 , cluster.e ());
378380 }
@@ -437,16 +439,16 @@ class EMCPhotonCut
437439 // / \param cut enum of the cluster cut to check
438440 // / \param cluster cluster to check
439441 // / \param matchedTrackIter current iterator of matched primary or secondary tracks
440- // / \param matchedTrackEnd end iterator of matched primary or secondary tracks
442+ // / \param nMatchedTracks number of matched primary or secondary tracks
441443 // / \return true if cluster survives cut else false
442- bool IsSelectedEMCalRunning (const EMCPhotonCuts& cut, o2::soa::is_iterator auto const & cluster, IsTrackIterator auto & matchedTrackIter, o2::soa::RowViewSentinel const matchedTrackEnd , o2::framework::HistogramRegistry* fRegistry = nullptr ) const
444+ bool IsSelectedEMCalRunning (const EMCPhotonCuts& cut, o2::soa::is_iterator auto const & cluster, IsFullTrackIterator auto & matchedTrackIter, int64_t const nMatchedTracks , o2::framework::HistogramRegistry* fRegistry = nullptr ) const
443445 {
444446 switch (cut) {
445447 case EMCPhotonCuts::kTM :
446- return checkTrackMatching (cluster, matchedTrackIter, matchedTrackEnd , true , [this ](float pt) { return GetTrackMatchingEta (pt); }, [this ](float pt) { return GetTrackMatchingPhi (pt); }, fRegistry , TrackType::kPrimary );
448+ return checkTrackMatching (cluster, matchedTrackIter, nMatchedTracks , true , [this ](float pt) { return GetTrackMatchingEta (pt); }, [this ](float pt) { return GetTrackMatchingPhi (pt); }, fRegistry , TrackType::kPrimary );
447449
448450 case EMCPhotonCuts::kSecondaryTM :
449- return checkTrackMatching (cluster, matchedTrackIter, matchedTrackEnd , false , [this ](float pt) { return GetSecTrackMatchingEta (pt); }, [this ](float pt) { return GetSecTrackMatchingPhi (pt); }, fRegistry , TrackType::kSecondary );
451+ return checkTrackMatching (cluster, matchedTrackIter, nMatchedTracks , false , [this ](float pt) { return GetSecTrackMatchingEta (pt); }, [this ](float pt) { return GetSecTrackMatchingPhi (pt); }, fRegistry , TrackType::kSecondary );
450452
451453 default :
452454 return true ;
@@ -518,7 +520,7 @@ class EMCPhotonCut
518520 return mMinTime <= cluster.time () && cluster.time () <= mMaxTime ;
519521
520522 case EMCPhotonCuts::kTM : {
521- if constexpr (IsTrackContainer <TMatchedTracks>) {
523+ if constexpr (IsFullTrackContainer <TMatchedTracks>) {
522524 for (const auto & emcmatchedtrack : emcmatchedtracks) {
523525 auto dEta = std::fabs (emcmatchedtrack.deltaEta ());
524526 auto dPhi = std::fabs (emcmatchedtrack.deltaPhi ());
@@ -551,7 +553,7 @@ class EMCPhotonCut
551553 return true ; // when we don't have any tracks the cluster should always survive the TM cut!
552554 }
553555 case EMCPhotonCuts::kSecondaryTM : {
554- if constexpr (IsTrackContainer <TMatchedTracks>) {
556+ if constexpr (IsFullTrackContainer <TMatchedTracks>) {
555557 for (const auto & emcmatchedtrack : emcmatchedtracks) {
556558 auto dEta = std::fabs (emcmatchedtrack.deltaEta ());
557559 auto dPhi = std::fabs (emcmatchedtrack.deltaPhi ());
0 commit comments