diff --git a/CalibPPS/AlignmentGlobal/BuildFile.xml b/CalibPPS/AlignmentGlobal/BuildFile.xml new file mode 100644 index 0000000000000..4148559a502f3 --- /dev/null +++ b/CalibPPS/AlignmentGlobal/BuildFile.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/CalibPPS/AlignmentGlobal/README.md b/CalibPPS/AlignmentGlobal/README.md index 2ed157af113b5..30e7c0e67717e 100644 --- a/CalibPPS/AlignmentGlobal/README.md +++ b/CalibPPS/AlignmentGlobal/README.md @@ -1,133 +1,22 @@ -# PPSAlignmentWorker -## Parameters: -| Name | Type | Description | -|-------------|----------------|--------------------------------------------------------------------------| -| `tagTracks` | `cms.InputTag` | Should be set to `"ctppsLocalTrackLiteProducer"`. | -| `folder` | `cms.string` | Should be the same as the `folder` parameter in DQM configuration. | -| `label` | `cms.string` | Label for EventSetup | -| `debug` | `cms.bool` | When set to `True`, the worker will produce some extra debug histograms. | +# PPS Global Alignment -# PPSAlignmentHarvester -## Parameters: -| Name | Type | Description | -|-------------------------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| -| `folder` | `cms.string` | Should be the same as the `folder` parameter in DQM configuration. | -| `sequence` | `cms.vstring` | Determines order of the alignment methods: `"x_alignemnt"`, `"x_alignment_relative"`, `"y_alignment"`. | -| `overwrite_sh_x` | `cms.bool` | If set to `True`, `x alignment` will overwrite horizontal shift passed in the configuration. | -| `test_results_path` | `cms.string` | Path of a file with the results. If empty (`""`), the file will not be created. | -| `write_sqlite_results` | `cms.bool` | When set to `True`, the harvester will try to use PoolDBOutputService to save the final results. | -| `x_ali_rel_final_slope_fixed` | `cms.bool` | `True`: the harvester will use the x relative alignment results with fixed slope to prepare final merged results. `False`: results without fixed slope. | -| `y_ali_final_slope_fixed` | `cms.bool` | `True`: the harvester will use the y alignment results with fixed slope to prepare final merged results. `False`: results without fixed slope. | -| `debug` | `cms.bool` | When set to `True`, the harvester will produce an extra ROOT file with debug plots. | +## Description -# Event Setup -Default values come from the `fillDescriptions` method in `CalibPPS/ESProducers/plugins/PPSAlignmentConfigESSource.cc`.
-NB: Parameters here are written in snake_case. Many of them are in camelCase in the code (as PPSAlignmentConfig getters). -| Name | Type | Default | Description | -|------------------------|---------------|----------------------------------------|------------------------------------------------------------------------------------------------------------| -| `debug` | `cms.bool` | `False` | When set to `True`, the ESProducer will produce an extra ROOT file with debug plots (from reference run). | -| `label` | `cms.string` | `""` | label to distinguish reference and test fill configs. Should be set either to `""` (test) or `"reference"` | -| `sector_45` | `cms.PSet` | [details below](#Sector-config) | Configuration of sector 45. [Details below](#Sector-config) | -| `sector_56` | `cms.PSet` | [details below](#Sector-config) | Configuration of sector 56. [Details below](#Sector-config) | -| `x_ali_sh_step` | `cms.double` | `0.01` | Step for x alignment algorithm [mm] | -| `y_mode_sys_unc` | `cms.double` | `0.03` | Squared is an element of y mode uncertainty in y alignment. | -| `chiSqThreshold` | `cms.double` | `50.` | Chi-square threshold of y mode | -| `y_mode_unc_max_valid` | `cms.double` | `5.` | Maximum valid y mode uncertainty | -| `y_mode_max_valid` | `cms.double` | `20.` | Maximum valid y mode | -| `min_RP_tracks_size` | `cms.uint32` | `1` | Minimum number of tracks in each RP | -| `max_RP_tracks_size` | `cms.uint32` | `1` | Maximum number of tracks in each RP | -| `n_si` | `cms.double` | `4.` | Element of checking whether the cuts passed | -| `matching` | `cms.PSet` | [details below](#matching) | Reference dataset parameters. [Details below](#matching) | -| `x_alignment_meth_o` | `cms.PSet` | [details below](#x_alignment_meth_o) | X alignment parameters. [Details below](#x_alignment_meth_o) | -| `x_alignment_relative` | `cms.PSet` | [details below](#x_alignment_relative) | Relative x alignment parameters. [Details below](#x_aligmment_relative) | -| `y_alignment` | `cms.PSet` | [details below](#y_alignment) | Y alignment parameters. [Details below](#y_alignment) | -| `binning` | `cms.PSet` | [details below](#binning) | Binning parameters for worker. [Details below](#binning) | -| `extraParams` | `cms.vdouble` | empty vector | Extra vector of doubles added in case new parameters need to be added in the future | +This package is responsible for PPS global alignment, that is alignment of high-luminosity physics runs based on the data from a low-luminosity reference run. -## Sector config -| Name | Type | Default (s_45) | Default (s_56) | Description | -|---------------|--------------|-----------------------------|-----------------------------|----------------------------------------------------| -| `rp_N` | `cms.PSet` | [details below](#RP-config) | [details below](#RP-config) | Near RP configuration. [Details below](#RP-config) | -| `rp_F` | `cms.PSet` | [details below](#RP-config) | [details below](#RP-config) | Far RP configuration. [Details below](#RP-config) | -| `slope` | `cms.double` | `0.006` | `-0.015` | Base slope value | -| `cut_h_apply` | `cms.bool` | `True` | `True` | If set to `True`, cut_h is applied | -| `cut_h_a` | `cms.double` | `-1.` | `-1.` | cut_h parameter | -| `cut_h_c` | `cms.double` | `-38.55` | `-39.26` | cut_h parameter | -| `cut_h_si` | `cms.double` | `0.2` | `0.2` | cut_h parameter | -| `cut_v_apply` | `cms.bool` | `True` | `True` | If set to `True`, cut_v is applied | -| `cut_v_a` | `cms.double` | `-1.07` | `-1.07` | cut_v parameter | -| `cut_v_c` | `cms.double` | `1.63` | `1.49` | cut_v parameter | -| `cut_v_si` | `cms.double` | `0.15` | `0.15` | cut_v parameter | +The structure of this software is based on the DQM framework: +1. `PPSAlignmentWorker` - takes tracks of particles produced by `ctppsLocalTrackLiteProducer` as input. It processes them by applying some cuts in order to reduce noise, and uses these data to fill the histograms that will be later used in the next module. Note that filling the histograms can be done in parallel. +2. `PPSAlignmentHarvester` - it analyses the plots filled by the worker, runs the alignment algorithms, and outputs horizontal and vertical corrections. -### RP config -| Name | Type | Default (s_45, rp_N) | Default (s_45, rp_F) | Default (s_56, rp_N) | Default (s_56, rp_F) | Description | -|------------------|--------------|----------------------|----------------------|----------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------| -| `name` | `cms.string` | `"L_1_F"` | `"L_2_F"` | `"R_1_F"` | `"R_2_F"` | Name of the RP | -| `id` | `cms.int32` | `3` | `23` | `103` | `123` | ID of the RP | -| `slope` | `cms.double` | `0.19` | `0.19` | `0.40` | `0.39` | Base slope value | -| `sh_x` | `cms.double` | `-3.6` | `-42.` | `-2.8` | `-41.9` | Base sh_x value [mm]. X alignment method overwrites it. | -| `x_min_fit_mode` | `cms.double` | `2.` | `2.` | `2.` | `2.` | Mode graph parameter. See [buildModeGraph](plugins/PPSAlignmentHarvester.cc#L648). | -| `x_max_fit_mode` | `cms.double` | `7.` | `7.5` | `7.4` | `8.` | Mode graph parameter. See [buildModeGraph](plugins/PPSAlignmentHarvester.cc#L648). | -| `y_max_fit_mode` | `cms.double` | `7.` | `7.5` | `7.4` | `8.` | Mode graph parameter (in 2018 the same value as x_max_fit_mode). See [buildModeGraph](plugins/PPSAlignmentHarvester.cc#L654). | -| `y_cen_add` | `cms.double` | `-0.3` | `-0.3` | `-0.8` | `-0.8` | The value is added to y_cen (mean of y) while constructing a graph in x alignment. | -| `y_width_mult` | `cms.double` | `1.1` | `1.1` | `1.0` | `1.` | y_width (RMS of y) is multiplied by the value when constructing a graph in x alignment. | -| `x_slice_min` | `cms.double` | `7.` | `46.` | `6.` | `45.` | Min x for slice plots (x alignment) | -| `x_slice_max` | `cms.double` | `19.` | `58.` | `17.` | `57.` | Max x for slice plots (x alignment) | -| `x_slice_w` | `cms.double` | `0.2` | `0.2` | `0.2` | `0.2` | X width for slice plots (x alignment) | +This package makes use of some modules from other packages: +- `PPSAlignmentConfiguration` in *CondFormats/PPSObjects* - a conditions format used as a configuration input for the alignment procedure, +- `PPSAlignmentConfigurationESSource` in *CalibPPS/ESProducers* - an ESSource module for `PPSAlignmentConfiguration`. -## matching -| Name | Type | Default | Description | -|---------------------|--------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `reference_dataset` | `cms.string` | `""` | Directory of the file with reference dataset histograms. Should be empty when running the worker for the reference dataset. After that, should be set to the name of the created ROOT file (in the reference config). | -| `rp_L_F` | `cms.PSet` | `-43.` - `-41.` | Left far RP. Contains two parameters of type `cms.double`: `sh_min` and `sh_max` - shift range for x alignment [mm] | -| `rp_L_N` | `cms.PSet` | `-4.2` - `-2.4` | Left near RP. Contains two parameters of type `cms.double`: `sh_min` and `sh_max` - shift range for x alignment [mm] | -| `rp_R_N` | `cms.PSet` | `-3.6` - `-1.8` | Right near RP. Contains two parameters of type `cms.double`: `sh_min` and `sh_max` - shift range for x alignment [mm] | -| `rp_R_F` | `cms.PSet` | `-43.2` - `-41.2` | Right far RP. Contains two parameters of type `cms.double`: `sh_min` and `sh_max` - shift range for x alignment [mm] | +For more information about the alignment algorithms and procedure, detailed instructions on how to run it, and possible use cases check out **[the TWiki page](https://twiki.cern.ch/twiki/bin/viewauth/CMS/PPSAlign)**. -## x_alignment_meth_o -| Name | Type | Default | Description | -|--------------------------------|--------------|----------------|------------------------------------------------------------------------------------------------------------| -| `rp_L_F` | `cms.PSet` | `47.` - `56.5` | Left far RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for x alignment | -| `rp_L_N` | `cms.PSet` | `9.` - `18.5` | Left near RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for x alignment | -| `rp_R_N` | `cms.PSet` | `7.` - `15.` | Right near RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for x alignment | -| `rp_R_F` | `cms.PSet` | `46.` - `54.` | Right far RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for x alignment | -| `fit_profile_min_bin_entries` | `cms.uint32` | `5` | Minimum number of entries in each bin in fitProfile method | -| `fit_profile_min_N_reasonable` | `cms.uint32` | `10` | Minimum number of valid bins in fitProfile method | -| `meth_o_graph_min_N` | `cms.uint32` | `5` | Minimum number of points in each of reference and test graph | -| `meth_o_unc_fit_range` | `cms.double` | `0.5` | Fit range for chi-square graph. | +## Contents of the package -## x_alignment_relative -| Name | Type | Default | Description | -|------------------------|--------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| -| `rp_L_N` | `cms.PSet` | `7.5` - `12.` | Sector 45 alignment x relative ranges configuration. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for relative x alignment | -| `rp_R_N` | `cms.PSet` | `6.` - `10.` | Sector 56 alignment x relative ranges configuration. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for relative x alignment | -| `near_far_min_entries` | `cms.uint32` | `100` | Minimum number of entries in n+A97:D100ear_far histograms | - -## y_alignment -| Name | Type | Default | Description | -|-------------------------------|--------------|----------------|------------------------------------------------------------------------------------------------------------| -| `rp_L_F` | `cms.PSet` | `44.5` - `49.` | Left far RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for y alignment | -| `rp_L_N` | `cms.PSet` | `6.7` - `11.` | Left near RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for y alignment | -| `rp_R_N` | `cms.PSet` | `5.9` - `10.` | Right near RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for y alignment | -| `rp_R_F` | `cms.PSet` | `44.5` - `49.` | Right far RP. Contains two parameters of type `cms.double`: `x_min` and `x_max` - x range for y alignment | -| `mode_graph_min_N` | `cms.uint32` | `5` | Minimum number of points in mode graph | -| `mult_sel_proj_y_min_entries` | `cms.uint32` | `300` | Minimum number of entries in y projection of multiplicity selection histograms | - -## binning -| Name | Type | Default | Description | -|-------------------|--------------|---------------|------------------------------------------| -| `bin_size_x` | `cms.double` | `142.3314E-3` | X bin size | -| `n_bins_x` | `cms.uint32` | `210` | Number of bins in many histograms | -| `pixel_x_offset` | `cms.double` | `40.` | Pixel x offset | -| `n_bins_y` | `cms.uint32` | `400` | Number of bins in many histograms | -| `y_min` | `cms.double` | `-20.` | Min y for 2D histograms | -| `y_max` | `cms.double` | `20.` | Max y for 2D histograms | -| `diffFN_n_bins_x` | `cms.uint32` | `100` | Number of bins in near-far profiles | -| `diffFN_x_min` | `cms.double` | `0.` | X axis min for near-far profiles | -| `diffFN_x_max` | `cms.double` | `20.` | X axis max for near-far profiles | -| `slice_n_bins_x` | `cms.uint32` | `100` | Number of bins in x axis for slice plots | -| `slice_x_min` | `cms.double` | `-10.` | X axis min for slice plots | -| `slice_x_max` | `cms.double` | `10.` | X axis max for slice plots | -| `slice_n_bins_y` | `cms.uint32` | `100` | Number of bins in y axis for slice plots | -| `slice_y_min` | `cms.double` | `-2.` | Y axis min for slice plots | -| `slice_y_max` | `cms.double` | `2.` | Y axis max for slice plots | \ No newline at end of file +- *interface* and *src* - declarations and definitions of auxiliary functions +- *plugins* - implementation of the main modules: `PPSAlignmentWorker` and `PPSAlignmentHarvester` +- *python* - configuration files used by the PPS alignment matrix test and the PCL +- *test* - example configuration files, instructions on how to run them, and expected results diff --git a/CalibPPS/AlignmentGlobal/interface/utils.h b/CalibPPS/AlignmentGlobal/interface/utils.h new file mode 100644 index 0000000000000..43d7b5fd4fb4a --- /dev/null +++ b/CalibPPS/AlignmentGlobal/interface/utils.h @@ -0,0 +1,25 @@ +/**************************************************************************** +* Authors: +* Jan Kašpar (jan.kaspar@gmail.com) +* Mateusz Kocot (mateuszkocot99@gmail.com) +****************************************************************************/ + +#ifndef CalibPPS_AlignmentGlobal_utils_h +#define CalibPPS_AlignmentGlobal_utils_h + +#include "TProfile.h" + +namespace alig_utils { + + // Fits a linear function to a TProfile. + int fitProfile(TProfile* p, + double x_mean, + double x_rms, + unsigned int minBinEntries, + unsigned int minNBinsReasonable, + double& sl, + double& sl_unc); + +} // namespace alig_utils + +#endif diff --git a/CalibPPS/AlignmentGlobal/plugins/BuildFile.xml b/CalibPPS/AlignmentGlobal/plugins/BuildFile.xml index aa1c70dbc725d..447dba4a45165 100644 --- a/CalibPPS/AlignmentGlobal/plugins/BuildFile.xml +++ b/CalibPPS/AlignmentGlobal/plugins/BuildFile.xml @@ -10,6 +10,7 @@ + diff --git a/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentHarvester.cc b/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentHarvester.cc index d8b52504193be..2418dd15b9dae 100644 --- a/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentHarvester.cc +++ b/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentHarvester.cc @@ -23,14 +23,16 @@ #include "CondFormats/PPSObjects/interface/PPSAlignmentConfiguration.h" #include "CondFormats/DataRecord/interface/PPSAlignmentConfigurationRcd.h" +#include "CalibPPS/AlignmentGlobal/interface/utils.h" + #include #include #include #include -#include #include #include #include +#include #include "TH1D.h" #include "TH2D.h" @@ -40,7 +42,6 @@ #include "TProfile.h" #include "TFile.h" #include "TKey.h" -#include "TSystemFile.h" #include "TSpline.h" #include "TCanvas.h" @@ -61,61 +62,48 @@ class PPSAlignmentHarvester : public DQMEDHarvester { edm::EventSetup const& iSetup) override; // ------------ x alignment ------------ - static int fitProfile(TProfile* p, - double x_mean, - double x_rms, - unsigned int fitProfileMinBinEntries, - unsigned int fitProfileMinNReasonable, - double& sl, - double& sl_unc); std::unique_ptr buildGraphFromVector(const std::vector& pv); std::unique_ptr buildGraphFromMonitorElements(DQMStore::IGetter& iGetter, const PPSAlignmentConfiguration::RPConfig& rpc, const std::vector& mes, - unsigned int fitProfileMinBinEntries, - unsigned int fitProfileMinNReasonable); + const unsigned int fitProfileMinBinEntries, + const unsigned int fitProfileMinNReasonable); 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, + const double sh_min, + const double sh_max, double& sh_best, double& sh_best_unc); void xAlignment(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter, const PPSAlignmentConfiguration& cfg, - const PPSAlignmentConfiguration& cfg_ref, - int seqPos); + const PPSAlignmentConfiguration& cfg_ref); std::map sh_x_map_; // ------------ x alignment relative ------------ - void xAlignmentRelative(DQMStore::IBooker& iBooker, - DQMStore::IGetter& iGetter, - const PPSAlignmentConfiguration& cfg, - int seqPos); + void xAlignmentRelative(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter, const PPSAlignmentConfiguration& cfg); // ------------ y alignment ------------ - static double findMax(TF1* ff_fit); + static double findMax(const TF1* ff_fit); TH1D* buildModeGraph(DQMStore::IBooker& iBooker, - MonitorElement* h2_y_vs_x, + const MonitorElement* h2_y_vs_x, const PPSAlignmentConfiguration& cfg, const PPSAlignmentConfiguration::RPConfig& rpc); - void yAlignment(DQMStore::IBooker& iBooker, - DQMStore::IGetter& iGetter, - const PPSAlignmentConfiguration& cfg, - int seqPos); + void yAlignment(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter, const PPSAlignmentConfiguration& cfg); // ------------ other member data and methods ------------ - static void writeCutPlot(TH2D* h, double a, double c, double si, double n_si, const std::string& label); + static void writeCutPlot( + TH2D* h, const double a, const double c, const double si, const double n_si, const std::string& label); static std::unique_ptr getTH1DFromTGraphErrors(TGraphErrors* graph, - std::string title = "", - std::string labels = "", + const std::string& title = "", + const std::string& labels = "", int n = -1, double binWidth = -1., double min = -1.); @@ -124,17 +112,20 @@ class PPSAlignmentHarvester : public DQMEDHarvester { edm::ESGetToken esTokenReference_; // variables from parameters - const std::string folder_; + const std::string dqmDir_; const std::vector sequence_; - bool overwriteShX_; + const bool overwriteShX_; const bool writeSQLiteResults_; const bool xAliRelFinalSlopeFixed_; const bool yAliFinalSlopeFixed_; + const std::pair xCorrRange_; + const std::pair yCorrRange_; const bool debug_; // other class variables std::unique_ptr debugFile_; std::ofstream textResultsFile_; + int seqPos = 1; // position in sequence_ CTPPSRPAlignmentCorrectionsData xAliResults_; @@ -152,12 +143,16 @@ PPSAlignmentHarvester::PPSAlignmentHarvester(const edm::ParameterSet& iConfig) edm::ESInputTag("", ""))), esTokenReference_(esConsumes( edm::ESInputTag("", "reference"))), - folder_(iConfig.getParameter("folder")), + dqmDir_(iConfig.getParameter("dqm_dir")), sequence_(iConfig.getParameter>("sequence")), overwriteShX_(iConfig.getParameter("overwrite_sh_x")), writeSQLiteResults_(iConfig.getParameter("write_sqlite_results")), xAliRelFinalSlopeFixed_(iConfig.getParameter("x_ali_rel_final_slope_fixed")), yAliFinalSlopeFixed_(iConfig.getParameter("y_ali_final_slope_fixed")), + xCorrRange_(std::make_pair(iConfig.getParameter("x_corr_min") / 1000., + iConfig.getParameter("x_corr_max") / 1000.)), // um -> mm + yCorrRange_(std::make_pair(iConfig.getParameter("y_corr_min") / 1000., + iConfig.getParameter("y_corr_max") / 1000.)), // um -> mm debug_(iConfig.getParameter("debug")) { auto textResultsPath = iConfig.getParameter("text_results_path"); if (!textResultsPath.empty()) { @@ -167,9 +162,9 @@ PPSAlignmentHarvester::PPSAlignmentHarvester(const edm::ParameterSet& iConfig) debugFile_ = std::make_unique("debug_harvester.root", "recreate"); } - edm::LogInfo("PPS").log([&](auto& li) { - li << "[harvester] parameters:\n"; - li << "* folder: " << folder_ << "\n"; + edm::LogInfo("PPSAlignmentHarvester").log([&](auto& li) { + li << "parameters:\n"; + li << "* dqm_dir: " << dqmDir_ << "\n"; li << "* sequence:\n"; for (unsigned int i = 0; i < sequence_.size(); i++) { li << " " << i + 1 << ": " << sequence_[i] << "\n"; @@ -179,7 +174,12 @@ PPSAlignmentHarvester::PPSAlignmentHarvester(const edm::ParameterSet& iConfig) li << "* write_sqlite_results: " << std::boolalpha << writeSQLiteResults_ << "\n"; li << "* x_ali_rel_final_slope_fixed: " << std::boolalpha << xAliRelFinalSlopeFixed_ << "\n"; li << "* y_ali_final_slope_fixed: " << std::boolalpha << yAliFinalSlopeFixed_ << "\n"; - li << "* debug: " << std::boolalpha << debug_; + // print in um + li << "* x_corr_min: " << std::fixed << xCorrRange_.first * 1000. << ", x_corr_max: " << xCorrRange_.second * 1000. + << "\n"; + // print in um + li << "* y_corr_min: " << std::fixed << yCorrRange_.first * 1000. << ", y_corr_max: " << yCorrRange_.second * 1000.; + li << "* debug: " << std::boolalpha << debug_ << "\n"; }); } @@ -192,13 +192,17 @@ PPSAlignmentHarvester::~PPSAlignmentHarvester() { void PPSAlignmentHarvester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("folder", "AlCaReco/PPSAlignment"); + desc.add("dqm_dir", "AlCaReco/PPSAlignment"); desc.add>("sequence", {"x_alignment", "x_alignment_relative", "y_alignment"}); desc.add("overwrite_sh_x", true); desc.add("text_results_path", "./alignment_results.txt"); desc.add("write_sqlite_results", false); desc.add("x_ali_rel_final_slope_fixed", true); desc.add("y_ali_final_slope_fixed", true); + desc.add("x_corr_min", -1'000'000.); + desc.add("x_corr_max", 1'000'000.); + desc.add("y_corr_min", -1'000'000.); + desc.add("y_corr_max", 1'000'000.); desc.add("debug", false); descriptions.addWithDefaultLabel(desc); @@ -220,8 +224,8 @@ void PPSAlignmentHarvester::dqmEndRun(DQMStore::IBooker& iBooker, sh_x_map_[rpc.id_] = rpc.sh_x_; } } - edm::LogInfo("PPS").log([&](auto& li) { - li << "[harvester] Setting sh_x from config of:\n"; + edm::LogInfo("PPSAlignmentHarvester").log([&](auto& li) { + li << "Setting sh_x from config of:\n"; for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) { for (const auto& rpc : {sc.rp_N_, sc.rp_F_}) { li << " " << rpc.name_ << " to " << std::fixed << std::setprecision(3) << rpc.sh_x_; @@ -232,18 +236,19 @@ void PPSAlignmentHarvester::dqmEndRun(DQMStore::IBooker& iBooker, }); bool doXAli = false, doXAliRel = false, doYAli = false; - for (unsigned int i = 0; i < sequence_.size(); i++) { - if (sequence_[i] == "x_alignment") { - xAlignment(iBooker, iGetter, cfg, cfg_ref, i); + for (const std::string& aliMethod : sequence_) { + if (aliMethod == "x_alignment") { + xAlignment(iBooker, iGetter, cfg, cfg_ref); doXAli = true; - } else if (sequence_[i] == "x_alignment_relative") { - xAlignmentRelative(iBooker, iGetter, cfg, i); + } else if (aliMethod == "x_alignment_relative") { + xAlignmentRelative(iBooker, iGetter, cfg); doXAliRel = true; - } else if (sequence_[i] == "y_alignment") { - yAlignment(iBooker, iGetter, cfg, i); + } else if (aliMethod == "y_alignment") { + yAlignment(iBooker, iGetter, cfg); doYAli = true; } else - edm::LogError("PPS") << "[harvester] " << sequence_[i] << " is a wrong method name."; + edm::LogError("PPSAlignmentHarvester") << aliMethod << " is a wrong method name."; + seqPos++; } // merge results from all the specified methods @@ -284,8 +289,31 @@ void PPSAlignmentHarvester::dqmEndRun(DQMStore::IBooker& iBooker, } } + // check if the results are within the reasonability ranges xCorrRange and yCorrRange + for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) { + for (const auto& rpc : {sc.rp_F_, sc.rp_N_}) { + auto& rpResults = finalResults.getRPCorrection(rpc.id_); + + if (!(xCorrRange_.first <= rpResults.getShX() && rpResults.getShX() <= xCorrRange_.second)) { + edm::LogWarning("PPSAlignmentHarvester") + << "The horizontal shift of " << rpc.name_ << " (" << std::fixed << std::setw(9) << std::setprecision(1) + << rpResults.getShX() * 1000. << " um) outside of the reasonability range. Setting it to 0."; + rpResults.setShX(0.); + rpResults.setShXUnc(0.); + } + + if (!(yCorrRange_.first <= rpResults.getShY() && rpResults.getShY() <= yCorrRange_.second)) { + edm::LogWarning("PPSAlignmentHarvester") + << "The vertical shift of " << rpc.name_ << " (" << std::fixed << std::setw(9) << std::setprecision(1) + << rpResults.getShY() * 1000. << " um) outside of the reasonability range. Setting it to 0."; + rpResults.setShY(0.); + rpResults.setShYUnc(0.); + } + } + } + // print the text results - edm::LogInfo("PPS") << "final merged results:\n" << finalResults; + edm::LogInfo("PPSAlignmentHarvester") << "final merged results:\n" << finalResults; if (textResultsFile_.is_open()) { textResultsFile_ << "final merged results:\n" << finalResults; @@ -297,7 +325,8 @@ void PPSAlignmentHarvester::dqmEndRun(DQMStore::IBooker& iBooker, if (poolDbService.isAvailable()) { poolDbService->writeOneIOV(finalResults, poolDbService->currentTime(), "CTPPSRPAlignmentCorrectionsDataRcd"); } else { - edm::LogWarning("PPS") << "Could not store the results in a DB object. PoolDBService not available."; + edm::LogWarning("PPSAlignmentHarvester") + << "Could not store the results in a DB object. PoolDBService not available."; } } @@ -308,15 +337,15 @@ void PPSAlignmentHarvester::dqmEndRun(DQMStore::IBooker& iBooker, TDirectory* sectorDir = cutsDir->mkdir(sc.name_.c_str()); gDirectory = sectorDir->mkdir("cut_h"); - auto* h2_cut_h_bef_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_h/h2_cut_h_bef"); - auto* h2_cut_h_aft_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_h/h2_cut_h_aft"); + auto* h2_cut_h_bef_monitor = iGetter.get(dqmDir_ + "/worker/" + sc.name_ + "/cuts/cut_h/h2_cut_h_bef"); + auto* h2_cut_h_aft_monitor = iGetter.get(dqmDir_ + "/worker/" + sc.name_ + "/cuts/cut_h/h2_cut_h_aft"); writeCutPlot( h2_cut_h_bef_monitor->getTH2D(), sc.cut_h_a_, sc.cut_h_c_, cfg.n_si(), sc.cut_h_si_, "canvas_before"); writeCutPlot(h2_cut_h_aft_monitor->getTH2D(), sc.cut_h_a_, sc.cut_h_c_, cfg.n_si(), sc.cut_h_si_, "canvas_after"); gDirectory = sectorDir->mkdir("cut_v"); - auto* h2_cut_v_bef_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_v/h2_cut_v_bef"); - auto* h2_cut_v_aft_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_v/h2_cut_v_aft"); + auto* h2_cut_v_bef_monitor = iGetter.get(dqmDir_ + "/worker/" + sc.name_ + "/cuts/cut_v/h2_cut_v_bef"); + auto* h2_cut_v_aft_monitor = iGetter.get(dqmDir_ + "/worker/" + sc.name_ + "/cuts/cut_v/h2_cut_v_aft"); writeCutPlot( h2_cut_v_bef_monitor->getTH2D(), sc.cut_v_a_, sc.cut_v_c_, cfg.n_si(), sc.cut_v_si_, "canvas_before"); writeCutPlot(h2_cut_v_aft_monitor->getTH2D(), sc.cut_v_a_, sc.cut_v_c_, cfg.n_si(), sc.cut_v_si_, "canvas_after"); @@ -326,40 +355,6 @@ void PPSAlignmentHarvester::dqmEndRun(DQMStore::IBooker& iBooker, // -------------------------------- x alignment methods -------------------------------- -// Fits a linear function to a TProfile (similar method in PPSAlignmentConfigurationESSource). -int PPSAlignmentHarvester::fitProfile(TProfile* p, - double x_mean, - double x_rms, - unsigned int fitProfileMinBinEntries, - unsigned int fitProfileMinNReasonable, - double& sl, - double& sl_unc) { - unsigned int n_reasonable = 0; - for (int bi = 1; bi <= p->GetNbinsX(); bi++) { - if (p->GetBinEntries(bi) < fitProfileMinBinEntries) { - p->SetBinContent(bi, 0.); - p->SetBinError(bi, 0.); - } else { - n_reasonable++; - } - } - - if (n_reasonable < fitProfileMinNReasonable) - return 1; - - double x_min = x_mean - x_rms, x_max = x_mean + x_rms; - - auto ff_pol1 = std::make_unique("ff_pol1", "[0] + [1]*x"); - - ff_pol1->SetParameter(0., 0.); - p->Fit(ff_pol1.get(), "Q", "", x_min, x_max); - - sl = ff_pol1->GetParameter(1); - sl_unc = ff_pol1->GetParError(1); - - return 0; -} - // Builds graph from a vector of points (with errors). std::unique_ptr PPSAlignmentHarvester::buildGraphFromVector( const std::vector& pv) { @@ -380,8 +375,8 @@ std::unique_ptr PPSAlignmentHarvester::buildGraphFromMonitorElemen DQMStore::IGetter& iGetter, const PPSAlignmentConfiguration::RPConfig& rpc, const std::vector& mes, - unsigned int fitProfileMinBinEntries, - unsigned int fitProfileMinNReasonable) { + const unsigned int fitProfileMinBinEntries, + const unsigned int fitProfileMinNReasonable) { auto g = std::make_unique(); for (auto* me : mes) { @@ -400,20 +395,17 @@ std::unique_ptr PPSAlignmentHarvester::buildGraphFromMonitorElemen // collect "p_y_diffFN_vs_y" corresponding to found "h_y" auto* p_y_diffFN_vs_y_monitor = iGetter.get(parentPath + "p_y_diffFN_vs_y"); if (p_y_diffFN_vs_y_monitor == nullptr) { - edm::LogWarning("PPS") << "[x_alignment] could not find p_y_diffFN_vs_y in: " << parentPath; + edm::LogWarning("PPSAlignmentHarvester") << "[x_alignment] could not find p_y_diffFN_vs_y in: " << parentPath; continue; } TProfile* p_y_diffFN_vs_y = p_y_diffFN_vs_y_monitor->getTProfile(); - double y_cen = h_y->GetMean(); - double y_width = h_y->GetRMS(); - - y_cen += rpc.y_cen_add_; - y_width *= rpc.y_width_mult_; + double y_cen = h_y->GetMean() + rpc.y_cen_add_; + double y_width = h_y->GetRMS() * rpc.y_width_mult_; - double sl = 0., sl_unc = 0.; - int fr = - fitProfile(p_y_diffFN_vs_y, y_cen, y_width, fitProfileMinBinEntries, fitProfileMinNReasonable, sl, sl_unc); + double sl, sl_unc; + int fr = alig_utils::fitProfile( + p_y_diffFN_vs_y, y_cen, y_width, fitProfileMinBinEntries, fitProfileMinNReasonable, sl, sl_unc); if (fr != 0) continue; @@ -437,16 +429,17 @@ void PPSAlignmentHarvester::doMatch(DQMStore::IBooker& iBooker, TGraphErrors* g_ref, TGraphErrors* g_test, const PPSAlignmentConfiguration::SelectionRange& range_ref, - double sh_min, - double sh_max, + const double sh_min, + const double sh_max, double& sh_best, double& sh_best_unc) { const auto range_test = cfg.alignment_x_meth_o_ranges().at(rpc.id_); // print config - edm::LogInfo("PPS") << std::fixed << std::setprecision(3) << "[x_alignment] " - << "ref: x_min = " << range_ref.x_min_ << ", x_max = " << range_ref.x_max_ << "\n" - << "test: x_min = " << range_test.x_min_ << ", x_max = " << range_test.x_max_; + edm::LogInfo("PPSAlignmentHarvester") << std::fixed << std::setprecision(3) << "[x_alignment] " + << "ref: x_min = " << range_ref.x_min_ << ", x_max = " << range_ref.x_max_ + << "\n" + << "test: x_min = " << range_test.x_min_ << ", x_max = " << range_test.x_max_; // make spline from g_ref auto s_ref = std::make_unique("s_ref", g_ref->GetX(), g_ref->GetY(), g_ref->GetN()); @@ -529,8 +522,8 @@ void PPSAlignmentHarvester::doMatch(DQMStore::IBooker& iBooker, sh_best_unc = 1. / sqrt(ff_pol2->GetParameter(2)); // print results - edm::LogInfo("PPS") << std::fixed << std::setprecision(3) << "[x_alignment] " - << "sh_best = (" << sh_best << " +- " << sh_best_unc << ") mm"; + edm::LogInfo("PPSAlignmentHarvester") << std::fixed << std::setprecision(3) << "[x_alignment] " + << "sh_best = (" << sh_best << " +- " << sh_best_unc << ") mm"; auto g_test_shifted = std::make_unique(*g_test); for (int i = 0; i < g_test_shifted->GetN(); ++i) { @@ -579,24 +572,18 @@ void PPSAlignmentHarvester::doMatch(DQMStore::IBooker& iBooker, void PPSAlignmentHarvester::xAlignment(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter, const PPSAlignmentConfiguration& cfg, - const PPSAlignmentConfiguration& cfg_ref, - int seqPos) { + const PPSAlignmentConfiguration& cfg_ref) { TDirectory* xAliDir = nullptr; if (debug_) - xAliDir = debugFile_->mkdir((std::to_string(seqPos + 1) + ": x alignment").c_str()); + xAliDir = debugFile_->mkdir((std::to_string(seqPos) + ": x alignment").c_str()); - for (const auto& scPair : {std::make_pair(cfg.sectorConfig45(), cfg_ref.sectorConfig45()), - std::make_pair(cfg.sectorConfig56(), cfg_ref.sectorConfig56())}) { - const auto& sc = scPair.first; - const auto& sc_ref = scPair.second; - - for (const auto& rpcPair : {std::make_pair(sc.rp_F_, sc_ref.rp_F_), std::make_pair(sc.rp_N_, sc_ref.rp_N_)}) { - const auto& rpc = rpcPair.first; - const auto& rpc_ref = rpcPair.second; - - auto mes_test = iGetter.getAllContents(folder_ + "/worker/" + sc.name_ + "/near_far/x slices, " + rpc.position_); + for (const auto& [sc, sc_ref] : {std::make_pair(cfg.sectorConfig45(), cfg_ref.sectorConfig45()), + std::make_pair(cfg.sectorConfig56(), cfg_ref.sectorConfig56())}) { + for (const auto& [rpc, rpc_ref] : + {std::make_pair(sc.rp_F_, sc_ref.rp_F_), std::make_pair(sc.rp_N_, sc_ref.rp_N_)}) { + auto mes_test = iGetter.getAllContents(dqmDir_ + "/worker/" + sc.name_ + "/near_far/x slices, " + rpc.position_); if (mes_test.empty()) { - edm::LogWarning("PPS") << "[x_alignment] " << rpc.name_ << ": could not load mes_test"; + edm::LogWarning("PPSAlignmentHarvester") << "[x_alignment] " << rpc.name_ << ": could not load mes_test"; continue; } @@ -606,7 +593,7 @@ void PPSAlignmentHarvester::xAlignment(DQMStore::IBooker& iBooker, auto vec_ref = cfg_ref.matchingReferencePoints().at(rpc.id_); if (vec_ref.empty()) { - edm::LogInfo("PPS") << "[x_alignment] " << rpc.name_ << ": reference points vector is empty"; + edm::LogInfo("PPSAlignmentHarvester") << "[x_alignment] " << rpc.name_ << ": reference points vector is empty"; continue; } @@ -619,13 +606,13 @@ void PPSAlignmentHarvester::xAlignment(DQMStore::IBooker& iBooker, // require minimal number of points if (g_ref->GetN() < (int)cfg.methOGraphMinN() || g_test->GetN() < (int)cfg.methOGraphMinN()) { - edm::LogWarning("PPS") << "[x_alignment] " << rpc.name_ << ": insufficient data, skipping (g_ref " - << g_ref->GetN() << "/" << cfg.methOGraphMinN() << ", g_test " << g_test->GetN() << "/" - << cfg.methOGraphMinN() << ")"; + edm::LogWarning("PPSAlignmentHarvester") + << "[x_alignment] " << rpc.name_ << ": insufficient data, skipping (g_ref " << g_ref->GetN() << "/" + << cfg.methOGraphMinN() << ", g_test " << g_test->GetN() << "/" << cfg.methOGraphMinN() << ")"; continue; } - iBooker.setCurrentFolder(folder_ + "/harvester/x alignment/" + rpc.name_); + iBooker.setCurrentFolder(dqmDir_ + "/harvester/x alignment/" + rpc.name_); std::unique_ptr histPtr = getTH1DFromTGraphErrors( g_ref.get(), "ref", ";x (mm);S", rpc_ref.x_slice_n_, rpc_ref.x_slice_w_, rpc_ref.x_slice_min_); @@ -661,8 +648,8 @@ void PPSAlignmentHarvester::xAlignment(DQMStore::IBooker& iBooker, // save the results CTPPSRPAlignmentCorrectionData rpResult(sh, sh_unc, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.); xAliResults_.setRPCorrection(rpc.id_, rpResult); - edm::LogInfo("PPS") << std::fixed << std::setprecision(3) << "[x_alignment] " - << "Setting sh_x of " << rpc.name_ << " to " << sh; + edm::LogInfo("PPSAlignmentHarvester") << std::fixed << std::setprecision(3) << "[x_alignment] " + << "Setting sh_x of " << rpc.name_ << " to " << sh; // update the shift if (overwriteShX_) { @@ -671,21 +658,20 @@ void PPSAlignmentHarvester::xAlignment(DQMStore::IBooker& iBooker, } } - edm::LogInfo("PPS") << seqPos + 1 << ": x_alignment:\n" << xAliResults_; + edm::LogInfo("PPSAlignmentHarvester") << seqPos << ": x_alignment:\n" << xAliResults_; if (textResultsFile_.is_open()) - textResultsFile_ << seqPos + 1 << ": x_alignment:\n" << xAliResults_ << "\n\n"; + textResultsFile_ << seqPos << ": x_alignment:\n" << xAliResults_ << "\n\n"; } // -------------------------------- x alignment relative methods -------------------------------- void PPSAlignmentHarvester::xAlignmentRelative(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter, - const PPSAlignmentConfiguration& cfg, - int seqPos) { + const PPSAlignmentConfiguration& cfg) { TDirectory* xAliRelDir = nullptr; if (debug_) - xAliRelDir = debugFile_->mkdir((std::to_string(seqPos + 1) + ": x_alignment_relative").c_str()); + xAliRelDir = debugFile_->mkdir((std::to_string(seqPos) + ": x_alignment_relative").c_str()); auto ff = std::make_unique("ff", "[0] + [1]*(x - [2])"); auto ff_sl_fix = std::make_unique("ff_sl_fix", "[0] + [1]*(x - [2])"); @@ -698,16 +684,18 @@ void PPSAlignmentHarvester::xAlignmentRelative(DQMStore::IBooker& iBooker, gDirectory = sectorDir; } - auto* p_x_diffFN_vs_x_N_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/near_far/p_x_diffFN_vs_x_N"); + auto* p_x_diffFN_vs_x_N_monitor = iGetter.get(dqmDir_ + "/worker/" + sc.name_ + "/near_far/p_x_diffFN_vs_x_N"); if (p_x_diffFN_vs_x_N_monitor == nullptr) { - edm::LogWarning("PPS") << "[x_alignment_relative] " << sc.name_ << ": cannot load data, skipping"; + edm::LogWarning("PPSAlignmentHarvester") + << "[x_alignment_relative] " << sc.name_ << ": cannot load data, skipping"; continue; } TProfile* p_x_diffFN_vs_x_N = p_x_diffFN_vs_x_N_monitor->getTProfile(); if (p_x_diffFN_vs_x_N->GetEntries() < cfg.nearFarMinEntries()) { - edm::LogWarning("PPS") << "[x_alignment_relative] " << sc.name_ << ": insufficient data, skipping (near_far " - << p_x_diffFN_vs_x_N->GetEntries() << "/" << cfg.nearFarMinEntries() << ")"; + edm::LogWarning("PPSAlignmentHarvester") + << "[x_alignment_relative] " << sc.name_ << ": insufficient data, skipping (near_far " + << p_x_diffFN_vs_x_N->GetEntries() << "/" << cfg.nearFarMinEntries() << ")"; continue; } @@ -717,6 +705,7 @@ void PPSAlignmentHarvester::xAlignmentRelative(DQMStore::IBooker& iBooker, const double sh_x_N = sh_x_map_[sc.rp_N_.id_]; double slope = sc.slope_; + // calculate the results without slope fixed ff->SetParameters(0., slope, 0.); ff->FixParameter(2, -sh_x_N); ff->SetLineColor(2); @@ -725,16 +714,17 @@ void PPSAlignmentHarvester::xAlignmentRelative(DQMStore::IBooker& iBooker, const double a = ff->GetParameter(1), a_unc = ff->GetParError(1); const double b = ff->GetParameter(0), b_unc = ff->GetParError(0); - edm::LogInfo("PPS") << "[x_alignment_relative] " << sc.name_ << ":\n" - << std::fixed << std::setprecision(3) << " x_min = " << x_min << ", x_max = " << x_max - << "\n" - << " sh_x_N = " << sh_x_N << ", slope (fix) = " << slope << ", slope (fitted) = " << a; + edm::LogInfo("PPSAlignmentHarvester") + << "[x_alignment_relative] " << sc.name_ << ":\n" + << std::fixed << std::setprecision(3) << " x_min = " << x_min << ", x_max = " << x_max << "\n" + << " sh_x_N = " << sh_x_N << ", slope (fix) = " << slope << ", slope (fitted) = " << a; CTPPSRPAlignmentCorrectionData rpResult_N(+b / 2., b_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.); xAliRelResults_.setRPCorrection(sc.rp_N_.id_, rpResult_N); CTPPSRPAlignmentCorrectionData rpResult_F(-b / 2., b_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.); xAliRelResults_.setRPCorrection(sc.rp_F_.id_, rpResult_F); + // calculate the results with slope fixed ff_sl_fix->SetParameters(0., slope, 0.); ff_sl_fix->FixParameter(1, slope); ff_sl_fix->FixParameter(2, -sh_x_N); @@ -748,13 +738,13 @@ void PPSAlignmentHarvester::xAlignmentRelative(DQMStore::IBooker& iBooker, CTPPSRPAlignmentCorrectionData rpResult_sl_fix_F(-b_fs / 2., b_fs_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.); xAliRelResultsSlopeFixed_.setRPCorrection(sc.rp_F_.id_, rpResult_sl_fix_F); - edm::LogInfo("PPS") << "[x_alignment_relative] " << std::fixed << std::setprecision(3) - << "ff: " << ff->GetParameter(0) << " + " << ff->GetParameter(1) << " * (x - " - << ff->GetParameter(2) << "), ff_sl_fix: " << ff_sl_fix->GetParameter(0) << " + " - << ff_sl_fix->GetParameter(1) << " * (x - " << ff_sl_fix->GetParameter(2) << ")"; + edm::LogInfo("PPSAlignmentHarvester") + << "[x_alignment_relative] " << std::fixed << std::setprecision(3) << "ff: " << ff->GetParameter(0) << " + " + << ff->GetParameter(1) << " * (x - " << ff->GetParameter(2) << "), ff_sl_fix: " << ff_sl_fix->GetParameter(0) + << " + " << ff_sl_fix->GetParameter(1) << " * (x - " << ff_sl_fix->GetParameter(2) << ")"; // rebook the diffFN plot in the harvester - iBooker.setCurrentFolder(folder_ + "/harvester/x_alignment_relative/" + sc.name_); + iBooker.setCurrentFolder(dqmDir_ + "/harvester/x_alignment_relative/" + sc.name_); iBooker.bookProfile("p_x_diffFN_vs_x_N", p_x_diffFN_vs_x_N); if (debug_) { @@ -770,19 +760,19 @@ void PPSAlignmentHarvester::xAlignmentRelative(DQMStore::IBooker& iBooker, } // write results - edm::LogInfo("PPS") << seqPos + 1 << ": x_alignment_relative:\n" - << xAliRelResults_ << seqPos + 1 << ": x_alignment_relative_sl_fix:\n" - << xAliRelResultsSlopeFixed_; + edm::LogInfo("PPSAlignmentHarvester") << seqPos << ": x_alignment_relative:\n" + << xAliRelResults_ << seqPos + 1 << ": x_alignment_relative_sl_fix:\n" + << xAliRelResultsSlopeFixed_; if (textResultsFile_.is_open()) { - textResultsFile_ << seqPos + 1 << ": x_alignment_relative:\n" << xAliRelResults_ << "\n"; - textResultsFile_ << seqPos + 1 << ": x_alignment_relative_sl_fix:\n" << xAliRelResultsSlopeFixed_ << "\n\n"; + textResultsFile_ << seqPos << ": x_alignment_relative:\n" << xAliRelResults_ << "\n"; + textResultsFile_ << seqPos << ": x_alignment_relative_sl_fix:\n" << xAliRelResultsSlopeFixed_ << "\n\n"; } } // -------------------------------- y alignment methods -------------------------------- -double PPSAlignmentHarvester::findMax(TF1* ff_fit) { +double PPSAlignmentHarvester::findMax(const TF1* ff_fit) { const double mu = ff_fit->GetParameter(1); const double si = ff_fit->GetParameter(2); @@ -804,7 +794,7 @@ double PPSAlignmentHarvester::findMax(TF1* ff_fit) { } TH1D* PPSAlignmentHarvester::buildModeGraph(DQMStore::IBooker& iBooker, - MonitorElement* h2_y_vs_x, + const MonitorElement* h2_y_vs_x, const PPSAlignmentConfiguration& cfg, const PPSAlignmentConfiguration::RPConfig& rpc) { TDirectory* d_top = nullptr; @@ -821,6 +811,7 @@ TH1D* PPSAlignmentHarvester::buildModeGraph(DQMStore::IBooker& iBooker, h2_y_vs_x->getTH2D()->GetXaxis()->GetBinCenter(1) - diff, h2_y_vs_x->getTH2D()->GetXaxis()->GetBinCenter(h_n) + diff); + // find mode for each bin for (int bix = 1; bix <= h_n; bix++) { const double x = h2_y_vs_x->getTH2D()->GetXaxis()->GetBinCenter(bix); @@ -892,11 +883,10 @@ TH1D* PPSAlignmentHarvester::buildModeGraph(DQMStore::IBooker& iBooker, void PPSAlignmentHarvester::yAlignment(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter, - const PPSAlignmentConfiguration& cfg, - int seqPos) { + const PPSAlignmentConfiguration& cfg) { TDirectory* yAliDir = nullptr; if (debug_) - yAliDir = debugFile_->mkdir((std::to_string(seqPos + 1) + ": y_alignment").c_str()); + yAliDir = debugFile_->mkdir((std::to_string(seqPos) + ": y_alignment").c_str()); auto ff = std::make_unique("ff", "[0] + [1]*(x - [2])"); auto ff_sl_fix = std::make_unique("ff_sl_fix", "[0] + [1]*(x - [2])"); @@ -911,19 +901,20 @@ void PPSAlignmentHarvester::yAlignment(DQMStore::IBooker& iBooker, } auto* h2_y_vs_x = - iGetter.get(folder_ + "/worker/" + sc.name_ + "/multiplicity selection/" + rpc.name_ + "/h2_y_vs_x"); + iGetter.get(dqmDir_ + "/worker/" + sc.name_ + "/multiplicity selection/" + rpc.name_ + "/h2_y_vs_x"); if (h2_y_vs_x == nullptr) { - edm::LogWarning("PPS") << "[y_alignment] " << rpc.name_ << ": cannot load data, skipping"; + edm::LogWarning("PPSAlignmentHarvester") << "[y_alignment] " << rpc.name_ << ": cannot load data, skipping"; continue; } - iBooker.setCurrentFolder(folder_ + "/harvester/y alignment/" + rpc.name_); + iBooker.setCurrentFolder(dqmDir_ + "/harvester/y alignment/" + rpc.name_); auto* h_y_cen_vs_x = buildModeGraph(iBooker, h2_y_vs_x, cfg, rpc); if ((unsigned int)h_y_cen_vs_x->GetEntries() < cfg.modeGraphMinN()) { - edm::LogWarning("PPS") << "[y_alignment] " << rpc.name_ << ": insufficient data, skipping (mode graph " - << h_y_cen_vs_x->GetEntries() << "/" << cfg.modeGraphMinN() << ")"; + edm::LogWarning("PPSAlignmentHarvester") + << "[y_alignment] " << rpc.name_ << ": insufficient data, skipping (mode graph " + << h_y_cen_vs_x->GetEntries() << "/" << cfg.modeGraphMinN() << ")"; continue; } @@ -933,6 +924,7 @@ void PPSAlignmentHarvester::yAlignment(DQMStore::IBooker& iBooker, const double sh_x = sh_x_map_[rpc.id_]; double slope = rpc.slope_; + // calculate the results without slope fixed ff->SetParameters(0., 0., 0.); ff->FixParameter(2, -sh_x); ff->SetLineColor(2); @@ -941,14 +933,15 @@ void PPSAlignmentHarvester::yAlignment(DQMStore::IBooker& iBooker, const double a = ff->GetParameter(1), a_unc = ff->GetParError(1); const double b = ff->GetParameter(0), b_unc = ff->GetParError(0); - edm::LogInfo("PPS") << "[y_alignment] " << rpc.name_ << ":\n" - << std::fixed << std::setprecision(3) << " x_min = " << x_min << ", x_max = " << x_max - << "\n" - << " sh_x = " << sh_x << ", slope (fix) = " << slope << ", slope (fitted) = " << a; + edm::LogInfo("PPSAlignmentHarvester") + << "[y_alignment] " << rpc.name_ << ":\n" + << std::fixed << std::setprecision(3) << " x_min = " << x_min << ", x_max = " << x_max << "\n" + << " sh_x = " << sh_x << ", slope (fix) = " << slope << ", slope (fitted) = " << a; CTPPSRPAlignmentCorrectionData rpResult(0., 0., b, b_unc, 0., 0., 0., 0., 0., 0., 0., 0.); yAliResults_.setRPCorrection(rpc.id_, rpResult); + // calculate the results with slope fixed ff_sl_fix->SetParameters(0., 0., 0.); ff_sl_fix->FixParameter(1, slope); ff_sl_fix->FixParameter(2, -sh_x); @@ -960,10 +953,10 @@ void PPSAlignmentHarvester::yAlignment(DQMStore::IBooker& iBooker, CTPPSRPAlignmentCorrectionData rpResult_sl_fix(0., 0., b_fs, b_fs_unc, 0., 0., 0., 0., 0., 0., 0., 0.); yAliResultsSlopeFixed_.setRPCorrection(rpc.id_, rpResult_sl_fix); - edm::LogInfo("PPS") << "[y_alignment] " << std::fixed << std::setprecision(3) << "ff: " << ff->GetParameter(0) - << " + " << ff->GetParameter(1) << " * (x - " << ff->GetParameter(2) - << "), ff_sl_fix: " << ff_sl_fix->GetParameter(0) << " + " << ff_sl_fix->GetParameter(1) - << " * (x - " << ff_sl_fix->GetParameter(2) << ")"; + edm::LogInfo("PPSAlignmentHarvester") + << "[y_alignment] " << std::fixed << std::setprecision(3) << "ff: " << ff->GetParameter(0) << " + " + << ff->GetParameter(1) << " * (x - " << ff->GetParameter(2) << "), ff_sl_fix: " << ff_sl_fix->GetParameter(0) + << " + " << ff_sl_fix->GetParameter(1) << " * (x - " << ff_sl_fix->GetParameter(2) << ")"; if (debug_) { gDirectory = rpDir; @@ -982,19 +975,21 @@ void PPSAlignmentHarvester::yAlignment(DQMStore::IBooker& iBooker, } // write results - edm::LogInfo("PPS") << seqPos + 1 << ": y_alignment:\n" - << yAliResults_ << seqPos + 1 << ": y_alignment_sl_fix:\n" - << yAliResultsSlopeFixed_; + edm::LogInfo("PPSAlignmentHarvester") << seqPos << ": y_alignment:\n" + << yAliResults_ << seqPos << ": y_alignment_sl_fix:\n" + << yAliResultsSlopeFixed_; if (textResultsFile_.is_open()) { - textResultsFile_ << seqPos + 1 << ": y_alignment:\n" << yAliResults_ << "\n"; - textResultsFile_ << seqPos + 1 << ": y_alignment_sl_fix:\n" << yAliResultsSlopeFixed_ << "\n\n"; + textResultsFile_ << seqPos << ": y_alignment:\n" << yAliResults_ << "\n"; + textResultsFile_ << seqPos << ": y_alignment_sl_fix:\n" << yAliResultsSlopeFixed_ << "\n\n"; } } // -------------------------------- other methods -------------------------------- -void PPSAlignmentHarvester::writeCutPlot(TH2D* h, double a, double c, double n_si, double si, const std::string& label) { +// Creates a plot showing a cut applied by the worker. Used only for debug purposes. +void PPSAlignmentHarvester::writeCutPlot( + TH2D* h, const double a, const double c, const double n_si, const double si, const std::string& label) { auto canvas = std::make_unique(); canvas->SetName(label.c_str()); canvas->SetLogz(1); @@ -1024,7 +1019,7 @@ void PPSAlignmentHarvester::writeCutPlot(TH2D* h, double a, double c, double n_s // Points in TGraph should be sorted (TGraph::Sort()) // if n, binWidth, or min is set to -1, method will find it on its own std::unique_ptr PPSAlignmentHarvester::getTH1DFromTGraphErrors( - TGraphErrors* graph, std::string title, std::string labels, int n, double binWidth, double min) { + TGraphErrors* graph, const std::string& title, const std::string& labels, int n, double binWidth, double min) { std::unique_ptr hist; if (n == 0) { hist = std::make_unique(title.c_str(), labels.c_str(), 0, -10., 10.); diff --git a/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentWorker.cc b/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentWorker.cc index a8f200e7fd073..e73cf5b4533ae 100644 --- a/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentWorker.cc +++ b/CalibPPS/AlignmentGlobal/plugins/PPSAlignmentWorker.cc @@ -48,9 +48,7 @@ class PPSAlignmentWorker : public DQMEDAnalyzer { // hit distributions std::map m_h2_y_vs_x_bef_sel; - std::map m_h2_y_vs_x_mlt_sel; - std::map m_h2_y_vs_x_aft_sel; // cut plots @@ -75,6 +73,7 @@ class PPSAlignmentWorker : public DQMEDAnalyzer { SlicePlots(); SlicePlots(DQMStore::IBooker& iBooker, const PPSAlignmentConfiguration& cfg, bool debug); + void fill(const double y, const double yDiff, const bool debug); }; std::map x_slice_plots_N, x_slice_plots_F; @@ -82,7 +81,7 @@ class PPSAlignmentWorker : public DQMEDAnalyzer { void init(DQMStore::IBooker& iBooker, const PPSAlignmentConfiguration& cfg, const PPSAlignmentConfiguration::SectorConfig& scfg, - const std::string& folder, + const std::string& rootDir, bool debug); unsigned int process(const CTPPSLocalTrackLiteCollection& tracks, const PPSAlignmentConfiguration& cfg, bool debug); @@ -97,7 +96,7 @@ class PPSAlignmentWorker : public DQMEDAnalyzer { SectorData sectorData45_; SectorData sectorData56_; - std::string folder_; + std::string dqmDir_; bool debug_; }; @@ -110,13 +109,13 @@ PPSAlignmentWorker::PPSAlignmentWorker(const edm::ParameterSet& iConfig) esTokenAnalyze_(esConsumes( edm::ESInputTag("", iConfig.getParameter("label")))), tracksToken_(consumes(iConfig.getParameter("tagTracks"))), - folder_(iConfig.getParameter("folder")), + dqmDir_(iConfig.getParameter("dqm_dir")), debug_(iConfig.getParameter("debug")) { - edm::LogInfo("PPS").log([&](auto& li) { - li << "[worker] parameters:\n"; + edm::LogInfo("PPSAlignmentWorker").log([&](auto& li) { + li << "parameters:\n"; li << "* label: " << iConfig.getParameter("label") << "\n"; li << "* tagTracks: " << iConfig.getParameter("tagTracks") << "\n"; - li << "* folder: " << folder_ << "\n"; + li << "* dqm_dir: " << dqmDir_ << "\n"; li << "* debug: " << std::boolalpha << debug_; }); } @@ -124,8 +123,8 @@ PPSAlignmentWorker::PPSAlignmentWorker(const edm::ParameterSet& iConfig) void PPSAlignmentWorker::bookHistograms(DQMStore::IBooker& iBooker, edm::Run const&, edm::EventSetup const& iSetup) { const auto& cfg = iSetup.getData(esTokenBookHistograms_); - sectorData45_.init(iBooker, cfg, cfg.sectorConfig45(), folder_ + "/worker", debug_); - sectorData56_.init(iBooker, cfg, cfg.sectorConfig56(), folder_ + "/worker", debug_); + sectorData45_.init(iBooker, cfg, cfg.sectorConfig45(), dqmDir_ + "/worker", debug_); + sectorData56_.init(iBooker, cfg, cfg.sectorConfig56(), dqmDir_ + "/worker", debug_); } void PPSAlignmentWorker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { @@ -142,7 +141,7 @@ void PPSAlignmentWorker::fillDescriptions(edm::ConfigurationDescriptions& descri desc.add("label", ""); desc.add("tagTracks", edm::InputTag("ctppsLocalTrackLiteProducer")); - desc.add("folder", "AlCaReco/PPSAlignment"); + desc.add("dqm_dir", "AlCaReco/PPSAlignment"); desc.add("debug", false); descriptions.addWithDefaultLabel(desc); @@ -173,10 +172,17 @@ PPSAlignmentWorker::SectorData::SlicePlots::SlicePlots(DQMStore::IBooker& iBooke cfg.binning().slice_y_max_); } +void PPSAlignmentWorker::SectorData::SlicePlots::fill(const double y, const double yDiff, const bool debug) { + h_y->Fill(y); + p_y_diffFN_vs_y->Fill(y, yDiff); + if (debug) + h2_y_diffFN_vs_y->Fill(y, yDiff); +} + void PPSAlignmentWorker::SectorData::init(DQMStore::IBooker& iBooker, const PPSAlignmentConfiguration& cfg, const PPSAlignmentConfiguration::SectorConfig& scfg, - const std::string& folder, + const std::string& rootDir, bool debug) { scfg_ = scfg; @@ -193,29 +199,29 @@ void PPSAlignmentWorker::SectorData::init(DQMStore::IBooker& iBooker, const double y_min = cfg.binning().y_min_, y_max = cfg.binning().y_max_; // hit distributions - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/before selection/" + scfg_.rp_N_.name_); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/before selection/" + scfg_.rp_N_.name_); m_h2_y_vs_x_bef_sel[scfg_.rp_N_.id_] = iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_str, x_max_str, n_bins_y, y_min, y_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/before selection/" + scfg_.rp_F_.name_); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/before selection/" + scfg_.rp_F_.name_); m_h2_y_vs_x_bef_sel[scfg_.rp_F_.id_] = iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_pix, x_max_pix, n_bins_y, y_min, y_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/multiplicity selection/" + scfg_.rp_N_.name_); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/multiplicity selection/" + scfg_.rp_N_.name_); m_h2_y_vs_x_mlt_sel[scfg_.rp_N_.id_] = iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_str, x_max_str, n_bins_y, y_min, y_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/multiplicity selection/" + scfg_.rp_F_.name_); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/multiplicity selection/" + scfg_.rp_F_.name_); m_h2_y_vs_x_mlt_sel[scfg_.rp_F_.id_] = iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_pix, x_max_pix, n_bins_y, y_min, y_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/after selection/" + scfg_.rp_N_.name_); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/after selection/" + scfg_.rp_N_.name_); m_h2_y_vs_x_aft_sel[scfg_.rp_N_.id_] = iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_str, x_max_str, n_bins_y, y_min, y_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/after selection/" + scfg_.rp_F_.name_); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/after selection/" + scfg_.rp_F_.name_); m_h2_y_vs_x_aft_sel[scfg_.rp_F_.id_] = iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_pix, x_max_pix, n_bins_y, y_min, y_max); // cut plots - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/cuts/cut_h"); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/cuts/cut_h"); h_q_cut_h_bef = iBooker.book1DD("h_q_cut_h_bef", ";cq_h", 400, -2., 2.); h_q_cut_h_aft = iBooker.book1DD("h_q_cut_h_aft", ";cq_h", 400, -2., 2.); h2_cut_h_bef = @@ -223,14 +229,14 @@ void PPSAlignmentWorker::SectorData::init(DQMStore::IBooker& iBooker, h2_cut_h_aft = iBooker.book2DD("h2_cut_h_aft", ";x_up;x_dw", n_bins_x, x_min_str, x_max_str, n_bins_x, x_min_pix, x_max_pix); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/cuts/cut_v"); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/cuts/cut_v"); h_q_cut_v_bef = iBooker.book1DD("h_q_cut_v_bef", ";cq_v", 400, -2., 2.); h_q_cut_v_aft = iBooker.book1DD("h_q_cut_v_aft", ";cq_v", 400, -2., 2.); h2_cut_v_bef = iBooker.book2DD("h2_cut_v_bef", ";y_up;y_dw", n_bins_y, y_min, y_max, n_bins_y, y_min, y_max); h2_cut_v_aft = iBooker.book2DD("h2_cut_v_aft", ";y_up;y_dw", n_bins_y, y_min, y_max, n_bins_y, y_min, y_max); // near-far plots - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/near_far"); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/near_far"); auto profilePtr = std::make_unique("", ";x_{N};x_{F} - x_{N}", @@ -239,6 +245,7 @@ void PPSAlignmentWorker::SectorData::init(DQMStore::IBooker& iBooker, cfg.binning().diffFN_x_max_); p_x_diffFN_vs_x_N = iBooker.bookProfile("p_x_diffFN_vs_x_N", profilePtr.get()); + // slice plots for (int i = 0; i < scfg_.rp_N_.x_slice_n_; i++) { const double x_min = scfg_.rp_N_.x_slice_min_ + i * scfg_.rp_N_.x_slice_w_; const double x_max = scfg_.rp_N_.x_slice_min_ + (i + 1) * scfg_.rp_N_.x_slice_w_; @@ -246,7 +253,7 @@ void PPSAlignmentWorker::SectorData::init(DQMStore::IBooker& iBooker, char buf[100]; sprintf(buf, "%.1f-%.1f", x_min, x_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/near_far/x slices, N/" + buf); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/near_far/x slices, N/" + buf); x_slice_plots_N.insert({i, SlicePlots(iBooker, cfg, debug)}); } @@ -257,7 +264,7 @@ void PPSAlignmentWorker::SectorData::init(DQMStore::IBooker& iBooker, char buf[100]; sprintf(buf, "%.1f-%.1f", x_min, x_max); - iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/near_far/x slices, F/" + buf); + iBooker.setCurrentFolder(rootDir + "/" + scfg_.name_ + "/near_far/x slices, F/" + buf); x_slice_plots_F.insert({i, SlicePlots(iBooker, cfg, debug)}); } } @@ -304,16 +311,17 @@ unsigned int PPSAlignmentWorker::SectorData::process(const CTPPSLocalTrackLiteCo // do the selection unsigned int pairsSelected = 0; - for (const auto& trUp : tracksUp) { for (const auto& trDw : tracksDw) { h2_cut_h_bef->Fill(trUp.x(), trDw.x()); h2_cut_v_bef->Fill(trUp.y(), trDw.y()); + // horizontal cut const double cq_h = trDw.x() + scfg_.cut_h_a_ * trUp.x() + scfg_.cut_h_c_; h_q_cut_h_bef->Fill(cq_h); const bool cv_h = (std::fabs(cq_h) < cfg.n_si() * scfg_.cut_h_si_); + // vertical cut const double cq_v = trDw.y() + scfg_.cut_v_a_ * trUp.y() + scfg_.cut_v_c_; h_q_cut_v_bef->Fill(cq_v); const bool cv_v = (std::fabs(cq_v) < cfg.n_si() * scfg_.cut_v_si_); @@ -340,18 +348,12 @@ unsigned int PPSAlignmentWorker::SectorData::process(const CTPPSLocalTrackLiteCo int idx = (trUp.x() - scfg_.rp_N_.x_slice_min_) / scfg_.rp_N_.x_slice_w_; if (idx >= 0 && idx < scfg_.rp_N_.x_slice_n_) { - x_slice_plots_N[idx].h_y->Fill(trUp.y()); - x_slice_plots_N[idx].p_y_diffFN_vs_y->Fill(trUp.y(), trDw.y() - trUp.y()); - if (debug) - x_slice_plots_N[idx].h2_y_diffFN_vs_y->Fill(trUp.y(), trDw.y() - trUp.y()); + x_slice_plots_N[idx].fill(trUp.y(), trDw.y() - trUp.y(), debug); } idx = (trDw.x() - scfg_.rp_F_.x_slice_min_) / scfg_.rp_F_.x_slice_w_; if (idx >= 0 && idx < scfg_.rp_F_.x_slice_n_) { - x_slice_plots_F[idx].h_y->Fill(trDw.y()); - x_slice_plots_F[idx].p_y_diffFN_vs_y->Fill(trDw.y(), trDw.y() - trUp.y()); - if (debug) - x_slice_plots_F[idx].h2_y_diffFN_vs_y->Fill(trDw.y(), trDw.y() - trUp.y()); + x_slice_plots_F[idx].fill(trDw.y(), trDw.y() - trUp.y(), debug); } } } diff --git a/CalibPPS/AlignmentGlobal/src/utils.cc b/CalibPPS/AlignmentGlobal/src/utils.cc new file mode 100644 index 0000000000000..3a7d909e9b0fa --- /dev/null +++ b/CalibPPS/AlignmentGlobal/src/utils.cc @@ -0,0 +1,45 @@ +/**************************************************************************** +* Authors: +* Jan Kašpar (jan.kaspar@gmail.com) +* Mateusz Kocot (mateuszkocot99@gmail.com) +****************************************************************************/ + +#include "CalibPPS/AlignmentGlobal/interface/utils.h" + +#include "TF1.h" + +#include + +// Fits a linear function to a TProfile. +int alig_utils::fitProfile(TProfile* p, + double x_mean, + double x_rms, + unsigned int minBinEntries, + unsigned int minNBinsReasonable, + double& sl, + double& sl_unc) { + unsigned int n_reasonable = 0; + for (int bi = 1; bi <= p->GetNbinsX(); bi++) { + if (p->GetBinEntries(bi) < minBinEntries) { + p->SetBinContent(bi, 0.); + p->SetBinError(bi, 0.); + } else { + n_reasonable++; + } + } + + if (n_reasonable < minNBinsReasonable) + return 1; + + double x_min = x_mean - x_rms, x_max = x_mean + x_rms; + + auto ff_pol1 = std::make_unique("ff_pol1", "[0] + [1]*x"); + + ff_pol1->SetParameter(0., 0.); + p->Fit(ff_pol1.get(), "Q", "", x_min, x_max); + + sl = ff_pol1->GetParameter(1); + sl_unc = ff_pol1->GetParError(1); + + return 0; +} diff --git a/CalibPPS/AlignmentGlobal/test/README.md b/CalibPPS/AlignmentGlobal/test/README.md index 85392e1bc019a..ccb3c7043a9b2 100644 --- a/CalibPPS/AlignmentGlobal/test/README.md +++ b/CalibPPS/AlignmentGlobal/test/README.md @@ -4,12 +4,12 @@ ### Reference dataset - `config_reference_cff.py` - configuration (Event Setup) for the reference dataset - `input_files_reference_cff.py` - file with vstring of ROOT input files for the reference dataset - - `run_distributions_reference_cfg.py` - process configuration for PPSAlignmentWorker. Produces standard ROOT file with reference histograms for x alignment of the test dataset. + - `run_distributions_reference_cfg.py` - process configuration for `PPSAlignmentWorker`. Produces a standard ROOT file with reference histograms for the horizontal alignment. ### Test dataset - `config_cff.py` - configuration (Event Setup) for the test dataset - `input_files_cff.py` - file with vstring of ROOT input files for the test dataset - - `run_distributions_cfg.py` - process configuration for PPSAlignmentWorker. Produces DQMIO ROOT file with histograms for the harvester. - - `run_analysis_manual_cfg.py` - process configuration for PPSAlignmentHarvester. Produces alignment results. + - `run_distributions_cfg.py` - process configuration for `PPSAlignmentWorker`. Produces a DQMIO ROOT file with histograms for the harvester. + - `run_analysis_cfg.py` - process configuration for `PPSAlignmentHarvester`. Runs the horizontal, the horizontal relative and the vertical alignment. Produces a text file with results and two ROOT files - one with DQM plots, and the other one with debug plots. Can be easily configured to produce an SQLite file with the results as well - check out the variables at the top of the file. ## Running instructions ``` diff --git a/CalibPPS/AlignmentGlobal/test/run_analysis_cfg.py b/CalibPPS/AlignmentGlobal/test/run_analysis_cfg.py index fceb4d3fab1c1..456eb11397392 100644 --- a/CalibPPS/AlignmentGlobal/test/run_analysis_cfg.py +++ b/CalibPPS/AlignmentGlobal/test/run_analysis_cfg.py @@ -19,7 +19,7 @@ output_conditions = 'sqlite_file:alignment_results.db' # Database tag. Used only if write_sqlite_results is set to True. -output_db_tag = 'CTPPSRPAlignmentCorrectionsData_test' +output_db_tag = 'CTPPSRPAlignment_real_pcl' ################################### import sys diff --git a/CalibPPS/ESProducers/plugins/BuildFile.xml b/CalibPPS/ESProducers/plugins/BuildFile.xml index d490a35ba805b..2e94eb3ffead4 100644 --- a/CalibPPS/ESProducers/plugins/BuildFile.xml +++ b/CalibPPS/ESProducers/plugins/BuildFile.xml @@ -2,6 +2,7 @@ + diff --git a/CalibPPS/ESProducers/plugins/PPSAlignmentConfigESSource.cc b/CalibPPS/ESProducers/plugins/PPSAlignmentConfigESSource.cc deleted file mode 100644 index 5a23314fe8e8b..0000000000000 --- a/CalibPPS/ESProducers/plugins/PPSAlignmentConfigESSource.cc +++ /dev/null @@ -1,690 +0,0 @@ -/**************************************************************************** - * - * CalibPPS/ESProducers/plugins/PPSAlignmentConfigESSource.cc - * - * Description: Constructs PPSAlignmentConfig instance - * - * Authors: - * - Jan Kašpar - * - Mateusz Kocot - * - ****************************************************************************/ - -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/SourceFactory.h" -#include "FWCore/Framework/interface/ModuleFactory.h" - -#include "FWCore/Framework/interface/ESProducer.h" -#include "FWCore/Framework/interface/ESProducts.h" -#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/ESInputTag.h" - -#include "CondFormats/PPSObjects/interface/PPSAlignmentConfig.h" -#include "CondFormats/DataRecord/interface/PPSAlignmentConfigRcd.h" - -#include -#include -#include -#include -#include - -#include "TF1.h" -#include "TProfile.h" -#include "TFile.h" -#include "TKey.h" -#include "TSystemFile.h" - -//--------------------------------------------------------------------------------------------- - -class PPSAlignmentConfigESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder { -public: - PPSAlignmentConfigESSource(const edm::ParameterSet &iConfig); - - std::unique_ptr produce(const PPSAlignmentConfigRcd &); - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - int fitProfile(TProfile *p, double x_mean, double x_rms, double &sl, double &sl_unc); - TDirectory *findDirectoryWithName(TDirectory *dir, std::string searchName); - std::vector buildVectorFromDirectory(TDirectory *dir, const RPConfig &rpd); - - void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, - const edm::IOVSyncValue &iosv, - edm::ValidityInterval &oValidity) override; - - bool debug; - - std::vector sequence; - std::string resultsDir; - - SectorConfig sectorConfig45, sectorConfig56; - - double x_ali_sh_step; - - double y_mode_sys_unc; - double chiSqThreshold; - double y_mode_unc_max_valid; - double y_mode_max_valid; - - unsigned int maxRPTracksSize; - double n_si; - - std::map> matchingReferencePoints; - std::map matchingShiftRanges; - - std::map alignment_x_meth_o_ranges; - unsigned int fitProfileMinBinEntries; - unsigned int fitProfileMinNReasonable; - unsigned int methOGraphMinN; - double methOUncFitRange; - - std::map alignment_x_relative_ranges; - unsigned int nearFarMinEntries; - - std::map alignment_y_ranges; - unsigned int modeGraphMinN; - unsigned int multSelProjYMinEntries; - - Binning binning; - - std::string label; -}; - -//--------------------------------------------------------------------------------------------- - -PPSAlignmentConfigESSource::PPSAlignmentConfigESSource(const edm::ParameterSet &iConfig) { - label = iConfig.getParameter("label"); - - debug = iConfig.getParameter("debug"); - TFile *debugFile = nullptr; - if (debug) { - debugFile = new TFile(("debug_producer_" + (label.empty() ? "test" : label) + ".root").c_str(), "recreate"); - } - - sequence = iConfig.getParameter>("sequence"); - resultsDir = iConfig.getParameter("results_dir"); - - sectorConfig45.name_ = "sector 45"; - - sectorConfig45.rp_N_.position_ = "N"; - sectorConfig45.rp_F_.position_ = "F"; - - sectorConfig56.name_ = "sector 56"; - - sectorConfig56.rp_N_.position_ = "N"; - sectorConfig56.rp_F_.position_ = "F"; - - for (std::string sectorName : {"sector_45", "sector_56"}) { - const auto &sps = iConfig.getParameter(sectorName); - SectorConfig *sc; - if (sectorName == "sector_45") - sc = §orConfig45; - else - sc = §orConfig56; - - for (std::string rpName : {"rp_N", "rp_F"}) { - const auto &rpps = sps.getParameter(rpName); - RPConfig *rc; - if (rpName == "rp_N") - rc = &sc->rp_N_; - else - rc = &sc->rp_F_; - - rc->name_ = rpps.getParameter("name"); - rc->id_ = rpps.getParameter("id"); - - rc->slope_ = rpps.getParameter("slope"); - rc->sh_x_ = rpps.getParameter("sh_x"); - - rc->x_min_fit_mode_ = rpps.getParameter("x_min_fit_mode"); - rc->x_max_fit_mode_ = rpps.getParameter("x_max_fit_mode"); - rc->y_max_fit_mode_ = rpps.getParameter("y_max_fit_mode"); - rc->y_cen_add_ = rpps.getParameter("y_cen_add"); - rc->y_width_mult_ = rpps.getParameter("y_width_mult"); - - rc->x_slice_min_ = rpps.getParameter("x_slice_min"); - rc->x_slice_w_ = rpps.getParameter("x_slice_w"); - rc->x_slice_n_ = std::ceil((rpps.getParameter("x_slice_max") - rc->x_slice_min_) / rc->x_slice_w_); - } - - sc->slope_ = sps.getParameter("slope"); - - sc->cut_h_apply_ = sps.getParameter("cut_h_apply"); - sc->cut_h_a_ = sps.getParameter("cut_h_a"); - sc->cut_h_c_ = sps.getParameter("cut_h_c"); - sc->cut_h_si_ = sps.getParameter("cut_h_si"); - - sc->cut_v_apply_ = sps.getParameter("cut_v_apply"); - sc->cut_v_a_ = sps.getParameter("cut_v_a"); - sc->cut_v_c_ = sps.getParameter("cut_v_c"); - sc->cut_v_si_ = sps.getParameter("cut_v_si"); - } - - std::map rpTags = {{sectorConfig45.rp_F_.id_, "rp_L_F"}, - {sectorConfig45.rp_N_.id_, "rp_L_N"}, - {sectorConfig56.rp_N_.id_, "rp_R_N"}, - {sectorConfig56.rp_F_.id_, "rp_R_F"}}; - - std::map sectorNames = {{sectorConfig45.rp_F_.id_, sectorConfig45.name_}, - {sectorConfig45.rp_N_.id_, sectorConfig45.name_}, - {sectorConfig56.rp_N_.id_, sectorConfig56.name_}, - {sectorConfig56.rp_F_.id_, sectorConfig56.name_}}; - - std::map rpConfigs = {{sectorConfig45.rp_F_.id_, §orConfig45.rp_F_}, - {sectorConfig45.rp_N_.id_, §orConfig45.rp_N_}, - {sectorConfig56.rp_N_.id_, §orConfig56.rp_N_}, - {sectorConfig56.rp_F_.id_, §orConfig56.rp_F_}}; - - x_ali_sh_step = iConfig.getParameter("x_ali_sh_step"); - - y_mode_sys_unc = iConfig.getParameter("y_mode_sys_unc"); - chiSqThreshold = iConfig.getParameter("chiSqThreshold"); - y_mode_unc_max_valid = iConfig.getParameter("y_mode_unc_max_valid"); - y_mode_max_valid = iConfig.getParameter("y_mode_max_valid"); - - maxRPTracksSize = iConfig.getParameter("max_RP_tracks_size"); - n_si = iConfig.getParameter("n_si"); - - const auto &c_axo = iConfig.getParameter("x_alignment_meth_o"); - for (const auto &p : rpTags) { - const auto &ps = c_axo.getParameter(p.second); - alignment_x_meth_o_ranges[p.first] = {ps.getParameter("x_min"), ps.getParameter("x_max")}; - } - fitProfileMinBinEntries = c_axo.getParameter("fit_profile_min_bin_entries"); - fitProfileMinNReasonable = c_axo.getParameter("fit_profile_min_N_reasonable"); - methOGraphMinN = c_axo.getParameter("meth_o_graph_min_N"); - methOUncFitRange = c_axo.getParameter("meth_o_unc_fit_range"); - - const auto &c_m = iConfig.getParameter("matching"); - const auto &referenceDataset = c_m.getParameter("reference_dataset"); - - // constructing vectors with reference data - if (!referenceDataset.empty()) { - TFile *f_ref = TFile::Open(referenceDataset.c_str()); - if (!f_ref->IsOpen()) { - edm::LogWarning("PPS") << "[ESSource] could not find reference dataset file: " << referenceDataset; - } else { - TDirectory *ad_ref = findDirectoryWithName((TDirectory *)f_ref, sectorConfig45.name_); - if (ad_ref == nullptr) { - edm::LogWarning("PPS") << "[ESSource] could not find reference dataset in " << referenceDataset; - } else { - edm::LogInfo("PPS") << "[ESSource] loading reference dataset from " << ad_ref->GetPath(); - - for (const auto &p : rpTags) { - if (debug) - gDirectory = debugFile->mkdir(rpConfigs[p.first]->name_.c_str())->mkdir("fits_ref"); - - auto *d_ref = (TDirectory *)ad_ref->Get( - (sectorNames[p.first] + "/near_far/x slices, " + rpConfigs[p.first]->position_).c_str()); - if (d_ref == nullptr) { - edm::LogWarning("PPS") << "[ESSource] could not load d_ref"; - } else { - matchingReferencePoints[p.first] = buildVectorFromDirectory(d_ref, *rpConfigs[p.first]); - } - } - } - } - delete f_ref; - } - - for (const auto &p : rpTags) { - const auto &ps = c_m.getParameter(p.second); - matchingShiftRanges[p.first] = {ps.getParameter("sh_min"), ps.getParameter("sh_max")}; - } - - const auto &c_axr = iConfig.getParameter("x_alignment_relative"); - for (const auto &p : rpTags) { - const auto &ps = c_axr.getParameter(p.second); - alignment_x_relative_ranges[p.first] = {ps.getParameter("x_min"), ps.getParameter("x_max")}; - } - nearFarMinEntries = c_axr.getParameter("near_far_min_entries"); - - const auto &c_ay = iConfig.getParameter("y_alignment"); - for (const auto &p : rpTags) { - const auto &ps = c_ay.getParameter(p.second); - alignment_y_ranges[p.first] = {ps.getParameter("x_min"), ps.getParameter("x_max")}; - } - modeGraphMinN = c_ay.getParameter("mode_graph_min_N"); - multSelProjYMinEntries = c_ay.getParameter("mult_sel_proj_y_min_entries"); - - const auto &bps = iConfig.getParameter("binning"); - binning.bin_size_x_ = bps.getParameter("bin_size_x"); - binning.n_bins_x_ = bps.getParameter("n_bins_x"); - binning.pixel_x_offset_ = bps.getParameter("pixel_x_offset"); - binning.n_bins_y_ = bps.getParameter("n_bins_y"); - binning.y_min_ = bps.getParameter("y_min"); - binning.y_max_ = bps.getParameter("y_max"); - - setWhatProduced(this, label); - findingRecord(); - - if (debug) - delete debugFile; -} - -//--------------------------------------------------------------------------------------------- - -std::unique_ptr PPSAlignmentConfigESSource::produce(const PPSAlignmentConfigRcd &) { - auto p = std::make_unique(); - - p->setSequence(sequence); - p->setResultsDir(resultsDir); - - p->setSectorConfig45(sectorConfig45); - p->setSectorConfig56(sectorConfig56); - - p->setX_ali_sh_step(x_ali_sh_step); - - p->setY_mode_sys_unc(y_mode_sys_unc); - p->setChiSqThreshold(chiSqThreshold); - p->setY_mode_unc_max_valid(y_mode_unc_max_valid); - p->setY_mode_max_valid(y_mode_max_valid); - - p->setMaxRPTracksSize(maxRPTracksSize); - p->setN_si(n_si); - - p->setMatchingReferencePoints(matchingReferencePoints); - p->setMatchingShiftRanges(matchingShiftRanges); - - p->setAlignment_x_meth_o_ranges(alignment_x_meth_o_ranges); - p->setFitProfileMinBinEntries(fitProfileMinBinEntries); - p->setFitProfileMinNReasonable(fitProfileMinNReasonable); - p->setMethOGraphMinN(methOGraphMinN); - p->setMethOUncFitRange(methOUncFitRange); - - p->setAlignment_x_relative_ranges(alignment_x_relative_ranges); - p->setNearFarMinEntries(nearFarMinEntries); - - p->setAlignment_y_ranges(alignment_y_ranges); - p->setModeGraphMinN(modeGraphMinN); - p->setMultSelProjYMinEntries(multSelProjYMinEntries); - - p->setBinning(binning); - - edm::LogInfo("PPS") << "\n" - << "[ESSource] " << (label.empty() ? "empty label" : "label = " + label) << ":\n\n" - << (*p); - - return p; -} - -//--------------------------------------------------------------------------------------------- - -// most default values come from 2018 period -void PPSAlignmentConfigESSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - edm::ParameterSetDescription desc; - - desc.add("debug", false); - - desc.add("label", ""); - - desc.add>("sequence", {}); - desc.add("results_dir", "./alignment_results.txt"); - - // sector_45 - { - edm::ParameterSetDescription sector45; - - edm::ParameterSetDescription rp_N; - rp_N.add("name", "L_1_F"); - rp_N.add("id", 3); - - rp_N.add("slope", 0.19); - rp_N.add("sh_x", -3.6); - - rp_N.add("x_min_fit_mode", 2.); - rp_N.add("x_max_fit_mode", 7.0); - rp_N.add("y_max_fit_mode", 7.0); - rp_N.add("y_cen_add", -0.3); - rp_N.add("y_width_mult", 1.1); - - rp_N.add("x_slice_min", 7.); - rp_N.add("x_slice_max", 19.); - rp_N.add("x_slice_w", 0.2); - sector45.add("rp_N", rp_N); - - edm::ParameterSetDescription rp_F; - rp_F.add("name", "L_2_F"); - rp_F.add("id", 23); - - rp_F.add("slope", 0.19); - rp_F.add("sh_x", -42.); - - rp_F.add("x_min_fit_mode", 2.); - rp_F.add("x_max_fit_mode", 7.5); - rp_F.add("y_max_fit_mode", 7.5); - rp_F.add("y_cen_add", -0.3); - rp_F.add("y_width_mult", 1.1); - - rp_F.add("x_slice_min", 46.); - rp_F.add("x_slice_max", 58.); - rp_F.add("x_slice_w", 0.2); - sector45.add("rp_F", rp_F); - - sector45.add("slope", 0.006); - sector45.add("cut_h_apply", true); - sector45.add("cut_h_a", -1.); - sector45.add("cut_h_c", -38.55); - sector45.add("cut_h_si", 0.2); - sector45.add("cut_v_apply", true); - sector45.add("cut_v_a", -1.07); - sector45.add("cut_v_c", 1.63); - sector45.add("cut_v_si", 0.15); - - desc.add("sector_45", sector45); - } - - // sector_56 - { - edm::ParameterSetDescription sector56; - - edm::ParameterSetDescription rp_N; - rp_N.add("name", "R_1_F"); - rp_N.add("id", 103); - - rp_N.add("slope", 0.40); - rp_N.add("sh_x", -2.8); - - rp_N.add("x_min_fit_mode", 2.); - rp_N.add("x_max_fit_mode", 7.4); - rp_N.add("y_max_fit_mode", 7.4); - rp_N.add("y_cen_add", -0.8); - rp_N.add("y_width_mult", 1.0); - - rp_N.add("x_slice_min", 6.); - rp_N.add("x_slice_max", 17.); - rp_N.add("x_slice_w", 0.2); - sector56.add("rp_N", rp_N); - - edm::ParameterSetDescription rp_F; - rp_F.add("name", "R_2_F"); - rp_F.add("id", 123); - - rp_F.add("slope", 0.39); - rp_F.add("sh_x", -41.9); - - rp_F.add("x_min_fit_mode", 2.); - rp_F.add("x_max_fit_mode", 8.0); - rp_F.add("y_max_fit_mode", 8.0); - rp_F.add("y_cen_add", -0.8); - rp_F.add("y_width_mult", 1.0); - - rp_F.add("x_slice_min", 45.); - rp_F.add("x_slice_max", 57.); - rp_F.add("x_slice_w", 0.2); - sector56.add("rp_F", rp_F); - - sector56.add("slope", -0.015); - sector56.add("cut_h_apply", true); - sector56.add("cut_h_a", -1.); - sector56.add("cut_h_c", -39.26); - sector56.add("cut_h_si", 0.2); - sector56.add("cut_v_apply", true); - sector56.add("cut_v_a", -1.07); - sector56.add("cut_v_c", 1.49); - sector56.add("cut_v_si", 0.15); - - desc.add("sector_56", sector56); - } - - desc.add("x_ali_sh_step", 0.01); - - desc.add("y_mode_sys_unc", 0.03); - desc.add("chiSqThreshold", 50.); - desc.add("y_mode_unc_max_valid", 5.); - desc.add("y_mode_max_valid", 20.); - - desc.add("max_RP_tracks_size", 2); - desc.add("n_si", 4.); - - // matching - { - edm::ParameterSetDescription matching; - matching.add("reference_dataset", ""); - - edm::ParameterSetDescription rpLF; - rpLF.add("sh_min", -43.); - rpLF.add("sh_max", -41.); - matching.add("rp_L_F", rpLF); - - edm::ParameterSetDescription rpLN; - rpLN.add("sh_min", -4.2); - rpLN.add("sh_max", -2.4); - matching.add("rp_L_N", rpLN); - - edm::ParameterSetDescription rpRN; - rpRN.add("sh_min", -3.6); - rpRN.add("sh_max", -1.8); - matching.add("rp_R_N", rpRN); - - edm::ParameterSetDescription rpRF; - rpRF.add("sh_min", -43.2); - rpRF.add("sh_max", -41.2); - matching.add("rp_R_F", rpRF); - - desc.add("matching", matching); - } - - // x alignment meth o - { - edm::ParameterSetDescription x_alignment_meth_o; - - edm::ParameterSetDescription rpLF; - rpLF.add("x_min", 47.); - rpLF.add("x_max", 56.5); - x_alignment_meth_o.add("rp_L_F", rpLF); - - edm::ParameterSetDescription rpLN; - rpLN.add("x_min", 9.); - rpLN.add("x_max", 18.5); - x_alignment_meth_o.add("rp_L_N", rpLN); - - edm::ParameterSetDescription rpRN; - rpRN.add("x_min", 7.); - rpRN.add("x_max", 15.); - x_alignment_meth_o.add("rp_R_N", rpRN); - - edm::ParameterSetDescription rpRF; - rpRF.add("x_min", 46.); - rpRF.add("x_max", 54.); - x_alignment_meth_o.add("rp_R_F", rpRF); - - x_alignment_meth_o.add("fit_profile_min_bin_entries", 5); - x_alignment_meth_o.add("fit_profile_min_N_reasonable", 10); - x_alignment_meth_o.add("meth_o_graph_min_N", 5); - x_alignment_meth_o.add("meth_o_unc_fit_range", 0.5); - - desc.add("x_alignment_meth_o", x_alignment_meth_o); - } - - // x alignment relative - { - edm::ParameterSetDescription x_alignment_relative; - - edm::ParameterSetDescription rpLF; - rpLF.add("x_min", 0.); - rpLF.add("x_max", 0.); - x_alignment_relative.add("rp_L_F", rpLF); - - edm::ParameterSetDescription rpLN; - rpLN.add("x_min", 7.5); - rpLN.add("x_max", 12.); - x_alignment_relative.add("rp_L_N", rpLN); - - edm::ParameterSetDescription rpRN; - rpRN.add("x_min", 6.); - rpRN.add("x_max", 10.); - x_alignment_relative.add("rp_R_N", rpRN); - - edm::ParameterSetDescription rpRF; - rpRF.add("x_min", 0.); - rpRF.add("x_max", 0.); - x_alignment_relative.add("rp_R_F", rpRF); - - x_alignment_relative.add("near_far_min_entries", 100); - - desc.add("x_alignment_relative", x_alignment_relative); - } - - // y alignment - { - edm::ParameterSetDescription y_alignment; - - edm::ParameterSetDescription rpLF; - rpLF.add("x_min", 44.5); - rpLF.add("x_max", 49.); - y_alignment.add("rp_L_F", rpLF); - - edm::ParameterSetDescription rpLN; - rpLN.add("x_min", 6.7); - rpLN.add("x_max", 11.); - y_alignment.add("rp_L_N", rpLN); - - edm::ParameterSetDescription rpRN; - rpRN.add("x_min", 5.9); - rpRN.add("x_max", 10.); - y_alignment.add("rp_R_N", rpRN); - - edm::ParameterSetDescription rpRF; - rpRF.add("x_min", 44.5); - rpRF.add("x_max", 49.); - y_alignment.add("rp_R_F", rpRF); - - y_alignment.add("mode_graph_min_N", 5); - y_alignment.add("mult_sel_proj_y_min_entries", 300); - - desc.add("y_alignment", y_alignment); - } - - // binning - { - edm::ParameterSetDescription binning; - - binning.add("bin_size_x", 142.3314E-3); - binning.add("n_bins_x", 210); - binning.add("pixel_x_offset", 40.); - binning.add("n_bins_y", 400); - binning.add("y_min", -20.); - binning.add("y_max", 20.); - - desc.add("binning", binning); - } - - descriptions.add("ppsAlignmentConfigESSource", desc); -} - -//--------------------------------------------------------------------------------------------- - -// Fits a linear function to a TProfile (similar method in PPSAlignmentHarvester). -int PPSAlignmentConfigESSource::fitProfile(TProfile *p, double x_mean, double x_rms, double &sl, double &sl_unc) { - unsigned int n_reasonable = 0; - for (int bi = 1; bi <= p->GetNbinsX(); bi++) { - if (p->GetBinEntries(bi) < fitProfileMinBinEntries) { - p->SetBinContent(bi, 0.); - p->SetBinError(bi, 0.); - } else { - n_reasonable++; - } - } - - if (n_reasonable < fitProfileMinNReasonable) - return 1; - - double xMin = x_mean - x_rms, xMax = x_mean + x_rms; - - TF1 *ff_pol1 = new TF1("ff_pol1", "[0] + [1]*x"); - - ff_pol1->SetParameter(0., 0.); - p->Fit(ff_pol1, "Q", "", xMin, xMax); - - sl = ff_pol1->GetParameter(1); - sl_unc = ff_pol1->GetParError(1); - - return 0; -} - -//--------------------------------------------------------------------------------------------- - -// Performs a breadth first search on dir. If found, returns the directory with object -// named searchName inside. Otherwise, returns nullptr. -TDirectory *PPSAlignmentConfigESSource::findDirectoryWithName(TDirectory *dir, std::string searchName) { - TIter next(dir->GetListOfKeys()); - std::queue dirQueue; - TObject *o; - while ((o = next())) { - TKey *k = (TKey *)o; - - std::string name = k->GetName(); - if (name == searchName) - return dir; - - if (((TSystemFile *)k)->IsDirectory()) - dirQueue.push((TDirectory *)k->ReadObj()); - } - - while (!dirQueue.empty()) { - TDirectory *resultDir = findDirectoryWithName(dirQueue.front(), searchName); - dirQueue.pop(); - if (resultDir != nullptr) - return resultDir; - } - - return nullptr; -} - -//--------------------------------------------------------------------------------------------- - -// Builds vector of PointErrors instances from slice plots in dir. -std::vector PPSAlignmentConfigESSource::buildVectorFromDirectory(TDirectory *dir, const RPConfig &rpd) { - std::vector pv; - - TIter next(dir->GetListOfKeys()); - TObject *o; - while ((o = next())) { - TKey *k = (TKey *)o; - - std::string name = k->GetName(); - size_t d = name.find('-'); - const double x_min = std::stod(name.substr(0, d)); - const double x_max = std::stod(name.substr(d + 1)); - - TDirectory *d_slice = (TDirectory *)k->ReadObj(); - - TH1D *h_y = (TH1D *)d_slice->Get("h_y"); - TProfile *p_y_diffFN_vs_y = (TProfile *)d_slice->Get("p_y_diffFN_vs_y"); - - double y_cen = h_y->GetMean(); - double y_width = h_y->GetRMS(); - - y_cen += rpd.y_cen_add_; - y_width *= rpd.y_width_mult_; - - double sl = 0., sl_unc = 0.; - int fr = fitProfile(p_y_diffFN_vs_y, y_cen, y_width, sl, sl_unc); - if (fr != 0) - continue; - - if (debug) - p_y_diffFN_vs_y->Write(name.c_str()); - - pv.push_back({(x_max + x_min) / 2., sl, (x_max - x_min) / 2., sl_unc}); - } - - return pv; -} - -//--------------------------------------------------------------------------------------------- - -void PPSAlignmentConfigESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, - const edm::IOVSyncValue &iosv, - edm::ValidityInterval &oValidity) { - edm::LogInfo("PPS") << ">> PPSAlignmentConfigESSource::setIntervalFor(" << key.name() << ")\n" - << " run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event(); - - edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime()); - oValidity = infinity; -} - -DEFINE_FWK_EVENTSETUP_SOURCE(PPSAlignmentConfigESSource); \ No newline at end of file diff --git a/CalibPPS/ESProducers/plugins/PPSAlignmentConfigurationESSource.cc b/CalibPPS/ESProducers/plugins/PPSAlignmentConfigurationESSource.cc index 19c5157ad80e3..dc83047627e28 100644 --- a/CalibPPS/ESProducers/plugins/PPSAlignmentConfigurationESSource.cc +++ b/CalibPPS/ESProducers/plugins/PPSAlignmentConfigurationESSource.cc @@ -18,6 +18,8 @@ #include "CondFormats/PPSObjects/interface/PPSAlignmentConfiguration.h" #include "CondFormats/DataRecord/interface/PPSAlignmentConfigurationRcd.h" +#include "CalibPPS/AlignmentGlobal/interface/utils.h" + #include #include #include @@ -40,7 +42,6 @@ class PPSAlignmentConfigurationESSource : public edm::ESProducer, public edm::Ev static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - int fitProfile(TProfile* p, double x_mean, double x_rms, double& sl, double& sl_unc); TDirectory* findDirectoryWithName(TDirectory* dir, std::string searchName); std::vector buildVectorFromDirectory( TDirectory* dir, const PPSAlignmentConfiguration::RPConfig& rpd); @@ -93,9 +94,10 @@ PPSAlignmentConfigurationESSource::PPSAlignmentConfigurationESSource(const edm:: label = iConfig.getParameter("label"); debug = iConfig.getParameter("debug"); - TFile* debugFile = nullptr; + std::unique_ptr debugFile; if (debug) { - debugFile = new TFile(("debug_producer_" + (label.empty() ? "test" : label) + ".root").c_str(), "recreate"); + debugFile = + std::make_unique(("debug_producer_" + (label.empty() ? "test" : label) + ".root").c_str(), "recreate"); } sectorConfig45.name_ = "sector 45"; @@ -196,11 +198,11 @@ PPSAlignmentConfigurationESSource::PPSAlignmentConfigurationESSource(const edm:: // constructing vectors with reference data if (!referenceDataset.empty()) { - TFile* f_ref = TFile::Open(referenceDataset.c_str()); + auto f_ref = std::make_unique(referenceDataset.c_str(), "READ"); if (!f_ref->IsOpen()) { edm::LogWarning("PPS") << "[ESSource] could not find reference dataset file: " << referenceDataset; } else { - TDirectory* ad_ref = findDirectoryWithName((TDirectory*)f_ref, sectorConfig45.name_); + TDirectory* ad_ref = findDirectoryWithName((TDirectory*)f_ref.get(), sectorConfig45.name_); if (ad_ref == nullptr) { edm::LogWarning("PPS") << "[ESSource] could not find reference dataset in " << referenceDataset; } else { @@ -220,7 +222,6 @@ PPSAlignmentConfigurationESSource::PPSAlignmentConfigurationESSource(const edm:: } } } - delete f_ref; } for (const auto& p : rpTags) { @@ -268,9 +269,6 @@ PPSAlignmentConfigurationESSource::PPSAlignmentConfigurationESSource(const edm:: setWhatProduced(this, label); findingRecord(); - - if (debug) - delete debugFile; } //--------------------------------------------------------------------------------------------- @@ -588,36 +586,6 @@ void PPSAlignmentConfigurationESSource::fillDescriptions(edm::ConfigurationDescr //--------------------------------------------------------------------------------------------- -// Fits a linear function to a TProfile (similar method in PPSAlignmentHarvester). -int PPSAlignmentConfigurationESSource::fitProfile(TProfile* p, double x_mean, double x_rms, double& sl, double& sl_unc) { - unsigned int n_reasonable = 0; - for (int bi = 1; bi <= p->GetNbinsX(); bi++) { - if (p->GetBinEntries(bi) < fitProfileMinBinEntries) { - p->SetBinContent(bi, 0.); - p->SetBinError(bi, 0.); - } else { - n_reasonable++; - } - } - - if (n_reasonable < fitProfileMinNReasonable) - return 1; - - double x_min = x_mean - x_rms, x_max = x_mean + x_rms; - - TF1* ff_pol1 = new TF1("ff_pol1", "[0] + [1]*x"); - - ff_pol1->SetParameter(0., 0.); - p->Fit(ff_pol1, "Q", "", x_min, x_max); - - sl = ff_pol1->GetParameter(1); - sl_unc = ff_pol1->GetParError(1); - - return 0; -} - -//--------------------------------------------------------------------------------------------- - // Performs a breadth first search on dir. If found, returns the directory with object // named searchName inside. Otherwise, returns nullptr. TDirectory* PPSAlignmentConfigurationESSource::findDirectoryWithName(TDirectory* dir, std::string searchName) { @@ -674,7 +642,8 @@ std::vector PPSAlignmentConfigurationESS y_width *= rpd.y_width_mult_; double sl = 0., sl_unc = 0.; - int fr = fitProfile(p_y_diffFN_vs_y, y_cen, y_width, sl, sl_unc); + int fr = alig_utils::fitProfile( + p_y_diffFN_vs_y, y_cen, y_width, fitProfileMinBinEntries, fitProfileMinNReasonable, sl, sl_unc); if (fr != 0) continue; diff --git a/CondCore/Utilities/src/CondDBFetch.cc b/CondCore/Utilities/src/CondDBFetch.cc index 7043331b0a519..b7f2885ed9b2f 100644 --- a/CondCore/Utilities/src/CondDBFetch.cc +++ b/CondCore/Utilities/src/CondDBFetch.cc @@ -56,7 +56,6 @@ namespace cond { FETCH_PAYLOAD_CASE(CTPPSPixelAnalysisMask) FETCH_PAYLOAD_CASE(CTPPSPixelGainCalibrations) FETCH_PAYLOAD_CASE(CTPPSRPAlignmentCorrectionsData) - FETCH_PAYLOAD_CASE(PPSAlignmentConfig) FETCH_PAYLOAD_CASE(PPSAlignmentConfiguration) FETCH_PAYLOAD_CASE(PPSAssociationCuts) FETCH_PAYLOAD_CASE(LHCOpticalFunctionsSetCollection) diff --git a/CondCore/Utilities/src/CondDBImport.cc b/CondCore/Utilities/src/CondDBImport.cc index 2f28abd8b2728..6f2e371abce4e 100644 --- a/CondCore/Utilities/src/CondDBImport.cc +++ b/CondCore/Utilities/src/CondDBImport.cc @@ -76,7 +76,6 @@ namespace cond { IMPORT_PAYLOAD_CASE(CTPPSPixelAnalysisMask) IMPORT_PAYLOAD_CASE(CTPPSPixelGainCalibrations) IMPORT_PAYLOAD_CASE(CTPPSRPAlignmentCorrectionsData) - IMPORT_PAYLOAD_CASE(PPSAlignmentConfig) IMPORT_PAYLOAD_CASE(PPSAlignmentConfiguration) IMPORT_PAYLOAD_CASE(PPSAssociationCuts) IMPORT_PAYLOAD_CASE(LHCOpticalFunctionsSetCollection) diff --git a/CondFormats/PPSObjects/interface/PPSAlignmentConfig.h b/CondFormats/PPSObjects/interface/PPSAlignmentConfig.h index c75bedf888c7e..009dbe75d26ef 100644 --- a/CondFormats/PPSObjects/interface/PPSAlignmentConfig.h +++ b/CondFormats/PPSObjects/interface/PPSAlignmentConfig.h @@ -1,8 +1,6 @@ /**************************************************************************** * - * CondFormats/PPSObjects/interface/PPSAlignmentConfig.h - * - * Description : Class with alignment parameters + * This class is obsolete! Use PPSAlignmentConfiguration instead. * * Authors: * - Jan Kašpar diff --git a/CondFormats/PPSObjects/src/PPSAlignmentConfig.cc b/CondFormats/PPSObjects/src/PPSAlignmentConfig.cc index 427269cbdd42c..0a4cff6a7fdfc 100644 --- a/CondFormats/PPSObjects/src/PPSAlignmentConfig.cc +++ b/CondFormats/PPSObjects/src/PPSAlignmentConfig.cc @@ -1,8 +1,6 @@ /**************************************************************************** * - * CondFormats/PPSObjects/interface/PPSAlignmentConfig.cc - * - * Description : Class with alignment parameters + * This class is obsolete! Use PPSAlignmentConfiguration instead. * * Authors: * - Jan Kašpar diff --git a/CondTools/CTPPS/plugins/RetrievePPSAlignmentConfig.cc b/CondTools/CTPPS/plugins/RetrievePPSAlignmentConfig.cc deleted file mode 100644 index b780cf149ce30..0000000000000 --- a/CondTools/CTPPS/plugins/RetrievePPSAlignmentConfig.cc +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -* Author: -* Mateusz Kocot (mateuszkocot99@gmail.com) -****************************************************************************/ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ServiceRegistry/interface/Service.h" - -#include "CondFormats/PPSObjects/interface/PPSAlignmentConfig.h" -#include "CondFormats/DataRecord/interface/PPSAlignmentConfigRcd.h" - -#include - -class RetrievePPSAlignmentConfig : public edm::one::EDAnalyzer<> { -public: - explicit RetrievePPSAlignmentConfig(const edm::ParameterSet &); - -private: - void analyze(const edm::Event &, const edm::EventSetup &) override; - - edm::ESGetToken esToken_; -}; - -RetrievePPSAlignmentConfig::RetrievePPSAlignmentConfig(const edm::ParameterSet &iConfig) : esToken_(esConsumes()) {} - -void RetrievePPSAlignmentConfig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { - // get the data - const auto &ppsAlignmentConfig = iSetup.getData(esToken_); - - edm::LogInfo("PPS") << ppsAlignmentConfig; -} - -//define this as a plug-in -DEFINE_FWK_MODULE(RetrievePPSAlignmentConfig); diff --git a/CondTools/CTPPS/plugins/WritePPSAlignmentConfig.cc b/CondTools/CTPPS/plugins/WritePPSAlignmentConfig.cc deleted file mode 100644 index 9ac076de64a31..0000000000000 --- a/CondTools/CTPPS/plugins/WritePPSAlignmentConfig.cc +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -* Author: -* Mateusz Kocot (mateuszkocot99@gmail.com) -****************************************************************************/ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ServiceRegistry/interface/Service.h" - -#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" - -#include "CondFormats/PPSObjects/interface/PPSAlignmentConfig.h" -#include "CondFormats/DataRecord/interface/PPSAlignmentConfigRcd.h" - -#include - -class WritePPSAlignmentConfig : public edm::one::EDAnalyzer<> { -public: - explicit WritePPSAlignmentConfig(const edm::ParameterSet &); - -private: - void analyze(const edm::Event &, const edm::EventSetup &) override; - - edm::ESGetToken esToken_; -}; - -WritePPSAlignmentConfig::WritePPSAlignmentConfig(const edm::ParameterSet &iConfig) - : esToken_(esConsumes( - edm::ESInputTag("", iConfig.getParameter("label")))) {} - -void WritePPSAlignmentConfig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { - // get the data - const auto &ppsAlignmentConfig = iSetup.getData(esToken_); - - // store the data in a DB object - edm::Service poolDbService; - if (poolDbService.isAvailable()) { - poolDbService->writeOneIOV(ppsAlignmentConfig, poolDbService->currentTime(), "PPSAlignmentConfigRcd"); - } else { - throw cms::Exception("WritePPSAlignmentConfig") << "PoolDBService required."; - } -} - -//define this as a plug-in -DEFINE_FWK_MODULE(WritePPSAlignmentConfig); diff --git a/CondTools/CTPPS/test/retrieve_PPSAlignmentConfig_cfg.py b/CondTools/CTPPS/test/retrieve_PPSAlignmentConfig_cfg.py deleted file mode 100644 index 5614bfe76bc4f..0000000000000 --- a/CondTools/CTPPS/test/retrieve_PPSAlignmentConfig_cfg.py +++ /dev/null @@ -1,52 +0,0 @@ -##### configuration ##### -input_conditions = 'sqlite_file:alignment_config.db' # input database -run_number = 1 # used to select the IOV -db_tag = 'PPSAlignmentConfig_test_v1_prompt' # database tag -######################### - -import FWCore.ParameterSet.Config as cms - -process = cms.Process("retrievePPSAlignmentConfig") - -# Message Logger -process.MessageLogger = cms.Service("MessageLogger", - destinations = cms.untracked.vstring('retrieve_PPSAlignmentConfig'), - retrieve_PPSAlignmentConfig = cms.untracked.PSet( - threshold = cms.untracked.string('INFO') - ) -) - -# Load CondDB service -process.load("CondCore.CondDB.CondDB_cfi") - -# input database (in this case the local sqlite file) -process.CondDB.connect = input_conditions - -# A data source must always be defined. We don't need it, so here's a dummy one. -process.source = cms.Source("EmptyIOVSource", - timetype = cms.string('runnumber'), - firstValue = cms.uint64(run_number), - lastValue = cms.uint64(run_number), - interval = cms.uint64(1) -) - -# input service -process.PoolDBESSource = cms.ESSource("PoolDBESSource", - process.CondDB, - DumbStat = cms.untracked.bool(True), - toGet = cms.VPSet(cms.PSet( - record = cms.string('PPSAlignmentConfigRcd'), - tag = cms.string(db_tag) - )) -) - -# DB object retrieve module -process.retrieve_config = cms.EDAnalyzer("RetrievePPSAlignmentConfig", - toGet = cms.VPSet(cms.PSet( - record = cms.string('PPSAlignmentConfigRcd'), - data = cms.vstring('PPSAlignmentConfig') - )), - verbose = cms.untracked.bool(True) -) - -process.path = cms.Path(process.retrieve_config) diff --git a/CondTools/CTPPS/test/write_PPSAlignmentConfig_cfg.py b/CondTools/CTPPS/test/write_PPSAlignmentConfig_cfg.py deleted file mode 100644 index 0a1fe540a76be..0000000000000 --- a/CondTools/CTPPS/test/write_PPSAlignmentConfig_cfg.py +++ /dev/null @@ -1,88 +0,0 @@ -##### configuration ##### -output_conditions = 'sqlite_file:alignment_config.db' # output database -run_number = 1 # beginning of the IOV -db_tag = 'PPSAlignmentConfig_test_v1_prompt' # database tag -produce_logs = True # if set to True, a file with logs will be produced. -product_instance_label = 'db_test' # ES product label -######################### - -import FWCore.ParameterSet.Config as cms - -process = cms.Process("writePPSAlignmentConfig") - -# Message Logger -if produce_logs: - process.MessageLogger = cms.Service("MessageLogger", - destinations = cms.untracked.vstring('write_PPSAlignmentConfig', - 'cout' - ), - write_PPSAlignmentConfig = cms.untracked.PSet( - threshold = cms.untracked.string('INFO') - ), - cout = cms.untracked.PSet( - threshold = cms.untracked.string('WARNING') - ) - ) -else: - process.MessageLogger = cms.Service("MessageLogger", - destinations = cms.untracked.vstring('cout'), - cout = cms.untracked.PSet( - threshold = cms.untracked.string('WARNING') - ) - ) - -# Load CondDB service -process.load("CondCore.CondDB.CondDB_cfi") - -# output database -process.CondDB.connect = output_conditions - -# A data source must always be defined. We don't need it, so here's a dummy one. -process.source = cms.Source("EmptyIOVSource", - timetype = cms.string('runnumber'), - firstValue = cms.uint64(run_number), - lastValue = cms.uint64(run_number), - interval = cms.uint64(1) -) - -# output service -process.PoolDBOutputService = cms.Service("PoolDBOutputService", - process.CondDB, - timetype = cms.untracked.string('runnumber'), - toPut = cms.VPSet(cms.PSet( - record = cms.string('PPSAlignmentConfigRcd'), - tag = cms.string(db_tag) - )) -) - -# ESSource -process.ppsAlignmentConfigESSource = cms.ESSource("PPSAlignmentConfigESSource", - # PPSAlignmentConfigESSource parameters, defaults will be taken from fillDescriptions - label = cms.string(product_instance_label), - sector_45 = cms.PSet( - rp_N = cms.PSet( - name = cms.string('db_test_RP'), - id = cms.int32(44), - y_max_fit_mode = cms.double(66.6) - ) - ), - y_alignment = cms.PSet( - rp_L_F = cms.PSet( - x_min = cms.double(102), - x_max = cms.double(210.0) - ) - ) -) - -# DB object maker -process.config_writer = cms.EDAnalyzer("WritePPSAlignmentConfig", - record = cms.string('PPSAlignmentConfigRcd'), - loggingOn = cms.untracked.bool(True), - SinceAppendMode = cms.bool(True), - Source = cms.PSet( - IOVRun = cms.untracked.uint32(1) - ), - label = cms.string(product_instance_label) -) - -process.path = cms.Path(process.config_writer) \ No newline at end of file