Commit b8ea0390 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'improvement_prealignment' into 'master'

More options for prealignment

Closes #65

See merge request !264
parents 38145c61 e770b529
Pipeline #1506529 failed with stages
in 6 minutes and 24 seconds
......@@ -19,6 +19,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);
method = m_config.get<std::string>("method", "mean");
std::transform(method.begin(), method.end(), method.begin(), ::tolower);
fit_range_rel = m_config.get<int>("fit_range_rel", 500);
// Backwards compatibilty: also allow timing_cut to be used for time_cut_abs
m_config.setAlias("time_cut_abs", "timing_cut", true);
......@@ -119,14 +123,56 @@ 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: " << method;
if(method == "gauss_fit") {
int binMaxX = correlationX->GetMaximumBin();
double fit_low_x =
correlationX->GetXaxis()->GetBinCenter(binMaxX) - m_detector->getSpatialResolution().x() * fit_range_rel;
double fit_high_x =
correlationX->GetXaxis()->GetBinCenter(binMaxX) + m_detector->getSpatialResolution().x() * fit_range_rel;
int binMaxY = correlationY->GetMaximumBin();
double fit_low_y =
correlationY->GetXaxis()->GetBinCenter(binMaxY) - m_detector->getSpatialResolution().y() * fit_range_rel;
double fit_high_y =
correlationY->GetXaxis()->GetBinCenter(binMaxY) + m_detector->getSpatialResolution().y() * fit_range_rel;
LOG(DEBUG) << "Fit range in x direction from: " << Units::display(fit_low_x, {"mm", "um"}) << " to "
<< Units::display(fit_high_x, {"mm", "um"});
LOG(DEBUG) << "Fit range in y direction from: " << Units::display(fit_low_y, {"mm", "um"}) << " to "
<< Units::display(fit_high_y, {"mm", "um"});
correlationX->Fit("gaus", "Q", "", fit_low_x, fit_high_x);
correlationY->Fit("gaus", "Q", "", fit_low_y, fit_high_y);
shift_X = correlationX->GetFunction("gaus")->GetParameter(1);
shift_Y = correlationY->GetFunction("gaus")->GetParameter(1);
} else if(method == "mean") {
shift_X = correlationX->GetMean();
shift_Y = correlationY->GetMean();
} else if(method == "maximum") {
int binMaxX = correlationX->GetMaximumBin();
shift_X = correlationX->GetXaxis()->GetBinCenter(binMaxX);
int binMaxY = correlationY->GetMaximumBin();
shift_Y = correlationY->GetXaxis()->GetBinCenter(binMaxY);
} else {
throw InvalidValueError(m_config, "method", "Invalid prealignment method");
LOG(DEBUG) << "Shift (without damping factor)" << 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"});
LOG(INFO) << "Detector position after shift in x = "
<< Units::display(m_detector->displacement().X() + damping_factor * shift_X, {"mm", "um"})
<< " , and in y = "
<< Units::display(m_detector->displacement().Y() + damping_factor * shift_Y, {"mm", "um"});
m_detector->displacement(XYZPoint(m_detector->displacement().X() + damping_factor * shift_X,
m_detector->displacement().Y() + damping_factor * shift_Y,
......@@ -12,6 +12,7 @@
#include <TCanvas.h>
#include <TF1.h>
#include <TH1F.h>
#include <TH2F.h>
#include <iostream>
......@@ -49,6 +50,8 @@ namespace corryvreckan {
double max_correlation_rms;
double damping_factor;
double timeCut;
std::string method;
int fit_range_rel;
} // namespace corryvreckan
......@@ -9,7 +9,8 @@ This module performs translational telescope plane alignment. The rotational ali
This initial alignment along the X and Y axes is designed to be performed before the `Alignment` module, which carries out translational and rotational alignment of the planes. To not include the DUT in this transaltional alignment, it will need to be masked in the configuration file.
The required translational shifts in X and Y are calculated for each detector as the mean of the 1D correlation histogram along the axis.
The way in which the required translational shifts in X and Y are calculated is specified by the parameter `method`.
Either the mean of the 1D correlation histogram, its maximum or the mean of a Gaussian fit can be used to determine the translational shifts.
As described in the alignment chapter of the user manual, the spatial correlations in X and Y should not be forced to be centered around zero for the final alignment as they correspond to the *physical displacement* of the detector plane in X and Y with respect to the reference plane.
However, for the prealignment this is a an acceptable estimation which works without any tracking.
......@@ -18,6 +19,8 @@ However, for the prealignment this is a an acceptable estimation which works wit
* `max_correlation_rms`: The maximum RMS of the 1D correlation histograms allowed for the shifts to be applied. This factor should be tuned for each run, and is combat the effect of flat distributions. Default value is `6mm`.
* `time_cut_rel`: Number of standard deviations the `time_resolution` of the detector plane will be multiplied by. This value is then used as the maximum time difference between a cluster on the current detector and a cluster on the reference plane to be considered in the prealignment. Absolute and relative time cuts are mutually exclusive. Defaults to `3.0`.
* `time_cut_abs`: Specifies an absolute value for the maximum time difference between a cluster on the current detector and a cluster on the reference plane to be considered in the prealignment. Absolute and relative time cuts are mutually exclusive. No default value.
* `method`: Specifies which method should be used to compute the translational shifts. With the option `mean` the mean of the 1D correlation histogram is used. The option `maximum` uses the maximum value of the histogram. With `method` set to `gauss_fit` a Gaussian is fitted and the mean of the fit is used for the translational shift. Default is to `mean`.
* `fit_range_rel`: Parameter to set the fit range of the Gaussian fit if `method` is set to `gauss_fit`. The absolute fit range is given by `fit_range_rel` times the spatial resolution of the corresponding detector around the maximum of the 1D correlation histogram. The default of the relative fit range is `fit_range_rel` = 500.
### Plots Created
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment