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