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