Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "Validator.h" | ||
2 | #include "TypeDefs.h" | ||
3 | #include "iguana/algorithms/physics/Tools.h" | ||
4 | |||
5 | #include <Math/Vector3D.h> | ||
6 | #include <TStyle.h> | ||
7 | |||
8 | namespace iguana::physics { | ||
9 | |||
10 | REGISTER_IGUANA_VALIDATOR(SingleHadronKinematicsValidator); | ||
11 | |||
12 | 1 | void SingleHadronKinematicsValidator::Start(hipo::banklist& banks) | |
13 | { | ||
14 | // define the algorithm sequence | ||
15 | 2 | m_algo_seq = std::make_unique<AlgorithmSequence>(); | |
16 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | m_algo_seq->Add("physics::InclusiveKinematics"); |
17 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | m_algo_seq->Add("physics::SingleHadronKinematics"); |
18 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | m_algo_seq->SetOption("physics::SingleHadronKinematics", "log", m_log->GetLevel()); |
19 |
4/10✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
3 | m_algo_seq->SetOption<std::vector<int>>("physics::SingleHadronKinematics", "hadron_list", {particle::pi_plus}); |
20 | 1 | m_algo_seq->Start(banks); | |
21 | |||
22 | // get bank indices | ||
23 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | b_result = GetBankIndex(banks, "physics::SingleHadronKinematics"); |
24 | |||
25 | // set an output file | ||
26 | 1 | auto output_dir = GetOutputDirectory(); | |
27 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(output_dir) { |
28 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | m_output_file_basename = output_dir.value() + "/single_hadron_kinematics"; |
29 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | m_output_file = new TFile(m_output_file_basename + ".root", "RECREATE"); |
30 | } | ||
31 | |||
32 | // define plots | ||
33 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | gStyle->SetOptStat(0); |
34 | const int n_bins = 100; | ||
35 |
2/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
8 | plot_list = { |
36 | { | ||
37 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("z_dist", "z", n_bins, 0, 1), |
38 | 62 | [](auto const& b, auto const r) { return b.getDouble("z", r); } | |
39 | }, | ||
40 | { | ||
41 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("PhPerp_dist", "P_{h}^{{}^{#perp}}", n_bins, 0, 2), |
42 | 62 | [](auto const& b, auto const r) { return b.getDouble("PhPerp", r); } | |
43 | }, | ||
44 | { | ||
45 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("MX_dist", "Missing mass: M_{X} [GeV];", n_bins, 0, 4), |
46 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 3 times.
|
62 | [](auto const& b, auto const r) { auto MX2 = b.getDouble("MX2", r); return MX2 >= 0 ? std::sqrt(MX2) : tools::UNDEF; } |
47 | }, | ||
48 | { | ||
49 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("xF_dist", "Feynman-x: x_{F};", n_bins, -1, 1), |
50 | 62 | [](auto const& b, auto const r) { return b.getDouble("xF", r); } | |
51 | }, | ||
52 | { | ||
53 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("yB_dist", "Breit frame rapidity: y_{B};", n_bins, -4, 4), |
54 | 62 | [](auto const& b, auto const r) { return b.getDouble("yB", r); } | |
55 | }, | ||
56 | { | ||
57 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("phiH_dist", "#phi_{h};", n_bins, -M_PI, M_PI), |
58 | 62 | [](auto const& b, auto const r) { return b.getDouble("phiH", r); } | |
59 | }, | ||
60 | { | ||
61 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | new TH1D("xi_dist", "#xi", n_bins, -1, 1), |
62 | 62 | [](auto const& b, auto const r) { return b.getDouble("xi", r); } | |
63 | }, | ||
64 |
2/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
8 | }; |
65 | |||
66 | // format plots | ||
67 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for(auto& plot : plot_list) { |
68 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | plot.hist->SetLineColor(kGreen+1); |
69 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | plot.hist->SetFillColor(kGreen+1); |
70 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | plot.hist->SetTitle( |
71 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | TString(particle::title.at(particle::pi_plus)) + |
72 |
3/8✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
28 | " " + plot.hist->GetTitle()); |
73 | } | ||
74 |
7/18✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
8 | } |
75 | |||
76 | |||
77 | 1000 | void SingleHadronKinematicsValidator::Run(hipo::banklist& banks) const | |
78 | { | ||
79 | // calculate kinematics | ||
80 | 1000 | m_algo_seq->Run(banks); | |
81 |
2/4✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
|
1000 | auto& result_bank = GetBank(banks, b_result, "physics::SingleHadronKinematics"); |
82 | |||
83 | // skip events with no hadrons | ||
84 |
2/2✓ Branch 0 taken 948 times.
✓ Branch 1 taken 52 times.
|
1000 | if(result_bank.getRowList().size() == 0) { |
85 | 948 | m_log->Debug("skip this event, since it has no kinematics results"); | |
86 | return; | ||
87 | } | ||
88 | |||
89 | // lock mutex and fill the plots | ||
90 | 52 | std::scoped_lock<std::mutex> lock(m_mutex); | |
91 |
3/4✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 52 times.
|
114 | for(auto const& row : result_bank.getRowList()) { |
92 |
2/2✓ Branch 0 taken 434 times.
✓ Branch 1 taken 62 times.
|
496 | for(auto& plot : plot_list) |
93 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
|
868 | plot.hist->Fill(plot.get_val(result_bank, row)); |
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | 1 | void SingleHadronKinematicsValidator::Stop() | |
99 | { | ||
100 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | if(GetOutputDirectory()) { |
101 | int const n_cols = 4; | ||
102 | 1 | int const n_rows = (plot_list.size() - 1) / n_cols + 1; | |
103 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto canv = new TCanvas("canv", "canv", n_cols * 800, n_rows * 600); |
104 | 1 | canv->Divide(n_cols, n_rows); | |
105 | int pad_num = 0; | ||
106 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for(auto& plot : plot_list) { |
107 | 7 | auto pad = canv->GetPad(++pad_num); | |
108 | 7 | pad->cd(); | |
109 | 7 | pad->SetGrid(1, 1); | |
110 | 7 | pad->SetLeftMargin(0.12); | |
111 | 7 | pad->SetRightMargin(0.12); | |
112 | 7 | pad->SetBottomMargin(0.12); | |
113 | 7 | plot.hist->Draw(); | |
114 | } | ||
115 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | canv->SaveAs(m_output_file_basename + ".png"); |
116 | 1 | m_output_file->Write(); | |
117 | 1 | m_log->Info("Wrote output file {}", m_output_file->GetName()); | |
118 | 1 | m_output_file->Close(); | |
119 | } | ||
120 | 1 | } | |
121 | |||
122 | } | ||
123 |