Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:58

0001 #ifndef G4EVAL_SVTXCLUSTEREVAL_H
0002 #define G4EVAL_SVTXCLUSTEREVAL_H
0003 
0004 #include "SvtxHitEval.h"
0005 
0006 #include <trackbase/ActsGeometry.h>
0007 #include <trackbase/TrkrDefs.h>
0008 
0009 #include <map>
0010 #include <memory>  // for shared_ptr, less
0011 #include <set>
0012 #include <utility>
0013 
0014 class PHCompositeNode;
0015 
0016 class PHG4Hit;
0017 class PHG4HitContainer;
0018 class PHG4Particle;
0019 class PHG4TruthInfoContainer;
0020 
0021 class TrkrCluster;
0022 class TrkrClusterContainer;
0023 class TrkrClusterHitAssoc;
0024 class TrkrHitTruthAssoc;
0025 class SvtxTruthEval;
0026 
0027 typedef std::multimap<float, TrkrDefs::cluskey> innerMap;
0028 
0029 class SvtxClusterEval
0030 {
0031  public:
0032   SvtxClusterEval(PHCompositeNode* topNode);
0033   virtual ~SvtxClusterEval();
0034 
0035   void next_event(PHCompositeNode* topNode);
0036   void do_caching(bool do_cache)
0037   {
0038     _do_cache = do_cache;
0039     _hiteval.do_caching(do_cache);
0040   }
0041   void set_strict(bool strict)
0042   {
0043     _strict = strict;
0044     _hiteval.set_strict(strict);
0045   }
0046   void set_verbosity(int verbosity)
0047   {
0048     _verbosity = verbosity;
0049     _hiteval.set_verbosity(verbosity);
0050   }
0051 
0052   // access the clustereval (and its cached values)
0053   SvtxHitEval* get_hit_eval() { return &_hiteval; }
0054   SvtxTruthEval* get_truth_eval() { return _hiteval.get_truth_eval(); }
0055 
0056   // backtrace through to PHG4Hits
0057   std::set<PHG4Hit*> all_truth_hits(TrkrDefs::cluskey cluster);
0058   PHG4Hit* max_truth_hit_by_energy(TrkrDefs::cluskey);
0059 
0060   // get all truth clusters matching a given layer
0061   std::map<TrkrDefs::cluskey, std::shared_ptr<TrkrCluster>> all_truth_clusters(TrkrDefs::cluskey cluster_key);
0062 
0063   std::pair<TrkrDefs::cluskey, std::shared_ptr<TrkrCluster>> max_truth_cluster_by_energy(TrkrDefs::cluskey cluster_key);
0064 
0065   PHG4Hit* all_truth_hits_by_nhit(TrkrDefs::cluskey cluster);
0066   std::pair<int, int> gtrackid_and_layer_by_nhit(TrkrDefs::cluskey cluster);
0067 
0068   // backtrace through to PHG4Particles
0069   std::set<PHG4Particle*> all_truth_particles(TrkrDefs::cluskey);
0070   PHG4Particle* max_truth_particle_by_energy(TrkrDefs::cluskey);
0071   PHG4Particle* max_truth_particle_by_cluster_energy(TrkrDefs::cluskey);
0072 
0073   // forwardtrace through to SvtxClusters
0074   std::set<TrkrDefs::cluskey> all_clusters_from(PHG4Particle* truthparticle);
0075   std::set<TrkrDefs::cluskey> all_clusters_from(PHG4Hit* truthhit);
0076   TrkrDefs::cluskey best_cluster_from(PHG4Hit* truthhit);
0077   TrkrDefs::cluskey best_cluster_by_nhit(int gid, int layer);
0078   void FillRecoClusterFromG4HitCache();
0079   // overlap calculations
0080   float get_energy_contribution(TrkrDefs::cluskey cluster_key, PHG4Particle* truthparticle);
0081   float get_energy_contribution(TrkrDefs::cluskey cluster_key, PHG4Hit* truthhit);
0082 
0083   std::pair<TrkrDefs::cluskey, TrkrCluster*> reco_cluster_from_truth_cluster(TrkrDefs::cluskey, const std::shared_ptr<TrkrCluster>& gclus);
0084 
0085   unsigned int get_errors() { return _errors + _hiteval.get_errors(); }
0086 
0087  private:
0088   void get_node_pointers(PHCompositeNode* topNode);
0089   void fill_cluster_layer_map();
0090   //  void fill_g4hit_layer_map();
0091   bool has_node_pointers();
0092 
0093   //! Fast approximation of atan2() for cluster searching
0094   //! From https://www.dsprelated.com/showarticle/1052.php
0095   float fast_approx_atan2(float y, float x);
0096   float fast_approx_atan2(float y2x);
0097 
0098   SvtxHitEval _hiteval;
0099   TrkrClusterContainer* _clustermap = nullptr;
0100   TrkrClusterHitAssoc* _cluster_hit_map = nullptr;
0101   TrkrHitTruthAssoc* _hit_truth_map = nullptr;
0102   PHG4TruthInfoContainer* _truthinfo = nullptr;
0103   PHG4HitContainer* _g4hits_tpc = nullptr;
0104   PHG4HitContainer* _g4hits_intt = nullptr;
0105   PHG4HitContainer* _g4hits_mvtx = nullptr;
0106   PHG4HitContainer* _g4hits_mms = nullptr;
0107   ActsGeometry* _tgeometry = nullptr;
0108 
0109   bool _strict = false;
0110   int _verbosity = 0;
0111   unsigned int _errors = 0;
0112 
0113   Acts::Vector3 getGlobalPosition(TrkrDefs::cluskey cluster_key, TrkrCluster* cluster);
0114 
0115   bool _do_cache = true;
0116   std::map<TrkrDefs::cluskey, std::set<PHG4Hit*>> _cache_all_truth_hits;
0117   std::map<TrkrDefs::cluskey, std::map<TrkrDefs::cluskey, std::shared_ptr<TrkrCluster>>> _cache_all_truth_clusters;
0118   std::map<TrkrDefs::cluskey, PHG4Hit*> _cache_max_truth_hit_by_energy;
0119   std::map<TrkrDefs::cluskey, std::pair<TrkrDefs::cluskey, std::shared_ptr<TrkrCluster>>> _cache_max_truth_cluster_by_energy;
0120   std::map<TrkrDefs::cluskey, std::set<PHG4Particle*>> _cache_all_truth_particles;
0121   std::map<TrkrDefs::cluskey, PHG4Particle*> _cache_max_truth_particle_by_energy;
0122   std::map<TrkrDefs::cluskey, PHG4Particle*> _cache_max_truth_particle_by_cluster_energy;
0123   std::map<PHG4Particle*, std::set<TrkrDefs::cluskey>> _cache_all_clusters_from_particle;
0124   std::map<PHG4Hit*, std::set<TrkrDefs::cluskey>> _cache_all_clusters_from_g4hit;
0125   std::map<PHG4Hit*, TrkrDefs::cluskey> _cache_best_cluster_from_g4hit;
0126   std::map<std::pair<int, int>, TrkrDefs::cluskey> _cache_best_cluster_from_gtrackid_layer;
0127   std::map<std::pair<TrkrDefs::cluskey, PHG4Particle*>, float> _cache_get_energy_contribution_g4particle;
0128   std::map<std::pair<TrkrDefs::cluskey, PHG4Hit*>, float> _cache_get_energy_contribution_g4hit;
0129   std::map<std::shared_ptr<TrkrCluster>, std::pair<TrkrDefs::cluskey, TrkrCluster*>> _cache_reco_cluster_from_truth_cluster;
0130 
0131   // measured for low occupancy events, all in cm
0132   const float sig_tpc_rphi_inner = 220e-04;
0133   const float sig_tpc_rphi_mid = 155e-04;
0134   const float sig_tpc_rphi_outer = 165e-04;
0135   const float sig_tpc_z = 750e-04;
0136   const float sig_intt_rphi = 17e-04;
0137   const float range_intt_z = 0.9;
0138   const float sig_mvtx_rphi = 4.0e-04;
0139   const float sig_mvtx_z = 4.7e-04;
0140   const float sig_mms_rphi_55 = 100e-04;
0141   const float sig_mms_z_56 = 200e-04;
0142 
0143   //! cluster azimuthal searching window in _clusters_per_layer. Unit: rad
0144   static constexpr float _clusters_searching_window = 0.1f;
0145   std::multimap<unsigned int, innerMap> _clusters_per_layer;
0146   //  std::multimap<unsigned int, PHG4Hit*> _g4hits_per_layer;
0147 };
0148 
0149 #endif  // G4EVAL_SVTXCLUSTEREVAL_H