37 #include "TSystemFile.h"
49 int fitProfile(TProfile *
p,
double x_mean,
double x_rms,
double &sl,
double &sl_unc);
101 TFile *debugFile =
nullptr;
103 debugFile =
new TFile((
"debug_producer_" + (
label.empty() ?
"test" :
label) +
".root").c_str(),
"recreate");
119 for (
std::string sectorName : {
"sector_45",
"sector_56"}) {
122 if (sectorName ==
"sector_45")
130 if (rpName ==
"rp_N")
136 rc->id_ = rpps.getParameter<
int>(
"id");
138 rc->slope_ = rpps.getParameter<
double>(
"slope");
139 rc->sh_x_ = rpps.getParameter<
double>(
"sh_x");
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");
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_);
152 sc->slope_ = sps.getParameter<
double>(
"slope");
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");
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");
191 for (
const auto &
p : rpTags) {
197 methOGraphMinN = c_axo.getParameter<
unsigned int>(
"meth_o_graph_min_N");
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;
210 if (ad_ref ==
nullptr) {
211 edm::LogWarning(
"PPS") <<
"[ESSource] could not find reference dataset in " << referenceDataset;
213 edm::LogInfo(
"PPS") <<
"[ESSource] loading reference dataset from " << ad_ref->GetPath();
215 for (
const auto &
p : rpTags) {
217 gDirectory = debugFile->mkdir(rpConfigs[
p.first]->name_.c_str())->
mkdir(
"fits_ref");
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) {
232 for (
const auto &
p : rpTags) {
234 matchingShiftRanges[
p.first] = {ps.getParameter<
double>(
"sh_min"), ps.getParameter<
double>(
"sh_max")};
238 for (
const auto &
p : rpTags) {
245 for (
const auto &
p : rpTags) {
247 alignment_y_ranges[
p.first] = {ps.getParameter<
double>(
"x_min"), ps.getParameter<
double>(
"x_max")};
249 modeGraphMinN = c_ay.getParameter<
unsigned int>(
"mode_graph_min_N");
261 findingRecord<PPSAlignmentConfigRcd>();
270 auto p = std::make_unique<PPSAlignmentConfig>();
307 <<
"[ESSource] " << (
label.empty() ?
"empty label" :
"label = " +
label) <<
":\n\n"
319 desc.
add<
bool>(
"debug",
false);
323 desc.
add<std::vector<std::string>>(
"sequence", {});
332 rp_N.
add<
int>(
"id", 3);
334 rp_N.
add<
double>(
"slope", 0.19);
335 rp_N.
add<
double>(
"sh_x", -3.6);
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);
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);
350 rp_F.add<
int>(
"id", 23);
352 rp_F.add<
double>(
"slope", 0.19);
353 rp_F.add<
double>(
"sh_x", -42.);
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);
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);
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);
385 rp_N.
add<
int>(
"id", 103);
387 rp_N.
add<
double>(
"slope", 0.40);
388 rp_N.
add<
double>(
"sh_x", -2.8);
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);
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);
403 rp_F.add<
int>(
"id", 123);
405 rp_F.add<
double>(
"slope", 0.39);
406 rp_F.add<
double>(
"sh_x", -41.9);
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);
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);
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);
432 desc.
add<
double>(
"x_ali_sh_step", 0.01);
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.);
439 desc.
add<
unsigned int>(
"max_RP_tracks_size", 2);
440 desc.
add<
double>(
"n_si", 4.);
448 rpLF.
add<
double>(
"sh_min", -43.);
449 rpLF.add<
double>(
"sh_max", -41.);
453 rpLN.
add<
double>(
"sh_min", -4.2);
454 rpLN.add<
double>(
"sh_max", -2.4);
458 rpRN.
add<
double>(
"sh_min", -3.6);
459 rpRN.add<
double>(
"sh_max", -1.8);
463 rpRF.
add<
double>(
"sh_min", -43.2);
464 rpRF.add<
double>(
"sh_max", -41.2);
475 rpLF.
add<
double>(
"x_min", 47.);
476 rpLF.
add<
double>(
"x_max", 56.5);
480 rpLN.
add<
double>(
"x_min", 9.);
481 rpLN.add<
double>(
"x_max", 18.5);
485 rpRN.
add<
double>(
"x_min", 7.);
486 rpRN.add<
double>(
"x_max", 15.);
490 rpRF.
add<
double>(
"x_min", 46.);
491 rpRF.add<
double>(
"x_max", 54.);
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);
507 rpLF.
add<
double>(
"x_min", 0.);
508 rpLF.
add<
double>(
"x_max", 0.);
512 rpLN.
add<
double>(
"x_min", 7.5);
513 rpLN.add<
double>(
"x_max", 12.);
517 rpRN.
add<
double>(
"x_min", 6.);
518 rpRN.add<
double>(
"x_max", 10.);
522 rpRF.
add<
double>(
"x_min", 0.);
523 rpRF.add<
double>(
"x_max", 0.);
526 x_alignment_relative.
add<
unsigned int>(
"near_far_min_entries", 100);
536 rpLF.
add<
double>(
"x_min", 44.5);
537 rpLF.
add<
double>(
"x_max", 49.);
541 rpLN.
add<
double>(
"x_min", 6.7);
542 rpLN.add<
double>(
"x_max", 11.);
546 rpRN.
add<
double>(
"x_min", 5.9);
547 rpRN.add<
double>(
"x_max", 10.);
551 rpRF.
add<
double>(
"x_min", 44.5);
552 rpRF.add<
double>(
"x_max", 49.);
555 y_alignment.
add<
unsigned int>(
"mode_graph_min_N", 5);
556 y_alignment.
add<
unsigned int>(
"mult_sel_proj_y_min_entries", 300);
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.);
575 descriptions.
add(
"ppsAlignmentConfigESSource", desc);
582 unsigned int n_reasonable = 0;
583 for (
int bi = 1; bi <= p->GetNbinsX(); bi++) {
585 p->SetBinContent(bi, 0.);
586 p->SetBinError(bi, 0.);
595 double xMin = x_mean - x_rms, xMax = x_mean + x_rms;
597 TF1 *ff_pol1 =
new TF1(
"ff_pol1",
"[0] + [1]*x");
599 ff_pol1->SetParameter(0., 0.);
600 p->Fit(ff_pol1,
"Q",
"", xMin, xMax);
602 sl = ff_pol1->GetParameter(1);
603 sl_unc = ff_pol1->GetParError(1);
613 TIter
next(dir->GetListOfKeys());
614 std::queue<TDirectory *> dirQueue;
616 while ((o =
next())) {
620 if (name == searchName)
623 if (((TSystemFile *)k)->IsDirectory())
624 dirQueue.push((TDirectory *)k->ReadObj());
627 while (!dirQueue.empty()) {
630 if (resultDir !=
nullptr)
641 std::vector<PointErrors>
pv;
643 TIter
next(dir->GetListOfKeys());
645 while ((o =
next())) {
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));
653 TDirectory *d_slice = (TDirectory *)k->ReadObj();
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");
658 double y_cen = h_y->GetMean();
659 double y_width = h_y->GetRMS();
664 double sl = 0., sl_unc = 0.;
665 int fr =
fitProfile(p_y_diffFN_vs_y, y_cen, y_width, sl, sl_unc);
670 p_y_diffFN_vs_y->Write(name.c_str());
672 pv.push_back({(x_max + x_min) / 2., sl, (x_max - x_min) / 2., sl_unc});
683 edm::LogInfo(
"PPS") <<
">> PPSAlignmentConfigESSource::setIntervalFor(" << key.
name() <<
")\n"
std::vector< PointErrors > buildVectorFromDirectory(TDirectory *dir, const RPConfig &rpd)
unsigned int nearFarMinEntries
std::map< unsigned int, SelectionRange > alignment_x_meth_o_ranges
constexpr int32_t ceil(float num)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
EventNumber_t event() const
PPSAlignmentConfigESSource(const edm::ParameterSet &iConfig)
unsigned int maxRPTracksSize
const EventID & eventID() const
SectorConfig sectorConfig56
std::map< unsigned int, SelectionRange > alignment_y_ranges
std::vector< std::string > sequence
std::map< unsigned int, std::vector< PointErrors > > matchingReferencePoints
double y_mode_unc_max_valid
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static const IOVSyncValue & endOfTime()
unsigned int fitProfileMinBinEntries
unsigned int fitProfileMinNReasonable
int fitProfile(TProfile *p, double x_mean, double x_rms, double &sl, double &sl_unc)
std::map< unsigned int, SelectionRange > alignment_x_relative_ranges
SectorConfig sectorConfig45
static const IOVSyncValue & beginOfTime()
const char * name() const
tuple key
prepare the HTCondor submission files and eventually submit them
unsigned int modeGraphMinN
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, const edm::IOVSyncValue &iosv, edm::ValidityInterval &oValidity) override
std::map< unsigned int, SelectionRange > matchingShiftRanges
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
std::unique_ptr< PPSAlignmentConfig > produce(const PPSAlignmentConfigRcd &)
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TDirectory * findDirectoryWithName(TDirectory *dir, std::string searchName)
Log< level::Warning, false > LogWarning
unsigned int multSelProjYMinEntries
unsigned int methOGraphMinN