All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ITCSSelectionTool.h
Go to the documentation of this file.
2 #include "fhiclcpp/ParameterSet.h"
3 
4 #include <stdlib.h>
5 #include <time.h>
6 
7 namespace sbn {
8 
10 public:
11  ITCSSelectionTool(const fhicl::ParameterSet &p):
12  fAllowT0(p.get<std::vector<bool>>("AllowT0", {})),
13  fRequireT0(p.get<bool>("RequireT0", true)),
14  fInvert(p.get<bool>("Invert", false)),
15  fNPreScale(p.get<unsigned>("PreScale", 1)),
17  {
18  // Set ISelect to a random number
19  // so that events get prescaled uniformly across runs
20  srand (time(NULL)); // random seed
21  fISelect = rand();
22  }
23 
24  virtual ~ITCSSelectionTool() noexcept = default;
25 
26  /// For external modules to call: run the actual selection
28 
29  bool has_good_t0 = t.whicht0 >= 0;
30  // Check if the T0 is allowed
31  if (!fAllowT0.empty()) {
32  if (t.whicht0 >= 0 && ((unsigned)t.whicht0 >= fAllowT0.size() || !fAllowT0[t.whicht0])) {
33  has_good_t0 = false;
34  }
35  }
36 
37  if (!has_good_t0 && fRequireT0) return false;
38 
39  bool selected = Select(t) == !fInvert /* implement inversion */;
40 
41  // update index
42  fISelect += selected;
43 
44  return selected && (fISelect % fNPreScale == 0) /* implement prescale */;
45  }
46 
47  unsigned GetPrescale() const { return fNPreScale; }
48 
49 protected:
50  /// For children to implement: Whether to select a given track
51  virtual bool Select(const TrackInfo &t) = 0;
52 
53  std::vector<bool> fAllowT0;
54  bool fRequireT0;
55  bool fInvert;
56  unsigned fNPreScale;
57  unsigned fISelect;
58 };
59 
60 } // end namespace sbn
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
unsigned GetPrescale() const
ITCSSelectionTool(const fhicl::ParameterSet &p)
virtual ~ITCSSelectionTool() noexcept=default
pdgs p
Definition: selectors.fcl:22
bool DoSelect(const TrackInfo &t)
For external modules to call: run the actual selection.
static constexpr bool
virtual bool Select(const TrackInfo &t)=0
For children to implement: Whether to select a given track.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< bool > fAllowT0
BEGIN_PROLOG default