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