39 double nominal_beam_momentum)
40 : x_parametrisation(5, polynom_type,
"k"),
41 theta_x_parametrisation(5, polynom_type,
"k"),
42 y_parametrisation(5, polynom_type,
"k"),
43 theta_y_parametrisation(5, polynom_type,
"k") {
44 this->SetName(
name.c_str());
45 this->SetTitle(
title.c_str());
48 if (beam_direction ==
"lhcb1")
50 else if (beam_direction ==
"lhcb2")
69 double in_corrected[5];
70 if (
beam ==
lhcb1 || !invert_beam_coord_sytems) {
71 in_corrected[0] =
in[0];
72 in_corrected[1] =
in[1];
73 in_corrected[2] =
in[2];
74 in_corrected[3] =
in[3];
75 in_corrected[4] =
in[4];
77 in_corrected[0] = -
in[0];
78 in_corrected[1] = -
in[1];
79 in_corrected[2] =
in[2];
80 in_corrected[3] =
in[3];
81 in_corrected[4] =
in[4];
88 for (
int i = 0;
i < 5;
i++) {
89 if (in_corrected[
i] < (*min_var)(
i)) {
90 double dist =
TMath::Abs(((*min_var)(
i)-in_corrected[
i]) / ((*max_var)(
i) - (*min_var)(
i)));
91 res += 8 * (TMath::Exp(dist) - 1.0);
92 in_corrected[
i] = (*min_var)(
i);
93 }
else if (in_corrected[
i] > (*max_var)(
i)) {
94 double dist =
TMath::Abs((in_corrected[
i] - (*max_var)(
i)) / ((*max_var)(
i) - (*min_var)(
i)));
95 res += 8 * (TMath::Exp(dist) - 1.0);
96 in_corrected[
i] = (*max_var)(
i);
104 bool check_apertures,
105 bool invert_beam_coord_sytems)
const {
110 double in_corrected[5];
112 if (
beam ==
lhcb1 || !invert_beam_coord_sytems) {
113 in_corrected[0] =
in[0];
114 in_corrected[1] =
in[1];
115 in_corrected[2] =
in[2];
116 in_corrected[3] =
in[3];
117 in_corrected[4] =
in[4];
124 in_corrected[0] = -
in[0];
125 in_corrected[1] = -
in[1];
126 in_corrected[2] =
in[2];
127 in_corrected[3] =
in[3];
128 in_corrected[4] =
in[4];
136 if (check_apertures) {
146 bool check_apertures,
147 bool invert_beam_coord_sytems)
const
150 if (
in ==
nullptr ||
out ==
nullptr || !trained_)
153 bool res = CheckInputRange(
in);
154 double in_corrected[5];
156 if (
beam == lhcb1 || !invert_beam_coord_sytems) {
157 in_corrected[0] =
in[0];
158 in_corrected[1] =
in[1];
159 in_corrected[2] =
in[2];
160 in_corrected[3] =
in[3];
161 in_corrected[4] =
in[4];
162 out[0] = x_parametrisation.Eval(in_corrected);
163 out[1] = y_parametrisation.Eval(in_corrected);
165 in_corrected[0] = -
in[0];
166 in_corrected[1] = -
in[1];
167 in_corrected[2] =
in[2];
168 in_corrected[3] =
in[3];
169 in_corrected[4] =
in[4];
170 out[0] = -x_parametrisation.Eval(in_corrected);
171 out[1] = y_parametrisation.Eval(in_corrected);
174 if (check_apertures) {
175 for (
unsigned int i = 0;
i < apertures_.size();
i++) {
176 res =
res && apertures_[
i].CheckAperture(
in);
183 double in_momentum[3],
185 double out_momentum[3],
186 bool check_apertures,
187 double z2_z1_dist)
const {
190 double part_mom = 0.0;
191 for (
int i = 0;
i < 3;
i++)
192 part_mom += in_momentum[
i] * in_momentum[
i];
194 part_mom = TMath::Sqrt(part_mom);
206 out_pos[2] = in_pos[2] + z2_z1_dist;
211 out_momentum[2] = TMath::Sqrt(part_out_total_mom * part_out_total_mom - out_momentum[0] * out_momentum[0] -
212 out_momentum[1] * out_momentum[1]);
213 out_momentum[2] =
TMath::Sign(out_momentum[2], in_momentum[2]);
220 bool check_apertures,
221 bool invert_beam_coord_sytems)
const {
247 x_parametrisation(org.x_parametrisation),
248 theta_x_parametrisation(org.theta_x_parametrisation),
249 y_parametrisation(org.y_parametrisation),
250 theta_y_parametrisation(org.theta_y_parametrisation) {
269 TNamed::operator=(org);
291 if (inp_tree ==
nullptr)
313 std::string theta_x_out_lab = data_prefix +
"_theta_x_out";
315 std::string theta_y_out_lab = data_prefix +
"_theta_y_out";
316 std::string ksi_out_lab = data_prefix +
"_ksi_out";
318 std::string valid_out_lab = data_prefix +
"_valid_out";
321 inp_tree->SetBranchStatus(
"*",
false);
322 inp_tree->SetBranchStatus(x_in_lab.c_str(),
true);
323 inp_tree->SetBranchStatus(theta_x_in_lab.c_str(),
true);
324 inp_tree->SetBranchStatus(y_in_lab.c_str(),
true);
325 inp_tree->SetBranchStatus(theta_y_in_lab.c_str(),
true);
326 inp_tree->SetBranchStatus(ksi_in_lab.c_str(),
true);
327 inp_tree->SetBranchStatus(x_out_lab.c_str(),
true);
328 inp_tree->SetBranchStatus(theta_x_out_lab.c_str(),
true);
329 inp_tree->SetBranchStatus(y_out_lab.c_str(),
true);
330 inp_tree->SetBranchStatus(theta_y_out_lab.c_str(),
true);
331 inp_tree->SetBranchStatus(ksi_out_lab.c_str(),
true);
332 inp_tree->SetBranchStatus(valid_out_lab.c_str(),
true);
335 inp_tree->SetBranchAddress(x_in_lab.c_str(), &(in_var[0]));
336 inp_tree->SetBranchAddress(theta_x_in_lab.c_str(), &(in_var[1]));
337 inp_tree->SetBranchAddress(y_in_lab.c_str(), &(in_var[2]));
338 inp_tree->SetBranchAddress(theta_y_in_lab.c_str(), &(in_var[3]));
339 inp_tree->SetBranchAddress(ksi_in_lab.c_str(), &(in_var[4]));
340 inp_tree->SetBranchAddress(s_in_lab.c_str(), &(in_var[5]));
343 inp_tree->SetBranchAddress(x_out_lab.c_str(), &(out_var[0]));
344 inp_tree->SetBranchAddress(theta_x_out_lab.c_str(), &(out_var[1]));
345 inp_tree->SetBranchAddress(y_out_lab.c_str(), &(out_var[2]));
346 inp_tree->SetBranchAddress(theta_y_out_lab.c_str(), &(out_var[3]));
347 inp_tree->SetBranchAddress(ksi_out_lab.c_str(), &(out_var[4]));
348 inp_tree->SetBranchAddress(s_out_lab.c_str(), &(out_var[5]));
349 inp_tree->SetBranchAddress(valid_out_lab.c_str(), &(out_var[6]));
351 Long64_t entries = inp_tree->GetEntries();
353 inp_tree->SetBranchStatus(s_in_lab.c_str(),
true);
354 inp_tree->SetBranchStatus(s_out_lab.c_str(),
true);
355 inp_tree->GetEntry(0);
358 inp_tree->SetBranchStatus(s_in_lab.c_str(),
false);
359 inp_tree->SetBranchStatus(s_out_lab.c_str(),
false);
363 for (Long64_t
i = 0;
i < entries; ++
i) {
364 inp_tree->GetEntry(
i);
377 for (
int i = 0;
i < 4;
i++) {
378 double best_precision = 0.0;
380 best_precision = prec[
i];
413 if (max_degree < 1 || max_degree > 20)
417 Int_t mPowers[] = {1, 1, 0, 0, max_degree};
429 Int_t mPowers[] = {0, 0, 1, 1, max_degree};
445 if (max_degree < 1 || max_degree > 20)
452 std::vector<Int_t> term_literals;
453 term_literals.reserve(5000);
457 for (
int i = 0;
i <= max_degree; ++
i) {
458 term_literals.push_back(1);
459 term_literals.push_back(0);
460 term_literals.push_back(0);
461 term_literals.push_back(0);
462 term_literals.push_back(
i);
465 for (
int i = 0;
i <= max_degree; ++
i) {
466 term_literals.push_back(0);
467 term_literals.push_back(1);
468 term_literals.push_back(0);
469 term_literals.push_back(0);
470 term_literals.push_back(
i);
473 for (
int i = 0;
i <= max_degree; ++
i) {
474 term_literals.push_back(0);
475 term_literals.push_back(2);
476 term_literals.push_back(0);
477 term_literals.push_back(0);
478 term_literals.push_back(
i);
481 for (
int i = 0;
i <= max_degree; ++
i) {
482 term_literals.push_back(0);
483 term_literals.push_back(3);
484 term_literals.push_back(0);
485 term_literals.push_back(0);
486 term_literals.push_back(
i);
489 for (
int i = 0;
i <= max_degree; ++
i) {
490 term_literals.push_back(0);
491 term_literals.push_back(0);
492 term_literals.push_back(0);
493 term_literals.push_back(0);
494 term_literals.push_back(
i);
500 for (
int i = 0;
i <= max_degree; ++
i) {
501 term_literals.push_back(0);
502 term_literals.push_back(0);
503 term_literals.push_back(1);
504 term_literals.push_back(0);
505 term_literals.push_back(
i);
508 for (
int i = 0;
i <= max_degree; ++
i) {
509 term_literals.push_back(0);
510 term_literals.push_back(0);
511 term_literals.push_back(0);
512 term_literals.push_back(1);
513 term_literals.push_back(
i);
516 for (
int i = 0;
i <= max_degree; ++
i) {
517 term_literals.push_back(0);
518 term_literals.push_back(0);
519 term_literals.push_back(0);
520 term_literals.push_back(2);
521 term_literals.push_back(
i);
524 for (
int i = 0;
i <= max_degree; ++
i) {
525 term_literals.push_back(0);
526 term_literals.push_back(0);
527 term_literals.push_back(0);
528 term_literals.push_back(3);
529 term_literals.push_back(
i);
532 for (
int i = 0;
i <= max_degree; ++
i) {
533 term_literals.push_back(0);
534 term_literals.push_back(0);
535 term_literals.push_back(0);
536 term_literals.push_back(0);
537 term_literals.push_back(
i);
543 term_literals.push_back(1), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0),
544 term_literals.push_back(0);
545 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0),
546 term_literals.push_back(0);
547 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1),
548 term_literals.push_back(0);
549 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(1), term_literals.push_back(0),
550 term_literals.push_back(0);
551 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(1),
552 term_literals.push_back(0);
553 term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(1),
554 term_literals.push_back(0);
556 term_literals.push_back(1), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0),
557 term_literals.push_back(1);
558 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0),
559 term_literals.push_back(1);
560 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1),
561 term_literals.push_back(1);
562 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(1), term_literals.push_back(0),
563 term_literals.push_back(1);
564 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(1),
565 term_literals.push_back(1);
566 term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(1),
567 term_literals.push_back(1);
569 term_literals.push_back(1), term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(0),
570 term_literals.push_back(0);
571 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(0),
572 term_literals.push_back(0);
573 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(2),
574 term_literals.push_back(0);
575 term_literals.push_back(2), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0),
576 term_literals.push_back(0);
577 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(2), term_literals.push_back(0),
578 term_literals.push_back(0);
579 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(2),
580 term_literals.push_back(0);
581 term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0),
582 term_literals.push_back(0);
583 term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(1), term_literals.push_back(0),
584 term_literals.push_back(0);
585 term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(2),
586 term_literals.push_back(0);
587 term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1),
588 term_literals.push_back(0);
589 term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(1),
590 term_literals.push_back(0);
591 term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(1),
592 term_literals.push_back(0);
594 term_literals.push_back(1), term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(0),
595 term_literals.push_back(1);
596 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(0),
597 term_literals.push_back(1);
598 term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(2),
599 term_literals.push_back(1);
600 term_literals.push_back(2), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(0),
601 term_literals.push_back(1);
602 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(2), term_literals.push_back(0),
603 term_literals.push_back(1);
604 term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0), term_literals.push_back(2),
605 term_literals.push_back(1);
606 term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(0),
607 term_literals.push_back(1);
608 term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(1), term_literals.push_back(0),
609 term_literals.push_back(1);
610 term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1), term_literals.push_back(2),
611 term_literals.push_back(1);
612 term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(1),
613 term_literals.push_back(1);
614 term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(0), term_literals.push_back(1),
615 term_literals.push_back(1);
616 term_literals.push_back(0), term_literals.push_back(0), term_literals.push_back(2), term_literals.push_back(1),
617 term_literals.push_back(1);
620 std::vector<Int_t> powers;
621 powers.resize(term_literals.size());
623 for (
unsigned int i = 0;
i < term_literals.size(); ++
i) {
624 powers[
i] = term_literals[
i];
626 approximator.
SetPowers(&powers[0], term_literals.size() / 5);
630 if (inp_tree ==
nullptr || f_out ==
nullptr)
650 std::string theta_x_out_lab = data_prefix +
"_theta_x_out";
652 std::string theta_y_out_lab = data_prefix +
"_theta_y_out";
653 std::string ksi_out_lab = data_prefix +
"_ksi_out";
655 std::string valid_out_lab = data_prefix +
"_valid_out";
658 inp_tree->SetBranchStatus(
"*",
false);
659 inp_tree->SetBranchStatus(x_in_lab.c_str(),
true);
660 inp_tree->SetBranchStatus(theta_x_in_lab.c_str(),
true);
661 inp_tree->SetBranchStatus(y_in_lab.c_str(),
true);
662 inp_tree->SetBranchStatus(theta_y_in_lab.c_str(),
true);
663 inp_tree->SetBranchStatus(ksi_in_lab.c_str(),
true);
664 inp_tree->SetBranchStatus(x_out_lab.c_str(),
true);
665 inp_tree->SetBranchStatus(theta_x_out_lab.c_str(),
true);
666 inp_tree->SetBranchStatus(y_out_lab.c_str(),
true);
667 inp_tree->SetBranchStatus(theta_y_out_lab.c_str(),
true);
668 inp_tree->SetBranchStatus(ksi_out_lab.c_str(),
true);
669 inp_tree->SetBranchStatus(valid_out_lab.c_str(),
true);
672 inp_tree->SetBranchAddress(x_in_lab.c_str(), &(in_var[0]));
673 inp_tree->SetBranchAddress(theta_x_in_lab.c_str(), &(in_var[1]));
674 inp_tree->SetBranchAddress(y_in_lab.c_str(), &(in_var[2]));
675 inp_tree->SetBranchAddress(theta_y_in_lab.c_str(), &(in_var[3]));
676 inp_tree->SetBranchAddress(ksi_in_lab.c_str(), &(in_var[4]));
677 inp_tree->SetBranchAddress(s_in_lab.c_str(), &(in_var[5]));
680 inp_tree->SetBranchAddress(x_out_lab.c_str(), &(out_var[0]));
681 inp_tree->SetBranchAddress(theta_x_out_lab.c_str(), &(out_var[1]));
682 inp_tree->SetBranchAddress(y_out_lab.c_str(), &(out_var[2]));
683 inp_tree->SetBranchAddress(theta_y_out_lab.c_str(), &(out_var[3]));
684 inp_tree->SetBranchAddress(ksi_out_lab.c_str(), &(out_var[4]));
685 inp_tree->SetBranchAddress(s_out_lab.c_str(), &(out_var[5]));
686 inp_tree->SetBranchAddress(valid_out_lab.c_str(), &(out_var[6]));
690 TH2D *err_inp_cor_hists[4][5];
691 TH2D *err_out_cor_hists[4][5];
697 Long64_t entries = inp_tree->GetEntries();
699 for (Long64_t
i = 0;
i < entries; ++
i) {
701 inp_tree->GetEntry(
i);
713 WriteHistograms(err_hists, err_inp_cor_hists, err_out_cor_hists, f_out, base_out_dir);
721 std::vector<std::string> error_labels;
722 error_labels.push_back(
"x error");
723 error_labels.push_back(
"theta_x error");
724 error_labels.push_back(
"y error");
725 error_labels.push_back(
"theta_y error");
727 for (
int i = 0;
i < 4; ++
i) {
728 err_hists[
i] =
new TH1D(error_labels[
i].c_str(), error_labels[
i].c_str(), 100, -0.0000000001, 0.0000000001);
729 err_hists[
i]->SetXTitle(error_labels[
i].c_str());
730 err_hists[
i]->SetYTitle(
"counts");
731 err_hists[
i]->SetDirectory(
nullptr);
732 err_hists[
i]->SetCanExtend(TH1::kAllAxes);
737 TTree *inp_tree, TTree *out_tree)
739 if (inp_tree ==
nullptr || out_tree ==
nullptr)
742 Long64_t entries = inp_tree->GetEntries();
744 double parametrization_out[5];
746 inp_tree->SetBranchAddress(
"x", &(
entry[0]));
747 inp_tree->SetBranchAddress(
"theta_x", &(
entry[1]));
748 inp_tree->SetBranchAddress(
"y", &(
entry[2]));
749 inp_tree->SetBranchAddress(
"theta_y", &(
entry[3]));
750 inp_tree->SetBranchAddress(
"ksi", &(
entry[4]));
751 inp_tree->SetBranchAddress(
"mad_accept", &(
entry[5]));
752 inp_tree->SetBranchAddress(
"par_accept", &(
entry[6]));
754 out_tree->SetBranchAddress(
"x", &(
entry[0]));
755 out_tree->SetBranchAddress(
"theta_x", &(
entry[1]));
756 out_tree->SetBranchAddress(
"y", &(
entry[2]));
757 out_tree->SetBranchAddress(
"theta_y", &(
entry[3]));
758 out_tree->SetBranchAddress(
"ksi", &(
entry[4]));
759 out_tree->SetBranchAddress(
"mad_accept", &(
entry[5]));
760 out_tree->SetBranchAddress(
"par_accept", &(
entry[6]));
763 for (Long64_t
i = 0;
i < entries;
i++) {
764 inp_tree->GetEntry(
i);
780 std::vector<std::string> error_labels;
781 std::vector<std::string> data_labels;
783 error_labels.push_back(
"x error");
784 error_labels.push_back(
"theta_x error");
785 error_labels.push_back(
"y error");
786 error_labels.push_back(
"theta_y error");
788 data_labels.push_back(
"x input");
789 data_labels.push_back(
"theta_x input");
790 data_labels.push_back(
"y input");
791 data_labels.push_back(
"theta_y input");
792 data_labels.push_back(
"ksi input");
794 for (
int eri = 0; eri < 4; ++eri) {
795 for (
int dati = 0; dati < 5; ++dati) {
798 err_inp_cor_hists[eri][dati] =
799 new TH2D(
name.c_str(),
title.c_str(), 100, -0.0000000001, 0.0000000001, 100, -0.0000000001, 0.0000000001);
800 err_inp_cor_hists[eri][dati]->SetXTitle(error_labels[eri].c_str());
801 err_inp_cor_hists[eri][dati]->SetYTitle(data_labels[dati].c_str());
802 err_inp_cor_hists[eri][dati]->SetDirectory(
nullptr);
803 err_inp_cor_hists[eri][dati]->SetCanExtend(TH1::kAllAxes);
809 std::vector<std::string> error_labels;
810 std::vector<std::string> data_labels;
812 error_labels.push_back(
"x error");
813 error_labels.push_back(
"theta_x error");
814 error_labels.push_back(
"y error");
815 error_labels.push_back(
"theta_y error");
817 data_labels.push_back(
"x output");
818 data_labels.push_back(
"theta_x output");
819 data_labels.push_back(
"y output");
820 data_labels.push_back(
"theta_y output");
821 data_labels.push_back(
"ksi output");
823 for (
int eri = 0; eri < 4; ++eri) {
824 for (
int dati = 0; dati < 5; ++dati) {
827 err_out_cor_hists[eri][dati] =
828 new TH2D(
name.c_str(),
title.c_str(), 100, -0.0000000001, 0.0000000001, 100, -0.0000000001, 0.0000000001);
829 err_out_cor_hists[eri][dati]->SetXTitle(error_labels[eri].c_str());
830 err_out_cor_hists[eri][dati]->SetYTitle(data_labels[dati].c_str());
831 err_out_cor_hists[eri][dati]->SetDirectory(
nullptr);
832 err_out_cor_hists[eri][dati]->SetCanExtend(TH1::kAllAxes);
838 for (
int i = 0;
i < 4; ++
i) {
844 for (
int eri = 0; eri < 4; ++eri) {
845 for (
int dati = 0; dati < 5; ++dati) {
846 err_cor_hists[eri][dati]->Fill(
errors[eri],
var[dati]);
852 for (
int i = 0;
i < 4; ++
i) {
858 for (
int eri = 0; eri < 4; ++eri) {
859 for (
int dati = 0; dati < 5; ++dati) {
860 delete err_cor_hists[eri][dati];
866 TH2D *err_inp_cor_hists[4][5],
867 TH2D *err_out_cor_hists[4][5],
870 if (f_out ==
nullptr)
874 if (!gDirectory->cd(base_out_dir.c_str()))
875 gDirectory->mkdir(base_out_dir.c_str());
877 gDirectory->cd(base_out_dir.c_str());
878 gDirectory->mkdir(this->GetName());
879 gDirectory->cd(this->GetName());
880 gDirectory->mkdir(
"x");
881 gDirectory->mkdir(
"theta_x");
882 gDirectory->mkdir(
"y");
883 gDirectory->mkdir(
"theta_y");
886 err_hists[0]->Write(
"", TObject::kWriteDelete);
887 for (
int i = 0;
i < 5;
i++) {
888 err_inp_cor_hists[0][
i]->Write(
"", TObject::kWriteDelete);
889 err_out_cor_hists[0][
i]->Write(
"", TObject::kWriteDelete);
892 gDirectory->cd(
"..");
893 gDirectory->cd(
"theta_x");
894 err_hists[1]->Write(
"", TObject::kWriteDelete);
895 for (
int i = 0;
i < 5;
i++) {
896 err_inp_cor_hists[1][
i]->Write(
"", TObject::kWriteDelete);
897 err_out_cor_hists[1][
i]->Write(
"", TObject::kWriteDelete);
900 gDirectory->cd(
"..");
902 err_hists[2]->Write(
"", TObject::kWriteDelete);
903 for (
int i = 0;
i < 5;
i++) {
904 err_inp_cor_hists[2][
i]->Write(
"", TObject::kWriteDelete);
905 err_out_cor_hists[2][
i]->Write(
"", TObject::kWriteDelete);
908 gDirectory->cd(
"..");
909 gDirectory->cd(
"theta_y");
910 err_hists[3]->Write(
"", TObject::kWriteDelete);
911 for (
int i = 0;
i < 5;
i++) {
912 err_inp_cor_hists[3][
i]->Write(
"", TObject::kWriteDelete);
913 err_out_cor_hists[3][
i]->Write(
"", TObject::kWriteDelete);
915 gDirectory->cd(
"..");
916 gDirectory->cd(
"..");
923 edm::LogInfo(
"LHCOpticsApproximator") <<
"Covered input parameters range:"
925 for (
int i = 0;
i < 5;
i++) {
932 bool invert_beam_coord_sytems)
const
934 double in_corrected[5];
935 if (
beam == lhcb1 || !invert_beam_coord_sytems) {
936 in_corrected[0] =
in[0];
937 in_corrected[1] =
in[1];
938 in_corrected[2] =
in[2];
939 in_corrected[3] =
in[3];
940 in_corrected[4] =
in[4];
942 in_corrected[0] = -
in[0];
943 in_corrected[1] = -
in[1];
944 in_corrected[2] =
in[2];
945 in_corrected[3] =
in[3];
946 in_corrected[4] =
in[4];
949 const TVectorD *min_var = x_parametrisation.GetMinVariables();
950 const TVectorD *max_var = x_parametrisation.GetMaxVariables();
953 for (
int i = 0;
i < 5;
i++) {
954 res =
res && in_corrected[
i] >= (*min_var)(
i) && in_corrected[
i] <= (*max_var)(
i);
981 bool invert_beam_coord_sytems)
const
984 bool result = Transport(
in,
out,
false, invert_beam_coord_sytems);
986 if (ap_type_ == ApertureType::RECTELLIPSE) {
988 (
out[0] *
out[0] / (r_el_x_ * r_el_x_) +
out[2] *
out[2] / (r_el_y_ * r_el_y_) < 1);
995 <<
"Linear terms of optical functions:"
997 for (
int i = 0;
i < 4;
i++) {
1004 const std::vector<std::string> &input_vars) {
1007 double d_out_d_in[5];
1008 double d_par = 1
e-5;
1011 for (
int j = 0;
j < 5;
j++)
1016 for (
int i = 0;
i < 5;
i++) {
1017 for (
int j = 0;
j < 5;
j++)
1024 d_out_d_in[
i] = d_out_d_in[
i] / d_par;
1026 edm::LogInfo(
"LHCOpticsApproximator") << coord_name <<
" = " << bias;
1027 for (
int i = 0;
i < 5;
i++) {
1028 edm::LogInfo(
"LHCOpticsApproximator") <<
" + " << d_out_d_in[
i] <<
"*" << input_vars[
i];
1034 double atPoint[],
double &Cx,
double &Lx,
double &vx,
double &Cy,
double &Ly,
double &vy,
double &
D,
double ep) {
1040 for (
int i = 0;
i < 5;
i++) {
1045 vx = (
out[0] - Cx) /
ep;
1048 Lx = (
out[0] - Cx) /
ep;
1051 vy = (
out[1] - Cy) /
ep;
1054 Ly = (
out[1] - Cy) /
ep;
1066 double mad_init_thx,
1068 double mad_init_thy,
1070 TMatrixD &transp_matrix,
1073 double MADX_momentum_correction_factor = 1.0 + mad_init_xi;
1074 transp_matrix.ResizeTo(2, 2);
1077 in[1] = mad_init_thx;
1079 in[3] = mad_init_thy;
1080 in[4] = mad_init_xi;
1086 double thx1 =
out[1];
1088 in[0] = mad_init_x + d_mad_x;
1090 double x2_dx =
out[0];
1091 double thx2_dx =
out[1];
1094 in[1] = mad_init_thx + d_mad_thx;
1096 double x2_dthx =
out[0];
1097 double thx2_dthx =
out[1];
1102 transp_matrix(0, 0) = (x2_dx -
x1) / d_mad_x;
1103 transp_matrix(1, 0) = (thx2_dx - thx1) / (d_mad_x * MADX_momentum_correction_factor);
1104 transp_matrix(0, 1) = MADX_momentum_correction_factor * (x2_dthx -
x1) / d_mad_thx;
1105 transp_matrix(1, 1) = (thx2_dthx - thx1) / d_mad_thx;
1110 double mad_init_thx,
1112 double mad_init_thy,
1114 TMatrixD &transp_matrix,
1117 double MADX_momentum_correction_factor = 1.0 + mad_init_xi;
1118 transp_matrix.ResizeTo(2, 2);
1121 in[1] = mad_init_thx;
1123 in[3] = mad_init_thy;
1124 in[4] = mad_init_xi;
1130 double thy1 =
out[3];
1132 in[2] = mad_init_y + d_mad_y;
1134 double y2_dy =
out[2];
1135 double thy2_dy =
out[3];
1138 in[3] = mad_init_thy + d_mad_thy;
1140 double y2_dthy =
out[2];
1141 double thy2_dthy =
out[3];
1146 transp_matrix(0, 0) = (y2_dy -
y1) / d_mad_y;
1147 transp_matrix(1, 0) = (thy2_dy - thy1) / (d_mad_y * MADX_momentum_correction_factor);
1148 transp_matrix(0, 1) = MADX_momentum_correction_factor * (y2_dthy -
y1) / d_mad_thy;
1149 transp_matrix(1, 1) = (thy2_dthy - thy1) / d_mad_thy;
1154 double mad_init_thx,
1156 double mad_init_thy,
1161 in[1] = mad_init_thx;
1163 in[3] = mad_init_thy;
1164 in[4] = mad_init_xi;
1171 in[4] = mad_init_xi + d_mad_xi;
1173 double x2_dxi =
out[0];
1174 double dispersion = (x2_dxi -
x1) / d_mad_xi;
1182 double mad_init_thx,
1184 double mad_init_thy,
1187 double MADX_momentum_correction_factor = 1.0 + mad_init_xi;
1190 in[1] = mad_init_thx;
1192 in[3] = mad_init_thy;
1193 in[4] = mad_init_xi;
1198 double thx1 =
out[1] / MADX_momentum_correction_factor;
1200 in[4] = mad_init_xi + d_mad_xi;
1202 double thx2_dxi =
out[1] / MADX_momentum_correction_factor;
1203 double dispersion = (thx2_dxi - thx1) / d_mad_xi;