src/iguana/algorithms/physics/Depolarization/Algorithm.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Algorithm.h" | ||
| 2 | |||
| 3 | namespace iguana::physics { | ||
| 4 | |||
| 5 | REGISTER_IGUANA_ALGORITHM(Depolarization, "physics::Depolarization"); | ||
| 6 | |||
| 7 | /////////////////////////////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | 2 | void Depolarization::StartHook(hipo::banklist& banks) | |
| 10 | { | ||
| 11 |
2/4✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 24 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 2 times.
|
4 | b_inc_kin = GetBankIndex(banks, "physics::InclusiveKinematics"); |
| 12 | |||
| 13 | // create the output bank | ||
| 14 |
1/2✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 30 not taken.
|
2 | auto result_schema = CreateBank(banks, b_result, GetClassName()); |
| 15 |
1/2✓ Branch 16 → 17 taken 2 times.
✗ Branch 16 → 36 not taken.
|
2 | i_epsilon = result_schema.getEntryOrder("epsilon"); |
| 16 |
1/2✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 36 not taken.
|
2 | i_A = result_schema.getEntryOrder("A"); |
| 17 |
1/2✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 36 not taken.
|
2 | i_B = result_schema.getEntryOrder("B"); |
| 18 |
1/2✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 36 not taken.
|
2 | i_C = result_schema.getEntryOrder("C"); |
| 19 |
1/2✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 36 not taken.
|
2 | i_V = result_schema.getEntryOrder("V"); |
| 20 |
1/2✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 36 not taken.
|
2 | i_W = result_schema.getEntryOrder("W"); |
| 21 | 2 | } | |
| 22 | |||
| 23 | /////////////////////////////////////////////////////////////////////////////// | ||
| 24 | |||
| 25 | 286 | bool Depolarization::RunHook(hipo::banklist& banks) const | |
| 26 | { | ||
| 27 |
1/2✓ Branch 6 → 7 taken 286 times.
✗ Branch 6 → 18 not taken.
|
572 | return Run( |
| 28 |
3/8✓ Branch 4 → 5 taken 286 times.
✗ Branch 4 → 24 not taken.
✓ Branch 5 → 6 taken 286 times.
✗ Branch 5 → 18 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 286 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 27 not taken.
|
572 | GetBank(banks, b_inc_kin, "physics::InclusiveKinematics"), |
| 29 |
1/2✓ Branch 3 → 4 taken 286 times.
✗ Branch 3 → 24 not taken.
|
572 | GetBank(banks, b_result, GetClassName())); |
| 30 | } | ||
| 31 | |||
| 32 | 286 | bool Depolarization::Run( | |
| 33 | hipo::bank const& inc_kin_bank, | ||
| 34 | hipo::bank& result_bank) const | ||
| 35 | { | ||
| 36 | 286 | result_bank.reset(); // IMPORTANT: always first `reset` the created bank(s) | |
| 37 |
1/2✓ Branch 6 → 7 taken 286 times.
✗ Branch 6 → 52 not taken.
|
572 | ShowBank(inc_kin_bank, Logger::Header("INPUT INCLUSIVE KINEMATICS")); |
| 38 | |||
| 39 | // set `result_bank` rows and rowlist to match those of `inc_kin_bank` | ||
| 40 | 286 | auto const& inc_kin_bank_rowlist = inc_kin_bank.getRowList(); | |
| 41 | 286 | result_bank.setRows(inc_kin_bank.getRows()); | |
| 42 | 286 | result_bank.getMutableRowList().setList(inc_kin_bank_rowlist); | |
| 43 | |||
| 44 | // loop over ALL `inc_kin_bank`'s rows; calculate depolarization for only the rows | ||
| 45 | // that are in its current rowlist, and zero the rest | ||
| 46 |
2/2✓ Branch 41 → 17 taken 286 times.
✓ Branch 41 → 42 taken 286 times.
|
572 | for(int row = 0; row < inc_kin_bank.getRows(); row++) { |
| 47 |
1/2✓ Branch 21 → 22 taken 286 times.
✗ Branch 21 → 34 not taken.
|
286 | if(std::find(inc_kin_bank_rowlist.begin(), inc_kin_bank_rowlist.end(), row) != inc_kin_bank_rowlist.end()) { |
| 48 | 286 | auto result_vars = Compute( | |
| 49 | inc_kin_bank.getDouble("Q2", row), | ||
| 50 | inc_kin_bank.getDouble("x", row), | ||
| 51 | inc_kin_bank.getDouble("y", row), | ||
| 52 | inc_kin_bank.getDouble("targetM", row)); | ||
| 53 | 286 | result_bank.putDouble(i_epsilon, row, result_vars.epsilon); | |
| 54 | 286 | result_bank.putDouble(i_A, row, result_vars.A); | |
| 55 | 286 | result_bank.putDouble(i_B, row, result_vars.B); | |
| 56 | 286 | result_bank.putDouble(i_C, row, result_vars.C); | |
| 57 | 286 | result_bank.putDouble(i_V, row, result_vars.V); | |
| 58 | 286 | result_bank.putDouble(i_W, row, result_vars.W); | |
| 59 | } | ||
| 60 | else { | ||
| 61 | ✗ | result_bank.putDouble(i_epsilon, row, 0); | |
| 62 | ✗ | result_bank.putDouble(i_A, row, 0); | |
| 63 | ✗ | result_bank.putDouble(i_B, row, 0); | |
| 64 | ✗ | result_bank.putDouble(i_C, row, 0); | |
| 65 | ✗ | result_bank.putDouble(i_V, row, 0); | |
| 66 | ✗ | result_bank.putDouble(i_W, row, 0); | |
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 |
1/2✓ Branch 45 → 46 taken 286 times.
✗ Branch 45 → 58 not taken.
|
572 | ShowBank(result_bank, Logger::Header("CREATED BANK")); |
| 71 | 286 | return true; | |
| 72 | } | ||
| 73 | |||
| 74 | /////////////////////////////////////////////////////////////////////////////// | ||
| 75 | |||
| 76 | 286 | DepolarizationVars Depolarization::Compute(double const Q2, double const x, double const y, double const targetM) const | |
| 77 | { | ||
| 78 | DepolarizationVars const zero_result{ | ||
| 79 | .epsilon = 0, | ||
| 80 | .A = 0, | ||
| 81 | .B = 0, | ||
| 82 | .C = 0, | ||
| 83 | .V = 0, | ||
| 84 | .W = 0}; | ||
| 85 | |||
| 86 | // calculate gamma | ||
| 87 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 286 times.
|
286 | if(Q2 <= 0) { |
| 88 | ✗ | m_log->Warn("Q2 = {} <= 0", Q2); | |
| 89 | ✗ | return zero_result; | |
| 90 | } | ||
| 91 | 286 | auto gamma = 2 * targetM * x / std::sqrt(Q2); | |
| 92 | |||
| 93 | // calculate epsilon | ||
| 94 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 286 times.
|
286 | auto epsilon_denom = 1 - y + y * y / 2 + std::pow(gamma * y, 2) / 4; |
| 95 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 286 times.
|
286 | if(!(std::abs(epsilon_denom) > 0)) { |
| 96 | ✗ | m_log->Warn("epsilon denominator is zero"); | |
| 97 | ✗ | return zero_result; | |
| 98 | } | ||
| 99 | 286 | auto epsilon = (1 - y - std::pow(gamma * y, 2) / 4) / epsilon_denom; | |
| 100 | |||
| 101 | // calculate A | ||
| 102 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 286 times.
|
286 | auto A_denom = 2 - 2 * epsilon; |
| 103 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 286 times.
|
286 | if(!(std::abs(A_denom) > 0)) { |
| 104 | ✗ | m_log->Warn("depol. factor A denominator is zero"); | |
| 105 | ✗ | return zero_result; | |
| 106 | } | ||
| 107 | 286 | auto A = y * y / A_denom; | |
| 108 | |||
| 109 | // calculate B,C,V,W | ||
| 110 | return { | ||
| 111 | .epsilon = epsilon, | ||
| 112 | .A = A, | ||
| 113 | 286 | .B = A * epsilon, | |
| 114 | 286 | .C = A * std::sqrt(1 - epsilon * epsilon), | |
| 115 | 286 | .V = A * std::sqrt(2 * epsilon * (1 + epsilon)), | |
| 116 | 286 | .W = A * std::sqrt(2 * epsilon * (1 - epsilon))}; | |
| 117 | } | ||
| 118 | |||
| 119 | /////////////////////////////////////////////////////////////////////////////// | ||
| 120 | |||
| 121 | } | ||
| 122 |