33 #include "TSystemFile.h"
97 std::unique_ptr<TFile> debugFile;
100 std::make_unique<TFile>((
"debug_producer_" + (
label.empty() ?
"test" :
label) +
".root").c_str(),
"recreate");
113 for (
std::string sectorName : {
"sector_45",
"sector_56"}) {
116 if (sectorName ==
"sector_45")
124 if (rpName ==
"rp_N")
130 rc->id_ = rpps.getParameter<
int>(
"id");
132 rc->slope_ = rpps.getParameter<
double>(
"slope");
133 rc->sh_x_ = rpps.getParameter<
double>(
"sh_x");
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");
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_);
146 sc->slope_ = sps.getParameter<
double>(
"slope");
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");
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");
169 std::map<unsigned int, const PPSAlignmentConfiguration::RPConfig*> rpConfigs = {
187 for (
const auto&
p : rpTags) {
193 methOGraphMinN = c_axo.getParameter<
unsigned int>(
"meth_o_graph_min_N");
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;
206 if (ad_ref ==
nullptr) {
207 edm::LogWarning(
"PPS") <<
"[ESSource] could not find reference dataset in " << referenceDataset;
209 edm::LogInfo(
"PPS") <<
"[ESSource] loading reference dataset from " << ad_ref->GetPath();
211 for (
const auto&
p : rpTags) {
213 gDirectory = debugFile->mkdir(rpConfigs[
p.first]->name_.c_str())->
mkdir(
"fits_ref");
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) {
227 for (
const auto&
p : rpTags) {
229 matchingShiftRanges[
p.first] = {ps.getParameter<
double>(
"sh_min"), ps.getParameter<
double>(
"sh_max")};
233 for (
const auto&
p : rpTags) {
234 if (
p.second.back() ==
'N') {
242 for (
const auto&
p : rpTags) {
244 alignment_y_ranges[
p.first] = {ps.getParameter<
double>(
"x_min"), ps.getParameter<
double>(
"x_max")};
246 modeGraphMinN = c_ay.getParameter<
unsigned int>(
"mode_graph_min_N");
271 findingRecord<PPSAlignmentConfigurationRcd>();
278 auto p = std::make_unique<PPSAlignmentConfiguration>();
315 <<
"[ESSource] " << (
label.empty() ?
"empty label" :
"label = " +
label) <<
":\n\n"
327 desc.
add<
bool>(
"debug",
false);
337 rp_N.
add<
int>(
"id", 3);
339 rp_N.
add<
double>(
"slope", 0.19);
340 rp_N.
add<
double>(
"sh_x", -3.6);
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);
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);
355 rp_F.add<
int>(
"id", 23);
357 rp_F.add<
double>(
"slope", 0.19);
358 rp_F.add<
double>(
"sh_x", -42.);
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);
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);
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);
390 rp_N.
add<
int>(
"id", 103);
392 rp_N.
add<
double>(
"slope", 0.40);
393 rp_N.
add<
double>(
"sh_x", -2.8);
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);
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);
408 rp_F.add<
int>(
"id", 123);
410 rp_F.add<
double>(
"slope", 0.39);
411 rp_F.add<
double>(
"sh_x", -41.9);
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);
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);
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);
437 desc.
add<
double>(
"x_ali_sh_step", 0.01);
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.);
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.);
454 rpLF.
add<
double>(
"sh_min", -43.);
455 rpLF.add<
double>(
"sh_max", -41.);
459 rpLN.
add<
double>(
"sh_min", -4.2);
460 rpLN.add<
double>(
"sh_max", -2.4);
464 rpRN.
add<
double>(
"sh_min", -3.6);
465 rpRN.add<
double>(
"sh_max", -1.8);
469 rpRF.
add<
double>(
"sh_min", -43.2);
470 rpRF.add<
double>(
"sh_max", -41.2);
481 rpLF.
add<
double>(
"x_min", 47.);
482 rpLF.
add<
double>(
"x_max", 56.5);
486 rpLN.
add<
double>(
"x_min", 9.);
487 rpLN.add<
double>(
"x_max", 18.5);
491 rpRN.
add<
double>(
"x_min", 7.);
492 rpRN.add<
double>(
"x_max", 15.);
496 rpRF.
add<
double>(
"x_min", 46.);
497 rpRF.add<
double>(
"x_max", 54.);
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);
513 rpLN.
add<
double>(
"x_min", 7.5);
514 rpLN.
add<
double>(
"x_max", 12.);
518 rpRN.
add<
double>(
"x_min", 6.);
519 rpRN.add<
double>(
"x_max", 10.);
522 x_alignment_relative.
add<
unsigned int>(
"near_far_min_entries", 100);
532 rpLF.
add<
double>(
"x_min", 44.5);
533 rpLF.
add<
double>(
"x_max", 49.);
537 rpLN.
add<
double>(
"x_min", 6.7);
538 rpLN.add<
double>(
"x_max", 11.);
542 rpRN.
add<
double>(
"x_min", 5.9);
543 rpRN.add<
double>(
"x_max", 10.);
547 rpRF.
add<
double>(
"x_min", 44.5);
548 rpRF.add<
double>(
"x_max", 49.);
551 y_alignment.
add<
unsigned int>(
"mode_graph_min_N", 5);
552 y_alignment.
add<
unsigned int>(
"mult_sel_proj_y_min_entries", 300);
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.);
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.);
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.);
582 desc.
add<std::vector<double>>(
"extra_params", {});
584 descriptions.
add(
"ppsAlignmentConfigurationESSource", desc);
592 TIter
next(dir->GetListOfKeys());
593 std::queue<TDirectory*> dirQueue;
595 while ((o =
next())) {
599 if (name == searchName)
602 if (((TSystemFile*)k)->IsDirectory())
603 dirQueue.push((TDirectory*)k->ReadObj());
606 while (!dirQueue.empty()) {
609 if (resultDir !=
nullptr)
621 std::vector<PPSAlignmentConfiguration::PointErrors>
pv;
623 TIter
next(dir->GetListOfKeys());
625 while ((o =
next())) {
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));
633 TDirectory* d_slice = (TDirectory*)k->ReadObj();
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");
638 double y_cen = h_y->GetMean();
639 double y_width = h_y->GetRMS();
644 double sl = 0., sl_unc = 0.;
651 p_y_diffFN_vs_y->Write(name.c_str());
653 pv.push_back({(x_max + x_min) / 2., sl, (x_max - x_min) / 2., sl_unc});
664 edm::LogInfo(
"PPS") <<
">> PPSAlignmentConfigurationESSource::setIntervalFor(" << key.
name() <<
")\n"
constexpr int32_t ceil(float num)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
EventNumber_t event() const
int fitProfile(TProfile *p, double x_mean, double x_rms, unsigned int minBinEntries, unsigned int minNBinsReasonable, double &sl, double &sl_unc)
unsigned int slice_n_bins_y_
PPSAlignmentConfiguration::SectorConfig sectorConfig56
const EventID & eventID() const
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, const edm::IOVSyncValue &iosv, edm::ValidityInterval &oValidity) override
static const IOVSyncValue & endOfTime()
unsigned int minRPTracksSize
unsigned int fitProfileMinBinEntries
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
unsigned int maxRPTracksSize
static const IOVSyncValue & beginOfTime()
PPSAlignmentConfigurationESSource(const edm::ParameterSet &iConfig)
double y_mode_unc_max_valid
unsigned int nearFarMinEntries
const char * name() const
tuple key
prepare the HTCondor submission files and eventually submit them
TDirectory * findDirectoryWithName(TDirectory *dir, std::string searchName)
unsigned int modeGraphMinN
ParameterDescriptionBase * add(U const &iLabel, T const &value)
unsigned int slice_n_bins_x_
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
unsigned int fitProfileMinNReasonable
std::vector< double > extraParams
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
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
unsigned int methOGraphMinN
unsigned int diffFN_n_bins_x_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::unique_ptr< PPSAlignmentConfiguration > produce(const PPSAlignmentConfigurationRcd &)
unsigned int multSelProjYMinEntries