CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PPSAlignmentHarvester.cc
Go to the documentation of this file.
1 /****************************************************************************
2 * Authors:
3 * Jan Kašpar (jan.kaspar@gmail.com)
4 * Mateusz Kocot (mateuszkocot99@gmail.com)
5 ****************************************************************************/
6 
10 
16 
18 
22 
25 
26 #include <memory>
27 #include <map>
28 #include <vector>
29 #include <string>
30 #include <iostream>
31 #include <fstream>
32 #include <iomanip>
33 #include <cmath>
34 
35 #include "TH1D.h"
36 #include "TH2D.h"
37 #include "TGraph.h"
38 #include "TGraphErrors.h"
39 #include "TF1.h"
40 #include "TProfile.h"
41 #include "TFile.h"
42 #include "TKey.h"
43 #include "TSystemFile.h"
44 #include "TSpline.h"
45 #include "TCanvas.h"
46 
47 //----------------------------------------------------------------------------------------------------
48 
50 public:
52  ~PPSAlignmentHarvester() override;
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void dqmEndJob(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter) override;
58  void dqmEndRun(DQMStore::IBooker& iBooker,
59  DQMStore::IGetter& iGetter,
60  edm::Run const& iRun,
61  edm::EventSetup const& iSetup) override;
62 
63  // ------------ x alignment ------------
64  static int fitProfile(TProfile* p,
65  double x_mean,
66  double x_rms,
67  unsigned int fitProfileMinBinEntries,
68  unsigned int fitProfileMinNReasonable,
69  double& sl,
70  double& sl_unc);
71  std::unique_ptr<TGraphErrors> buildGraphFromVector(const std::vector<PPSAlignmentConfiguration::PointErrors>& pv);
72  std::unique_ptr<TGraphErrors> buildGraphFromMonitorElements(DQMStore::IGetter& iGetter,
74  const std::vector<MonitorElement*>& mes,
75  unsigned int fitProfileMinBinEntries,
76  unsigned int fitProfileMinNReasonable);
77  void doMatch(DQMStore::IBooker& iBooker,
80  TGraphErrors* g_ref,
81  TGraphErrors* g_test,
83  double sh_min,
84  double sh_max,
85  double& sh_best,
86  double& sh_best_unc);
87 
88  void xAlignment(DQMStore::IBooker& iBooker,
89  DQMStore::IGetter& iGetter,
90  const PPSAlignmentConfiguration& cfg,
91  const PPSAlignmentConfiguration& cfg_ref,
92  int seqPos);
93 
94  std::map<unsigned int, double> sh_x_map_;
95 
96  // ------------ x alignment relative ------------
98  DQMStore::IGetter& iGetter,
99  const PPSAlignmentConfiguration& cfg,
100  int seqPos);
101 
102  // ------------ y alignment ------------
103  static double findMax(TF1* ff_fit);
104  TH1D* buildModeGraph(DQMStore::IBooker& iBooker,
105  MonitorElement* h2_y_vs_x,
106  const PPSAlignmentConfiguration& cfg,
108 
109  void yAlignment(DQMStore::IBooker& iBooker,
110  DQMStore::IGetter& iGetter,
111  const PPSAlignmentConfiguration& cfg,
112  int seqPos);
113 
114  // ------------ other member data and methods ------------
115  static void writeCutPlot(TH2D* h, double a, double c, double si, double n_si, const std::string& label);
116  static std::unique_ptr<TH1D> getTH1DFromTGraphErrors(TGraphErrors* graph,
117  std::string title = "",
118  std::string labels = "",
119  int n = -1,
120  double binWidth = -1.,
121  double min = -1.);
122 
125 
126  // variables from parameters
128  const std::vector<std::string> sequence_;
133  const bool debug_;
134 
135  // other class variables
136  std::unique_ptr<TFile> debugFile_;
137  std::ofstream textResultsFile_;
138 
140 
143 
146 };
147 
148 // -------------------------------- DQMEDHarvester methods --------------------------------
149 
152  edm::ESInputTag("", ""))),
154  edm::ESInputTag("", "reference"))),
155  folder_(iConfig.getParameter<std::string>("folder")),
156  sequence_(iConfig.getParameter<std::vector<std::string>>("sequence")),
157  overwriteShX_(iConfig.getParameter<bool>("overwrite_sh_x")),
158  writeSQLiteResults_(iConfig.getParameter<bool>("write_sqlite_results")),
159  xAliRelFinalSlopeFixed_(iConfig.getParameter<bool>("x_ali_rel_final_slope_fixed")),
160  yAliFinalSlopeFixed_(iConfig.getParameter<bool>("y_ali_final_slope_fixed")),
161  debug_(iConfig.getParameter<bool>("debug")) {
162  auto textResultsPath = iConfig.getParameter<std::string>("text_results_path");
163  if (!textResultsPath.empty()) {
164  textResultsFile_.open(textResultsPath, std::ios::out | std::ios::trunc);
165  }
166  if (debug_) {
167  debugFile_ = std::make_unique<TFile>("debug_harvester.root", "recreate");
168  }
169 
170  edm::LogInfo("PPS").log([&](auto& li) {
171  li << "[harvester] parameters:\n";
172  li << "* folder: " << folder_ << "\n";
173  li << "* sequence:\n";
174  for (unsigned int i = 0; i < sequence_.size(); i++) {
175  li << " " << i + 1 << ": " << sequence_[i] << "\n";
176  }
177  li << "* overwrite_sh_x: " << std::boolalpha << overwriteShX_ << "\n";
178  li << "* text_results_path: " << textResultsPath << "\n";
179  li << "* write_sqlite_results: " << std::boolalpha << writeSQLiteResults_ << "\n";
180  li << "* x_ali_rel_final_slope_fixed: " << std::boolalpha << xAliRelFinalSlopeFixed_ << "\n";
181  li << "* y_ali_final_slope_fixed: " << std::boolalpha << yAliFinalSlopeFixed_ << "\n";
182  li << "* debug: " << std::boolalpha << debug_;
183  });
184 }
185 
187  if (textResultsFile_.is_open()) {
188  textResultsFile_.close();
189  }
190 }
191 
194 
195  desc.add<std::string>("folder", "AlCaReco/PPSAlignment");
196  desc.add<std::vector<std::string>>("sequence", {"x_alignment", "x_alignment_relative", "y_alignment"});
197  desc.add<bool>("overwrite_sh_x", true);
198  desc.add<std::string>("text_results_path", "./alignment_results.txt");
199  desc.add<bool>("write_sqlite_results", false);
200  desc.add<bool>("x_ali_rel_final_slope_fixed", true);
201  desc.add<bool>("y_ali_final_slope_fixed", true);
202  desc.add<bool>("debug", false);
203 
204  descriptions.addWithDefaultLabel(desc);
205 }
206 
208 
210  DQMStore::IGetter& iGetter,
211  edm::Run const& iRun,
212  edm::EventSetup const& iSetup) {
213  const auto& cfg = iSetup.getData(esTokenTest_);
214 
215  const auto& cfg_ref = iSetup.getData(esTokenReference_);
216 
217  // setting default sh_x values from config
218  for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) {
219  for (const auto& rpc : {sc.rp_N_, sc.rp_F_}) {
220  sh_x_map_[rpc.id_] = rpc.sh_x_;
221  }
222  }
223  edm::LogInfo("PPS").log([&](auto& li) {
224  li << "[harvester] Setting sh_x from config of:\n";
225  for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) {
226  for (const auto& rpc : {sc.rp_N_, sc.rp_F_}) {
227  li << " " << rpc.name_ << " to " << std::fixed << std::setprecision(3) << rpc.sh_x_;
228  if (rpc.name_ != "R_2_F")
229  li << "\n";
230  }
231  }
232  });
233 
234  bool doXAli = false, doXAliRel = false, doYAli = false;
235  for (unsigned int i = 0; i < sequence_.size(); i++) {
236  if (sequence_[i] == "x_alignment") {
237  xAlignment(iBooker, iGetter, cfg, cfg_ref, i);
238  doXAli = true;
239  } else if (sequence_[i] == "x_alignment_relative") {
240  xAlignmentRelative(iBooker, iGetter, cfg, i);
241  doXAliRel = true;
242  } else if (sequence_[i] == "y_alignment") {
243  yAlignment(iBooker, iGetter, cfg, i);
244  doYAli = true;
245  } else
246  edm::LogError("PPS") << "[harvester] " << sequence_[i] << " is a wrong method name.";
247  }
248 
249  // merge results from all the specified methods
250  CTPPSRPAlignmentCorrectionsData finalResults;
251  if (doXAli) { // x alignment
252  finalResults.addCorrections(xAliResults_);
253  if (doXAliRel) { // merge with x alignment relative
254  for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) {
255  // extract shifts
256  double d_x_N = xAliResults_.getRPCorrection(sc.rp_N_.id_).getShX();
257  double d_x_F = xAliResults_.getRPCorrection(sc.rp_F_.id_).getShX();
258 
259  double d_x_rel_N, d_x_rel_F;
261  d_x_rel_N = xAliRelResultsSlopeFixed_.getRPCorrection(sc.rp_N_.id_).getShX();
262  d_x_rel_F = xAliRelResultsSlopeFixed_.getRPCorrection(sc.rp_F_.id_).getShX();
263  } else {
264  d_x_rel_N = xAliRelResults_.getRPCorrection(sc.rp_N_.id_).getShX();
265  d_x_rel_F = xAliRelResults_.getRPCorrection(sc.rp_F_.id_).getShX();
266  }
267 
268  // merge the results
269  double b = d_x_rel_N - d_x_rel_F;
270  double xCorrRel = b + d_x_F - d_x_N;
271 
272  CTPPSRPAlignmentCorrectionData corrRelN(xCorrRel / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
273  finalResults.addRPCorrection(sc.rp_N_.id_, corrRelN);
274  CTPPSRPAlignmentCorrectionData corrRelF(-xCorrRel / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
275  finalResults.addRPCorrection(sc.rp_F_.id_, corrRelF);
276  }
277  }
278  }
279  if (doYAli) { // y alignment
280  if (yAliFinalSlopeFixed_) {
282  } else {
283  finalResults.addCorrections(yAliResults_);
284  }
285  }
286 
287  // print the text results
288  edm::LogInfo("PPS") << "final merged results:\n" << finalResults;
289 
290  if (textResultsFile_.is_open()) {
291  textResultsFile_ << "final merged results:\n" << finalResults;
292  }
293 
294  // if requested, store the results in a DB object
295  if (writeSQLiteResults_) {
297  if (poolDbService.isAvailable()) {
298  poolDbService->writeOneIOV(finalResults, poolDbService->currentTime(), "CTPPSRPAlignmentCorrectionsDataRcd");
299  } else {
300  edm::LogWarning("PPS") << "Could not store the results in a DB object. PoolDBService not available.";
301  }
302  }
303 
304  // if debug_, save nice-looking cut plots with the worker data in the debug ROOT file
305  if (debug_) {
306  TDirectory* cutsDir = debugFile_->mkdir("cuts");
307  for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) {
308  TDirectory* sectorDir = cutsDir->mkdir(sc.name_.c_str());
309 
310  gDirectory = sectorDir->mkdir("cut_h");
311  auto* h2_cut_h_bef_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_h/h2_cut_h_bef");
312  auto* h2_cut_h_aft_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_h/h2_cut_h_aft");
313  writeCutPlot(
314  h2_cut_h_bef_monitor->getTH2D(), sc.cut_h_a_, sc.cut_h_c_, cfg.n_si(), sc.cut_h_si_, "canvas_before");
315  writeCutPlot(h2_cut_h_aft_monitor->getTH2D(), sc.cut_h_a_, sc.cut_h_c_, cfg.n_si(), sc.cut_h_si_, "canvas_after");
316 
317  gDirectory = sectorDir->mkdir("cut_v");
318  auto* h2_cut_v_bef_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_v/h2_cut_v_bef");
319  auto* h2_cut_v_aft_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/cuts/cut_v/h2_cut_v_aft");
320  writeCutPlot(
321  h2_cut_v_bef_monitor->getTH2D(), sc.cut_v_a_, sc.cut_v_c_, cfg.n_si(), sc.cut_v_si_, "canvas_before");
322  writeCutPlot(h2_cut_v_aft_monitor->getTH2D(), sc.cut_v_a_, sc.cut_v_c_, cfg.n_si(), sc.cut_v_si_, "canvas_after");
323  }
324  }
325 }
326 
327 // -------------------------------- x alignment methods --------------------------------
328 
329 // Fits a linear function to a TProfile (similar method in PPSAlignmentConfigurationESSource).
331  double x_mean,
332  double x_rms,
333  unsigned int fitProfileMinBinEntries,
334  unsigned int fitProfileMinNReasonable,
335  double& sl,
336  double& sl_unc) {
337  unsigned int n_reasonable = 0;
338  for (int bi = 1; bi <= p->GetNbinsX(); bi++) {
339  if (p->GetBinEntries(bi) < fitProfileMinBinEntries) {
340  p->SetBinContent(bi, 0.);
341  p->SetBinError(bi, 0.);
342  } else {
343  n_reasonable++;
344  }
345  }
346 
347  if (n_reasonable < fitProfileMinNReasonable)
348  return 1;
349 
350  double x_min = x_mean - x_rms, x_max = x_mean + x_rms;
351 
352  auto ff_pol1 = std::make_unique<TF1>("ff_pol1", "[0] + [1]*x");
353 
354  ff_pol1->SetParameter(0., 0.);
355  p->Fit(ff_pol1.get(), "Q", "", x_min, x_max);
356 
357  sl = ff_pol1->GetParameter(1);
358  sl_unc = ff_pol1->GetParError(1);
359 
360  return 0;
361 }
362 
363 // Builds graph from a vector of points (with errors).
364 std::unique_ptr<TGraphErrors> PPSAlignmentHarvester::buildGraphFromVector(
365  const std::vector<PPSAlignmentConfiguration::PointErrors>& pv) {
366  auto g = std::make_unique<TGraphErrors>();
367 
368  for (unsigned int i = 0; i < pv.size(); i++) {
369  const auto& p = pv[i];
370  g->SetPoint(i, p.x_, p.y_);
371  g->SetPointError(i, p.ex_, p.ey_);
372  }
373  g->Sort();
374 
375  return g;
376 }
377 
378 // Builds a TGraphErrors from slice plots represented as MonitorElements.
380  DQMStore::IGetter& iGetter,
382  const std::vector<MonitorElement*>& mes,
383  unsigned int fitProfileMinBinEntries,
384  unsigned int fitProfileMinNReasonable) {
385  auto g = std::make_unique<TGraphErrors>();
386 
387  for (auto* me : mes) {
388  if (me->getName() == "h_y") // find "h_y"
389  {
390  // retrieve parent directory
391  std::string parentPath = me->getPathname();
392  size_t parentPos = parentPath.substr(0, parentPath.size() - 1).find_last_of('/') + 1;
393  std::string parentName = parentPath.substr(parentPos);
394  size_t d = parentName.find('-');
395  const double x_min = std::stod(parentName.substr(0, d));
396  const double x_max = std::stod(parentName.substr(d + 1));
397 
398  TH1D* h_y = me->getTH1D();
399 
400  // collect "p_y_diffFN_vs_y" corresponding to found "h_y"
401  auto* p_y_diffFN_vs_y_monitor = iGetter.get(parentPath + "p_y_diffFN_vs_y");
402  if (p_y_diffFN_vs_y_monitor == nullptr) {
403  edm::LogWarning("PPS") << "[x_alignment] could not find p_y_diffFN_vs_y in: " << parentPath;
404  continue;
405  }
406  TProfile* p_y_diffFN_vs_y = p_y_diffFN_vs_y_monitor->getTProfile();
407 
408  double y_cen = h_y->GetMean();
409  double y_width = h_y->GetRMS();
410 
411  y_cen += rpc.y_cen_add_;
412  y_width *= rpc.y_width_mult_;
413 
414  double sl = 0., sl_unc = 0.;
415  int fr =
416  fitProfile(p_y_diffFN_vs_y, y_cen, y_width, fitProfileMinBinEntries, fitProfileMinNReasonable, sl, sl_unc);
417  if (fr != 0)
418  continue;
419 
420  if (debug_)
421  p_y_diffFN_vs_y->Write(parentName.c_str());
422 
423  int idx = g->GetN();
424  g->SetPoint(idx, (x_max + x_min) / 2., sl);
425  g->SetPointError(idx, (x_max - x_min) / 2., sl_unc);
426  }
427  }
428  g->Sort();
429 
430  return g;
431 }
432 
433 // Matches reference data with test data.
437  TGraphErrors* g_ref,
438  TGraphErrors* g_test,
440  double sh_min,
441  double sh_max,
442  double& sh_best,
443  double& sh_best_unc) {
444  const auto range_test = cfg.alignment_x_meth_o_ranges().at(rpc.id_);
445 
446  // print config
447  edm::LogInfo("PPS") << std::fixed << std::setprecision(3) << "[x_alignment] "
448  << "ref: x_min = " << range_ref.x_min_ << ", x_max = " << range_ref.x_max_ << "\n"
449  << "test: x_min = " << range_test.x_min_ << ", x_max = " << range_test.x_max_;
450 
451  // make spline from g_ref
452  auto s_ref = std::make_unique<TSpline3>("s_ref", g_ref->GetX(), g_ref->GetY(), g_ref->GetN());
453 
454  // book match-quality graphs
455  auto g_n_points = std::make_unique<TGraph>();
456  g_n_points->SetName("g_n_points");
457  g_n_points->SetTitle(";sh;N");
458  auto g_chi_sq = std::make_unique<TGraph>();
459  g_chi_sq->SetName("g_chi_sq");
460  g_chi_sq->SetTitle(";sh;S2");
461  auto g_chi_sq_norm = std::make_unique<TGraph>();
462  g_chi_sq_norm->SetName("g_chi_sq_norm");
463  g_chi_sq_norm->SetTitle(";sh;S2 / N");
464 
465  // optimalisation variables
466  double S2_norm_best = 1E100;
467 
468  for (double sh = sh_min; sh <= sh_max; sh += cfg.x_ali_sh_step()) {
469  // calculate chi^2
470  int n_points = 0;
471  double S2 = 0.;
472 
473  for (int i = 0; i < g_test->GetN(); ++i) {
474  const double x_test = g_test->GetX()[i];
475  const double y_test = g_test->GetY()[i];
476  const double y_test_unc = g_test->GetErrorY(i);
477 
478  const double x_ref = x_test + sh;
479 
480  if (x_ref < range_ref.x_min_ || x_ref > range_ref.x_max_ || x_test < range_test.x_min_ ||
481  x_test > range_test.x_max_)
482  continue;
483 
484  const double y_ref = s_ref->Eval(x_ref);
485 
486  int js = -1, jg = -1;
487  double xs = -1E100, xg = +1E100;
488  for (int j = 0; j < g_ref->GetN(); ++j) {
489  const double x = g_ref->GetX()[j];
490  if (x < x_ref && x > xs) {
491  xs = x;
492  js = j;
493  }
494  if (x > x_ref && x < xg) {
495  xg = x;
496  jg = j;
497  }
498  }
499  if (jg == -1)
500  jg = js;
501 
502  const double y_ref_unc = (g_ref->GetErrorY(js) + g_ref->GetErrorY(jg)) / 2.;
503 
504  n_points++;
505  const double S2_inc = pow(y_test - y_ref, 2.) / (y_ref_unc * y_ref_unc + y_test_unc * y_test_unc);
506  S2 += S2_inc;
507  }
508 
509  // update best result
510  double S2_norm = S2 / n_points;
511 
512  if (S2_norm < S2_norm_best) {
513  S2_norm_best = S2_norm;
514  sh_best = sh;
515  }
516 
517  // fill in graphs
518  int idx = g_n_points->GetN();
519  g_n_points->SetPoint(idx, sh, n_points);
520  g_chi_sq->SetPoint(idx, sh, S2);
521  g_chi_sq_norm->SetPoint(idx, sh, S2_norm);
522  }
523 
524  auto ff_pol2 = std::make_unique<TF1>("ff_pol2", "[0] + [1]*x + [2]*x*x");
525 
526  // determine uncertainty
527  double fit_range = cfg.methOUncFitRange();
528  g_chi_sq->Fit(ff_pol2.get(), "Q", "", sh_best - fit_range, sh_best + fit_range);
529  sh_best_unc = 1. / sqrt(ff_pol2->GetParameter(2));
530 
531  // print results
532  edm::LogInfo("PPS") << std::fixed << std::setprecision(3) << "[x_alignment] "
533  << "sh_best = (" << sh_best << " +- " << sh_best_unc << ") mm";
534 
535  auto g_test_shifted = std::make_unique<TGraphErrors>(*g_test);
536  for (int i = 0; i < g_test_shifted->GetN(); ++i) {
537  g_test_shifted->GetX()[i] += sh_best;
538  }
539 
540  std::unique_ptr<TH1D> histPtr = getTH1DFromTGraphErrors(
541  g_test_shifted.get(), "test_shifted", ";x (mm);S", rpc.x_slice_n_, rpc.x_slice_w_, rpc.x_slice_min_ + sh_best);
542  iBooker.book1DD("h_test_shifted", histPtr.get());
543 
544  if (debug_) {
545  // save graphs
546  g_n_points->Write();
547  g_chi_sq->Write();
548  g_chi_sq_norm->Write();
549  g_test_shifted->SetTitle(";x (mm);S");
550  g_test_shifted->Write("g_test_shifted");
551 
552  // save results
553  auto g_results = std::make_unique<TGraph>();
554  g_results->SetName("g_results");
555  g_results->SetPoint(0, sh_best, sh_best_unc);
556  g_results->SetPoint(1, range_ref.x_min_, range_ref.x_max_);
557  g_results->SetPoint(2, range_test.x_min_, range_test.x_max_);
558  g_results->Write();
559 
560  // save debug canvas
561  auto c_cmp = std::make_unique<TCanvas>("c_cmp");
562  g_ref->SetLineColor(1);
563  g_ref->SetName("g_ref");
564  g_ref->Draw("apl");
565 
566  g_test->SetLineColor(4);
567  g_test->SetName("g_test");
568  g_test->Draw("pl");
569 
570  g_test_shifted->SetLineColor(2);
571  g_test_shifted->SetName("g_test_shifted");
572 
573  g_test_shifted->Draw("pl");
574  c_cmp->Write();
575  }
576 }
577 
578 // method o
580  DQMStore::IGetter& iGetter,
582  const PPSAlignmentConfiguration& cfg_ref,
583  int seqPos) {
584  TDirectory* xAliDir = nullptr;
585  if (debug_)
586  xAliDir = debugFile_->mkdir((std::to_string(seqPos + 1) + ": x alignment").c_str());
587 
588  for (const auto& scPair : {std::make_pair(cfg.sectorConfig45(), cfg_ref.sectorConfig45()),
589  std::make_pair(cfg.sectorConfig56(), cfg_ref.sectorConfig56())}) {
590  const auto& sc = scPair.first;
591  const auto& sc_ref = scPair.second;
592 
593  for (const auto& rpcPair : {std::make_pair(sc.rp_F_, sc_ref.rp_F_), std::make_pair(sc.rp_N_, sc_ref.rp_N_)}) {
594  const auto& rpc = rpcPair.first;
595  const auto& rpc_ref = rpcPair.second;
596 
597  auto mes_test = iGetter.getAllContents(folder_ + "/worker/" + sc.name_ + "/near_far/x slices, " + rpc.position_);
598  if (mes_test.empty()) {
599  edm::LogWarning("PPS") << "[x_alignment] " << rpc.name_ << ": could not load mes_test";
600  continue;
601  }
602 
603  TDirectory* rpDir = nullptr;
604  if (debug_)
605  rpDir = xAliDir->mkdir(rpc.name_.c_str());
606 
607  auto vec_ref = cfg_ref.matchingReferencePoints().at(rpc.id_);
608  if (vec_ref.empty()) {
609  edm::LogInfo("PPS") << "[x_alignment] " << rpc.name_ << ": reference points vector is empty";
610  continue;
611  }
612 
613  std::unique_ptr<TGraphErrors> g_ref = buildGraphFromVector(vec_ref);
614 
615  if (debug_)
616  gDirectory = rpDir->mkdir("fits_test");
617  std::unique_ptr<TGraphErrors> g_test = buildGraphFromMonitorElements(
618  iGetter, rpc, mes_test, cfg.fitProfileMinBinEntries(), cfg.fitProfileMinNReasonable());
619 
620  // require minimal number of points
621  if (g_ref->GetN() < (int)cfg.methOGraphMinN() || g_test->GetN() < (int)cfg.methOGraphMinN()) {
622  edm::LogWarning("PPS") << "[x_alignment] " << rpc.name_ << ": insufficient data, skipping (g_ref "
623  << g_ref->GetN() << "/" << cfg.methOGraphMinN() << ", g_test " << g_test->GetN() << "/"
624  << cfg.methOGraphMinN() << ")";
625  continue;
626  }
627 
628  iBooker.setCurrentFolder(folder_ + "/harvester/x alignment/" + rpc.name_);
629 
630  std::unique_ptr<TH1D> histPtr = getTH1DFromTGraphErrors(
631  g_ref.get(), "ref", ";x (mm);S", rpc_ref.x_slice_n_, rpc_ref.x_slice_w_, rpc_ref.x_slice_min_);
632  iBooker.book1DD("h_ref", histPtr.get());
633 
634  histPtr =
635  getTH1DFromTGraphErrors(g_test.get(), "test", ";x (mm);S", rpc.x_slice_n_, rpc.x_slice_w_, rpc.x_slice_min_);
636  iBooker.book1DD("h_test", histPtr.get());
637 
638  if (debug_) {
639  gDirectory = rpDir;
640  g_ref->SetTitle(";x (mm);S");
641  g_ref->Write("g_ref");
642  g_test->SetTitle(";x (mm);S");
643  g_test->Write("g_test");
644  }
645 
646  const auto& shiftRange = cfg.matchingShiftRanges().at(rpc.id_);
647  double sh = 0., sh_unc = 0.;
648 
649  // matching
650  doMatch(iBooker,
651  cfg,
652  rpc,
653  g_ref.get(),
654  g_test.get(),
655  cfg_ref.alignment_x_meth_o_ranges().at(rpc.id_),
656  shiftRange.x_min_,
657  shiftRange.x_max_,
658  sh,
659  sh_unc);
660 
661  // save the results
662  CTPPSRPAlignmentCorrectionData rpResult(sh, sh_unc, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
663  xAliResults_.setRPCorrection(rpc.id_, rpResult);
664  edm::LogInfo("PPS") << std::fixed << std::setprecision(3) << "[x_alignment] "
665  << "Setting sh_x of " << rpc.name_ << " to " << sh;
666 
667  // update the shift
668  if (overwriteShX_) {
669  sh_x_map_[rpc.id_] = sh;
670  }
671  }
672  }
673 
674  edm::LogInfo("PPS") << seqPos + 1 << ": x_alignment:\n" << xAliResults_;
675 
676  if (textResultsFile_.is_open())
677  textResultsFile_ << seqPos + 1 << ": x_alignment:\n" << xAliResults_ << "\n\n";
678 }
679 
680 // -------------------------------- x alignment relative methods --------------------------------
681 
683  DQMStore::IGetter& iGetter,
684  const PPSAlignmentConfiguration& cfg,
685  int seqPos) {
686  TDirectory* xAliRelDir = nullptr;
687  if (debug_)
688  xAliRelDir = debugFile_->mkdir((std::to_string(seqPos + 1) + ": x_alignment_relative").c_str());
689 
690  auto ff = std::make_unique<TF1>("ff", "[0] + [1]*(x - [2])");
691  auto ff_sl_fix = std::make_unique<TF1>("ff_sl_fix", "[0] + [1]*(x - [2])");
692 
693  // processing
694  for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) {
695  TDirectory* sectorDir = nullptr;
696  if (debug_) {
697  sectorDir = xAliRelDir->mkdir(sc.name_.c_str());
698  gDirectory = sectorDir;
699  }
700 
701  auto* p_x_diffFN_vs_x_N_monitor = iGetter.get(folder_ + "/worker/" + sc.name_ + "/near_far/p_x_diffFN_vs_x_N");
702  if (p_x_diffFN_vs_x_N_monitor == nullptr) {
703  edm::LogWarning("PPS") << "[x_alignment_relative] " << sc.name_ << ": cannot load data, skipping";
704  continue;
705  }
706  TProfile* p_x_diffFN_vs_x_N = p_x_diffFN_vs_x_N_monitor->getTProfile();
707 
708  if (p_x_diffFN_vs_x_N->GetEntries() < cfg.nearFarMinEntries()) {
709  edm::LogWarning("PPS") << "[x_alignment_relative] " << sc.name_ << ": insufficient data, skipping (near_far "
710  << p_x_diffFN_vs_x_N->GetEntries() << "/" << cfg.nearFarMinEntries() << ")";
711  continue;
712  }
713 
714  const double x_min = cfg.alignment_x_relative_ranges().at(sc.rp_N_.id_).x_min_;
715  const double x_max = cfg.alignment_x_relative_ranges().at(sc.rp_N_.id_).x_max_;
716 
717  const double sh_x_N = sh_x_map_[sc.rp_N_.id_];
718  double slope = sc.slope_;
719 
720  ff->SetParameters(0., slope, 0.);
721  ff->FixParameter(2, -sh_x_N);
722  ff->SetLineColor(2);
723  p_x_diffFN_vs_x_N->Fit(ff.get(), "Q", "", x_min, x_max);
724 
725  const double a = ff->GetParameter(1), a_unc = ff->GetParError(1);
726  const double b = ff->GetParameter(0), b_unc = ff->GetParError(0);
727 
728  edm::LogInfo("PPS") << "[x_alignment_relative] " << sc.name_ << ":\n"
729  << std::fixed << std::setprecision(3) << " x_min = " << x_min << ", x_max = " << x_max
730  << "\n"
731  << " sh_x_N = " << sh_x_N << ", slope (fix) = " << slope << ", slope (fitted) = " << a;
732 
733  CTPPSRPAlignmentCorrectionData rpResult_N(+b / 2., b_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
734  xAliRelResults_.setRPCorrection(sc.rp_N_.id_, rpResult_N);
735  CTPPSRPAlignmentCorrectionData rpResult_F(-b / 2., b_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
736  xAliRelResults_.setRPCorrection(sc.rp_F_.id_, rpResult_F);
737 
738  ff_sl_fix->SetParameters(0., slope, 0.);
739  ff_sl_fix->FixParameter(1, slope);
740  ff_sl_fix->FixParameter(2, -sh_x_N);
741  ff_sl_fix->SetLineColor(4);
742  p_x_diffFN_vs_x_N->Fit(ff_sl_fix.get(), "Q+", "", x_min, x_max);
743 
744  const double b_fs = ff_sl_fix->GetParameter(0), b_fs_unc = ff_sl_fix->GetParError(0);
745 
746  CTPPSRPAlignmentCorrectionData rpResult_sl_fix_N(+b_fs / 2., b_fs_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
747  xAliRelResultsSlopeFixed_.setRPCorrection(sc.rp_N_.id_, rpResult_sl_fix_N);
748  CTPPSRPAlignmentCorrectionData rpResult_sl_fix_F(-b_fs / 2., b_fs_unc / 2., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.);
749  xAliRelResultsSlopeFixed_.setRPCorrection(sc.rp_F_.id_, rpResult_sl_fix_F);
750 
751  edm::LogInfo("PPS") << "[x_alignment_relative] " << std::fixed << std::setprecision(3)
752  << "ff: " << ff->GetParameter(0) << " + " << ff->GetParameter(1) << " * (x - "
753  << ff->GetParameter(2) << "), ff_sl_fix: " << ff_sl_fix->GetParameter(0) << " + "
754  << ff_sl_fix->GetParameter(1) << " * (x - " << ff_sl_fix->GetParameter(2) << ")";
755 
756  // rebook the diffFN plot in the harvester
757  iBooker.setCurrentFolder(folder_ + "/harvester/x_alignment_relative/" + sc.name_);
758  iBooker.bookProfile("p_x_diffFN_vs_x_N", p_x_diffFN_vs_x_N);
759 
760  if (debug_) {
761  p_x_diffFN_vs_x_N->Write("p_x_diffFN_vs_x_N");
762 
763  auto g_results = std::make_unique<TGraph>();
764  g_results->SetPoint(0, sh_x_N, 0.);
765  g_results->SetPoint(1, a, a_unc);
766  g_results->SetPoint(2, b, b_unc);
767  g_results->SetPoint(3, b_fs, b_fs_unc);
768  g_results->Write("g_results");
769  }
770  }
771 
772  // write results
773  edm::LogInfo("PPS") << seqPos + 1 << ": x_alignment_relative:\n"
774  << xAliRelResults_ << seqPos + 1 << ": x_alignment_relative_sl_fix:\n"
776 
777  if (textResultsFile_.is_open()) {
778  textResultsFile_ << seqPos + 1 << ": x_alignment_relative:\n" << xAliRelResults_ << "\n";
779  textResultsFile_ << seqPos + 1 << ": x_alignment_relative_sl_fix:\n" << xAliRelResultsSlopeFixed_ << "\n\n";
780  }
781 }
782 
783 // -------------------------------- y alignment methods --------------------------------
784 
785 double PPSAlignmentHarvester::findMax(TF1* ff_fit) {
786  const double mu = ff_fit->GetParameter(1);
787  const double si = ff_fit->GetParameter(2);
788 
789  // unreasonable fit?
790  if (si > 25. || std::fabs(mu) > 100.)
791  return 1E100;
792 
793  double x_max = 1E100;
794  double y_max = -1E100;
795  for (double x = mu - si; x <= mu + si; x += 0.001) {
796  double y = ff_fit->Eval(x);
797  if (y > y_max) {
798  x_max = x;
799  y_max = y;
800  }
801  }
802 
803  return x_max;
804 }
805 
807  MonitorElement* h2_y_vs_x,
808  const PPSAlignmentConfiguration& cfg,
810  TDirectory* d_top = nullptr;
811  if (debug_)
812  d_top = gDirectory;
813 
814  auto ff_fit = std::make_unique<TF1>("ff_fit", "[0] * exp(-(x-[1])*(x-[1])/2./[2]/[2]) + [3] + [4]*x");
815 
816  int h_n = h2_y_vs_x->getNbinsX();
817  double diff = h2_y_vs_x->getTH2D()->GetXaxis()->GetBinWidth(1) / 2.;
818  auto h_mode = iBooker.book1DD("mode",
819  ";x (mm); mode of y (mm)",
820  h_n,
821  h2_y_vs_x->getTH2D()->GetXaxis()->GetBinCenter(1) - diff,
822  h2_y_vs_x->getTH2D()->GetXaxis()->GetBinCenter(h_n) + diff);
823 
824  for (int bix = 1; bix <= h_n; bix++) {
825  const double x = h2_y_vs_x->getTH2D()->GetXaxis()->GetBinCenter(bix);
826 
827  char buf[100];
828  sprintf(buf, "h_y_x=%.3f", x);
829  TH1D* h_y = h2_y_vs_x->getTH2D()->ProjectionY(buf, bix, bix);
830 
831  if (h_y->GetEntries() < cfg.multSelProjYMinEntries())
832  continue;
833 
834  if (debug_) {
835  sprintf(buf, "x=%.3f", x);
836  gDirectory = d_top->mkdir(buf);
837  }
838 
839  double conMax = -1.;
840  double conMax_x = 0.;
841  for (int biy = 1; biy < h_y->GetNbinsX(); biy++) {
842  if (h_y->GetBinContent(biy) > conMax) {
843  conMax = h_y->GetBinContent(biy);
844  conMax_x = h_y->GetBinCenter(biy);
845  }
846  }
847 
848  ff_fit->SetParameters(conMax, conMax_x, h_y->GetRMS() * 0.75, 0., 0.);
849  ff_fit->FixParameter(4, 0.);
850 
851  double x_min = rpc.x_min_fit_mode_, x_max = rpc.x_max_fit_mode_;
852  h_y->Fit(ff_fit.get(), "Q", "", x_min, x_max);
853 
854  ff_fit->ReleaseParameter(4);
855  double w = std::min(4., 2. * ff_fit->GetParameter(2));
856  x_min = ff_fit->GetParameter(1) - w;
857  x_max = std::min(rpc.y_max_fit_mode_, ff_fit->GetParameter(1) + w);
858 
859  h_y->Fit(ff_fit.get(), "Q", "", x_min, x_max);
860 
861  if (debug_)
862  h_y->Write("h_y");
863 
864  double y_mode = findMax(ff_fit.get());
865  const double y_mode_fit_unc = ff_fit->GetParameter(2) / 10;
866  const double y_mode_sys_unc = cfg.y_mode_sys_unc();
867  double y_mode_unc = std::sqrt(y_mode_fit_unc * y_mode_fit_unc + y_mode_sys_unc * y_mode_sys_unc);
868 
869  const double chiSqThreshold = cfg.chiSqThreshold();
870 
871  const bool valid =
872  !(std::fabs(y_mode_unc) > cfg.y_mode_unc_max_valid() || std::fabs(y_mode) > cfg.y_mode_max_valid() ||
873  ff_fit->GetChisquare() / ff_fit->GetNDF() > chiSqThreshold);
874 
875  if (debug_) {
876  auto g_data = std::make_unique<TGraph>();
877  g_data->SetPoint(0, y_mode, y_mode_unc);
878  g_data->SetPoint(1, ff_fit->GetChisquare(), ff_fit->GetNDF());
879  g_data->SetPoint(2, valid, 0.);
880  g_data->Write("g_data");
881  }
882 
883  if (!valid)
884  continue;
885 
886  h_mode->Fill(x, y_mode);
887  h_mode->setBinError(bix, y_mode_unc);
888  }
889 
890  return h_mode->getTH1D();
891 }
892 
894  DQMStore::IGetter& iGetter,
895  const PPSAlignmentConfiguration& cfg,
896  int seqPos) {
897  TDirectory* yAliDir = nullptr;
898  if (debug_)
899  yAliDir = debugFile_->mkdir((std::to_string(seqPos + 1) + ": y_alignment").c_str());
900 
901  auto ff = std::make_unique<TF1>("ff", "[0] + [1]*(x - [2])");
902  auto ff_sl_fix = std::make_unique<TF1>("ff_sl_fix", "[0] + [1]*(x - [2])");
903 
904  // processing
905  for (const auto& sc : {cfg.sectorConfig45(), cfg.sectorConfig56()}) {
906  for (const auto& rpc : {sc.rp_F_, sc.rp_N_}) {
907  TDirectory* rpDir = nullptr;
908  if (debug_) {
909  rpDir = yAliDir->mkdir(rpc.name_.c_str());
910  gDirectory = rpDir->mkdir("x");
911  }
912 
913  auto* h2_y_vs_x =
914  iGetter.get(folder_ + "/worker/" + sc.name_ + "/multiplicity selection/" + rpc.name_ + "/h2_y_vs_x");
915 
916  if (h2_y_vs_x == nullptr) {
917  edm::LogWarning("PPS") << "[y_alignment] " << rpc.name_ << ": cannot load data, skipping";
918  continue;
919  }
920 
921  iBooker.setCurrentFolder(folder_ + "/harvester/y alignment/" + rpc.name_);
922  auto* h_y_cen_vs_x = buildModeGraph(iBooker, h2_y_vs_x, cfg, rpc);
923 
924  if ((unsigned int)h_y_cen_vs_x->GetEntries() < cfg.modeGraphMinN()) {
925  edm::LogWarning("PPS") << "[y_alignment] " << rpc.name_ << ": insufficient data, skipping (mode graph "
926  << h_y_cen_vs_x->GetEntries() << "/" << cfg.modeGraphMinN() << ")";
927  continue;
928  }
929 
930  const double x_min = cfg.alignment_y_ranges().at(rpc.id_).x_min_;
931  const double x_max = cfg.alignment_y_ranges().at(rpc.id_).x_max_;
932 
933  const double sh_x = sh_x_map_[rpc.id_];
934  double slope = rpc.slope_;
935 
936  ff->SetParameters(0., 0., 0.);
937  ff->FixParameter(2, -sh_x);
938  ff->SetLineColor(2);
939  h_y_cen_vs_x->Fit(ff.get(), "Q", "", x_min, x_max);
940 
941  const double a = ff->GetParameter(1), a_unc = ff->GetParError(1);
942  const double b = ff->GetParameter(0), b_unc = ff->GetParError(0);
943 
944  edm::LogInfo("PPS") << "[y_alignment] " << rpc.name_ << ":\n"
945  << std::fixed << std::setprecision(3) << " x_min = " << x_min << ", x_max = " << x_max
946  << "\n"
947  << " sh_x = " << sh_x << ", slope (fix) = " << slope << ", slope (fitted) = " << a;
948 
949  CTPPSRPAlignmentCorrectionData rpResult(0., 0., b, b_unc, 0., 0., 0., 0., 0., 0., 0., 0.);
950  yAliResults_.setRPCorrection(rpc.id_, rpResult);
951 
952  ff_sl_fix->SetParameters(0., 0., 0.);
953  ff_sl_fix->FixParameter(1, slope);
954  ff_sl_fix->FixParameter(2, -sh_x);
955  ff_sl_fix->SetLineColor(4);
956  h_y_cen_vs_x->Fit(ff_sl_fix.get(), "Q+", "", x_min, x_max);
957 
958  const double b_fs = ff_sl_fix->GetParameter(0), b_fs_unc = ff_sl_fix->GetParError(0);
959 
960  CTPPSRPAlignmentCorrectionData rpResult_sl_fix(0., 0., b_fs, b_fs_unc, 0., 0., 0., 0., 0., 0., 0., 0.);
961  yAliResultsSlopeFixed_.setRPCorrection(rpc.id_, rpResult_sl_fix);
962 
963  edm::LogInfo("PPS") << "[y_alignment] " << std::fixed << std::setprecision(3) << "ff: " << ff->GetParameter(0)
964  << " + " << ff->GetParameter(1) << " * (x - " << ff->GetParameter(2)
965  << "), ff_sl_fix: " << ff_sl_fix->GetParameter(0) << " + " << ff_sl_fix->GetParameter(1)
966  << " * (x - " << ff_sl_fix->GetParameter(2) << ")";
967 
968  if (debug_) {
969  gDirectory = rpDir;
970 
971  h_y_cen_vs_x->SetTitle(";x (mm); mode of y (mm)");
972  h_y_cen_vs_x->Write("h_y_cen_vs_x");
973 
974  auto g_results = std::make_unique<TGraph>();
975  g_results->SetPoint(0, sh_x, 0.);
976  g_results->SetPoint(1, a, a_unc);
977  g_results->SetPoint(2, b, b_unc);
978  g_results->SetPoint(3, b_fs, b_fs_unc);
979  g_results->Write("g_results");
980  }
981  }
982  }
983 
984  // write results
985  edm::LogInfo("PPS") << seqPos + 1 << ": y_alignment:\n"
986  << yAliResults_ << seqPos + 1 << ": y_alignment_sl_fix:\n"
988 
989  if (textResultsFile_.is_open()) {
990  textResultsFile_ << seqPos + 1 << ": y_alignment:\n" << yAliResults_ << "\n";
991  textResultsFile_ << seqPos + 1 << ": y_alignment_sl_fix:\n" << yAliResultsSlopeFixed_ << "\n\n";
992  }
993 }
994 
995 // -------------------------------- other methods --------------------------------
996 
997 void PPSAlignmentHarvester::writeCutPlot(TH2D* h, double a, double c, double n_si, double si, const std::string& label) {
998  auto canvas = std::make_unique<TCanvas>();
999  canvas->SetName(label.c_str());
1000  canvas->SetLogz(1);
1001 
1002  h->Draw("colz");
1003 
1004  double x_min = -30.;
1005  double x_max = 30.;
1006 
1007  auto g_up = std::make_unique<TGraph>();
1008  g_up->SetName("g_up");
1009  g_up->SetPoint(0, x_min, -a * x_min - c + n_si * si);
1010  g_up->SetPoint(1, x_max, -a * x_max - c + n_si * si);
1011  g_up->SetLineColor(1);
1012  g_up->Draw("l");
1013 
1014  auto g_down = std::make_unique<TGraph>();
1015  g_down->SetName("g_down");
1016  g_down->SetPoint(0, x_min, -a * x_min - c - n_si * si);
1017  g_down->SetPoint(1, x_max, -a * x_max - c - n_si * si);
1018  g_down->SetLineColor(1);
1019  g_down->Draw("l");
1020 
1021  canvas->Write();
1022 }
1023 
1024 // Points in TGraph should be sorted (TGraph::Sort())
1025 // if n, binWidth, or min is set to -1, method will find it on its own
1027  TGraphErrors* graph, std::string title, std::string labels, int n, double binWidth, double min) {
1028  std::unique_ptr<TH1D> hist;
1029  if (n == 0) {
1030  hist = std::make_unique<TH1D>(title.c_str(), labels.c_str(), 0, -10., 10.);
1031  } else if (n == 1) {
1032  hist = std::make_unique<TH1D>(title.c_str(), labels.c_str(), 1, graph->GetPointX(0) - 5., graph->GetPointX(0) + 5.);
1033  } else {
1034  n = n == -1 ? graph->GetN() : n;
1035  binWidth = binWidth == -1 ? graph->GetPointX(1) - graph->GetPointX(0) : binWidth;
1036  double diff = binWidth / 2.;
1037  min = min == -1 ? graph->GetPointX(0) - diff : min;
1038  double max = min + n * binWidth;
1039  hist = std::make_unique<TH1D>(title.c_str(), labels.c_str(), n, min, max);
1040  }
1041 
1042  for (int i = 0; i < graph->GetN(); i++) {
1043  double x, y;
1044  graph->GetPoint(i, x, y);
1045  hist->Fill(x, y);
1046  hist->SetBinError(hist->GetXaxis()->FindBin(x), graph->GetErrorY(i));
1047  }
1048  return hist;
1049 }
1050 
void dqmEndRun(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::Run const &iRun, edm::EventSetup const &iSetup) override
virtual TH2D * getTH2D() const
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EventSetup & c
CTPPSRPAlignmentCorrectionData & getRPCorrection(unsigned int id)
returns the correction value from the RP map
tuple cfg
Definition: looper.py:296
std::map< unsigned int, double > sh_x_map_
std::string folder_
edm::ESGetToken< PPSAlignmentConfiguration, PPSAlignmentConfigurationRcd > esTokenReference_
const double w
Definition: UKUtility.cc:23
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
std::unique_ptr< TGraphErrors > buildGraphFromMonitorElements(DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration::RPConfig &rpc, const std::vector< MonitorElement * > &mes, unsigned int fitProfileMinBinEntries, unsigned int fitProfileMinNReasonable)
unsigned int fitProfileMinBinEntries() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CTPPSRPAlignmentCorrectionsData xAliRelResults_
static const double slope[3]
static int fitProfile(TProfile *p, double x_mean, double x_rms, unsigned int fitProfileMinBinEntries, unsigned int fitProfileMinNReasonable, double &sl, double &sl_unc)
unsigned int multSelProjYMinEntries() const
unsigned int methOGraphMinN() const
const std::map< unsigned int, std::vector< PointErrors > > & matchingReferencePoints() const
CTPPSRPAlignmentCorrectionsData yAliResults_
const SectorConfig & sectorConfig56() const
void setRPCorrection(unsigned int id, const CTPPSRPAlignmentCorrectionData &ac)
sets the alignment correction for the given RP
Log< level::Error, false > LogError
const std::map< unsigned int, SelectionRange > & matchingShiftRanges() const
void yAlignment(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration &cfg, int seqPos)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:609
static std::unique_ptr< TH1D > getTH1DFromTGraphErrors(TGraphErrors *graph, std::string title="", std::string labels="", int n=-1, double binWidth=-1., double min=-1.)
def canvas
Definition: svgfig.py:482
bool getData(T &iHolder) const
Definition: EventSetup.h:128
tuple d
Definition: ztail.py:151
std::unique_ptr< TGraphErrors > buildGraphFromVector(const std::vector< PPSAlignmentConfiguration::PointErrors > &pv)
const std::map< unsigned int, SelectionRange > & alignment_y_ranges() const
char const * label
CTPPSRPAlignmentCorrectionsData yAliResultsSlopeFixed_
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:155
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual int getNbinsX() const
get # of bins in X-axis
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
CTPPSRPAlignmentCorrectionsData xAliResults_
PPSAlignmentHarvester(const edm::ParameterSet &iConfig)
T sqrt(T t)
Definition: SSEVec.h:19
void doMatch(DQMStore::IBooker &iBooker, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration::RPConfig &rpc, TGraphErrors *g_ref, TGraphErrors *g_test, const PPSAlignmentConfiguration::SelectionRange &range_ref, double sh_min, double sh_max, double &sh_best, double &sh_best_unc)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
bool isAvailable() const
Definition: Service.h:40
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Transition
Definition: Transition.h:12
TH1D * buildModeGraph(DQMStore::IBooker &iBooker, MonitorElement *h2_y_vs_x, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration::RPConfig &rpc)
const int mu
Definition: Constants.h:22
const std::vector< std::string > sequence_
T min(T a, T b)
Definition: MathUtil.h:58
edm::ESGetToken< PPSAlignmentConfiguration, PPSAlignmentConfigurationRcd > esTokenTest_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void addRPCorrection(unsigned int, const CTPPSRPAlignmentCorrectionData &, bool sumErrors=true, bool addSh=true, bool addRot=true)
std::unique_ptr< TFile > debugFile_
static void writeCutPlot(TH2D *h, double a, double c, double si, double n_si, const std::string &label)
void addCorrections(const CTPPSRPAlignmentCorrectionsData &, bool sumErrors=true, bool addSh=true, bool addRot=true)
adds (merges) corrections on top of the current values
__shared__ Hist hist
Log< level::Info, false > LogInfo
unsigned int nearFarMinEntries() const
unsigned int fitProfileMinNReasonable() const
void dqmEndJob(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double b
Definition: hdecay.h:118
void xAlignment(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration &cfg_ref, int seqPos)
Container for CTPPS RP alignment corrections. The corrections are stored on two levels - RP and senso...
const SectorConfig & sectorConfig45() const
void xAlignmentRelative(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const PPSAlignmentConfiguration &cfg, int seqPos)
double a
Definition: hdecay.h:119
CTPPSRPAlignmentCorrectionsData xAliRelResultsSlopeFixed_
const std::map< unsigned int, SelectionRange > & alignment_x_relative_ranges() const
Log< level::Warning, false > LogWarning
static double findMax(TF1 *ff_fit)
const std::map< unsigned int, SelectionRange > & alignment_x_meth_o_ranges() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Alignment correction for an element of the CT-PPS detector. Within the geometry description, every sensor (more generally every element) is given its translation and rotation. These two quantities shall be understood in local-to-global coordinate transform. That is, if r_l is a point in local coordinate system and x_g in global, then it holds.
Definition: Run.h:45