279 if ((vals !=
nullptr) && (vals->size() ==
nParams * 2)) {
280 double nSigmaXY = 10.;
282 double parDistanceXY = 1
e-3;
283 double parDistanceZ = 1
e-2;
284 double parDistanceddZ = 1
e-3;
285 double parDistanceCxy = 1
e-5;
288 const unsigned int trials = 4;
289 double largerDist[trials] = {0.1, 5., 10., 100.};
291 double covxz, covyz, det;
293 int bestMovementX = 1;
294 int bestMovementY = 1;
295 int bestMovementZ = 1;
300 vector<double>::const_iterator it = vals->begin();
302 ROOT::Math::Minimizer* Gauss3D = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Migrad");
303 Gauss3D->SetErrorDef(1.0);
305 Gauss3D->SetPrintLevel(3);
307 Gauss3D->SetPrintLevel(0);
310 Gauss3D->SetFunction(_Gauss3DFunc);
313 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\t@@@ START FITTING @@@";
317 for (
int i = 0;
i < 3;
i++) {
318 deltaMean = (double(
i) - 1.) *
std::sqrt(*(it + 0));
320 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tdeltaMean --> " << deltaMean;
324 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
325 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
326 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
327 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
328 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
329 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
330 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + deltaMean, parDistanceXY);
331 Gauss3D->SetVariable(7,
"mean y", *(it + 7), parDistanceXY);
332 Gauss3D->SetVariable(8,
"mean z", *(it + 8), parDistanceZ);
348 goodData = Gauss3D->Status();
349 edm = Gauss3D->Edm();
356 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite edm !";
362 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite errors !";
366 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
367 Gauss3D->X()[5] * Gauss3D->X()[3];
368 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
369 Gauss3D->X()[4] * Gauss3D->X()[3];
371 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
372 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
373 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
377 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNegative determinant !";
381 if ((goodData == 0) && (std::fabs(
edm) < bestEdm)) {
387 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tFound bestMovementX --> " << bestMovementX;
391 for (
int i = 0;
i < 3;
i++) {
392 deltaMean = (double(
i) - 1.) *
std::sqrt(*(it + 1));
394 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tdeltaMean --> " << deltaMean;
395 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tdeltaMean X --> " << (double(bestMovementX) - 1.) *
std::sqrt(*(it + 0));
400 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
401 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
402 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
403 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
404 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
405 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
406 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)), parDistanceXY);
407 Gauss3D->SetVariable(7,
"mean y", *(it + 7) + deltaMean, parDistanceXY);
408 Gauss3D->SetVariable(8,
"mean z", *(it + 8), parDistanceZ);
411 xPos = Gauss3D->X()[6];
412 yPos = Gauss3D->X()[7];
413 zPos = Gauss3D->X()[8];
424 goodData = Gauss3D->Status();
425 edm = Gauss3D->Edm();
432 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite edm !";
438 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite errors !";
442 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
443 Gauss3D->X()[5] * Gauss3D->X()[3];
444 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
445 Gauss3D->X()[4] * Gauss3D->X()[3];
447 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
448 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
449 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
453 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNegative determinant !";
457 if ((goodData == 0) && (std::fabs(
edm) < bestEdm)) {
463 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tFound bestMovementY --> " << bestMovementY;
467 for (
int i = 0;
i < 3;
i++) {
468 deltaMean = (double(
i) - 1.) *
std::sqrt(*(it + 2));
470 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tdeltaMean --> " << deltaMean;
471 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tdeltaMean X --> " << (double(bestMovementX) - 1.) *
std::sqrt(*(it + 0));
472 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tdeltaMean Y --> " << (double(bestMovementY) - 1.) *
std::sqrt(*(it + 1));
477 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
478 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
479 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
480 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
481 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
482 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
483 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)), parDistanceXY);
484 Gauss3D->SetVariable(7,
"mean y", *(it + 7) + (
double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)), parDistanceXY);
485 Gauss3D->SetVariable(8,
"mean z", *(it + 8) + deltaMean, parDistanceZ);
488 xPos = Gauss3D->X()[6];
489 yPos = Gauss3D->X()[7];
490 zPos = Gauss3D->X()[8];
501 goodData = Gauss3D->Status();
502 edm = Gauss3D->Edm();
509 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite edm !";
515 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite errors !";
519 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
520 Gauss3D->X()[5] * Gauss3D->X()[3];
521 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
522 Gauss3D->X()[4] * Gauss3D->X()[3];
524 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
525 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
526 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
530 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNegative determinant !";
534 if ((goodData == 0) && (std::fabs(
edm) < bestEdm)) {
540 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tFound bestMovementZ --> " << bestMovementZ;
545 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
546 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
547 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
548 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
549 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
550 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
551 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)), parDistanceXY);
552 Gauss3D->SetVariable(7,
"mean y", *(it + 7) + (
double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)), parDistanceXY);
553 Gauss3D->SetVariable(8,
"mean z", *(it + 8) + (
double(bestMovementZ) - 1.) *
std::sqrt(*(it + 2)), parDistanceZ);
569 goodData = Gauss3D->Status();
570 edm = Gauss3D->Edm();
577 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite edm !";
583 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite errors !";
587 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
588 Gauss3D->X()[5] * Gauss3D->X()[3];
589 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
590 Gauss3D->X()[4] * Gauss3D->X()[3];
592 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
593 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
594 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
598 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNegative determinant !";
603 for (
unsigned int i = 0;
i < trials;
i++) {
604 if ((goodData != 0) && (goodData != -2)) {
608 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tFIT WITH DIFFERENT PARAMETER DISTANCES - STEP " <<
i + 1;
610 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY * largerDist[
i]);
611 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY * largerDist[
i]);
612 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ * largerDist[
i]);
613 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy * largerDist[
i]);
614 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ * largerDist[
i]);
615 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ * largerDist[
i]);
616 Gauss3D->SetVariable(6,
618 *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)),
619 parDistanceXY * largerDist[
i]);
620 Gauss3D->SetVariable(7,
622 *(it + 7) + (
double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)),
623 parDistanceXY * largerDist[
i]);
624 Gauss3D->SetVariable(
625 8,
"mean z", *(it + 8) + (
double(bestMovementZ) - 1.) *
std::sqrt(*(it + 2)), parDistanceZ * largerDist[
i]);
628 xPos = Gauss3D->X()[6];
629 yPos = Gauss3D->X()[7];
630 zPos = Gauss3D->X()[8];
641 goodData = Gauss3D->Status();
642 edm = Gauss3D->Edm();
649 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite edm !";
655 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNot finite errors !";
659 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
660 Gauss3D->X()[5] * Gauss3D->X()[3];
661 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
662 Gauss3D->X()[4] * Gauss3D->X()[3];
664 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
665 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
666 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
670 edm::LogInfo(
"Vx3DHLTAnalyzer") <<
"\tNegative determinant !";
679 vals->operator[](
i) = Gauss3D->X()[
i];
680 vals->operator[](
i +
nParams) = Gauss3D->Errors()[
i];
constexpr bool isNotFinite(T x)
Log< level::Error, false > LogError
double Gauss3DFunc(const double *par)
Log< level::Info, false > LogInfo
char const * what() const noexcept override