Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef TPCCALIB_STRIPEDETECTOR_H
0002 #define TPCCALIB_STRIPEDETECTOR_H
0003 
0004 #include "StripeMatchingTypes.h"
0005 
0006 #include <cstddef>
0007 #include <array>
0008 #include <vector>
0009 
0010 class TH2;
0011 
0012 // A flood-fill bin is std::array<double, 5>.
0013 // Entries are original histogram bin x/y plus physical phi/R/content.
0014 inline constexpr int component_bin_x = 0;
0015 inline constexpr int component_bin_y = 1;
0016 inline constexpr int component_phi = 2;
0017 inline constexpr int component_r = 3;
0018 inline constexpr int component_content = 4;
0019 
0020 class StripeDetector {
0021 public:
0022   // Finds stripe centroids in one input histogram.
0023   // Output stripes are std::array<double, 3> indexed with stripe_*.
0024   bool detect(TH2 *histogram, std::vector<std::array<double, 3>> &stripes);
0025 
0026   // Deletes the temporary cloned histogram.
0027   void clear();
0028 
0029 private:
0030   // Sets dimensions and clears output/state for a new detection pass.
0031   bool initialize(TH2 *histogram, std::vector<std::array<double, 3>> &stripes);
0032 
0033   // Clones the input histogram so flood fill can work on a detached copy.
0034   bool create_working_histogram(TH2 *histogram);
0035 
0036   // Collects bins above the seed threshold, grouped by phi bin.
0037   void collect_seed_bins(TH2 *histogram);
0038 
0039   // Grows connected components from the seed bins.
0040   void build_connected_components();
0041 
0042   // Converts connected components into one centroid per stripe.
0043   void convert_components_to_raw_stripes(TH2 *histogram);
0044 
0045   // Wraps phi-bin arithmetic around the periodic histogram axis.
0046   static int wrapped_phi_bin(int bin, int nBinsX);
0047 
0048   // Normalizes a physical phi value back into the histogram x-axis range.
0049   static void normalize_phi_to_axis(TH2 *histogram, double &phi);
0050 
0051   // Temporary histogram used only during one detect() call.
0052   TH2 *m_workingHist = nullptr;
0053 
0054   // Cached histogram dimensions.
0055   int m_nBinsX = 0;
0056   int m_nBinsY = 0;
0057 
0058   // Seed bins and connected components using component_* array indices.
0059   std::vector<std::vector<std::array<double, 5>>> m_seedBinsByPhi;
0060   std::vector<std::vector<std::array<double, 5>>> m_components;
0061 
0062   // Final raw stripe candidates before duplicate removal.
0063   std::vector<std::array<double, 3>> m_rawStripes;
0064   size_t m_nSeedBins = 0;
0065 };
0066 
0067 #endif