Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-04 00:02:28

0001 #ifndef RecoTracker_MkFitCore_interface_HitStructures_h
0002 #define RecoTracker_MkFitCore_interface_HitStructures_h
0003 
0004 #include "RecoTracker/MkFitCore/interface/Config.h"
0005 #include "RecoTracker/MkFitCore/interface/Hit.h"
0006 #include "RecoTracker/MkFitCore/interface/TrackerInfo.h"
0007 #include "RecoTracker/MkFitCore/interface/binnor.h"
0008 
0009 namespace mkfit {
0010 
0011   class IterationParams;
0012 
0013   //==============================================================================
0014   // LayerOfHits
0015   //==============================================================================
0016 
0017   // Note: the same code is used for barrel and endcap. In barrel the longitudinal
0018   // bins are in Z and in endcap they are in R -- here this coordinate is called Q.
0019 
0020   // When COPY_SORTED_HITS is not defined, hits are accessed from the original hit
0021   // vector and only sort ranks are kept for proper access.
0022   // #define COPY_SORTED_HITS
0023 
0024   class LayerOfHits {
0025   public:
0026     using bin_index_t = unsigned short;
0027     using bin_content_t = unsigned int;
0028     using axis_phi_t = axis_pow2_u1<float, bin_index_t, 16, 8>;
0029     using axis_eta_t = axis<float, bin_index_t, 16, 8>;
0030     using binnor_t = binnor<bin_content_t, axis_phi_t, axis_eta_t, 18, 14>;
0031 
0032     // Initializator
0033 
0034     struct Initializator {
0035       const LayerInfo& m_linfo;
0036       float m_qmin, m_qmax;
0037       unsigned int m_nq;
0038 
0039       void setup(float qmin, float qmax, float dq);
0040 
0041       Initializator(const LayerInfo& li, float qmin, float qmax, unsigned int nq);
0042       Initializator(const LayerInfo& li, float qmin, float qmax, float dq);
0043       Initializator(const LayerInfo& li);
0044     };
0045 
0046     // Constructor
0047 
0048     LayerOfHits(const LayerOfHits::Initializator& i);
0049 
0050     ~LayerOfHits();
0051 
0052     // Setup and filling
0053     //-------------------
0054 
0055     void reset();
0056 
0057     // Get in all hits from given hit-vec
0058     void suckInHits(const HitVec& hitv);
0059 
0060     // Get in all dead regions from given dead-vec
0061     void suckInDeads(const DeadVec& deadv);
0062 
0063     // Use external hit-vec and only use hits that are passed to me.
0064     void beginRegistrationOfHits(const HitVec& hitv);
0065     void registerHit(unsigned int idx);
0066     void endRegistrationOfHits(bool build_original_to_internal_map);
0067 
0068     unsigned int nHits() const { return m_n_hits; }
0069 
0070     // Bin access / queries
0071     //----------------------
0072     bin_index_t qBin(float q) const { return m_ax_eta.from_R_to_N_bin(q); }
0073     bin_index_t qBinChecked(float q) const { return m_ax_eta.from_R_to_N_bin_safe(q); }
0074 
0075     // if you don't pass phi in (-pi, +pi), mask away the upper bits using m_phi_mask or use the Checked version.
0076     bin_index_t phiBin(float phi) const { return m_ax_phi.from_R_to_N_bin(phi); }
0077     bin_index_t phiBinChecked(float phi) const { return m_ax_phi.from_R_to_N_bin_safe(phi); }
0078 
0079     bin_index_t phiMaskApply(bin_index_t in) const { return in & m_ax_phi.c_N_mask; }
0080 
0081     binnor_t::C_pair phiQBinContent(bin_index_t pi, bin_index_t qi) const { return m_binnor.get_content(pi, qi); }
0082 
0083     bool isBinDead(bin_index_t pi, bin_index_t qi) const { return m_dead_bins[qi * m_ax_phi.size_of_N() + pi]; }
0084 
0085     struct HitInfo {
0086       float phi;
0087       float q;
0088       float q_half_length;
0089       float qbar;
0090     };
0091     const HitInfo& hit_info(unsigned int i) const { return m_hit_infos[i]; }
0092     float hit_phi(unsigned int i) const { return m_hit_infos[i].phi; }
0093     float hit_q(unsigned int i) const { return m_hit_infos[i].q; }
0094     float hit_q_half_length(unsigned int i) const { return m_hit_infos[i].q_half_length; }
0095     float hit_qbar(unsigned int i) const { return m_hit_infos[i].qbar; }
0096 
0097     // Use this to map original indices to sorted internal ones. m_ext_idcs needs to be initialized.
0098     unsigned int getHitIndexFromOriginal(unsigned int i) const { return m_ext_idcs[i - m_min_ext_idx]; }
0099     // Use this to remap internal hit index to external one.
0100     unsigned int getOriginalHitIndex(unsigned int i) const { return m_binnor.m_ranks[i]; }
0101 
0102 #ifdef COPY_SORTED_HITS
0103     const Hit& refHit(int i) const { return m_hits[i]; }
0104     const Hit* hitArray() const { return m_hits; }
0105 #else
0106     const Hit& refHit(int i) const { return (*m_ext_hits)[i]; }
0107     const Hit* hitArray() const { return m_ext_hits->data(); }
0108 #endif
0109 
0110     void printBins();
0111 
0112     // Geometry / LayerInfo accessors
0113     //--------------------------------
0114 
0115     const LayerInfo* layer_info() const { return m_layer_info; }
0116     int layer_id() const { return m_layer_info->layer_id(); }
0117 
0118     bool is_barrel() const { return m_is_barrel; }
0119     bool is_endcap() const { return !m_is_barrel; }
0120 
0121     bool is_within_z_limits(float z) const { return m_layer_info->is_within_z_limits(z); }
0122     bool is_within_r_limits(float r) const { return m_layer_info->is_within_r_limits(r); }
0123 
0124     WSR_Result is_within_z_sensitive_region(float z, float dz) const {
0125       return m_layer_info->is_within_z_sensitive_region(z, dz);
0126     }
0127 
0128     WSR_Result is_within_r_sensitive_region(float r, float dr) const {
0129       return m_layer_info->is_within_r_sensitive_region(r, dr);
0130     }
0131 
0132     bool is_stereo() const { return m_layer_info->is_stereo(); }
0133     bool is_pixel() const { return m_layer_info->is_pixel(); }
0134     int subdet() const { return m_layer_info->subdet(); }
0135 
0136   private:
0137     axis_phi_t m_ax_phi;
0138     axis_eta_t m_ax_eta;
0139     binnor_t m_binnor;
0140 
0141 #ifdef COPY_SORTED_HITS
0142     void alloc_hits(int size);
0143     void free_hits()
0144 
0145         Hit* m_hits = nullptr;
0146     int m_capacity = 0;
0147 #else
0148     const HitVec* m_ext_hits;
0149 #endif
0150     unsigned int* m_hit_ranks = nullptr;  // allocated by IceSort via new []
0151     std::vector<unsigned int> m_ext_idcs;
0152     unsigned int m_min_ext_idx, m_max_ext_idx;
0153     unsigned int m_n_hits = 0;
0154 
0155     // Bin information for dead regions
0156     std::vector<bool> m_dead_bins;
0157 
0158     // Geometry / q-binning constants - initialized in setupLayer()
0159     const LayerInfo* m_layer_info = nullptr;
0160     bool m_is_barrel;
0161 
0162     // Cached hit phi, q  and qbar values to minimize Hit memory access
0163     std::vector<HitInfo> m_hit_infos;
0164   };
0165 
0166   //==============================================================================
0167 
0168   class EventOfHits {
0169   public:
0170     EventOfHits(const TrackerInfo& trk_inf);
0171 
0172     void reset() {
0173       for (auto& i : m_layers_of_hits) {
0174         i.reset();
0175       }
0176     }
0177 
0178     void suckInHits(int layer, const HitVec& hitv) { m_layers_of_hits[layer].suckInHits(hitv); }
0179 
0180     void suckInDeads(int layer, const DeadVec& deadv) { m_layers_of_hits[layer].suckInDeads(deadv); }
0181 
0182     const BeamSpot& refBeamSpot() const { return m_beam_spot; }
0183     void setBeamSpot(const BeamSpot& bs) { m_beam_spot = bs; }
0184 
0185     int nLayers() const { return m_n_layers; }
0186 
0187     LayerOfHits& operator[](int i) { return m_layers_of_hits[i]; }
0188     const LayerOfHits& operator[](int i) const { return m_layers_of_hits[i]; }
0189 
0190   private:
0191     std::vector<LayerOfHits> m_layers_of_hits;
0192     int m_n_layers;
0193     BeamSpot m_beam_spot;
0194   };
0195 
0196 }  // end namespace mkfit
0197 #endif