308 double nSigmaXY = 10.;
310 double parDistanceXY = 1
e-3;
311 double parDistanceZ = 1
e-2;
312 double parDistanceddZ = 1
e-3;
313 double parDistanceCxy = 1
e-5;
316 const unsigned int trials = 4;
317 double largerDist[trials] = {0.1, 5., 10., 100.};
319 double covxz,covyz,det;
321 int bestMovementX = 1;
322 int bestMovementY = 1;
323 int bestMovementZ = 1;
328 vector<double>::const_iterator it =
vals->begin();
330 ROOT::Math::Minimizer* Gauss3D = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Migrad");
331 Gauss3D->SetErrorDef(1.0);
333 else Gauss3D->SetPrintLevel(0);
336 Gauss3D->SetFunction(_Gauss3DFunc);
338 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\t@@@ START FITTING @@@" << endl;
342 for (
int i = 0;
i < 3;
i++)
344 deltaMean = (double(
i)-1.)*
std::sqrt(*(it+0));
345 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
349 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
350 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
351 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
352 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
353 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
354 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
355 Gauss3D->SetVariable(6,
"mean x", *(it+6)+deltaMean, parDistanceXY);
356 Gauss3D->SetVariable(7,
"mean y", *(it+7), parDistanceXY);
357 Gauss3D->SetVariable(8,
"mean z", *(it+8), parDistanceZ);
360 xPos = Gauss3D->X()[6];
361 yPos = Gauss3D->X()[7];
362 zPos = Gauss3D->X()[8];
369 goodData = Gauss3D->Status();
370 edm = Gauss3D->Edm();
373 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
374 else for (
unsigned int j = 0; j <
nParams; j++)
378 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
383 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
384 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
386 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
387 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
388 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
389 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
392 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementX =
i; }
394 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementX --> " << bestMovementX << endl;
398 for (
int i = 0;
i < 3;
i++)
400 deltaMean = (double(
i)-1.)*
std::sqrt(*(it+1));
403 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
404 cout <<
"[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX)-1.)*
std::sqrt(*(it+0)) << endl;
409 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
410 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
411 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
412 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
413 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
414 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
415 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY);
416 Gauss3D->SetVariable(7,
"mean y", *(it+7)+deltaMean, parDistanceXY);
417 Gauss3D->SetVariable(8,
"mean z", *(it+8), parDistanceZ);
420 xPos = Gauss3D->X()[6];
421 yPos = Gauss3D->X()[7];
422 zPos = Gauss3D->X()[8];
429 goodData = Gauss3D->Status();
430 edm = Gauss3D->Edm();
433 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
434 else for (
unsigned int j = 0; j <
nParams; j++)
438 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
443 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
444 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
446 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
447 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
448 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
449 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
452 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementY =
i; }
454 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementY --> " << bestMovementY << endl;
458 for (
int i = 0;
i < 3;
i++)
460 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();
494 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
495 else for (
unsigned int j = 0; j <
nParams; j++)
499 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
504 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
505 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
507 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
508 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
509 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
510 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
513 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementZ =
i; }
515 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFound bestMovementZ --> " << bestMovementZ << endl;
520 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY);
521 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY);
522 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ);
523 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
524 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
525 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
526 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY);
527 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt(*(it+1)), parDistanceXY);
528 Gauss3D->SetVariable(8,
"mean z", *(it+8)+(
double(bestMovementZ)-1.)*
std::sqrt(*(it+2)), parDistanceZ);
531 xPos = Gauss3D->X()[6];
532 yPos = Gauss3D->X()[7];
533 zPos = Gauss3D->X()[8];
540 goodData = Gauss3D->Status();
541 edm = Gauss3D->Edm();
544 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
545 else for (
unsigned int j = 0; j <
nParams; j++)
549 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
554 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
555 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
557 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
558 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
559 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
560 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
564 for (
unsigned int i = 0;
i < trials;
i++)
566 if ((goodData != 0) && (goodData != -2))
570 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tFIT WITH DIFFERENT PARAMETER DISTANCES - STEP " <<
i+1 << endl;
572 Gauss3D->SetVariable(0,
"var x ", *(it+0), parDistanceXY * parDistanceXY * largerDist[
i]);
573 Gauss3D->SetVariable(1,
"var y ", *(it+1), parDistanceXY * parDistanceXY * largerDist[i]);
574 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ * parDistanceZ * largerDist[i]);
575 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy * largerDist[i]);
576 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ * largerDist[i]);
577 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ * largerDist[i]);
578 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt(*(it+0)), parDistanceXY * largerDist[i]);
579 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt(*(it+1)), parDistanceXY * largerDist[i]);
580 Gauss3D->SetVariable(8,
"mean z", *(it+8)+(
double(bestMovementZ)-1.)*
std::sqrt(*(it+2)), parDistanceZ * largerDist[i]);
583 xPos = Gauss3D->X()[6];
584 yPos = Gauss3D->X()[7];
585 zPos = Gauss3D->X()[8];
592 goodData = Gauss3D->Status();
593 edm = Gauss3D->Edm();
596 else if (
isNotFinite(edm) ==
true) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
597 else for (
unsigned int j = 0; j <
nParams; j++)
601 if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
606 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
607 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
609 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
610 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
611 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
612 if (det < 0.) { goodData = -4;
if (
internalDebug ==
true)
cout <<
"[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
618 for (
unsigned int i = 0; i <
nParams; i++)
620 vals->operator[](
i) = Gauss3D->X()[
i];
double Gauss3DFunc(const double *par)