12 LogDebug(
"VectorHitBuilderAlgorithm") <<
"Run VectorHitBuilderAlgorithm ... \n";
13 const auto* clustersPhase2Collection =
clusters.product();
16 LogDebug(
"VectorHitBuilderAlgorithm") <<
"with #clusters : " << clustersPhase2Collection->size() << std::endl;
17 for (
auto dSViter : *clustersPhase2Collection) {
18 unsigned int rawDetId1(dSViter.detId());
19 DetId detId1(rawDetId1);
20 DetId lowerDetId, upperDetId;
30 LogDebug(
"VectorHitBuilderAlgorithm") <<
" DetId stack : " << detIdStack.
rawId() << std::endl;
31 LogDebug(
"VectorHitBuilderAlgorithm") <<
" DetId lower set of clusters : " << lowerDetId.
rawId();
32 LogDebug(
"VectorHitBuilderAlgorithm") <<
" DetId upper set of clusters : " << upperDetId.
rawId() << std::endl;
36 const auto& it_detLower = dSViter;
37 const auto& it_detUpper = clustersPhase2Collection->find(upperDetId);
39 if (it_detUpper != clustersPhase2Collection->end()) {
41 stackDet = dynamic_cast<const StackGeomDet*>(gd);
45 LogDebug(
"VectorHitBuilderAlgorithm") <<
"End run VectorHitBuilderAlgorithm ... \n";
50 const Detset& theLowerDetSet,
51 const Detset& theUpperDetSet)
const {
52 if (theLowerDetSet.
size() == 1 && theUpperDetSet.
size() == 1)
56 std::vector<Phase2TrackerCluster1D> lowerClusters;
57 lowerClusters.reserve(theLowerDetSet.
size());
58 if (theLowerDetSet.
size() > 1)
59 LogDebug(
"VectorHitBuilderAlgorithm") <<
" more than 1 lower cluster! " << std::endl;
60 if (theUpperDetSet.
size() > 1)
61 LogDebug(
"VectorHitBuilderAlgorithm") <<
" more than 1 upper cluster! " << std::endl;
64 lowerClusters.push_back(*clusterLower);
83 const Detset& theLowerDetSet,
84 const Detset& theUpperDetSet,
85 const std::vector<bool>& phase2OTClustersToSkip)
const {
87 LogDebug(
"VectorHitBuilderAlgorithm") <<
" compatible -> continue ... " << std::endl;
89 LogTrace(
"VectorHitBuilderAlgorithm") <<
" not compatible, going to the next cluster";
97 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t is barrel. " << std::endl;
99 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t is endcap. " << std::endl;
100 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t layer is : " << layerStack << std::endl;
107 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t the cut is:" <<
cut << std::endl;
110 std::vector<std::pair<LocalPoint, LocalError>> localParamsUpper;
111 std::vector<const PixelGeomDetUnit*> localGDUUpper;
114 for (
auto const& clusterUpper : theUpperDetSet) {
115 localGDUUpper.push_back(gduUpp);
118 int upperIterator = 0;
121 LogDebug(
"VectorHitBuilderAlgorithm") <<
" lower clusters " << std::endl;
128 for (
const_iterator ciu = theUpperDetSet.begin(); ciu != theUpperDetSet.end(); ++ciu) {
129 LogDebug(
"VectorHitBuilderAlgorithm") <<
"\t upper clusters " << std::endl;
136 gduLow, lparamsLow.first, localGDUUpper[upperIterator], localParamsUpper[upperIterator].first);
137 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t parallax correction:" << pC << std::endl;
138 double lpos_upp_corr = 0.0;
139 double lpos_low_corr = 0.0;
140 auto const localUpperX = localParamsUpper[upperIterator].first.x();
141 if (localUpperX > lparamsLow.first.x()) {
142 if (localUpperX > 0) {
143 lpos_low_corr = lparamsLow.first.x();
144 lpos_upp_corr = localParamsUpper[upperIterator].first.x() -
std::abs(pC);
145 }
else if (localUpperX < 0) {
146 lpos_low_corr = lparamsLow.first.x() +
std::abs(pC);
147 lpos_upp_corr = localUpperX;
149 }
else if (localUpperX < lparamsLow.first.x()) {
150 if (localUpperX > 0) {
151 lpos_low_corr = lparamsLow.first.x() -
std::abs(pC);
152 lpos_upp_corr = localUpperX;
153 }
else if (localUpperX < 0) {
154 lpos_low_corr = lparamsLow.first.x();
155 lpos_upp_corr = localUpperX +
std::abs(pC);
158 if (localUpperX > 0) {
159 lpos_low_corr = lparamsLow.first.x();
160 lpos_upp_corr = localUpperX -
std::abs(pC);
161 }
else if (localUpperX < 0) {
162 lpos_low_corr = lparamsLow.first.x();
163 lpos_upp_corr = localUpperX +
std::abs(pC);
167 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t local pos upper corrected (x):" << lpos_upp_corr << std::endl;
168 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t local pos lower corrected (x):" << lpos_low_corr << std::endl;
170 double width = lpos_low_corr - lpos_upp_corr;
171 LogDebug(
"VectorHitBuilderAlgorithm") <<
" \t width: " <<
width << std::endl;
181 LogDebug(
"VectorHitBuilderAlgorithm") <<
" accepting VH! " << std::endl;
189 LogDebug(
"VectorHitBuilderAlgorithm") <<
" rejecting VH: " << std::endl;
204 LogTrace(
"VectorHitBuilderAlgorithm") <<
"Build VH with: ";
212 Global3DPoint gparamsLower = geomDetLower->surface().toGlobal(lparamsLower.first);
213 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t lower global pos: " << gparamsLower;
216 Global3DPoint gparamsUpper = geomDetUpper->surface().toGlobal(lparamsUpper.first);
217 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t upper global pos: " << gparamsUpper;
220 Local3DPoint lparamsUpperInLower = geomDetLower->surface().toLocal(gparamsUpper);
222 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t lower global pos: " << gparamsLower;
223 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t upper global pos: " << gparamsUpper;
225 LogTrace(
"VectorHitBuilderAlgorithm") <<
"A:\t lower local pos: " << lparamsLower.first
226 <<
" with error: " << lparamsLower.second << std::endl;
227 LogTrace(
"VectorHitBuilderAlgorithm") <<
"A:\t upper local pos in the lower sof " << lparamsUpperInLower
228 <<
" with error: " << lparamsUpper.second << std::endl;
235 double chi22Dzx = 0.0;
246 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t pos2Dzx: " << pos2Dzx;
247 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t dir2Dzx: " << dir2Dzx;
248 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t cov2Dzx: " << covMat2Dzx;
252 double chi22Dzy = 0.0;
263 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t pos2Dzy: " << pos2Dzy;
264 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t dir2Dzy: " << dir2Dzy;
265 LogTrace(
"VectorHitBuilderAlgorithm") <<
"\t cov2Dzy: " << covMat2Dzy;
276 if (gPositionLower.
perp() > gPositionUpper.
perp()) {
277 std::swap(gPositionLower, gPositionUpper);
289 curvatureAndPhi.
phi);
303 double&
chi2)
const {
304 float x[2] = {lpCI.
z(), lpCO.
z()};
305 float y[2] = {lpCI.
x(), lpCO.
x()};
306 float sqCI =
sqrt(leCI.
xx());
307 float sqCO =
sqrt(leCO.
xx());
308 float sigy2[2] = {sqCI * sqCI, sqCO * sqCO};
322 double&
chi2)
const {
323 float x[2] = {lpCI.
z(), lpCO.
z()};
324 float y[2] = {lpCI.
y(), lpCO.
y()};
325 float sqCI =
sqrt(leCI.
yy());
326 float sqCO =
sqrt(leCO.
yy());
327 float sigy2[2] = {sqCI * sqCI, sqCO * sqCO};
340 double&
chi2)
const {
342 float intercept = 0.;
349 covMatrix[0][0] = covss;
350 covMatrix[1][1] = covii;
351 covMatrix[1][0] = covsi;
353 for (
unsigned int j = 0;
j < 2;
j++) {
354 const double ypred = intercept +
slope *
x[
j];
355 const double dy = (
y[
j] - ypred) /
sqrt(sigy2[
j]);
361 float slopeZ =
x[1] -
x[0];
372 float errorCurvature = -999.;
375 float h1 = gPositionLower.
x() * gPositionUpper.
y() - gPositionUpper.
x() * gPositionLower.
y();
379 n1[0] = -gPositionLower.
y();
380 n1[1] = gPositionLower.
x();
382 n2[0] = gPositionUpper.
x() - gPositionLower.
x();
383 n2[1] = gPositionUpper.
y() - gPositionLower.
y();
385 double n3 = n1[0] * n2[0] + n1[1] * n2[1];
386 double signCurv = -copysign(1.0, n3);
387 double phi1 = atan2(gPositionUpper.
y() - gPositionLower.
y(), gPositionUpper.
x() - gPositionLower.
x());
389 double x2Low =
pow(gPositionLower.
x(), 2);
390 double y2Low =
pow(gPositionLower.
y(), 2);
391 double x2Up =
pow(gPositionUpper.
x(), 2);
392 double y2Up =
pow(gPositionUpper.
y(), 2);
396 double h2Inf = 1. / (2 * h1);
397 double r12 = gPositionLower.
perp2();
398 double r22 = gPositionUpper.
perp2();
399 double h3 =
pow(n2[0], 2) +
pow(n2[1], 2);
400 double h4 = -x2Low * gPositionUpper.
x() + gPositionLower.
x() * x2Up + gPositionLower.
x() * y2Up -
401 gPositionUpper.
x() * y2Low;
403 x2Low * gPositionUpper.
y() - x2Up * gPositionLower.
y() + y2Low * gPositionUpper.
y() - gPositionLower.
y() * y2Up;
406 double invRho2 = (4. * h1 * h1) / (r12 * r22 * h3);
410 double xcentre = h5 / h2;
411 double ycentre = h4 / h2;
414 double xtg = gPositionLower.
y() - ycentre;
415 double ytg = -(gPositionLower.
x() - xcentre);
418 phi = atan2(ytg, xtg);
422 double denom1 = 1. /
sqrt(r12 * r22 * h3);
423 double denom2 = 1. / (
pow(r12 * r22 * h3, 1.5));
424 jacobian[0][0] = 1.0;
425 jacobian[1][1] = 1.0;
427 -2. * ((h1 * (gPositionLower.
x() * r22 * h3 + (gPositionLower.
x() - gPositionUpper.
x()) * r12 * r22)) * denom2 -
428 (gPositionUpper.
y()) * denom1);
430 -2. * ((gPositionUpper.
x()) * denom1 +
431 (h1 * (gPositionLower.
y() * r22 * h3 + r12 * r22 * (gPositionLower.
y() - gPositionUpper.
y()))) *
434 -2. * ((gPositionLower.
y()) * denom1 +
435 (h1 * (gPositionUpper.
x() * r12 * h3 - (gPositionLower.
x() - gPositionUpper.
x()) * r12 * r22)) *
438 -2. * ((h1 * (gPositionUpper.
y() * r12 * h3 - r12 * r22 * (gPositionLower.
y() - gPositionUpper.
y()))) * denom2 -
439 (gPositionLower.
x()) * denom1);
442 mVector[0] = (gPositionLower.
y() - ycentre) * invRho2;
443 mVector[1] = -(gPositionLower.
x() - xcentre) * invRho2;
446 double h22Inv = 1. /
pow(h2, 2);
450 2. * ((gPositionLower.
x() * gPositionUpper.
y()) * h2Inf - (gPositionUpper.
y() * h5) * h22Inv);
451 kMatrix[0][1] = (2. * gPositionUpper.
x() * h5) * h22Inv -
452 (x2Up + y2Up - 2. * gPositionLower.
y() * gPositionUpper.
y()) * h2Inf;
454 2. * ((gPositionLower.
y() * h5) * h22Inv - (gPositionUpper.
x() * gPositionLower.
y()) * h2Inf);
455 kMatrix[0][3] = (x2Low + y2Low - 2. * gPositionUpper.
y() * gPositionLower.
y()) * h2Inf -
456 (2. * gPositionLower.
x() * h5) * h22Inv;
457 kMatrix[1][0] = (x2Up - 2. * gPositionLower.
x() * gPositionUpper.
x() + y2Up) * h2Inf -
458 (2. * gPositionUpper.
y() * h4) * h22Inv;
460 2. * ((gPositionUpper.
x() * h4) * h22Inv - (gPositionUpper.
x() * gPositionLower.
y()) * h2Inf);
461 kMatrix[1][2] = (2. * gPositionLower.
y() * h4) * h22Inv -
462 (x2Low - 2. * gPositionUpper.
x() * gPositionLower.
x() + y2Low) * h2Inf;
464 2. * (gPositionLower.
x() * gPositionUpper.
y()) * h2Inf - (gPositionLower.
x() * h4) * h22Inv;
467 jacobian[3][0] = nMatrix[0];
468 jacobian[3][1] = nMatrix[1];
469 jacobian[3][2] = nMatrix[2];
470 jacobian[3][3] = nMatrix[3];
473 if ((signCurv < 0 && curvature > 0) || (signCurv > 0 &&
curvature < 0)) {
475 for (
int i = 0;
i < 4;
i++) {
476 jacobian[2][
i] = -jacobian[2][
i];
489 for (
int i = 0;
i < 4;
i++) {
490 curvatureJacobian[
i] = jacobian[2][
i];
495 gErrors[0][0] = gErrorLower.
cxx();
496 gErrors[0][1] = gErrorLower.
cyx();
497 gErrors[1][0] = gErrorLower.
cyx();
498 gErrors[1][1] = gErrorLower.
cyy();
499 gErrors[2][2] = gErrorUpper.
cxx();
500 gErrors[2][3] = gErrorUpper.
cyx();
501 gErrors[3][2] = gErrorUpper.
cyx();
502 gErrors[3][3] = gErrorUpper.
cyy();
506 errorCurvature =
temp[0] * curvatureJacobian[0] +
temp[1] * curvatureJacobian[1] +
temp[2] * curvatureJacobian[2] +
507 temp[3] * curvatureJacobian[3];
511 result.curvatureError = errorCurvature;