Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
g4evaltools.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file g4evaltools.h
1 #ifndef G4EVAL_G4EVALTOOLS_H
2 #define G4EVAL_G4EVALTOOLS_H
3 
4 #include <trackbase/TrkrDefs.h>
5 
7 
8 #include <Eigen/Core>
9 
10 #include <array>
11 #include <cfloat>
12 #include <set>
13 #include <tuple>
14 #include <utility>
15 #include <vector>
16 
17 class ActsGeometry;
19 class PHCompositeNode;
20 class SvtxTrack;
21 class SvtxTrackMap;
22 class TrkrCluster;
24 class TrkrTruthTrack;
25 
26 namespace G4Eval
27 {
28  // ClusLoc holds layer, location, phi size and z size
29  using ClusLoc = std::tuple<int, Eigen::Vector3d, int, int>;
30 
31  // Following function writes msg to the currently active TFile
32  // if f_outname is provided, then it will write the message to a new
33  // TFiles of that name and close it again.
34  void write_StringToTFile(const std::string& msg_name, const std::string& msg);
35 
37 
39  {
40  // most members are public for easy access after the node has been used
41  public:
42  TrkrClusterComparer(float _nphi_widths = 0.5, float _nz_widths = 0.5);
43  int init(PHCompositeNode* topNode,
44  const std::string& name_truth_clusters = "TRKR_TRUTHCLUSTERCONTAINER",
45  const std::string& name_reco_clusters = "TRKR_CLUSTER");
46 
47  TrkrCluster* clus_T{nullptr};
48  TrkrCluster* clus_R{nullptr};
49 
50  /* std::pair<bool, float> is_match_b */
51  std::pair<bool, float> operator()(TrkrDefs::cluskey key_T, TrkrDefs::cluskey key_R);
52 
53  // Members that are set with each set of cluster keys that
54  // are passed to it.
55  // z and phi locations of phg4 hit (T) and Svtx hit (R)
56  bool is_match{false};
57  int layer{INT_MAX};
58 
59  float z_T{FLT_MAX}, z_R{FLT_MAX};
60  float phi_T{FLT_MAX}, phi_R{FLT_MAX};
61  float phisize_R{FLT_MAX}, phisize_T{FLT_MAX}; // phisize is in nbins * nwidhts
62  float zsize_R{FLT_MAX}, zsize_T{FLT_MAX}; // zsize is in nbins * nwdiths
63  float phi_delta{FLT_MAX}, z_delta{FLT_MAX}; // deltas are also in nbins
64 
65  bool in_tpc{false};
66  bool in_mvtx{false};
67  bool in_intt{false};
68  bool in_tpot{false};
69 
70  // z pixel sizes. n.b.: there is no z clustering in the INTT
71  float m_zstep_tpc{0.}; // from tpc geometry
72  float m_zstep_mvtx{0.};
73  // TPOT not implemented yet...
74 
75  void set_nz_widths(float val) { m_nz_widths = val; };
76  void set_nphi_widths(float val) { m_nphi_widths = val; };
77 
78  ClusLoc clusloc_PHG4(std::pair<TrkrDefs::hitsetkey, TrkrDefs::cluskey>);
79  ClusLoc clusloc_SVTX(std::pair<TrkrDefs::hitsetkey, TrkrDefs::cluskey>);
80 
83 
84  private:
85  // phi pixel sizes, got for the geometries from the topNode
86  std::array<double, 56> m_phistep{0.}; // the phistep squared
88  float m_nz_widths;
89 
91  };
92 
93  // The following is a struct to iterate over the cluster keys for a given
94  // StvxTrack* tracks, starting with the silicone seed and then returning
95  // values for the tpc seed. It is used like:
96  //
97  // for (auto& cluskey : ClusKeyIter(svtx_track)) {
98  // ... // do things with cluster keys
99  // }
100  struct ClusKeyIter
101  {
102  typedef std::set<TrkrDefs::cluskey> ClusterKeySet;
103  typedef ClusterKeySet::iterator ClusterKeyIter;
104 
105  ClusKeyIter(SvtxTrack* _track);
106  // data
109  bool has_tpc;
110  bool no_data; // neither a tpc nor a silicon seed
113 
114  ClusKeyIter begin();
115  ClusKeyIter end();
116 
117  void operator++();
119  bool operator!=(const ClusKeyIter& rhs);
120  };
121 
122  int trklayer_0123(TrkrDefs::hitsetkey); // 0:Mvtx 1:Intt 2:Tpc 3:Tpot
123 
124  class ClusCntr
125  {
126  private:
127  using Vector = std::vector<std::pair<TrkrDefs::hitsetkey, TrkrDefs::cluskey>>;
128  using Iter = Vector::iterator;
129 
131  std::array<int, 5> cntclus(Vector& keys);
132  std::array<int, 5> cnt_matchedclus(Vector& keys, std::vector<bool>& matches);
133 
134  public:
136  : comp{_} {};
139 
142 
143  double match_stat{0};
144 
145  void reset();
146  std::array<int, 3> find_matches(); // populated matches_{svtx,phg4};
147  // return's {n-matched, n-phg4, n-svtx}
148  std::array<int, 3> find_matches(TrkrTruthTrack* g4_track, SvtxTrack* sv_track);
149 
150  int phg4_n_matched(); // also same as phg4_cnt_matchedclus()[4]
151  int svtx_n_matched(); // should be almost always the same
152  // which is ALMOST guaranteed to be same as svtx_cnt_matchedclus()[4]
153  int phg4_nclus() { return (int) phg4_keys.size(); }
154  int svtx_nclus() { return (int) svtx_keys.size(); }
155 
156  std::vector<bool> svtx_matches;
157  std::vector<bool> phg4_matches;
158 
159  int addClusKeys(SvtxTrack*); // return number of clusters
160  int addClusKeys(TrkrTruthTrack*); // return number of clusters
161 
162  std::array<int, 5> svtx_cntclus() { return cntclus(svtx_keys); }; // Mvtx Intt Tpc TPOT Sum
163  std::array<int, 5> phg4_cntclus() { return cntclus(phg4_keys); };
164 
165  std::array<int, 5> svtx_cnt_matchedclus() { return cnt_matchedclus(svtx_keys, svtx_matches); };
166  std::array<int, 5> phg4_cnt_matchedclus() { return cnt_matchedclus(phg4_keys, phg4_matches); };
167 
168  // I need the cluster widths for diagnostics, too
169  std::vector<ClusLoc> phg4_clusloc_all();
170  std::vector<ClusLoc> phg4_clusloc_unmatched();
171  std::vector<ClusLoc> svtx_clusloc_all();
172  std::vector<ClusLoc> svtx_clusloc_unmatched();
173  std::vector<ClusLoc> clusloc_matched();
174 
175  void set_comparer(TrkrClusterComparer* _comp) { comp = _comp; };
176  };
177 } // namespace G4Eval
178 
179 #endif