Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "Validator.h" | ||
2 | |||
3 | #include <Math/Vector3D.h> | ||
4 | #include <TStyle.h> | ||
5 | |||
6 | namespace iguana::physics { | ||
7 | |||
8 | REGISTER_IGUANA_VALIDATOR(InclusiveKinematicsValidator); | ||
9 | |||
10 | 1 | void InclusiveKinematicsValidator::Start(hipo::banklist& banks) | |
11 | { | ||
12 | // define the algorithm sequence | ||
13 | 2 | m_algo_seq = std::make_unique<AlgorithmSequence>(); | |
14 |
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"); |
15 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | m_algo_seq->SetOption("physics::InclusiveKinematics", "log", m_log->GetLevel()); |
16 | 1 | m_algo_seq->Start(banks); | |
17 | |||
18 | // get bank indices | ||
19 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | b_particle = GetBankIndex(banks, "REC::Particle"); |
20 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | b_result = GetBankIndex(banks, "physics::InclusiveKinematics"); |
21 | |||
22 | // set an output file | ||
23 | 1 | auto output_dir = GetOutputDirectory(); | |
24 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(output_dir) { |
25 |
3/8✓ 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 not taken.
✗ Branch 7 not taken.
|
2 | m_output_file_basename = output_dir.value() + "/inclusive_kinematics"; |
26 |
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"); |
27 | } | ||
28 | |||
29 | // define plots | ||
30 | // clang-format off | ||
31 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | gStyle->SetOptStat(0); |
32 | const int n_bins = 100; | ||
33 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | lepton_p_dist = new TH1D("lepton_p_dist", "lepton p;p [GeV]", n_bins, 0, 12); |
34 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | lepton_theta_dist = new TH1D("lepton_theta_dist", "lepton #theta;#theta [deg]", n_bins, 0, 60); |
35 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | lepton_phi_dist = new TH1D("lepton_phi_dist", "lepton #phi;#phi [deg]", n_bins, -180, 180); |
36 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | lepton_vz_dist = new TH1D("lepton_vz_dist", "lepton v_{z};v_{z} [cm]", n_bins, -30, 30); |
37 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | Q2_vs_x = new TH2D("Q2_vs_x", "Q^{2} vs. x;x;Q^{2} [GeV^{2}]", n_bins, 0, 1, n_bins, 0, 12); |
38 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | Q2_vs_W = new TH2D("Q2_vs_W", "Q^{2} vs. W;W [GeV];Q^{2} [GeV^{2}]", n_bins, 0, 5, n_bins, 0, 12); |
39 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | y_dist = new TH1D("y_dist", "y distribution;y", n_bins, 0, 1); |
40 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | nu_dist = new TH1D("nu_dist", "#nu distribution;#nu", n_bins, 0, 12); |
41 | // clang-format on | ||
42 | |||
43 | // format plots | ||
44 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for(auto hist : {lepton_p_dist, lepton_theta_dist, lepton_phi_dist, lepton_vz_dist}) { |
45 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | hist->SetLineColor(kYellow + 2); |
46 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | hist->SetFillColor(kYellow + 2); |
47 | } | ||
48 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for(auto hist : {y_dist, nu_dist}) { |
49 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | hist->SetLineColor(kBlue); |
50 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | hist->SetFillColor(kBlue); |
51 | } | ||
52 | 1 | } | |
53 | |||
54 | |||
55 | 1000 | void InclusiveKinematicsValidator::Run(hipo::banklist& banks) const | |
56 | { | ||
57 | // calculate kinematics | ||
58 | 1000 | m_algo_seq->Run(banks); | |
59 |
1/2✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
|
1000 | auto& particle_bank = GetBank(banks, b_particle, "REC::Particle"); |
60 |
1/2✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
|
1000 | auto& result_bank = GetBank(banks, b_result, "physics::InclusiveKinematics"); |
61 | |||
62 |
2/2✓ Branch 0 taken 883 times.
✓ Branch 1 taken 117 times.
|
1000 | if(result_bank.getRowList().size() == 0) { |
63 | 883 | m_log->Debug("skip this event, since it has no inclusive kinematics results"); | |
64 | 883 | return; | |
65 | } | ||
66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | if(result_bank.getRowList().size() > 1) { |
67 | ✗ | m_log->Warn("found event with more than 1 inclusive kinematics bank rows; only the first row will be used"); | |
68 | } | ||
69 | |||
70 | 117 | auto pindex = result_bank.getShort("pindex", 0); | |
71 | 117 | auto Q2 = result_bank.getDouble("Q2", 0); | |
72 | 117 | auto x = result_bank.getDouble("x", 0); | |
73 | 117 | auto W = result_bank.getDouble("W", 0); | |
74 | 117 | auto y = result_bank.getDouble("y", 0); | |
75 | 117 | auto nu = result_bank.getDouble("nu", 0); | |
76 | |||
77 | ROOT::Math::XYZVector vec_lepton( | ||
78 | 117 | particle_bank.getFloat("px", pindex), | |
79 | 117 | particle_bank.getFloat("py", pindex), | |
80 | 117 | particle_bank.getFloat("pz", pindex)); | |
81 | 117 | auto lepton_p = std::sqrt(vec_lepton.Mag2()); | |
82 | 117 | auto lepton_theta = vec_lepton.Theta() * 180.0 / M_PI; | |
83 | 117 | auto lepton_phi = vec_lepton.Phi() * 180.0 / M_PI; | |
84 | 117 | auto lepton_vz = particle_bank.getFloat("vz", pindex); | |
85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | while(lepton_phi > 180) |
86 | ✗ | lepton_phi -= 360; | |
87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | while(lepton_phi < -180) |
88 | ✗ | lepton_phi += 360; | |
89 | |||
90 | // lock mutex and fill the plots | ||
91 | 117 | std::scoped_lock<std::mutex> lock(m_mutex); | |
92 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | lepton_p_dist->Fill(lepton_p); |
93 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | lepton_theta_dist->Fill(lepton_theta); |
94 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | lepton_phi_dist->Fill(lepton_phi); |
95 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | lepton_vz_dist->Fill(lepton_vz); |
96 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | Q2_vs_x->Fill(x, Q2); |
97 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | Q2_vs_W->Fill(W, Q2); |
98 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | y_dist->Fill(y); |
99 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | nu_dist->Fill(nu); |
100 | } | ||
101 | |||
102 | |||
103 | 1 | void InclusiveKinematicsValidator::Stop() | |
104 | { | ||
105 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | if(GetOutputDirectory()) { |
106 | int n_rows = 2; | ||
107 | int n_cols = 4; | ||
108 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto canv = new TCanvas("canv", "canv", n_cols * 800, n_rows * 600); |
109 | 1 | canv->Divide(n_cols, n_rows); | |
110 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for(int pad_num = 1; pad_num <= n_rows * n_cols; pad_num++) { |
111 | 8 | auto pad = canv->GetPad(pad_num); | |
112 | 8 | pad->cd(); | |
113 | 8 | pad->SetGrid(1, 1); | |
114 | 8 | pad->SetLeftMargin(0.12); | |
115 | 8 | pad->SetRightMargin(0.12); | |
116 | 8 | pad->SetBottomMargin(0.12); | |
117 |
8/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
8 | switch(pad_num) { |
118 | 1 | case 1: | |
119 | 1 | lepton_p_dist->Draw(); | |
120 | 1 | break; | |
121 | 1 | case 2: | |
122 | 1 | lepton_theta_dist->Draw(); | |
123 | 1 | break; | |
124 | 1 | case 3: | |
125 | 1 | lepton_phi_dist->Draw(); | |
126 | 1 | break; | |
127 | 1 | case 4: | |
128 | 1 | lepton_vz_dist->Draw(); | |
129 | 1 | break; | |
130 | 1 | case 5: | |
131 | 1 | pad->SetLogz(); | |
132 | 1 | Q2_vs_x->Draw("colz"); | |
133 | 1 | break; | |
134 | 1 | case 6: | |
135 | 1 | pad->SetLogz(); | |
136 | 1 | Q2_vs_W->Draw("colz"); | |
137 | 1 | break; | |
138 | 1 | case 7: | |
139 | 1 | y_dist->Draw(); | |
140 | 1 | break; | |
141 | 1 | case 8: | |
142 | 1 | nu_dist->Draw(); | |
143 | 1 | break; | |
144 | } | ||
145 | } | ||
146 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | canv->SaveAs(m_output_file_basename + ".png"); |
147 | 1 | m_output_file->Write(); | |
148 | 1 | m_log->Info("Wrote output file {}", m_output_file->GetName()); | |
149 | 1 | m_output_file->Close(); | |
150 | } | ||
151 | 1 | } | |
152 | |||
153 | } | ||
154 |