GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/physics/SingleHadronKinematics/Algorithm.cc
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 83 84 98.8%
Functions: 3 3 100.0%
Branches: 52 94 55.3%

Line Branch Exec Source
1 #include "Algorithm.h"
2 #include "TypeDefs.h"
3 #include "iguana/algorithms/physics/Tools.h"
4
5 #include <Math/Boost.h>
6
7 namespace iguana::physics {
8
9 REGISTER_IGUANA_ALGORITHM(SingleHadronKinematics, "physics::SingleHadronKinematics");
10
11 2 void SingleHadronKinematics::Start(hipo::banklist& banks)
12 {
13
1/2
✓ Branch 0 (3→4) taken 2 times.
✗ Branch 1 (3→32) not taken.
2 b_particle = GetBankIndex(banks, "REC::Particle");
14
1/2
✓ Branch 0 (6→7) taken 2 times.
✗ Branch 1 (6→34) not taken.
2 b_inc_kin = GetBankIndex(banks, "physics::InclusiveKinematics");
15
16 // create the output bank
17
1/2
✓ Branch 0 (9→10) taken 2 times.
✗ Branch 1 (9→36) not taken.
2 auto result_schema = CreateBank(banks, b_result, GetClassName());
18
1/2
✓ Branch 0 (11→12) taken 2 times.
✗ Branch 1 (11→42) not taken.
2 i_pindex = result_schema.getEntryOrder("pindex");
19
1/2
✓ Branch 0 (12→13) taken 2 times.
✗ Branch 1 (12→42) not taken.
2 i_pdg = result_schema.getEntryOrder("pdg");
20
1/2
✓ Branch 0 (13→14) taken 2 times.
✗ Branch 1 (13→42) not taken.
2 i_z = result_schema.getEntryOrder("z");
21
1/2
✓ Branch 0 (14→15) taken 2 times.
✗ Branch 1 (14→42) not taken.
2 i_PhPerp = result_schema.getEntryOrder("PhPerp");
22
1/2
✓ Branch 0 (15→16) taken 2 times.
✗ Branch 1 (15→42) not taken.
2 i_MX2 = result_schema.getEntryOrder("MX2");
23
1/2
✓ Branch 0 (16→17) taken 2 times.
✗ Branch 1 (16→42) not taken.
2 i_xF = result_schema.getEntryOrder("xF");
24
1/2
✓ Branch 0 (17→18) taken 2 times.
✗ Branch 1 (17→42) not taken.
2 i_yB = result_schema.getEntryOrder("yB");
25
1/2
✓ Branch 0 (18→19) taken 2 times.
✗ Branch 1 (18→42) not taken.
2 i_phiH = result_schema.getEntryOrder("phiH");
26
1/2
✓ Branch 0 (19→20) taken 2 times.
✗ Branch 1 (19→42) not taken.
2 i_xi = result_schema.getEntryOrder("xi");
27
28 // parse config file
29
1/2
✓ Branch 0 (20→21) taken 2 times.
✗ Branch 1 (20→42) not taken.
2 ParseYAMLConfig();
30
4/8
✓ Branch 0 (21→22) taken 2 times.
✗ Branch 1 (21→42) not taken.
✓ Branch 2 (23→24) taken 2 times.
✗ Branch 3 (23→40) not taken.
✓ Branch 4 (24→25) taken 2 times.
✗ Branch 5 (24→38) not taken.
✓ Branch 6 (29→30) taken 2 times.
✗ Branch 7 (29→42) not taken.
6 o_hadron_pdgs = GetOptionSet<int>("hadron_list");
31
32 2 m_log->Warn("the kinematic calculations in this algorithm need to be cross checked; use this algorithm at your own risk!");
33 2 }
34
35 ///////////////////////////////////////////////////////////////////////////////
36
37 2000 void SingleHadronKinematics::Run(hipo::banklist& banks) const
38 {
39
1/2
✓ Branch 0 (3→4) taken 2000 times.
✗ Branch 1 (3→118) not taken.
2000 auto& particle_bank = GetBank(banks, b_particle, "REC::Particle");
40
1/2
✓ Branch 0 (6→7) taken 2000 times.
✗ Branch 1 (6→120) not taken.
4000 auto& inc_kin_bank = GetBank(banks, b_inc_kin, "physics::InclusiveKinematics");
41
1/2
✓ Branch 0 (9→10) taken 2000 times.
✗ Branch 1 (9→122) not taken.
4000 auto& result_bank = GetBank(banks, b_result, GetClassName());
42
1/2
✓ Branch 0 (12→13) taken 2000 times.
✗ Branch 1 (12→124) not taken.
2000 ShowBank(particle_bank, Logger::Header("INPUT PARTICLES"));
43
44
4/4
✓ Branch 0 (15→16) taken 1948 times.
✓ Branch 1 (15→18) taken 52 times.
✓ Branch 2 (17→18) taken 1714 times.
✓ Branch 3 (17→20) taken 234 times.
2000 if(particle_bank.getRowList().empty() || inc_kin_bank.getRowList().empty()) {
45 1766 m_log->Debug("skip this event, since not all required banks have entries");
46 1766 return;
47 }
48
49 // get beam and target momenta
50 // FIXME: makes some assumptions about the beam; this should be generalized...
51 ROOT::Math::PxPyPzMVector p_beam(
52 0.0,
53 0.0,
54 234 inc_kin_bank.getDouble("beamPz", 0),
55 234 particle::mass.at(particle::electron));
56 ROOT::Math::PxPyPzMVector p_target(
57 0.0,
58 0.0,
59 0.0,
60 234 inc_kin_bank.getDouble("targetM", 0));
61
62 // get virtual photon momentum
63 ROOT::Math::PxPyPzEVector p_q(
64 234 inc_kin_bank.getDouble("qx", 0),
65 234 inc_kin_bank.getDouble("qy", 0),
66 234 inc_kin_bank.getDouble("qz", 0),
67 234 inc_kin_bank.getDouble("qE", 0));
68
69 // get additional inclusive variables
70 234 auto x = inc_kin_bank.getDouble("x", 0);
71 234 auto W = inc_kin_bank.getDouble("W", 0);
72
73 // boosts
74 234 ROOT::Math::Boost boost__qp((p_q + p_target).BoostToCM()); // CoM frame of target and virtual photon
75 234 ROOT::Math::Boost boost__breit((p_q + 2 * x * p_target).BoostToCM()); // Breit frame
76 234 auto p_q__qp = boost__qp(p_q);
77 234 auto p_q__breit = boost__breit(p_q);
78
79 // banks' row lists
80 234 auto const& particle_bank_rowlist = particle_bank.getRowList();
81 hipo::bank::rowlist::list_t result_bank_rowlist{};
82
1/2
✓ Branch 0 (42→43) taken 234 times.
✗ Branch 1 (42→129) not taken.
234 result_bank.setRows(particle_bank.getRows());
83
84 // loop over ALL rows of `particle_bank`
85 // - we will calculate kinematics for rows in `particle_bank_rowlist`, and zero out all the other rows
86 // - we want the `result_bank` to have the same number of rows as `particle_bank` and the same ordering,
87 // so that banks which reference `particle_bank` rows can be used to reference `result_bank` rows too
88
2/2
✓ Branch 0 (107→44) taken 1430 times.
✓ Branch 1 (107→108) taken 234 times.
1664 for(int row = 0; row < particle_bank.getRows(); row++) {
89
90 // if the particle is in `o_hadron_pdgs` AND the row is in `particle_bank`'s filtered row list
91 1430 if(auto pdg{particle_bank.getInt("pid", row)};
92
3/4
✓ Branch 0 (54→55) taken 200 times.
✓ Branch 1 (54→56) taken 1230 times.
✗ Branch 2 (55→56) not taken.
✓ Branch 3 (55→65) taken 200 times.
1430 o_hadron_pdgs.find(pdg) != o_hadron_pdgs.end() &&
93
1/2
✗ Branch 0 (55→56) not taken.
✓ Branch 1 (55→65) taken 200 times.
200 std::find(particle_bank_rowlist.begin(), particle_bank_rowlist.end(), row) != particle_bank_rowlist.end()) {
94
95 // hadron momentum
96 auto p_Ph = ROOT::Math::PxPyPzMVector(
97
1/2
✗ Branch 0 (69→70) not taken.
✓ Branch 1 (69→71) taken 200 times.
200 particle_bank.getFloat("px", row),
98 200 particle_bank.getFloat("py", row),
99 200 particle_bank.getFloat("pz", row),
100
1/2
✓ Branch 0 (65→66) taken 200 times.
✗ Branch 1 (65→126) not taken.
200 particle::mass.at(static_cast<particle::PDG>(pdg)));
101
1/2
✓ Branch 0 (71→72) taken 200 times.
✗ Branch 1 (71→126) not taken.
200 auto p_Ph__qp = boost__qp(p_Ph);
102
1/2
✓ Branch 0 (72→73) taken 200 times.
✗ Branch 1 (72→126) not taken.
200 auto p_Ph__breit = boost__breit(p_Ph);
103
104 // calculate z
105
1/2
✓ Branch 0 (75→76) taken 200 times.
✗ Branch 1 (75→126) not taken.
200 double z = p_target.Dot(p_Ph) / p_target.Dot(p_q);
106
107 // calculate PhPerp
108
2/4
✓ Branch 0 (75→76) taken 200 times.
✗ Branch 1 (75→126) not taken.
✓ Branch 2 (76→77) taken 200 times.
✗ Branch 3 (76→78) not taken.
200 auto opt_PhPerp = tools::RejectVector(p_Ph.Vect(), p_q.Vect());
109
1/2
✓ Branch 0 (76→77) taken 200 times.
✗ Branch 1 (76→78) not taken.
200 double PhPerp = opt_PhPerp.has_value() ? opt_PhPerp.value().R() : tools::UNDEF;
110
111 // calculate MX2
112
1/2
✓ Branch 0 (85→86) taken 200 times.
✗ Branch 1 (85→126) not taken.
200 double MX2 = (p_target + p_q - p_Ph).M2();
113
114 // calculate xF
115
1/2
✓ Branch 0 (85→86) taken 200 times.
✗ Branch 1 (85→126) not taken.
200 double xF = 2 * p_Ph__qp.Vect().Dot(p_q__qp.Vect()) / (W * p_q__qp.Vect().R());
116
117 // calculate yB
118
2/4
✓ Branch 0 (85→86) taken 200 times.
✗ Branch 1 (85→126) not taken.
✓ Branch 2 (88→89) taken 200 times.
✗ Branch 3 (88→126) not taken.
400 double yB = tools::ParticleRapidity(p_Ph__breit, p_q__breit.Vect()).value_or(tools::UNDEF);
119
120 // calculate phiH
121 200 double phiH = tools::PlaneAngle(
122 200 p_q.Vect(),
123 200 p_beam.Vect(),
124 200 p_q.Vect(),
125 p_Ph.Vect()).value_or(tools::UNDEF);
126
127 // calculate xi
128
2/2
✓ Branch 0 (93→94) taken 1 times.
✓ Branch 1 (93→95) taken 199 times.
200 double xi = p_q.Dot(p_Ph) / p_target.Dot(p_q);
129
130 // put this particle in `result_bank`'s row list
131 result_bank_rowlist.push_back(row);
132
133 // fill the bank
134 200 result_bank.putShort(i_pindex, row, static_cast<int16_t>(row));
135 200 result_bank.putInt(i_pdg, row, pdg);
136 200 result_bank.putDouble(i_z, row, z);
137 200 result_bank.putDouble(i_PhPerp, row, PhPerp);
138 200 result_bank.putDouble(i_MX2, row, MX2);
139 200 result_bank.putDouble(i_xF, row, xF);
140 200 result_bank.putDouble(i_yB, row, yB);
141 200 result_bank.putDouble(i_phiH, row, phiH);
142 200 result_bank.putDouble(i_xi, row, xi);
143 }
144 else {
145 // zero the row
146 1230 result_bank.putShort(i_pindex, row, static_cast<int16_t>(row));
147 1230 result_bank.putInt(i_pdg, row, pdg);
148 1230 result_bank.putDouble(i_z, row, 0);
149 1230 result_bank.putDouble(i_PhPerp, row, 0);
150 1230 result_bank.putDouble(i_MX2, row, 0);
151 1230 result_bank.putDouble(i_xF, row, 0);
152 1230 result_bank.putDouble(i_yB, row, 0);
153 1230 result_bank.putDouble(i_phiH, row, 0);
154 1230 result_bank.putDouble(i_xi, row, 0);
155 }
156 }
157
158 // apply the filtered rowlist to `result_bank`
159
2/4
✓ Branch 0 (108→109) taken 234 times.
✗ Branch 1 (108→129) not taken.
✓ Branch 2 (109→110) taken 234 times.
✗ Branch 3 (109→129) not taken.
234 result_bank.getMutableRowList().setList(result_bank_rowlist);
160
161
4/8
✓ Branch 0 (110→111) taken 234 times.
✗ Branch 1 (110→129) not taken.
✓ Branch 2 (111→112) taken 234 times.
✗ Branch 3 (111→127) not taken.
✓ Branch 4 (113→114) taken 140 times.
✓ Branch 5 (113→116) taken 94 times.
✗ Branch 6 (129→130) not taken.
✗ Branch 7 (129→132) not taken.
468 ShowBank(result_bank, Logger::Header("CREATED BANK"));
162 }
163
164 ///////////////////////////////////////////////////////////////////////////////
165
166 1 void SingleHadronKinematics::Stop()
167 {
168 1 }
169
170 }
171