1 #include <cuda_runtime.h> 22 template <
typename TrackerTraits>
35 <<
"ERROR: GenErrors not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version " 36 << (*genErrorDBObject_).version();
49 template <
typename TrackerTraits>
51 cudaStream_t cudaStream)
const {
56 const auto&
data = gpuData_.dataForCurrentDeviceAsync(cudaStream, [
this](
GPUData&
data, cudaStream_t
stream) {
66 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_commonParams,
67 &this->commonParamsGPU_,
71 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_averageGeometry,
72 &this->averageGeometry_,
76 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_layerGeometry,
77 &this->layerGeometry_,
81 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_detParams,
82 this->detParamsGPU_.data(),
87 return data.paramsOnGPU_d;
90 template <
typename TrackerTraits>
97 commonParamsGPU_.theThicknessB = m_DetParams.front().theThickness;
98 commonParamsGPU_.theThicknessE = m_DetParams.back().theThickness;
99 commonParamsGPU_.thePitchX = m_DetParams[0].thePitchX;
100 commonParamsGPU_.thePitchY = m_DetParams[0].thePitchY;
102 commonParamsGPU_.numberOfLaddersInBarrel = TrackerTraits::numberOfLaddersInBarrel;
104 LogDebug(
"PixelCPEFast") <<
"pitch & thickness " << commonParamsGPU_.thePitchX <<
' ' << commonParamsGPU_.thePitchY
105 <<
" " << commonParamsGPU_.theThicknessB <<
' ' << commonParamsGPU_.theThicknessE;
110 uint32_t oldLayer = 0;
111 uint32_t oldLadder = 0;
114 float miz = 500, mxz = 0;
117 detParamsGPU_.resize(m_DetParams.size());
119 for (
auto i = 0
U;
i < m_DetParams.size(); ++
i) {
120 auto&
p = m_DetParams[
i];
121 auto&
g = detParamsGPU_[
i];
123 g.nRowsRoc =
p.theDet->specificTopology().rowsperroc();
124 g.nColsRoc =
p.theDet->specificTopology().colsperroc();
125 g.nRows =
p.theDet->specificTopology().rocsX() *
g.nRowsRoc;
126 g.nCols =
p.theDet->specificTopology().rocsY() *
g.nColsRoc;
128 g.numPixsInModule =
g.nRows *
g.nCols;
131 assert(commonParamsGPU_.thePitchY ==
p.thePitchY);
132 assert(commonParamsGPU_.thePitchX ==
p.thePitchX);
135 g.isPosZ =
p.theDet->surface().position().z() > 0;
136 g.layer = ttopo_.layer(
p.theDet->geographicalId());
138 g.rawId =
p.theDet->geographicalId();
139 auto thickness =
g.isBarrel ? commonParamsGPU_.theThicknessB : commonParamsGPU_.theThicknessE;
142 auto ladder = ttopo_.pxbLadder(
p.theDet->geographicalId());
143 if (oldLayer !=
g.layer) {
145 LogDebug(
"PixelCPEFast") <<
"new layer at " <<
i << (
g.isBarrel ?
" B " : (
g.isPosZ ?
" E+ " :
" E- "))
146 <<
g.layer <<
" starting at " <<
g.rawId <<
'\n' 147 <<
"old layer had " << nl <<
" ladders";
150 if (oldLadder !=
ladder) {
152 LogDebug(
"PixelCPEFast") <<
"new ladder at " <<
i << (
g.isBarrel ?
" B " : (
g.isPosZ ?
" E+ " :
" E- "))
153 <<
ladder <<
" starting at " <<
g.rawId <<
'\n' 154 <<
"old ladder ave z,r,p mz " << zl / 8.f <<
" " << rl / 8.f <<
" " << pl / 8.f <<
' ' 155 << miz <<
' ' << mxz;
164 g.shiftX = 0.5f *
p.lorentzShiftInCmX;
165 g.shiftY = 0.5f *
p.lorentzShiftInCmY;
166 g.chargeWidthX =
p.lorentzShiftInCmX *
p.widthLAFractionX;
167 g.chargeWidthY =
p.lorentzShiftInCmY *
p.widthLAFractionY;
169 g.x0 =
p.theOrigin.x();
170 g.y0 =
p.theOrigin.y();
171 g.z0 =
p.theOrigin.z();
173 auto vv =
p.theDet->surface().position();
186 cp.with_track_angle =
false;
188 auto lape =
p.theDet->localAlignmentError();
195 auto toMicron = [&](
float x) {
return std::min(511,
int(
x * 1.e4f + 0.5
f)); };
198 auto gvx =
p.theOrigin.x() + 40.f * commonParamsGPU_.thePitchX;
199 auto gvy =
p.theOrigin.y();
200 auto gvz = 1.f /
p.theOrigin.z();
205 cp.cotalpha = gvx * gvz;
206 cp.cotbeta = gvy * gvz;
208 errorFromTemplates(
p,
cp, 20000.);
213 for (
float qclus = 15000; qclus < 35000; qclus += 15000) {
214 errorFromTemplates(
p,
cp, qclus);
215 LogDebug(
"PixelCPEFast") <<
i <<
' ' << qclus <<
' ' <<
cp.pixmx <<
' ' <<
m *
cp.sigmax <<
' ' <<
m *
cp.sx1
216 <<
' ' <<
m *
cp.sx2 <<
' ' <<
m *
cp.sigmay <<
' ' <<
m *
cp.sy1 <<
' ' <<
m *
cp.sy2;
219 #endif // EDM_ML_DEBUG 222 g.sx2 = toMicron(
cp.sx2);
229 float moduleOffsetX = -(0.5f *
float(
g.nRows) + TrackerTraits::bigPixXCorrection);
230 auto const xoff = moduleOffsetX * commonParamsGPU_.thePitchX;
233 auto x = xoff * (1.f - (0.5f +
float(
ix)) / 8.
f);
234 auto gvx =
p.theOrigin.x() -
x;
235 auto gvy =
p.theOrigin.y();
236 auto gvz = 1.f /
p.theOrigin.z();
237 cp.cotbeta = gvy * gvz;
238 cp.cotalpha = gvx * gvz;
239 errorFromTemplates(
p,
cp, 20000.
f);
240 g.sigmax[
ix] = toMicron(
cp.sigmax);
241 g.sigmax1[
ix] = toMicron(
cp.sx1);
242 LogDebug(
"PixelCPEFast") <<
"sigmax vs x " <<
i <<
' ' <<
x <<
' ' <<
cp.cotalpha <<
' ' <<
int(
g.sigmax[
ix])
243 <<
' ' <<
int(
g.sigmax1[
ix]) <<
' ' << 10000.f *
cp.sigmay << std::endl;
248 float moduleOffsetY = 0.5f *
float(
g.nCols) + TrackerTraits::bigPixYCorrection;
249 auto const yoff = -moduleOffsetY * commonParamsGPU_.thePitchY;
252 auto y = yoff * (1.f - (0.5f +
float(
ix)) / 8.
f);
253 auto gvx =
p.theOrigin.x() + 40.f * commonParamsGPU_.thePitchY;
254 auto gvy =
p.theOrigin.y() -
y;
255 auto gvz = 1.f /
p.theOrigin.z();
256 cp.cotbeta = gvy * gvz;
257 cp.cotalpha = gvx * gvz;
258 errorFromTemplates(
p,
cp, 20000.
f);
259 LogDebug(
"PixelCPEFast") <<
"sigmay vs y " <<
i <<
' ' <<
y <<
' ' <<
cp.cotbeta <<
' ' << 10000.f *
cp.sigmay
262 #endif // EDM_ML_DEBUG 265 cp.cotalpha = gvx * gvz;
266 cp.cotbeta = gvy * gvz;
267 auto aveCB =
cp.cotbeta;
272 for (
int qclus = 1000; qclus < 200000; qclus += 1000) {
273 errorFromTemplates(
p,
cp, qclus);
274 if (
cp.qBin_ == qbin)
277 g.xfact[
k] =
cp.sigmax;
278 g.yfact[
k] =
cp.sigmay;
279 g.minCh[
k++] = qclus;
281 LogDebug(
"PixelCPEFast") <<
i <<
' ' <<
g.rawId <<
' ' <<
cp.cotalpha <<
' ' << qclus <<
' ' <<
cp.qBin_ <<
' ' 282 <<
cp.pixmx <<
' ' <<
m *
cp.sigmax <<
' ' <<
m *
cp.sx1 <<
' ' <<
m *
cp.sx2 <<
' ' 283 <<
m *
cp.sigmay <<
' ' <<
m *
cp.sy1 <<
' ' <<
m *
cp.sy2 << std::endl;
284 #endif // EDM_ML_DEBUG 291 g.xfact[
kk] =
g.xfact[
k - 1];
292 g.yfact[
kk] =
g.yfact[
k - 1];
293 g.minCh[
kk] =
g.minCh[
k - 1];
295 auto detx = 1.f /
g.xfact[0];
296 auto dety = 1.f /
g.yfact[0];
302 float ys = 8.f - 4.f;
310 cp.cotbeta = std::copysign(ys * (commonParamsGPU_.thePitchY / (8.f *
thickness)), aveCB);
311 errorFromTemplates(
p,
cp, 20000.
f);
312 g.sigmay[
iy] = toMicron(
cp.sigmay);
313 LogDebug(
"PixelCPEFast") <<
"sigmax/sigmay " <<
i <<
' ' << (ys + 4.f) / 8.
f <<
' ' <<
cp.cotalpha <<
'/' 314 <<
cp.cotbeta <<
' ' << 10000.f *
cp.sigmax <<
'/' <<
int(
g.sigmay[
iy]) << std::endl;
318 constexpr int numberOfModulesInLadder = TrackerTraits::numberOfModulesInLadder;
319 constexpr int numberOfLaddersInBarrel = TrackerTraits::numberOfLaddersInBarrel;
320 constexpr int numberOfModulesInBarrel = TrackerTraits::numberOfModulesInBarrel;
322 constexpr float ladderFactor = 1.f /
float(numberOfModulesInLadder);
324 constexpr int firstEndcapPos = TrackerTraits::firstEndcapPos;
325 constexpr int firstEndcapNeg = TrackerTraits::firstEndcapNeg;
329 auto& aveGeom = averageGeometry_;
331 for (
int im = 0, nm = numberOfModulesInBarrel; im < nm; ++im) {
332 auto const&
g = detParamsGPU_[im];
333 il = im / numberOfModulesInLadder;
334 assert(il <
int(numberOfLaddersInBarrel));
335 auto z =
g.frame.z();
336 aveGeom.ladderZ[il] += ladderFactor *
z;
337 aveGeom.ladderMinZ[il] =
std::min(aveGeom.ladderMinZ[il],
z);
338 aveGeom.ladderMaxZ[il] =
std::max(aveGeom.ladderMaxZ[il],
z);
339 aveGeom.ladderX[il] += ladderFactor *
g.frame.x();
340 aveGeom.ladderY[il] += ladderFactor *
g.frame.y();
341 aveGeom.ladderR[il] += ladderFactor *
sqrt(
g.frame.x() *
g.frame.x() +
g.frame.y() *
g.frame.y());
343 assert(il + 1 ==
int(numberOfLaddersInBarrel));
345 constexpr float moduleLength = TrackerTraits::moduleLength;
347 for (
int il = 0, nl = numberOfLaddersInBarrel; il < nl; ++il) {
348 aveGeom.ladderMinZ[il] -= (0.5f * moduleLength - module_tolerance);
349 aveGeom.ladderMaxZ[il] += (0.5f * moduleLength - module_tolerance);
354 auto const&
g = detParamsGPU_[im];
355 aveGeom.endCapZ[0] =
std::max(aveGeom.endCapZ[0],
g.frame.z());
358 auto const&
g = detParamsGPU_[im];
359 aveGeom.endCapZ[1] =
std::min(aveGeom.endCapZ[1],
g.frame.z());
362 aveGeom.endCapZ[0] -= TrackerTraits::endcapCorrection;
363 aveGeom.endCapZ[1] += TrackerTraits::endcapCorrection;
365 for (
int jl = 0, nl = numberOfLaddersInBarrel; jl < nl; ++jl) {
366 LogDebug(
"PixelCPEFast") << jl <<
':' << aveGeom.ladderR[jl] <<
'/' 367 <<
std::sqrt(aveGeom.ladderX[jl] * aveGeom.ladderX[jl] +
368 aveGeom.ladderY[jl] * aveGeom.ladderY[jl])
369 <<
',' << aveGeom.ladderZ[jl] <<
',' << aveGeom.ladderMinZ[jl] <<
',' 370 << aveGeom.ladderMaxZ[jl] <<
'\n';
372 LogDebug(
"PixelCPEFast") << aveGeom.endCapZ[0] <<
' ' << aveGeom.endCapZ[1];
373 #endif // EDM_ML_DEBUG 377 memcpy(layerGeometry_.layerStart,
380 memcpy(layerGeometry_.layer, pixelTopology::layer<TrackerTraits>.data(), pixelTopology::layer<TrackerTraits>.size());
381 layerGeometry_.maxModuleStride = pixelTopology::maxModuleStride<TrackerTraits>;
384 template <
typename TrackerTraits>
395 template <
typename TrackerTraits>
399 float locBz = theDetParam.
bz;
400 float locBx = theDetParam.
bx;
401 LogDebug(
"PixelCPEFast") <<
"PixelCPEFast::localPosition(...) : locBz = " << locBz;
405 theClusterParam.
sigmay = -999.9;
406 theClusterParam.
sigmax = -999.9;
407 theClusterParam.
sy1 = -999.9;
408 theClusterParam.
sy2 = -999.9;
409 theClusterParam.
sx1 = -999.9;
410 theClusterParam.
sx2 = -999.9;
417 theClusterParam.
qBin_ = gtempl.
qbin(gtemplID,
424 theClusterParam.
pixmx,
452 template <
typename TrackerTraits>
460 theClusterParam.
qBin_ = 0;
486 auto xPos =
cp.xpos[0];
487 auto yPos =
cp.ypos[0];
491 theClusterParam.
sigmax =
cp.xerr[0];
492 theClusterParam.
sigmay =
cp.yerr[0];
494 LogDebug(
"PixelCPEFast") <<
" in PixelCPEFast:localPosition - pos = " << xPos <<
" " << yPos <<
" size " 495 <<
cp.maxRow[0] -
cp.minRow[0] <<
' ' <<
cp.maxCol[0] -
cp.minCol[0];
507 template <
typename TrackerTraits>
512 auto xerr = theClusterParam.
sigmax;
513 auto yerr = theClusterParam.
sigmay;
515 LogDebug(
"PixelCPEFast") <<
" errors " << xerr <<
" " << yerr;
517 auto xerr_sq = xerr * xerr;
518 auto yerr_sq = yerr * yerr;
523 template <
typename TrackerTraits>
static bool pushfile(int filenum, std::vector< SiPixelGenErrorStore > &pixelTemp, std::string dir="")
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
ParamsOnGPU * paramsOnGPU_d
const SiPixelCluster * theCluster
AverageGeometry const * m_averageGeometry
bool isBarrel(GeomDetEnumerators::SubDetector m)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
static void collect_edge_charges(ClusterParam &theClusterParam, int &q_f_X, int &q_l_X, int &q_f_Y, int &q_l_Y, bool truncate)
DetParams const * m_detParams
constexpr int kGenErrorQBins
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
const PixelGeomDetUnit * theDet
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
constexpr float micronsToCm
std::vector< SiPixelGenErrorStore > thePixelGenError_
int qbin(int id, float cotalpha, float cotbeta, float locBz, float locBx, float qclus, bool irradiationCorrections, int &pixmx, float &sigmay, float &deltay, float &sigmax, float &deltax, float &sy1, float &dy1, float &sy2, float &dy2, float &sx1, float &dx1, float &sx2, float &dx2)
PixelCPEFast(edm::ParameterSet const &conf, const MagneticField *, const TrackerGeometry &, const TrackerTopology &, const SiPixelLorentzAngle *, const SiPixelGenErrorDBObject *, const SiPixelLorentzAngle *)
The constructor.
CommonParams const * m_commonParams
std::vector< pixelCPEforGPU::DetParams > detParamsGPU_
LayerGeometry const * m_layerGeometry
bool useErrorsFromTemplates_
const bool truncatePixelCharge_
Abs< T >::type abs(const T &t)
LayerGeometry layerGeometry_
static void fillPSetDescription(edm::ParameterSetDescription &desc)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
LocalPoint localPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
SOARotation< float > Rotation
ParamsOnGPU paramsOnGPU_h
const SiPixelGenErrorDBObject * genErrorDBObject_
AverageGeometry averageGeometry_
const ParamsOnGPU * getGPUProductAsync(cudaStream_t cudaStream) const
pixelCPEforGPU::CommonParams commonParamsGPU_
char data[epos_bytes_allocation]
static constexpr uint32_t layerStart[numberOfLayers+1]
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
void errorFromTemplates(DetParam const &theDetParam, ClusterParamGeneric &theClusterParam, float qclus) const
#define cudaCheck(ARG,...)
constexpr int kNumErrorBins
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)