File indexing completed on 2025-08-05 08:17:56
0001 #ifndef G4EVAL_G4EVALTOOLS_H
0002 #define G4EVAL_G4EVALTOOLS_H
0003
0004 #include <trackbase/TrkrDefs.h>
0005
0006 #include <fun4all/Fun4AllReturnCodes.h>
0007
0008 #include <Eigen/Core>
0009
0010 #include <array>
0011 #include <cfloat>
0012 #include <set>
0013 #include <tuple>
0014 #include <utility>
0015 #include <vector>
0016
0017 class ActsGeometry;
0018 class EmbRecoMatchContainer;
0019 class PHCompositeNode;
0020 class SvtxTrack;
0021 class SvtxTrackMap;
0022 class TrkrCluster;
0023 class TrkrClusterContainer;
0024 class TrkrTruthTrack;
0025
0026 namespace G4Eval
0027 {
0028
0029 using ClusLoc = std::tuple<int, Eigen::Vector3d, int, int>;
0030
0031
0032
0033
0034 void write_StringToTFile(const std::string& msg_name, const std::string& msg);
0035
0036 std::vector<int> unmatchedSvtxTrkIds(EmbRecoMatchContainer*, SvtxTrackMap*);
0037
0038 class TrkrClusterComparer
0039 {
0040
0041 public:
0042 TrkrClusterComparer(float _nphi_widths = 0.5, float _nz_widths = 0.5);
0043 int init(PHCompositeNode* topNode,
0044 const std::string& name_truth_clusters = "TRKR_TRUTHCLUSTERCONTAINER",
0045 const std::string& name_reco_clusters = "TRKR_CLUSTER");
0046
0047 TrkrCluster* clus_T{nullptr};
0048 TrkrCluster* clus_R{nullptr};
0049
0050
0051 std::pair<bool, float> operator()(TrkrDefs::cluskey key_T, TrkrDefs::cluskey key_R);
0052
0053
0054
0055
0056 bool is_match{false};
0057 int layer{INT_MAX};
0058
0059 float z_T{FLT_MAX}, z_R{FLT_MAX};
0060 float phi_T{FLT_MAX}, phi_R{FLT_MAX};
0061 float phisize_R{FLT_MAX}, phisize_T{FLT_MAX};
0062 float zsize_R{FLT_MAX}, zsize_T{FLT_MAX};
0063 float phi_delta{FLT_MAX}, z_delta{FLT_MAX};
0064
0065 bool in_tpc{false};
0066 bool in_mvtx{false};
0067 bool in_intt{false};
0068 bool in_tpot{false};
0069
0070
0071 float m_zstep_tpc{0.};
0072 float m_zstep_mvtx{0.};
0073
0074
0075 void set_nz_widths(float val) { m_nz_widths = val; };
0076 void set_nphi_widths(float val) { m_nphi_widths = val; };
0077
0078 ClusLoc clusloc_PHG4(std::pair<TrkrDefs::hitsetkey, TrkrDefs::cluskey>);
0079 ClusLoc clusloc_SVTX(std::pair<TrkrDefs::hitsetkey, TrkrDefs::cluskey>);
0080
0081 TrkrClusterContainer* m_TruthClusters{nullptr};
0082 TrkrClusterContainer* m_RecoClusters{nullptr};
0083
0084 private:
0085
0086 std::array<double, 56> m_phistep{0.};
0087 float m_nphi_widths;
0088 float m_nz_widths;
0089
0090 ActsGeometry* m_ActsGeometry{nullptr};
0091 };
0092
0093
0094
0095
0096
0097
0098
0099
0100 struct ClusKeyIter
0101 {
0102 typedef std::set<TrkrDefs::cluskey> ClusterKeySet;
0103 typedef ClusterKeySet::iterator ClusterKeyIter;
0104
0105 ClusKeyIter(SvtxTrack* _track);
0106
0107 SvtxTrack* track;
0108 bool in_silicon;
0109 bool has_tpc;
0110 bool no_data;
0111 ClusterKeyIter iter{};
0112 ClusterKeyIter iter_end_silicon{};
0113
0114 ClusKeyIter begin();
0115 ClusKeyIter end();
0116
0117 void operator++();
0118 TrkrDefs::cluskey operator*();
0119 bool operator!=(const ClusKeyIter& rhs);
0120 };
0121
0122 int trklayer_0123(TrkrDefs::hitsetkey);
0123
0124 class ClusCntr
0125 {
0126 private:
0127 using Vector = std::vector<std::pair<TrkrDefs::hitsetkey, TrkrDefs::cluskey>>;
0128 using Iter = Vector::iterator;
0129
0130 TrkrClusterComparer* comp;
0131 std::array<int, 5> cntclus(Vector& keys);
0132 std::array<int, 5> cnt_matchedclus(Vector& keys, std::vector<bool>& matches);
0133
0134 public:
0135 ClusCntr(TrkrClusterComparer* _ = nullptr)
0136 : comp{_} {};
0137 TrkrClusterContainer* get_PHG4_clusters();
0138 TrkrClusterContainer* get_SVTX_clusters();
0139
0140 Vector svtx_keys{};
0141 Vector phg4_keys{};
0142
0143 double match_stat{0};
0144
0145 void reset();
0146 std::array<int, 3> find_matches();
0147
0148 std::array<int, 3> find_matches(TrkrTruthTrack* g4_track, SvtxTrack* sv_track);
0149
0150 int phg4_n_matched();
0151 int svtx_n_matched();
0152
0153 int phg4_nclus() { return (int) phg4_keys.size(); }
0154 int svtx_nclus() { return (int) svtx_keys.size(); }
0155
0156 std::vector<bool> svtx_matches;
0157 std::vector<bool> phg4_matches;
0158
0159 int addClusKeys(SvtxTrack*);
0160 int addClusKeys(TrkrTruthTrack*);
0161
0162 std::array<int, 5> svtx_cntclus() { return cntclus(svtx_keys); };
0163 std::array<int, 5> phg4_cntclus() { return cntclus(phg4_keys); };
0164
0165 std::array<int, 5> svtx_cnt_matchedclus() { return cnt_matchedclus(svtx_keys, svtx_matches); };
0166 std::array<int, 5> phg4_cnt_matchedclus() { return cnt_matchedclus(phg4_keys, phg4_matches); };
0167
0168
0169 std::vector<ClusLoc> phg4_clusloc_all();
0170 std::vector<ClusLoc> phg4_clusloc_unmatched();
0171 std::vector<ClusLoc> svtx_clusloc_all();
0172 std::vector<ClusLoc> svtx_clusloc_unmatched();
0173 std::vector<ClusLoc> clusloc_matched();
0174
0175 void set_comparer(TrkrClusterComparer* _comp) { comp = _comp; };
0176 };
0177 }
0178
0179 #endif