31 #include "TSystemFile.h"
43 int fitProfile(TProfile*
p,
double x_mean,
double x_rms,
double& sl,
double& sl_unc);
96 TFile* debugFile =
nullptr;
98 debugFile =
new TFile((
"debug_producer_" + (
label.empty() ?
"test" :
label) +
".root").c_str(),
"recreate");
111 for (
std::string sectorName : {
"sector_45",
"sector_56"}) {
114 if (sectorName ==
"sector_45")
122 if (rpName ==
"rp_N")
128 rc->id_ = rpps.getParameter<
int>(
"id");
130 rc->slope_ = rpps.getParameter<
double>(
"slope");
131 rc->sh_x_ = rpps.getParameter<
double>(
"sh_x");
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");
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_);
144 sc->slope_ = sps.getParameter<
double>(
"slope");
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");
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");
167 std::map<unsigned int, const PPSAlignmentConfiguration::RPConfig*> rpConfigs = {
185 for (
const auto&
p : rpTags) {
191 methOGraphMinN = c_axo.getParameter<
unsigned int>(
"meth_o_graph_min_N");
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;
204 if (ad_ref ==
nullptr) {
205 edm::LogWarning(
"PPS") <<
"[ESSource] could not find reference dataset in " << referenceDataset;
207 edm::LogInfo(
"PPS") <<
"[ESSource] loading reference dataset from " << ad_ref->GetPath();
209 for (
const auto&
p : rpTags) {
211 gDirectory = debugFile->mkdir(rpConfigs[
p.first]->name_.c_str())->
mkdir(
"fits_ref");
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) {
226 for (
const auto&
p : rpTags) {
228 matchingShiftRanges[
p.first] = {ps.getParameter<
double>(
"sh_min"), ps.getParameter<
double>(
"sh_max")};
232 for (
const auto&
p : rpTags) {
233 if (
p.second.back() ==
'N') {
241 for (
const auto&
p : rpTags) {
243 alignment_y_ranges[
p.first] = {ps.getParameter<
double>(
"x_min"), ps.getParameter<
double>(
"x_max")};
245 modeGraphMinN = c_ay.getParameter<
unsigned int>(
"mode_graph_min_N");
270 findingRecord<PPSAlignmentConfigurationRcd>();
280 auto p = std::make_unique<PPSAlignmentConfiguration>();
317 <<
"[ESSource] " << (
label.empty() ?
"empty label" :
"label = " +
label) <<
":\n\n"
329 desc.
add<
bool>(
"debug",
false);
339 rp_N.
add<
int>(
"id", 3);
341 rp_N.
add<
double>(
"slope", 0.19);
342 rp_N.
add<
double>(
"sh_x", -3.6);
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);
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);
357 rp_F.add<
int>(
"id", 23);
359 rp_F.add<
double>(
"slope", 0.19);
360 rp_F.add<
double>(
"sh_x", -42.);
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);
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);
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);
392 rp_N.
add<
int>(
"id", 103);
394 rp_N.
add<
double>(
"slope", 0.40);
395 rp_N.
add<
double>(
"sh_x", -2.8);
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);
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);
410 rp_F.add<
int>(
"id", 123);
412 rp_F.add<
double>(
"slope", 0.39);
413 rp_F.add<
double>(
"sh_x", -41.9);
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);
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);
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);
439 desc.
add<
double>(
"x_ali_sh_step", 0.01);
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.);
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.);
456 rpLF.
add<
double>(
"sh_min", -43.);
457 rpLF.add<
double>(
"sh_max", -41.);
461 rpLN.
add<
double>(
"sh_min", -4.2);
462 rpLN.add<
double>(
"sh_max", -2.4);
466 rpRN.
add<
double>(
"sh_min", -3.6);
467 rpRN.add<
double>(
"sh_max", -1.8);
471 rpRF.
add<
double>(
"sh_min", -43.2);
472 rpRF.add<
double>(
"sh_max", -41.2);
483 rpLF.
add<
double>(
"x_min", 47.);
484 rpLF.
add<
double>(
"x_max", 56.5);
488 rpLN.
add<
double>(
"x_min", 9.);
489 rpLN.add<
double>(
"x_max", 18.5);
493 rpRN.
add<
double>(
"x_min", 7.);
494 rpRN.add<
double>(
"x_max", 15.);
498 rpRF.
add<
double>(
"x_min", 46.);
499 rpRF.add<
double>(
"x_max", 54.);
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);
515 rpLN.
add<
double>(
"x_min", 7.5);
516 rpLN.
add<
double>(
"x_max", 12.);
520 rpRN.
add<
double>(
"x_min", 6.);
521 rpRN.add<
double>(
"x_max", 10.);
524 x_alignment_relative.
add<
unsigned int>(
"near_far_min_entries", 100);
534 rpLF.
add<
double>(
"x_min", 44.5);
535 rpLF.
add<
double>(
"x_max", 49.);
539 rpLN.
add<
double>(
"x_min", 6.7);
540 rpLN.add<
double>(
"x_max", 11.);
544 rpRN.
add<
double>(
"x_min", 5.9);
545 rpRN.add<
double>(
"x_max", 10.);
549 rpRF.
add<
double>(
"x_min", 44.5);
550 rpRF.add<
double>(
"x_max", 49.);
553 y_alignment.
add<
unsigned int>(
"mode_graph_min_N", 5);
554 y_alignment.
add<
unsigned int>(
"mult_sel_proj_y_min_entries", 300);
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.);
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.);
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.);
584 desc.
add<std::vector<double>>(
"extra_params", {});
586 descriptions.
add(
"ppsAlignmentConfigurationESSource", desc);
593 unsigned int n_reasonable = 0;
594 for (
int bi = 1; bi <= p->GetNbinsX(); bi++) {
596 p->SetBinContent(bi, 0.);
597 p->SetBinError(bi, 0.);
606 double x_min = x_mean - x_rms, x_max = x_mean + x_rms;
608 TF1* ff_pol1 =
new TF1(
"ff_pol1",
"[0] + [1]*x");
610 ff_pol1->SetParameter(0., 0.);
611 p->Fit(ff_pol1,
"Q",
"", x_min, x_max);
613 sl = ff_pol1->GetParameter(1);
614 sl_unc = ff_pol1->GetParError(1);
624 TIter
next(dir->GetListOfKeys());
625 std::queue<TDirectory*> dirQueue;
627 while ((o =
next())) {
631 if (name == searchName)
634 if (((TSystemFile*)k)->IsDirectory())
635 dirQueue.push((TDirectory*)k->ReadObj());
638 while (!dirQueue.empty()) {
641 if (resultDir !=
nullptr)
653 std::vector<PPSAlignmentConfiguration::PointErrors>
pv;
655 TIter
next(dir->GetListOfKeys());
657 while ((o =
next())) {
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));
665 TDirectory* d_slice = (TDirectory*)k->ReadObj();
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");
670 double y_cen = h_y->GetMean();
671 double y_width = h_y->GetRMS();
676 double sl = 0., sl_unc = 0.;
677 int fr =
fitProfile(p_y_diffFN_vs_y, y_cen, y_width, sl, sl_unc);
682 p_y_diffFN_vs_y->Write(name.c_str());
684 pv.push_back({(x_max + x_min) / 2., sl, (x_max - x_min) / 2., sl_unc});
695 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
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
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
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