34 #include "TSystemFile.h" 98 std::unique_ptr<TFile> debugFile;
101 std::make_unique<TFile>((
"debug_producer_" + (
label.empty() ?
"test" :
label) +
".root").c_str(),
"recreate");
114 for (
std::string sectorName : {
"sector_45",
"sector_56"}) {
117 if (sectorName ==
"sector_45")
125 if (rpName ==
"rp_N")
131 rc->id_ = rpps.getParameter<
int>(
"id");
133 rc->slope_ = rpps.getParameter<
double>(
"slope");
134 rc->sh_x_ = rpps.getParameter<
double>(
"sh_x");
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");
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_);
147 sc->slope_ = sps.getParameter<
double>(
"slope");
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");
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");
170 std::map<unsigned int, const PPSAlignmentConfiguration::RPConfig*> rpConfigs = {
188 for (
const auto&
p : rpTags) {
194 methOGraphMinN = c_axo.getParameter<
unsigned int>(
"meth_o_graph_min_N");
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;
207 if (ad_ref ==
nullptr) {
208 edm::LogWarning(
"PPS") <<
"[ESSource] could not find reference dataset in " << referenceDataset;
210 edm::LogInfo(
"PPS") <<
"[ESSource] loading reference dataset from " << ad_ref->GetPath();
212 for (
const auto&
p : rpTags) {
214 gDirectory = debugFile->mkdir(rpConfigs[
p.first]->name_.c_str())->
mkdir(
"fits_ref");
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) {
228 for (
const auto&
p : rpTags) {
230 matchingShiftRanges[
p.first] = {ps.getParameter<
double>(
"sh_min"), ps.getParameter<
double>(
"sh_max")};
234 for (
const auto&
p : rpTags) {
235 if (
p.second.back() ==
'N') {
243 for (
const auto&
p : rpTags) {
245 alignment_y_ranges[
p.first] = {ps.getParameter<
double>(
"x_min"), ps.getParameter<
double>(
"x_max")};
247 modeGraphMinN = c_ay.getParameter<
unsigned int>(
"mode_graph_min_N");
272 findingRecord<PPSAlignmentConfigurationRcd>();
279 auto p = std::make_unique<PPSAlignmentConfiguration>();
316 <<
"[ESSource] " << (
label.empty() ?
"empty label" :
"label = " +
label) <<
":\n\n" 328 desc.add<
bool>(
"debug",
false);
338 rp_N.
add<
int>(
"id", 3);
340 rp_N.
add<
double>(
"slope", 0.19);
341 rp_N.
add<
double>(
"sh_x", -3.6);
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);
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);
356 rp_F.add<
int>(
"id", 23);
358 rp_F.add<
double>(
"slope", 0.19);
359 rp_F.add<
double>(
"sh_x", -42.);
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);
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);
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);
391 rp_N.
add<
int>(
"id", 103);
393 rp_N.
add<
double>(
"slope", 0.40);
394 rp_N.
add<
double>(
"sh_x", -2.8);
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);
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);
409 rp_F.add<
int>(
"id", 123);
411 rp_F.add<
double>(
"slope", 0.39);
412 rp_F.add<
double>(
"sh_x", -41.9);
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);
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);
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);
438 desc.add<
double>(
"x_ali_sh_step", 0.01);
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.);
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.);
455 rpLF.
add<
double>(
"sh_min", -43.);
456 rpLF.add<
double>(
"sh_max", -41.);
460 rpLN.
add<
double>(
"sh_min", -4.2);
461 rpLN.add<
double>(
"sh_max", -2.4);
465 rpRN.
add<
double>(
"sh_min", -3.6);
466 rpRN.add<
double>(
"sh_max", -1.8);
470 rpRF.
add<
double>(
"sh_min", -43.2);
471 rpRF.add<
double>(
"sh_max", -41.2);
482 rpLF.
add<
double>(
"x_min", 47.);
483 rpLF.
add<
double>(
"x_max", 56.5);
487 rpLN.
add<
double>(
"x_min", 9.);
488 rpLN.add<
double>(
"x_max", 18.5);
492 rpRN.
add<
double>(
"x_min", 7.);
493 rpRN.add<
double>(
"x_max", 15.);
497 rpRF.
add<
double>(
"x_min", 46.);
498 rpRF.add<
double>(
"x_max", 54.);
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);
514 rpLN.
add<
double>(
"x_min", 7.5);
515 rpLN.
add<
double>(
"x_max", 12.);
519 rpRN.
add<
double>(
"x_min", 6.);
520 rpRN.add<
double>(
"x_max", 10.);
523 x_alignment_relative.
add<
unsigned int>(
"near_far_min_entries", 100);
533 rpLF.
add<
double>(
"x_min", 44.5);
534 rpLF.
add<
double>(
"x_max", 49.);
538 rpLN.
add<
double>(
"x_min", 6.7);
539 rpLN.add<
double>(
"x_max", 11.);
543 rpRN.
add<
double>(
"x_min", 5.9);
544 rpRN.add<
double>(
"x_max", 10.);
548 rpRF.
add<
double>(
"x_min", 44.5);
549 rpRF.add<
double>(
"x_max", 49.);
552 y_alignment.
add<
unsigned int>(
"mode_graph_min_N", 5);
553 y_alignment.
add<
unsigned int>(
"mult_sel_proj_y_min_entries", 300);
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.);
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.);
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.);
583 desc.add<std::vector<double>>(
"extra_params", {});
585 descriptions.
add(
"ppsAlignmentConfigurationESSource",
desc);
593 TIter
next(
dir->GetListOfKeys());
594 std::queue<TDirectory*> dirQueue;
596 while ((
o =
next())) {
600 if (
name == searchName)
603 if (((TSystemFile*)
k)->IsDirectory())
604 dirQueue.push((TDirectory*)
k->ReadObj());
607 while (!dirQueue.empty()) {
610 if (resultDir !=
nullptr)
622 std::vector<PPSAlignmentConfiguration::PointErrors>
pv;
624 TIter
next(
dir->GetListOfKeys());
626 while ((
o =
next())) {
630 size_t d =
name.find(
'-');
632 const double x_min = std::stod(
name.substr(0,
d));
633 const double x_max = std::stod(
name.substr(
d + 1));
635 TDirectory* d_slice = (TDirectory*)
k->ReadObj();
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");
640 double y_cen = h_y->GetMean();
641 double y_width = h_y->GetRMS();
646 double sl = 0., sl_unc = 0.;
653 p_y_diffFN_vs_y->Write(
name.c_str());
655 pv.push_back({(x_max + x_min) / 2., sl, (x_max - x_min) / 2., sl_unc});
666 edm::LogInfo(
"PPS") <<
">> PPSAlignmentConfigurationESSource::setIntervalFor(" <<
key.name() <<
")\n" constexpr int32_t ceil(float num)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
int fitProfile(TProfile *p, double x_mean, double x_rms, unsigned int minBinEntries, unsigned int minNBinsReasonable, double &sl, double &sl_unc)
T getParameter(std::string const &) const
unsigned int slice_n_bins_y_
PPSAlignmentConfiguration::SectorConfig sectorConfig56
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, const edm::IOVSyncValue &iosv, edm::ValidityInterval &oValidity) override
static const IOVSyncValue & endOfTime()
unsigned int minRPTracksSize
def replace(string, replacements)
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
TDirectory * findDirectoryWithName(TDirectory *dir, std::string searchName)
key
prepare the HTCondor submission files and eventually submit them
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const EventID & eventID() const
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 &)
EventNumber_t event() const
unsigned int multSelProjYMinEntries