Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:29

0001 
0002 #ifndef TRACKRECO_PHCOSMICSTRKFITTER_H
0003 #define TRACKRECO_PHCOSMICSTRKFITTER_H
0004 
0005 #include "ActsAlignmentStates.h"
0006 #include "ActsEvaluator.h"
0007 
0008 #include <fun4all/SubsysReco.h>
0009 
0010 #include <trackbase/ActsSourceLink.h>
0011 #include <trackbase/ActsTrackFittingAlgorithm.h>
0012 #include <trackbase/ClusterErrorPara.h>
0013 
0014 #include <tpc/TpcGlobalPositionWrapper.h>
0015 
0016 #include <Acts/Definitions/Algebra.hpp>
0017 #include <Acts/EventData/VectorMultiTrajectory.hpp>
0018 #include <Acts/Utilities/BinnedArray.hpp>
0019 #include <Acts/Utilities/Logger.hpp>
0020 
0021 #include <ActsExamples/EventData/Trajectories.hpp>
0022 
0023 #include <memory>
0024 #include <string>
0025 
0026 class alignmentTransformationContainer;
0027 class ActsGeometry;
0028 class SvtxTrack;
0029 class SvtxTrackMap;
0030 class TrackSeed;
0031 class TrackSeedContainer;
0032 class TrkrClusterContainer;
0033 class SvtxAlignmentStateMap;
0034 class PHG4TpcCylinderGeomContainer;
0035 
0036 class TFile;
0037 class TTree;
0038 
0039 using SourceLink = ActsSourceLink;
0040 using FitResult = ActsTrackFittingAlgorithm::TrackFitterResult;
0041 using Trajectory = ActsExamples::Trajectories;
0042 using Measurement = Acts::Measurement<Acts::BoundIndices, 2>;
0043 using SurfacePtrVec = std::vector<const Acts::Surface*>;
0044 using SourceLinkVec = std::vector<Acts::SourceLink>;
0045 
0046 class PHCosmicsTrkFitter : public SubsysReco
0047 {
0048  public:
0049   /// Default constructor
0050   PHCosmicsTrkFitter(const std::string& name = "PHCosmicsTrkFitter");
0051 
0052   /// Destructor
0053   ~PHCosmicsTrkFitter() override = default;
0054 
0055   /// End, write and close files
0056   int End(PHCompositeNode* topNode) override;
0057 
0058   /// Get and create nodes
0059   int InitRun(PHCompositeNode* topNode) override;
0060 
0061   /// Process each event by calling the fitter
0062   int process_event(PHCompositeNode* topNode) override;
0063 
0064   int ResetEvent(PHCompositeNode* topNode) override;
0065 
0066   void setUpdateSvtxTrackStates(bool fillSvtxTrackStates)
0067   {
0068     m_fillSvtxTrackStates = fillSvtxTrackStates;
0069   }
0070 
0071   void useActsEvaluator(bool actsEvaluator)
0072   {
0073     m_actsEvaluator = actsEvaluator;
0074   }
0075 
0076   void setEvaluatorName(const std::string& name) { m_evalname = name; }
0077   void setFieldMap(const std::string& fieldMap)
0078   {
0079     m_fieldMap = fieldMap;
0080   }
0081 
0082   void setAbsPdgHypothesis(unsigned int pHypothesis)
0083   {
0084     m_pHypothesis = pHypothesis;
0085   }
0086   void seedAnalysis() { m_seedClusAnalysis = true; }
0087   void commissioning(bool com) { m_commissioning = com; }
0088 
0089   void useOutlierFinder(bool outlier) { m_useOutlierFinder = outlier; }
0090 
0091   void SetIteration(int iter) { _n_iteration = iter; }
0092   void set_track_map_name(const std::string& map_name) { _track_map_name = map_name; }
0093   void set_seed_track_map_name(const std::string& map_name) { _seed_track_map_name = map_name; }
0094 
0095   void ignoreLayer(int layer) { m_ignoreLayer.insert(layer); }
0096   void setVertexRadius(const float rad) { m_vertexRadius = rad; }
0097   void zeroField() { m_zeroField = true; }
0098 
0099  private:
0100   /// Get all the nodes
0101   int getNodes(PHCompositeNode* topNode);
0102 
0103   /// Create new nodes
0104   int createNodes(PHCompositeNode* topNode);
0105 
0106   void loopTracks(Acts::Logging::Level logLevel);
0107   void getCharge(TrackSeed* track, int& charge, float& cosmicslope);
0108 
0109   /// Convert the acts track fit result to an svtx track
0110   void updateSvtxTrack(std::vector<Acts::MultiTrajectoryTraits::IndexType>& tips,
0111                        Trajectory::IndexedParameters& paramsMap,
0112                        ActsTrackFittingAlgorithm::TrackContainer& tracks,
0113                        SvtxTrack* track);
0114 
0115   /// Helper function to call either the regular navigation or direct
0116   /// navigation, depending on m_fitSiliconMMs
0117   inline ActsTrackFittingAlgorithm::TrackFitterResult fitTrack(
0118       const std::vector<Acts::SourceLink>& sourceLinks,
0119       const ActsTrackFittingAlgorithm::TrackParameters& seed,
0120       const ActsTrackFittingAlgorithm::GeneralFitterOptions&
0121           kfOptions,
0122       const CalibratorAdapter& calibrator,
0123       ActsTrackFittingAlgorithm::TrackContainer& tracks);
0124 
0125   bool getTrackFitResult(FitResult& fitOutput, TrackSeed* seed,
0126                          SvtxTrack* track,
0127                          ActsTrackFittingAlgorithm::TrackContainer& tracks,
0128                          const ActsTrackFittingAlgorithm::MeasurementContainer& measurements);
0129 
0130   Acts::BoundSquareMatrix setDefaultCovariance() const;
0131   void printTrackSeed(const ActsTrackFittingAlgorithm::TrackParameters& seed) const;
0132   void makeBranches();
0133 
0134   /// Event counter
0135   int m_event = 0;
0136 
0137   /// Options that Acts::Fitter needs to run from MakeActsGeometry
0138   ActsGeometry* m_tGeometry = nullptr;
0139 
0140   /// Configuration containing the fitting function instance
0141   ActsTrackFittingAlgorithm::Config m_fitCfg;
0142 
0143   /// TrackMap containing SvtxTracks
0144   SvtxTrackMap* m_trackMap = nullptr;
0145   //  SvtxTrackMap* m_directedTrackMap = nullptr;
0146   TrkrClusterContainer* m_clusterContainer = nullptr;
0147   TrackSeedContainer* m_seedMap = nullptr;
0148   TrackSeedContainer* m_tpcSeeds = nullptr;
0149   TrackSeedContainer* m_siliconSeeds = nullptr;
0150 
0151   // Used for distortion correction transformations
0152   alignmentTransformationContainer* m_alignmentTransformationMapTransient = nullptr;
0153   std::set<Acts::GeometryIdentifier> m_transient_id_set;
0154   Acts::GeometryContext m_transient_geocontext;
0155 
0156   /// Number of acts fits that returned an error
0157   int m_nBadFits = 0;
0158   int m_nGoodFits = 0;
0159   int m_nLongSeeds = 0;
0160   //! bool to fill alignment state map for further processing
0161   bool m_commissioning = true;
0162 
0163   /// A bool to update the SvtxTrackState information (or not)
0164   bool m_fillSvtxTrackStates = true;
0165 
0166   // do we have a constant field
0167   bool m_ConstField = false;
0168   double fieldstrength{std::numeric_limits<double>::quiet_NaN()};
0169 
0170   /// A bool to use the chi2 outlier finder in the track fitting
0171   bool m_useOutlierFinder = false;
0172   ResidualOutlierFinder m_outlierFinder;
0173 
0174   float m_vertexRadius = 80;
0175 
0176   bool m_actsEvaluator = false;
0177   std::unique_ptr<ActsEvaluator> m_evaluator = nullptr;
0178   std::string m_evalname = "ActsEvaluator.root";
0179 
0180   std::map<const unsigned int, Trajectory>* m_trajectories = nullptr;
0181   SvtxTrackMap* m_seedTracks = nullptr;
0182 
0183   //! tpc global position wrapper
0184   TpcGlobalPositionWrapper m_globalPositionWrapper;
0185 
0186   //! cluster error parametrization
0187   ClusterErrorPara _ClusErrPara;
0188 
0189   std::set<int> m_ignoreLayer;
0190 
0191   std::string m_fieldMap = "";
0192 
0193   int _n_iteration = 0;
0194   std::string _track_map_name = "SvtxTrackMap";
0195   std::string _seed_track_map_name = "SeedTrackMap";
0196 
0197   /// Default particle assumption to muon
0198   unsigned int m_pHypothesis = 13;
0199 
0200   SvtxAlignmentStateMap* m_alignmentStateMap = nullptr;
0201   ActsAlignmentStates m_alignStates;
0202 
0203   bool m_zeroField = false;
0204   PHG4TpcCylinderGeomContainer* _tpccellgeo = nullptr;
0205 
0206   //! for diagnosing seed param + clusters
0207   bool m_seedClusAnalysis = false;
0208   TFile* m_outfile = nullptr;
0209   TTree* m_tree = nullptr;
0210   int m_seed = std::numeric_limits<int>::max();
0211   float m_R = NAN;
0212   float m_X0 = NAN;
0213   float m_Y0 = NAN;
0214   float m_Z0 = NAN;
0215   float m_slope = NAN;
0216   float m_pcax = NAN;
0217   float m_pcay = NAN;
0218   float m_pcaz = NAN;
0219   float m_px = NAN;
0220   float m_py = NAN;
0221   float m_pz = NAN;
0222   int m_charge = std::numeric_limits<int>::max();
0223   int m_nmaps = std::numeric_limits<int>::max();
0224   int m_nintt = std::numeric_limits<int>::max();
0225   int m_ntpc = std::numeric_limits<int>::max();
0226   int m_nmm = std::numeric_limits<int>::max();
0227   std::vector<float> m_locx, m_locy, m_x, m_y, m_z, m_r, m_layer, m_phi, m_eta,
0228       m_phisize, m_zsize, m_ephi, m_ez;
0229   void clearVectors();
0230   void fillVectors(TrackSeed* tpcseed, TrackSeed* siseed);
0231   ClusterErrorPara m_clusErrPara;
0232 };
0233 
0234 #endif