Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-08-30 08:14:28

0001 #ifndef TPCCALIB_TpcCentralMembraneStripeMatching_H
0002 #define TPCCALIB_TpcCentralMembraneStripeMatching_H
0003 
0004 #include "StripeComparison.h"
0005 #include "StripeDetector.h"
0006 #include <tpc/TpcDistortionCorrection.h>
0007 #include <tpc/TpcDistortionCorrectionContainer.h>
0008 #include <fun4all/SubsysReco.h>
0009 
0010 #include <string>
0011 #include <array>
0012 #include <vector>
0013 
0014 class LaserClusterContainer;
0015 class PHCompositeNode;
0016 
0017 class TH2;
0018 
0019 // Fun4All subsystem wrapper around the flattened stripe analysis.
0020 //
0021 // This class handles framework tasks: fetch nodes, fill measured/reference
0022 // histograms, run the detector and comparison helpers, and write the output
0023 // file at End(). The matching math itself lives in StripeComparison.
0024 class TpcCentralMembraneStripeMatching : public SubsysReco {
0025 public:
0026   TpcCentralMembraneStripeMatching(const std::string &name = "TpcCentralMembraneStripeMatching");
0027   ~TpcCentralMembraneStripeMatching() override = default;
0028 
0029   // Output ROOT file for distortion maps and diagnostics.
0030   void setOutputfile(const std::string &outputfile);
0031 
0032   // ROOT file containing the measured-coordinate reference stripe histogram.
0033   void setReferenceStripeFile(const std::string &stripePatternFile)
0034   {
0035     m_referenceStripePatternFile = stripePatternFile;
0036   }
0037 
0038   // ROOT file containing the ideal stripe pattern, used when parameters request
0039   // the ideal pattern instead of the measured-coordinate reference file.
0040   void setIdealStripeFile(const std::string &stripePatternFile)
0041   {
0042     m_idealStripePatternFile = stripePatternFile;
0043   }
0044 
0045   void setStaticCorrectionFile(const std::string &staticCorrectionFile)
0046   {
0047     m_staticCorrectionFile = staticCorrectionFile;
0048   }
0049 
0050   void setFillReferenceHistogramsOnly()
0051   {
0052     m_fillReferenceHistogramsOnly = true;
0053   }
0054 
0055   TH2 *cloneReferenceHistogram(int side, const std::string &name) const;
0056 
0057   // Fun4All lifecycle hooks.
0058   int InitRun(PHCompositeNode *topNode) override;
0059 
0060   int process_event(PHCompositeNode *topNode) override;
0061 
0062   int End(PHCompositeNode *topNode) override;
0063 
0064 private:
0065   // Pull node pointers needed for cluster input and optional distortion maps.
0066   int GetNodes(PHCompositeNode *topNode);
0067 
0068   // Allocate measured histograms with the binning configured below.
0069   void CreateMeasuredHistograms();
0070 
0071   // Allocate reference histograms when building a measured-coordinate reference.
0072   void CreateReferenceHistograms();
0073 
0074   // Read reference histograms from the selected reference or ideal-pattern file.
0075   void LoadReferenceHistograms();
0076 
0077   // Shared cluster filling for measured/reference histogram arrays.
0078   void FillClusterHistograms(int histogramSet);
0079 
0080   // Convert laser clusters into side-separated phi/R occupancy histograms.
0081   void FillMeasuredHistograms();
0082 
0083   // Fill measured-coordinate reference histograms from laser clusters.
0084   void FillReferenceHistograms();
0085 
0086   // Put cluster phi values into the histogram convention used by this analysis.
0087   double NormalizeClusterPhi(double phi) const;
0088 
0089   // Run StripeComparison for one detector side after stripe detection.
0090   void ComputeStripeComparisonMaps(const std::vector<std::array<double, 3>> &measured, const std::vector<std::array<double, 3>> &reference, const std::vector<double> &measuredRadialGapCenters, int side);
0091 
0092   // Writes measured clusters shifted by the static distortion map for diagnostics.
0093   void WriteStaticCorrectedMeasuredHistogram(int side);
0094 
0095   // Apply lamination cleaning to histograms before stripe finding.
0096   int CleanClusterHistograms();
0097 
0098   // Finds stripe centers from TH2 input using only flat arrays.
0099   StripeDetector m_detector;
0100 
0101   // Output path configured by the macro or by a calling job.
0102   std::string m_outputfile{"CMDistortionCorrections_idealtpccoordinatesTEST.root"};
0103 
0104   // Framework node pointers. They are owned by Fun4All, not by this class.
0105   LaserClusterContainer *m_laserClusterContainer = nullptr;
0106   TpcDistortionCorrectionContainer *m_dcc_in_module_edge = nullptr;
0107   TpcDistortionCorrectionContainer *m_dcc_in_static = nullptr;
0108   TpcDistortionCorrection m_distortionCorrection;
0109 
0110   // Basic histogram and event counters.
0111   unsigned int m_minClusterLayers = 1;
0112   int m_phiBins = 8000;
0113   int m_rBins = 500;
0114   double m_rMin = 30.0;
0115   double m_rMax = 80.0;
0116   long long m_processedEvents = 0;
0117   long long m_filledClusters[2]{0, 0};
0118   long long m_filledReferenceClusters[2]{0, 0};
0119   bool m_fillReferenceHistogramsOnly = false;
0120 
0121   // Histogram arrays use [measured/reference][side].
0122   TH2 *m_hPetal[2][2]{nullptr};        // [measured/reference][side]
0123   TH2 *m_hPetalCleaned[2][2]{nullptr}; // [measured/reference][side]
0124 
0125   // Detected stripe arrays use [measured/reference][side]. Each stripe is
0126   // std::array<double, 3> with slots documented in StripeMatchingTypes.h.
0127   std::vector<std::array<double, 3>> m_stripes[2][2]; // [measured/reference][side]
0128 
0129   // Radial controls derived while masking laminations.
0130   std::vector<double> m_lamination_radial_gap_centers[2][2];
0131 
0132   // Reused comparison helper. clear() is called inside initialize() for each
0133   // side so previous-side state is removed before the next side begins.
0134   StripeComparison m_comparison;
0135 
0136   // ********************** Field off beam off reference *************** //
0137 
0138   // std::string m_referenceStripePatternFile = "/sphenix/user/dloomis/DistortionsAnalysis/laminationfits/"
0139   //                                            "78242_fieldoffbeamoff/idealtpccoordinates_updatedfitstripereference/"
0140   //                                            "Laminations_run3auau_new_nocdbtag_v001-00078242.root";
0141 
0142   // ******************************************************************* //
0143 
0144   // ********************** Field on beam off reference *************** //
0145   std::string m_referenceStripePatternFile = "/sphenix/user/dloomis/DistortionsAnalysis/laminationfits/"
0146                                              "fieldonbeamoff_all/idealtpccoordinates_hugoupdatedstaticdistortionmap/"
0147                                              "laminations.root";
0148 
0149   // ******************************************************************* //
0150 
0151   // ************************** Ideal Stripe Pattern ****************** //
0152   std::string m_idealStripePatternFile = "/sphenix/user/dloomis/Distortions/StripePatterns/"
0153                                          "CMStripePattern_ideal.root";
0154 
0155   std::string m_staticCorrectionFile = "/sphenix/user/dloomis/Distortions/DistortionMaps_Static/"
0156                                        "static_only_inverted_10-new_hugoupdate.root";
0157 
0158   // ******************************************************************* //
0159 };
0160 
0161 #endif