Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef TPCCALIB_TPCSPACECHARGERECONSTRUCTION_H
0002 #define TPCCALIB_TPCSPACECHARGERECONSTRUCTION_H
0003 /**
0004  * \file TpcSpaceChargeReconstruction.h
0005  * \brief performs space charge distortion reconstruction using tracks
0006  * \author Hugo Pereira Da Costa <hugo.pereira-da-costa@cea.fr>
0007  */
0008 #include <fun4all/SubsysReco.h>
0009 #include <phparameter/PHParameterInterface.h>
0010 #include <tpc/TpcGlobalPositionWrapper.h>
0011 
0012 /// Acts includes to create all necessary definitions
0013 #include <Acts/Definitions/Algebra.hpp>
0014 #include <Acts/Utilities/BinnedArray.hpp>
0015 #include <Acts/Utilities/Logger.hpp>
0016 
0017 #include <memory>
0018 #include <vector>
0019 
0020 // forward declaration
0021 class SvtxTrack;
0022 class SvtxTrackMap;
0023 class TpcSpaceChargeMatrixContainer;
0024 class TrkrCluster;
0025 class TrkrClusterContainer;
0026 
0027 class TFile;
0028 class TH1;
0029 class TH2;
0030 
0031 /**
0032  * \class TpcSpaceChargeReconstruction
0033  * \brief performs space charge distortion reconstruction using tracks
0034  * \detail To reconstruct the distortions dr0, drphi0 and dz0 in a given volume element, the following chisquare is minimized
0035  chisquare = sum_cluster (drphi - (drphi0 + dr0 tan alpha))**2/error**2 + sum_cluster ( dz - (dz0 + dr0 tan beta))**2/error**2
0036  with
0037  - drphi and dz the residuals (track - cluster) measured for a given cluster
0038  - alpha and beta the track angles at the cluster in the rphi,r plane and the z,r plane, respectively
0039  The chisquare being quadratic in dr0, drphi0 and dz0, it can be minimized analytically.
0040  This results in a linear equation lhs[i].[corrections] = rhs[i], and thus [corrections] = lhs[i]**(-1).rhs[i]
0041  The lhs and rhs matrices are filled in TpcSpaceChargeReconstruction::process_track
0042  The actual inversion is performed in TpcSpaceChargeMatrixInversion::calculate_distortions
0043  */
0044 
0045 class TpcSpaceChargeReconstruction : public SubsysReco, public PHParameterInterface
0046 {
0047  public:
0048   /// constructor
0049   TpcSpaceChargeReconstruction(const std::string& = "TPCSPACECHARGERECONSTRUCTION");
0050 
0051   ///@name configuration
0052   //@{
0053 
0054   /// set whether to use only tracks with micromegas or not
0055   void set_use_micromegas(bool value)
0056   {
0057     m_use_micromegas = value;
0058   }
0059 
0060   /// track min pT
0061   void set_min_pt(double value)
0062   {
0063     m_min_pt = value;
0064   }
0065 
0066   /// set grid dimensions
0067   /**
0068   \param phibins the number of bins in the azimuth direction
0069   \param zbins the number of bins along z
0070   */
0071   void set_grid_dimensions(int phibins, int rbins, int zbins);
0072 
0073   /// set to true to store evaluation histograms and ntuples
0074   void set_save_histograms(bool value) { m_savehistograms = value; }
0075 
0076   /// output file name for evaluation histograms
0077   void set_histogram_outputfile(const std::string& outputfile) { m_histogramfilename = outputfile; }
0078 
0079   /// output file
0080   /**
0081    * this is the file where space charge matrix container is stored
0082    */
0083   void set_outputfile(const std::string& filename)
0084   {
0085     m_outputfile = filename;
0086   }
0087 
0088   //@}
0089 
0090   /// global initialization
0091   int Init(PHCompositeNode*) override;
0092 
0093   /// run initialization
0094   int InitRun(PHCompositeNode*) override;
0095 
0096   /// event processing
0097   int process_event(PHCompositeNode*) override;
0098 
0099   /// end of processing
0100   int End(PHCompositeNode*) override;
0101 
0102   /// parameters
0103   void SetDefaultParameters() override;
0104 
0105  private:
0106   /// load nodes
0107   int load_nodes(PHCompositeNode*);
0108 
0109   /// create evaluation histograms
0110   void create_histograms();
0111 
0112   /// process tracks
0113   void process_tracks();
0114 
0115   /// returns true if track fulfills basic requirement for distortion calculations
0116   bool accept_track(SvtxTrack*) const;
0117 
0118   /// process track
0119   void process_track(SvtxTrack*);
0120 
0121   /// get relevant cell for a given cluster
0122   int get_cell_index(const Acts::Vector3&);
0123 
0124   /// output file
0125   std::string m_outputfile = "TpcSpaceChargeMatrices.root";
0126 
0127   /// true if only tracks with micromegas must be used
0128   bool m_use_micromegas = true;
0129 
0130   /// minimum pT required for track to be considered in residuals calculation (GeV/c)
0131   double m_min_pt = 0.5;
0132 
0133   ///@name selection parameters
0134   //@{
0135   // residual cuts in r, phi plane
0136   float m_max_talpha = 0.6;
0137   float m_max_drphi = 0.5;
0138 
0139   // residual cuts in r, z plane
0140   float m_max_tbeta = 1.5;
0141   float m_max_dz = 0.5;
0142   //@}
0143 
0144   /// matrix container
0145   std::unique_ptr<TpcSpaceChargeMatrixContainer> m_matrix_container;
0146 
0147   ///@name counters
0148   //@{
0149   int m_total_tracks = 0;
0150   int m_accepted_tracks = 0;
0151 
0152   int m_total_clusters = 0;
0153   int m_accepted_clusters = 0;
0154   //@}
0155 
0156   ///@name evaluation histograms
0157   //@{
0158   /// Output root histograms
0159   bool m_savehistograms = false;
0160 
0161   /// histogram output file name
0162   std::string m_histogramfilename = "TpcSpaceChargeReconstruction.root";
0163   std::unique_ptr<TFile> m_histogramfile;
0164 
0165   using TH1_map_t = std::map<int, TH1*>;
0166   using TH2_map_t = std::map<int, TH2*>;
0167 
0168   TH1_map_t m_h_drphi;
0169   TH1_map_t m_h_dz;
0170   TH2_map_t m_h_drphi_alpha;
0171   TH2_map_t m_h_dz_beta;
0172   //@}
0173 
0174   //! tracks
0175   SvtxTrackMap* m_track_map = nullptr;
0176 
0177   //! clusters
0178   TrkrClusterContainer* m_cluster_map = nullptr;
0179 
0180   //! tpc global position wrapper
0181   TpcGlobalPositionWrapper m_globalPositionWrapper;
0182 };
0183 
0184 #endif