307 double nSigmaXY = 10.;
309 double parDistanceXY = 1
e-3;
310 double parDistanceZ = 1
e-2;
311 double parDistanceddZ = 1
e-3;
312 double parDistanceCxy = 1
e-5;
315 const unsigned int trials = 4;
316 double largerDist[trials] = {0.1, 5., 10., 100.};
318 double covxz,covyz,det;
320 int bestMovementX = 1;
321 int bestMovementY = 1;
322 int bestMovementZ = 1;
327 vector<double>::const_iterator it =
vals->begin();
329 ROOT::Math::Minimizer* Gauss3D = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Migrad");
330 Gauss3D->SetErrorDef(1.0);
332 else Gauss3D->SetPrintLevel(0);
335 Gauss3D->SetFunction(_Gauss3DFunc);
337 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\t@@@ START FITTING @@@" << endl;
341 for (
int i = 0;
i < 3;
i++)
343 deltaMean = (double(
i)-1.)*
std::sqrt(*(it+0));
344 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
348 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
349 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
350 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
351 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
352 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
353 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
354 Gauss3D->SetVariable(6,
"mean x", *(it+6)+deltaMean, parDistanceXY);
355 Gauss3D->SetVariable(7,
"mean y", *(it+7), parDistanceXY);
356 Gauss3D->SetVariable(8,
"mean z", *(it+8), parDistanceZ);
359 xPos = Gauss3D->X()[6];
360 yPos = Gauss3D->X()[7];
361 zPos = Gauss3D->X()[8];
368 goodData = Gauss3D->Status();
369 edm = Gauss3D->Edm();
372 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
373 else for (
unsigned int j = 0; j <
nParams; j++)
377 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
382 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
383 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
385 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
386 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
387 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
388 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
391 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementX =
i; }
393 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementX --> " << bestMovementX << endl;
397 for (
int i = 0;
i < 3;
i++)
399 deltaMean = (double(
i)-1.)*
std::sqrt(*(it+1));
402 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
403 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX)-1.)*
std::sqrt(*(it+0)) << endl;
408 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
409 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
410 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
411 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
412 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
413 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
414 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY);
415 Gauss3D->SetVariable(7,
"mean y", *(it+7)+deltaMean, parDistanceXY);
416 Gauss3D->SetVariable(8,
"mean z", *(it+8), parDistanceZ);
419 xPos = Gauss3D->X()[6];
420 yPos = Gauss3D->X()[7];
421 zPos = Gauss3D->X()[8];
428 goodData = Gauss3D->Status();
429 edm = Gauss3D->Edm();
432 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
433 else for (
unsigned int j = 0; j <
nParams; j++)
437 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
442 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
443 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
445 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
446 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
447 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
448 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
451 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementY =
i; }
453 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementY --> " << bestMovementY << endl;
457 for (
int i = 0;
i < 3;
i++)
459 deltaMean = (double(
i)-1.)*
std::sqrt(*(it+2));
462 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
463 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX)-1.)*
std::sqrt(*(it+0)) << endl;
464 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean Y --> " << (double(bestMovementY)-1.)*
std::sqrt(*(it+1)) << endl;
469 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
470 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
471 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
472 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
473 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
474 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
475 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY);
476 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt(*(it+1)), parDistanceXY);
477 Gauss3D->SetVariable(8,
"mean z", *(it+8)+deltaMean, parDistanceZ);
480 xPos = Gauss3D->X()[6];
481 yPos = Gauss3D->X()[7];
482 zPos = Gauss3D->X()[8];
489 goodData = Gauss3D->Status();
490 edm = Gauss3D->Edm();
493 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
494 else for (
unsigned int j = 0; j <
nParams; j++)
498 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
503 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
504 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
506 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
507 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
508 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
509 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
512 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementZ =
i; }
514 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementZ --> " << bestMovementZ << endl;
519 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
520 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
521 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
522 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
523 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
524 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
525 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY);
526 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt(*(it+1)), parDistanceXY);
527 Gauss3D->SetVariable(8,
"mean z", *(it+8)+(
double(bestMovementZ)-1.)*
std::sqrt(*(it+2)), parDistanceZ);
530 xPos = Gauss3D->X()[6];
531 yPos = Gauss3D->X()[7];
532 zPos = Gauss3D->X()[8];
539 goodData = Gauss3D->Status();
540 edm = Gauss3D->Edm();
543 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
544 else for (
unsigned int j = 0; j <
nParams; j++)
548 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
553 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
554 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
556 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
557 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
558 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
559 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
563 for (
unsigned int i = 0;
i < trials;
i++)
565 if ((goodData != 0) && (goodData != -2))
569 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFIT WITH DIFFERENT PARAMETER DISTANCES - STEP " <<
i+1 << endl;
571 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY * largerDist[
i]);
572 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY * largerDist[i]);
573 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ * largerDist[i]);
574 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy * largerDist[i]);
575 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ * largerDist[i]);
576 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ * largerDist[i]);
577 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY * largerDist[i]);
578 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt(*(it+1)), parDistanceXY * largerDist[i]);
579 Gauss3D->SetVariable(8,
"mean z", *(it+8)+(
double(bestMovementZ)-1.)*
std::sqrt(*(it+2)), parDistanceZ * largerDist[i]);
582 xPos = Gauss3D->X()[6];
583 yPos = Gauss3D->X()[7];
584 zPos = Gauss3D->X()[8];
591 goodData = Gauss3D->Status();
592 edm = Gauss3D->Edm();
595 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
596 else for (
unsigned int j = 0; j <
nParams; j++)
600 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
605 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
606 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
608 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
609 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
610 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
611 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
617 for (
unsigned int i = 0; i <
nParams; i++)
619 vals->operator[](
i) = Gauss3D->X()[
i];
double Gauss3DFunc(const double *par)