38 #include "TGraphErrors.h"
43 #include "TSystemFile.h"
67 unsigned int fitProfileMinBinEntries,
68 unsigned int fitProfileMinNReasonable,
71 std::unique_ptr<TGraphErrors>
buildGraphFromVector(
const std::vector<PPSAlignmentConfiguration::PointErrors>&
pv);
74 const std::vector<MonitorElement*>& mes,
75 unsigned int fitProfileMinBinEntries,
76 unsigned int fitProfileMinNReasonable);
103 static double findMax(TF1* ff_fit);
120 double binWidth = -1.,
156 sequence_(iConfig.getParameter<std::
vector<std::
string>>(
"sequence")),
157 overwriteShX_(iConfig.getParameter<bool>(
"overwrite_sh_x")),
158 writeSQLiteResults_(iConfig.getParameter<bool>(
"write_sqlite_results")),
159 xAliRelFinalSlopeFixed_(iConfig.getParameter<bool>(
"x_ali_rel_final_slope_fixed")),
160 yAliFinalSlopeFixed_(iConfig.getParameter<bool>(
"y_ali_final_slope_fixed")),
161 debug_(iConfig.getParameter<bool>(
"debug")) {
163 if (!textResultsPath.empty()) {
167 debugFile_ = std::make_unique<TFile>(
"debug_harvester.root",
"recreate");
171 li <<
"[harvester] parameters:\n";
172 li <<
"* folder: " <<
folder_ <<
"\n";
173 li <<
"* sequence:\n";
175 li <<
" " <<
i + 1 <<
": " <<
sequence_[
i] <<
"\n";
177 li <<
"* overwrite_sh_x: " << std::boolalpha <<
overwriteShX_ <<
"\n";
178 li <<
"* text_results_path: " << textResultsPath <<
"\n";
182 li <<
"* debug: " << std::boolalpha <<
debug_;
196 desc.
add<std::vector<std::string>>(
"sequence", {
"x_alignment",
"x_alignment_relative",
"y_alignment"});
197 desc.
add<
bool>(
"overwrite_sh_x",
true);
198 desc.
add<
std::string>(
"text_results_path",
"./alignment_results.txt");
199 desc.
add<
bool>(
"write_sqlite_results",
false);
200 desc.
add<
bool>(
"x_ali_rel_final_slope_fixed",
true);
201 desc.
add<
bool>(
"y_ali_final_slope_fixed",
true);
202 desc.
add<
bool>(
"debug",
false);
218 for (
const auto& sc : {
cfg.sectorConfig45(),
cfg.sectorConfig56()}) {
219 for (
const auto&
rpc : {sc.rp_N_, sc.rp_F_}) {
224 li <<
"[harvester] Setting sh_x from config of:\n";
225 for (
const auto& sc : {
cfg.sectorConfig45(),
cfg.sectorConfig56()}) {
226 for (
const auto&
rpc : {sc.rp_N_, sc.rp_F_}) {
227 li <<
" " <<
rpc.name_ <<
" to " << std::fixed << std::setprecision(3) <<
rpc.sh_x_;
228 if (
rpc.name_ !=
"R_2_F")
234 bool doXAli =
false, doXAliRel =
false, doYAli =
false;
239 }
else if (
sequence_[
i] ==
"x_alignment_relative") {
254 for (
const auto& sc : {
cfg.sectorConfig45(),
cfg.sectorConfig56()}) {
259 double d_x_rel_N, d_x_rel_F;
269 double b = d_x_rel_N - d_x_rel_F;
270 double xCorrRel = b + d_x_F - d_x_N;
272 CTPPSRPAlignmentCorrectionData corrRelN(xCorrRel / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
274 CTPPSRPAlignmentCorrectionData corrRelF(-xCorrRel / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
288 edm::LogInfo(
"PPS") <<
"final merged results:\n" << finalResults;
298 poolDbService->
writeOneIOV(finalResults, poolDbService->
currentTime(),
"CTPPSRPAlignmentCorrectionsDataRcd");
300 edm::LogWarning(
"PPS") <<
"Could not store the results in a DB object. PoolDBService not available.";
306 TDirectory* cutsDir =
debugFile_->mkdir(
"cuts");
307 for (
const auto& sc : {
cfg.sectorConfig45(),
cfg.sectorConfig56()}) {
308 TDirectory* sectorDir = cutsDir->mkdir(sc.name_.c_str());
310 gDirectory = sectorDir->mkdir(
"cut_h");
311 auto* h2_cut_h_bef_monitor = iGetter.
get(
folder_ +
"/worker/" + sc.name_ +
"/cuts/cut_h/h2_cut_h_bef");
312 auto* h2_cut_h_aft_monitor = iGetter.
get(
folder_ +
"/worker/" + sc.name_ +
"/cuts/cut_h/h2_cut_h_aft");
314 h2_cut_h_bef_monitor->getTH2D(), sc.cut_h_a_, sc.cut_h_c_,
cfg.n_si(), sc.cut_h_si_,
"canvas_before");
315 writeCutPlot(h2_cut_h_aft_monitor->getTH2D(), sc.cut_h_a_, sc.cut_h_c_,
cfg.n_si(), sc.cut_h_si_,
"canvas_after");
317 gDirectory = sectorDir->mkdir(
"cut_v");
318 auto* h2_cut_v_bef_monitor = iGetter.
get(
folder_ +
"/worker/" + sc.name_ +
"/cuts/cut_v/h2_cut_v_bef");
319 auto* h2_cut_v_aft_monitor = iGetter.
get(
folder_ +
"/worker/" + sc.name_ +
"/cuts/cut_v/h2_cut_v_aft");
321 h2_cut_v_bef_monitor->getTH2D(), sc.cut_v_a_, sc.cut_v_c_,
cfg.n_si(), sc.cut_v_si_,
"canvas_before");
322 writeCutPlot(h2_cut_v_aft_monitor->getTH2D(), sc.cut_v_a_, sc.cut_v_c_,
cfg.n_si(), sc.cut_v_si_,
"canvas_after");
333 unsigned int fitProfileMinBinEntries,
334 unsigned int fitProfileMinNReasonable,
337 unsigned int n_reasonable = 0;
338 for (
int bi = 1; bi <= p->GetNbinsX(); bi++) {
339 if (p->GetBinEntries(bi) < fitProfileMinBinEntries) {
340 p->SetBinContent(bi, 0.);
341 p->SetBinError(bi, 0.);
347 if (n_reasonable < fitProfileMinNReasonable)
350 double x_min = x_mean - x_rms, x_max = x_mean + x_rms;
352 auto ff_pol1 = std::make_unique<TF1>(
"ff_pol1",
"[0] + [1]*x");
354 ff_pol1->SetParameter(0., 0.);
355 p->Fit(ff_pol1.get(),
"Q",
"", x_min, x_max);
357 sl = ff_pol1->GetParameter(1);
358 sl_unc = ff_pol1->GetParError(1);
365 const std::vector<PPSAlignmentConfiguration::PointErrors>&
pv) {
366 auto g = std::make_unique<TGraphErrors>();
368 for (
unsigned int i = 0;
i < pv.size();
i++) {
369 const auto&
p = pv[
i];
370 g->SetPoint(
i,
p.x_,
p.y_);
371 g->SetPointError(
i,
p.ex_,
p.ey_);
382 const std::vector<MonitorElement*>& mes,
383 unsigned int fitProfileMinBinEntries,
384 unsigned int fitProfileMinNReasonable) {
385 auto g = std::make_unique<TGraphErrors>();
387 for (
auto*
me : mes) {
388 if (
me->getName() ==
"h_y")
392 size_t parentPos = parentPath.substr(0, parentPath.size() - 1).find_last_of(
'/') + 1;
393 std::string parentName = parentPath.substr(parentPos);
394 size_t d = parentName.find(
'-');
395 const double x_min = std::stod(parentName.substr(0, d));
396 const double x_max = std::stod(parentName.substr(d + 1));
398 TH1D* h_y =
me->getTH1D();
401 auto* p_y_diffFN_vs_y_monitor = iGetter.
get(parentPath +
"p_y_diffFN_vs_y");
402 if (p_y_diffFN_vs_y_monitor ==
nullptr) {
403 edm::LogWarning(
"PPS") <<
"[x_alignment] could not find p_y_diffFN_vs_y in: " << parentPath;
406 TProfile* p_y_diffFN_vs_y = p_y_diffFN_vs_y_monitor->getTProfile();
408 double y_cen = h_y->GetMean();
409 double y_width = h_y->GetRMS();
414 double sl = 0., sl_unc = 0.;
416 fitProfile(p_y_diffFN_vs_y, y_cen, y_width, fitProfileMinBinEntries, fitProfileMinNReasonable, sl, sl_unc);
421 p_y_diffFN_vs_y->Write(parentName.c_str());
424 g->SetPoint(idx, (x_max + x_min) / 2., sl);
425 g->SetPointError(idx, (x_max - x_min) / 2., sl_unc);
438 TGraphErrors* g_test,
443 double& sh_best_unc) {
447 edm::LogInfo(
"PPS") << std::fixed << std::setprecision(3) <<
"[x_alignment] "
448 <<
"ref: x_min = " << range_ref.
x_min_ <<
", x_max = " << range_ref.
x_max_ <<
"\n"
449 <<
"test: x_min = " << range_test.x_min_ <<
", x_max = " << range_test.x_max_;
452 auto s_ref = std::make_unique<TSpline3>(
"s_ref", g_ref->GetX(), g_ref->GetY(), g_ref->GetN());
455 auto g_n_points = std::make_unique<TGraph>();
456 g_n_points->SetName(
"g_n_points");
457 g_n_points->SetTitle(
";sh;N");
458 auto g_chi_sq = std::make_unique<TGraph>();
459 g_chi_sq->SetName(
"g_chi_sq");
460 g_chi_sq->SetTitle(
";sh;S2");
461 auto g_chi_sq_norm = std::make_unique<TGraph>();
462 g_chi_sq_norm->SetName(
"g_chi_sq_norm");
463 g_chi_sq_norm->SetTitle(
";sh;S2 / N");
466 double S2_norm_best = 1E100;
468 for (
double sh = sh_min; sh <= sh_max; sh += cfg.
x_ali_sh_step()) {
473 for (
int i = 0;
i < g_test->GetN(); ++
i) {
474 const double x_test = g_test->GetX()[
i];
475 const double y_test = g_test->GetY()[
i];
476 const double y_test_unc = g_test->GetErrorY(
i);
478 const double x_ref = x_test + sh;
480 if (x_ref < range_ref.x_min_ || x_ref > range_ref.
x_max_ || x_test < range_test.x_min_ ||
481 x_test > range_test.x_max_)
484 const double y_ref = s_ref->Eval(x_ref);
486 int js = -1, jg = -1;
487 double xs = -1E100, xg = +1E100;
488 for (
int j = 0;
j < g_ref->GetN(); ++
j) {
489 const double x = g_ref->GetX()[
j];
490 if (x < x_ref && x > xs) {
494 if (x > x_ref && x < xg) {
502 const double y_ref_unc = (g_ref->GetErrorY(js) + g_ref->GetErrorY(jg)) / 2.;
505 const double S2_inc =
pow(y_test - y_ref, 2.) / (y_ref_unc * y_ref_unc + y_test_unc * y_test_unc);
510 double S2_norm = S2 / n_points;
512 if (S2_norm < S2_norm_best) {
513 S2_norm_best = S2_norm;
518 int idx = g_n_points->GetN();
519 g_n_points->SetPoint(idx, sh, n_points);
520 g_chi_sq->SetPoint(idx, sh, S2);
521 g_chi_sq_norm->SetPoint(idx, sh, S2_norm);
524 auto ff_pol2 = std::make_unique<TF1>(
"ff_pol2",
"[0] + [1]*x + [2]*x*x");
528 g_chi_sq->Fit(ff_pol2.get(),
"Q",
"", sh_best - fit_range, sh_best + fit_range);
529 sh_best_unc = 1. /
sqrt(ff_pol2->GetParameter(2));
532 edm::LogInfo(
"PPS") << std::fixed << std::setprecision(3) <<
"[x_alignment] "
533 <<
"sh_best = (" << sh_best <<
" +- " << sh_best_unc <<
") mm";
535 auto g_test_shifted = std::make_unique<TGraphErrors>(*g_test);
536 for (
int i = 0;
i < g_test_shifted->GetN(); ++
i) {
537 g_test_shifted->GetX()[
i] += sh_best;
542 iBooker.
book1DD(
"h_test_shifted", histPtr.get());
548 g_chi_sq_norm->Write();
549 g_test_shifted->SetTitle(
";x (mm);S");
550 g_test_shifted->Write(
"g_test_shifted");
553 auto g_results = std::make_unique<TGraph>();
554 g_results->SetName(
"g_results");
555 g_results->SetPoint(0, sh_best, sh_best_unc);
556 g_results->SetPoint(1, range_ref.
x_min_, range_ref.
x_max_);
557 g_results->SetPoint(2, range_test.x_min_, range_test.x_max_);
561 auto c_cmp = std::make_unique<TCanvas>(
"c_cmp");
562 g_ref->SetLineColor(1);
563 g_ref->SetName(
"g_ref");
566 g_test->SetLineColor(4);
567 g_test->SetName(
"g_test");
570 g_test_shifted->SetLineColor(2);
571 g_test_shifted->SetName(
"g_test_shifted");
573 g_test_shifted->Draw(
"pl");
584 TDirectory* xAliDir =
nullptr;
586 xAliDir =
debugFile_->mkdir((std::to_string(seqPos + 1) +
": x alignment").c_str());
590 const auto& sc = scPair.first;
591 const auto& sc_ref = scPair.second;
593 for (
const auto& rpcPair : {std::make_pair(sc.rp_F_, sc_ref.rp_F_), std::make_pair(sc.rp_N_, sc_ref.rp_N_)}) {
594 const auto&
rpc = rpcPair.first;
595 const auto& rpc_ref = rpcPair.second;
598 if (mes_test.empty()) {
599 edm::LogWarning(
"PPS") <<
"[x_alignment] " <<
rpc.name_ <<
": could not load mes_test";
603 TDirectory* rpDir =
nullptr;
605 rpDir = xAliDir->mkdir(
rpc.name_.c_str());
608 if (vec_ref.empty()) {
609 edm::LogInfo(
"PPS") <<
"[x_alignment] " <<
rpc.name_ <<
": reference points vector is empty";
616 gDirectory = rpDir->mkdir(
"fits_test");
622 edm::LogWarning(
"PPS") <<
"[x_alignment] " <<
rpc.name_ <<
": insufficient data, skipping (g_ref "
623 << g_ref->GetN() <<
"/" << cfg.
methOGraphMinN() <<
", g_test " << g_test->GetN() <<
"/"
631 g_ref.get(),
"ref",
";x (mm);S", rpc_ref.x_slice_n_, rpc_ref.x_slice_w_, rpc_ref.x_slice_min_);
632 iBooker.
book1DD(
"h_ref", histPtr.get());
636 iBooker.
book1DD(
"h_test", histPtr.get());
640 g_ref->SetTitle(
";x (mm);S");
641 g_ref->Write(
"g_ref");
642 g_test->SetTitle(
";x (mm);S");
643 g_test->Write(
"g_test");
647 double sh = 0., sh_unc = 0.;
662 CTPPSRPAlignmentCorrectionData rpResult(sh, sh_unc, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
664 edm::LogInfo(
"PPS") << std::fixed << std::setprecision(3) <<
"[x_alignment] "
665 <<
"Setting sh_x of " <<
rpc.name_ <<
" to " << sh;
677 textResultsFile_ << seqPos + 1 <<
": x_alignment:\n" << xAliResults_ <<
"\n\n";
686 TDirectory* xAliRelDir =
nullptr;
688 xAliRelDir =
debugFile_->mkdir((std::to_string(seqPos + 1) +
": x_alignment_relative").c_str());
690 auto ff = std::make_unique<TF1>(
"ff",
"[0] + [1]*(x - [2])");
691 auto ff_sl_fix = std::make_unique<TF1>(
"ff_sl_fix",
"[0] + [1]*(x - [2])");
695 TDirectory* sectorDir =
nullptr;
697 sectorDir = xAliRelDir->mkdir(sc.name_.c_str());
698 gDirectory = sectorDir;
701 auto* p_x_diffFN_vs_x_N_monitor = iGetter.
get(
folder_ +
"/worker/" + sc.name_ +
"/near_far/p_x_diffFN_vs_x_N");
702 if (p_x_diffFN_vs_x_N_monitor ==
nullptr) {
703 edm::LogWarning(
"PPS") <<
"[x_alignment_relative] " << sc.name_ <<
": cannot load data, skipping";
706 TProfile* p_x_diffFN_vs_x_N = p_x_diffFN_vs_x_N_monitor->getTProfile();
709 edm::LogWarning(
"PPS") <<
"[x_alignment_relative] " << sc.name_ <<
": insufficient data, skipping (near_far "
717 const double sh_x_N =
sh_x_map_[sc.rp_N_.id_];
718 double slope = sc.slope_;
720 ff->SetParameters(0., slope, 0.);
721 ff->FixParameter(2, -sh_x_N);
723 p_x_diffFN_vs_x_N->Fit(
ff.get(),
"Q",
"", x_min, x_max);
725 const double a =
ff->GetParameter(1), a_unc =
ff->GetParError(1);
726 const double b =
ff->GetParameter(0), b_unc =
ff->GetParError(0);
728 edm::LogInfo(
"PPS") <<
"[x_alignment_relative] " << sc.name_ <<
":\n"
729 << std::fixed << std::setprecision(3) <<
" x_min = " << x_min <<
", x_max = " << x_max
731 <<
" sh_x_N = " << sh_x_N <<
", slope (fix) = " << slope <<
", slope (fitted) = " <<
a;
733 CTPPSRPAlignmentCorrectionData rpResult_N(+b / 2., b_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
735 CTPPSRPAlignmentCorrectionData rpResult_F(-b / 2., b_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
738 ff_sl_fix->SetParameters(0., slope, 0.);
739 ff_sl_fix->FixParameter(1, slope);
740 ff_sl_fix->FixParameter(2, -sh_x_N);
741 ff_sl_fix->SetLineColor(4);
742 p_x_diffFN_vs_x_N->Fit(ff_sl_fix.get(),
"Q+",
"", x_min, x_max);
744 const double b_fs = ff_sl_fix->GetParameter(0), b_fs_unc = ff_sl_fix->GetParError(0);
746 CTPPSRPAlignmentCorrectionData rpResult_sl_fix_N(+b_fs / 2., b_fs_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
748 CTPPSRPAlignmentCorrectionData rpResult_sl_fix_F(-b_fs / 2., b_fs_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
751 edm::LogInfo(
"PPS") <<
"[x_alignment_relative] " << std::fixed << std::setprecision(3)
752 <<
"ff: " <<
ff->GetParameter(0) <<
" + " <<
ff->GetParameter(1) <<
" * (x - "
753 <<
ff->GetParameter(2) <<
"), ff_sl_fix: " << ff_sl_fix->GetParameter(0) <<
" + "
754 << ff_sl_fix->GetParameter(1) <<
" * (x - " << ff_sl_fix->GetParameter(2) <<
")";
758 iBooker.
bookProfile(
"p_x_diffFN_vs_x_N", p_x_diffFN_vs_x_N);
761 p_x_diffFN_vs_x_N->Write(
"p_x_diffFN_vs_x_N");
763 auto g_results = std::make_unique<TGraph>();
764 g_results->SetPoint(0, sh_x_N, 0.);
765 g_results->SetPoint(1, a, a_unc);
766 g_results->SetPoint(2, b, b_unc);
767 g_results->SetPoint(3, b_fs, b_fs_unc);
768 g_results->Write(
"g_results");
773 edm::LogInfo(
"PPS") << seqPos + 1 <<
": x_alignment_relative:\n"
779 textResultsFile_ << seqPos + 1 <<
": x_alignment_relative_sl_fix:\n" << xAliRelResultsSlopeFixed_ <<
"\n\n";
786 const double mu = ff_fit->GetParameter(1);
787 const double si = ff_fit->GetParameter(2);
790 if (si > 25. || std::fabs(mu) > 100.)
793 double x_max = 1E100;
794 double y_max = -1E100;
795 for (
double x = mu - si;
x <= mu + si;
x += 0.001) {
796 double y = ff_fit->Eval(
x);
810 TDirectory* d_top =
nullptr;
814 auto ff_fit = std::make_unique<TF1>(
"ff_fit",
"[0] * exp(-(x-[1])*(x-[1])/2./[2]/[2]) + [3] + [4]*x");
817 double diff = h2_y_vs_x->
getTH2D()->GetXaxis()->GetBinWidth(1) / 2.;
818 auto h_mode = iBooker.
book1DD(
"mode",
819 ";x (mm); mode of y (mm)",
821 h2_y_vs_x->
getTH2D()->GetXaxis()->GetBinCenter(1) -
diff,
822 h2_y_vs_x->
getTH2D()->GetXaxis()->GetBinCenter(h_n) +
diff);
824 for (
int bix = 1; bix <= h_n; bix++) {
825 const double x = h2_y_vs_x->
getTH2D()->GetXaxis()->GetBinCenter(bix);
828 sprintf(buf,
"h_y_x=%.3f", x);
829 TH1D* h_y = h2_y_vs_x->
getTH2D()->ProjectionY(buf, bix, bix);
835 sprintf(buf,
"x=%.3f", x);
836 gDirectory = d_top->mkdir(buf);
840 double conMax_x = 0.;
841 for (
int biy = 1; biy < h_y->GetNbinsX(); biy++) {
842 if (h_y->GetBinContent(biy) > conMax) {
843 conMax = h_y->GetBinContent(biy);
844 conMax_x = h_y->GetBinCenter(biy);
848 ff_fit->SetParameters(conMax, conMax_x, h_y->GetRMS() * 0.75, 0., 0.);
849 ff_fit->FixParameter(4, 0.);
852 h_y->Fit(ff_fit.get(),
"Q",
"", x_min, x_max);
854 ff_fit->ReleaseParameter(4);
855 double w =
std::min(4., 2. * ff_fit->GetParameter(2));
856 x_min = ff_fit->GetParameter(1) -
w;
859 h_y->Fit(ff_fit.get(),
"Q",
"", x_min, x_max);
864 double y_mode =
findMax(ff_fit.get());
865 const double y_mode_fit_unc = ff_fit->GetParameter(2) / 10;
867 double y_mode_unc =
std::sqrt(y_mode_fit_unc * y_mode_fit_unc + y_mode_sys_unc * y_mode_sys_unc);
873 ff_fit->GetChisquare() / ff_fit->GetNDF() > chiSqThreshold);
876 auto g_data = std::make_unique<TGraph>();
877 g_data->SetPoint(0, y_mode, y_mode_unc);
878 g_data->SetPoint(1, ff_fit->GetChisquare(), ff_fit->GetNDF());
879 g_data->SetPoint(2, valid, 0.);
880 g_data->Write(
"g_data");
886 h_mode->Fill(x, y_mode);
887 h_mode->setBinError(bix, y_mode_unc);
890 return h_mode->getTH1D();
897 TDirectory* yAliDir =
nullptr;
899 yAliDir =
debugFile_->mkdir((std::to_string(seqPos + 1) +
": y_alignment").c_str());
901 auto ff = std::make_unique<TF1>(
"ff",
"[0] + [1]*(x - [2])");
902 auto ff_sl_fix = std::make_unique<TF1>(
"ff_sl_fix",
"[0] + [1]*(x - [2])");
906 for (
const auto&
rpc : {sc.rp_F_, sc.rp_N_}) {
907 TDirectory* rpDir =
nullptr;
909 rpDir = yAliDir->mkdir(
rpc.name_.c_str());
910 gDirectory = rpDir->mkdir(
"x");
914 iGetter.
get(
folder_ +
"/worker/" + sc.name_ +
"/multiplicity selection/" +
rpc.name_ +
"/h2_y_vs_x");
916 if (h2_y_vs_x ==
nullptr) {
917 edm::LogWarning(
"PPS") <<
"[y_alignment] " <<
rpc.name_ <<
": cannot load data, skipping";
924 if ((
unsigned int)h_y_cen_vs_x->GetEntries() < cfg.
modeGraphMinN()) {
925 edm::LogWarning(
"PPS") <<
"[y_alignment] " <<
rpc.name_ <<
": insufficient data, skipping (mode graph "
926 << h_y_cen_vs_x->GetEntries() <<
"/" << cfg.
modeGraphMinN() <<
")";
936 ff->SetParameters(0., 0., 0.);
937 ff->FixParameter(2, -sh_x);
939 h_y_cen_vs_x->Fit(
ff.get(),
"Q",
"", x_min, x_max);
941 const double a =
ff->GetParameter(1), a_unc =
ff->GetParError(1);
942 const double b =
ff->GetParameter(0), b_unc =
ff->GetParError(0);
945 << std::fixed << std::setprecision(3) <<
" x_min = " << x_min <<
", x_max = " << x_max
947 <<
" sh_x = " << sh_x <<
", slope (fix) = " << slope <<
", slope (fitted) = " <<
a;
949 CTPPSRPAlignmentCorrectionData rpResult(0., 0., b, b_unc, 0., 0., 0., 0., 0., 0., 0., 0.);
952 ff_sl_fix->SetParameters(0., 0., 0.);
953 ff_sl_fix->FixParameter(1, slope);
954 ff_sl_fix->FixParameter(2, -sh_x);
955 ff_sl_fix->SetLineColor(4);
956 h_y_cen_vs_x->Fit(ff_sl_fix.get(),
"Q+",
"", x_min, x_max);
958 const double b_fs = ff_sl_fix->GetParameter(0), b_fs_unc = ff_sl_fix->GetParError(0);
960 CTPPSRPAlignmentCorrectionData rpResult_sl_fix(0., 0., b_fs, b_fs_unc, 0., 0., 0., 0., 0., 0., 0., 0.);
963 edm::LogInfo(
"PPS") <<
"[y_alignment] " << std::fixed << std::setprecision(3) <<
"ff: " <<
ff->GetParameter(0)
964 <<
" + " <<
ff->GetParameter(1) <<
" * (x - " <<
ff->GetParameter(2)
965 <<
"), ff_sl_fix: " << ff_sl_fix->GetParameter(0) <<
" + " << ff_sl_fix->GetParameter(1)
966 <<
" * (x - " << ff_sl_fix->GetParameter(2) <<
")";
971 h_y_cen_vs_x->SetTitle(
";x (mm); mode of y (mm)");
972 h_y_cen_vs_x->Write(
"h_y_cen_vs_x");
974 auto g_results = std::make_unique<TGraph>();
975 g_results->SetPoint(0, sh_x, 0.);
976 g_results->SetPoint(1, a, a_unc);
977 g_results->SetPoint(2, b, b_unc);
978 g_results->SetPoint(3, b_fs, b_fs_unc);
979 g_results->Write(
"g_results");
986 <<
yAliResults_ << seqPos + 1 <<
": y_alignment_sl_fix:\n"
991 textResultsFile_ << seqPos + 1 <<
": y_alignment_sl_fix:\n" << yAliResultsSlopeFixed_ <<
"\n\n";
998 auto canvas = std::make_unique<TCanvas>();
999 canvas->SetName(label.c_str());
1004 double x_min = -30.;
1007 auto g_up = std::make_unique<TGraph>();
1008 g_up->SetName(
"g_up");
1009 g_up->SetPoint(0, x_min, -a * x_min - c + n_si * si);
1010 g_up->SetPoint(1, x_max, -a * x_max - c + n_si * si);
1011 g_up->SetLineColor(1);
1014 auto g_down = std::make_unique<TGraph>();
1015 g_down->SetName(
"g_down");
1016 g_down->SetPoint(0, x_min, -a * x_min - c - n_si * si);
1017 g_down->SetPoint(1, x_max, -a * x_max - c - n_si * si);
1018 g_down->SetLineColor(1);
1028 std::unique_ptr<TH1D>
hist;
1030 hist = std::make_unique<TH1D>(title.c_str(), labels.c_str(), 0, -10., 10.);
1031 }
else if (n == 1) {
1032 hist = std::make_unique<TH1D>(title.c_str(), labels.c_str(), 1, graph->GetPointX(0) - 5., graph->GetPointX(0) + 5.);
1034 n = n == -1 ? graph->GetN() :
n;
1035 binWidth = binWidth == -1 ? graph->GetPointX(1) - graph->GetPointX(0) : binWidth;
1036 double diff = binWidth / 2.;
1037 min = min == -1 ? graph->GetPointX(0) - diff :
min;
1038 double max = min + n * binWidth;
1039 hist = std::make_unique<TH1D>(title.c_str(), labels.c_str(),
n,
min,
max);
1042 for (
int i = 0;
i < graph->GetN();
i++) {
1044 graph->GetPoint(
i, x, y);
1046 hist->SetBinError(hist->GetXaxis()->FindBin(x), graph->GetErrorY(
i));
void dqmEndRun(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::Run const &iRun, edm::EventSetup const &iSetup) override
virtual TH2D * getTH2D() const
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
unsigned int modeGraphMinN() const
const edm::EventSetup & c
double x_ali_sh_step() const
CTPPSRPAlignmentCorrectionData & getRPCorrection(unsigned int id)
returns the correction value from the RP map
std::map< unsigned int, double > sh_x_map_
edm::ESGetToken< PPSAlignmentConfiguration, PPSAlignmentConfigurationRcd > esTokenReference_
virtual void setCurrentFolder(std::string const &fullpath)
std::ofstream textResultsFile_
std::unique_ptr< TGraphErrors > buildGraphFromMonitorElements(DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration::RPConfig &rpc, const std::vector< MonitorElement * > &mes, unsigned int fitProfileMinBinEntries, unsigned int fitProfileMinNReasonable)
double y_mode_unc_max_valid() const
unsigned int fitProfileMinBinEntries() const
#define DEFINE_FWK_MODULE(type)
CTPPSRPAlignmentCorrectionsData xAliRelResults_
static const double slope[3]
static int fitProfile(TProfile *p, double x_mean, double x_rms, unsigned int fitProfileMinBinEntries, unsigned int fitProfileMinNReasonable, double &sl, double &sl_unc)
unsigned int multSelProjYMinEntries() const
unsigned int methOGraphMinN() const
const std::map< unsigned int, std::vector< PointErrors > > & matchingReferencePoints() const
CTPPSRPAlignmentCorrectionsData yAliResults_
const SectorConfig & sectorConfig56() const
void setRPCorrection(unsigned int id, const CTPPSRPAlignmentCorrectionData &ac)
sets the alignment correction for the given RP
Log< level::Error, false > LogError
const std::map< unsigned int, SelectionRange > & matchingShiftRanges() const
void yAlignment(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration &cfg, int seqPos)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
static std::unique_ptr< TH1D > getTH1DFromTGraphErrors(TGraphErrors *graph, std::string title="", std::string labels="", int n=-1, double binWidth=-1., double min=-1.)
bool getData(T &iHolder) const
std::unique_ptr< TGraphErrors > buildGraphFromVector(const std::vector< PPSAlignmentConfiguration::PointErrors > &pv)
const std::map< unsigned int, SelectionRange > & alignment_y_ranges() const
CTPPSRPAlignmentCorrectionsData yAliResultsSlopeFixed_
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual int getNbinsX() const
get # of bins in X-axis
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
double chiSqThreshold() const
CTPPSRPAlignmentCorrectionsData xAliResults_
const bool writeSQLiteResults_
PPSAlignmentHarvester(const edm::ParameterSet &iConfig)
~PPSAlignmentHarvester() override
const bool xAliRelFinalSlopeFixed_
void doMatch(DQMStore::IBooker &iBooker, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration::RPConfig &rpc, TGraphErrors *g_ref, TGraphErrors *g_test, const PPSAlignmentConfiguration::SelectionRange &range_ref, double sh_min, double sh_max, double &sh_best, double &sh_best_unc)
virtual MonitorElement * get(std::string const &fullpath) const
const bool yAliFinalSlopeFixed_
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
double y_mode_max_valid() const
TH1D * buildModeGraph(DQMStore::IBooker &iBooker, MonitorElement *h2_y_vs_x, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration::RPConfig &rpc)
const std::vector< std::string > sequence_
edm::ESGetToken< PPSAlignmentConfiguration, PPSAlignmentConfigurationRcd > esTokenTest_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void addRPCorrection(unsigned int, const CTPPSRPAlignmentCorrectionData &, bool sumErrors=true, bool addSh=true, bool addRot=true)
std::unique_ptr< TFile > debugFile_
static void writeCutPlot(TH2D *h, double a, double c, double si, double n_si, const std::string &label)
void addCorrections(const CTPPSRPAlignmentCorrectionsData &, bool sumErrors=true, bool addSh=true, bool addRot=true)
adds (merges) corrections on top of the current values
Log< level::Info, false > LogInfo
unsigned int nearFarMinEntries() const
unsigned int fitProfileMinNReasonable() const
const std::string folder_
void dqmEndJob(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) override
double methOUncFitRange() const
T getParameter(std::string const &) const
void xAlignment(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration &cfg_ref, int seqPos)
Container for CTPPS RP alignment corrections. The corrections are stored on two levels - RP and senso...
const SectorConfig & sectorConfig45() const
void xAlignmentRelative(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration &cfg, int seqPos)
double y_mode_sys_unc() const
cond::Time_t currentTime() const
CTPPSRPAlignmentCorrectionsData xAliRelResultsSlopeFixed_
const std::map< unsigned int, SelectionRange > & alignment_x_relative_ranges() const
Log< level::Warning, false > LogWarning
static double findMax(TF1 *ff_fit)
const std::map< unsigned int, SelectionRange > & alignment_x_meth_o_ranges() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Power< A, B >::type pow(const A &a, const B &b)
Alignment correction for an element of the CT-PPS detector. Within the geometry description, every sensor (more generally every element) is given its translation and rotation. These two quantities shall be understood in local-to-global coordinate transform. That is, if r_l is a point in local coordinate system and x_g in global, then it holds.