Cut.h
Go to the documentation of this file.
1 #pragma once
2 
3 // This file defines the basic Cut object. For specific cuts, and examples of
4 // how to implement your own, see Cuts.h
5 
6 #include <functional>
7 
9 
10 namespace ana
11 {
12  typedef double (ExposureFunc_t)(const caf::SRSpillProxy* spill);
13 
14  /// Template for Cut and SpillCut
15  template<class T> class _Cut
16  {
17  public:
18  /// The type of the function part of a cut
19  typedef bool (CutFunc_t)(const T* sr);
20 
21  /// std::function can wrap a real function, function object, or lambda
22  _Cut(const std::function<CutFunc_t>& func,
23  const std::function<ExposureFunc_t>& liveFunc = 0,
24  const std::function<ExposureFunc_t>& potFunc = 0);
25 
26  _Cut(const _Cut<T>& c);
27 
28  _Cut& operator=(const _Cut<T>& c);
29 
30  ~_Cut();
31 
32  /// Allows a cut to be called with bool result = myCut(sr) syntax
33  bool operator()(const T* sr) const
34  {
35  return fFunc(sr);
36  }
37 
38  /// Provide a Livetime function if your cut is a timing cut etc
39  double Livetime(const caf::SRSpillProxy* spill) const
40  {
41  return fLiveFunc ? fLiveFunc(spill) : -1;
42  }
43 
44  /// Could be useful for cuts on specific batches?
45  double POT(const caf::SRSpillProxy* spill) const
46  {
47  return fPOTFunc ? fPOTFunc(spill) : -1;
48  }
49 
50  _Cut<T> operator&&(const _Cut<T>& c) const;
51  _Cut<T> operator||(const _Cut<T>& b) const;
52  _Cut<T> operator!() const;
53 
54  /// Cuts with the same definition will have the same ID
55  int ID() const {return fID;}
56 
57  static int MaxID() {return fgNextID-1;}
58 
59  // Python doesn't allow overloading and/or/not, but &/|/~ are
60  // available. Don't expose these publicly to C++ users though.
61  // This #define is set in Dict/classes.h
62 #ifdef DICT_FOR_PYTHON
63  _Cut<T> __and__(const _Cut<T>& c) const {return *this && c;}
64  _Cut<T> __or__(const _Cut<T>& c) const {return *this || c;}
65  _Cut<T> __invert__() const {return !(*this);}
66 #else
67  protected:
68 #endif
69  // Python's default implementation of and/or is very dangerous - it returns
70  // one of its operands, which means the user probably won't notice the
71  // problem. Make all checks of truthiness abort with a message.
72  operator bool() const;
73 
74  protected:
75  _Cut(const std::function<CutFunc_t>& fun,
76  const std::function<ExposureFunc_t>& liveFunc,
77  const std::function<ExposureFunc_t>& potFunc,
78  int id);
79 
80  std::function<CutFunc_t> fFunc;
81  std::function<ExposureFunc_t> fLiveFunc, fPOTFunc;
82 
83  int fID;
84  /// The next ID that hasn't yet been assigned
85  static int fgNextID;
86  };
87 
88  /// \brief Representation of a cut (selection) to be applied to a \ref
89  /// caf::StandardRecord object
90  ///
91  /// A Cut consists of a function, taking a StandardRecord and returning a
92  /// boolean indicating if that event passes the cut.
93  ///
94  /// Cut objects may be combined with the standard boolean operations && ||
95  /// and !
97 
98  /// \brief Equivalent of \ref Cut acting on \ref caf::SRSpill. For use in
99  /// spill-by-spill data quality cuts
101 
102  /// \brief Cut designed to be used over the nuTree, ie all neutrinos, not
103  /// just those that got slices.
105 
106  template<class T> struct NoCut{bool operator()(const T*) const {return true;}};
107 
108  /// The simplest possible cut: pass everything, used as a default
110 
111  /// The simplest possible cut: pass everything, used as a default
113 
114  /// The simplest possible cut: pass everything, used as a default
116 } // namespace
std::function< ExposureFunc_t > fPOTFunc
Definition: Cut.h:81
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
double Livetime(const caf::SRSpillProxy *spill) const
Provide a Livetime function if your cut is a timing cut etc.
Definition: Cut.h:39
bool operator()(const T *) const
Definition: Cut.h:106
bool( CutFunc_t)(const T *sr)
The type of the function part of a cut.
Definition: Cut.h:19
static int fgNextID
The next ID that hasn&#39;t yet been assigned.
Definition: Cut.h:85
_Cut(const std::function< CutFunc_t > &func, const std::function< ExposureFunc_t > &liveFunc=0, const std::function< ExposureFunc_t > &potFunc=0)
std::function can wrap a real function, function object, or lambda
Definition: Cut.cxx:12
double POT(const caf::SRSpillProxy *spill) const
Could be useful for cuts on specific batches?
Definition: Cut.h:45
double( ExposureFunc_t)(const caf::SRSpillProxy *spill)
Definition: Cut.h:12
_Cut< caf::SRNeutrinoProxy > NuTruthCut
Cut designed to be used over the nuTree, ie all neutrinos, not just those that got slices...
Definition: Cut.h:104
_Cut< T > operator&&(const _Cut< T > &c) const
Definition: Cut.cxx:129
const NuTruthCut kNoNuTruthCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:115
_Cut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
int ID() const
Cuts with the same definition will have the same ID.
Definition: Cut.h:55
caf::StandardRecord * sr
double func(double x, double y)
std::function< ExposureFunc_t > fLiveFunc
Definition: Cut.h:81
_Cut< caf::SRSpillProxy > SpillCut
Equivalent of Cut acting on caf::SRSpill. For use in spill-by-spill data quality cuts.
Definition: Cut.h:100
const SpillCut kNoSpillCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:112
_Cut & operator=(const _Cut< T > &c)
Definition: Cut.cxx:62
_Cut< T > operator||(const _Cut< T > &b) const
Definition: Cut.cxx:151
Proxy for caf::SRSpill.
Definition: SRProxy.h:1346
_Cut< T > operator!() const
Definition: Cut.cxx:170
const hit & b
Definition: hits.cxx:21
static int MaxID()
Definition: Cut.h:57
~_Cut()
Definition: Cut.cxx:33
double T
Definition: Xdiff_gwt.C:5
Template for Cut and SpillCut.
Definition: Cut.h:15
std::function< CutFunc_t > fFunc
Definition: Cut.h:80
bool operator()(const T *sr) const
Allows a cut to be called with bool result = myCut(sr) syntax.
Definition: Cut.h:33
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
int fID
Definition: Cut.h:83