Result.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file Result.h
3 /// \brief Result for CVN
4 /// \author Alexander Radovic - a.radovic@gmail.com
5 /// Leigh Whitehead - leigh.howard.whitehead@cern.ch
6 /// Saul Alonso Monsalve - saul.alonso.monsalve@cern.ch
7 ////////////////////////////////////////////////////////////////////////
8 
9 #include <cassert>
10 #include <iostream>
11 #include <ostream>
12 #include <algorithm>
13 
16 
17 namespace cvn
18 {
19 
20  Result::Result(const float* output, unsigned int& nOutputs):
21  fOutput(1)
22  {
23  fOutput[0].resize(nOutputs);
24  for(size_t i = 0; i < nOutputs; ++i)
25  {
26  fOutput[0][i] = output[i];
27  }
28  }
29 
30  Result::Result(const std::vector< std::vector<float> > output){
31  fOutput = output;
32  }
33 
35  fOutput()
36  {}
37 
38  unsigned int Result::ArgMax(int output_n) const
39  {
40  // Get the max element iterator and convert to vector index
41 
42  // single-output
43  if(fOutput.size() == 1)
44  return std::distance(fOutput[0].begin(),std::max_element(fOutput[0].begin(),fOutput[0].end()));
45  // multi-output
46  return std::distance(fOutput[output_n].begin(),std::max_element(fOutput[output_n].begin(),fOutput[output_n].end()));
47  }
48 
49  /*
50  float Result::Max(){
51  // Get the maximum value by dereferencing the iterator
52  return *std::max_element(fOutput.begin(),fOutput.end());
53  }
54 
55  unsigned int Result::NOutput(){
56  return fOutput.size();
57  }
58  */
59 
60  /// Return the predicted is_antineutrion
62  return static_cast<TFIsAntineutrino>((int)round(this->GetIsAntineutrinoProbability()));
63  }
64 
65  /// Return the predicted flavour
67  {
68  return static_cast<TFFlavour>(this->ArgMax(TFMultioutputs::flavour));
69  }
70 
71  /// Return the predicted interaction
73  return static_cast<TFInteraction>(this->ArgMax(TFMultioutputs::interaction));
74  }
75 
76  /// Return the predicted protons
78  return static_cast<TFTopologyProtons>(this->ArgMax(TFMultioutputs::protons));
79  }
80 
81  /// Return the predicted pions
83  return static_cast<TFTopologyPions>(this->ArgMax(TFMultioutputs::pions));
84  }
85 
86  /// Return the predicted pizeros
88  return static_cast<TFTopologyPizeros>(this->ArgMax(TFMultioutputs::pizeros));
89  }
90 
91  /// Return the predicted neutrons
93  return static_cast<TFTopologyNeutrons>(this->ArgMax(TFMultioutputs::neutrons));
94  }
95 
96  /// Return the is_antineutrino probability
98  {
99  // single-output
100  if(fOutput.size() == 1)
101  return -1; // There is no is_antineutrino output
102  // multi-output
104  }
105 
106  /// Return the numu flavour probability
108  {
109  // single-output
110  if(fOutput.size() == 1)
113  // multi-output
115  }
116 
117  /// Return the nue flavour probability
119  {
120  // single-output
121  if(fOutput.size() == 1)
124  // multi-output
126  }
127 
128  /// Return the nutau flavour probability
130  {
131  // single-output
132  if(fOutput.size() == 1)
135  // multi-output
137  }
138 
139  /// Return the NC probability
141  {
142 
143  // The old caffe network didn't give us an NC probability
144  // So make sure we have enough values to grab it
145  float result = -999;
146 
147  // single-output
148  if(fOutput.size() == 1){
149  if(fOutput[0].size() > static_cast<unsigned int>(TFResultType::kTFNC)){
150  result = fOutput[0][TFResultType::kTFNC];
151  }
152  else{
153  mf::LogError("cvn::Result") << "Output vector too short to include an NC probability" << std::endl;
154  }
155  return result;
156  }
157  // multi-output
159  }
160 
161  /// Return the CC QE interaction probability
163  {
164  // single-output
165  if(fOutput.size() == 1)
166  return -1; // There is no interaction probability
167  // multi-output
169  }
170 
171  /// Return the CC Res interaction probability
173  {
174  // single-output
175  if(fOutput.size() == 1)
176  return -1; // There is no interaction probability
177  // multi-output
179  }
180 
181  /// Return the CC DIS interaction probability
183  {
184  // single-output
185  if(fOutput.size() == 1)
186  return -1; // There is no interaction probability
187  // multi-output
189  }
190 
191  /// Return the CC Other interaction probability
193  {
194  // single-output
195  if(fOutput.size() == 1)
196  return -1; // There is no interaction probability
197  // multi-output
199  }
200 
201  /// Return the 0 protons topology probability
203  {
204  // single-output
205  if(fOutput.size() == 1)
206  return -1; // There is no protons probability
207  // multi-output
209  }
210 
211  /// Return the 1 protons topology probability
213  {
214  // single-output
215  if(fOutput.size() == 1)
216  return -1; // There is no protons probability
217  // multi-output
219  }
220 
221  /// Return the 2 protons topology probability
223  {
224  // single-output
225  if(fOutput.size() == 1)
226  return -1; // There is no protons probability
227  // multi-output
229  }
230 
231  /// Return the >2 protons topology probability
233  {
234  // single-output
235  if(fOutput.size() == 1)
236  return -1; // There is no protons probability
237  // multi-output
239  }
240 
241  /// Return the 0 pions topology probability
243  {
244  // single-output
245  if(fOutput.size() == 1)
246  return -1; // There is no pions probability
247  // multi-output
249  }
250 
251  /// Return the 1 pions topology probability
253  {
254  // single-output
255  if(fOutput.size() == 1)
256  return -1; // There is no pions probability
257  // multi-output
259  }
260 
261  /// Return the 2 pions topology probability
263  {
264  // single-output
265  if(fOutput.size() == 1)
266  return -1; // There is no pions probability
267  // multi-output
269  }
270 
271  /// Return the >2 pions topology probability
273  {
274  // single-output
275  if(fOutput.size() == 1)
276  return -1; // There is no pions probability
277  // multi-output
279  }
280 
281  /// Return the 0 pizeros topology probability
283  {
284  // single-output
285  if(fOutput.size() == 1)
286  return -1; // There is no pizeros probability
287  // multi-output
289  }
290 
291  /// Return the 1 pizeros topology probability
293  {
294  // single-output
295  if(fOutput.size() == 1)
296  return -1; // There is no pizeros probability
297  // multi-output
299  }
300 
301  /// Return the 2 pizeros topology probability
303  {
304  // single-output
305  if(fOutput.size() == 1)
306  return -1; // There is no pizeros probability
307  // multi-output
309  }
310 
311  /// Return the >2 pizeros topology probability
313  {
314  // single-output
315  if(fOutput.size() == 1)
316  return -1; // There is no pizeros probability
317  // multi-output
319  }
320 
321  /// Return the 0 neutrons topology probability
323  {
324  // single-output
325  if(fOutput.size() == 1)
326  return -1; // There is no neutrons probability
327  // multi-output
329  }
330 
331  /// Return the 1 neutrons topology probability
333  {
334  // single-output
335  if(fOutput.size() == 1)
336  return -1; // There is no neutrons probability
337  // multi-output
339  }
340 
341  /// Return the 2 neutrons topology probability
343  {
344  // single-output
345  if(fOutput.size() == 1)
346  return -1; // There is no neutrons probability
347  // multi-output
349  }
350 
351  /// Return the >2 neutrons topology probability
353  {
354  // single-output
355  if(fOutput.size() == 1)
356  return -1; // There is no neutrons probability
357  // multi-output
359  }
360 }
float Get2neutronsProbability() const
Return the 2 neutrons topology probability.
Definition: Result.cxx:342
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
float Get1protonsProbability() const
Return the 1 protons topology probability.
Definition: Result.cxx:212
NC interaction.
float Get0pizerosProbability() const
Return the 0 pizeros topology probability.
Definition: Result.cxx:282
float GetNpionsProbability() const
Return the >2 pions topology probability.
Definition: Result.cxx:272
float Get2pionsProbability() const
Return the 2 pions topology probability.
Definition: Result.cxx:262
unsigned int ArgMax(int output_n) const
Index of maximum value in vector.
Definition: Result.cxx:38
Numu CC QE interaction.
Nutau CC Resonant interaction.
static QCString result
float Get1pizerosProbability() const
Return the 1 pizeros topology probability.
Definition: Result.cxx:292
float GetNpizerosProbability() const
Return the >2 pizeros topology probability.
Definition: Result.cxx:312
Nue CC, other than above.
Numu CC Resonant interaction.
TFTopologyNeutrons PredictedNeutrons() const
Return the predicted neutrons.
Definition: Result.cxx:92
TFTopologyNeutrons
float Get0protonsProbability() const
Return the 0 protons topology probability.
Definition: Result.cxx:202
struct vector vector
float GetNneutronsProbability() const
Return the >2 neutrons topology probability.
Definition: Result.cxx:352
float Get0pionsProbability() const
Return the 0 pions topology probability.
Definition: Result.cxx:242
TFTopologyPions PredictedPions() const
Return the predicted pions.
Definition: Result.cxx:82
TFTopologyPizeros PredictedPizeros() const
Return the predicted pizeros.
Definition: Result.cxx:87
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Utility class for truth labels.
Nue CC DIS interaction.
float GetNCProbability() const
Return the NC probability.
Definition: Result.cxx:140
float Get2pizerosProbability() const
Return the 2 pizeros topology probability.
Definition: Result.cxx:302
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Numu CC, other than above.
float GetResProbability() const
Return the CC Res interaction probability.
Definition: Result.cxx:172
Result for CVN.
float GetNumuProbability() const
Return the numu flavour probability.
Definition: Result.cxx:107
TFInteraction PredictedInteraction() const
Return the predicted interaction.
Definition: Result.cxx:72
TFIsAntineutrino PredictedIsAntineutrino() const
Return the predicted is_antineutrino.
Definition: Result.cxx:61
TFIsAntineutrino
Nue CC QE interaction.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
float Get0neutronsProbability() const
Return the 0 neutrons topology probability.
Definition: Result.cxx:322
float GetIsAntineutrinoProbability() const
Return the is_antineutrino probability.
Definition: Result.cxx:97
float GetNutauProbability() const
Return the nutau flavour probability.
Definition: Result.cxx:129
TFTopologyProtons
Nutau CC DIS interaction.
TFFlavour PredictedFlavour() const
Return the predicted flavour.
Definition: Result.cxx:66
float GetDISProbability() const
Return the CC DIS interaction probability.
Definition: Result.cxx:182
float GetNueProbability() const
Return the nue flavour probability.
Definition: Result.cxx:118
std::vector< std::vector< float > > fOutput
Vector of outputs from neural net.
Definition: Result.h:132
TFTopologyProtons PredictedProtons() const
Return the predicted protons.
Definition: Result.cxx:77
Nutau CC QE interaction.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
float GetNprotonsProbability() const
Return the >2 protons topology probability.
Definition: Result.cxx:232
Nutau CC, other than above.
Nue CC Resonant interaction.
TFTopologyPizeros
float GetQEProbability() const
Return the CC QE interaction probability.
Definition: Result.cxx:162
float Get2protonsProbability() const
Return the 2 protons topology probability.
Definition: Result.cxx:222
float GetOtherProbability() const
Return the CC Other interaction probability.
Definition: Result.cxx:192
float Get1neutronsProbability() const
Return the 1 neutrons topology probability.
Definition: Result.cxx:332
float Get1pionsProbability() const
Return the 1 pions topology probability.
Definition: Result.cxx:252
QTextStream & endl(QTextStream &s)
Numu CC DIS interaction.