Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-27 23:38:48

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     float hit_q(unsigned int i) const { return m_hit_qs[i]; }
0086     float hit_phi(unsigned int i) const { return m_hit_phis[i]; }
0087 
0088     // Use this to map original indices to sorted internal ones. m_ext_idcs needs to be initialized.
0089     unsigned int getHitIndexFromOriginal(unsigned int i) const { return m_ext_idcs[i - m_min_ext_idx]; }
0090     // Use this to remap internal hit index to external one.
0091     unsigned int getOriginalHitIndex(unsigned int i) const { return m_binnor.m_ranks[i]; }
0092 
0093 #ifdef COPY_SORTED_HITS
0094     const Hit& refHit(int i) const { return m_hits[i]; }
0095     const Hit* hitArray() const { return m_hits; }
0096 #else
0097     const Hit& refHit(int i) const { return (*m_ext_hits)[i]; }
0098     const Hit* hitArray() const { return m_ext_hits->data(); }
0099 #endif
0100 
0101     void printBins();
0102 
0103     // Geometry / LayerInfo accessors
0104     //--------------------------------
0105 
0106     const LayerInfo* layer_info() const { return m_layer_info; }
0107     int layer_id() const { return m_layer_info->layer_id(); }
0108 
0109     bool is_barrel() const { return m_is_barrel; }
0110     bool is_endcap() const { return !m_is_barrel; }
0111 
0112     bool is_within_z_limits(float z) const { return m_layer_info->is_within_z_limits(z); }
0113     bool is_within_r_limits(float r) const { return m_layer_info->is_within_r_limits(r); }
0114 
0115     WSR_Result is_within_z_sensitive_region(float z, float dz) const {
0116       return m_layer_info->is_within_z_sensitive_region(z, dz);
0117     }
0118 
0119     WSR_Result is_within_r_sensitive_region(float r, float dr) const {
0120       return m_layer_info->is_within_r_sensitive_region(r, dr);
0121     }
0122 
0123     bool is_stereo() const { return m_layer_info->is_stereo(); }
0124     bool is_pixel() const { return m_layer_info->is_pixel(); }
0125     int subdet() const { return m_layer_info->subdet(); }
0126 
0127   private:
0128     axis_phi_t m_ax_phi;
0129     axis_eta_t m_ax_eta;
0130     binnor_t m_binnor;
0131 
0132 #ifdef COPY_SORTED_HITS
0133     void alloc_hits(int size);
0134     void free_hits()
0135 
0136         Hit* m_hits = nullptr;
0137     int m_capacity = 0;
0138 #else
0139     const HitVec* m_ext_hits;
0140 #endif
0141     unsigned int* m_hit_ranks = nullptr;  // allocated by IceSort via new []
0142     std::vector<unsigned int> m_ext_idcs;
0143     unsigned int m_min_ext_idx, m_max_ext_idx;
0144     unsigned int m_n_hits = 0;
0145 
0146     // Bin information for dead regions
0147     std::vector<bool> m_dead_bins;
0148 
0149     // Cached hit phi and q values to minimize Hit memory access
0150     std::vector<float> m_hit_phis;
0151     std::vector<float> m_hit_qs;
0152 
0153     // Geometry / q-binning constants - initialized in setupLayer()
0154     const LayerInfo* m_layer_info = nullptr;
0155     bool m_is_barrel;
0156 
0157     // Data needed during setup
0158     struct HitInfo {
0159       float phi;
0160       float q;
0161     };
0162     std::vector<HitInfo> m_hit_infos;
0163   };
0164 
0165   //==============================================================================
0166 
0167   class EventOfHits {
0168   public:
0169     EventOfHits(const TrackerInfo& trk_inf);
0170 
0171     void reset() {
0172       for (auto& i : m_layers_of_hits) {
0173         i.reset();
0174       }
0175     }
0176 
0177     void suckInHits(int layer, const HitVec& hitv) { m_layers_of_hits[layer].suckInHits(hitv); }
0178 
0179     void suckInDeads(int layer, const DeadVec& deadv) { m_layers_of_hits[layer].suckInDeads(deadv); }
0180 
0181     const BeamSpot& refBeamSpot() const { return m_beam_spot; }
0182     void setBeamSpot(const BeamSpot& bs) { m_beam_spot = bs; }
0183 
0184     int nLayers() const { return m_n_layers; }
0185 
0186     LayerOfHits& operator[](int i) { return m_layers_of_hits[i]; }
0187     const LayerOfHits& operator[](int i) const { return m_layers_of_hits[i]; }
0188 
0189   private:
0190     std::vector<LayerOfHits> m_layers_of_hits;
0191     int m_n_layers;
0192     BeamSpot m_beam_spot;
0193   };
0194 
0195 }  // end namespace mkfit
0196 #endif