Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-10-16 08:28:09

0001 #ifndef TPCCALIB_LASERCLUSTERTRUTHMATCHER_H
0002 #define TPCCALIB_LASERCLUSTERTRUTHMATCHER_H
0003 
0004 #include <cdbobjects/CDBTTree.h>
0005 
0006 #include <tpc/LaserClusterHelper.h>
0007 #include <tpc/TpcDistortionCorrection.h>
0008 #include <tpc/TpcDistortionCorrectionContainer.h>
0009 
0010 #include <fun4all/SubsysReco.h>
0011 
0012 #include <map>
0013 #include <string>
0014 #include <vector>
0015 
0016 
0017 class PHCompositeNode;
0018 class LaserClusterContainer;
0019 
0020 /*
0021  * Matches already-aggregated-and-clustered laser clusters (LaserClusterv5,
0022  * produced upstream by LaserAggregatedClusterizer) to the CDB truth laser
0023  * pattern, writing only a truthIndex (or -999 if unmatched) back onto each
0024  * cluster in place.
0025  *
0026  * This is deliberately a separate module from LaserAggregatedClusterizer:
0027  * clustering is per-block/parallelized, matching needs the FULL set of
0028  * clusters for a side at once (row-finding and stripe-finding are whole-side
0029  * KDE operations), and matching needs to be retuned/rerun far more often
0030  * than clustering itself. Because distortions differ run to run, matching is
0031  * always redone from scratch here -- nothing is cached across runs.
0032  *
0033  * If wanting to run with PHGarfield distortion corrections, turn on
0034  * set_usePHGarfieldDistortions, and the CDB variables for PHGarfield will
0035  * automatically be pulled and used to propagate the clusters through the
0036  * fields along the poly lines before doing the matching.
0037  */
0038 
0039 struct TruthRow
0040 {
0041   double R{0.0};
0042   double dphi{0.0};
0043   int nstripes{0};
0044 };
0045 
0046 struct TruthRowPattern
0047 {
0048   std::vector<double> stripePhi;   // coordinate phi, ascending
0049   std::vector<int> stripeIPhi;          // stripeIPhi[slot] = CDB iphi digit for that slot
0050 };
0051 
0052 class LaserClusterTruthMatcher : public SubsysReco
0053 {
0054  public:
0055   explicit LaserClusterTruthMatcher(const std::string &name = "LaserClusterTruthMatcher");
0056   ~LaserClusterTruthMatcher() override { delete m_cdbttree; }
0057   LaserClusterTruthMatcher(const LaserClusterTruthMatcher&) = delete;
0058   LaserClusterTruthMatcher& operator=(const LaserClusterTruthMatcher&) = delete;
0059   LaserClusterTruthMatcher(LaserClusterTruthMatcher&&) = delete;
0060   LaserClusterTruthMatcher& operator=(LaserClusterTruthMatcher&&) = delete;
0061 
0062   int InitRun(PHCompositeNode *topNode) override;
0063   int process_event(PHCompositeNode *topNode) override;
0064   int End(PHCompositeNode *topNode) override;
0065 
0066   //! path to the CDB truth-pattern file (CMStripePattern_*.root)
0067   //  TODO: this should probably come from the CDB machinery (run-dependent
0068   //  calibration lookup) rather than a hardcoded path, once this is wired
0069   //  into the real calibration framework.
0070   void setTruthFile(const std::string &file) { m_truthFile = file; }
0071   
0072   //! node name of the LaserClusterContainer written by LaserAggregatedClusterizer
0073   void setLaserClusterNodeName(const std::string &name) { m_laserClusterNodeName = name; }
0074   void setLaserClusterNodeNameOut(const std::string &name) { m_laserClusterNodeNameOut = name; }
0075 
0076   void set_useGlobal(bool use) { m_useGlobal = use; }
0077 
0078   void set_usePHGarfieldDistortions(bool use) { m_usePHGarfieldDistortions = use; }
0079   void set_garfield_cmvoltage(double use) { m_garfield_cmvoltage = use; }
0080   void set_garfield_zerofield(bool use) { m_garfield_zerofield = use; }
0081   void set_garfield_keffside0(double use) { m_garfield_keffside0 = use; m_manual_garfield_keffside0 = true; }
0082   void set_garfield_keffside1(double use) { m_garfield_keffside1 = use; m_manual_garfield_keffside1 = true;}
0083   void set_garfield_stepns(double use) { m_garfield_stepns = use; }
0084 
0085   void set_QABase(const std::string &name) { m_QABase = name; }
0086 
0087   void set_grid_dimensions(int phibins, int rbins){ m_phibins = phibins; m_rbins = rbins; }
0088   void setDistortionOutputfile(const std::string &outputfile) { m_distortionOutputfile = outputfile; }
0089 
0090  private:
0091   int getNodes(PHCompositeNode *topNode);
0092 
0093   std::string m_truthFile{"CMStripePattern_full.root"};
0094   std::string m_laserClusterNodeName{"LASER_AGGREGATED_CLUSTER"};
0095   std::string m_laserClusterNodeNameOut{"LASER_AGGREGATED_CLUSTER_MATCHED"};
0096   std::string m_QABase;
0097 
0098   LaserClusterContainer *m_laserClusterContainer{nullptr};
0099   CDBTTree *m_cdbttree{nullptr};
0100 
0101   std::map<int, TruthRowPattern> m_truthRowPatterns[2];
0102   std::vector<TruthRow> m_truthRows[2];
0103 
0104   LaserClusterHelper m_laserClusterHelper;
0105   bool m_useGlobal{true};
0106   bool m_usePHGarfieldDistortions{false};
0107   double m_garfield_cmvoltage{380.0};
0108   bool m_garfield_zerofield{false};
0109   bool m_manual_garfield_keffside0{false};
0110   bool m_manual_garfield_keffside1{false};  
0111   double m_garfield_keffside0{1.0};
0112   double m_garfield_keffside1{1.0};
0113   double m_garfield_stepns{50.0};
0114 
0115   std::string m_distortionOutputfile{"CMDistortionCorrections.root"};
0116 
0117   TpcDistortionCorrectionContainer *m_dcc_out{nullptr};
0118 
0119   int m_phibins{500};
0120 
0121   static constexpr float m_phiMin{0};
0122   static constexpr float m_phiMax{2. * M_PI};
0123 
0124   /// distortion correction grid size along r
0125   // int m_rbins{12};
0126   int m_rbins{500};
0127 
0128   static constexpr float m_rMin{20};  // cm
0129   static constexpr float m_rMax{80};  // cm
0130   
0131 };
0132 
0133 #endif