Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:54

0001 #ifndef TRACKRECO_PHTPCRESIDUALS_H
0002 #define TRACKRECO_PHTPCRESIDUALS_H
0003 
0004 #include <fun4all/SubsysReco.h>
0005 #include <tpc/TpcGlobalPositionWrapper.h>
0006 #include <trackbase/ActsGeometry.h>
0007 #include <trackbase/TrkrDefs.h>
0008 #include <trackbase_historic/ActsTransformations.h>
0009 
0010 #include <Acts/EventData/TrackParameters.hpp>
0011 #include <Acts/Utilities/Result.hpp>
0012 
0013 #include <memory>
0014 #include <optional>
0015 
0016 class PHCompositeNode;
0017 class SvtxTrack;
0018 class SvtxTrackMap;
0019 class TpcSpaceChargeMatrixContainer;
0020 class TrkrCluster;
0021 class TrkrClusterContainer;
0022 
0023 class TFile;
0024 class TH1;
0025 class TH2;
0026 class TTree;
0027 
0028 /**
0029  * This class takes preliminary fits from PHActsTrkFitter to the
0030  * silicon + MM clusters and calculates the residuals in the TPC
0031  * from that track fit. The TPC state has to be explicitly determined
0032  * here since the Acts::DirectNavigator does not visit the TPC states
0033  */
0034 class PHTpcResiduals : public SubsysReco
0035 {
0036  public:
0037   PHTpcResiduals(const std::string &name = "PHTpcResiduals");
0038   ~PHTpcResiduals() override = default;
0039 
0040   int Init(PHCompositeNode *topNode) override;
0041   int InitRun(PHCompositeNode *topNode) override;
0042   int process_event(PHCompositeNode *topNode) override;
0043   int End(PHCompositeNode *topNode) override;
0044 
0045   ///@name Option for setting distortion correction calculation limits
0046   //@{
0047   void setMaxTrackAlpha(float maxTAlpha)
0048   {
0049     m_maxTAlpha = maxTAlpha;
0050   }
0051 
0052   void setMaxTrackBeta(float maxTBeta)
0053   {
0054     m_maxTBeta = maxTBeta;
0055   }
0056 
0057   void setMaxTrackResidualDrphi(float maxResidualDrphi)
0058   {
0059     m_maxResidualDrphi = maxResidualDrphi;
0060   }
0061 
0062   void setMaxTrackResidualDz(float maxResidualDz)
0063   {
0064     m_maxResidualDz = maxResidualDz;
0065   }
0066   //@}
0067 
0068   /// track min pT
0069   void setMinPt(double value)
0070   {
0071     m_minPt = value;
0072   }
0073 
0074   /// Grid dimensions
0075   void setGridDimensions(const int phiBins, const int rBins, const int zBins);
0076 
0077   /// set to true to store evaluation histograms and ntuples
0078   void setSavehistograms(bool) {}
0079 
0080   /// output file name for evaluation histograms
0081   void setHistogramOutputfile(const std::string &) {}
0082 
0083   /// output file name for storing the space charge reconstruction matrices
0084   void setOutputfile(const std::string &outputfile)
0085   {
0086     m_outputfile = outputfile;
0087   }
0088 
0089   /// require micromegas to be present when extrapolating tracks to the TPC
0090   void setUseMicromegas(bool value)
0091   {
0092     m_useMicromegas = value;
0093   }
0094 
0095  private:
0096   using BoundTrackParam =
0097       const Acts::BoundTrackParameters;
0098 
0099   /// pairs path length and track parameters
0100   using BoundTrackParamPair = std::pair<float, BoundTrackParam>;
0101 
0102   int getNodes(PHCompositeNode *topNode);
0103   int createNodes(PHCompositeNode *topNode);
0104 
0105   int processTracks(PHCompositeNode *topNode);
0106 
0107   bool checkTrack(SvtxTrack *track) const;
0108   void processTrack(SvtxTrack *track);
0109 
0110   /// fill track state from bound track parameters
0111   void addTrackState(SvtxTrack *track, TrkrDefs::cluskey key, float pathlength, const Acts::BoundTrackParameters &params);
0112 
0113   /// Gets distortion cell for identifying bins in TPC
0114   int getCell(const Acts::Vector3 &loc);
0115 
0116   //! create ACTS track parameters from Svtx track
0117   Acts::BoundTrackParameters makeTrackParams(SvtxTrack *) const;
0118 
0119   //! create ACTS track parameters from Svtx track state
0120   Acts::BoundTrackParameters makeTrackParams(SvtxTrack *, SvtxTrackState *) const;
0121 
0122   /// acts transformation
0123   ActsTransformations m_transformer;
0124 
0125   /// Node information for Acts tracking geometry and silicon+MM
0126   /// track fit
0127   SvtxTrackMap *m_trackMap = nullptr;
0128   ActsGeometry *m_tGeometry = nullptr;
0129   TrkrClusterContainer *m_clusterContainer = nullptr;
0130 
0131   //! tpc global position wrapper
0132   TpcGlobalPositionWrapper m_globalPositionWrapper;
0133 
0134   float m_maxTAlpha = 0.6;
0135   float m_maxResidualDrphi = 0.5;  // cm
0136   float m_maxTBeta = 1.5;
0137   float m_maxResidualDz = 0.5;  // cm
0138 
0139   static constexpr float m_phiMin = 0;
0140   static constexpr float m_phiMax = 2. * M_PI;
0141 
0142   static constexpr float m_rMin = 20;  // cm
0143   static constexpr float m_rMax = 78;  // cm
0144 
0145   static constexpr int m_minClusCount = 10;
0146 
0147   /// Tpc geometry
0148   static constexpr unsigned int m_nLayersTpc = 48;
0149   static constexpr float m_zMin = -105.5;  // cm
0150   static constexpr float m_zMax = 105.5;   // cm
0151 
0152   /// matrix container
0153   std::unique_ptr<TpcSpaceChargeMatrixContainer> m_matrix_container;
0154 
0155   // TODO: check if needed
0156   int m_event = 0;
0157 
0158   /// require micromegas to be present when extrapolating tracks to the TPC
0159   bool m_useMicromegas = true;
0160 
0161   /// minimum pT required for track to be considered in residuals calculation (GeV/c)
0162   double m_minPt = 0.5;
0163 
0164   /// output file
0165   std::string m_outputfile = "TpcSpaceChargeMatrices.root";
0166 
0167   ///@name counters
0168   //@{
0169   int m_total_tracks = 0;
0170   int m_accepted_tracks = 0;
0171 
0172   int m_total_clusters = 0;
0173   int m_accepted_clusters = 0;
0174   //@}
0175 };
0176 
0177 #endif