3 #ifdef STANDALONE_FITTER 17 double sum_of_weights;
18 double number_of_hits;
19 bool weight_alignment;
21 double residual_x(
double delta_x,
32 double residual_dxdz) {
33 return delta_x - track_dxdz * delta_z - track_y * track_dxdz * delta_phix + track_x * track_dxdz * delta_phiy -
34 track_y * delta_phiz + residual_dxdz * alphax;
37 double residual_y(
double delta_x,
48 double residual_dydz) {
49 return delta_y - track_dydz * delta_z - track_y * track_dydz * delta_phix + track_x * track_dydz * delta_phiy +
50 track_x * delta_phiz + residual_dydz * alphay;
53 double residual_dxdz(
double delta_x,
63 return -track_dxdz * track_dydz * delta_phix + (1. + track_dxdz * track_dxdz) * delta_phiy -
64 track_dydz * delta_phiz;
67 double residual_dydz(
double delta_x,
77 return -(1. + track_dydz * track_dydz) * delta_phix + track_dxdz * track_dydz * delta_phiy +
78 track_dxdz * delta_phiz;
81 Double_t residual_x_trackx_TF1(Double_t *
xx, Double_t *
p) {
82 return 10. * residual_x(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
xx[0],
p[7],
p[8],
p[9],
p[10],
p[11]);
84 Double_t residual_x_tracky_TF1(Double_t *
xx, Double_t *
p) {
85 return 10. * residual_x(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
xx[0],
p[8],
p[9],
p[10],
p[11]);
87 Double_t residual_x_trackdxdz_TF1(Double_t *
xx, Double_t *
p) {
88 return 10. * residual_x(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
xx[0],
p[9],
p[10],
p[11]);
90 Double_t residual_x_trackdydz_TF1(Double_t *
xx, Double_t *
p) {
91 return 10. * residual_x(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
p[8],
xx[0],
p[10],
p[11]);
94 Double_t residual_y_trackx_TF1(Double_t *
xx, Double_t *
p) {
95 return 10. * residual_y(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
xx[0],
p[7],
p[8],
p[9],
p[12],
p[13]);
97 Double_t residual_y_tracky_TF1(Double_t *
xx, Double_t *
p) {
98 return 10. * residual_y(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
xx[0],
p[8],
p[9],
p[12],
p[13]);
100 Double_t residual_y_trackdxdz_TF1(Double_t *
xx, Double_t *
p) {
101 return 10. * residual_y(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
xx[0],
p[9],
p[12],
p[13]);
103 Double_t residual_y_trackdydz_TF1(Double_t *
xx, Double_t *
p) {
104 return 10. * residual_y(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
p[8],
xx[0],
p[12],
p[13]);
107 Double_t residual_dxdz_trackx_TF1(Double_t *
xx, Double_t *
p) {
108 return 1000. * residual_dxdz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
xx[0],
p[7],
p[8],
p[9]);
110 Double_t residual_dxdz_tracky_TF1(Double_t *
xx, Double_t *
p) {
111 return 1000. * residual_dxdz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
xx[0],
p[8],
p[9]);
113 Double_t residual_dxdz_trackdxdz_TF1(Double_t *
xx, Double_t *
p) {
114 return 1000. * residual_dxdz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
xx[0],
p[9]);
116 Double_t residual_dxdz_trackdydz_TF1(Double_t *
xx, Double_t *
p) {
117 return 1000. * residual_dxdz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
p[8],
xx[0]);
120 Double_t residual_dydz_trackx_TF1(Double_t *
xx, Double_t *
p) {
121 return 1000. * residual_dydz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
xx[0],
p[7],
p[8],
p[9]);
123 Double_t residual_dydz_tracky_TF1(Double_t *
xx, Double_t *
p) {
124 return 1000. * residual_dydz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
xx[0],
p[8],
p[9]);
126 Double_t residual_dydz_trackdxdz_TF1(Double_t *
xx, Double_t *
p) {
127 return 1000. * residual_dydz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
xx[0],
p[9]);
129 Double_t residual_dydz_trackdydz_TF1(Double_t *
xx, Double_t *
p) {
130 return 1000. * residual_dydz(
p[0],
p[1],
p[2],
p[3],
p[4],
p[5],
p[6],
p[7],
p[8],
xx[0]);
168 double coefX = alphax, coefY = alphay;
172 double residXpeak = residual_x(
173 alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, coefX, resslopeX);
174 double residYpeak = residual_y(
175 alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, coefY, resslopeY);
177 residual_dxdz(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
179 residual_dydz(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
181 double weight = (1. / redchi2) * number_of_hits / sum_of_weights;
182 if (!weight_alignment)
185 if (!weight_alignment || TMath::Prob(redchi2 * 12, 12) < 0.99)
213 residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax);
215 residY, resslopeY, residYpeak, slopeYpeak, resYsigma, slopeYsigma, alphay);
218 residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax);
225 residX, resslopeX, residXpeak, slopeXpeak, resXsigma, slopeXsigma, alphax);
272 double redchi2 = (*resiter)[
kRedChi2];
273 if (TMath::Prob(redchi2 * 12, 12) < 0.99) {
274 sum_of_weights += 1. / redchi2;
275 number_of_hits += 1.;
278 sum_of_weights += 1.;
279 number_of_hits += 1.;
282 return sum_of_weights;
289 double resx_std = 0.5;
290 double resy_std = 3.0;
291 double resslopex_std = 0.002;
292 double resslopey_std = 0.005;
326 double starts[16] = {0.,
341 0.1 * resslopey_std};
342 double steps[16] = {0.1,
350 0.001 * resslopex_std,
351 0.001 * resslopey_std,
356 0.01 * resslopex_std,
357 0.01 * resslopey_std};
358 double lows[16] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., -1., -1., 0., 0., 0., 0.};
359 double highs[16] = {0., 0., 0., 0., 0., 0., 10., 10., 0.1, 0.1, 1., 1., 0., 0., 0., 0.};
361 std::vector<int>
num(nums, nums + 6);
363 std::vector<double>
start(starts, starts + 6);
365 std::vector<double>
low(lows, lows + 6);
366 std::vector<double>
high(highs, highs + 6);
373 for (ni = 0; ni < 4; ni++)
386 for (ni = 0; ni < 3; ni++)
398 for (ni = 0; ni < 2; ni++)
431 for (
int i = 0;
i < ni;
i++) {
446 double mean_residualx = 0., mean_residualy = 0., mean_resslopex = 0., mean_resslopey = 0.;
447 double mean_trackx = 0., mean_tracky = 0., mean_trackdxdz = 0., mean_trackdydz = 0.;
451 const double redchi2 = (*rit)[
kRedChi2];
452 double weight = 1. / redchi2;
458 double factor_w = 1. / (sum_w +
weight);
459 mean_residualx = factor_w * (sum_w * mean_residualx +
weight * (*rit)[
kResidX]);
460 mean_residualy = factor_w * (sum_w * mean_residualy +
weight * (*rit)[
kResidY]);
461 mean_resslopex = factor_w * (sum_w * mean_resslopex +
weight * (*rit)[
kResSlopeX]);
462 mean_resslopey = factor_w * (sum_w * mean_resslopey +
weight * (*rit)[
kResSlopeY]);
463 mean_trackx = factor_w * (sum_w * mean_trackx +
weight * (*rit)[
kPositionX]);
464 mean_tracky = factor_w * (sum_w * mean_tracky +
weight * (*rit)[
kPositionY]);
465 mean_trackdxdz = factor_w * (sum_w * mean_trackdxdz +
weight * (*rit)[
kAngleX]);
466 mean_trackdydz = factor_w * (sum_w * mean_trackdydz +
weight * (*rit)[
kAngleY]);
471 std::string name_x, name_y, name_dxdz, name_dydz, name_x_raw, name_y_raw, name_dxdz_raw, name_dydz_raw, name_x_cut,
472 name_y_cut, name_alphax, name_alphay;
473 std::string name_x_trackx, name_y_trackx, name_dxdz_trackx, name_dydz_trackx;
474 std::string name_x_tracky, name_y_tracky, name_dxdz_tracky, name_dydz_tracky;
475 std::string name_x_trackdxdz, name_y_trackdxdz, name_dxdz_trackdxdz, name_dydz_trackdxdz;
476 std::string name_x_trackdydz, name_y_trackdydz, name_dxdz_trackdydz, name_dydz_trackdydz;
478 name_x =
name +
"_x";
479 name_y =
name +
"_y";
480 name_dxdz =
name +
"_dxdz";
481 name_dydz =
name +
"_dydz";
482 name_x_raw =
name +
"_x_raw";
483 name_y_raw =
name +
"_y_raw";
484 name_dxdz_raw =
name +
"_dxdz_raw";
485 name_dydz_raw =
name +
"_dydz_raw";
486 name_x_cut =
name +
"_x_cut";
487 name_y_cut =
name +
"_y_cut";
488 name_alphax =
name +
"_alphax";
489 name_alphay =
name +
"_alphay";
490 name_x_trackx =
name +
"_x_trackx";
491 name_y_trackx =
name +
"_y_trackx";
492 name_dxdz_trackx =
name +
"_dxdz_trackx";
493 name_dydz_trackx =
name +
"_dydz_trackx";
494 name_x_tracky =
name +
"_x_tracky";
495 name_y_tracky =
name +
"_y_tracky";
496 name_dxdz_tracky =
name +
"_dxdz_tracky";
497 name_dydz_tracky =
name +
"_dydz_tracky";
498 name_x_trackdxdz =
name +
"_x_trackdxdz";
499 name_y_trackdxdz =
name +
"_y_trackdxdz";
500 name_dxdz_trackdxdz =
name +
"_dxdz_trackdxdz";
501 name_dydz_trackdxdz =
name +
"_dydz_trackdxdz";
502 name_x_trackdydz =
name +
"_x_trackdydz";
503 name_y_trackdydz =
name +
"_y_trackdydz";
504 name_dxdz_trackdydz =
name +
"_dxdz_trackdydz";
505 name_dydz_trackdydz =
name +
"_dydz_trackdydz";
510 double min_x = -100., max_x = 100.;
511 double min_y = -100., max_y = 100.;
512 double min_dxdz = -75., max_dxdz = 75.;
513 double min_dydz = -150., max_dydz = 150.;
514 double min_trackx = -
width / 2., max_trackx =
width / 2.;
515 double min_tracky = -length / 2., max_tracky = length / 2.;
516 double min_trackdxdz = -1.5, max_trackdxdz = 1.5;
517 double min_trackdydz = -1.5, max_trackdydz = 1.5;
519 TH1F *hist_x =
dir->make<TH1F>(name_x.c_str(),
"",
bins, min_x, max_x);
520 TH1F *hist_y =
dir->make<TH1F>(name_y.c_str(),
"",
bins, min_y, max_y);
521 TH1F *hist_dxdz =
dir->make<TH1F>(name_dxdz.c_str(),
"",
bins, min_dxdz, max_dxdz);
522 TH1F *hist_dydz =
dir->make<TH1F>(name_dydz.c_str(),
"",
bins, min_dydz, max_dydz);
523 TH1F *hist_x_raw =
dir->make<TH1F>(name_x_raw.c_str(),
"",
bins, min_x, max_x);
524 TH1F *hist_y_raw =
dir->make<TH1F>(name_y_raw.c_str(),
"",
bins, min_y, max_y);
525 TH1F *hist_dxdz_raw =
dir->make<TH1F>(name_dxdz_raw.c_str(),
"",
bins, min_dxdz, max_dxdz);
526 TH1F *hist_dydz_raw =
dir->make<TH1F>(name_dydz_raw.c_str(),
"",
bins, min_dydz, max_dydz);
527 TH1F *hist_x_cut =
dir->make<TH1F>(name_x_cut.c_str(),
"",
bins, min_x, max_x);
528 TH1F *hist_y_cut =
dir->make<TH1F>(name_y_cut.c_str(),
"",
bins, min_y, max_y);
529 TH2F *hist_alphax =
dir->make<TH2F>(name_alphax.c_str(),
"", 50, 50, 50, 50, -50., 50.);
530 TH2F *hist_alphay =
dir->make<TH2F>(name_alphay.c_str(),
"", 75, 100, 100, 75, -75., 75.);
532 TProfile *hist_x_trackx =
dir->make<TProfile>(name_x_trackx.c_str(),
"", 50, min_trackx, max_trackx, min_x, max_x);
533 TProfile *hist_y_trackx =
dir->make<TProfile>(name_y_trackx.c_str(),
"", 50, min_trackx, max_trackx, min_y, max_y);
534 TProfile *hist_dxdz_trackx =
535 dir->make<TProfile>(name_dxdz_trackx.c_str(),
"", 50, min_trackx, max_trackx, min_dxdz, max_dxdz);
536 TProfile *hist_dydz_trackx =
537 dir->make<TProfile>(name_dydz_trackx.c_str(),
"", 50, min_trackx, max_trackx, min_dydz, max_dydz);
538 TProfile *hist_x_tracky =
dir->make<TProfile>(name_x_tracky.c_str(),
"", 50, min_tracky, max_tracky, min_x, max_x);
539 TProfile *hist_y_tracky =
dir->make<TProfile>(name_y_tracky.c_str(),
"", 50, min_tracky, max_tracky, min_y, max_y);
540 TProfile *hist_dxdz_tracky =
541 dir->make<TProfile>(name_dxdz_tracky.c_str(),
"", 50, min_tracky, max_tracky, min_dxdz, max_dxdz);
542 TProfile *hist_dydz_tracky =
543 dir->make<TProfile>(name_dydz_tracky.c_str(),
"", 50, min_tracky, max_tracky, min_dydz, max_dydz);
544 TProfile *hist_x_trackdxdz =
545 dir->make<TProfile>(name_x_trackdxdz.c_str(),
"", 250, min_trackdxdz, max_trackdxdz, min_x, max_x);
546 TProfile *hist_y_trackdxdz =
547 dir->make<TProfile>(name_y_trackdxdz.c_str(),
"", 250, min_trackdxdz, max_trackdxdz, min_y, max_y);
548 TProfile *hist_dxdz_trackdxdz =
549 dir->make<TProfile>(name_dxdz_trackdxdz.c_str(),
"", 250, min_trackdxdz, max_trackdxdz, min_dxdz, max_dxdz);
550 TProfile *hist_dydz_trackdxdz =
551 dir->make<TProfile>(name_dydz_trackdxdz.c_str(),
"", 250, min_trackdxdz, max_trackdxdz, min_dydz, max_dydz);
552 TProfile *hist_x_trackdydz =
553 dir->make<TProfile>(name_x_trackdydz.c_str(),
"", 250, min_trackdydz, max_trackdydz, min_x, max_x);
554 TProfile *hist_y_trackdydz =
555 dir->make<TProfile>(name_y_trackdydz.c_str(),
"", 250, min_trackdydz, max_trackdydz, min_y, max_y);
556 TProfile *hist_dxdz_trackdydz =
557 dir->make<TProfile>(name_dxdz_trackdydz.c_str(),
"", 250, min_trackdydz, max_trackdydz, min_dxdz, max_dxdz);
558 TProfile *hist_dydz_trackdydz =
559 dir->make<TProfile>(name_dydz_trackdydz.c_str(),
"", 250, min_trackdydz, max_trackdydz, min_dydz, max_dydz);
561 hist_x_trackx->SetAxisRange(-10., 10.,
"Y");
562 hist_y_trackx->SetAxisRange(-20., 20.,
"Y");
563 hist_dxdz_trackx->SetAxisRange(-10., 10.,
"Y");
564 hist_dydz_trackx->SetAxisRange(-20., 20.,
"Y");
565 hist_x_tracky->SetAxisRange(-10., 10.,
"Y");
566 hist_y_tracky->SetAxisRange(-20., 20.,
"Y");
567 hist_dxdz_tracky->SetAxisRange(-10., 10.,
"Y");
568 hist_dydz_tracky->SetAxisRange(-20., 20.,
"Y");
569 hist_x_trackdxdz->SetAxisRange(-10., 10.,
"Y");
570 hist_y_trackdxdz->SetAxisRange(-20., 20.,
"Y");
571 hist_dxdz_trackdxdz->SetAxisRange(-10., 10.,
"Y");
572 hist_dydz_trackdxdz->SetAxisRange(-20., 20.,
"Y");
573 hist_x_trackdydz->SetAxisRange(-10., 10.,
"Y");
574 hist_y_trackdydz->SetAxisRange(-20., 20.,
"Y");
575 hist_dxdz_trackdydz->SetAxisRange(-10., 10.,
"Y");
576 hist_dydz_trackdydz->SetAxisRange(-20., 20.,
"Y");
582 name_alphax +=
"_fit";
583 name_alphay +=
"_fit";
584 name_x_trackx +=
"_fit";
585 name_y_trackx +=
"_fit";
586 name_dxdz_trackx +=
"_fit";
587 name_dydz_trackx +=
"_fit";
588 name_x_tracky +=
"_fit";
589 name_y_tracky +=
"_fit";
590 name_dxdz_tracky +=
"_fit";
591 name_dydz_tracky +=
"_fit";
592 name_x_trackdxdz +=
"_fit";
593 name_y_trackdxdz +=
"_fit";
594 name_dxdz_trackdxdz +=
"_fit";
595 name_dydz_trackdxdz +=
"_fit";
596 name_x_trackdydz +=
"_fit";
597 name_y_trackdydz +=
"_fit";
598 name_dxdz_trackdydz +=
"_fit";
599 name_dydz_trackdydz +=
"_fit";
601 TF1 *fit_x =
nullptr;
602 TF1 *fit_y =
nullptr;
603 TF1 *fit_dxdz =
nullptr;
604 TF1 *fit_dydz =
nullptr;
609 fit_x->SetParErrors(er_x);
613 fit_y->SetParErrors(er_y);
615 fit_dxdz->SetParameters(
618 fit_dxdz->SetParErrors(er_dxdz);
620 fit_dydz->SetParameters(
623 fit_dydz->SetParErrors(er_dydz);
626 fit_x->SetParameters(sum_of_weights * (max_x - min_x) /
bins,
631 fit_y->SetParameters(sum_of_weights * (max_y - min_y) /
bins,
636 fit_dxdz->SetParameters(sum_of_weights * (max_dxdz - min_dxdz) /
bins,
641 fit_dydz->SetParameters(sum_of_weights * (max_dydz - min_dydz) /
bins,
647 fit_x->SetParameters(sum_of_weights * (max_x - min_x) /
bins,
652 fit_y->SetParameters(sum_of_weights * (max_y - min_y) /
bins,
657 fit_dxdz->SetParameters(sum_of_weights * (max_dxdz - min_dxdz) /
bins,
662 fit_dydz->SetParameters(sum_of_weights * (max_dydz - min_dydz) /
bins,
672 fit_dxdz->SetParameters(
675 fit_dydz->SetParameters(
681 fit_x->SetLineColor(2);
682 fit_x->SetLineWidth(2);
684 fit_y->SetLineColor(2);
685 fit_y->SetLineWidth(2);
687 fit_dxdz->SetLineColor(2);
688 fit_dxdz->SetLineWidth(2);
690 fit_dydz->SetLineColor(2);
691 fit_dydz->SetLineWidth(2);
694 TF1 *fit_alphax =
new TF1(name_alphax.c_str(),
"[0] + x*[1]", min_dxdz, max_dxdz);
695 TF1 *fit_alphay =
new TF1(name_alphay.c_str(),
"[0] + x*[1]", min_dydz, max_dydz);
703 bX = 1. / (
sy /
sx *
r);
704 aX = -bX * mean_resslopex;
712 bY = 1. / (
sy /
sx *
r);
713 aY = -bY * mean_resslopey;
716 fit_alphax->SetParameters(aX, bX);
717 fit_alphay->SetParameters(aY, bY);
719 fit_alphax->SetLineColor(2);
720 fit_alphax->SetLineWidth(2);
722 fit_alphay->SetLineColor(2);
723 fit_alphay->SetLineWidth(2);
726 TProfile *fit_x_trackx =
dir->make<TProfile>(name_x_trackx.c_str(),
"", 100, min_trackx, max_trackx);
727 TProfile *fit_y_trackx =
dir->make<TProfile>(name_y_trackx.c_str(),
"", 100, min_trackx, max_trackx);
728 TProfile *fit_dxdz_trackx =
dir->make<TProfile>(name_dxdz_trackx.c_str(),
"", 100, min_trackx, max_trackx);
729 TProfile *fit_dydz_trackx =
dir->make<TProfile>(name_dydz_trackx.c_str(),
"", 100, min_trackx, max_trackx);
730 TProfile *fit_x_tracky =
dir->make<TProfile>(name_x_tracky.c_str(),
"", 100, min_tracky, max_tracky);
731 TProfile *fit_y_tracky =
dir->make<TProfile>(name_y_tracky.c_str(),
"", 100, min_tracky, max_tracky);
732 TProfile *fit_dxdz_tracky =
dir->make<TProfile>(name_dxdz_tracky.c_str(),
"", 100, min_tracky, max_tracky);
733 TProfile *fit_dydz_tracky =
dir->make<TProfile>(name_dydz_tracky.c_str(),
"", 100, min_tracky, max_tracky);
734 TProfile *fit_x_trackdxdz =
dir->make<TProfile>(name_x_trackdxdz.c_str(),
"", 500, min_trackdxdz, max_trackdxdz);
735 TProfile *fit_y_trackdxdz =
dir->make<TProfile>(name_y_trackdxdz.c_str(),
"", 500, min_trackdxdz, max_trackdxdz);
736 TProfile *fit_dxdz_trackdxdz =
737 dir->make<TProfile>(name_dxdz_trackdxdz.c_str(),
"", 500, min_trackdxdz, max_trackdxdz);
738 TProfile *fit_dydz_trackdxdz =
739 dir->make<TProfile>(name_dydz_trackdxdz.c_str(),
"", 500, min_trackdxdz, max_trackdxdz);
740 TProfile *fit_x_trackdydz =
dir->make<TProfile>(name_x_trackdydz.c_str(),
"", 500, min_trackdydz, max_trackdydz);
741 TProfile *fit_y_trackdydz =
dir->make<TProfile>(name_y_trackdydz.c_str(),
"", 500, min_trackdydz, max_trackdydz);
742 TProfile *fit_dxdz_trackdydz =
743 dir->make<TProfile>(name_dxdz_trackdydz.c_str(),
"", 500, min_trackdydz, max_trackdydz);
744 TProfile *fit_dydz_trackdydz =
745 dir->make<TProfile>(name_dydz_trackdydz.c_str(),
"", 500, min_trackdydz, max_trackdydz);
747 fit_x_trackx->SetLineColor(2);
748 fit_x_trackx->SetLineWidth(2);
749 fit_y_trackx->SetLineColor(2);
750 fit_y_trackx->SetLineWidth(2);
751 fit_dxdz_trackx->SetLineColor(2);
752 fit_dxdz_trackx->SetLineWidth(2);
753 fit_dydz_trackx->SetLineColor(2);
754 fit_dydz_trackx->SetLineWidth(2);
755 fit_x_tracky->SetLineColor(2);
756 fit_x_tracky->SetLineWidth(2);
757 fit_y_tracky->SetLineColor(2);
758 fit_y_tracky->SetLineWidth(2);
759 fit_dxdz_tracky->SetLineColor(2);
760 fit_dxdz_tracky->SetLineWidth(2);
761 fit_dydz_tracky->SetLineColor(2);
762 fit_dydz_tracky->SetLineWidth(2);
763 fit_x_trackdxdz->SetLineColor(2);
764 fit_x_trackdxdz->SetLineWidth(2);
765 fit_y_trackdxdz->SetLineColor(2);
766 fit_y_trackdxdz->SetLineWidth(2);
767 fit_dxdz_trackdxdz->SetLineColor(2);
768 fit_dxdz_trackdxdz->SetLineWidth(2);
769 fit_dydz_trackdxdz->SetLineColor(2);
770 fit_dydz_trackdxdz->SetLineWidth(2);
771 fit_x_trackdydz->SetLineColor(2);
772 fit_x_trackdydz->SetLineWidth(2);
773 fit_y_trackdydz->SetLineColor(2);
774 fit_y_trackdydz->SetLineWidth(2);
775 fit_dxdz_trackdydz->SetLineColor(2);
776 fit_dxdz_trackdydz->SetLineWidth(2);
777 fit_dydz_trackdydz->SetLineColor(2);
778 fit_dydz_trackdydz->SetLineWidth(2);
780 name_x_trackx +=
"line";
781 name_y_trackx +=
"line";
782 name_dxdz_trackx +=
"line";
783 name_dydz_trackx +=
"line";
784 name_x_tracky +=
"line";
785 name_y_tracky +=
"line";
786 name_dxdz_tracky +=
"line";
787 name_dydz_tracky +=
"line";
788 name_x_trackdxdz +=
"line";
789 name_y_trackdxdz +=
"line";
790 name_dxdz_trackdxdz +=
"line";
791 name_dydz_trackdxdz +=
"line";
792 name_x_trackdydz +=
"line";
793 name_y_trackdydz +=
"line";
794 name_dxdz_trackdydz +=
"line";
795 name_dydz_trackdydz +=
"line";
797 TF1 *fitline_x_trackx =
new TF1(name_x_trackx.c_str(), residual_x_trackx_TF1, min_trackx, max_trackx, 14);
798 TF1 *fitline_y_trackx =
new TF1(name_y_trackx.c_str(), residual_y_trackx_TF1, min_trackx, max_trackx, 14);
799 TF1 *fitline_dxdz_trackx =
new TF1(name_dxdz_trackx.c_str(), residual_dxdz_trackx_TF1, min_trackx, max_trackx, 14);
800 TF1 *fitline_dydz_trackx =
new TF1(name_dydz_trackx.c_str(), residual_dydz_trackx_TF1, min_trackx, max_trackx, 14);
801 TF1 *fitline_x_tracky =
new TF1(name_x_tracky.c_str(), residual_x_tracky_TF1, min_tracky, max_tracky, 14);
802 TF1 *fitline_y_tracky =
new TF1(name_y_tracky.c_str(), residual_y_tracky_TF1, min_tracky, max_tracky, 14);
803 TF1 *fitline_dxdz_tracky =
new TF1(name_dxdz_tracky.c_str(), residual_dxdz_tracky_TF1, min_tracky, max_tracky, 14);
804 TF1 *fitline_dydz_tracky =
new TF1(name_dydz_tracky.c_str(), residual_dydz_tracky_TF1, min_tracky, max_tracky, 14);
805 TF1 *fitline_x_trackdxdz =
806 new TF1(name_x_trackdxdz.c_str(), residual_x_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
807 TF1 *fitline_y_trackdxdz =
808 new TF1(name_y_trackdxdz.c_str(), residual_y_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
809 TF1 *fitline_dxdz_trackdxdz =
810 new TF1(name_dxdz_trackdxdz.c_str(), residual_dxdz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
811 TF1 *fitline_dydz_trackdxdz =
812 new TF1(name_dydz_trackdxdz.c_str(), residual_dydz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
813 TF1 *fitline_x_trackdydz =
814 new TF1(name_x_trackdydz.c_str(), residual_x_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
815 TF1 *fitline_y_trackdydz =
816 new TF1(name_y_trackdydz.c_str(), residual_y_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
817 TF1 *fitline_dxdz_trackdydz =
818 new TF1(name_dxdz_trackdydz.c_str(), residual_dxdz_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
819 TF1 *fitline_dydz_trackdydz =
820 new TF1(name_dydz_trackdydz.c_str(), residual_dydz_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
822 std::vector<TF1 *> fitlines;
823 fitlines.push_back(fitline_x_trackx);
824 fitlines.push_back(fitline_y_trackx);
825 fitlines.push_back(fitline_dxdz_trackx);
826 fitlines.push_back(fitline_dydz_trackx);
827 fitlines.push_back(fitline_x_tracky);
828 fitlines.push_back(fitline_y_tracky);
829 fitlines.push_back(fitline_dxdz_tracky);
830 fitlines.push_back(fitline_dydz_tracky);
831 fitlines.push_back(fitline_x_trackdxdz);
832 fitlines.push_back(fitline_y_trackdxdz);
833 fitlines.push_back(fitline_dxdz_trackdxdz);
834 fitlines.push_back(fitline_dydz_trackdxdz);
835 fitlines.push_back(fitline_x_trackdydz);
836 fitlines.push_back(fitline_y_trackdydz);
837 fitlines.push_back(fitline_dxdz_trackdydz);
838 fitlines.push_back(fitline_dydz_trackdydz);
855 fitparameters[10] = fitparameters[12] = 0.;
857 for (std::vector<TF1 *>::const_iterator itr = fitlines.begin(); itr != fitlines.end(); itr++) {
858 (*itr)->SetParameters(fitparameters);
859 (*itr)->SetLineColor(2);
860 (*itr)->SetLineWidth(2);
865 const double residX = (*resiter)[
kResidX];
866 const double residY = (*resiter)[
kResidY];
867 const double resslopeX = (*resiter)[
kResSlopeX];
868 const double resslopeY = (*resiter)[
kResSlopeY];
869 const double positionX = (*resiter)[
kPositionX];
870 const double positionY = (*resiter)[
kPositionY];
871 const double angleX = (*resiter)[
kAngleX];
872 const double angleY = (*resiter)[
kAngleY];
873 const double redchi2 = (*resiter)[
kRedChi2];
874 double weight = 1. / redchi2;
880 hist_alphax->Fill(1000. * resslopeX, 10. * residX);
881 hist_alphay->Fill(1000. * resslopeY, 10. * residY);
899 hist_x_trackx->Fill(positionX, 10. * residX,
weight);
900 hist_x_tracky->Fill(positionY, 10. * residX,
weight);
901 hist_x_trackdxdz->Fill(angleX, 10. * residX,
weight);
902 hist_x_trackdydz->Fill(angleY, 10. * residX,
weight);
903 fit_x_trackx->Fill(positionX, 10. * geom_residX,
weight);
904 fit_x_tracky->Fill(positionY, 10. * geom_residX,
weight);
905 fit_x_trackdxdz->Fill(angleX, 10. * geom_residX,
weight);
906 fit_x_trackdydz->Fill(angleY, 10. * geom_residX,
weight);
921 hist_y_trackx->Fill(positionX, 10. * residY,
weight);
922 hist_y_tracky->Fill(positionY, 10. * residY,
weight);
923 hist_y_trackdxdz->Fill(angleX, 10. * residY,
weight);
924 hist_y_trackdydz->Fill(angleY, 10. * residY,
weight);
925 fit_y_trackx->Fill(positionX, 10. * geom_residY,
weight);
926 fit_y_tracky->Fill(positionY, 10. * geom_residY,
weight);
927 fit_y_trackdxdz->Fill(angleX, 10. * geom_residY,
weight);
928 fit_y_trackdydz->Fill(angleY, 10. * geom_residY,
weight);
941 hist_dxdz_trackx->Fill(positionX, 1000. * resslopeX,
weight);
942 hist_dxdz_tracky->Fill(positionY, 1000. * resslopeX,
weight);
943 hist_dxdz_trackdxdz->Fill(angleX, 1000. * resslopeX,
weight);
944 hist_dxdz_trackdydz->Fill(angleY, 1000. * resslopeX,
weight);
945 fit_dxdz_trackx->Fill(positionX, 1000. * geom_resslopeX,
weight);
946 fit_dxdz_tracky->Fill(positionY, 1000. * geom_resslopeX,
weight);
947 fit_dxdz_trackdxdz->Fill(angleX, 1000. * geom_resslopeX,
weight);
948 fit_dxdz_trackdydz->Fill(angleY, 1000. * geom_resslopeX,
weight);
961 hist_dydz_trackx->Fill(positionX, 1000. * resslopeY,
weight);
962 hist_dydz_tracky->Fill(positionY, 1000. * resslopeY,
weight);
963 hist_dydz_trackdxdz->Fill(angleX, 1000. * resslopeY,
weight);
964 hist_dydz_trackdydz->Fill(angleY, 1000. * resslopeY,
weight);
965 fit_dydz_trackx->Fill(positionX, 1000. * geom_resslopeY,
weight);
966 fit_dydz_tracky->Fill(positionY, 1000. * geom_resslopeY,
weight);
967 fit_dydz_trackdxdz->Fill(angleX, 1000. * geom_resslopeY,
weight);
968 fit_dydz_trackdydz->Fill(angleY, 1000. * geom_resslopeY,
weight);
971 hist_x_raw->Fill(10. * residX);
972 hist_y_raw->Fill(10. * residY);
973 hist_dxdz_raw->Fill(1000. * resslopeX);
974 hist_dydz_raw->Fill(1000. * resslopeY);
975 if (fabs(resslopeX) < 0.005)
976 hist_x_cut->Fill(10. * residX);
977 if (fabs(resslopeY) < 0.030)
978 hist_y_cut->Fill(10. * residY);
983 for (
int i = 1;
i <= hist_x->GetNbinsX();
i++) {
984 double xi = hist_x->GetBinCenter(
i);
985 double yi = hist_x->GetBinContent(
i);
986 double yerri = hist_x->GetBinError(
i);
987 double yth = fit_x->Eval(
xi);
989 chi2 +=
pow((yth - yi) / yerri, 2);
993 for (
int i = 1;
i <= hist_y->GetNbinsX();
i++) {
994 double xi = hist_y->GetBinCenter(
i);
995 double yi = hist_y->GetBinContent(
i);
996 double yerri = hist_y->GetBinError(
i);
997 double yth = fit_y->Eval(
xi);
999 chi2 +=
pow((yth - yi) / yerri, 2);
1003 for (
int i = 1;
i <= hist_dxdz->GetNbinsX();
i++) {
1004 double xi = hist_dxdz->GetBinCenter(
i);
1005 double yi = hist_dxdz->GetBinContent(
i);
1006 double yerri = hist_dxdz->GetBinError(
i);
1007 double yth = fit_dxdz->Eval(
xi);
1009 chi2 +=
pow((yth - yi) / yerri, 2);
1013 for (
int i = 1;
i <= hist_dydz->GetNbinsX();
i++) {
1014 double xi = hist_dydz->GetBinCenter(
i);
1015 double yi = hist_dydz->GetBinContent(
i);
1016 double yerri = hist_dydz->GetBinError(
i);
1017 double yth = fit_dydz->Eval(
xi);
1019 chi2 +=
pow((yth - yi) / yerri, 2);
1030 TFile *
f =
new TFile(
fname.c_str());
1031 TTree *
t = (TTree *)
f->Get(
"mual_ttree");
1034 TFile *tmpf =
new TFile(
"small_tree_fit.root",
"recreate");
1038 TTree *
tt =
t->CopyTree(Form(
1039 "is_dt && ring_wheel==%d && station==%d && sector==%d && select==%d",
wheel,
station,
sector, (
bool)preselected));
1042 tt->SetBranchAddress(
"res_x", &
r.res_x);
1043 tt->SetBranchAddress(
"res_slope_x", &
r.res_slope_x);
1044 tt->SetBranchAddress(
"res_y", &
r.res_y);
1045 tt->SetBranchAddress(
"res_slope_y", &
r.res_slope_y);
1046 tt->SetBranchAddress(
"pos_x", &
r.pos_x);
1047 tt->SetBranchAddress(
"pos_y", &
r.pos_y);
1048 tt->SetBranchAddress(
"angle_x", &
r.angle_x);
1049 tt->SetBranchAddress(
"angle_y", &
r.angle_y);
1050 tt->SetBranchAddress(
"pz", &
r.pz);
1051 tt->SetBranchAddress(
"pt", &
r.pt);
1052 tt->SetBranchAddress(
"q", &
r.q);
1054 Long64_t nentries =
tt->GetEntries();
1055 for (Long64_t
i = 0;
i < nentries;
i++) {
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
double MuonResidualsFitter_logPureGaussian2D(double x, double y, double x0, double y0, double sx, double sy, double r)
bool fit(Alignable *ali) override
int residualsModel() const
std::vector< double * >::const_iterator residuals_begin() const
void inform(TMinuit *tMinuit) override
void fill(double *residual)
align::Scalar width() const
MuonResidualsFitter * fitter()
std::vector< double * >::const_iterator residuals_end() const
const std::string names[nVars_]
bool dofit(void(*fcn)(int &, double *, double &, double *, int), std::vector< int > &parNum, std::vector< std::string > &parName, std::vector< double > &start, std::vector< double > &step, std::vector< double > &low, std::vector< double > &high)
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
void correctBField() override
double plot(std::string name, TFileDirectory *dir, Alignable *ali) override
TTree * readNtuple(std::string fname, unsigned int wheel, unsigned int station, unsigned int sector, unsigned int preselected=1)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
double sumofweights() override
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
void fix(int parNum, bool dofix=true)
virtual void correctBField()=0
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
double errorerror(int parNum)
align::Scalar length() const
int useRes(int pattern=-1)
Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par)
void MuonResiduals6DOFFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)
Power< A, B >::type pow(const A &a, const B &b)