Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-17 22:59:02

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