Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 /*!
0004  *  \file       PHG4TrackFastSim.h
0005  *  \brief      Kalman Filter based on smeared truth PHG4Hit
0006  *  \details    Kalman Filter based on smeared truth PHG4Hit
0007  *  \author     Haiwang Yu <yuhw@nmsu.edu>
0008  */
0009 
0010 #ifndef G4TRACKFASTSIM_PHG4TRACKFASTSIM_H
0011 #define G4TRACKFASTSIM_PHG4TRACKFASTSIM_H
0012 
0013 #include <fun4all/SubsysReco.h>
0014 
0015 #include <TMatrixDSymfwd.h>  // for TMatrixDSym
0016 #include <TVector3.h>
0017 
0018 // #include <phgenfit/Track.h> is needed, it crashes on Ubuntu using
0019 // singularity with local cvmfs install
0020 // shared pointer later on uses this, forward declaration does not cut it
0021 #include <phgenfit/Track.h>
0022 
0023 #include <gsl/gsl_rng.h>
0024 
0025 #include <climits>  // for UINT_MAX
0026 #include <map>
0027 #include <memory>
0028 #include <string>
0029 #include <vector>
0030 
0031 class PHG4Hit;
0032 class PHG4HitContainer;
0033 class PHG4Particle;
0034 class SvtxTrack;
0035 class SvtxTrackMap;
0036 class SvtxVertexMap;
0037 class PHCompositeNode;
0038 class PHG4TruthInfoContainer;
0039 class PHParameters;
0040 
0041 namespace PHGenFit
0042 {
0043   class Fitter;
0044   class Measurement;
0045   class PlanarMeasurement;
0046   class Track;
0047 } /* namespace PHGenFit */
0048 namespace genfit
0049 {
0050   class GFRaveVertex;
0051   class GFRaveVertexFactory;
0052 } /* namespace genfit */
0053 
0054 class PHG4TrackFastSim : public SubsysReco
0055 {
0056  public:
0057   enum DETECTOR_TYPE
0058   {
0059     Vertical_Plane = 0,
0060     Cylinder = 1
0061   };
0062 
0063   //! Default constructor
0064   explicit PHG4TrackFastSim(const std::string& name = "PHG4TrackFastSim");
0065 
0066   //! dtor
0067   ~PHG4TrackFastSim() override;
0068 
0069   //! Initialization Run, called for initialization of a run
0070   int InitRun(PHCompositeNode*) override;
0071 
0072   //! Process Event, called for each event
0073   int process_event(PHCompositeNode*) override;
0074 
0075   //! End, write and close files
0076   int End(PHCompositeNode*) override;
0077 
0078   bool is_do_evt_display() const
0079   {
0080     return m_DoEvtDisplayFlag;
0081   }
0082 
0083   void set_do_evt_display(bool doEvtDisplay)
0084   {
0085     m_DoEvtDisplayFlag = doEvtDisplay;
0086   }
0087 
0088   const std::string& get_fit_alg_name() const
0089   {
0090     return m_FitAlgoName;
0091   }
0092 
0093   void set_fit_alg_name(const std::string& fitAlgName)
0094   {
0095     m_FitAlgoName = fitAlgName;
0096   }
0097 
0098   const std::vector<std::string>& get_phg4hits_names() const
0099   {
0100     return m_PHG4HitsNames;
0101   }
0102 
0103   //! adding hits from a PHG4Hit node, which usually belong to one detector or a sub group of detectors
0104   //! Orders of adding detectors do not matter as the hits are internally assembled in the time order
0105   //! \param[in] phg4hitsNames node name such as "G4HIT_SVTX"
0106   //! \param[in] PHG4TrackFastSim::Vertical_Plane or PHG4TrackFastSim::Cylinder
0107   //! \param[in] radres radial resolution [cm], not used for PHG4TrackFastSim::Cylinder
0108   //! \param[in] phires azimuthal resolution [cm]
0109   //! \param[in] lonres z-resolution [cm], not used for PHG4TrackFastSim::Vertical_Plane
0110   //! \param[in] eff    Efficiency [0-1] for a existing hit to be included in the tracking
0111   //! \param[in] noise  Noise hit propability [0-1]
0112   void add_phg4hits(
0113       const std::string& phg4hitsNames,
0114       const DETECTOR_TYPE phg4dettype,
0115       const float radres,
0116       const float phires,
0117       const float lonres,
0118       const float eff,
0119       const float noise)
0120   {
0121     m_PHG4HitsNames.push_back(phg4hitsNames);
0122     m_phg4_detector_type.push_back(phg4dettype);
0123     m_phg4_detector_radres.push_back(radres);
0124     m_phg4_detector_phires.push_back(phires);
0125     m_phg4_detector_lonres.push_back(lonres);
0126     m_phg4_detector_hitfindeff.push_back(eff);
0127     m_phg4_detector_noise.push_back(noise);
0128   }
0129 
0130   // legacy interface for Babar calorimeter projections
0131   void add_state_name(const std::string& stateName);
0132 
0133   // add saving of state at plane in z
0134   void add_zplane_state(const std::string& stateName, const double zplane);
0135 
0136   void add_cylinder_state(const std::string& stateName, const double radius);
0137 
0138   const std::string& get_trackmap_out_name() const
0139   {
0140     return m_TrackmapOutNodeName;
0141   }
0142 
0143   void set_trackmap_out_name(const std::string& trackmapOutName)
0144   {
0145     m_TrackmapOutNodeName = trackmapOutName;
0146   }
0147 
0148   const std::string& get_sub_top_node_name() const
0149   {
0150     return m_SubTopnodeName;
0151   }
0152 
0153   void set_sub_top_node_name(const std::string& subTopNodeName)
0154   {
0155     m_SubTopnodeName = subTopNodeName;
0156   }
0157 
0158   bool is_use_vertex_in_fitting() const
0159   {
0160     return m_UseVertexInFittingFlag;
0161   }
0162 
0163   void set_use_vertex_in_fitting(bool useVertexInFitting)
0164   {
0165     m_UseVertexInFittingFlag = useVertexInFitting;
0166   }
0167 
0168   double get_vertex_xy_resolution() const
0169   {
0170     return m_VertexXYResolution;
0171   }
0172 
0173   void set_vertex_xy_resolution(double vertexXyResolution)
0174   {
0175     m_VertexXYResolution = vertexXyResolution;
0176   }
0177 
0178   double get_vertex_z_resolution() const
0179   {
0180     return m_VertexZResolution;
0181   }
0182 
0183   void set_vertex_z_resolution(double vertexZResolution)
0184   {
0185     m_VertexZResolution = vertexZResolution;
0186   }
0187 
0188   int get_primary_assumption_pid() const
0189   {
0190     return m_PrimaryAssumptionPid;
0191   }
0192 
0193   void set_primary_assumption_pid(int primaryAssumptionPid)
0194   {
0195     m_PrimaryAssumptionPid = primaryAssumptionPid;
0196   }
0197 
0198   void set_primary_tracking(int pTrk)
0199   {
0200     m_PrimaryTrackingFlag = pTrk;
0201   }
0202 
0203   //! https://rave.hepforge.org/trac/wiki/RaveMethods
0204   const std::string& get_vertexing_method() const
0205   {
0206     return m_VertexingMethod;
0207   }
0208 
0209   //! https://rave.hepforge.org/trac/wiki/RaveMethods
0210   void set_vertexing_method(const std::string& vertexingMethod)
0211   {
0212     m_VertexingMethod = vertexingMethod;
0213   }
0214 
0215   double get_vertex_min_ndf() const
0216   {
0217     return m_VertexMinNdf;
0218   }
0219 
0220   void set_vertex_min_ndf(double vertexMinNdf)
0221   {
0222     m_VertexMinNdf = vertexMinNdf;
0223   }
0224 
0225   void enable_vertexing(const bool& b = true)
0226   {
0227     m_DoVertexingFlag = b;
0228   }
0229 
0230   void DisplayEvent() const;
0231 
0232   void Smearing(const bool b) { m_SmearingFlag = b; }
0233 
0234  private:
0235   typedef std::map<const genfit::Track*, unsigned int> GenFitTrackMap;
0236 
0237   /*!
0238    * Create needed nodes.
0239    */
0240   int CreateNodes(PHCompositeNode*);
0241 
0242   /*!
0243    * Get all the all the required nodes off the node tree.
0244    */
0245   int GetNodes(PHCompositeNode*);
0246 
0247   /*!
0248    *
0249    */
0250   int PseudoPatternRecognition(const PHG4Particle* particle,
0251                                std::vector<PHGenFit::Measurement*>& meas_out,
0252                                SvtxTrack* track_out,
0253                                TVector3& seed_pos,
0254                                TVector3& seed_mom,
0255                                TMatrixDSym& seed_cov,
0256                                const bool do_smearing = true);
0257 
0258   PHGenFit::PlanarMeasurement* PHG4HitToMeasurementVerticalPlane(const PHG4Hit* g4hit, const double phi_resolution, const double r_resolution);
0259 
0260   PHGenFit::PlanarMeasurement* PHG4HitToMeasurementCylinder(const PHG4Hit* g4hit, const double phi_resolution, const double z_resolution);
0261 
0262   PHGenFit::Measurement* VertexMeasurement(const TVector3& vtx, double dxy, double dz);
0263 
0264   /*!
0265    * Make SvtxTrack from PHGenFit::Track
0266    */
0267   bool MakeSvtxTrack(SvtxTrack* track_out, const PHGenFit::Track* phgf_track_in,
0268                      const unsigned int truth_track_id = UINT_MAX,
0269                      const unsigned int nmeas = 0, const TVector3& vtx = TVector3(0.0, 0.0, 0.0));
0270 
0271   /*
0272    * Fill SvtxVertexMap from GFRaveVertexes and Tracks
0273    */
0274   bool FillSvtxVertexMap(const std::vector<genfit::GFRaveVertex*>& rave_vertices,
0275                          const GenFitTrackMap& gf_tracks);
0276 
0277  protected:
0278   // Pointers first
0279   //! random generator that conform with sPHENIX standard
0280   gsl_rng* m_RandomGenerator;
0281 
0282   /*!
0283    *    GenFit fitter interface
0284    */
0285   PHGenFit::Fitter* m_Fitter;
0286   genfit::GFRaveVertexFactory* m_RaveVertexFactory;
0287 
0288   //! Input Node pointers
0289   PHG4TruthInfoContainer* m_TruthContainer;
0290 
0291   SvtxTrackMap* m_SvtxTrackMapOut;
0292   SvtxVertexMap* m_SvtxVertexMap;
0293 
0294   std::vector<PHG4HitContainer*> m_PHG4HitContainer;
0295   std::vector<std::string> m_PHG4HitsNames;
0296   std::vector<DETECTOR_TYPE> m_phg4_detector_type;
0297   std::vector<float> m_phg4_detector_radres;
0298   std::vector<float> m_phg4_detector_phires;
0299   std::vector<float> m_phg4_detector_lonres;
0300   std::vector<float> m_phg4_detector_hitfindeff;
0301   std::vector<float> m_phg4_detector_noise;
0302 
0303   //!
0304   std::map<std::string, std::pair<int, double>> m_ProjectionsMap;
0305 
0306   std::string m_SubTopnodeName;
0307   std::string m_TrackmapOutNodeName;
0308   //! https://rave.hepforge.org/trac/wiki/RaveMethods
0309   std::string m_VertexingMethod;
0310 
0311   /*!
0312    * Available choices:
0313    * KalmanFitter
0314    * KalmanFitterRefTrack
0315    * DafSimple
0316    * DafRef
0317    */
0318   std::string m_FitAlgoName;
0319 
0320   double m_VertexMinNdf;
0321   double m_VertexXYResolution;
0322   double m_VertexZResolution;
0323 
0324   //! Event counter
0325   int m_EventCnt;
0326 
0327   int m_PrimaryAssumptionPid;
0328 
0329   bool m_SmearingFlag;
0330 
0331   //!
0332   bool m_DoEvtDisplayFlag;
0333 
0334   /*!
0335    * For PseudoPatternRecognition function.
0336    */
0337 
0338   bool m_UseVertexInFittingFlag;
0339 
0340   //!
0341   int m_PrimaryTrackingFlag;
0342 
0343   bool m_DoVertexingFlag;
0344 
0345   PHParameters* m_Parameter = nullptr;
0346 };
0347 
0348 #endif /*__PHG4TrackFastSim_H__*/