GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/physics/DihadronKinematics/Validator.cc
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 69 69 100.0%
Functions: 4 4 100.0%
Branches: 73 148 49.3%

Line Branch Exec Source
1 #include "Validator.h"
2 #include "TypeDefs.h"
3
4 #include <Math/Vector3D.h>
5 #include <TStyle.h>
6
7 namespace iguana::physics {
8
9 REGISTER_IGUANA_VALIDATOR(DihadronKinematicsValidator);
10
11 1 void DihadronKinematicsValidator::Start(hipo::banklist& banks)
12 {
13 // define the algorithm sequence
14 2 m_algo_seq = std::make_unique<AlgorithmSequence>();
15
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");
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::DihadronKinematics");
17
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 m_algo_seq->SetOption("physics::DihadronKinematics", "log", m_log->GetLevel());
18
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::DihadronKinematics", "hadron_a_list", {particle::pi_plus});
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::DihadronKinematics", "hadron_b_list", {particle::pi_minus});
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::DihadronKinematics");
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() + "/dihadron_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 9 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 plot_list = {
36 {
37
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("Mh_dist", "invariant mass M_{h} [GeV]", n_bins, 0, 4),
38 12 [](auto const& b, auto const r) { return b.getDouble("Mh", r); }
39 },
40 {
41
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("z_dist", "z", n_bins, 0, 1),
42 12 [](auto const& b, auto const r) { return b.getDouble("z", r); }
43 },
44 {
45
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("PhPerp_dist", "P_{h}^{{}^{#perp}}", n_bins, 0, 2),
46 12 [](auto const& b, auto const r) { return b.getDouble("PhPerp", r); }
47 },
48 {
49
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),
50
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 [](auto const& b, auto const r) { auto MX2 = b.getDouble("MX2", r); return MX2 >= 0 ? std::sqrt(MX2) : -100; } // FIXME: handle space-like case better
51 },
52 {
53
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("xF_dist", "Feynman-x: x_{F};", n_bins, -1, 1),
54 12 [](auto const& b, auto const r) { return b.getDouble("xF", r); }
55 },
56 {
57
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),
58 12 [](auto const& b, auto const r) { return b.getDouble("yB", r); }
59 },
60 {
61
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("phiH_dist", "#phi_{h};", n_bins, -M_PI, M_PI),
62 12 [](auto const& b, auto const r) { return b.getDouble("phiH", r); }
63 },
64 {
65
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("phiR_dist", "#phi_{R}", n_bins, -M_PI, M_PI),
66 12 [](auto const& b, auto const r) { return b.getDouble("phiR", r); }
67 },
68 {
69
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 new TH1D("theta_dist", "#theta;", n_bins, 0, M_PI),
70 12 [](auto const& b, auto const r) { return b.getDouble("theta", r); }
71 }
72
2/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
10 };
73
74 // format plots
75
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
10 for(auto& plot : plot_list) {
76
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 plot.hist->SetLineColor(kRed);
77
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 plot.hist->SetFillColor(kRed);
78
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 plot.hist->SetTitle(
79
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 TString(particle::title.at(particle::pi_plus)) +
80
3/6
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
36 TString(particle::title.at(particle::pi_minus)) +
81
3/8
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
36 " " + plot.hist->GetTitle());
82 }
83
9/22
✓ 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 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
10 }
84
85
86 1000 void DihadronKinematicsValidator::Run(hipo::banklist& banks) const
87 {
88 // calculate kinematics
89 1000 m_algo_seq->Run(banks);
90
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::DihadronKinematics");
91
92 // skip events with no dihadrons
93
2/2
✓ Branch 0 taken 993 times.
✓ Branch 1 taken 7 times.
1000 if(result_bank.getRowList().size() == 0) {
94 993 m_log->Debug("skip this event, since it has no kinematics results");
95 return;
96 }
97
98 // lock mutex and fill the plots
99 7 std::scoped_lock<std::mutex> lock(m_mutex);
100
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 7 times.
19 for(auto const& row : result_bank.getRowList()) {
101
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(auto& plot : plot_list)
102
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 108 times.
✗ Branch 3 not taken.
216 plot.hist->Fill(plot.get_val(result_bank, row));
103 }
104 }
105
106
107 1 void DihadronKinematicsValidator::Stop()
108 {
109
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if(GetOutputDirectory()) {
110 int const n_cols = 4;
111 1 int const n_rows = (plot_list.size() - 1) / n_cols + 1;
112
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 auto canv = new TCanvas("canv", "canv", n_cols * 800, n_rows * 600);
113 1 canv->Divide(n_cols, n_rows);
114 int pad_num = 0;
115
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
10 for(auto& plot : plot_list) {
116 9 auto pad = canv->GetPad(++pad_num);
117 9 pad->cd();
118 9 pad->SetGrid(1, 1);
119 9 pad->SetLeftMargin(0.12);
120 9 pad->SetRightMargin(0.12);
121 9 pad->SetBottomMargin(0.12);
122 9 plot.hist->Draw();
123 }
124
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 canv->SaveAs(m_output_file_basename + ".png");
125 1 m_output_file->Write();
126 1 m_log->Info("Wrote output file {}", m_output_file->GetName());
127 1 m_output_file->Close();
128 }
129 1 }
130
131 }
132