Skip to content

Commit d403d7a

Browse files
authored
Merge pull request #40 from YonsiG/CMSSW_14_1_0_pre3_LST_X_LSTCore_realfiles_TrackLooperPR410
LST object build upgrade: change pT5 rz chi2 cut definition into helix approximation
2 parents 125f21c + 5b2fe32 commit d403d7a

File tree

2 files changed

+138
-72
lines changed

2 files changed

+138
-72
lines changed

RecoTracker/LSTCore/src/alpaka/PixelTriplet.h

Lines changed: 137 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,7 @@ namespace SDL {
755755
float z1 = zPix[1] / 100;
756756
float r1 = rtPix[1] / 100;
757757

758-
float Bz = SDL::magnetic_field;
759-
float a = -0.299792 * Bz * charge;
758+
float a = -100 / SDL::kR1GeVf * charge;
760759

761760
for (size_t i = 0; i < 3; i++) {
762761
float zsi = zs[i] / 100;
@@ -776,6 +775,7 @@ namespace SDL {
776775
float x = x1 + Px / a * alpaka::math::sin(acc, rou * s) - Py / a * (1 - alpaka::math::cos(acc, rou * s));
777776
float y = y1 + Py / a * alpaka::math::sin(acc, rou * s) + Px / a * (1 - alpaka::math::cos(acc, rou * s));
778777
diffr = alpaka::math::abs(acc, rtsi - alpaka::math::sqrt(acc, x * x + y * y)) * 100;
778+
residual = diffr;
779779
}
780780

781781
if (moduleSubdet == SDL::Barrel) {
@@ -792,10 +792,9 @@ namespace SDL {
792792
float diffz1 = alpaka::math::abs(acc, solz1 - zsi) * 100;
793793
float diffz2 = alpaka::math::abs(acc, solz2 - zsi) * 100;
794794
diffz = alpaka::math::min(acc, diffz1, diffz2);
795+
residual = diffz;
795796
}
796797

797-
residual = moduleSubdet == SDL::Barrel ? diffz : diffr;
798-
799798
//PS Modules
800799
if (moduleType == 0) {
801800
error = 0.15f;
@@ -2053,63 +2052,61 @@ namespace SDL {
20532052
5 * (modulesInGPU.subdets[lowerModuleIndex5] == SDL::Endcap and
20542053
modulesInGPU.moduleType[lowerModuleIndex5] == SDL::TwoS);
20552054

2055+
// This slides shows the cut threshold definition. The comments below in the code, e.g, "cat 10", is consistent with the region separation in the slides
2056+
// https://indico.cern.ch/event/1410985/contributions/5931017/attachments/2875400/5035406/helix%20approxi%20for%20pT5%20rzchi2%20new%20results%20versions.pdf
20562057
if (layer1 == 1 and layer2 == 2 and layer3 == 3) {
2057-
if (layer4 == 12 and layer5 == 13) {
2058-
return rzChiSquared < 451.141f;
2059-
} else if (layer4 == 4 and layer5 == 12) {
2060-
return rzChiSquared < 392.654f;
2061-
} else if (layer4 == 4 and layer5 == 5) {
2062-
return rzChiSquared < 225.322f;
2063-
} else if (layer4 == 7 and layer5 == 13) {
2064-
return rzChiSquared < 595.546f;
2065-
} else if (layer4 == 7 and layer5 == 8) {
2066-
return rzChiSquared < 196.111f;
2058+
if (layer4 == 12 and layer5 == 13) { // cat 10
2059+
return rzChiSquared < 14.031f;
2060+
} else if (layer4 == 4 and layer5 == 12) { // cat 12
2061+
return rzChiSquared < 8.760f;
2062+
} else if (layer4 == 4 and layer5 == 5) { // cat 11
2063+
return rzChiSquared < 3.607f;
2064+
} else if (layer4 == 7 and layer5 == 13) { // cat 9
2065+
return rzChiSquared < 16.620;
2066+
} else if (layer4 == 7 and layer5 == 8) { // cat 8
2067+
return rzChiSquared < 17.910f;
20672068
}
20682069
} else if (layer1 == 1 and layer2 == 2 and layer3 == 7) {
2069-
if (layer4 == 13 and layer5 == 14) {
2070-
return rzChiSquared < 297.446f;
2071-
} else if (layer4 == 8 and layer5 == 14) {
2072-
return rzChiSquared < 451.141f;
2073-
} else if (layer4 == 8 and layer5 == 9) {
2074-
return rzChiSquared < 518.339f;
2070+
if (layer4 == 13 and layer5 == 14) { // cat 7
2071+
return rzChiSquared < 8.950f;
2072+
} else if (layer4 == 8 and layer5 == 14) { // cat 6
2073+
return rzChiSquared < 14.837f;
2074+
} else if (layer4 == 8 and layer5 == 9) { // cat 5
2075+
return rzChiSquared < 18.519f;
20752076
}
20762077
} else if (layer1 == 1 and layer2 == 7 and layer3 == 8) {
2077-
if (layer4 == 9 and layer5 == 10) {
2078-
return rzChiSquared < 341.75f;
2079-
} else if (layer4 == 9 and layer5 == 15) {
2080-
return rzChiSquared < 341.75f;
2078+
if (layer4 == 9 and layer5 == 10) { // cat 3
2079+
return rzChiSquared < 15.093f;
2080+
} else if (layer4 == 9 and layer5 == 15) { // cat 4
2081+
return rzChiSquared < 11.200f;
20812082
}
20822083
} else if (layer1 == 2 and layer2 == 3 and layer3 == 4) {
2083-
if (layer4 == 12 and layer5 == 13) {
2084-
return rzChiSquared < 392.655f;
2085-
} else if (layer4 == 5 and layer5 == 12) {
2086-
return rzChiSquared < 341.75f;
2087-
} else if (layer4 == 5 and layer5 == 6) {
2088-
return rzChiSquared < 112.537f;
2084+
if (layer4 == 12 and layer5 == 13) { // cat 20
2085+
return rzChiSquared < 12.868f;
2086+
} else if (layer4 == 5 and layer5 == 12) { // cat 19
2087+
return rzChiSquared < 6.128f;
2088+
} else if (layer4 == 5 and layer5 == 6) { // cat 18
2089+
return rzChiSquared < 2.987f;
20892090
}
20902091
} else if (layer1 == 2 and layer2 == 3 and layer4 == 7) {
2091-
if (layer4 == 13 and layer5 == 14) {
2092-
return rzChiSquared < 595.545f;
2093-
} else if (layer4 == 8 and layer5 == 14) {
2094-
return rzChiSquared < 74.198f;
2092+
if (layer4 == 13 and layer5 == 14) { // cat 17
2093+
return rzChiSquared < 19.446f;
2094+
} else if (layer4 == 8 and layer5 == 14) { // cat 16
2095+
return rzChiSquared < 17.520f;
20952096
}
20962097
} else if (layer1 == 2 and layer2 == 7 and layer3 == 8) {
2097-
if (layer4 == 14 and layer5 == 15) {
2098-
return rzChiSquared < 518.339f;
2099-
} else if (layer4 == 9 and layer5 == 10) {
2100-
return rzChiSquared < 8.046f;
2101-
} else if (layer4 == 9 and layer5 == 15) {
2102-
return rzChiSquared < 451.141f;
2098+
if (layer4 == 14 and layer5 == 15) { // cat 15
2099+
return rzChiSquared < 14.71f;
2100+
} else if (layer4 == 9 and layer5 == 15) { // cat 14
2101+
return rzChiSquared < 18.213f;
21032102
}
2104-
} else if (layer1 == 3 and layer2 == 7 and layer3 == 8 and layer4 == 14 and layer5 == 15) {
2105-
return rzChiSquared < 56.207f;
21062103
} else if (layer1 == 7 and layer2 == 8 and layer3 == 9) {
2107-
if (layer4 == 10 and layer5 == 11) {
2108-
return rzChiSquared < 64.578f;
2109-
} else if (layer4 == 10 and layer5 == 16) {
2110-
return rzChiSquared < 85.250f;
2111-
} else if (layer4 == 15 and layer5 == 16) {
2112-
return rzChiSquared < 85.250f;
2104+
if (layer4 == 10 and layer5 == 11) { // cat 0
2105+
return rzChiSquared < 10.016f;
2106+
} else if (layer4 == 10 and layer5 == 16) { // cat 1
2107+
return rzChiSquared < 87.671f;
2108+
} else if (layer4 == 15 and layer5 == 16) { // cat 2
2109+
return rzChiSquared < 5.844f;
21132110
}
21142111
}
21152112
return true;
@@ -2534,8 +2531,11 @@ namespace SDL {
25342531
uint16_t lowerModuleIndices[5] = {
25352532
lowerModuleIndex1, lowerModuleIndex2, lowerModuleIndex3, lowerModuleIndex4, lowerModuleIndex5};
25362533

2537-
float zPix[2] = {mdsInGPU.anchorZ[pixelInnerMDIndex], mdsInGPU.anchorZ[pixelOuterMDIndex]};
25382534
float rtPix[2] = {mdsInGPU.anchorRt[pixelInnerMDIndex], mdsInGPU.anchorRt[pixelOuterMDIndex]};
2535+
float xPix[2] = {mdsInGPU.anchorX[pixelInnerMDIndex], mdsInGPU.anchorX[pixelOuterMDIndex]};
2536+
float yPix[2] = {mdsInGPU.anchorY[pixelInnerMDIndex], mdsInGPU.anchorY[pixelOuterMDIndex]};
2537+
float zPix[2] = {mdsInGPU.anchorZ[pixelInnerMDIndex], mdsInGPU.anchorZ[pixelOuterMDIndex]};
2538+
25392539
float zs[5] = {mdsInGPU.anchorZ[firstMDIndex],
25402540
mdsInGPU.anchorZ[secondMDIndex],
25412541
mdsInGPU.anchorZ[thirdMDIndex],
@@ -2547,9 +2547,32 @@ namespace SDL {
25472547
mdsInGPU.anchorRt[fourthMDIndex],
25482548
mdsInGPU.anchorRt[fifthMDIndex]};
25492549

2550-
rzChiSquared = computePT5RZChiSquared(acc, modulesInGPU, lowerModuleIndices, rtPix, zPix, rts, zs);
2550+
float pixelSegmentPt = segmentsInGPU.ptIn[pixelSegmentArrayIndex];
2551+
float pixelSegmentPx = segmentsInGPU.px[pixelSegmentArrayIndex];
2552+
float pixelSegmentPy = segmentsInGPU.py[pixelSegmentArrayIndex];
2553+
float pixelSegmentPz = segmentsInGPU.pz[pixelSegmentArrayIndex];
2554+
int pixelSegmentCharge = segmentsInGPU.charge[pixelSegmentArrayIndex];
2555+
2556+
rzChiSquared = 0;
25512557

2552-
if (/*pixelRadius*/ 0 < 5.0f * kR1GeVf) { // FIXME: pixelRadius is not defined yet
2558+
//get the appropriate centers
2559+
pixelRadius = segmentsInGPU.circleRadius[pixelSegmentArrayIndex];
2560+
2561+
if (pixelRadius < 5.0f * kR1GeVf) { //only apply r-z chi2 cuts for <5GeV tracks
2562+
rzChiSquared = computePT5RZChiSquared(acc,
2563+
modulesInGPU,
2564+
lowerModuleIndices,
2565+
rtPix,
2566+
xPix,
2567+
yPix,
2568+
zPix,
2569+
rts,
2570+
zs,
2571+
pixelSegmentPt,
2572+
pixelSegmentPx,
2573+
pixelSegmentPy,
2574+
pixelSegmentPz,
2575+
pixelSegmentCharge);
25532576
pass = pass and passPT5RZChiSquaredCuts(modulesInGPU,
25542577
lowerModuleIndex1,
25552578
lowerModuleIndex2,
@@ -2573,10 +2596,9 @@ namespace SDL {
25732596
mdsInGPU.anchorY[fourthMDIndex],
25742597
mdsInGPU.anchorY[fifthMDIndex]};
25752598

2576-
//get the appropriate radii and centers
2599+
//get the appropriate centers
25772600
centerX = segmentsInGPU.circleCenterX[pixelSegmentArrayIndex];
25782601
centerY = segmentsInGPU.circleCenterY[pixelSegmentArrayIndex];
2579-
pixelRadius = segmentsInGPU.circleRadius[pixelSegmentArrayIndex];
25802602

25812603
float T5CenterX = quintupletsInGPU.regressionG[quintupletIndex];
25822604
float T5CenterY = quintupletsInGPU.regressionF[quintupletIndex];
@@ -2593,12 +2615,11 @@ namespace SDL {
25932615
lowerModuleIndex4,
25942616
lowerModuleIndex5,
25952617
rPhiChiSquared);
2618+
25962619
if (not pass)
25972620
return pass;
25982621
}
25992622

2600-
float xPix[] = {mdsInGPU.anchorX[pixelInnerMDIndex], mdsInGPU.anchorX[pixelOuterMDIndex]};
2601-
float yPix[] = {mdsInGPU.anchorY[pixelInnerMDIndex], mdsInGPU.anchorY[pixelOuterMDIndex]};
26022623
rPhiChiSquaredInwards =
26032624
computePT5RPhiChiSquaredInwards(modulesInGPU, T5CenterX, T5CenterY, quintupletRadius, xPix, yPix);
26042625

@@ -2623,29 +2644,71 @@ namespace SDL {
26232644

26242645
template <typename TAcc>
26252646
ALPAKA_FN_ACC ALPAKA_FN_INLINE float computePT5RZChiSquared(TAcc const& acc,
2626-
struct SDL::modules& modulesInGPU,
2627-
uint16_t* lowerModuleIndices,
2628-
float* rtPix,
2629-
float* zPix,
2630-
float* rts,
2631-
float* zs) {
2632-
//use the two anchor hits of the pixel segment to compute the slope
2633-
//then compute the pseudo chi squared of the five outer hits
2634-
2635-
float slope = (zPix[1] - zPix[0]) / (rtPix[1] - rtPix[0]);
2647+
struct SDL::modules const& modulesInGPU,
2648+
const uint16_t* lowerModuleIndices,
2649+
const float* rtPix,
2650+
const float* xPix,
2651+
const float* yPix,
2652+
const float* zPix,
2653+
const float* rts,
2654+
const float* zs,
2655+
float pixelSegmentPt,
2656+
float pixelSegmentPx,
2657+
float pixelSegmentPy,
2658+
float pixelSegmentPz,
2659+
int pixelSegmentCharge) {
26362660
float residual = 0;
26372661
float error = 0;
2638-
//hardcoded array indices!!!
26392662
float RMSE = 0;
2663+
2664+
// the pixel positions are in unit of cm, and need to be divided by 100 to be in consistent with unit mm.
2665+
float Px = pixelSegmentPx, Py = pixelSegmentPy, Pz = pixelSegmentPz;
2666+
int charge = pixelSegmentCharge;
2667+
float x1 = xPix[1] / 100;
2668+
float y1 = yPix[1] / 100;
2669+
float z1 = zPix[1] / 100;
2670+
float r1 = rtPix[1] / 100;
2671+
2672+
float a = -100 / SDL::kR1GeVf * charge;
2673+
26402674
for (size_t i = 0; i < 5; i++) {
2641-
uint16_t& lowerModuleIndex = lowerModuleIndices[i];
2675+
float zsi = zs[i] / 100;
2676+
float rtsi = rts[i] / 100;
2677+
uint16_t lowerModuleIndex = lowerModuleIndices[i];
26422678
const int moduleType = modulesInGPU.moduleType[lowerModuleIndex];
26432679
const int moduleSide = modulesInGPU.sides[lowerModuleIndex];
26442680
const int moduleSubdet = modulesInGPU.subdets[lowerModuleIndex];
26452681

2646-
residual = (moduleSubdet == SDL::Barrel) ? (zs[i] - zPix[0]) - slope * (rts[i] - rtPix[0])
2647-
: (rts[i] - rtPix[0]) - (zs[i] - zPix[0]) / slope;
2648-
const float& drdz = modulesInGPU.drdzs[lowerModuleIndex];
2682+
// calculation is detailed documented here https://indico.cern.ch/event/1185895/contributions/4982756/attachments/2526561/4345805/helix%20pT3%20summarize.pdf
2683+
float diffr, diffz;
2684+
float p = alpaka::math::sqrt(acc, Px * Px + Py * Py + Pz * Pz);
2685+
2686+
float rou = a / p;
2687+
if (moduleSubdet == SDL::Endcap) {
2688+
float s = (zsi - z1) * p / Pz;
2689+
float x = x1 + Px / a * alpaka::math::sin(acc, rou * s) - Py / a * (1 - alpaka::math::cos(acc, rou * s));
2690+
float y = y1 + Py / a * alpaka::math::sin(acc, rou * s) + Px / a * (1 - alpaka::math::cos(acc, rou * s));
2691+
diffr = alpaka::math::abs(acc, rtsi - alpaka::math::sqrt(acc, x * x + y * y)) * 100;
2692+
}
2693+
2694+
if (moduleSubdet == SDL::Barrel) {
2695+
float paraA = r1 * r1 + 2 * (Px * Px + Py * Py) / (a * a) + 2 * (y1 * Px - x1 * Py) / a - rtsi * rtsi;
2696+
float paraB = 2 * (x1 * Px + y1 * Py) / a;
2697+
float paraC = 2 * (y1 * Px - x1 * Py) / a + 2 * (Px * Px + Py * Py) / (a * a);
2698+
float A = paraB * paraB + paraC * paraC;
2699+
float B = 2 * paraA * paraB;
2700+
float C = paraA * paraA - paraC * paraC;
2701+
float sol1 = (-B + alpaka::math::sqrt(acc, B * B - 4 * A * C)) / (2 * A);
2702+
float sol2 = (-B - alpaka::math::sqrt(acc, B * B - 4 * A * C)) / (2 * A);
2703+
float solz1 = alpaka::math::asin(acc, sol1) / rou * Pz / p + z1;
2704+
float solz2 = alpaka::math::asin(acc, sol2) / rou * Pz / p + z1;
2705+
float diffz1 = alpaka::math::abs(acc, solz1 - zsi) * 100;
2706+
float diffz2 = alpaka::math::abs(acc, solz2 - zsi) * 100;
2707+
diffz = alpaka::math::min(acc, diffz1, diffz2);
2708+
}
2709+
2710+
residual = moduleSubdet == SDL::Barrel ? diffz : diffr;
2711+
26492712
//PS Modules
26502713
if (moduleType == 0) {
26512714
error = 0.15f;
@@ -2656,12 +2719,14 @@ namespace SDL {
26562719

26572720
//special dispensation to tilted PS modules!
26582721
if (moduleType == 0 and moduleSubdet == SDL::Barrel and moduleSide != Center) {
2659-
error /= alpaka::math::sqrt(acc, 1.f + drdz * drdz);
2722+
float drdz = modulesInGPU.drdzs[lowerModuleIndex];
2723+
error /= alpaka::math::sqrt(acc, 1 + drdz * drdz);
26602724
}
26612725
RMSE += (residual * residual) / (error * error);
26622726
}
26632727

2664-
RMSE = alpaka::math::sqrt(acc, 0.2f * RMSE);
2728+
RMSE = alpaka::math::sqrt(acc, 0.2f * RMSE); //Divided by the degree of freedom 5.
2729+
26652730
return RMSE;
26662731
};
26672732

RecoTracker/LSTCore/standalone/code/core/write_sdl_ntuple.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ void setPixelQuintupletOutputBranches(SDL::Event<SDL::Acc>* event) {
404404
ana.tx->pushbackToBranch<float>("pT5_phi", phi);
405405
ana.tx->pushbackToBranch<int>("pT5_layer_binary", layer_binary);
406406
ana.tx->pushbackToBranch<int>("pT5_moduleType_binary", moduleType_binary);
407+
ana.tx->pushbackToBranch<float>("pT5_rzChiSquared", pixelQuintupletsInGPU.rzChiSquared[pT5]);
407408

408409
pT5_matched_simIdx.push_back(simidx);
409410

0 commit comments

Comments
 (0)