253 unsigned int nParams = 9;
257 double nSigmaXY = 100.;
258 double nSigmaZ = 100.;
259 double varFactor = 4./25.;
260 double parDistanceXY = 0.005;
261 double parDistanceZ = 0.5;
262 double parDistanceddZ = 1
e-3;
263 double parDistanceCxy = 1
e-5;
264 double bestEdm = 1
e-1;
266 const unsigned int trials = 4;
267 double largerDist[trials] = {0.1, 5., 10., 100.};
269 double covxz,covyz,det;
271 int bestMovementX = 1;
272 int bestMovementY = 1;
273 int bestMovementZ = 1;
278 vector<double>::const_iterator it =
vals->begin();
280 ROOT::Math::Minimizer* Gauss3D = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Migrad");
281 Gauss3D->SetMaxFunctionCalls(1e4);
282 Gauss3D->SetTolerance(1
e-9);
284 else Gauss3D->SetPrintLevel(0);
286 ROOT::Math::Functor _Gauss3DFunc(&
Gauss3DFunc,nParams);
287 Gauss3D->SetFunction(_Gauss3DFunc);
293 for (
int i = 0;
i < 3;
i++)
295 deltaMean = (double(
i)-1.)*
std::sqrt((*(it+0))*varFactor);
300 Gauss3D->SetVariable(0,
"var x ", *(it+0)*varFactor, parDistanceXY*parDistanceXY);
301 Gauss3D->SetVariable(1,
"var y ", *(it+1)*varFactor, parDistanceXY*parDistanceXY);
302 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ*parDistanceZ);
303 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
304 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
305 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
306 Gauss3D->SetVariable(6,
"mean x", *(it+6)+deltaMean, parDistanceXY);
307 Gauss3D->SetVariable(7,
"mean y", *(it+7), parDistanceXY);
308 Gauss3D->SetVariable(8,
"mean z", *(it+8), parDistanceZ);
311 xPos = Gauss3D->X()[6];
312 yPos = Gauss3D->X()[7];
313 zPos = Gauss3D->X()[8];
320 goodData = Gauss3D->Status();
321 edm = Gauss3D->Edm();
325 else for (
unsigned int j = 0;
j < nParams;
j++)
if (
edm::isNotFinite(Gauss3D->Errors()[
j]) ==
true) { goodData = -1;
break; }
328 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
329 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
331 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
332 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
333 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
334 if (det < 0.) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"Negative determinant !" << endl; }
337 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementX =
i; }
339 if (
internalDebug ==
true)
cout <<
"Found bestMovementX --> " << bestMovementX << endl;
343 for (
int i = 0;
i < 3;
i++)
345 deltaMean = (double(
i)-1.)*
std::sqrt((*(it+1))*varFactor);
348 cout <<
"deltaMean --> " << deltaMean << endl;
349 cout <<
"deltaMean X --> " << (double(bestMovementX)-1.)*
std::sqrt((*(it+0))*varFactor) << endl;
354 Gauss3D->SetVariable(0,
"var x ", *(it+0)*varFactor, parDistanceXY*parDistanceXY);
355 Gauss3D->SetVariable(1,
"var y ", *(it+1)*varFactor, parDistanceXY*parDistanceXY);
356 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ*parDistanceZ);
357 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
358 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
359 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
360 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt((*(it+0))*varFactor), parDistanceXY);
361 Gauss3D->SetVariable(7,
"mean y", *(it+7)+deltaMean, parDistanceXY);
362 Gauss3D->SetVariable(8,
"mean z", *(it+8), parDistanceZ);
365 xPos = Gauss3D->X()[6];
366 yPos = Gauss3D->X()[7];
367 zPos = Gauss3D->X()[8];
374 goodData = Gauss3D->Status();
375 edm = Gauss3D->Edm();
379 else for (
unsigned int j = 0;
j < nParams;
j++)
if (
edm::isNotFinite(Gauss3D->Errors()[
j]) ==
true) { goodData = -1;
break; }
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 = -1;
if (
internalDebug ==
true)
cout <<
"Negative determinant !" << endl; }
391 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementY =
i; }
393 if (
internalDebug ==
true)
cout <<
"Found bestMovementY --> " << bestMovementY << endl;
397 for (
int i = 0;
i < 3;
i++)
399 deltaMean = (double(
i)-1.)*
std::sqrt(*(it+2));
402 cout <<
"deltaMean --> " << deltaMean << endl;
403 cout <<
"deltaMean X --> " << (double(bestMovementX)-1.)*
std::sqrt((*(it+0))*varFactor) << endl;
404 cout <<
"deltaMean Y --> " << (double(bestMovementY)-1.)*
std::sqrt((*(it+1))*varFactor) << endl;
409 Gauss3D->SetVariable(0,
"var x ", *(it+0)*varFactor, parDistanceXY*parDistanceXY);
410 Gauss3D->SetVariable(1,
"var y ", *(it+1)*varFactor, 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))*varFactor), parDistanceXY);
416 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt((*(it+1))*varFactor), parDistanceXY);
417 Gauss3D->SetVariable(8,
"mean z", *(it+8)+deltaMean, parDistanceZ);
420 xPos = Gauss3D->X()[6];
421 yPos = Gauss3D->X()[7];
422 zPos = Gauss3D->X()[8];
429 goodData = Gauss3D->Status();
430 edm = Gauss3D->Edm();
434 else for (
unsigned int j = 0;
j < nParams;
j++)
if (
edm::isNotFinite(Gauss3D->Errors()[
j]) ==
true) { goodData = -1;
break; }
437 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
438 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - 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]));
443 if (det < 0.) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"Negative determinant !" << endl; }
446 if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementZ =
i; }
448 if (
internalDebug ==
true)
cout <<
"Found bestMovementZ --> " << bestMovementZ << endl;
453 Gauss3D->SetVariable(0,
"var x ", *(it+0)*varFactor, parDistanceXY*parDistanceXY);
454 Gauss3D->SetVariable(1,
"var y ", *(it+1)*varFactor, parDistanceXY*parDistanceXY);
455 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ*parDistanceZ);
456 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy);
457 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ);
458 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ);
459 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt((*(it+0))*varFactor), parDistanceXY);
460 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt((*(it+1))*varFactor), parDistanceXY);
461 Gauss3D->SetVariable(8,
"mean z", *(it+8)+(
double(bestMovementZ)-1.)*
std::sqrt(*(it+2)), parDistanceZ);
464 xPos = Gauss3D->X()[6];
465 yPos = Gauss3D->X()[7];
466 zPos = Gauss3D->X()[8];
473 goodData = Gauss3D->Status();
474 edm = Gauss3D->Edm();
478 else for (
unsigned int j = 0;
j < nParams;
j++)
if (
edm::isNotFinite(Gauss3D->Errors()[
j]) ==
true) { goodData = -1;
break; }
481 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
482 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
484 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
485 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
486 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
487 if (det < 0.) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"Negative determinant !" << endl; }
491 for (
unsigned int i = 0;
i < trials;
i++)
493 if ((goodData != 0) && (goodData != -2))
497 if (
internalDebug ==
true)
cout <<
"FIT WITH DIFFERENT PARAMETER DISTANCES - STEP " <<
i+1 << endl;
499 Gauss3D->SetVariable(0,
"var x ", *(it+0)*varFactor, parDistanceXY*parDistanceXY * largerDist[
i]);
500 Gauss3D->SetVariable(1,
"var y ", *(it+1)*varFactor, parDistanceXY*parDistanceXY * largerDist[i]);
501 Gauss3D->SetVariable(2,
"var z ", *(it+2), parDistanceZ*parDistanceZ * largerDist[i]);
502 Gauss3D->SetVariable(3,
"cov xy", *(it+3), parDistanceCxy * largerDist[i]);
503 Gauss3D->SetVariable(4,
"dydz ", *(it+4), parDistanceddZ * largerDist[i]);
504 Gauss3D->SetVariable(5,
"dxdz ", *(it+5), parDistanceddZ * largerDist[i]);
505 Gauss3D->SetVariable(6,
"mean x", *(it+6)+(
double(bestMovementX)-1.)*
std::sqrt((*(it+0))*varFactor), parDistanceXY * largerDist[i]);
506 Gauss3D->SetVariable(7,
"mean y", *(it+7)+(
double(bestMovementY)-1.)*
std::sqrt((*(it+1))*varFactor), parDistanceXY * largerDist[i]);
507 Gauss3D->SetVariable(8,
"mean z", *(it+8)+(
double(bestMovementZ)-1.)*
std::sqrt(*(it+2)), parDistanceZ * largerDist[i]);
510 xPos = Gauss3D->X()[6];
511 yPos = Gauss3D->X()[7];
512 zPos = Gauss3D->X()[8];
519 goodData = Gauss3D->Status();
520 edm = Gauss3D->Edm();
524 else for (
unsigned int j = 0;
j < nParams;
j++)
if (
edm::isNotFinite(Gauss3D->Errors()[
j]) ==
true) { goodData = -1;
break; }
527 covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
528 covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
530 det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
531 Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
532 covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
533 if (det < 0.) { goodData = -1;
if (
internalDebug ==
true)
cout <<
"Negative determinant !" << endl; }
539 for (
unsigned int i = 0; i < nParams; i++)
541 vals->operator[](
i) = Gauss3D->X()[
i];
542 vals->operator[](i+nParams) = Gauss3D->Errors()[
i];
double Gauss3DFunc(const double *par)