Skip to content

Commit 4897f70

Browse files
committed
improve beginJob method of ShortenedTrackValidation
1 parent dd1a441 commit 4897f70

File tree

1 file changed

+92
-99
lines changed

1 file changed

+92
-99
lines changed

Alignment/OfflineValidation/plugins/ShortenedTrackValidation.cc

Lines changed: 92 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -403,108 +403,101 @@ T *ShortenedTrackValidation::book(const TFileDirectory &dir, const Args &...args
403403

404404
//__________________________________________________________________________________
405405
void ShortenedTrackValidation::beginJob() {
406-
std::string currentFolder = folderName_ + "/Resolutions";
407-
TFileDirectory ShortTrackResolution = fs_->mkdir(currentFolder);
408-
currentFolder = folderName_ + "/Tracks";
409-
TFileDirectory TrackQuals = fs_->mkdir(currentFolder);
406+
const std::string resFolder = folderName_ + "/Resolutions";
407+
const std::string trackFolder = folderName_ + "/Tracks";
408+
TFileDirectory resDir = fs_->mkdir(resFolder);
409+
TFileDirectory trackDir = fs_->mkdir(trackFolder);
410+
411+
const size_t n = hitsRemain_.size();
412+
histsPtRatioAll_.reserve(n);
413+
histsPtDiffAll_.reserve(n);
414+
histsEtaDiffAll_.reserve(n);
415+
histsPhiDiffAll_.reserve(n);
416+
histsPtRatioVsDeltaRAll_.reserve(n);
417+
histsDeltaPtOverPtAll_.reserve(n);
418+
histsPtAll_.reserve(n);
419+
histsNhitsAll_.reserve(n);
420+
histsDeltaRAll_.reserve(n);
421+
comparators_.resize(n);
422+
423+
// Lambda helpers
424+
auto book1DRes = [&](const std::string &name, const std::string &title, int bins, double xmin, double xmax) {
425+
return book<TH1F>(resDir, name.c_str(), title.c_str(), bins, xmin, xmax);
426+
};
410427

411-
for (unsigned int i = 0; i < hitsRemain_.size(); ++i) {
412-
histsPtRatioAll_.push_back(
413-
book<TH1F>(ShortTrackResolution,
414-
fmt::sprintf("trackPtRatio_%s", hitsRemain_[i]).c_str(),
415-
fmt::sprintf("Short Track p_{T} / Full Track p_{T} - %s layers;p_{T}^{short}/p_{T}^{full};n. tracks",
416-
hitsRemain_[i])
417-
.c_str(),
418-
100,
419-
0.5,
420-
1.5));
421-
422-
histsPtDiffAll_.push_back(book<TH1F>(
423-
ShortTrackResolution,
424-
fmt::sprintf("trackPtDiff_%s", hitsRemain_[i]).c_str(),
425-
fmt::sprintf("Short Track p_{T} - Full Track p_{T} - %s layers;p_{T}^{short} - p_{T}^{full} [GeV];n. tracks",
426-
hitsRemain_[i])
427-
.c_str(),
428-
100,
429-
-10.,
430-
10.));
431-
432-
histsEtaDiffAll_.push_back(
433-
book<TH1F>(ShortTrackResolution,
434-
fmt::sprintf("trackEtaDiff_%s", hitsRemain_[i]).c_str(),
435-
fmt::sprintf("Short Track #eta - Full Track #eta - %s layers;#eta^{short} - #eta^{full};n. tracks",
436-
hitsRemain_[i])
437-
.c_str(),
438-
100,
439-
-0.001,
440-
0.001));
441-
442-
histsPhiDiffAll_.push_back(
443-
book<TH1F>(ShortTrackResolution,
444-
fmt::sprintf("trackPhiDiff_%s", hitsRemain_[i]).c_str(),
445-
fmt::sprintf("Short Track #phi - Full Track #phi - %s layers;#phi^{short} - #phi^{full};n. tracks",
446-
hitsRemain_[i])
447-
.c_str(),
448-
100,
449-
-0.001,
450-
0.001));
451-
452-
histsPtRatioVsDeltaRAll_.push_back(
453-
book<TH2F>(ShortTrackResolution,
454-
fmt::sprintf("trackPtRatioVsDeltaR_%s", hitsRemain_[i]).c_str(),
455-
fmt::sprintf("Short Track p_{T} / Full Track p_{T} - %s layers vs "
456-
"#DeltaR;#DeltaR(short,full);p_{T}^{short}/p_{T}^{full} [GeV];n. tracks",
457-
hitsRemain_[i])
458-
.c_str(),
459-
100,
460-
0.,
461-
0.01,
462-
101,
463-
-0.05,
464-
2.05));
465-
466-
histsDeltaPtOverPtAll_.push_back(
467-
book<TH1F>(ShortTrackResolution,
468-
fmt::sprintf("trackDeltaPtOverPt_%s", hitsRemain_[i]).c_str(),
469-
fmt::sprintf("Short Track p_{T} - Full Track p_{T} / Full Track p_{T} - %s layers;p_{T}^{short} - "
470-
"p_{T}^{full} / p^{full}_{T};n. tracks",
471-
hitsRemain_[i])
472-
.c_str(),
473-
101,
474-
-5.,
475-
5.));
476-
477-
histsPtAll_.push_back(
478-
book<TH1F>(TrackQuals,
479-
fmt::sprintf("trackPt_%s", hitsRemain_[i]).c_str(),
480-
fmt::sprintf("Short Track p_{T} - %s layers;p_{T}^{short} [GeV];n. tracks", hitsRemain_[i]).c_str(),
481-
100,
482-
0.,
483-
100.));
484-
485-
histsNhitsAll_.push_back(
486-
book<TH1F>(TrackQuals,
487-
fmt::sprintf("trackNhits_%s", hitsRemain_[i]).c_str(),
488-
fmt::sprintf("Short Track n. hits - %s layers; n. hits per track;n. tracks", hitsRemain_[i]).c_str(),
489-
20,
490-
-0.5,
491-
19.5));
492-
493-
histsDeltaRAll_.push_back(book<TH1F>(
494-
TrackQuals,
495-
fmt::sprintf("trackDeltaR_%s", hitsRemain_[i]).c_str(),
496-
fmt::sprintf("Short Track / Long Track #DeltaR %s layers;#DeltaR(short,long);n. tracks", hitsRemain_[i]).c_str(),
497-
100,
498-
0.,
499-
0.005));
500-
501-
currentFolder = fmt::sprintf("%s/Compare_%sHit", folderName_, hitsRemain_[i]);
502-
comparators_[i]->book(fs_->mkdir(currentFolder));
428+
auto book1DTrack = [&](const std::string &name, const std::string &title, int bins, double xmin, double xmax) {
429+
return book<TH1F>(trackDir, name.c_str(), title.c_str(), bins, xmin, xmax);
430+
};
431+
432+
auto book2DRes = [&](const std::string &name,
433+
const std::string &title,
434+
int xbins,
435+
double xmin,
436+
double xmax,
437+
int ybins,
438+
double ymin,
439+
double ymax) {
440+
return book<TH2F>(resDir, name.c_str(), title.c_str(), xbins, xmin, xmax, ybins, ymin, ymax);
441+
};
442+
443+
for (size_t i = 0; i < n; ++i) {
444+
const auto &label = hitsRemain_[i];
445+
446+
std::string name, title;
447+
448+
// --- Resolutions ---
449+
name = fmt::sprintf("trackPtRatio_%s", label);
450+
title =
451+
fmt::sprintf("Short Track p_{T} / Full Track p_{T} - %s layers;p_{T}^{short}/p_{T}^{full};n. tracks", label);
452+
histsPtRatioAll_.push_back(book1DRes(name, title, 100, 0.5, 1.5));
453+
454+
name = fmt::sprintf("trackPtDiff_%s", label);
455+
title = fmt::sprintf(
456+
"Short Track p_{T} - Full Track p_{T} - %s layers;p_{T}^{short} - p_{T}^{full} [GeV];n. tracks", label);
457+
histsPtDiffAll_.push_back(book1DRes(name, title, 100, -10., 10.));
458+
459+
name = fmt::sprintf("trackEtaDiff_%s", label);
460+
title = fmt::sprintf("Short Track #eta - Full Track #eta - %s layers;#eta^{short} - #eta^{full};n. tracks", label);
461+
histsEtaDiffAll_.push_back(book1DRes(name, title, 100, -0.001, 0.001));
462+
463+
name = fmt::sprintf("trackPhiDiff_%s", label);
464+
title = fmt::sprintf("Short Track #phi - Full Track #phi - %s layers;#phi^{short} - #phi^{full};n. tracks", label);
465+
histsPhiDiffAll_.push_back(book1DRes(name, title, 100, -0.001, 0.001));
466+
467+
name = fmt::sprintf("trackPtRatioVsDeltaR_%s", label);
468+
title = fmt::sprintf(
469+
"Short Track p_{T} / Full Track p_{T} - %s layers vs #DeltaR;#DeltaR(short,full);p_{T}^{short}/p_{T}^{full};n. "
470+
"tracks",
471+
label);
472+
histsPtRatioVsDeltaRAll_.push_back(book2DRes(name, title, 100, 0., 0.01, 101, -0.05, 2.05));
473+
474+
name = fmt::sprintf("trackDeltaPtOverPt_%s", label);
475+
title = fmt::sprintf(
476+
"(Short - Full) p_{T} / Full Track p_{T} - %s layers;(p_{T}^{short} - p_{T}^{full})/p_{T}^{full};n. tracks",
477+
label);
478+
histsDeltaPtOverPtAll_.push_back(book1DRes(name, title, 101, -5., 5.));
479+
480+
// --- Track quality ---
481+
name = fmt::sprintf("trackPt_%s", label);
482+
title = fmt::sprintf("Short Track p_{T} - %s layers;p_{T}^{short} [GeV];n. tracks", label);
483+
histsPtAll_.push_back(book1DTrack(name, title, 100, 0., 100.));
484+
485+
name = fmt::sprintf("trackNhits_%s", label);
486+
title = fmt::sprintf("Short Track n. hits - %s layers;n. hits per track;n. tracks", label);
487+
histsNhitsAll_.push_back(book1DTrack(name, title, 20, -0.5, 19.5));
488+
489+
name = fmt::sprintf("trackDeltaR_%s", label);
490+
title = fmt::sprintf("Short / Long Track #DeltaR - %s layers;#DeltaR(short,long);n. tracks", label);
491+
histsDeltaRAll_.push_back(book1DTrack(name, title, 100, 0., 0.005));
492+
493+
// --- Comparator ---
494+
const std::string compareFolder = fmt::format("{}/Compare_{}Hit", folderName_, label);
495+
comparators_[i]->book(fs_->mkdir(compareFolder));
503496
}
504497

505-
currentFolder = folderName_ + "/OriginalTrack";
506-
TFileDirectory original = fs_->mkdir(currentFolder);
507-
originalTrack.book(original);
498+
// --- Original track histos ---
499+
const std::string originalFolder = folderName_ + "/OriginalTrack";
500+
originalTrack.book(fs_->mkdir(originalFolder));
508501
}
509502

510503
//__________________________________________________________________________________

0 commit comments

Comments
 (0)