Crombie Tools
Cutflow.h
Go to the documentation of this file.
1 #ifndef CROMBIE_CUTFLOW_H
2 #define CROMBIE_CUTFLOW_H
3 
4 #include "crombie/Types.h"
5 #include "crombie/FileConfig.h"
6 #include "crombie/LoadTree.h"
7 
8 namespace crombie {
9  namespace Cutflow {
10 
11  /// The contents of the cutflow is a vector of decreasing number of events
12  using SingleOut = std::vector<unsigned long>;
14 
15 
16  namespace {
17  // We need a reference to the result in a vector, so here's a wrapper class
18  struct Reader {
19  double& res;
20  };
21  }
22 
23 
24  /// Takes a vectors of cuts and returns a parallel cutflow vector
26  return SingleFunc {
27  [&cuts] (const FileConfig::FileInfo& info) {
28  LoadTree::Tree loaded{info.name, cuts};
29  std::vector<struct Reader> readers;
30  readers.reserve(cuts.size());
31  SingleOut output(cuts.size());
32  for (auto& cut : cuts)
33  readers.push_back({loaded.result(cut)});
34 
35  while (loaded.next()) {
36  for (unsigned icut = 0; icut < readers.size(); ++icut) {
37  if (not readers[icut].res)
38  break;
39  ++output[icut];
40  }
41  }
42 
43  return output;
44  }
45  };
46  }
47 
48 
49  /// Returns a cutflow vector
51  SingleOut output {};
52  for (auto& info : outputs) {
53  // Add the LumiSelections in the vector
54  for (auto& vec : info.second) {
55  if (output.size()) {
56  for (unsigned icut = 0; icut < output.size(); ++icut)
57  output[icut] += vec[icut];
58  }
59  else
60  output = vec;
61  }
62  }
63  return output;
64  }
65 
66  }
67 }
68 
69 #endif