Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef TPCCALIB_STRIPECOMPARISON_H
0002 #define TPCCALIB_STRIPECOMPARISON_H
0003 
0004 #include "GlobalFieldFitter.h"
0005 #include "StripeMatchingTypes.h"
0006 
0007 #include <cstddef>
0008 #include <string>
0009 #include <array>
0010 #include <vector>
0011 
0012 class TH2;
0013 
0014 // A selected seed match is std::array<double, 9>.
0015 // It stores measured/reference indices and the displacement values that seed
0016 // the global field fit. This replaces the old SeedMatch record.
0017 inline constexpr int seed_measured_idx = 0;
0018 inline constexpr int seed_reference_idx = 1;
0019 inline constexpr int seed_phi = 2;
0020 inline constexpr int seed_r = 3;
0021 inline constexpr int seed_reference_phi = 4;
0022 inline constexpr int seed_reference_r = 5;
0023 inline constexpr int seed_delta_r = 6;
0024 inline constexpr int seed_delta_phi = 7;
0025 inline constexpr int seed_r_delta_phi = 8;
0026 
0027 class StripeComparison {
0028 public:
0029   ~StripeComparison();
0030 
0031   // Sets side name and stores radial controls for one detector side.
0032   bool initialize(const std::vector<std::array<double, 3>> &measured, const std::vector<std::array<double, 3>> &reference, int side, const std::vector<double> &controlRPositions);
0033 
0034   // Removes isolated stripes and topology edge rows before matching.
0035   bool filter_isolated_inputs(const std::vector<std::array<double, 3>> &measured, const std::vector<std::array<double, 3>> &reference);
0036 
0037   // Selects measured/reference stripe pairs.
0038   bool build_global_pattern_matches();
0039 
0040   // Builds the final global distortion field from selected pairs.
0041   bool build_global_field_estimates();
0042 
0043   // Writes ROOT diagnostics and distortion maps.
0044   void write_output_maps();
0045 
0046   // Writes histograms shifted by the fitted field.
0047   void write_corrected_measured_histogram(TH2 *measuredHistogram);
0048   void write_distorted_reference_histogram(TH2 *referenceHistogram);
0049 
0050   // Clears side-local state.
0051   void clear();
0052 
0053 private:
0054   // Fills one row of the phi-assignment diagnostic tree.
0055   void fill_candidate_diagnostics(size_t diagnosticMeasuredIndex, size_t diagnosticReferenceIndex, double &referencePhi, double &referenceR, double &deltaR, double &deltaPhi, double &rDeltaPhi, double &cost, double &residualDeltaR, double &residualDeltaPhi, double &residualRDeltaPhi, int &withinGate);
0056 
0057   // Applies a fitted shift to every filled bin of a source histogram.
0058   void write_shifted_histogram(TH2 *sourceHistogram, const std::string &name, const std::string &title, double shiftSign);
0059 
0060   // Human-readable side label: negz or posz.
0061   std::string m_sideName;
0062 
0063   // Radial grid controls from lamination cleaning.
0064   std::vector<double> m_controlRPositions;
0065 
0066   // Filtered measured/reference stripes, indexed with stripe_*.
0067   std::vector<std::array<double, 3>> m_measuredFiltered;
0068   std::vector<std::array<double, 3>> m_referenceFiltered;
0069 
0070   // Selected matches and final field observations.
0071   std::vector<std::array<double, 9>> m_seedMatches;
0072   std::vector<std::array<double, 6>> m_globalObservations;
0073 
0074   // Diagnostics for the selected branch hypothesis.
0075   int m_selectedBranchShift = 0;
0076   std::vector<int> m_selectedReferenceRowByIndex;
0077   std::vector<int> m_selectedAllowedReferenceRowByMeasured;
0078 
0079   // Owned fitter for the current detector side.
0080   GlobalFieldFitter *m_globalFieldFitter = nullptr;
0081 };
0082 
0083 #endif