Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef TRACKRECO_PHGENFITTRKFITTER_H
0002 #define TRACKRECO_PHGENFITTRKFITTER_H
0003 
0004 /*!
0005  *  \file       PHGenFitTrkFitter.h
0006  *  \brief      Refit SvtxTracks with PHGenFit.
0007  *  \details    Refit SvtxTracks with PHGenFit.
0008  *  \author     Haiwang Yu <yuhw@nmsu.edu>
0009  */
0010 
0011 #include <fun4all/SubsysReco.h>
0012 
0013 #include <tpc/TpcGlobalPositionWrapper.h>
0014 
0015 #if defined(__CLING__)
0016 // needed, it crashes on Ubuntu using singularity with local cvmfs install
0017 // shared pointer later on uses this, forward declaration does not cut it
0018 #include <phgenfit/Track.h>
0019 #else
0020 namespace PHGenFit
0021 {
0022   class Track;
0023 } /* namespace PHGenFit */
0024 #endif
0025 
0026 #include <TMatrixFfwd.h>  // for TMatrixF
0027 #include <TVector3.h>     // for TVector3
0028 
0029 #include <map>
0030 #include <memory>  // for shared_ptr
0031 #include <set>
0032 #include <string>
0033 #include <vector>
0034 
0035 namespace genfit
0036 {
0037   class GFRaveVertex;
0038   class GFRaveVertexFactory;
0039   class Track;
0040 } /* namespace genfit */
0041 
0042 class SvtxTrack;
0043 namespace PHGenFit
0044 {
0045   class Fitter;
0046 } /* namespace PHGenFit */
0047 
0048 class ActsGeometry;
0049 class PHCompositeNode;
0050 class SvtxTrackMap;
0051 class TrkrClusterContainer;
0052 class TrackSeedContainer;
0053 
0054 //! \brief      Refit SvtxTracks with PHGenFit.
0055 class PHGenFitTrkFitter : public SubsysReco
0056 {
0057  public:
0058 
0059   //! Default constructor
0060   PHGenFitTrkFitter(const std::string& name = "PHGenFitTrkFitter");
0061 
0062   //! Initialization, called for initialization
0063   int Init(PHCompositeNode*) override;
0064 
0065   //! Initialization Run, called for initialization of a run
0066   int InitRun(PHCompositeNode*) override;
0067 
0068   //! Process Event, called for each event
0069   int process_event(PHCompositeNode*) override;
0070 
0071   //! End, write and close files
0072   int End(PHCompositeNode*) override;
0073 
0074   const std::string& get_track_fitting_alg_name() const
0075   {
0076     return _track_fitting_alg_name;
0077   }
0078 
0079   void set_track_fitting_alg_name(const std::string& trackFittingAlgName)
0080   {
0081     _track_fitting_alg_name = trackFittingAlgName;
0082   }
0083 
0084   int get_primary_pid_guess() const
0085   {
0086     return _primary_pid_guess;
0087   }
0088 
0089   void set_primary_pid_guess(int primaryPidGuess)
0090   {
0091     _primary_pid_guess = primaryPidGuess;
0092   }
0093 
0094   double get_fit_min_pT() const
0095   {
0096     return _fit_min_pT;
0097   }
0098 
0099   void set_fit_min_pT(double cutMinPT)
0100   {
0101     _fit_min_pT = cutMinPT;
0102   }
0103 
0104   double get_vertex_min_ndf() const
0105   {
0106     return _vertex_min_ndf;
0107   }
0108 
0109   void set_vertex_min_ndf(double vertexMinPT)
0110   {
0111     _vertex_min_ndf = vertexMinPT;
0112   }
0113 
0114   //!@name disabled layers interface
0115   //@{
0116 
0117   //! mark layer as disbled
0118   void disable_layer(int layer, bool disabled = true);
0119 
0120   //! set disabled layers
0121   void set_disabled_layers(const std::set<int>&);
0122 
0123   //! clear disabled layers
0124   void clear_disabled_layers();
0125 
0126   //! get disabled layers
0127   const std::set<int>& get_disabled_layers() const;
0128 
0129   //@}
0130 
0131   /// fit only tracks with silicon+MM hits
0132   void set_fit_silicon_mms(bool);
0133 
0134   /// require micromegas in SiliconMM fits
0135   void set_use_micromegas(bool value)
0136   {
0137     m_use_micromegas = value;
0138   }
0139 
0140   void set_svtx_seed_map_name(const std::string &name) {_seedMap_name = name;}
0141   void set_svtx_track_map_name(const std::string &name) {_trackMap_name = name;}
0142 
0143   void disableModuleEdgeCorr() { m_disable_module_edge_corr = true; }
0144   void disableStaticCorr() { m_disable_static_corr = true; }
0145   void disableAverageCorr() { m_disable_average_corr = true; }
0146   void disableFluctuationCorr() { m_disable_fluctuation_corr = true; }
0147 
0148  private:
0149   //! Event counter
0150   int _event = 0;
0151 
0152   //! Get all the nodes
0153   int GetNodes(PHCompositeNode*);
0154 
0155   //! Create New nodes
0156   int CreateNodes(PHCompositeNode*);
0157 
0158   /*
0159    * fit track with SvtxTrack as input seed.
0160    * \param intrack Input SvtxTrack
0161    * \param invertex Input Vertex, if fit track as a primary vertex
0162    */
0163   std::shared_ptr<PHGenFit::Track> ReFitTrack(PHCompositeNode*, const SvtxTrack* intrack);
0164 
0165   //! Make SvtxTrack from PHGenFit::Track and SvtxTrack
0166   std::shared_ptr<SvtxTrack> MakeSvtxTrack(const SvtxTrack* svtxtrack, const std::shared_ptr<PHGenFit::Track>& genfit_track );
0167 
0168   bool pos_cov_XYZ_to_RZ(
0169       const TVector3& n,
0170       const TMatrixF& pos_in,
0171       const TMatrixF& cov_in,
0172       TMatrixF& pos_out,
0173       TMatrixF& cov_out) const;
0174 
0175   //! disabled layers
0176   /** clusters belonging to disabled layers are not included in track fit */
0177   std::set<int> _disabled_layers;
0178 
0179   /// Boolean to use normal tracking geometry navigator or the
0180   /// Acts::DirectedNavigator with a list of sorted silicon+MM surfaces
0181   bool m_fit_silicon_mms = false;
0182 
0183   /// requires micromegas present when fitting silicon-MM surfaces
0184   bool m_use_micromegas = true;
0185 
0186   //! KalmanFitterRefTrack, KalmanFitter, DafSimple, DafRef
0187   std::string _track_fitting_alg_name = "DafRef";
0188 
0189   int _primary_pid_guess = 211;
0190   double _fit_min_pT = 0.1;
0191   double _vertex_min_ndf = 20;
0192 
0193   /*
0194   need to use shared_ptr and not unique_ptr because root5 cint
0195   requires the existence of a copy constructor, which the unique_ptr forbids
0196   */
0197   std::shared_ptr<PHGenFit::Fitter> _fitter;
0198 
0199   /// acts geometry
0200   ActsGeometry* m_tgeometry = nullptr;
0201 
0202   //! Input Node pointers
0203   TrkrClusterContainer* m_clustermap = nullptr;
0204 
0205   // track seeds
0206   TrackSeedContainer* m_seedMap = nullptr;
0207   TrackSeedContainer* m_tpcSeeds = nullptr;
0208   TrackSeedContainer* m_siliconSeeds = nullptr;
0209 
0210   //! Output Node pointers
0211   SvtxTrackMap* m_trackMap = nullptr;
0212 
0213   //! tpc global position wrapper
0214   TpcGlobalPositionWrapper m_globalPositionWrapper;
0215 
0216   std::string _seedMap_name = "SvtxTrackSeedContainer";
0217   std::string _trackMap_name = "SvtxTrackMap";
0218 
0219   /// disable distortion correction
0220   bool m_disable_module_edge_corr = false;
0221   bool m_disable_static_corr = false;
0222   bool m_disable_average_corr = false;
0223   bool m_disable_fluctuation_corr = false;
0224 };
0225 
0226 #endif