CMS 3D CMS Logo

CalibPixel.h
Go to the documentation of this file.
1 #ifndef RecoLocalTracker_SiPixelClusterizer_plugins_alpaka_CalibPixel_h
2 #define RecoLocalTracker_SiPixelClusterizer_plugins_alpaka_CalibPixel_h
3 
4 #include <algorithm>
5 #include <cstdint>
6 #include <cstdio>
7 #include <limits>
8 
9 #include <alpaka/alpaka.hpp>
10 
19 
20 //#define GPU_DEBUG
21 
22 namespace calibPixel {
23  using namespace cms::alpakatools;
24 
25  template <bool debug = false>
26  struct CalibDigis {
27  template <typename TAcc>
28  ALPAKA_FN_ACC void operator()(const TAcc& acc,
29  SiPixelClusterThresholds clusterThresholds,
31  SiPixelClustersSoAView clus_view,
33  int numElements) const {
34  const float VCaltoElectronGain = clusterThresholds.vCaltoElectronGain;
35  const float VCaltoElectronGain_L1 = clusterThresholds.vCaltoElectronGain_L1;
36  const float VCaltoElectronOffset = clusterThresholds.vCaltoElectronOffset;
37  const float VCaltoElectronOffset_L1 = clusterThresholds.vCaltoElectronOffset_L1;
38 
39  // zero for next kernels...
41  clus_view[0].clusModuleStart() = 0;
42  clus_view[0].moduleStart() = 0;
43  }
45  clus_view[i].clusInModule() = 0;
46  }
47 
49  auto dvgi = view[i];
50  if (dvgi.moduleId() == ::pixelClustering::invalidModuleId)
51  continue;
52 
53  bool isDeadColumn = false, isNoisyColumn = false;
54  int row = dvgi.xx();
55  int col = dvgi.yy();
56  auto ret = SiPixelGainUtilities::getPedAndGain(gains, dvgi.moduleId(), col, row, isDeadColumn, isNoisyColumn);
57  float pedestal = ret.first;
58  float gain = ret.second;
59  if (isDeadColumn | isNoisyColumn) {
60  if constexpr (debug)
61  printf("bad pixel at %d in %d\n", i, dvgi.moduleId());
62  dvgi.moduleId() = ::pixelClustering::invalidModuleId;
63  dvgi.adc() = 0;
64  } else {
65  float vcal = dvgi.adc() * gain - pedestal * gain;
66 
67  float conversionFactor = dvgi.moduleId() < 96 ? VCaltoElectronGain_L1 : VCaltoElectronGain;
68  float offset = dvgi.moduleId() < 96 ? VCaltoElectronOffset_L1 : VCaltoElectronOffset;
69 #ifdef GPU_DEBUG
70  auto old_adc = dvgi.adc();
71 #endif
72  dvgi.adc() = std::max(100, int(vcal * conversionFactor + offset));
73 #ifdef GPU_DEBUG
75  printf(
76  "module %d pixel %d -> old_adc = %d; vcal = %.2f; conversionFactor = %.2f; offset = %.2f; new_adc = "
77  "%d \n",
78  dvgi.moduleId(),
79  i,
80  old_adc,
81  vcal,
82  conversionFactor,
83  offset,
84  dvgi.adc());
85  }
86 #endif
87  }
88  }
89  }
90  };
91 
93  template <typename TAcc>
94  ALPAKA_FN_ACC void operator()(const TAcc& acc,
95  SiPixelClusterThresholds clusterThresholds,
97  SiPixelClustersSoAView clus_view,
98  int numElements) const {
99  const float ElectronPerADCGain = clusterThresholds.electronPerADCGain;
100  const int8_t Phase2ReadoutMode = clusterThresholds.phase2ReadoutMode;
101  const uint16_t Phase2DigiBaseline = clusterThresholds.phase2DigiBaseline;
102  const uint8_t Phase2KinkADC = clusterThresholds.phase2KinkADC;
103 
104  // zero for next kernels...
106  clus_view[0].clusModuleStart() = clus_view[0].moduleStart() = 0;
107  }
108 
110  clus_view[i].clusInModule() = 0;
111  }
112 
113  for (uint32_t i : cms::alpakatools::uniform_elements(acc, numElements)) {
114  auto dvgi = view[i];
115  if (pixelClustering::invalidModuleId != dvgi.moduleId()) {
116  const int mode = (Phase2ReadoutMode < -1 ? -1 : Phase2ReadoutMode);
117  int adc_int = dvgi.adc();
118  if (mode < 0)
119  adc_int = int(adc_int * ElectronPerADCGain);
120  else {
121  if (adc_int < Phase2KinkADC)
122  adc_int = int((adc_int + 0.5) * ElectronPerADCGain);
123  else {
124  const int8_t dspp = (Phase2ReadoutMode < 10 ? Phase2ReadoutMode : 10);
125  const int8_t ds = int8_t(dspp <= 1 ? 1 : (dspp - 1) * (dspp - 1));
126  adc_int -= Phase2KinkADC;
127  adc_int *= ds;
128  adc_int += Phase2KinkADC;
129  adc_int = ((adc_int + 0.5 * ds) * ElectronPerADCGain);
130  }
131  adc_int += int(Phase2DigiBaseline);
132  }
133  dvgi.adc() = std::min(adc_int, int(std::numeric_limits<uint16_t>::max()));
134  }
135  }
136  }
137  };
138 } // namespace calibPixel
139 
140 #endif // RecoLocalTracker_SiPixelClusterizer_plugins_alpaka_CalibPixel_h
ALPAKA_FN_ACC auto uniform_elements(TAcc const &acc, TArgs... args)
Definition: workdivision.h:303
ALPAKA_FN_ACC void operator()(const TAcc &acc, SiPixelClusterThresholds clusterThresholds, SiPixelDigisSoAView view, SiPixelClustersSoAView clus_view, int numElements) const
Definition: CalibPixel.h:94
ret
prodAgent to be discontinued
constexpr uint16_t numberOfModules
ALPAKA_FN_ACC void operator()(const TAcc &acc, SiPixelClusterThresholds clusterThresholds, SiPixelDigisSoAView view, SiPixelClustersSoAView clus_view, const SiPixelGainCalibrationForHLTSoAConstView gains, int numElements) const
Definition: CalibPixel.h:28
constexpr uint16_t invalidModuleId
constexpr float gains[NGAINS]
Definition: EcalConstants.h:20
uint16_t *__restrict__ uint16_t const *__restrict__ uint32_t const *__restrict__ uint32_t *__restrict__ uint32_t const *__restrict__ int32_t *__restrict__ uint32_t numElements
#define debug
Definition: HDRShower.cc:19
ALPAKA_FN_ACC constexpr bool once_per_grid(TAcc const &acc)
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC static ALPAKA_FN_INLINE std::pair< float, float > getPedAndGain(const SiPixelGainCalibrationForHLTSoAConstView &view, uint32_t moduleInd, int col, int row, bool &isDeadColumn, bool &isNoisyColumn)
col
Definition: cuy.py:1009
constexpr uint16_t numberOfModules
constexpr uint16_t invalidModuleId