280 if ((vals !=
nullptr) && (vals->size() ==
nParams * 2)) {
281 double nSigmaXY = 10.;
283 double parDistanceXY = 1
e-3;
284 double parDistanceZ = 1
e-2;
285 double parDistanceddZ = 1
e-3;
286 double parDistanceCxy = 1
e-5;
289 const unsigned int trials = 4;
290 double largerDist[trials] = {0.1, 5., 10., 100.};
292 double covxz, covyz, det;
294 int bestMovementX = 1;
295 int bestMovementY = 1;
296 int bestMovementZ = 1;
301 vector<double>::const_iterator it = vals->begin();
303 ROOT::Math::Minimizer* Gauss3D = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Migrad");
304 Gauss3D->SetErrorDef(1.0);
306 Gauss3D->SetPrintLevel(3);
308 Gauss3D->SetPrintLevel(0);
311 Gauss3D->SetFunction(_Gauss3DFunc);
314 cout <<
"[Vx3DHLTAnalyzer]::\t@@@ START FITTING @@@" << endl;
318 for (
int i = 0;
i < 3;
i++) {
319 deltaMean = (double(
i) - 1.) *
std::sqrt(*(it + 0));
321 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
325 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
326 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
327 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
328 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
329 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
330 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
331 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + deltaMean, parDistanceXY);
332 Gauss3D->SetVariable(7,
"mean y", *(it + 7), parDistanceXY);
333 Gauss3D->SetVariable(8,
"mean z", *(it + 8), parDistanceZ);
345 goodData = Gauss3D->Status();
346 edm = Gauss3D->Edm();
353 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl;
359 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
363 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
364 Gauss3D->X()[5] * Gauss3D->X()[3];
365 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
366 Gauss3D->X()[4] * Gauss3D->X()[3];
368 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
369 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
370 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
374 cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl;
378 if ((goodData == 0) && (std::fabs(
edm) < bestEdm)) {
384 cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementX --> " << bestMovementX << endl;
388 for (
int i = 0;
i < 3;
i++) {
389 deltaMean = (double(
i) - 1.) *
std::sqrt(*(it + 1));
391 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
392 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)) << endl;
397 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
398 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
399 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
400 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
401 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
402 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
403 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)), parDistanceXY);
404 Gauss3D->SetVariable(7,
"mean y", *(it + 7) + deltaMean, parDistanceXY);
405 Gauss3D->SetVariable(8,
"mean z", *(it + 8), parDistanceZ);
408 xPos = Gauss3D->X()[6];
409 yPos = Gauss3D->X()[7];
410 zPos = Gauss3D->X()[8];
417 goodData = Gauss3D->Status();
418 edm = Gauss3D->Edm();
425 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl;
431 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
435 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
436 Gauss3D->X()[5] * Gauss3D->X()[3];
437 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
438 Gauss3D->X()[4] * Gauss3D->X()[3];
440 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
441 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
442 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
446 cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl;
450 if ((goodData == 0) && (std::fabs(
edm) < bestEdm)) {
456 cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementY --> " << bestMovementY << endl;
460 for (
int i = 0;
i < 3;
i++) {
461 deltaMean = (double(
i) - 1.) *
std::sqrt(*(it + 2));
463 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
464 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)) << endl;
465 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean Y --> " << (double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)) << endl;
470 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
471 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
472 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
473 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
474 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
475 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
476 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)), parDistanceXY);
477 Gauss3D->SetVariable(7,
"mean y", *(it + 7) + (
double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)), parDistanceXY);
478 Gauss3D->SetVariable(8,
"mean z", *(it + 8) + deltaMean, parDistanceZ);
481 xPos = Gauss3D->X()[6];
482 yPos = Gauss3D->X()[7];
483 zPos = Gauss3D->X()[8];
490 goodData = Gauss3D->Status();
491 edm = Gauss3D->Edm();
498 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl;
504 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
508 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
509 Gauss3D->X()[5] * Gauss3D->X()[3];
510 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
511 Gauss3D->X()[4] * Gauss3D->X()[3];
513 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
514 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
515 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
519 cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl;
523 if ((goodData == 0) && (std::fabs(
edm) < bestEdm)) {
529 cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementZ --> " << bestMovementZ << endl;
534 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY);
535 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY);
536 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ);
537 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy);
538 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ);
539 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ);
540 Gauss3D->SetVariable(6,
"mean x", *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)), parDistanceXY);
541 Gauss3D->SetVariable(7,
"mean y", *(it + 7) + (
double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)), parDistanceXY);
542 Gauss3D->SetVariable(8,
"mean z", *(it + 8) + (
double(bestMovementZ) - 1.) *
std::sqrt(*(it + 2)), parDistanceZ);
554 goodData = Gauss3D->Status();
555 edm = Gauss3D->Edm();
562 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl;
568 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
572 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
573 Gauss3D->X()[5] * Gauss3D->X()[3];
574 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
575 Gauss3D->X()[4] * Gauss3D->X()[3];
577 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
578 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
579 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
583 cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl;
588 for (
unsigned int i = 0;
i < trials;
i++) {
589 if ((goodData != 0) && (goodData != -2)) {
593 cout <<
"[Vx3DHLTAnalyzer]::\tFIT WITH DIFFERENT PARAMETER DISTANCES - STEP " <<
i + 1 << endl;
595 Gauss3D->SetVariable(0,
"var x ", *(it + 0), parDistanceXY * parDistanceXY * largerDist[
i]);
596 Gauss3D->SetVariable(1,
"var y ", *(it + 1), parDistanceXY * parDistanceXY * largerDist[
i]);
597 Gauss3D->SetVariable(2,
"var z ", *(it + 2), parDistanceZ * parDistanceZ * largerDist[
i]);
598 Gauss3D->SetVariable(3,
"cov xy", *(it + 3), parDistanceCxy * largerDist[
i]);
599 Gauss3D->SetVariable(4,
"dydz ", *(it + 4), parDistanceddZ * largerDist[
i]);
600 Gauss3D->SetVariable(5,
"dxdz ", *(it + 5), parDistanceddZ * largerDist[
i]);
601 Gauss3D->SetVariable(6,
603 *(it + 6) + (
double(bestMovementX) - 1.) *
std::sqrt(*(it + 0)),
604 parDistanceXY * largerDist[
i]);
605 Gauss3D->SetVariable(7,
607 *(it + 7) + (
double(bestMovementY) - 1.) *
std::sqrt(*(it + 1)),
608 parDistanceXY * largerDist[
i]);
609 Gauss3D->SetVariable(
610 8,
"mean z", *(it + 8) + (
double(bestMovementZ) - 1.) *
std::sqrt(*(it + 2)), parDistanceZ * largerDist[
i]);
613 xPos = Gauss3D->X()[6];
614 yPos = Gauss3D->X()[7];
615 zPos = Gauss3D->X()[8];
622 goodData = Gauss3D->Status();
623 edm = Gauss3D->Edm();
630 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl;
636 cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
640 covyz = Gauss3D->X()[4] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[1])) -
641 Gauss3D->X()[5] * Gauss3D->X()[3];
642 covxz = Gauss3D->X()[5] * (std::fabs(Gauss3D->X()[2]) - std::fabs(Gauss3D->X()[0])) -
643 Gauss3D->X()[4] * Gauss3D->X()[3];
645 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1]) * std::fabs(Gauss3D->X()[2]) - covyz * covyz) -
646 Gauss3D->X()[3] * (Gauss3D->X()[3] * std::fabs(Gauss3D->X()[2]) - covxz * covyz) +
647 covxz * (Gauss3D->X()[3] * covyz - covxz * std::fabs(Gauss3D->X()[1]));
651 cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl;
660 vals->operator[](
i) = Gauss3D->X()[
i];
661 vals->operator[](
i +
nParams) = Gauss3D->Errors()[
i];