Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "Algorithm.h" | ||
2 | |||
3 | namespace iguana::clas12 { | ||
4 | |||
5 | REGISTER_IGUANA_ALGORITHM(SectorFinder, "REC::Particle::Sector"); | ||
6 | |||
7 | 6 | void SectorFinder::Start(hipo::banklist& banks) | |
8 | { | ||
9 | |||
10 | // define options, their default values, and cache them | ||
11 | 6 | ParseYAMLConfig(); | |
12 |
2/4✓ Branch 0 (4→5) taken 6 times.
✗ Branch 1 (4→109) not taken.
✓ Branch 2 (5→6) taken 6 times.
✗ Branch 3 (5→103) not taken.
|
12 | o_bankname_charged = GetOptionScalar<std::string>("bank_charged"); |
13 |
2/4✓ Branch 0 (19→20) taken 6 times.
✗ Branch 1 (19→117) not taken.
✓ Branch 2 (20→21) taken 6 times.
✗ Branch 3 (20→111) not taken.
|
12 | o_bankname_uncharged = GetOptionScalar<std::string>("bank_uncharged"); |
14 | |||
15 | bool setDefaultBanks=false; | ||
16 | // get expected bank indices | ||
17 |
4/6✓ Branch 0 (34→35) taken 6 times.
✗ Branch 1 (34→119) not taken.
✓ Branch 2 (35→36) taken 6 times.
✗ Branch 3 (35→38) not taken.
✓ Branch 4 (40→41) taken 1 times.
✓ Branch 5 (40→43) taken 5 times.
|
12 | b_particle = GetBankIndex(banks, "REC::Particle"); |
18 |
2/2✓ Branch 0 (40→41) taken 1 times.
✓ Branch 1 (40→43) taken 5 times.
|
6 | if(o_bankname_charged != "default") { |
19 | 1 | b_user_charged = GetBankIndex(banks, o_bankname_charged); | |
20 | 1 | userSpecifiedBank_charged = true; | |
21 | } | ||
22 | else { | ||
23 |
2/4✓ Branch 0 (44→45) taken 5 times.
✗ Branch 1 (44→125) not taken.
✗ Branch 2 (45→46) not taken.
✓ Branch 3 (45→48) taken 5 times.
|
5 | b_calorimeter = GetBankIndex(banks, "REC::Calorimeter"); |
24 |
2/4✓ Branch 0 (51→52) taken 5 times.
✗ Branch 1 (51→131) not taken.
✓ Branch 2 (52→53) taken 5 times.
✗ Branch 3 (52→55) not taken.
|
5 | b_track = GetBankIndex(banks, "REC::Track"); |
25 |
2/4✓ Branch 0 (58→59) taken 5 times.
✗ Branch 1 (58→137) not taken.
✗ Branch 2 (59→60) not taken.
✓ Branch 3 (59→62) taken 5 times.
|
5 | b_scint = GetBankIndex(banks, "REC::Scintillator"); |
26 | setDefaultBanks = true; | ||
27 | 5 | userSpecifiedBank_charged = false; | |
28 | } | ||
29 | |||
30 |
1/2✗ Branch 0 (65→66) not taken.
✓ Branch 1 (65→68) taken 6 times.
|
6 | if(o_bankname_uncharged != "default") { |
31 | ✗ | b_user_uncharged = GetBankIndex(banks, o_bankname_uncharged); | |
32 | ✗ | userSpecifiedBank_uncharged = true; | |
33 | } | ||
34 | else { | ||
35 | //avoid setting default banks twice | ||
36 |
2/2✓ Branch 0 (68→69) taken 1 times.
✓ Branch 1 (68→91) taken 5 times.
|
6 | if(!setDefaultBanks){ |
37 |
2/4✓ Branch 0 (70→71) taken 1 times.
✗ Branch 1 (70→143) not taken.
✗ Branch 2 (71→72) not taken.
✓ Branch 3 (71→74) taken 1 times.
|
1 | b_calorimeter = GetBankIndex(banks, "REC::Calorimeter"); |
38 |
2/4✓ Branch 0 (77→78) taken 1 times.
✗ Branch 1 (77→149) not taken.
✓ Branch 2 (78→79) taken 1 times.
✗ Branch 3 (78→81) not taken.
|
1 | b_track = GetBankIndex(banks, "REC::Track"); |
39 |
2/4✓ Branch 0 (84→85) taken 1 times.
✗ Branch 1 (84→155) not taken.
✗ Branch 2 (85→86) not taken.
✓ Branch 3 (85→88) taken 1 times.
|
2 | b_scint = GetBankIndex(banks, "REC::Scintillator"); |
40 | setDefaultBanks = true; | ||
41 | } | ||
42 | 6 | userSpecifiedBank_uncharged = false; | |
43 | } | ||
44 | |||
45 | // create the output bank | ||
46 |
1/2✓ Branch 0 (93→94) taken 6 times.
✗ Branch 1 (93→161) not taken.
|
6 | auto result_schema = CreateBank(banks, b_result, "REC::Particle::Sector"); |
47 |
1/2✓ Branch 0 (99→100) taken 6 times.
✗ Branch 1 (99→167) not taken.
|
6 | i_sector = result_schema.getEntryOrder("sector"); |
48 |
1/2✓ Branch 0 (100→101) taken 6 times.
✗ Branch 1 (100→167) not taken.
|
6 | i_pindex = result_schema.getEntryOrder("pindex"); |
49 | 6 | } | |
50 | |||
51 | 4100 | void SectorFinder::Run(hipo::banklist& banks) const | |
52 | { | ||
53 |
1/2✓ Branch 0 (3→4) taken 4100 times.
✗ Branch 1 (3→127) not taken.
|
4100 | auto& particleBank = GetBank(banks, b_particle, "REC::Particle"); |
54 |
2/4✓ Branch 0 (10→11) taken 4100 times.
✗ Branch 1 (10→133) not taken.
✗ Branch 2 (16→17) not taken.
✓ Branch 3 (16→25) taken 4100 times.
|
8200 | auto& resultBank = GetBank(banks, b_result, "REC::Particle::Sector"); |
55 | |||
56 | std::vector<int> sectors_user_uncharged; | ||
57 | std::vector<int> pindices_user_uncharged; | ||
58 |
1/2✗ Branch 0 (16→17) not taken.
✓ Branch 1 (16→25) taken 4100 times.
|
4100 | if(userSpecifiedBank_uncharged){ |
59 | ✗ | auto const& userBank = GetBank(banks, b_user_uncharged); | |
60 | ✗ | GetListsSectorPindex(userBank,sectors_user_uncharged,pindices_user_uncharged); | |
61 | } | ||
62 | |||
63 | std::vector<int> sectors_user_charged; | ||
64 | std::vector<int> pindices_user_charged; | ||
65 |
2/2✓ Branch 0 (25→26) taken 1000 times.
✓ Branch 1 (25→34) taken 3100 times.
|
4100 | if(userSpecifiedBank_charged){ |
66 |
1/2✓ Branch 0 (27→28) taken 1000 times.
✗ Branch 1 (27→145) not taken.
|
1000 | auto const& userBank = GetBank(banks, b_user_charged); |
67 |
1/2✓ Branch 0 (33→34) taken 1000 times.
✗ Branch 1 (33→199) not taken.
|
1000 | GetListsSectorPindex(userBank,sectors_user_charged,pindices_user_charged); |
68 | } | ||
69 | |||
70 | std::vector<int> sectors_track; | ||
71 | std::vector<int> pindices_track; | ||
72 |
3/4✓ Branch 0 (34→35) taken 1000 times.
✓ Branch 1 (34→36) taken 3100 times.
✓ Branch 2 (35→36) taken 1000 times.
✗ Branch 3 (35→44) not taken.
|
4100 | if(!userSpecifiedBank_charged || !userSpecifiedBank_uncharged){ |
73 |
1/2✓ Branch 0 (37→38) taken 4100 times.
✗ Branch 1 (37→151) not taken.
|
4100 | auto const& trackBank = GetBank(banks, b_track); |
74 |
1/2✓ Branch 0 (43→44) taken 4100 times.
✗ Branch 1 (43→191) not taken.
|
4100 | GetListsSectorPindex(trackBank,sectors_track,pindices_track); |
75 | } | ||
76 | |||
77 | std::vector<int> sectors_cal; | ||
78 | std::vector<int> pindices_cal; | ||
79 |
3/4✓ Branch 0 (44→45) taken 1000 times.
✓ Branch 1 (44→46) taken 3100 times.
✓ Branch 2 (45→46) taken 1000 times.
✗ Branch 3 (45→54) not taken.
|
4100 | if(!userSpecifiedBank_charged || !userSpecifiedBank_uncharged){ |
80 |
1/2✓ Branch 0 (47→48) taken 4100 times.
✗ Branch 1 (47→157) not taken.
|
4100 | auto const& calBank = GetBank(banks, b_calorimeter); |
81 |
1/2✓ Branch 0 (53→54) taken 4100 times.
✗ Branch 1 (53→183) not taken.
|
4100 | GetListsSectorPindex(calBank,sectors_cal,pindices_cal); |
82 | } | ||
83 | |||
84 | std::vector<int> sectors_scint; | ||
85 | std::vector<int> pindices_scint; | ||
86 |
3/4✓ Branch 0 (54→55) taken 1000 times.
✓ Branch 1 (54→56) taken 3100 times.
✓ Branch 2 (55→56) taken 1000 times.
✗ Branch 3 (55→64) not taken.
|
4100 | if(!userSpecifiedBank_charged || !userSpecifiedBank_uncharged){ |
87 |
1/2✓ Branch 0 (57→58) taken 4100 times.
✗ Branch 1 (57→163) not taken.
|
4100 | auto const& scintBank = GetBank(banks, b_scint); |
88 |
1/2✓ Branch 0 (63→64) taken 4100 times.
✗ Branch 1 (63→175) not taken.
|
4100 | GetListsSectorPindex(scintBank,sectors_scint,pindices_scint); |
89 | } | ||
90 | |||
91 | |||
92 | // sync new bank with particle bank, and fill it with zeroes | ||
93 |
1/2✓ Branch 0 (64→65) taken 4100 times.
✗ Branch 1 (64→175) not taken.
|
4100 | resultBank.setRows(particleBank.getRows()); |
94 |
3/6✓ Branch 0 (65→66) taken 4100 times.
✗ Branch 1 (65→175) not taken.
✓ Branch 2 (66→67) taken 4100 times.
✗ Branch 3 (66→175) not taken.
✓ Branch 4 (67→71) taken 4100 times.
✗ Branch 5 (67→175) not taken.
|
4100 | resultBank.getMutableRowList().setList(particleBank.getRowList()); |
95 |
2/2✓ Branch 0 (71→68) taken 28655 times.
✓ Branch 1 (71→72) taken 4100 times.
|
32755 | for(int row = 0; row < resultBank.getRows(); row++){ |
96 | 28655 | resultBank.putInt(i_sector, row, 0); | |
97 | 28655 | resultBank.putShort(i_pindex, row, static_cast<int16_t>(row)); | |
98 | } | ||
99 | |||
100 | |||
101 | // some downstream algorithms may still need sector info, so obtain sector for _all_ particles, | ||
102 | // not just the ones that were filtered out (use `.getRows()` rather than `.getRowList()`) | ||
103 |
2/2✓ Branch 0 (86→73) taken 28655 times.
✓ Branch 1 (86→87) taken 4100 times.
|
32755 | for(int row = 0; row < particleBank.getRows(); row++) { |
104 | |||
105 | 28655 | auto charge=particleBank.getInt("charge",row); | |
106 | int sect = -1; | ||
107 | |||
108 | // if user-specified bank | ||
109 |
4/4✓ Branch 0 (74→75) taken 15184 times.
✓ Branch 1 (74→76) taken 13471 times.
✓ Branch 2 (77→78) taken 3289 times.
✓ Branch 3 (77→81) taken 25366 times.
|
28655 | if(charge==0 ? userSpecifiedBank_uncharged : userSpecifiedBank_charged) |
110 |
2/4✓ Branch 0 (78→79) taken 3289 times.
✗ Branch 1 (78→80) not taken.
✓ Branch 2 (80→82) taken 3289 times.
✗ Branch 3 (80→175) not taken.
|
6578 | sect = GetSector( |
111 | charge==0 ? sectors_user_uncharged : sectors_user_charged, | ||
112 | charge==0 ? pindices_user_uncharged : pindices_user_charged, | ||
113 | row); | ||
114 | else // if not user-specified bank, use the standard method | ||
115 |
1/2✓ Branch 0 (81→82) taken 25366 times.
✗ Branch 1 (81→175) not taken.
|
25366 | sect = GetStandardSector( |
116 | sectors_track, | ||
117 | pindices_track, | ||
118 | sectors_cal, | ||
119 | pindices_cal, | ||
120 | sectors_scint, | ||
121 | pindices_scint, | ||
122 | row); | ||
123 | |||
124 |
2/2✓ Branch 0 (82→83) taken 17828 times.
✓ Branch 1 (82→85) taken 10827 times.
|
28655 | if (sect!=-1){ |
125 | 17828 | resultBank.putInt(i_sector, row, sect); | |
126 | 17828 | resultBank.putShort(i_pindex, row, static_cast<int16_t>(row)); | |
127 | } | ||
128 | } | ||
129 | |||
130 |
4/8✓ Branch 0 (87→88) taken 4100 times.
✗ Branch 1 (87→175) not taken.
✓ Branch 2 (90→91) taken 4100 times.
✗ Branch 3 (90→169) not taken.
✓ Branch 4 (96→97) taken 3791 times.
✓ Branch 5 (96→99) taken 309 times.
✗ Branch 6 (175→176) not taken.
✗ Branch 7 (175→178) not taken.
|
12300 | ShowBank(resultBank, Logger::Header("CREATED BANK")); |
131 | 4100 | } | |
132 | |||
133 | 13300 | void SectorFinder::GetListsSectorPindex(hipo::bank const& bank, std::vector<int>& sectors, std::vector<int>& pindices) const | |
134 | { | ||
135 |
2/2✓ Branch 0 (21→4) taken 64544 times.
✓ Branch 1 (21→22) taken 13300 times.
|
77844 | for(auto const& row : bank.getRowList()) { |
136 | //check that we're only using FD detectors | ||
137 | //eg have "sectors" in CND which we don't want to add here | ||
138 | 64544 | auto det=bank.getByte("detector",row); | |
139 |
2/2✓ Branch 0 (14→15) taken 51184 times.
✓ Branch 1 (14→20) taken 13360 times.
|
64544 | if (listFDDets.find(det) != listFDDets.end()) { |
140 | 51184 | sectors.push_back(bank.getInt("sector", row)); | |
141 | 51184 | pindices.push_back(bank.getShort("pindex", row)); | |
142 | } | ||
143 | } | ||
144 | 13300 | } | |
145 | |||
146 | 64907 | int SectorFinder::GetSector(std::vector<int> const& sectors, std::vector<int> const& pindices, int const& pindex_particle) const | |
147 | { | ||
148 |
2/2✓ Branch 0 (10→3) taken 244996 times.
✓ Branch 1 (10→11) taken 46922 times.
|
583836 | for(std::size_t i=0;i<sectors.size();i++){ |
149 |
2/2✓ Branch 0 (4→5) taken 17985 times.
✓ Branch 1 (4→7) taken 227011 times.
|
244996 | if (pindices.at(i)==pindex_particle){ |
150 | 17985 | return sectors.at(i); | |
151 | } | ||
152 | } | ||
153 | return -1; | ||
154 | } | ||
155 | |||
156 | 25567 | int SectorFinder::GetStandardSector( | |
157 | std::vector<int> const& sectors_track, | ||
158 | std::vector<int> const& pindices_track, | ||
159 | std::vector<int> const& sectors_cal, | ||
160 | std::vector<int> const& pindices_cal, | ||
161 | std::vector<int> const& sectors_scint, | ||
162 | std::vector<int> const& pindices_scint, | ||
163 | int const& pindex_particle) const | ||
164 | { | ||
165 | enum det_enum {kTrack, kScint, kCal, nDet}; // try to get sector from these detectors, in this order | ||
166 |
2/2✓ Branch 0 (33→3) taken 61618 times.
✓ Branch 1 (33→34) taken 9449 times.
|
71067 | for(int d = 0; d < nDet; d++) { |
167 | int sect = -1; | ||
168 | std::string det_name; | ||
169 |
3/3✓ Branch 0 (3→4) taken 25567 times.
✓ Branch 1 (3→6) taken 19639 times.
✓ Branch 2 (3→8) taken 16412 times.
|
61618 | switch(d) { |
170 | 25567 | case kTrack: | |
171 |
1/2✓ Branch 0 (4→5) taken 25567 times.
✗ Branch 1 (4→41) not taken.
|
25567 | sect = GetSector(sectors_track, pindices_track, pindex_particle); |
172 | det_name = "track"; | ||
173 | break; | ||
174 | 19639 | case kScint: | |
175 |
1/2✓ Branch 0 (6→7) taken 19639 times.
✗ Branch 1 (6→41) not taken.
|
19639 | sect = GetSector(sectors_scint, pindices_scint, pindex_particle); |
176 | det_name = "scint"; | ||
177 | break; | ||
178 | 16412 | case kCal: | |
179 |
1/2✓ Branch 0 (8→9) taken 16412 times.
✗ Branch 1 (8→41) not taken.
|
16412 | sect = GetSector(sectors_cal, pindices_cal, pindex_particle); |
180 | det_name = "cal"; | ||
181 | break; | ||
182 | } | ||
183 |
2/2✓ Branch 0 (10→11) taken 16118 times.
✓ Branch 1 (10→27) taken 45500 times.
|
61618 | if(sect != -1) { |
184 |
4/12✗ Branch 0 (11→12) not taken.
✓ Branch 1 (11→13) taken 16118 times.
✓ Branch 2 (15→16) taken 16118 times.
✗ Branch 3 (15→35) not taken.
✓ Branch 4 (16→17) taken 16118 times.
✗ Branch 5 (16→19) not taken.
✓ Branch 6 (21→22) taken 16118 times.
✗ Branch 7 (21→24) not taken.
✗ Branch 8 (35→36) not taken.
✗ Branch 9 (35→38) not taken.
✗ Branch 10 (41→42) not taken.
✗ Branch 11 (41→44) not taken.
|
48354 | m_log->Trace("{} pindex {} sect {}", det_name, pindex_particle, sect); |
185 | return sect; | ||
186 | } | ||
187 | } | ||
188 | return -1; | ||
189 | } | ||
190 | |||
191 | ✗ | std::vector<int> SectorFinder::GetStandardSector( | |
192 | std::vector<int> const& sectors_track, | ||
193 | std::vector<int> const& pindices_track, | ||
194 | std::vector<int> const& sectors_cal, | ||
195 | std::vector<int> const& pindices_cal, | ||
196 | std::vector<int> const& sectors_scint, | ||
197 | std::vector<int> const& pindices_scint, | ||
198 | std::vector<int> const& pindices_particle) const | ||
199 | { | ||
200 | std::vector<int> sect_list; | ||
201 | ✗ | for(auto const& pindex : pindices_particle) | |
202 | ✗ | sect_list.push_back(GetStandardSector( | |
203 | sectors_track, | ||
204 | pindices_track, | ||
205 | sectors_cal, | ||
206 | pindices_cal, | ||
207 | sectors_scint, | ||
208 | pindices_scint, | ||
209 | pindex)); | ||
210 | ✗ | return sect_list; | |
211 | } | ||
212 | |||
213 | 3 | void SectorFinder::Stop() | |
214 | { | ||
215 | 3 | } | |
216 | |||
217 | } | ||
218 |