Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:21:10

0001 #pragma once
0002 
0003 #include <fun4all/SubsysReco.h>
0004 
0005 // #include <trackbase/ClusterErrorPara.h>
0006 #include <trackbase/TrkrDefs.h>
0007 
0008 #include <trackbase_historic/WeightedTrack.h>
0009 
0010 // #include <tpc/TpcClusterZCrossingCorrection.h>
0011 #include <tpc/TpcGlobalPositionWrapper.h>
0012 
0013 #include <Eigen/Dense>
0014 
0015 #include <Math/Factory.h>
0016 #include <Math/Functor.h>
0017 #include <Math/Minimizer.h>
0018 
0019 #include <array>
0020 #include <functional>
0021 #include <type_traits>
0022 #include <set>
0023 
0024 class PHCompositeNode;
0025 class ActsGeometry;
0026 class SvtxTrackMap;
0027 class SvtxAlignmentStateMap;
0028 class SvtxVertexMap;
0029 class TrackSeed;
0030 class TrackSeedContainer;
0031 class TrkrCluster;
0032 class TrkrClusterContainer;
0033 class WeightedTrackMap;
0034 
0035 class TFile;
0036 class TNtuple;
0037 
0038 class WeightedFitter : public SubsysReco {
0039 public:
0040     enum which_track_e { k_silicon_tracks, k_tpc_tracks, k_svtx_tracks, };
0041 
0042     WeightedFitter(std::string const& = "WeightedFitter");
0043     virtual ~WeightedFitter() override;
0044 
0045     int InitRun(PHCompositeNode*) override;
0046     int process_event(PHCompositeNode*) override;
0047     int End(PHCompositeNode*) override;
0048 
0049     /// Input setting methods
0050     void set_which_tracks (which_track_e which_tracks) { m_which_tracks = which_tracks; }
0051     void set_trkr_cluster_container_node_name (std::string const& name) { m_trkr_cluster_container_node_name = name; }
0052     void set_svtx_track_seed_container_node_name (std::string const& name) { m_svtx_track_seed_container_node_name = name; }
0053     void set_silicon_track_seed_container_node_name (std::string const& name) { m_silicon_track_seed_container_node_name = name; }
0054     void set_tpc_track_seed_container_node_name (std::string const& name) { m_tpc_track_seed_container_node_name = name; }
0055 
0056     /// Set the minimum number of clusters for the track to be used
0057     void set_min_num_mvtx (int num_mvtx) { m_min_num_mvtx = num_mvtx; }
0058     void set_min_num_intt (int num_intt) { m_min_num_intt = num_intt; }
0059     void set_min_num_tpc (int num_tpc) { m_min_num_tpc = num_tpc; }
0060     void set_min_num_tpot (int num_tpot) { m_min_num_tpot = num_tpot; }
0061 
0062     void use_vertex (bool const& use_vertex = true) { m_use_vertex = use_vertex; }
0063     void set_vertex_node_name (std::string const& name) { m_vertex_map_node_name = name; }
0064 
0065     // Set which layers to use in the fit (added to the WeightedTrack)
0066     void exclude_layer_in_fit (int layer) { m_fit_excluded_layers.insert(layer); m_fit_included_layers.erase(layer); }
0067     void include_layer_in_fit (int layer) { m_fit_included_layers.insert(layer); m_fit_excluded_layers.erase(layer); }
0068 
0069     /// Set which layers to use in output SvtxTracks, SvtxAlignmentStates
0070     void exclude_layer_in_output (int layer) { m_output_excluded_layers.insert(layer); m_output_included_layers.erase(layer); }
0071     void include_layer_in_output (int layer) { m_output_included_layers.insert(layer); m_output_excluded_layers.erase(layer); }
0072 
0073     /// Set the type of tracks to use for the fit via a template argument
0074     /// By default, WeightedFitterZeroField tracks are used
0075     template <typename T>
0076     void set_track_type() {
0077         // Helps clarify compilation failures to users
0078         static_assert (std::is_convertible_v<T*, WeightedTrack*>, "Template argument must be derived from trackbase_historic/WeightedTrack");
0079         m_track_factory = []{ return new T; };
0080     }
0081 
0082     /// Set the method to produce "new" (owned by an instance of this class) tracks
0083     /// Useful if some configuration beyond default construction, otherwise, see set_track_type
0084     void set_track_factory (std::function<WeightedTrack*(void)> track_factory) { m_track_factory = track_factory; }
0085 
0086     /// Output setting methods
0087     void set_track_map_node_name (std::string const& name) { m_track_map_node_name = name; }
0088     void set_alignment_map_node_name (std::string const& name) { m_alignment_map_node_name = name; }
0089     void set_weighted_track_map_node_name (std::string const& name) { m_weighted_track_map_node_name = name; }
0090 
0091     void set_ntuple_file_name (std::string const& name) { m_ntuple_file_name = name; }
0092     void reassign_cluster_sides (bool reassign_sides = true) { m_reassign_sides = reassign_sides; }
0093 
0094 private:
0095     void get_nodes(PHCompositeNode*);
0096     void make_nodes(PHCompositeNode*);
0097     void make_ntuple();
0098 
0099     bool get_cluster_keys (TrackSeed*);
0100     bool get_points();
0101     bool do_fit();
0102     bool refit_with_vertex();
0103     bool add_track();
0104 
0105     Eigen::Matrix4d param_cov{Eigen::Matrix4d::Zero()};
0106 
0107     std::string m_ntuple_file_name{}; // empty--by default do not make it
0108     TFile* m_file{};
0109     TNtuple* m_ntuple{};
0110 
0111     std::string m_geometry_node_name{"ActsGeometry"};
0112     ActsGeometry* m_geometry{};
0113 
0114     std::string m_trkr_cluster_container_node_name{"TRKR_CLUSTER"};
0115     TrkrClusterContainer* m_trkr_cluster_container{};
0116 
0117     which_track_e m_which_tracks = k_svtx_tracks;
0118 
0119     std::string m_silicon_track_seed_container_node_name{"SiliconTrackSeedContainer"};
0120     TrackSeedContainer* m_silicon_track_seed_container{};
0121     TrackSeed* m_silicon_seed{};
0122 
0123     std::string m_tpc_track_seed_container_node_name{"TpcTrackSeedContainer"};
0124     TrackSeedContainer* m_tpc_track_seed_container{};
0125     TrackSeed* m_tpc_seed{};
0126 
0127     std::string m_svtx_track_seed_container_node_name{"SvtxTrackSeedContainer"};
0128     TrackSeedContainer* m_svtx_track_seed_container{};
0129 
0130     bool m_use_vertex{false};
0131     std::string m_vertex_map_node_name{"SvtxVertexMap"};
0132     SvtxVertexMap* m_vertex_map{};
0133 
0134     // Nodes that this class will populate
0135     std::string m_track_map_node_name{"WeightedFitterTrackMap"};
0136     SvtxTrackMap* m_track_map{};
0137 
0138     std::string m_alignment_map_node_name{"WeightedFitterAlignmentStateMap"};
0139     SvtxAlignmentStateMap* m_alignment_map{};
0140 
0141     std::string m_weighted_track_map_node_name{"WeightedFitterWeightedTrackMap"};
0142     WeightedTrackMap* m_weighted_track_map{};
0143 
0144     // Layers to use in the fit (added to the WeightedTrack)
0145     std::set<int> m_fit_included_layers;
0146     std::set<int> m_fit_excluded_layers;
0147 
0148     /// Layers to use in output SvtxTracks, SvtxAlignmentStates
0149     std::set<int> m_output_included_layers;
0150     std::set<int> m_output_excluded_layers;
0151     std::vector<ClusterFitPoint> m_output_cluster_fit_points{};
0152 
0153     int m_track_id{0};
0154     int m_crossing{SHRT_MAX};
0155     std::vector<TrkrDefs::cluskey> m_cluster_keys;
0156 
0157     ROOT::Math::Minimizer* m_minimizer{};
0158     WeightedTrack* m_weighted_track{};
0159     std::function<WeightedTrack*(void)> m_track_factory;
0160 
0161     bool m_reassign_sides{false};
0162     int m_num_mvtx{0};
0163     int m_num_intt{0};
0164     int m_num_tpc{0};
0165     int m_num_tpot{0};
0166     int m_side{-1};
0167 
0168     int m_min_num_mvtx{0}; // 3
0169     int m_min_num_intt{0}; // 2
0170     int m_min_num_tpc{0}; // 20
0171     int m_min_num_tpot{0}; // 0
0172 
0173     TpcGlobalPositionWrapper m_global_position_wrapper;
0174     // ClusterErrorPara m_cluster_error_para;
0175     // TpcClusterZCrossingCorrection m_clusterCrossingCorrection; // unused for now, maybe to get uncorrected positions later
0176 };
0177