| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Algorithm.h" | ||
| 2 | #include "iguana/algorithms/physics/Tools.h" | ||
| 3 | |||
| 4 | namespace iguana::clas12 { | ||
| 5 | |||
| 6 | REGISTER_IGUANA_ALGORITHM(MCProximityMatch, "MC::RecMatch::Proximity"); | ||
| 7 | |||
| 8 | 1 | void MCProximityMatch::Start(hipo::banklist& banks) | |
| 9 | { | ||
| 10 |
2/4✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 7 not taken.
|
1 | b_rec_particle_bank = GetBankIndex(banks, "REC::Particle"); |
| 11 |
2/4✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 34 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 14 not taken.
|
1 | b_mc_particle_bank = GetBankIndex(banks, "MC::Particle"); |
| 12 | |||
| 13 | // create the output bank | ||
| 14 |
1/2✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 40 not taken.
|
1 | auto result_schema = CreateBank(banks, b_result, "MC::RecMatch::Proximity"); |
| 15 |
1/2✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 46 not taken.
|
1 | i_pindex = result_schema.getEntryOrder("pindex"); |
| 16 |
1/2✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 46 not taken.
|
1 | i_mcindex = result_schema.getEntryOrder("mcindex"); |
| 17 |
1/2✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 46 not taken.
|
1 | i_proximity = result_schema.getEntryOrder("proximity"); |
| 18 | 1 | } | |
| 19 | |||
| 20 | /////////////////////////////////////////////////////////////////////////////// | ||
| 21 | |||
| 22 | 1000 | bool MCProximityMatch::Run(hipo::banklist& banks) const | |
| 23 | { | ||
| 24 |
1/2✓ Branch 8 → 9 taken 1000 times.
✗ Branch 8 → 25 not taken.
|
1000 | return Run( |
| 25 |
3/8✓ Branch 6 → 7 taken 1000 times.
✗ Branch 6 → 31 not taken.
✓ Branch 7 → 8 taken 1000 times.
✗ Branch 7 → 25 not taken.
✓ Branch 14 → 15 taken 1000 times.
✗ Branch 14 → 17 not taken.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 34 not taken.
|
2000 | GetBank(banks, b_rec_particle_bank, "REC::Particle"), |
| 26 |
3/8✓ Branch 4 → 5 taken 1000 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 1000 times.
✗ Branch 5 → 31 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 1000 times.
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 40 not taken.
|
2000 | GetBank(banks, b_mc_particle_bank, "MC::Particle"), |
| 27 |
1/2✓ Branch 3 → 4 taken 1000 times.
✗ Branch 3 → 37 not taken.
|
2000 | GetBank(banks, b_result, "MC::RecMatch::Proximity")); |
| 28 | } | ||
| 29 | |||
| 30 | 1000 | bool MCProximityMatch::Run( | |
| 31 | hipo::bank const& rec_particle_bank, | ||
| 32 | hipo::bank const& mc_particle_bank, | ||
| 33 | hipo::bank& result_bank) const | ||
| 34 | { | ||
| 35 | 1000 | result_bank.reset(); // IMPORTANT: always first `reset` the created bank(s) | |
| 36 |
1/2✓ Branch 6 → 7 taken 1000 times.
✗ Branch 6 → 69 not taken.
|
2000 | ShowBank(rec_particle_bank, Logger::Header("INPUT RECONSTRUCTED PARTICLES")); |
| 37 |
1/2✓ Branch 15 → 16 taken 1000 times.
✗ Branch 15 → 75 not taken.
|
3000 | ShowBank(mc_particle_bank, Logger::Header("INPUT GENERATED PARTICLE")); |
| 38 | |||
| 39 | // output rows | ||
| 40 | std::vector<MCProximityMatchVars> result_rows; | ||
| 41 | |||
| 42 | // loop over ALL reconstructed particles, to find matching generated particles | ||
| 43 |
2/2✓ Branch 46 → 22 taken 6993 times.
✓ Branch 46 → 47 taken 1000 times.
|
7993 | for(int row_rec = 0; row_rec < rec_particle_bank.getRows(); row_rec++) { |
| 44 | |||
| 45 | // matching variables | ||
| 46 | double min_prox = -1; // minimum proximity | ||
| 47 | int pindex_gen = -1; // matching `pindex` of `mc_particle_bank` | ||
| 48 | |||
| 49 | // reconstructed particle info | ||
| 50 | 6993 | auto pid_rec = rec_particle_bank.getInt("pid", row_rec); | |
| 51 | ROOT::Math::XYZVector p_rec( | ||
| 52 | 6993 | rec_particle_bank.getFloat("px", row_rec), | |
| 53 | 6993 | rec_particle_bank.getFloat("py", row_rec), | |
| 54 | 6993 | rec_particle_bank.getFloat("pz", row_rec)); | |
| 55 | auto theta_rec = p_rec.theta(); | ||
| 56 | auto phi_rec = p_rec.phi(); | ||
| 57 | |||
| 58 | // loop over ALL generated particles, and find the one with the smallest proximity to | ||
| 59 | // the current reconstructed particle | ||
| 60 |
1/2✗ Branch 41 → 28 not taken.
✓ Branch 41 → 42 taken 6993 times.
|
6993 | for(int row_gen = 0; row_gen < mc_particle_bank.getRows(); row_gen++) { |
| 61 | // PID must match | ||
| 62 | ✗ | if(pid_rec == mc_particle_bank.getInt("pid", row_gen)) { | |
| 63 | // generated particle info | ||
| 64 | ROOT::Math::XYZVector p_gen( | ||
| 65 | ✗ | mc_particle_bank.getFloat("px", row_gen), | |
| 66 | ✗ | mc_particle_bank.getFloat("py", row_gen), | |
| 67 | ✗ | mc_particle_bank.getFloat("pz", row_gen)); | |
| 68 | auto theta_gen = p_gen.theta(); | ||
| 69 | auto phi_gen = p_gen.phi(); | ||
| 70 | // calculate Euclidean distance in (theta,phi) space | ||
| 71 | ✗ | auto prox = std::hypot( | |
| 72 | physics::tools::AdjustAnglePi(theta_gen - theta_rec), | ||
| 73 | physics::tools::AdjustAnglePi(phi_gen - phi_rec)); | ||
| 74 | // if smallest proximity, this is the best one | ||
| 75 | ✗ | if(min_prox < 0 || prox < min_prox) { | |
| 76 | min_prox = prox; | ||
| 77 | pindex_gen = row_gen; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | // if a match was found, populate the output bank | ||
| 83 |
1/2✗ Branch 42 → 43 not taken.
✓ Branch 42 → 45 taken 6993 times.
|
6993 | if(pindex_gen >= 0) |
| 84 | ✗ | result_rows.push_back({ | |
| 85 | .pindex = row_rec, | ||
| 86 | .mcindex = pindex_gen, | ||
| 87 | .proximity = min_prox, | ||
| 88 | }); | ||
| 89 | } | ||
| 90 | |||
| 91 | // fill output bank | ||
| 92 |
1/2✓ Branch 49 → 55 taken 1000 times.
✗ Branch 49 → 87 not taken.
|
1000 | result_bank.setRows(result_rows.size()); |
| 93 |
1/2✗ Branch 55 → 50 not taken.
✓ Branch 55 → 56 taken 1000 times.
|
1000 | for(decltype(result_rows)::size_type row = 0; row < result_rows.size(); row++) { |
| 94 | ✗ | auto const& result_row = result_rows.at(row); | |
| 95 | ✗ | result_bank.putShort(i_pindex, row, result_row.pindex); | |
| 96 | ✗ | result_bank.putShort(i_mcindex, row, result_row.mcindex); | |
| 97 | ✗ | result_bank.putDouble(i_proximity, row, result_row.proximity); | |
| 98 | } | ||
| 99 | |||
| 100 |
3/8✓ Branch 56 → 57 taken 1000 times.
✗ Branch 56 → 87 not taken.
✓ Branch 59 → 60 taken 1000 times.
✗ Branch 59 → 81 not taken.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 68 taken 1000 times.
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 90 not taken.
|
3000 | ShowBank(result_bank, Logger::Header("CREATED BANK")); |
| 101 |
1/2✗ Branch 65 → 66 not taken.
✓ Branch 65 → 68 taken 1000 times.
|
1000 | return result_bank.getRows() > 0; |
| 102 | } | ||
| 103 | |||
| 104 | /////////////////////////////////////////////////////////////////////////////// | ||
| 105 | |||
| 106 | 1 | void MCProximityMatch::Stop() | |
| 107 | { | ||
| 108 | 1 | } | |
| 109 | |||
| 110 | } | ||
| 111 |