All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DynamicSelector.cc
Go to the documentation of this file.
1 #include "DynamicSelector.h"
2 #include "../uScript/api.h"
3 #include <iostream>
4 
5 template <typename T>
6 void Increment(std::vector<unsigned> &indices, const std::vector<std::vector<T>> &lists) {
7  for (unsigned i = 0; i < indices.size(); i++) {
8  indices[i] += 1;
9  if (indices[i] == lists[i].size()) {
10  indices[i] = 0;
11  }
12  else {
13  break;
14  }
15  }
16 }
17 
18 bool NotZero(const std::vector<unsigned> &indices) {
19  for (unsigned i = 0; i < indices.size(); i++) {
20  if (indices[i] != 0) return true;
21  }
22  return false;
23 }
24 
25 std::vector<std::string> numu::MultiplyNames(const std::vector<std::vector<std::string>> &strings, char join) {
26  std::vector<std::string> ret;
27  std::vector<unsigned> indices (strings.size(), 0);
28  do {
29  std::string this_str;
30  for (unsigned i = 0; i < indices.size(); i++) {
31  this_str += strings[i][indices[i]] + join;
32  }
33  ret.push_back(this_str);
34  Increment(indices, strings);
35  } while (NotZero(indices));
36  return ret;
37 }
38 
39 std::vector<numu::TrackSelector> numu::MultiplyTrackSelectors(const std::vector<std::vector<std::string>> &track_function_strings) {
40  std::vector<numu::TrackSelector> ret;
41  std::vector<std::vector<numu::TrackFunction>> track_functions;
42  for (unsigned i = 0; i < track_function_strings.size(); i++) {
43  track_functions.emplace_back();
44  for (unsigned j = 0; j < track_function_strings[i].size(); j++) {
45  track_functions[i].push_back(uscript::compile<numu::RecoTrack, numu::TrueParticle, unsigned>("track", "particle", "mctype", track_function_strings[i][j].c_str()));
46  }
47  }
48  std::vector<unsigned> indices (track_functions.size(), 0);
49  do {
50  std::vector<numu::TrackFunction> functions;
51  for (unsigned i = 0; i < indices.size(); i++) {
52  functions.push_back(track_functions[i][indices[i]]);
53  }
54  ret.push_back(
55  [functions](const numu::RecoTrack &track, const numu::TrueParticle &part, unsigned mctype) {
56  for (const numu::TrackFunction &function: functions) {
57  uscript::Value ret = function(&track, &part, &mctype);
58  if (!ret) return false;
59  }
60  return true;
61  });
62  Increment(indices, track_functions);
63  } while (NotZero(indices));
64  return ret;
65 }
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
process_name use argoneut_mc_hitfinder track
void Increment(std::vector< unsigned > &indices, const std::vector< std::vector< T >> &lists)
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< TrackSelector > MultiplyTrackSelectors(const std::vector< std::vector< std::string >> &track_function_strings)
std::function< uscript::Value(const numu::RecoTrack *, const numu::TrueParticle *, const unsigned *)> TrackFunction
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
bool NotZero(const std::vector< unsigned > &indices)
std::vector< std::string > MultiplyNames(const std::vector< std::vector< std::string >> &strings, char join='_')