LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Result.cxx
Go to the documentation of this file.
1 
9 #include <algorithm>
10 #include <cassert>
11 #include <iostream>
12 #include <ostream>
13 
16 
17 namespace lcvn {
18 
19  Result::Result(const float* output, unsigned int& nOutputs) : fOutput(1)
20  {
21  fOutput[0].resize(nOutputs);
22  for (size_t i = 0; i < nOutputs; ++i) {
23  fOutput[0][i] = output[i];
24  }
25  }
26 
27  Result::Result(const std::vector<std::vector<float>> output)
28  {
29  fOutput = output;
30  }
31 
33 
34  unsigned int Result::ArgMax(int output_n) const
35  {
36  // Get the max element iterator and convert to vector index
37 
38  // single-output
39  if (fOutput.size() == 1)
40  return std::distance(fOutput[0].begin(),
41  std::max_element(fOutput[0].begin(), fOutput[0].end()));
42  // multi-output
43  return std::distance(fOutput[output_n].begin(),
44  std::max_element(fOutput[output_n].begin(), fOutput[output_n].end()));
45  }
46 
47  /*
48  float Result::Max(){
49  // Get the maximum value by dereferencing the iterator
50  return *std::max_element(fOutput.begin(),fOutput.end());
51  }
52 
53  unsigned int Result::NOutput(){
54  return fOutput.size();
55  }
56  */
57 
60  {
61  return static_cast<TFIsAntineutrino>((int)round(this->GetIsAntineutrinoProbability()));
62  }
63 
66  {
67  return static_cast<TFFlavour>(this->ArgMax(TFMultioutputs::flavour));
68  }
69 
72  {
73  return static_cast<TFInteraction>(this->ArgMax(TFMultioutputs::interaction));
74  }
75 
78  {
79  return static_cast<TFTopologyProtons>(this->ArgMax(TFMultioutputs::protons));
80  }
81 
84  {
85  return static_cast<TFTopologyPions>(this->ArgMax(TFMultioutputs::pions));
86  }
87 
90  {
91  return static_cast<TFTopologyPizeros>(this->ArgMax(TFMultioutputs::pizeros));
92  }
93 
96  {
97  return static_cast<TFTopologyNeutrons>(this->ArgMax(TFMultioutputs::neutrons));
98  }
99 
102  {
103  // single-output
104  if (fOutput.size() == 1) return -1; // There is no is_antineutrino output
105  // multi-output
107  }
108 
111  {
112  // single-output
113  if (fOutput.size() == 1)
116  // multi-output
118  }
119 
122  {
123  // single-output
124  if (fOutput.size() == 1)
127  // multi-output
129  }
130 
133  {
134  // single-output
135  if (fOutput.size() == 1)
138  // multi-output
140  }
141 
144  {
145 
146  // The old caffe network didn't give us an NC probability
147  // So make sure we have enough values to grab it
148  float result = -999;
149 
150  // single-output
151  if (fOutput.size() == 1) {
152  if (fOutput[0].size() > static_cast<unsigned int>(TFResultType::kTFNC)) {
153  result = fOutput[0][TFResultType::kTFNC];
154  }
155  else {
156  mf::LogError("lcvn::Result")
157  << "Output vector too short to include an NC probability" << std::endl;
158  }
159  return result;
160  }
161  // multi-output
163  }
164 
167  {
168  // single-output
169  if (fOutput.size() == 1) return -1; // There is no interaction probability
170  // multi-output
172  }
173 
176  {
177  // single-output
178  if (fOutput.size() == 1) return -1; // There is no interaction probability
179  // multi-output
181  }
182 
185  {
186  // single-output
187  if (fOutput.size() == 1) return -1; // There is no interaction probability
188  // multi-output
190  }
191 
194  {
195  // single-output
196  if (fOutput.size() == 1) return -1; // There is no interaction probability
197  // multi-output
199  }
200 
203  {
204  // single-output
205  if (fOutput.size() == 1) return -1; // There is no protons probability
206  // multi-output
208  }
209 
212  {
213  // single-output
214  if (fOutput.size() == 1) return -1; // There is no protons probability
215  // multi-output
217  }
218 
221  {
222  // single-output
223  if (fOutput.size() == 1) return -1; // There is no protons probability
224  // multi-output
226  }
227 
230  {
231  // single-output
232  if (fOutput.size() == 1) return -1; // There is no protons probability
233  // multi-output
235  }
236 
239  {
240  // single-output
241  if (fOutput.size() == 1) return -1; // There is no pions probability
242  // multi-output
244  }
245 
248  {
249  // single-output
250  if (fOutput.size() == 1) return -1; // There is no pions probability
251  // multi-output
253  }
254 
257  {
258  // single-output
259  if (fOutput.size() == 1) return -1; // There is no pions probability
260  // multi-output
262  }
263 
266  {
267  // single-output
268  if (fOutput.size() == 1) return -1; // There is no pions probability
269  // multi-output
271  }
272 
275  {
276  // single-output
277  if (fOutput.size() == 1) return -1; // There is no pizeros probability
278  // multi-output
280  }
281 
284  {
285  // single-output
286  if (fOutput.size() == 1) return -1; // There is no pizeros probability
287  // multi-output
289  }
290 
293  {
294  // single-output
295  if (fOutput.size() == 1) return -1; // There is no pizeros probability
296  // multi-output
298  }
299 
302  {
303  // single-output
304  if (fOutput.size() == 1) return -1; // There is no pizeros probability
305  // multi-output
307  }
308 
311  {
312  // single-output
313  if (fOutput.size() == 1) return -1; // There is no neutrons probability
314  // multi-output
316  }
317 
320  {
321  // single-output
322  if (fOutput.size() == 1) return -1; // There is no neutrons probability
323  // multi-output
325  }
326 
329  {
330  // single-output
331  if (fOutput.size() == 1) return -1; // There is no neutrons probability
332  // multi-output
334  }
335 
338  {
339  // single-output
340  if (fOutput.size() == 1) return -1; // There is no neutrons probability
341  // multi-output
343  }
344 }
float Get1neutronsProbability() const
Return the 1 neutrons topology probability.
Definition: Result.cxx:319
float GetQEProbability() const
Return the CC QE interaction probability.
Definition: Result.cxx:166
Nue CC Resonant interaction.
Numu CC Resonant interaction.
Numu CC, other than above.
TFTopologyPions PredictedPions() const
Return the predicted pions.
Definition: Result.cxx:83
Nue CC DIS interaction.
Nutau CC QE interaction.
TFTopologyProtons
float GetNueProbability() const
Return the nue flavour probability.
Definition: Result.cxx:121
float GetNutauProbability() const
Return the nutau flavour probability.
Definition: Result.cxx:132
Utility class for truth labels.
float Get1pizerosProbability() const
Return the 1 pizeros topology probability.
Definition: Result.cxx:283
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
float Get1pionsProbability() const
Return the 1 pions topology probability.
Definition: Result.cxx:247
TFFlavour PredictedFlavour() const
Return the predicted flavour.
Definition: Result.cxx:65
Numu CC QE interaction.
float Get2pizerosProbability() const
Return the 2 pizeros topology probability.
Definition: Result.cxx:292
float Get0pizerosProbability() const
Return the 0 pizeros topology probability.
Definition: Result.cxx:274
NC interaction.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
TFTopologyNeutrons PredictedNeutrons() const
Return the predicted neutrons.
Definition: Result.cxx:95
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
TFInteraction PredictedInteraction() const
Return the predicted interaction.
Definition: Result.cxx:71
TFTopologyPizeros PredictedPizeros() const
Return the predicted pizeros.
Definition: Result.cxx:89
Result for CVN.
float Get0pionsProbability() const
Return the 0 pions topology probability.
Definition: Result.cxx:238
float GetNneutronsProbability() const
Return the >2 neutrons topology probability.
Definition: Result.cxx:337
float GetDISProbability() const
Return the CC DIS interaction probability.
Definition: Result.cxx:184
float GetNCProbability() const
Return the NC probability.
Definition: Result.cxx:143
TFTopologyPizeros
Nutau CC Resonant interaction.
TFTopologyNeutrons
float Get1protonsProbability() const
Return the 1 protons topology probability.
Definition: Result.cxx:211
float Get2neutronsProbability() const
Return the 2 neutrons topology probability.
Definition: Result.cxx:328
float GetIsAntineutrinoProbability() const
Return the is_antineutrino probability.
Definition: Result.cxx:101
TFIsAntineutrino
float Get0neutronsProbability() const
Return the 0 neutrons topology probability.
Definition: Result.cxx:310
float GetNumuProbability() const
Return the numu flavour probability.
Definition: Result.cxx:110
float GetResProbability() const
Return the CC Res interaction probability.
Definition: Result.cxx:175
Nue CC QE interaction.
float GetNpizerosProbability() const
Return the >2 pizeros topology probability.
Definition: Result.cxx:301
unsigned int ArgMax(int output_n) const
Index of maximum value in vector.
Definition: Result.cxx:34
TFTopologyProtons PredictedProtons() const
Return the predicted protons.
Definition: Result.cxx:77
Nutau CC DIS interaction.
std::vector< std::vector< float > > fOutput
Vector of outputs from neural net.
Definition: Result.h:130
Nutau CC, other than above.
Numu CC DIS interaction.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Nue CC, other than above.
float GetNpionsProbability() const
Return the >2 pions topology probability.
Definition: Result.cxx:265
float GetNprotonsProbability() const
Return the >2 protons topology probability.
Definition: Result.cxx:229
float Get2pionsProbability() const
Return the 2 pions topology probability.
Definition: Result.cxx:256
TFIsAntineutrino PredictedIsAntineutrino() const
Return the predicted is_antineutrino.
Definition: Result.cxx:59
float GetOtherProbability() const
Return the CC Other interaction probability.
Definition: Result.cxx:193
float Get2protonsProbability() const
Return the 2 protons topology probability.
Definition: Result.cxx:220
float Get0protonsProbability() const
Return the 0 protons topology probability.
Definition: Result.cxx:202