| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Algorithm.h" | ||
| 2 | #include "iguana/algorithms/TypeDefs.h" | ||
| 3 | |||
| 4 | namespace iguana::clas12 { | ||
| 5 | |||
| 6 | REGISTER_IGUANA_ALGORITHM(ZVertexFilter); | ||
| 7 | |||
| 8 | 8 | void ZVertexFilter::Start(hipo::banklist& banks) | |
| 9 | { | ||
| 10 | |||
| 11 | // get configuration | ||
| 12 | 8 | ParseYAMLConfig(); | |
| 13 |
2/4✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 41 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 35 not taken.
|
16 | o_particle_bank = GetOptionScalar<std::string>("particle_bank"); |
| 14 | 8 | o_runnum = ConcurrentParamFactory::Create<int>(); | |
| 15 | 8 | o_electron_vz_cuts = ConcurrentParamFactory::Create<std::vector<double>>(); | |
| 16 | |||
| 17 | // get expected bank indices | ||
| 18 | 8 | b_particle = GetBankIndex(banks, o_particle_bank); | |
| 19 |
2/4✓ Branch 28 → 29 taken 8 times.
✗ Branch 28 → 43 not taken.
✓ Branch 29 → 30 taken 8 times.
✗ Branch 29 → 32 not taken.
|
8 | b_config = GetBankIndex(banks, "RUN::config"); |
| 20 | 8 | } | |
| 21 | |||
| 22 | 2000 | bool ZVertexFilter::Run(hipo::banklist& banks) const | |
| 23 | { | ||
| 24 |
1/2✓ Branch 5 → 6 taken 2000 times.
✗ Branch 5 → 12 not taken.
|
2000 | return Run( |
| 25 |
1/2✓ Branch 4 → 5 taken 2000 times.
✗ Branch 4 → 12 not taken.
|
2000 | GetBank(banks, b_particle, o_particle_bank), |
| 26 |
1/2✓ Branch 3 → 4 taken 2000 times.
✗ Branch 3 → 12 not taken.
|
4000 | GetBank(banks, b_config, "RUN::config")); |
| 27 | } | ||
| 28 | |||
| 29 | 2000 | bool ZVertexFilter::Run(hipo::bank& particleBank, hipo::bank const& configBank) const | |
| 30 | { | ||
| 31 | // dump the bank | ||
| 32 |
1/2✓ Branch 5 → 6 taken 2000 times.
✗ Branch 5 → 28 not taken.
|
4000 | ShowBank(particleBank, Logger::Header("INPUT PARTICLES")); |
| 33 | |||
| 34 | // prepare the event, reloading configuration parameters, if necessary | ||
| 35 | 2000 | auto key = PrepareEvent(configBank.getInt("run", 0)); | |
| 36 | |||
| 37 | // filter the input bank for requested PDG code(s) | ||
| 38 |
1/2✓ Branch 14 → 15 taken 2000 times.
✗ Branch 14 → 34 not taken.
|
2000 | particleBank.getMutableRowList().filter([this, key](auto bank, auto row) { |
| 39 | 13986 | auto zvertex = bank.getFloat("vz", row); | |
| 40 | 13986 | auto pid = bank.getInt("pid", row); | |
| 41 | 13986 | auto status = bank.getShort("status", row); | |
| 42 | 13986 | auto accept = Filter(zvertex, pid, status, key); | |
| 43 | 13986 | m_log->Debug("input vz {} pid {} status {} -- accept = {}", zvertex, pid, status, accept); | |
| 44 |
2/2✓ Branch 7 → 8 taken 42 times.
✓ Branch 7 → 9 taken 13944 times.
|
13986 | return accept ? 1 : 0; |
| 45 | }); | ||
| 46 | |||
| 47 | // dump the modified bank | ||
| 48 |
1/2✓ Branch 20 → 21 taken 2000 times.
✗ Branch 20 → 37 not taken.
|
4000 | ShowBank(particleBank, Logger::Header("OUTPUT PARTICLES")); |
| 49 | 2000 | return !particleBank.getRowList().empty(); | |
| 50 | } | ||
| 51 | |||
| 52 | 2005 | concurrent_key_t ZVertexFilter::PrepareEvent(int const runnum) const | |
| 53 | { | ||
| 54 |
2/2✓ Branch 3 → 4 taken 1005 times.
✓ Branch 3 → 8 taken 1000 times.
|
2005 | m_log->Trace("calling PrepareEvent({})", runnum); |
| 55 |
2/2✓ Branch 3 → 4 taken 1005 times.
✓ Branch 3 → 8 taken 1000 times.
|
2005 | if(o_runnum->NeedsHashing()) { |
| 56 | std::hash<int> hash_ftn; | ||
| 57 | auto hash_key = hash_ftn(runnum); | ||
| 58 |
2/2✓ Branch 5 → 6 taken 6 times.
✓ Branch 5 → 7 taken 999 times.
|
1005 | if(!o_runnum->HasKey(hash_key)) |
| 59 | 6 | Reload(runnum, hash_key); | |
| 60 | return hash_key; | ||
| 61 | } | ||
| 62 | else { | ||
| 63 |
3/4✓ Branch 8 → 9 taken 999 times.
✓ Branch 8 → 11 taken 1 time.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 999 times.
|
1000 | if(o_runnum->IsEmpty() || o_runnum->Load(0) != runnum) |
| 64 | 1 | Reload(runnum, 0); | |
| 65 | 1000 | return 0; | |
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | 7 | void ZVertexFilter::Reload(int const runnum, concurrent_key_t key) const | |
| 70 | { | ||
| 71 | 7 | std::lock_guard<std::mutex> const lock(m_mutex); // NOTE: be sure to lock successive `ConcurrentParam::Save` calls !!! | |
| 72 |
2/4✓ Branch 3 → 4 taken 7 times.
✗ Branch 3 → 69 not taken.
✓ Branch 4 → 5 taken 7 times.
✗ Branch 4 → 69 not taken.
|
7 | m_log->Trace("-> calling Reload({}, {})", runnum, key); |
| 73 |
1/2✓ Branch 4 → 5 taken 7 times.
✗ Branch 4 → 69 not taken.
|
7 | o_runnum->Save(runnum, key); |
| 74 |
10/20✓ Branch 5 → 6 taken 7 times.
✗ Branch 5 → 64 not taken.
✓ Branch 6 → 7 taken 7 times.
✗ Branch 6 → 64 not taken.
✓ Branch 7 → 8 taken 7 times.
✗ Branch 7 → 64 not taken.
✓ Branch 8 → 9 taken 7 times.
✗ Branch 8 → 58 not taken.
✓ Branch 12 → 13 taken 7 times.
✗ Branch 12 → 50 not taken.
✓ Branch 13 → 14 taken 7 times.
✗ Branch 13 → 48 not taken.
✓ Branch 14 → 15 taken 7 times.
✗ Branch 14 → 42 not taken.
✓ Branch 15 → 16 taken 7 times.
✗ Branch 15 → 38 not taken.
✓ Branch 26 → 27 taken 21 times.
✓ Branch 26 → 29 taken 7 times.
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 54 not taken.
|
49 | o_electron_vz_cuts->Save(GetOptionVector<double>("electron_vz", {"electron", GetConfig()->InRange("runs", runnum), "vz"}), key); |
| 75 |
0/2✗ Branch 65 → 66 not taken.
✗ Branch 65 → 68 not taken.
|
7 | } |
| 76 | |||
| 77 | 13986 | bool ZVertexFilter::Filter(double const zvertex, int const pid, int const status, concurrent_key_t key) const | |
| 78 | { | ||
| 79 |
4/4✓ Branch 2 → 3 taken 1278 times.
✓ Branch 2 → 14 taken 12708 times.
✓ Branch 3 → 4 taken 290 times.
✓ Branch 3 → 14 taken 988 times.
|
13986 | if(pid == particle::PDG::electron && abs(status) >= 2000) { |
| 80 | 290 | auto zcuts = GetElectronZcuts(key); | |
| 81 |
6/8✓ Branch 5 → 6 taken 290 times.
✗ Branch 5 → 15 not taken.
✓ Branch 6 → 7 taken 286 times.
✓ Branch 6 → 9 taken 4 times.
✓ Branch 7 → 8 taken 286 times.
✗ Branch 7 → 15 not taken.
✓ Branch 8 → 9 taken 38 times.
✓ Branch 8 → 10 taken 248 times.
|
290 | return zvertex > zcuts.at(0) && zvertex < zcuts.at(1); |
| 82 | } | ||
| 83 | return true; // cuts don't apply | ||
| 84 | } | ||
| 85 | |||
| 86 | 1 | int ZVertexFilter::GetRunNum(concurrent_key_t const key) const | |
| 87 | { | ||
| 88 | 1 | return o_runnum->Load(key); | |
| 89 | } | ||
| 90 | |||
| 91 | 302 | std::vector<double> ZVertexFilter::GetElectronZcuts(concurrent_key_t const key) const | |
| 92 | { | ||
| 93 | 302 | return o_electron_vz_cuts->Load(key); | |
| 94 | } | ||
| 95 | |||
| 96 | 1 | void ZVertexFilter::SetElectronZcuts(double zcut_lower, double zcut_upper, concurrent_key_t const key) | |
| 97 | { | ||
| 98 |
1/2✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 8 not taken.
|
1 | o_electron_vz_cuts->Save({zcut_lower, zcut_upper}, key); |
| 99 | 1 | } | |
| 100 | |||
| 101 | 7 | void ZVertexFilter::Stop() | |
| 102 | { | ||
| 103 | 7 | } | |
| 104 | |||
| 105 | } | ||
| 106 |