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 (7→8) taken 1 times.
✗ Branch 1 (7→93) not taken.
✓ Branch 2 (8→9) taken 1 times.
✗ Branch 3 (8→91) not taken.
|
2 | m_algo_seq->Add("physics::InclusiveKinematics"); |
17 |
2/4✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→97) not taken.
✓ Branch 2 (13→14) taken 1 times.
✗ Branch 3 (13→95) not taken.
|
2 | m_algo_seq->Add("physics::SingleHadronKinematics"); |
18 |
1/2✓ Branch 0 (18→19) taken 1 times.
✗ Branch 1 (18→101) not taken.
|
2 | m_algo_seq->SetOption("physics::SingleHadronKinematics", "log", m_log->GetLevel()); |
19 |
4/10✓ Branch 0 (25→26) taken 1 times.
✗ Branch 1 (25→107) not taken.
✓ Branch 2 (26→27) taken 1 times.
✗ Branch 3 (26→105) not taken.
✓ Branch 4 (27→28) taken 1 times.
✗ Branch 5 (27→103) not taken.
✓ Branch 6 (30→31) taken 1 times.
✗ Branch 7 (30→33) not taken.
✗ Branch 8 (107→108) not taken.
✗ Branch 9 (107→110) 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 (35→36) taken 1 times.
✗ Branch 1 (35→111) 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 (38→39) taken 1 times.
✗ Branch 1 (38→49) not taken.
|
1 | if(output_dir) { |
28 |
3/6✓ Branch 0 (39→40) taken 1 times.
✗ Branch 1 (39→151) not taken.
✓ Branch 2 (40→41) taken 1 times.
✗ Branch 3 (40→113) not taken.
✓ Branch 4 (42→43) taken 1 times.
✗ Branch 5 (42→151) not taken.
|
2 | m_output_file_basename = output_dir.value() + "/single_hadron_kinematics"; |
29 |
2/4✓ Branch 0 (43→44) taken 1 times.
✗ Branch 1 (43→117) not taken.
✓ Branch 2 (46→47) taken 1 times.
✗ Branch 3 (46→115) not taken.
|
2 | m_output_file = new TFile(m_output_file_basename + ".root", "RECREATE"); |
30 | } | ||
31 | |||
32 | // define plots | ||
33 |
1/2✓ Branch 0 (49→50) taken 1 times.
✗ Branch 1 (49→151) not taken.
|
1 | gStyle->SetOptStat(0); |
34 | const int n_bins = 100; | ||
35 |
2/4✓ Branch 0 (67→68) taken 7 times.
✓ Branch 1 (67→71) taken 1 times.
✗ Branch 2 (120→121) not taken.
✗ Branch 3 (120→124) not taken.
|
8 | plot_list = { |
36 | { | ||
37 |
1/2✓ Branch 0 (51→52) taken 1 times.
✗ Branch 1 (51→137) 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 (53→54) taken 1 times.
✗ Branch 1 (53→135) 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 (55→56) taken 1 times.
✗ Branch 1 (55→133) not taken.
|
1 | new TH1D("MX_dist", "Missing mass: M_{X} [GeV];", n_bins, 0, 4), |
46 |
2/2✓ Branch 0 (3→4) taken 59 times.
✓ Branch 1 (3→5) 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 (57→58) taken 1 times.
✗ Branch 1 (57→131) 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 (59→60) taken 1 times.
✗ Branch 1 (59→129) 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 (61→62) taken 1 times.
✗ Branch 1 (61→127) 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 (63→64) taken 1 times.
✗ Branch 1 (63→125) 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 (64→65) taken 1 times.
✗ Branch 1 (64→119) not taken.
✓ Branch 2 (68→69) taken 7 times.
✗ Branch 3 (68→70) not taken.
✗ Branch 4 (121→122) not taken.
✗ Branch 5 (121→123) not taken.
|
8 | }; |
65 | |||
66 | // format plots | ||
67 |
2/2✓ Branch 0 (86→72) taken 7 times.
✓ Branch 1 (86→87) taken 1 times.
|
8 | for(auto& plot : plot_list) { |
68 |
1/2✓ Branch 0 (72→73) taken 7 times.
✗ Branch 1 (72→151) not taken.
|
7 | plot.hist->SetLineColor(kGreen+1); |
69 |
1/2✓ Branch 0 (73→74) taken 7 times.
✗ Branch 1 (73→151) not taken.
|
7 | plot.hist->SetFillColor(kGreen+1); |
70 |
1/2✓ Branch 0 (81→82) taken 7 times.
✗ Branch 1 (81→145) not taken.
|
7 | plot.hist->SetTitle( |
71 |
2/4✓ Branch 0 (75→76) taken 7 times.
✗ Branch 1 (75→151) not taken.
✓ Branch 2 (76→77) taken 7 times.
✗ Branch 3 (76→151) not taken.
|
14 | TString(particle::title.at(particle::pi_plus)) + |
72 |
3/8✓ Branch 0 (74→75) taken 7 times.
✗ Branch 1 (74→151) not taken.
✓ Branch 2 (77→78) taken 7 times.
✗ Branch 3 (77→149) not taken.
✓ Branch 4 (78→79) taken 7 times.
✗ Branch 5 (78→147) not taken.
✗ Branch 6 (151→152) not taken.
✗ Branch 7 (151→154) not taken.
|
28 | " " + plot.hist->GetTitle()); |
73 | } | ||
74 |
7/18✓ Branch 0 (52→53) taken 1 times.
✗ Branch 1 (52→139) not taken.
✓ Branch 2 (54→55) taken 1 times.
✗ Branch 3 (54→139) not taken.
✓ Branch 4 (56→57) taken 1 times.
✗ Branch 5 (56→139) not taken.
✓ Branch 6 (58→59) taken 1 times.
✗ Branch 7 (58→139) not taken.
✓ Branch 8 (60→61) taken 1 times.
✗ Branch 9 (60→139) not taken.
✓ Branch 10 (62→63) taken 1 times.
✗ Branch 11 (62→139) not taken.
✓ Branch 12 (64→65) taken 1 times.
✗ Branch 13 (64→119) not taken.
✗ Branch 14 (140→141) not taken.
✗ Branch 15 (140→144) not taken.
✗ Branch 16 (141→142) not taken.
✗ Branch 17 (141→143) 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 (3→4) taken 1000 times.
✗ Branch 1 (3→26) not taken.
✓ Branch 2 (4→5) taken 1000 times.
✗ Branch 3 (4→24) not taken.
|
1000 | auto& result_bank = GetBank(banks, b_result, "physics::SingleHadronKinematics"); |
82 | |||
83 | // skip events with no hadrons | ||
84 |
2/2✓ Branch 0 (7→8) taken 948 times.
✓ Branch 1 (7→10) 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 (11→12) taken 52 times.
✗ Branch 1 (11→27) not taken.
✓ Branch 2 (21→13) taken 62 times.
✓ Branch 3 (21→22) taken 52 times.
|
114 | for(auto const& row : result_bank.getRowList()) { |
92 |
2/2✓ Branch 0 (19→14) taken 434 times.
✓ Branch 1 (19→20) taken 62 times.
|
496 | for(auto& plot : plot_list) |
93 |
2/4✗ Branch 0 (14→15) not taken.
✓ Branch 1 (14→16) taken 434 times.
✓ Branch 2 (17→18) taken 434 times.
✗ Branch 3 (17→27) 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 (6→7) taken 1 times.
✗ Branch 1 (6→29) 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 (8→9) taken 1 times.
✗ Branch 1 (8→30) 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 (19→11) taken 7 times.
✓ Branch 1 (19→20) 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 (23→24) taken 1 times.
✗ Branch 1 (23→32) 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 |