CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PPSAlignmentConfigurationESSource.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 
17 
20 
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include <memory>
25 #include <queue>
26 
27 #include "TF1.h"
28 #include "TProfile.h"
29 #include "TFile.h"
30 #include "TKey.h"
31 #include "TSystemFile.h"
32 
33 //---------------------------------------------------------------------------------------------
34 
36 public:
38 
39  std::unique_ptr<PPSAlignmentConfiguration> produce(const PPSAlignmentConfigurationRcd&);
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42 private:
43  int fitProfile(TProfile* p, double x_mean, double x_rms, double& sl, double& sl_unc);
44  TDirectory* findDirectoryWithName(TDirectory* dir, std::string searchName);
45  std::vector<PPSAlignmentConfiguration::PointErrors> buildVectorFromDirectory(
46  TDirectory* dir, const PPSAlignmentConfiguration::RPConfig& rpd);
47 
49  const edm::IOVSyncValue& iosv,
50  edm::ValidityInterval& oValidity) override;
51 
52  bool debug;
53 
55 
56  double x_ali_sh_step;
57 
62 
63  unsigned int minRPTracksSize;
64  unsigned int maxRPTracksSize;
65  double n_si;
66 
67  std::map<unsigned int, std::vector<PPSAlignmentConfiguration::PointErrors>> matchingReferencePoints;
68  std::map<unsigned int, PPSAlignmentConfiguration::SelectionRange> matchingShiftRanges;
69 
70  std::map<unsigned int, PPSAlignmentConfiguration::SelectionRange> alignment_x_meth_o_ranges;
73  unsigned int methOGraphMinN;
75 
76  std::map<unsigned int, PPSAlignmentConfiguration::SelectionRange> alignment_x_relative_ranges;
77  unsigned int nearFarMinEntries;
78 
79  std::map<unsigned int, PPSAlignmentConfiguration::SelectionRange> alignment_y_ranges;
80  unsigned int modeGraphMinN;
81  unsigned int multSelProjYMinEntries;
82 
84 
85  std::vector<double> extraParams;
86 
88 };
89 
90 //---------------------------------------------------------------------------------------------
91 
93  label = iConfig.getParameter<std::string>("label");
94 
95  debug = iConfig.getParameter<bool>("debug");
96  TFile* debugFile = nullptr;
97  if (debug) {
98  debugFile = new TFile(("debug_producer_" + (label.empty() ? "test" : label) + ".root").c_str(), "recreate");
99  }
100 
101  sectorConfig45.name_ = "sector 45";
102 
105 
106  sectorConfig56.name_ = "sector 56";
107 
110 
111  for (std::string sectorName : {"sector_45", "sector_56"}) {
112  const auto& sps = iConfig.getParameter<edm::ParameterSet>(sectorName);
114  if (sectorName == "sector_45")
115  sc = &sectorConfig45;
116  else
117  sc = &sectorConfig56;
118 
119  for (std::string rpName : {"rp_N", "rp_F"}) {
120  const auto& rpps = sps.getParameter<edm::ParameterSet>(rpName);
122  if (rpName == "rp_N")
123  rc = &sc->rp_N_;
124  else
125  rc = &sc->rp_F_;
126 
127  rc->name_ = rpps.getParameter<std::string>("name");
128  rc->id_ = rpps.getParameter<int>("id");
129 
130  rc->slope_ = rpps.getParameter<double>("slope");
131  rc->sh_x_ = rpps.getParameter<double>("sh_x");
132 
133  rc->x_min_fit_mode_ = rpps.getParameter<double>("x_min_fit_mode");
134  rc->x_max_fit_mode_ = rpps.getParameter<double>("x_max_fit_mode");
135  rc->y_max_fit_mode_ = rpps.getParameter<double>("y_max_fit_mode");
136  rc->y_cen_add_ = rpps.getParameter<double>("y_cen_add");
137  rc->y_width_mult_ = rpps.getParameter<double>("y_width_mult");
138 
139  rc->x_slice_min_ = rpps.getParameter<double>("x_slice_min");
140  rc->x_slice_w_ = rpps.getParameter<double>("x_slice_w");
141  rc->x_slice_n_ = std::ceil((rpps.getParameter<double>("x_slice_max") - rc->x_slice_min_) / rc->x_slice_w_);
142  }
143 
144  sc->slope_ = sps.getParameter<double>("slope");
145 
146  sc->cut_h_apply_ = sps.getParameter<bool>("cut_h_apply");
147  sc->cut_h_a_ = sps.getParameter<double>("cut_h_a");
148  sc->cut_h_c_ = sps.getParameter<double>("cut_h_c");
149  sc->cut_h_si_ = sps.getParameter<double>("cut_h_si");
150 
151  sc->cut_v_apply_ = sps.getParameter<bool>("cut_v_apply");
152  sc->cut_v_a_ = sps.getParameter<double>("cut_v_a");
153  sc->cut_v_c_ = sps.getParameter<double>("cut_v_c");
154  sc->cut_v_si_ = sps.getParameter<double>("cut_v_si");
155  }
156 
157  std::map<unsigned int, std::string> rpTags = {{sectorConfig45.rp_F_.id_, "rp_L_F"},
158  {sectorConfig45.rp_N_.id_, "rp_L_N"},
159  {sectorConfig56.rp_N_.id_, "rp_R_N"},
160  {sectorConfig56.rp_F_.id_, "rp_R_F"}};
161 
162  std::map<unsigned int, std::string> sectorNames = {{sectorConfig45.rp_F_.id_, sectorConfig45.name_},
166 
167  std::map<unsigned int, const PPSAlignmentConfiguration::RPConfig*> rpConfigs = {
172 
173  x_ali_sh_step = iConfig.getParameter<double>("x_ali_sh_step");
174 
175  y_mode_sys_unc = iConfig.getParameter<double>("y_mode_sys_unc");
176  chiSqThreshold = iConfig.getParameter<double>("chiSqThreshold");
177  y_mode_unc_max_valid = iConfig.getParameter<double>("y_mode_unc_max_valid");
178  y_mode_max_valid = iConfig.getParameter<double>("y_mode_max_valid");
179 
180  minRPTracksSize = iConfig.getParameter<unsigned int>("min_RP_tracks_size");
181  maxRPTracksSize = iConfig.getParameter<unsigned int>("max_RP_tracks_size");
182  n_si = iConfig.getParameter<double>("n_si");
183 
184  const auto& c_axo = iConfig.getParameter<edm::ParameterSet>("x_alignment_meth_o");
185  for (const auto& p : rpTags) {
186  const auto& ps = c_axo.getParameter<edm::ParameterSet>(p.second);
187  alignment_x_meth_o_ranges[p.first] = {ps.getParameter<double>("x_min"), ps.getParameter<double>("x_max")};
188  }
189  fitProfileMinBinEntries = c_axo.getParameter<unsigned int>("fit_profile_min_bin_entries");
190  fitProfileMinNReasonable = c_axo.getParameter<unsigned int>("fit_profile_min_N_reasonable");
191  methOGraphMinN = c_axo.getParameter<unsigned int>("meth_o_graph_min_N");
192  methOUncFitRange = c_axo.getParameter<double>("meth_o_unc_fit_range");
193 
194  const auto& c_m = iConfig.getParameter<edm::ParameterSet>("matching");
195  const auto& referenceDataset = c_m.getParameter<std::string>("reference_dataset");
196 
197  // constructing vectors with reference data
198  if (!referenceDataset.empty()) {
199  TFile* f_ref = TFile::Open(referenceDataset.c_str());
200  if (!f_ref->IsOpen()) {
201  edm::LogWarning("PPS") << "[ESSource] could not find reference dataset file: " << referenceDataset;
202  } else {
203  TDirectory* ad_ref = findDirectoryWithName((TDirectory*)f_ref, sectorConfig45.name_);
204  if (ad_ref == nullptr) {
205  edm::LogWarning("PPS") << "[ESSource] could not find reference dataset in " << referenceDataset;
206  } else {
207  edm::LogInfo("PPS") << "[ESSource] loading reference dataset from " << ad_ref->GetPath();
208 
209  for (const auto& p : rpTags) {
210  if (debug)
211  gDirectory = debugFile->mkdir(rpConfigs[p.first]->name_.c_str())->mkdir("fits_ref");
212 
213  auto* d_ref = (TDirectory*)ad_ref->Get(
214  (sectorNames[p.first] + "/near_far/x slices, " + rpConfigs[p.first]->position_).c_str());
215  if (d_ref == nullptr) {
216  edm::LogWarning("PPS") << "[ESSource] could not load d_ref";
217  } else {
218  matchingReferencePoints[p.first] = buildVectorFromDirectory(d_ref, *rpConfigs[p.first]);
219  }
220  }
221  }
222  }
223  delete f_ref;
224  }
225 
226  for (const auto& p : rpTags) {
227  const auto& ps = c_m.getParameter<edm::ParameterSet>(p.second);
228  matchingShiftRanges[p.first] = {ps.getParameter<double>("sh_min"), ps.getParameter<double>("sh_max")};
229  }
230 
231  const auto& c_axr = iConfig.getParameter<edm::ParameterSet>("x_alignment_relative");
232  for (const auto& p : rpTags) {
233  if (p.second.back() == 'N') { // only near RPs
234  const auto& ps = c_axr.getParameter<edm::ParameterSet>(p.second);
235  alignment_x_relative_ranges[p.first] = {ps.getParameter<double>("x_min"), ps.getParameter<double>("x_max")};
236  }
237  }
238  nearFarMinEntries = c_axr.getParameter<unsigned int>("near_far_min_entries");
239 
240  const auto& c_ay = iConfig.getParameter<edm::ParameterSet>("y_alignment");
241  for (const auto& p : rpTags) {
242  const auto& ps = c_ay.getParameter<edm::ParameterSet>(p.second);
243  alignment_y_ranges[p.first] = {ps.getParameter<double>("x_min"), ps.getParameter<double>("x_max")};
244  }
245  modeGraphMinN = c_ay.getParameter<unsigned int>("mode_graph_min_N");
246  multSelProjYMinEntries = c_ay.getParameter<unsigned int>("mult_sel_proj_y_min_entries");
247 
248  const auto& bps = iConfig.getParameter<edm::ParameterSet>("binning");
249  binning.bin_size_x_ = bps.getParameter<double>("bin_size_x");
250  binning.n_bins_x_ = bps.getParameter<unsigned int>("n_bins_x");
251  binning.pixel_x_offset_ = bps.getParameter<double>("pixel_x_offset");
252  binning.n_bins_y_ = bps.getParameter<unsigned int>("n_bins_y");
253  binning.y_min_ = bps.getParameter<double>("y_min");
254  binning.y_max_ = bps.getParameter<double>("y_max");
255 
256  binning.diffFN_n_bins_x_ = bps.getParameter<unsigned int>("diffFN_n_bins_x");
257  binning.diffFN_x_min_ = bps.getParameter<double>("diffFN_x_min");
258  binning.diffFN_x_max_ = bps.getParameter<double>("diffFN_x_max");
259 
260  binning.slice_n_bins_x_ = bps.getParameter<unsigned int>("slice_n_bins_x");
261  binning.slice_x_min_ = bps.getParameter<double>("slice_x_min");
262  binning.slice_x_max_ = bps.getParameter<double>("slice_x_max");
263  binning.slice_n_bins_y_ = bps.getParameter<unsigned int>("slice_n_bins_y");
264  binning.slice_y_min_ = bps.getParameter<double>("slice_y_min");
265  binning.slice_y_max_ = bps.getParameter<double>("slice_y_max");
266 
267  extraParams = iConfig.getParameter<std::vector<double>>("extra_params");
268 
269  setWhatProduced(this, label);
270  findingRecord<PPSAlignmentConfigurationRcd>();
271 
272  if (debug)
273  delete debugFile;
274 }
275 
276 //---------------------------------------------------------------------------------------------
277 
278 std::unique_ptr<PPSAlignmentConfiguration> PPSAlignmentConfigurationESSource::produce(
280  auto p = std::make_unique<PPSAlignmentConfiguration>();
281 
282  p->setSectorConfig45(sectorConfig45);
283  p->setSectorConfig56(sectorConfig56);
284 
285  p->setX_ali_sh_step(x_ali_sh_step);
286 
287  p->setY_mode_sys_unc(y_mode_sys_unc);
288  p->setChiSqThreshold(chiSqThreshold);
289  p->setY_mode_unc_max_valid(y_mode_unc_max_valid);
290  p->setY_mode_max_valid(y_mode_max_valid);
291 
292  p->setMinRPTracksSize(minRPTracksSize);
293  p->setMaxRPTracksSize(maxRPTracksSize);
294  p->setN_si(n_si);
295 
296  p->setMatchingReferencePoints(matchingReferencePoints);
297  p->setMatchingShiftRanges(matchingShiftRanges);
298 
299  p->setAlignment_x_meth_o_ranges(alignment_x_meth_o_ranges);
300  p->setFitProfileMinBinEntries(fitProfileMinBinEntries);
301  p->setFitProfileMinNReasonable(fitProfileMinNReasonable);
302  p->setMethOGraphMinN(methOGraphMinN);
303  p->setMethOUncFitRange(methOUncFitRange);
304 
305  p->setAlignment_x_relative_ranges(alignment_x_relative_ranges);
306  p->setNearFarMinEntries(nearFarMinEntries);
307 
308  p->setAlignment_y_ranges(alignment_y_ranges);
309  p->setModeGraphMinN(modeGraphMinN);
310  p->setMultSelProjYMinEntries(multSelProjYMinEntries);
311 
312  p->setBinning(binning);
313 
314  p->setExtraParams(extraParams);
315 
316  edm::LogInfo("PPS") << "\n"
317  << "[ESSource] " << (label.empty() ? "empty label" : "label = " + label) << ":\n\n"
318  << (*p);
319 
320  return p;
321 }
322 
323 //---------------------------------------------------------------------------------------------
324 
325 // most default values come from 2018 period
328 
329  desc.add<bool>("debug", false);
330 
331  desc.add<std::string>("label", "");
332 
333  // sector_45
334  {
336 
338  rp_N.add<std::string>("name", "L_1_F");
339  rp_N.add<int>("id", 3);
340 
341  rp_N.add<double>("slope", 0.19);
342  rp_N.add<double>("sh_x", -3.6);
343 
344  rp_N.add<double>("x_min_fit_mode", 2.);
345  rp_N.add<double>("x_max_fit_mode", 7.0);
346  rp_N.add<double>("y_max_fit_mode", 7.0);
347  rp_N.add<double>("y_cen_add", -0.3);
348  rp_N.add<double>("y_width_mult", 1.1);
349 
350  rp_N.add<double>("x_slice_min", 7.);
351  rp_N.add<double>("x_slice_max", 19.);
352  rp_N.add<double>("x_slice_w", 0.2);
353  sector45.add<edm::ParameterSetDescription>("rp_N", rp_N);
354 
356  rp_F.add<std::string>("name", "L_2_F");
357  rp_F.add<int>("id", 23);
358 
359  rp_F.add<double>("slope", 0.19);
360  rp_F.add<double>("sh_x", -42.);
361 
362  rp_F.add<double>("x_min_fit_mode", 2.);
363  rp_F.add<double>("x_max_fit_mode", 7.5);
364  rp_F.add<double>("y_max_fit_mode", 7.5);
365  rp_F.add<double>("y_cen_add", -0.3);
366  rp_F.add<double>("y_width_mult", 1.1);
367 
368  rp_F.add<double>("x_slice_min", 46.);
369  rp_F.add<double>("x_slice_max", 58.);
370  rp_F.add<double>("x_slice_w", 0.2);
371  sector45.add<edm::ParameterSetDescription>("rp_F", rp_F);
372 
373  sector45.add<double>("slope", 0.006);
374  sector45.add<bool>("cut_h_apply", true);
375  sector45.add<double>("cut_h_a", -1.);
376  sector45.add<double>("cut_h_c", -38.55);
377  sector45.add<double>("cut_h_si", 0.2);
378  sector45.add<bool>("cut_v_apply", true);
379  sector45.add<double>("cut_v_a", -1.07);
380  sector45.add<double>("cut_v_c", 1.63);
381  sector45.add<double>("cut_v_si", 0.15);
382 
383  desc.add<edm::ParameterSetDescription>("sector_45", sector45);
384  }
385 
386  // sector_56
387  {
389 
391  rp_N.add<std::string>("name", "R_1_F");
392  rp_N.add<int>("id", 103);
393 
394  rp_N.add<double>("slope", 0.40);
395  rp_N.add<double>("sh_x", -2.8);
396 
397  rp_N.add<double>("x_min_fit_mode", 2.);
398  rp_N.add<double>("x_max_fit_mode", 7.4);
399  rp_N.add<double>("y_max_fit_mode", 7.4);
400  rp_N.add<double>("y_cen_add", -0.8);
401  rp_N.add<double>("y_width_mult", 1.0);
402 
403  rp_N.add<double>("x_slice_min", 6.);
404  rp_N.add<double>("x_slice_max", 17.);
405  rp_N.add<double>("x_slice_w", 0.2);
406  sector56.add<edm::ParameterSetDescription>("rp_N", rp_N);
407 
409  rp_F.add<std::string>("name", "R_2_F");
410  rp_F.add<int>("id", 123);
411 
412  rp_F.add<double>("slope", 0.39);
413  rp_F.add<double>("sh_x", -41.9);
414 
415  rp_F.add<double>("x_min_fit_mode", 2.);
416  rp_F.add<double>("x_max_fit_mode", 8.0);
417  rp_F.add<double>("y_max_fit_mode", 8.0);
418  rp_F.add<double>("y_cen_add", -0.8);
419  rp_F.add<double>("y_width_mult", 1.0);
420 
421  rp_F.add<double>("x_slice_min", 45.);
422  rp_F.add<double>("x_slice_max", 57.);
423  rp_F.add<double>("x_slice_w", 0.2);
424  sector56.add<edm::ParameterSetDescription>("rp_F", rp_F);
425 
426  sector56.add<double>("slope", -0.015);
427  sector56.add<bool>("cut_h_apply", true);
428  sector56.add<double>("cut_h_a", -1.);
429  sector56.add<double>("cut_h_c", -39.26);
430  sector56.add<double>("cut_h_si", 0.2);
431  sector56.add<bool>("cut_v_apply", true);
432  sector56.add<double>("cut_v_a", -1.07);
433  sector56.add<double>("cut_v_c", 1.49);
434  sector56.add<double>("cut_v_si", 0.15);
435 
436  desc.add<edm::ParameterSetDescription>("sector_56", sector56);
437  }
438 
439  desc.add<double>("x_ali_sh_step", 0.01);
440 
441  desc.add<double>("y_mode_sys_unc", 0.03);
442  desc.add<double>("chiSqThreshold", 50.);
443  desc.add<double>("y_mode_unc_max_valid", 5.);
444  desc.add<double>("y_mode_max_valid", 20.);
445 
446  desc.add<unsigned int>("min_RP_tracks_size", 1);
447  desc.add<unsigned int>("max_RP_tracks_size", 1);
448  desc.add<double>("n_si", 4.);
449 
450  // matching
451  {
453  matching.add<std::string>("reference_dataset", "");
454 
456  rpLF.add<double>("sh_min", -43.);
457  rpLF.add<double>("sh_max", -41.);
458  matching.add<edm::ParameterSetDescription>("rp_L_F", rpLF);
459 
461  rpLN.add<double>("sh_min", -4.2);
462  rpLN.add<double>("sh_max", -2.4);
463  matching.add<edm::ParameterSetDescription>("rp_L_N", rpLN);
464 
466  rpRN.add<double>("sh_min", -3.6);
467  rpRN.add<double>("sh_max", -1.8);
468  matching.add<edm::ParameterSetDescription>("rp_R_N", rpRN);
469 
471  rpRF.add<double>("sh_min", -43.2);
472  rpRF.add<double>("sh_max", -41.2);
473  matching.add<edm::ParameterSetDescription>("rp_R_F", rpRF);
474 
475  desc.add<edm::ParameterSetDescription>("matching", matching);
476  }
477 
478  // x alignment meth o
479  {
480  edm::ParameterSetDescription x_alignment_meth_o;
481 
483  rpLF.add<double>("x_min", 47.);
484  rpLF.add<double>("x_max", 56.5);
485  x_alignment_meth_o.add<edm::ParameterSetDescription>("rp_L_F", rpLF);
486 
488  rpLN.add<double>("x_min", 9.);
489  rpLN.add<double>("x_max", 18.5);
490  x_alignment_meth_o.add<edm::ParameterSetDescription>("rp_L_N", rpLN);
491 
493  rpRN.add<double>("x_min", 7.);
494  rpRN.add<double>("x_max", 15.);
495  x_alignment_meth_o.add<edm::ParameterSetDescription>("rp_R_N", rpRN);
496 
498  rpRF.add<double>("x_min", 46.);
499  rpRF.add<double>("x_max", 54.);
500  x_alignment_meth_o.add<edm::ParameterSetDescription>("rp_R_F", rpRF);
501 
502  x_alignment_meth_o.add<unsigned int>("fit_profile_min_bin_entries", 5);
503  x_alignment_meth_o.add<unsigned int>("fit_profile_min_N_reasonable", 10);
504  x_alignment_meth_o.add<unsigned int>("meth_o_graph_min_N", 5);
505  x_alignment_meth_o.add<double>("meth_o_unc_fit_range", 0.5);
506 
507  desc.add<edm::ParameterSetDescription>("x_alignment_meth_o", x_alignment_meth_o);
508  }
509 
510  // x alignment relative
511  {
512  edm::ParameterSetDescription x_alignment_relative;
513 
515  rpLN.add<double>("x_min", 7.5);
516  rpLN.add<double>("x_max", 12.);
517  x_alignment_relative.add<edm::ParameterSetDescription>("rp_L_N", rpLN);
518 
520  rpRN.add<double>("x_min", 6.);
521  rpRN.add<double>("x_max", 10.);
522  x_alignment_relative.add<edm::ParameterSetDescription>("rp_R_N", rpRN);
523 
524  x_alignment_relative.add<unsigned int>("near_far_min_entries", 100);
525 
526  desc.add<edm::ParameterSetDescription>("x_alignment_relative", x_alignment_relative);
527  }
528 
529  // y alignment
530  {
531  edm::ParameterSetDescription y_alignment;
532 
534  rpLF.add<double>("x_min", 44.5);
535  rpLF.add<double>("x_max", 49.);
536  y_alignment.add<edm::ParameterSetDescription>("rp_L_F", rpLF);
537 
539  rpLN.add<double>("x_min", 6.7);
540  rpLN.add<double>("x_max", 11.);
541  y_alignment.add<edm::ParameterSetDescription>("rp_L_N", rpLN);
542 
544  rpRN.add<double>("x_min", 5.9);
545  rpRN.add<double>("x_max", 10.);
546  y_alignment.add<edm::ParameterSetDescription>("rp_R_N", rpRN);
547 
549  rpRF.add<double>("x_min", 44.5);
550  rpRF.add<double>("x_max", 49.);
551  y_alignment.add<edm::ParameterSetDescription>("rp_R_F", rpRF);
552 
553  y_alignment.add<unsigned int>("mode_graph_min_N", 5);
554  y_alignment.add<unsigned int>("mult_sel_proj_y_min_entries", 300);
555 
556  desc.add<edm::ParameterSetDescription>("y_alignment", y_alignment);
557  }
558 
559  // binning
560  {
562 
563  binning.add<double>("bin_size_x", 142.3314E-3);
564  binning.add<unsigned int>("n_bins_x", 210);
565  binning.add<double>("pixel_x_offset", 40.);
566  binning.add<unsigned int>("n_bins_y", 400);
567  binning.add<double>("y_min", -20.);
568  binning.add<double>("y_max", 20.);
569 
570  binning.add<unsigned int>("diffFN_n_bins_x", 100);
571  binning.add<double>("diffFN_x_min", 0.);
572  binning.add<double>("diffFN_x_max", 20.);
573 
574  binning.add<unsigned int>("slice_n_bins_x", 100);
575  binning.add<double>("slice_x_min", -10.);
576  binning.add<double>("slice_x_max", 10.);
577  binning.add<unsigned int>("slice_n_bins_y", 100);
578  binning.add<double>("slice_y_min", -2.);
579  binning.add<double>("slice_y_max", 2.);
580 
581  desc.add<edm::ParameterSetDescription>("binning", binning);
582  }
583 
584  desc.add<std::vector<double>>("extra_params", {});
585 
586  descriptions.add("ppsAlignmentConfigurationESSource", desc);
587 }
588 
589 //---------------------------------------------------------------------------------------------
590 
591 // Fits a linear function to a TProfile (similar method in PPSAlignmentHarvester).
592 int PPSAlignmentConfigurationESSource::fitProfile(TProfile* p, double x_mean, double x_rms, double& sl, double& sl_unc) {
593  unsigned int n_reasonable = 0;
594  for (int bi = 1; bi <= p->GetNbinsX(); bi++) {
595  if (p->GetBinEntries(bi) < fitProfileMinBinEntries) {
596  p->SetBinContent(bi, 0.);
597  p->SetBinError(bi, 0.);
598  } else {
599  n_reasonable++;
600  }
601  }
602 
603  if (n_reasonable < fitProfileMinNReasonable)
604  return 1;
605 
606  double x_min = x_mean - x_rms, x_max = x_mean + x_rms;
607 
608  TF1* ff_pol1 = new TF1("ff_pol1", "[0] + [1]*x");
609 
610  ff_pol1->SetParameter(0., 0.);
611  p->Fit(ff_pol1, "Q", "", x_min, x_max);
612 
613  sl = ff_pol1->GetParameter(1);
614  sl_unc = ff_pol1->GetParError(1);
615 
616  return 0;
617 }
618 
619 //---------------------------------------------------------------------------------------------
620 
621 // Performs a breadth first search on dir. If found, returns the directory with object
622 // named searchName inside. Otherwise, returns nullptr.
624  TIter next(dir->GetListOfKeys());
625  std::queue<TDirectory*> dirQueue;
626  TObject* o;
627  while ((o = next())) {
628  TKey* k = (TKey*)o;
629 
630  std::string name = k->GetName();
631  if (name == searchName)
632  return dir;
633 
634  if (((TSystemFile*)k)->IsDirectory())
635  dirQueue.push((TDirectory*)k->ReadObj());
636  }
637 
638  while (!dirQueue.empty()) {
639  TDirectory* resultDir = findDirectoryWithName(dirQueue.front(), searchName);
640  dirQueue.pop();
641  if (resultDir != nullptr)
642  return resultDir;
643  }
644 
645  return nullptr;
646 }
647 
648 //---------------------------------------------------------------------------------------------
649 
650 // Builds vector of PointErrors instances from slice plots in dir.
651 std::vector<PPSAlignmentConfiguration::PointErrors> PPSAlignmentConfigurationESSource::buildVectorFromDirectory(
652  TDirectory* dir, const PPSAlignmentConfiguration::RPConfig& rpd) {
653  std::vector<PPSAlignmentConfiguration::PointErrors> pv;
654 
655  TIter next(dir->GetListOfKeys());
656  TObject* o;
657  while ((o = next())) {
658  TKey* k = (TKey*)o;
659 
660  std::string name = k->GetName();
661  size_t d = name.find('-');
662  const double x_min = std::stod(name.substr(0, d));
663  const double x_max = std::stod(name.substr(d + 1));
664 
665  TDirectory* d_slice = (TDirectory*)k->ReadObj();
666 
667  TH1D* h_y = (TH1D*)d_slice->Get("h_y");
668  TProfile* p_y_diffFN_vs_y = (TProfile*)d_slice->Get("p_y_diffFN_vs_y");
669 
670  double y_cen = h_y->GetMean();
671  double y_width = h_y->GetRMS();
672 
673  y_cen += rpd.y_cen_add_;
674  y_width *= rpd.y_width_mult_;
675 
676  double sl = 0., sl_unc = 0.;
677  int fr = fitProfile(p_y_diffFN_vs_y, y_cen, y_width, sl, sl_unc);
678  if (fr != 0)
679  continue;
680 
681  if (debug)
682  p_y_diffFN_vs_y->Write(name.c_str());
683 
684  pv.push_back({(x_max + x_min) / 2., sl, (x_max - x_min) / 2., sl_unc});
685  }
686 
687  return pv;
688 }
689 
690 //---------------------------------------------------------------------------------------------
691 
693  const edm::IOVSyncValue& iosv,
694  edm::ValidityInterval& oValidity) {
695  edm::LogInfo("PPS") << ">> PPSAlignmentConfigurationESSource::setIntervalFor(" << key.name() << ")\n"
696  << " run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();
697 
699  oValidity = infinity;
700 }
701 
RunNumber_t run() const
Definition: EventID.h:38
constexpr int32_t ceil(float num)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
EventNumber_t event() const
Definition: EventID.h:40
bool empty() const
Definition: ParameterSet.h:201
PPSAlignmentConfiguration::SectorConfig sectorConfig56
const EventID & eventID() const
Definition: IOVSyncValue.h:40
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, const edm::IOVSyncValue &iosv, edm::ValidityInterval &oValidity) override
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
std::map< unsigned int, PPSAlignmentConfiguration::SelectionRange > alignment_y_ranges
std::map< unsigned int, PPSAlignmentConfiguration::SelectionRange > alignment_x_relative_ranges
PPSAlignmentConfiguration::SectorConfig sectorConfig45
tuple d
Definition: ztail.py:151
std::map< unsigned int, PPSAlignmentConfiguration::SelectionRange > matchingShiftRanges
std::map< unsigned int, std::vector< PPSAlignmentConfiguration::PointErrors > > matchingReferencePoints
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
PPSAlignmentConfigurationESSource(const edm::ParameterSet &iConfig)
tuple key
prepare the HTCondor submission files and eventually submit them
const double infinity
TDirectory * findDirectoryWithName(TDirectory *dir, std::string searchName)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
def mkdir
Definition: eostools.py:251
PPSAlignmentConfiguration::Binning binning
int fitProfile(TProfile *p, double x_mean, double x_rms, double &sl, double &sl_unc)
std::map< unsigned int, PPSAlignmentConfiguration::SelectionRange > alignment_x_meth_o_ranges
std::vector< PPSAlignmentConfiguration::PointErrors > buildVectorFromDirectory(TDirectory *dir, const PPSAlignmentConfiguration::RPConfig &rpd)
Log< level::Warning, false > LogWarning
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::unique_ptr< PPSAlignmentConfiguration > produce(const PPSAlignmentConfigurationRcd &)