CMS 3D CMS Logo

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