GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/physics/Depolarization/Validator.cc
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 75 75 100.0%
Functions: 8 8 100.0%
Branches: 107 214 50.0%

Line Branch Exec Source
1 #include "Validator.h"
2 #include <TStyle.h>
3
4 namespace iguana::physics {
5
6 REGISTER_IGUANA_VALIDATOR(DepolarizationValidator);
7
8 1 void DepolarizationValidator::Start(hipo::banklist& banks)
9 {
10 // define the algorithm sequence
11 2 m_algo_seq = std::make_unique<AlgorithmSequence>();
12
2/4
✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→171) not taken.
✓ Branch 2 (8→9) taken 1 times.
✗ Branch 3 (8→169) not taken.
2 m_algo_seq->Add("physics::InclusiveKinematics");
13
2/4
✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→175) not taken.
✓ Branch 2 (13→14) taken 1 times.
✗ Branch 3 (13→173) not taken.
2 m_algo_seq->Add("physics::Depolarization");
14
1/2
✓ Branch 0 (18→19) taken 1 times.
✗ Branch 1 (18→179) not taken.
2 m_algo_seq->SetOption("physics::Depolarization", "log", m_log->GetLevel());
15 1 m_algo_seq->Start(banks);
16
17 // get bank indices
18
1/2
✓ Branch 0 (26→27) taken 1 times.
✗ Branch 1 (26→181) not taken.
1 b_inc_kin = GetBankIndex(banks, "physics::InclusiveKinematics");
19
1/2
✓ Branch 0 (29→30) taken 1 times.
✗ Branch 1 (29→183) not taken.
1 b_depol = GetBankIndex(banks, "physics::Depolarization");
20
21 // set an output file
22 1 auto output_dir = GetOutputDirectory();
23
1/2
✓ Branch 0 (32→33) taken 1 times.
✗ Branch 1 (32→43) not taken.
1 if(output_dir) {
24
3/6
✓ Branch 0 (33→34) taken 1 times.
✗ Branch 1 (33→277) not taken.
✓ Branch 2 (34→35) taken 1 times.
✗ Branch 3 (34→185) not taken.
✓ Branch 4 (36→37) taken 1 times.
✗ Branch 5 (36→277) not taken.
2 m_output_file_basename = output_dir.value() + "/depolarization";
25
2/4
✓ Branch 0 (37→38) taken 1 times.
✗ Branch 1 (37→189) not taken.
✓ Branch 2 (40→41) taken 1 times.
✗ Branch 3 (40→187) not taken.
2 m_output_file = new TFile(m_output_file_basename + ".root", "RECREATE");
26 }
27
28 // plot binning
29
1/2
✓ Branch 0 (43→44) taken 1 times.
✗ Branch 1 (43→277) not taken.
1 gStyle->SetOptStat(0);
30 int const n_bins = 100;
31 std::pair<double,double> const depol_range = {-0.5, 2.5};
32 std::map<TString, std::pair<double,double>> const kin_range = {
33 {"Q2", {0, 10}},
34 {"x", {0, 1}},
35 {"y", {0, 1}}
36
6/14
✓ Branch 0 (44→45) taken 1 times.
✗ Branch 1 (44→201) not taken.
✓ Branch 2 (46→47) taken 1 times.
✗ Branch 3 (46→199) not taken.
✓ Branch 4 (48→49) taken 1 times.
✗ Branch 5 (48→197) not taken.
✗ Branch 6 (50→51) not taken.
✓ Branch 7 (50→52) taken 1 times.
✓ Branch 8 (53→54) taken 3 times.
✓ Branch 9 (53→56) taken 1 times.
✗ Branch 10 (191→192) not taken.
✗ Branch 11 (191→194) not taken.
✗ Branch 12 (277→278) not taken.
✗ Branch 13 (277→280) not taken.
7 };
37
38 // plot names, in preferred order for the canvas
39 std::vector<TString> const depol_names = {
40 "A",
41 "B",
42 "C",
43 "V",
44 "W",
45 "epsilon",
46 "BA",
47 "CA",
48 "VA",
49 "WA"
50
1/2
✓ Branch 0 (59→60) taken 1 times.
✗ Branch 1 (59→275) not taken.
1 };
51
52 // plot titles
53 std::map<TString,TString> const depol_titles = {
54 {"epsilon", "#varepsilon"},
55 {"A", "A"},
56 {"B", "B"},
57 {"C", "C"},
58 {"V", "V"},
59 {"W", "W"},
60 {"BA", "B/A"},
61 {"CA", "C/A"},
62 {"VA", "V/A"},
63 {"WA", "W/A"}
64
4/8
✗ Branch 0 (70→71) not taken.
✓ Branch 1 (70→72) taken 1 times.
✓ Branch 2 (73→74) taken 10 times.
✓ Branch 3 (73→77) taken 1 times.
✓ Branch 4 (77→78) taken 1 times.
✗ Branch 5 (77→220) not taken.
✗ Branch 6 (206→207) not taken.
✗ Branch 7 (206→210) not taken.
11 };
65
66 // bank accessors
67 std::map<TString, std::function<double(hipo::bank const&, int const)>> const accessors = {
68 351 {"epsilon", [](auto const& b, auto const r) { return b.getDouble("epsilon", r); }},
69 351 {"A", [](auto const& b, auto const r) { return b.getDouble("A", r); }},
70 351 {"B", [](auto const& b, auto const r) { return b.getDouble("B", r); }},
71 351 {"C", [](auto const& b, auto const r) { return b.getDouble("C", r); }},
72 351 {"V", [](auto const& b, auto const r) { return b.getDouble("V", r); }},
73 351 {"W", [](auto const& b, auto const r) { return b.getDouble("W", r); }},
74 351 {"BA", [](auto const& b, auto const r) { return b.getDouble("B", r) / b.getDouble("A", r); }},
75 351 {"CA", [](auto const& b, auto const r) { return b.getDouble("C", r) / b.getDouble("A", r); }},
76 351 {"VA", [](auto const& b, auto const r) { return b.getDouble("V", r) / b.getDouble("A", r); }},
77 351 {"WA", [](auto const& b, auto const r) { return b.getDouble("W", r) / b.getDouble("A", r); }}
78
3/6
✗ Branch 0 (87→88) not taken.
✓ Branch 1 (87→89) taken 1 times.
✓ Branch 2 (90→91) taken 10 times.
✓ Branch 3 (90→92) taken 1 times.
✗ Branch 4 (217→218) not taken.
✗ Branch 5 (217→219) not taken.
11 };
79
80 // construct plots
81
2/2
✓ Branch 0 (160→93) taken 10 times.
✓ Branch 1 (160→161) taken 1 times.
11 for(auto const& name : depol_names) {
82
1/2
✓ Branch 0 (93→94) taken 10 times.
✗ Branch 1 (93→269) not taken.
10 plots_vs_Q2.push_back({
83
8/16
✓ Branch 0 (94→95) taken 10 times.
✗ Branch 1 (94→236) not taken.
✓ Branch 2 (95→96) taken 10 times.
✗ Branch 3 (95→234) not taken.
✓ Branch 4 (96→97) taken 10 times.
✗ Branch 5 (96→234) not taken.
✓ Branch 6 (97→98) taken 10 times.
✗ Branch 7 (97→232) not taken.
✓ Branch 8 (98→99) taken 10 times.
✗ Branch 9 (98→231) not taken.
✓ Branch 10 (99→100) taken 10 times.
✗ Branch 11 (99→231) not taken.
✓ Branch 12 (102→103) taken 10 times.
✗ Branch 13 (102→229) not taken.
✓ Branch 14 (105→106) taken 10 times.
✗ Branch 15 (105→227) not taken.
40 new TH2D(name + "_vs_Q2", depol_titles.at(name) + " vs. Q^{2}", n_bins, kin_range.at("Q2").first, kin_range.at("Q2").second, n_bins, depol_range.first, depol_range.second),
84 10 accessors.at(name)
85 });
86
1/2
✓ Branch 0 (115→116) taken 10 times.
✗ Branch 1 (115→269) not taken.
10 plots_vs_x.push_back({
87
8/16
✓ Branch 0 (116→117) taken 10 times.
✗ Branch 1 (116→251) not taken.
✓ Branch 2 (117→118) taken 10 times.
✗ Branch 3 (117→249) not taken.
✓ Branch 4 (118→119) taken 10 times.
✗ Branch 5 (118→249) not taken.
✓ Branch 6 (119→120) taken 10 times.
✗ Branch 7 (119→247) not taken.
✓ Branch 8 (120→121) taken 10 times.
✗ Branch 9 (120→246) not taken.
✓ Branch 10 (121→122) taken 10 times.
✗ Branch 11 (121→246) not taken.
✓ Branch 12 (124→125) taken 10 times.
✗ Branch 13 (124→244) not taken.
✓ Branch 14 (127→128) taken 10 times.
✗ Branch 15 (127→242) not taken.
40 new TH2D(name + "_vs_x", depol_titles.at(name) + " vs. x", n_bins, kin_range.at("x").first, kin_range.at("x").second, n_bins, depol_range.first, depol_range.second),
88 10 accessors.at(name)
89 });
90
1/2
✓ Branch 0 (137→138) taken 10 times.
✗ Branch 1 (137→269) not taken.
10 plots_vs_y.push_back({
91
8/16
✓ Branch 0 (138→139) taken 10 times.
✗ Branch 1 (138→266) not taken.
✓ Branch 2 (139→140) taken 10 times.
✗ Branch 3 (139→264) not taken.
✓ Branch 4 (140→141) taken 10 times.
✗ Branch 5 (140→264) not taken.
✓ Branch 6 (141→142) taken 10 times.
✗ Branch 7 (141→262) not taken.
✓ Branch 8 (142→143) taken 10 times.
✗ Branch 9 (142→261) not taken.
✓ Branch 10 (143→144) taken 10 times.
✗ Branch 11 (143→261) not taken.
✓ Branch 12 (146→147) taken 10 times.
✗ Branch 13 (146→259) not taken.
✓ Branch 14 (149→150) taken 10 times.
✗ Branch 15 (149→257) not taken.
40 new TH2D(name + "_vs_y", depol_titles.at(name) + " vs. y", n_bins, kin_range.at("y").first, kin_range.at("y").second, n_bins, depol_range.first, depol_range.second),
92 10 accessors.at(name)
93 });
94 }
95
16/44
✓ Branch 0 (60→61) taken 1 times.
✗ Branch 1 (60→211) not taken.
✓ Branch 2 (61→62) taken 1 times.
✗ Branch 3 (61→211) not taken.
✓ Branch 4 (62→63) taken 1 times.
✗ Branch 5 (62→211) not taken.
✓ Branch 6 (63→64) taken 1 times.
✗ Branch 7 (63→211) not taken.
✓ Branch 8 (64→65) taken 1 times.
✗ Branch 9 (64→211) not taken.
✓ Branch 10 (65→66) taken 1 times.
✗ Branch 11 (65→211) not taken.
✓ Branch 12 (66→67) taken 1 times.
✗ Branch 13 (66→211) not taken.
✓ Branch 14 (67→68) taken 1 times.
✗ Branch 15 (67→211) not taken.
✓ Branch 16 (68→69) taken 1 times.
✗ Branch 17 (68→211) not taken.
✓ Branch 18 (69→70) taken 1 times.
✗ Branch 19 (69→211) not taken.
✓ Branch 20 (106→107) taken 10 times.
✗ Branch 21 (106→227) not taken.
✓ Branch 22 (107→108) taken 10 times.
✗ Branch 23 (107→227) not taken.
✓ Branch 24 (128→129) taken 10 times.
✗ Branch 25 (128→242) not taken.
✓ Branch 26 (129→130) taken 10 times.
✗ Branch 27 (129→242) not taken.
✓ Branch 28 (150→151) taken 10 times.
✗ Branch 29 (150→257) not taken.
✓ Branch 30 (151→152) taken 10 times.
✗ Branch 31 (151→257) not taken.
✗ Branch 32 (202→203) not taken.
✗ Branch 33 (202→205) not taken.
✗ Branch 34 (212→213) not taken.
✗ Branch 35 (212→216) not taken.
✗ Branch 36 (221→222) not taken.
✗ Branch 37 (221→223) not taken.
✗ Branch 38 (236→237) not taken.
✗ Branch 39 (236→238) not taken.
✗ Branch 40 (251→252) not taken.
✗ Branch 41 (251→253) not taken.
✗ Branch 42 (266→267) not taken.
✗ Branch 43 (266→268) not taken.
33 }
96
97
98 1000 void DepolarizationValidator::Run(hipo::banklist& banks) const
99 {
100 // calculate kinematics
101 1000 m_algo_seq->Run(banks);
102
2/4
✓ Branch 0 (3→4) taken 1000 times.
✗ Branch 1 (3→48) not taken.
✓ Branch 2 (4→5) taken 1000 times.
✗ Branch 3 (4→46) not taken.
1000 auto& inc_kin_bank = GetBank(banks, b_inc_kin, "physics::InclusiveKinematics");
103
2/4
✓ Branch 0 (6→7) taken 1000 times.
✗ Branch 1 (6→51) not taken.
✓ Branch 2 (7→8) taken 1000 times.
✗ Branch 3 (7→49) not taken.
1000 auto& depol_bank = GetBank(banks, b_depol, "physics::Depolarization");
104
105 // skip events with empty bank(s)
106
3/4
✓ Branch 0 (10→11) taken 117 times.
✓ Branch 1 (10→13) taken 883 times.
✗ Branch 2 (12→13) not taken.
✓ Branch 3 (12→15) taken 117 times.
1000 if(inc_kin_bank.getRowList().size() == 0 || depol_bank.getRowList().size() == 0) {
107 883 m_log->Debug("skip this event, since it has no kinematics results");
108 return;
109 }
110
111 // lock mutex and fill the plots
112 117 std::scoped_lock<std::mutex> lock(m_mutex);
113
3/4
✓ Branch 0 (16→17) taken 117 times.
✗ Branch 1 (16→52) not taken.
✓ Branch 2 (43→18) taken 117 times.
✓ Branch 3 (43→44) taken 117 times.
234 for(auto const& row : inc_kin_bank.getRowList()) {
114
2/2
✓ Branch 0 (25→19) taken 1170 times.
✓ Branch 1 (25→26) taken 117 times.
1287 for(auto& plot : plots_vs_Q2)
115
2/4
✗ Branch 0 (19→20) not taken.
✓ Branch 1 (19→21) taken 1170 times.
✓ Branch 2 (23→24) taken 1170 times.
✗ Branch 3 (23→52) not taken.
2340 plot.hist->Fill(inc_kin_bank.getDouble("Q2", row), plot.get_val(depol_bank, row));
116
2/2
✓ Branch 0 (33→27) taken 1170 times.
✓ Branch 1 (33→34) taken 117 times.
1287 for(auto& plot : plots_vs_x)
117
2/4
✗ Branch 0 (27→28) not taken.
✓ Branch 1 (27→29) taken 1170 times.
✓ Branch 2 (31→32) taken 1170 times.
✗ Branch 3 (31→52) not taken.
2340 plot.hist->Fill(inc_kin_bank.getDouble("x", row), plot.get_val(depol_bank, row));
118
2/2
✓ Branch 0 (41→35) taken 1170 times.
✓ Branch 1 (41→42) taken 117 times.
1287 for(auto& plot : plots_vs_y)
119
2/4
✗ Branch 0 (35→36) not taken.
✓ Branch 1 (35→37) taken 1170 times.
✓ Branch 2 (39→40) taken 1170 times.
✗ Branch 3 (39→52) not taken.
2340 plot.hist->Fill(inc_kin_bank.getDouble("y", row), plot.get_val(depol_bank, row));
120 }
121 }
122
123
124 1 void DepolarizationValidator::Stop()
125 {
126
1/2
✓ Branch 0 (6→7) taken 1 times.
✗ Branch 1 (6→21) not taken.
2 if(GetOutputDirectory()) {
127
128 3 auto make_plots = [this](TString const& name, std::vector<Plot2D> const& plot_list) {
129 int const n_cols = 5;
130 3 int const n_rows = (plot_list.size() - 1) / n_cols + 1;
131
3/6
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 3 times.
✓ Branch 2 (6→7) taken 3 times.
✗ Branch 3 (6→35) not taken.
✓ Branch 4 (9→10) taken 3 times.
✗ Branch 5 (9→33) not taken.
9 auto canv = new TCanvas("canv_" + name, name, n_cols * 800, n_rows * 1000);
132 3 canv->Divide(n_cols, n_rows);
133 int pad_num = 0;
134
2/2
✓ Branch 0 (21→13) taken 30 times.
✓ Branch 1 (21→22) taken 3 times.
33 for(auto& plot : plot_list) {
135 30 auto pad = canv->GetPad(++pad_num);
136 30 pad->cd();
137 30 pad->SetGrid(1, 1);
138 30 pad->SetLeftMargin(0.12);
139 30 pad->SetRightMargin(0.15);
140 30 pad->SetBottomMargin(0.12);
141 30 plot.hist->Draw("colz");
142 }
143
3/6
✓ Branch 0 (24→25) taken 3 times.
✗ Branch 1 (24→41) not taken.
✓ Branch 2 (25→26) taken 3 times.
✗ Branch 3 (25→39) not taken.
✓ Branch 4 (28→29) taken 3 times.
✗ Branch 5 (28→37) not taken.
6 canv->SaveAs(m_output_file_basename + "_" + canv->GetTitle() + ".png");
144 3 };
145
146
1/2
✓ Branch 0 (8→9) taken 1 times.
✗ Branch 1 (8→22) not taken.
1 make_plots("Q2", plots_vs_Q2);
147
1/2
✓ Branch 0 (11→12) taken 1 times.
✗ Branch 1 (11→24) not taken.
1 make_plots("x", plots_vs_x);
148
1/2
✓ Branch 0 (14→15) taken 1 times.
✗ Branch 1 (14→26) not taken.
1 make_plots("y", plots_vs_y);
149
150 1 m_output_file->Write();
151 1 m_log->Info("Wrote output file {}", m_output_file->GetName());
152 1 m_output_file->Close();
153 }
154 1 }
155
156 }
157