diff --git a/src/modules/Prealignment/Prealignment.cpp b/src/modules/Prealignment/Prealignment.cpp index 7806301f70210181fcb26a34696d6f92b8644b8e..80152be48a1be9c759832419861321beec775e35 100644 --- a/src/modules/Prealignment/Prealignment.cpp +++ b/src/modules/Prealignment/Prealignment.cpp @@ -9,6 +9,10 @@ Prealignment::Prealignment(Configuration config, std::shared_ptr<Detector> detec max_correlation_rms = m_config.get<double>("max_correlation_rms", Units::get<double>(6, "mm")); damping_factor = m_config.get<double>("damping_factor", 1.0); + prealign_method = m_config.get<std::string>("prealign_method", "mean"); + fit_high = m_config.get<double>("fit_high", Units::get<double>(2, "mm")); + fit_low = m_config.get<double>("fit_low", Units::get<double>(-2, "mm")); + // Backwards compatibilty: also allow timing_cut to be used for time_cut_abs m_config.setAlias("time_cut_abs", "timing_cut", true); @@ -109,14 +113,34 @@ void Prealignment::finalise() { // Move all but the reference: if(!m_detector->isReference()) { - double mean_X = correlationX->GetMean(); - double mean_Y = correlationY->GetMean(); - LOG(INFO) << "Detector " << m_detector->name() << ": x = " << Units::display(mean_X, {"mm", "um"}) - << " , y = " << Units::display(mean_Y, {"mm", "um"}); - LOG(INFO) << "Move in x by = " << Units::display(mean_X * damping_factor, {"mm", "um"}) - << " , and in y by = " << Units::display(mean_Y * damping_factor, {"mm", "um"}); - m_detector->displacement(XYZPoint(m_detector->displacement().X() + damping_factor * mean_X, - m_detector->displacement().Y() + damping_factor * mean_Y, + + double shift_X = 0.; + double shift_Y = 0.; + + LOG(INFO) << "Using prealignment method: " << prealign_method; + if(prealign_method == "gauss_fit"){ + correlationX->Fit("gaus", "Q","", fit_low, fit_high); + correlationY->Fit("gaus", "Q","", fit_low, fit_high); + shift_X = correlationX->GetFunction("gaus")->GetParameter(1); + shift_Y = correlationY->GetFunction("gaus")->GetParameter(1); + } + else if(prealign_method == "mean"){ + shift_X = correlationX->GetMean(); + shift_Y = correlationY->GetMean(); + } + else if(prealign_method == "maximum"){ + int binMaxX = correlationX->GetMaximumBin(); + shift_X = correlationX->GetXaxis()->GetBinCenter(binMaxX); + int binMaxY = correlationY->GetMaximumBin(); + shift_Y = correlationY->GetXaxis()->GetBinCenter(binMaxY); + } + + LOG(INFO) << "Detector " << m_detector->name() << ": x = " << Units::display(shift_X, {"mm", "um"}) + << " , y = " << Units::display(shift_Y, {"mm", "um"}); + LOG(INFO) << "Move in x by = " << Units::display(shift_X * damping_factor, {"mm", "um"}) + << " , and in y by = " << Units::display(shift_Y * damping_factor, {"mm", "um"}); + m_detector->displacement(XYZPoint(m_detector->displacement().X() + damping_factor * shift_X, + m_detector->displacement().Y() + damping_factor * shift_Y, m_detector->displacement().Z())); } } diff --git a/src/modules/Prealignment/Prealignment.h b/src/modules/Prealignment/Prealignment.h index dce2a3c92f65db88e763de3265d5316cc368386d..f7624e4641ca435dbbba9984597e8d59be84be22 100644 --- a/src/modules/Prealignment/Prealignment.h +++ b/src/modules/Prealignment/Prealignment.h @@ -4,6 +4,7 @@ #include <TCanvas.h> #include <TH1F.h> #include <TH2F.h> +#include <TF1.h> #include <iostream> #include "core/module/Module.hpp" #include "objects/Cluster.hpp" @@ -39,6 +40,9 @@ namespace corryvreckan { double max_correlation_rms; double damping_factor; double timeCut; + std::string prealign_method; + double fit_high; + double fit_low; }; } // namespace corryvreckan #endif // PREALIGNMENT_H