1 #include <cuda_runtime.h> 23 template <
typename TrackerTraits>
36 <<
"ERROR: GenErrors not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version " 37 << (*genErrorDBObject_).version();
50 template <
typename TrackerTraits>
52 cudaStream_t cudaStream)
const {
57 const auto&
data = gpuData_.dataForCurrentDeviceAsync(cudaStream, [
this](
GPUData&
data, cudaStream_t
stream) {
67 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_commonParams,
68 &this->commonParamsGPU_,
72 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_averageGeometry,
73 &this->averageGeometry_,
77 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_layerGeometry,
78 &this->layerGeometry_,
82 cudaCheck(cudaMemcpyAsync((
void*)
data.paramsOnGPU_h.m_detParams,
83 this->detParamsGPU_.data(),
88 return data.paramsOnGPU_d;
91 template <
typename TrackerTraits>
98 commonParamsGPU_.theThicknessB = m_DetParams.front().theThickness;
99 commonParamsGPU_.theThicknessE = m_DetParams.back().theThickness;
100 commonParamsGPU_.thePitchX = m_DetParams[0].thePitchX;
101 commonParamsGPU_.thePitchY = m_DetParams[0].thePitchY;
103 commonParamsGPU_.numberOfLaddersInBarrel = TrackerTraits::numberOfLaddersInBarrel;
105 LogDebug(
"PixelCPEFast") <<
"pitch & thickness " << commonParamsGPU_.thePitchX <<
' ' << commonParamsGPU_.thePitchY
106 <<
" " << commonParamsGPU_.theThicknessB <<
' ' << commonParamsGPU_.theThicknessE;
111 uint32_t oldLayer = 0;
112 uint32_t oldLadder = 0;
115 float miz = 500, mxz = 0;
118 detParamsGPU_.resize(m_DetParams.size());
120 for (
auto i = 0
U;
i < m_DetParams.size(); ++
i) {
121 auto&
p = m_DetParams[
i];
122 auto&
g = detParamsGPU_[
i];
124 g.nRowsRoc =
p.theDet->specificTopology().rowsperroc();
125 g.nColsRoc =
p.theDet->specificTopology().colsperroc();
126 g.nRows =
p.theDet->specificTopology().rocsX() *
g.nRowsRoc;
127 g.nCols =
p.theDet->specificTopology().rocsY() *
g.nColsRoc;
129 g.numPixsInModule =
g.nRows *
g.nCols;
132 assert(commonParamsGPU_.thePitchY ==
p.thePitchY);
133 assert(commonParamsGPU_.thePitchX ==
p.thePitchX);
136 g.isPosZ =
p.theDet->surface().position().z() > 0;
137 g.layer = ttopo_.layer(
p.theDet->geographicalId());
139 g.rawId =
p.theDet->geographicalId();
140 auto thickness =
g.isBarrel ? commonParamsGPU_.theThicknessB : commonParamsGPU_.theThicknessE;
143 auto ladder = ttopo_.pxbLadder(
p.theDet->geographicalId());
144 if (oldLayer !=
g.layer) {
146 LogDebug(
"PixelCPEFast") <<
"new layer at " <<
i << (
g.isBarrel ?
" B " : (
g.isPosZ ?
" E+ " :
" E- "))
147 <<
g.layer <<
" starting at " <<
g.rawId <<
'\n' 148 <<
"old layer had " << nl <<
" ladders";
151 if (oldLadder !=
ladder) {
153 LogDebug(
"PixelCPEFast") <<
"new ladder at " <<
i << (
g.isBarrel ?
" B " : (
g.isPosZ ?
" E+ " :
" E- "))
154 <<
ladder <<
" starting at " <<
g.rawId <<
'\n' 155 <<
"old ladder ave z,r,p mz " << zl / 8.f <<
" " << rl / 8.f <<
" " << pl / 8.f <<
' ' 156 << miz <<
' ' << mxz;
165 g.shiftX = 0.5f *
p.lorentzShiftInCmX;
166 g.shiftY = 0.5f *
p.lorentzShiftInCmY;
167 g.chargeWidthX =
p.lorentzShiftInCmX *
p.widthLAFractionX;
168 g.chargeWidthY =
p.lorentzShiftInCmY *
p.widthLAFractionY;
170 g.x0 =
p.theOrigin.x();
171 g.y0 =
p.theOrigin.y();
172 g.z0 =
p.theOrigin.z();
174 auto vv =
p.theDet->surface().position();
187 cp.with_track_angle =
false;
189 auto lape =
p.theDet->localAlignmentError();
196 auto toMicron = [&](
float x) {
return std::min(511,
int(
x * 1.e4f + 0.5
f)); };
199 auto gvx =
p.theOrigin.x() + 40.f * commonParamsGPU_.thePitchX;
200 auto gvy =
p.theOrigin.y();
201 auto gvz = 1.f /
p.theOrigin.z();
206 cp.cotalpha = gvx * gvz;
207 cp.cotbeta = gvy * gvz;
209 errorFromTemplates(
p,
cp, 20000.);
214 for (
float qclus = 15000; qclus < 35000; qclus += 15000) {
215 errorFromTemplates(
p,
cp, qclus);
216 LogDebug(
"PixelCPEFast") <<
i <<
' ' << qclus <<
' ' <<
cp.pixmx <<
' ' <<
m *
cp.sigmax <<
' ' <<
m *
cp.sx1
217 <<
' ' <<
m *
cp.sx2 <<
' ' <<
m *
cp.sigmay <<
' ' <<
m *
cp.sy1 <<
' ' <<
m *
cp.sy2;
220 #endif // EDM_ML_DEBUG 223 g.sx2 = toMicron(
cp.sx2);
230 float moduleOffsetX = -(0.5f *
float(
g.nRows) + TrackerTraits::bigPixXCorrection);
231 auto const xoff = moduleOffsetX * commonParamsGPU_.thePitchX;
234 auto x = xoff * (1.f - (0.5f +
float(
ix)) / 8.
f);
235 auto gvx =
p.theOrigin.x() -
x;
236 auto gvy =
p.theOrigin.y();
237 auto gvz = 1.f /
p.theOrigin.z();
238 cp.cotbeta = gvy * gvz;
239 cp.cotalpha = gvx * gvz;
240 errorFromTemplates(
p,
cp, 20000.
f);
241 g.sigmax[
ix] = toMicron(
cp.sigmax);
242 g.sigmax1[
ix] = toMicron(
cp.sx1);
243 LogDebug(
"PixelCPEFast") <<
"sigmax vs x " <<
i <<
' ' <<
x <<
' ' <<
cp.cotalpha <<
' ' <<
int(
g.sigmax[
ix])
244 <<
' ' <<
int(
g.sigmax1[
ix]) <<
' ' << 10000.f *
cp.sigmay << std::endl;
249 float moduleOffsetY = 0.5f *
float(
g.nCols) + TrackerTraits::bigPixYCorrection;
250 auto const yoff = -moduleOffsetY * commonParamsGPU_.thePitchY;
253 auto y = yoff * (1.f - (0.5f +
float(
ix)) / 8.
f);
254 auto gvx =
p.theOrigin.x() + 40.f * commonParamsGPU_.thePitchY;
255 auto gvy =
p.theOrigin.y() -
y;
256 auto gvz = 1.f /
p.theOrigin.z();
257 cp.cotbeta = gvy * gvz;
258 cp.cotalpha = gvx * gvz;
259 errorFromTemplates(
p,
cp, 20000.
f);
260 LogDebug(
"PixelCPEFast") <<
"sigmay vs y " <<
i <<
' ' <<
y <<
' ' <<
cp.cotbeta <<
' ' << 10000.f *
cp.sigmay
263 #endif // EDM_ML_DEBUG 266 cp.cotalpha = gvx * gvz;
267 cp.cotbeta = gvy * gvz;
268 auto aveCB =
cp.cotbeta;
273 for (
int qclus = 1000; qclus < 200000; qclus += 1000) {
274 errorFromTemplates(
p,
cp, qclus);
275 if (
cp.qBin_ == qbin)
278 g.xfact[
k] =
cp.sigmax;
279 g.yfact[
k] =
cp.sigmay;
280 g.minCh[
k++] = qclus;
282 LogDebug(
"PixelCPEFast") <<
i <<
' ' <<
g.rawId <<
' ' <<
cp.cotalpha <<
' ' << qclus <<
' ' <<
cp.qBin_ <<
' ' 283 <<
cp.pixmx <<
' ' <<
m *
cp.sigmax <<
' ' <<
m *
cp.sx1 <<
' ' <<
m *
cp.sx2 <<
' ' 284 <<
m *
cp.sigmay <<
' ' <<
m *
cp.sy1 <<
' ' <<
m *
cp.sy2 << std::endl;
285 #endif // EDM_ML_DEBUG 292 g.xfact[
kk] =
g.xfact[
k - 1];
293 g.yfact[
kk] =
g.yfact[
k - 1];
294 g.minCh[
kk] =
g.minCh[
k - 1];
296 auto detx = 1.f /
g.xfact[0];
297 auto dety = 1.f /
g.yfact[0];
303 float ys = 8.f - 4.f;
311 cp.cotbeta = std::copysign(ys * (commonParamsGPU_.thePitchY / (8.f *
thickness)), aveCB);
312 errorFromTemplates(
p,
cp, 20000.
f);
313 g.sigmay[
iy] = toMicron(
cp.sigmay);
314 LogDebug(
"PixelCPEFast") <<
"sigmax/sigmay " <<
i <<
' ' << (ys + 4.f) / 8.
f <<
' ' <<
cp.cotalpha <<
'/' 315 <<
cp.cotbeta <<
' ' << 10000.f *
cp.sigmax <<
'/' <<
int(
g.sigmay[
iy]) << std::endl;
319 constexpr int numberOfModulesInLadder = TrackerTraits::numberOfModulesInLadder;
320 constexpr int numberOfLaddersInBarrel = TrackerTraits::numberOfLaddersInBarrel;
321 constexpr int numberOfModulesInBarrel = TrackerTraits::numberOfModulesInBarrel;
323 constexpr float ladderFactor = 1.f /
float(numberOfModulesInLadder);
325 constexpr int firstEndcapPos = TrackerTraits::firstEndcapPos;
326 constexpr int firstEndcapNeg = TrackerTraits::firstEndcapNeg;
330 auto& aveGeom = averageGeometry_;
332 for (
int im = 0, nm = numberOfModulesInBarrel; im < nm; ++im) {
333 auto const&
g = detParamsGPU_[im];
334 il = im / numberOfModulesInLadder;
335 assert(il <
int(numberOfLaddersInBarrel));
336 auto z =
g.frame.z();
337 aveGeom.ladderZ[il] += ladderFactor *
z;
338 aveGeom.ladderMinZ[il] =
std::min(aveGeom.ladderMinZ[il],
z);
339 aveGeom.ladderMaxZ[il] =
std::max(aveGeom.ladderMaxZ[il],
z);
340 aveGeom.ladderX[il] += ladderFactor *
g.frame.x();
341 aveGeom.ladderY[il] += ladderFactor *
g.frame.y();
342 aveGeom.ladderR[il] += ladderFactor *
sqrt(
g.frame.x() *
g.frame.x() +
g.frame.y() *
g.frame.y());
344 assert(il + 1 ==
int(numberOfLaddersInBarrel));
346 constexpr float moduleLength = TrackerTraits::moduleLength;
348 for (
int il = 0, nl = numberOfLaddersInBarrel; il < nl; ++il) {
349 aveGeom.ladderMinZ[il] -= (0.5f * moduleLength - module_tolerance);
350 aveGeom.ladderMaxZ[il] += (0.5f * moduleLength - module_tolerance);
355 auto const&
g = detParamsGPU_[im];
356 aveGeom.endCapZ[0] =
std::max(aveGeom.endCapZ[0],
g.frame.z());
359 auto const&
g = detParamsGPU_[im];
360 aveGeom.endCapZ[1] =
std::min(aveGeom.endCapZ[1],
g.frame.z());
363 aveGeom.endCapZ[0] -= TrackerTraits::endcapCorrection;
364 aveGeom.endCapZ[1] += TrackerTraits::endcapCorrection;
366 for (
int jl = 0, nl = numberOfLaddersInBarrel; jl < nl; ++jl) {
367 LogDebug(
"PixelCPEFast") << jl <<
':' << aveGeom.ladderR[jl] <<
'/' 368 <<
std::sqrt(aveGeom.ladderX[jl] * aveGeom.ladderX[jl] +
369 aveGeom.ladderY[jl] * aveGeom.ladderY[jl])
370 <<
',' << aveGeom.ladderZ[jl] <<
',' << aveGeom.ladderMinZ[jl] <<
',' 371 << aveGeom.ladderMaxZ[jl] <<
'\n';
373 LogDebug(
"PixelCPEFast") << aveGeom.endCapZ[0] <<
' ' << aveGeom.endCapZ[1];
374 #endif // EDM_ML_DEBUG 378 memcpy(layerGeometry_.layerStart,
381 memcpy(layerGeometry_.layer, pixelTopology::layer<TrackerTraits>.data(), pixelTopology::layer<TrackerTraits>.size());
382 layerGeometry_.maxModuleStride = pixelTopology::maxModuleStride<TrackerTraits>;
385 template <
typename TrackerTraits>
396 template <
typename TrackerTraits>
400 float locBz = theDetParam.
bz;
401 float locBx = theDetParam.
bx;
402 LogDebug(
"PixelCPEFast") <<
"PixelCPEFast::localPosition(...) : locBz = " << locBz;
406 theClusterParam.
sigmay = -999.9;
407 theClusterParam.
sigmax = -999.9;
408 theClusterParam.
sy1 = -999.9;
409 theClusterParam.
sy2 = -999.9;
410 theClusterParam.
sx1 = -999.9;
411 theClusterParam.
sx2 = -999.9;
418 theClusterParam.
qBin_ = gtempl.
qbin(gtemplID,
425 theClusterParam.
pixmx,
453 template <
typename TrackerTraits>
461 theClusterParam.
qBin_ = 0;
487 auto xPos =
cp.xpos[0];
488 auto yPos =
cp.ypos[0];
492 theClusterParam.
sigmax =
cp.xerr[0];
493 theClusterParam.
sigmay =
cp.yerr[0];
495 LogDebug(
"PixelCPEFast") <<
" in PixelCPEFast:localPosition - pos = " << xPos <<
" " << yPos <<
" size " 496 <<
cp.maxRow[0] -
cp.minRow[0] <<
' ' <<
cp.maxCol[0] -
cp.minCol[0];
508 template <
typename TrackerTraits>
513 auto xerr = theClusterParam.
sigmax;
514 auto yerr = theClusterParam.
sigmay;
516 LogDebug(
"PixelCPEFast") <<
" errors " << xerr <<
" " << yerr;
518 auto xerr_sq = xerr * xerr;
519 auto yerr_sq = yerr * yerr;
524 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)