CMS 3D CMS Logo

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