src/iguana/algorithms/clas12/TrajLinker/Algorithm.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Algorithm.h" | ||
| 2 | #include "iguana/algorithms/TypeDefs.h" | ||
| 3 | |||
| 4 | namespace iguana::clas12 { | ||
| 5 | |||
| 6 | REGISTER_IGUANA_ALGORITHM(TrajLinker, "REC::Particle::Traj"); | ||
| 7 | |||
| 8 | 4 | void TrajLinker::StartHook(hipo::banklist& banks) | |
| 9 | { | ||
| 10 |
2/4✓ Branch 3 → 4 taken 4 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 7 not taken.
|
4 | b_particle = GetBankIndex(banks, "REC::Particle"); |
| 11 |
2/4✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 45 not taken.
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 14 not taken.
|
4 | b_traj = GetBankIndex(banks, "REC::Traj"); |
| 12 |
1/2✓ Branch 17 → 18 taken 4 times.
✗ Branch 17 → 51 not taken.
|
4 | auto result_schema = CreateBank(banks, b_result, "REC::Particle::Traj"); |
| 13 |
1/2✓ Branch 23 → 24 taken 4 times.
✗ Branch 23 → 57 not taken.
|
4 | i_pindex = result_schema.getEntryOrder("pindex"); |
| 14 |
1/2✓ Branch 24 → 25 taken 4 times.
✗ Branch 24 → 57 not taken.
|
4 | i_sector = result_schema.getEntryOrder("sector"); |
| 15 |
1/2✓ Branch 25 → 26 taken 4 times.
✗ Branch 25 → 57 not taken.
|
4 | i_r1_found = result_schema.getEntryOrder("r1_found"); |
| 16 |
1/2✓ Branch 26 → 27 taken 4 times.
✗ Branch 26 → 57 not taken.
|
4 | i_r1_x = result_schema.getEntryOrder("r1_x"); |
| 17 |
1/2✓ Branch 27 → 28 taken 4 times.
✗ Branch 27 → 57 not taken.
|
4 | i_r1_y = result_schema.getEntryOrder("r1_y"); |
| 18 |
1/2✓ Branch 28 → 29 taken 4 times.
✗ Branch 28 → 57 not taken.
|
4 | i_r1_z = result_schema.getEntryOrder("r1_z"); |
| 19 |
1/2✓ Branch 29 → 30 taken 4 times.
✗ Branch 29 → 57 not taken.
|
4 | i_r2_found = result_schema.getEntryOrder("r2_found"); |
| 20 |
1/2✓ Branch 30 → 31 taken 4 times.
✗ Branch 30 → 57 not taken.
|
4 | i_r2_x = result_schema.getEntryOrder("r2_x"); |
| 21 |
1/2✓ Branch 31 → 32 taken 4 times.
✗ Branch 31 → 57 not taken.
|
4 | i_r2_y = result_schema.getEntryOrder("r2_y"); |
| 22 |
1/2✓ Branch 32 → 33 taken 4 times.
✗ Branch 32 → 57 not taken.
|
4 | i_r2_z = result_schema.getEntryOrder("r2_z"); |
| 23 |
1/2✓ Branch 33 → 34 taken 4 times.
✗ Branch 33 → 57 not taken.
|
4 | i_r3_found = result_schema.getEntryOrder("r3_found"); |
| 24 |
1/2✓ Branch 34 → 35 taken 4 times.
✗ Branch 34 → 57 not taken.
|
4 | i_r3_x = result_schema.getEntryOrder("r3_x"); |
| 25 |
1/2✓ Branch 35 → 36 taken 4 times.
✗ Branch 35 → 57 not taken.
|
4 | i_r3_y = result_schema.getEntryOrder("r3_y"); |
| 26 |
1/2✓ Branch 36 → 37 taken 4 times.
✗ Branch 36 → 57 not taken.
|
4 | i_r3_z = result_schema.getEntryOrder("r3_z"); |
| 27 | 4 | } | |
| 28 | |||
| 29 | 4000 | bool TrajLinker::RunHook(hipo::banklist& banks) const | |
| 30 | { | ||
| 31 |
1/2✓ Branch 8 → 9 taken 4000 times.
✗ Branch 8 → 25 not taken.
|
4000 | return Run( |
| 32 |
3/8✓ Branch 6 → 7 taken 4000 times.
✗ Branch 6 → 31 not taken.
✓ Branch 7 → 8 taken 4000 times.
✗ Branch 7 → 25 not taken.
✓ Branch 14 → 15 taken 4000 times.
✗ Branch 14 → 17 not taken.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 34 not taken.
|
8000 | GetBank(banks, b_particle, "REC::Particle"), |
| 33 |
3/8✓ Branch 4 → 5 taken 4000 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 4000 times.
✗ Branch 5 → 31 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 4000 times.
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 40 not taken.
|
8000 | GetBank(banks, b_traj, "REC::Traj"), |
| 34 |
1/2✓ Branch 3 → 4 taken 4000 times.
✗ Branch 3 → 37 not taken.
|
8000 | GetBank(banks, b_result, "REC::Particle::Traj")); |
| 35 | } | ||
| 36 | |||
| 37 | 4000 | bool TrajLinker::Run( | |
| 38 | hipo::bank const& bank_particle, | ||
| 39 | hipo::bank const& bank_traj, | ||
| 40 | hipo::bank& bank_result) const | ||
| 41 | { | ||
| 42 | 4000 | bank_result.reset(); // IMPORTANT: always first `reset` the created bank(s) | |
| 43 |
1/2✓ Branch 6 → 7 taken 4000 times.
✗ Branch 6 → 93 not taken.
|
8000 | ShowBank(bank_particle, Logger::Header("INPUT PARTICLE BANK")); |
| 44 |
1/2✓ Branch 15 → 16 taken 4000 times.
✗ Branch 15 → 99 not taken.
|
12000 | ShowBank(bank_traj, Logger::Header("INPUT TRAJECTORY BANK")); |
| 45 | |||
| 46 | // sync new bank with particle bank, and fill it with zeroes | ||
| 47 | 4000 | bank_result.setRows(bank_particle.getRows()); | |
| 48 | 4000 | bank_result.getMutableRowList().setList(bank_particle.getRowList()); | |
| 49 |
2/2✓ Branch 40 → 25 taken 27972 times.
✓ Branch 40 → 41 taken 4000 times.
|
31972 | for(int row = 0; row < bank_result.getRows(); row++) { |
| 50 | 27972 | bank_result.putShort(i_pindex, row, static_cast<int16_t>(row)); | |
| 51 | 27972 | bank_result.putInt(i_sector, row, 0); | |
| 52 | 27972 | bank_result.putByte(i_r1_found, row, 0); | |
| 53 | 27972 | bank_result.putFloat(i_r1_x, row, 0); | |
| 54 | 27972 | bank_result.putFloat(i_r1_y, row, 0); | |
| 55 | 27972 | bank_result.putFloat(i_r1_z, row, 0); | |
| 56 | 27972 | bank_result.putByte(i_r2_found, row, 0); | |
| 57 | 27972 | bank_result.putFloat(i_r2_x, row, 0); | |
| 58 | 27972 | bank_result.putFloat(i_r2_y, row, 0); | |
| 59 | 27972 | bank_result.putFloat(i_r2_z, row, 0); | |
| 60 | 27972 | bank_result.putByte(i_r3_found, row, 0); | |
| 61 | 27972 | bank_result.putFloat(i_r3_x, row, 0); | |
| 62 | 27972 | bank_result.putFloat(i_r3_y, row, 0); | |
| 63 | 27972 | bank_result.putFloat(i_r3_z, row, 0); | |
| 64 | } | ||
| 65 | |||
| 66 | // map particle `pindex` -> `TrajLinkerVars` object | ||
| 67 | std::map<int, TrajLinkerVars> link_map; | ||
| 68 | |||
| 69 | // loop over particle rows | ||
| 70 |
3/4✓ Branch 41 → 42 taken 4000 times.
✗ Branch 41 → 111 not taken.
✓ Branch 81 → 43 taken 23305 times.
✓ Branch 81 → 82 taken 4000 times.
|
27305 | for(auto const& row_particle : bank_particle.getRowList()) { |
| 71 | // create new `TrajLinkerVars` object for this particle | ||
| 72 |
1/2✓ Branch 43 → 44 taken 23305 times.
✗ Branch 43 → 111 not taken.
|
23305 | auto& link_particle = link_map[row_particle]; |
| 73 | // loop over `REC::Traj` rows, setting elements of linked `TrajLinkerVars` | ||
| 74 |
3/4✓ Branch 44 → 45 taken 23305 times.
✗ Branch 44 → 111 not taken.
✓ Branch 66 → 46 taken 1041807 times.
✓ Branch 66 → 67 taken 23305 times.
|
1065112 | for(auto const& row_traj : bank_traj.getRowList()) { |
| 75 |
2/2✓ Branch 47 → 48 taken 141913 times.
✓ Branch 47 → 65 taken 899894 times.
|
1041807 | if(row_particle == bank_traj.getShort("pindex", row_traj)) { |
| 76 |
2/2✓ Branch 49 → 50 taken 21336 times.
✓ Branch 49 → 65 taken 120577 times.
|
141913 | if(bank_traj.getByte("detector", row_traj) == DetectorType::DC) { // only apply to DC |
| 77 |
3/4✓ Branch 51 → 52 taken 7112 times.
✓ Branch 51 → 56 taken 7112 times.
✓ Branch 51 → 61 taken 7112 times.
✗ Branch 51 → 65 not taken.
|
21336 | switch(bank_traj.getInt("layer", row_traj)) { |
| 78 | 7112 | case 6: // region 1 | |
| 79 | 7112 | link_particle.r1_found = 1; | |
| 80 | 7112 | link_particle.r1_x = bank_traj.getFloat("x", row_traj); | |
| 81 | 7112 | link_particle.r1_y = bank_traj.getFloat("y", row_traj); | |
| 82 | 7112 | link_particle.r1_z = bank_traj.getFloat("z", row_traj); | |
| 83 | 7112 | break; | |
| 84 | 7112 | case 18: // region 2 | |
| 85 | 7112 | link_particle.r2_found = 1; | |
| 86 | 7112 | link_particle.r2_x = bank_traj.getFloat("x", row_traj); | |
| 87 | 7112 | link_particle.r2_y = bank_traj.getFloat("y", row_traj); | |
| 88 | 7112 | link_particle.r2_z = bank_traj.getFloat("z", row_traj); | |
| 89 | // Determine Sector from the center of the DC | ||
| 90 |
1/2✓ Branch 59 → 60 taken 7112 times.
✗ Branch 59 → 111 not taken.
|
7112 | link_particle.sector = GetSector(link_particle.r2_x, link_particle.r2_y, link_particle.r2_z); |
| 91 | 7112 | break; | |
| 92 | 7112 | case 36: // region 3 | |
| 93 | 7112 | link_particle.r3_found = 1; | |
| 94 | 7112 | link_particle.r3_x = bank_traj.getFloat("x", row_traj); | |
| 95 | 7112 | link_particle.r3_y = bank_traj.getFloat("y", row_traj); | |
| 96 | 7112 | link_particle.r3_z = bank_traj.getFloat("z", row_traj); | |
| 97 | 7112 | break; | |
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 102 | // fill output bank | ||
| 103 | 23305 | bank_result.putInt(i_sector, row_particle, link_particle.sector); | |
| 104 | 23305 | bank_result.putByte(i_r1_found, row_particle, link_particle.r1_found); | |
| 105 | 23305 | bank_result.putFloat(i_r1_x, row_particle, link_particle.r1_x); | |
| 106 | 23305 | bank_result.putFloat(i_r1_y, row_particle, link_particle.r1_y); | |
| 107 | 23305 | bank_result.putFloat(i_r1_z, row_particle, link_particle.r1_z); | |
| 108 | 23305 | bank_result.putByte(i_r2_found, row_particle, link_particle.r2_found); | |
| 109 | 23305 | bank_result.putFloat(i_r2_x, row_particle, link_particle.r2_x); | |
| 110 | 23305 | bank_result.putFloat(i_r2_y, row_particle, link_particle.r2_y); | |
| 111 | 23305 | bank_result.putFloat(i_r2_z, row_particle, link_particle.r2_z); | |
| 112 | 23305 | bank_result.putByte(i_r3_found, row_particle, link_particle.r3_found); | |
| 113 | 23305 | bank_result.putFloat(i_r3_x, row_particle, link_particle.r3_x); | |
| 114 | 23305 | bank_result.putFloat(i_r3_y, row_particle, link_particle.r3_y); | |
| 115 | 23305 | bank_result.putFloat(i_r3_z, row_particle, link_particle.r3_z); | |
| 116 | } | ||
| 117 |
2/4✓ Branch 82 → 83 taken 4000 times.
✗ Branch 82 → 111 not taken.
✓ Branch 85 → 86 taken 4000 times.
✗ Branch 85 → 105 not taken.
|
12000 | ShowBank(bank_result, Logger::Header("CREATED BANK")); |
| 118 | 4000 | return true; | |
| 119 | } | ||
| 120 | |||
| 121 | 7112 | int TrajLinker::GetSector(float const& x, float const& y, float const& z) const | |
| 122 | { | ||
| 123 | 7112 | float phi = 180 / M_PI * atan2(y / sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2)), x / sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2))); | |
| 124 |
4/4✓ Branch 2 → 3 taken 4143 times.
✓ Branch 2 → 4 taken 2969 times.
✓ Branch 3 → 4 taken 2889 times.
✓ Branch 3 → 13 taken 1254 times.
|
7112 | if(phi < 30 && phi >= -30) |
| 125 | return 1; | ||
| 126 |
4/4✓ Branch 4 → 5 taken 4096 times.
✓ Branch 4 → 6 taken 1762 times.
✓ Branch 5 → 6 taken 2889 times.
✓ Branch 5 → 13 taken 1207 times.
|
5858 | else if(phi < 90 && phi >= 30) |
| 127 | return 2; | ||
| 128 |
4/4✓ Branch 6 → 7 taken 4065 times.
✓ Branch 6 → 8 taken 586 times.
✓ Branch 7 → 9 taken 2889 times.
✓ Branch 7 → 13 taken 1176 times.
|
4651 | else if(phi < 150 && phi >= 90) |
| 129 | return 3; | ||
| 130 |
3/4✗ Branch 8 → 9 not taken.
✓ Branch 8 → 13 taken 586 times.
✓ Branch 9 → 10 taken 2349 times.
✓ Branch 9 → 13 taken 540 times.
|
3475 | else if(phi >= 150 || phi < -150) |
| 131 | return 4; | ||
| 132 |
2/2✓ Branch 10 → 11 taken 1101 times.
✓ Branch 10 → 13 taken 1248 times.
|
2349 | else if(phi < -90 && phi >= -150) |
| 133 | return 5; | ||
| 134 |
1/2✓ Branch 11 → 12 taken 1101 times.
✗ Branch 11 → 13 not taken.
|
1101 | else if(phi < -30 && phi >= -90) |
| 135 | 1101 | return 6; | |
| 136 | return -1; | ||
| 137 | } | ||
| 138 | |||
| 139 | } | ||
| 140 |