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