CMS 3D CMS Logo

SiPixelRawToClusterKernel.h
Go to the documentation of this file.
1 #ifndef RecoLocalTracker_SiPixelClusterizer_SiPixelRawToClusterKernel_h
2 #define RecoLocalTracker_SiPixelClusterizer_SiPixelRawToClusterKernel_h
3 
4 #include <algorithm>
5 #include <optional>
6 #include <utility>
7 
10 
18 
22 
26 
27 namespace pixelDetails {
28 
32 
33  // Phase 1 geometry constants
34  constexpr uint32_t layerStartBit = 20;
35  constexpr uint32_t ladderStartBit = 12;
36  constexpr uint32_t moduleStartBit = 2;
37 
38  constexpr uint32_t panelStartBit = 10;
39  constexpr uint32_t diskStartBit = 18;
40  constexpr uint32_t bladeStartBit = 12;
41 
42  constexpr uint32_t layerMask = 0xF;
43  constexpr uint32_t ladderMask = 0xFF;
44  constexpr uint32_t moduleMask = 0x3FF;
45  constexpr uint32_t panelMask = 0x3;
46  constexpr uint32_t diskMask = 0xF;
47  constexpr uint32_t bladeMask = 0x3F;
48 
49  constexpr uint32_t LINK_bits = 6;
50  constexpr uint32_t ROC_bits = 5;
51  constexpr uint32_t DCOL_bits = 5;
52  constexpr uint32_t PXID_bits = 8;
53  constexpr uint32_t ADC_bits = 8;
54 
55  // special for layer 1
56  constexpr uint32_t LINK_bits_l1 = 6;
57  constexpr uint32_t ROC_bits_l1 = 5;
58  constexpr uint32_t COL_bits_l1 = 6;
59  constexpr uint32_t ROW_bits_l1 = 7;
60  constexpr uint32_t OMIT_ERR_bits = 1;
61 
62  constexpr uint32_t maxROCIndex = 8;
63  constexpr uint32_t numRowsInRoc = 80;
64  constexpr uint32_t numColsInRoc = 52;
65 
66  constexpr uint32_t MAX_WORD = 2000;
67 
68  constexpr uint32_t ADC_shift = 0;
73  // special for layer 1 ROC
76  constexpr uint32_t OMIT_ERR_shift = 20;
77 
78  constexpr uint32_t LINK_mask = ~(~uint32_t(0) << LINK_bits_l1);
79  constexpr uint32_t ROC_mask = ~(~uint32_t(0) << ROC_bits_l1);
80  constexpr uint32_t COL_mask = ~(~uint32_t(0) << COL_bits_l1);
81  constexpr uint32_t ROW_mask = ~(~uint32_t(0) << ROW_bits_l1);
82  constexpr uint32_t DCOL_mask = ~(~uint32_t(0) << DCOL_bits);
83  constexpr uint32_t PXID_mask = ~(~uint32_t(0) << PXID_bits);
84  constexpr uint32_t ADC_mask = ~(~uint32_t(0) << ADC_bits);
85  constexpr uint32_t ERROR_mask = ~(~uint32_t(0) << ROC_bits_l1);
86  constexpr uint32_t OMIT_ERR_mask = ~(~uint32_t(0) << OMIT_ERR_bits);
87 
88  struct DetIdGPU {
89  uint32_t rawId;
90  uint32_t rocInDet;
91  uint32_t moduleId;
92  };
93 
94  struct Pixel {
95  uint32_t row;
96  uint32_t col;
97  };
98 
99  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr pixelchannelidentifierimpl::Packing packing() {
101  }
102 
103  ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr uint32_t pack(uint32_t row,
104  uint32_t col,
105  uint32_t adc,
106  uint32_t flag = 0) {
108  adc = std::min(adc, uint32_t(thePacking.max_adc));
109 
110  return (row << thePacking.row_shift) | (col << thePacking.column_shift) | (adc << thePacking.adc_shift);
111  }
112 
113  constexpr uint32_t pixelToChannel(int row, int col) {
115  return (row << thePacking.column_width) | col;
116  }
117 
118 } // namespace pixelDetails
119 
121  namespace pixelDetails {
122 
124  public:
125  WordFedAppender(Queue& queue, uint32_t words)
126  : word_{cms::alpakatools::make_host_buffer<unsigned int[]>(queue, words)},
127  fedId_{cms::alpakatools::make_host_buffer<unsigned char[]>(queue, words)} {};
128 
129  void initializeWordFed(int fedId, unsigned int wordCounterGPU, const uint32_t* src, unsigned int length) {
130  std::memcpy(word_.data() + wordCounterGPU, src, sizeof(uint32_t) * length);
131  std::memset(fedId_.data() + wordCounterGPU / 2, fedId - 1200, length / 2);
132  }
133  auto word() const { return word_; }
134  auto fedId() const { return fedId_; }
135 
136  private:
139  };
140 
141  template <typename TrackerTraits>
143  public:
144  SiPixelRawToClusterKernel() : nModules_Clusters_h{cms::alpakatools::make_host_buffer<uint32_t[], Platform>(3u)} {}
145 
146  ~SiPixelRawToClusterKernel() = default;
147 
152 
154  const SiPixelClusterThresholds clusterThresholds,
155  const SiPixelMappingSoAConstView& cablingMap,
156  const unsigned char* modToUnp,
158  const WordFedAppender& wordFed,
159  const uint32_t wordCounter,
160  const uint32_t fedCounter,
161  bool useQualityInfo,
162  bool includeErrors,
163  bool debug);
164 
166  const SiPixelClusterThresholds clusterThresholds,
167  SiPixelDigisSoAView& digis_view,
168  const uint32_t numDigis);
169 
171  digis_d->setNModules(nModules_Clusters_h[0]);
172  return std::move(*digis_d);
173  }
174 
176  clusters_d->setNClusters(nModules_Clusters_h[1], nModules_Clusters_h[2]);
177  return std::move(*clusters_d);
178  }
179 
181 
182  auto nModules() { return nModules_Clusters_h[0]; }
183 
184  private:
185  uint32_t nDigis = 0;
186 
187  // Data to be put in the event
189  std::optional<SiPixelDigisSoACollection> digis_d;
190  std::optional<SiPixelClustersSoACollection> clusters_d;
191  std::optional<SiPixelDigiErrorsSoACollection> digiErrors_d;
192  };
193 
194  } // namespace pixelDetails
195 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
196 
197 #endif // plugin_SiPixelClusterizer_alpaka_SiPixelRawToClusterKernel_h
cms::alpakatools::host_buffer< unsigned char[]> fedId_
constexpr uint32_t bladeMask
void makePhase1ClustersAsync(Queue &queue, const SiPixelClusterThresholds clusterThresholds, const SiPixelMappingSoAConstView &cablingMap, const unsigned char *modToUnp, const SiPixelGainCalibrationForHLTSoAConstView &gains, const WordFedAppender &wordFed, const uint32_t wordCounter, const uint32_t fedCounter, bool useQualityInfo, bool includeErrors, bool debug)
constexpr uint32_t moduleStartBit
constexpr uint32_t DCOL_mask
constexpr uint32_t ERROR_mask
constexpr uint32_t ADC_bits
constexpr uint32_t ADC_mask
constexpr uint32_t LINK_bits_l1
constexpr auto MAX_LINK
constexpr uint32_t layerMask
constexpr uint32_t numRowsInRoc
constexpr uint32_t ROC_shift
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr pixelchannelidentifierimpl::Packing packing()
void makePhase2ClustersAsync(Queue &queue, const SiPixelClusterThresholds clusterThresholds, SiPixelDigisSoAView &digis_view, const uint32_t numDigis)
constexpr uint32_t DCOL_bits
ALPAKA_ACCELERATOR_NAMESPACE::Queue Queue
Definition: LSTEvent.dev.cc:14
constexpr uint32_t panelMask
constexpr uint32_t OMIT_ERR_shift
constexpr uint32_t OMIT_ERR_mask
constexpr uint32_t PXID_bits
static constexpr Packing thePacking
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelDigisHost, SiPixelDigisDevice< Device > > SiPixelDigisSoACollection
constexpr uint32_t ADC_shift
constexpr uint32_t DCOL_shift
constexpr uint32_t OMIT_ERR_bits
constexpr uint32_t pixelToChannel(int row, int col)
constexpr unsigned int MAX_ROC
SiPixelRawToClusterKernel & operator=(const SiPixelRawToClusterKernel &)=delete
constexpr uint32_t PXID_shift
constexpr uint32_t ROC_bits
constexpr uint32_t ROC_mask
constexpr uint32_t moduleMask
constexpr uint32_t maxROCIndex
constexpr auto MAX_SIZE
constexpr uint32_t diskStartBit
constexpr auto MAX_ROC
constexpr float gains[NGAINS]
Definition: EcalConstants.h:20
typename detail::buffer_type< DevHost, T >::type host_buffer
Definition: memory.h:57
constexpr uint32_t ROW_bits_l1
#define debug
Definition: HDRShower.cc:19
constexpr uint32_t panelStartBit
constexpr uint32_t LINK_bits
constexpr uint32_t layerStartBit
constexpr uint32_t COL_shift
constexpr uint32_t LINK_shift
constexpr uint32_t bladeStartBit
constexpr uint32_t MAX_WORD
col
Definition: cuy.py:1009
constexpr uint32_t ladderMask
constexpr unsigned int MAX_SIZE
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr uint32_t pack(uint32_t row, uint32_t col, uint32_t adc, uint32_t flag=0)
constexpr uint32_t COL_mask
constexpr uint32_t COL_bits_l1
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelDigiErrorsHost, SiPixelDigiErrorsDevice< Device > > SiPixelDigiErrorsSoACollection
constexpr uint32_t ROW_shift
void initializeWordFed(int fedId, unsigned int wordCounterGPU, const uint32_t *src, unsigned int length)
constexpr uint32_t numColsInRoc
constexpr uint32_t ROW_mask
constexpr uint32_t LINK_mask
constexpr uint32_t ladderStartBit
constexpr unsigned int MAX_LINK
constexpr uint32_t diskMask
def move(src, dest)
Definition: eostools.py:511
constexpr uint32_t PXID_mask
uint16_t *__restrict__ uint16_t const *__restrict__ adc
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelClustersHost, SiPixelClustersDevice< Device > > SiPixelClustersSoACollection
constexpr uint32_t ROC_bits_l1