All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include <set>
8 #include <string>
9 
10 #include "sbnana/CAFAna/Core/Var.h"
11 
12 namespace caf{class StandardRecord; class SRSpill; class SRSpillTruthBranch; class SRSlice;}
13 
14 namespace ana
15 {
16  template<class T> class _Cut;
17 
18  template<class T> _Cut<T> operator&&(const _Cut<T>& a,
19  const _Cut<T>& b);
20  template<class T> _Cut<T> operator||(const _Cut<T>& a,
21  const _Cut<T>& b);
22  template<class T> _Cut<T> operator!(const _Cut<T>& a);
23 
24  typedef double (ExposureFunc_t)(const caf::SRSpill* spill);
25 
26  /// Template for Cut and SpillCut
27  template<class T> class _Cut
28  {
29  public:
30  /// The type of the function part of a cut
31  typedef bool (CutFunc_t)(const T* sr);
32 
33  /// std::function can wrap a real function, function object, or lambda
34  _Cut(const std::function<CutFunc_t>& func,
35  const std::function<ExposureFunc_t>& liveFunc = 0,
36  const std::function<ExposureFunc_t>& potFunc = 0);
37 
38  /// Allows a cut to be called with bool result = myCut(sr) syntax
39  bool operator()(const T* sr) const
40  {
41  return fFunc(sr);
42  }
43 
44  /// Provide a Livetime function if your cut is a timing cut etc
45  double Livetime(const caf::SRSpill* spill) const
46  {
47  return fLiveFunc ? fLiveFunc(spill) : -1;
48  }
49 
50  /// Could be useful for cuts on specific batches?
51  double POT(const caf::SRSpill* spill) const
52  {
53  return fPOTFunc ? fPOTFunc(spill) : -1;
54  }
55 
56  /// Cuts with the same definition will have the same ID
57  int ID() const {return fID;}
58 
59  static int MaxID();
60 
61  protected:
62  friend std::function<ExposureFunc_t> CombineExposures(const std::function<ExposureFunc_t>& a, const std::function<ExposureFunc_t>& b);
63 
64  // Give these guys access to the constructor that sets fID.
65  friend _Cut<T> operator&&<>(const _Cut<T>& a,
66  const _Cut<T>& b);
67  friend _Cut<T> operator||<>(const _Cut<T>& a,
68  const _Cut<T>& b);
69  friend _Cut<T> operator!<>(const _Cut<T>& a);
70  _Cut(const std::function<CutFunc_t>& fun,
71  const std::function<ExposureFunc_t>& liveFunc,
72  const std::function<ExposureFunc_t>& potFunc,
73  int id)
74  : fFunc(fun), fLiveFunc(liveFunc), fPOTFunc(potFunc), fID(id)
75  {
76  }
77 
78  std::function<CutFunc_t> fFunc;
79  std::function<ExposureFunc_t> fLiveFunc, fPOTFunc;
80 
81  int fID;
82  /// The next ID that hasn't yet been assigned
83  static int fgNextID;
84  };
85 
86  /// \brief Representation of a cut (selection) to be applied to a \ref
87  /// caf::StandardRecord object
88  ///
89  /// A Cut consists of a function, taking a StandardRecord and returning a
90  /// boolean indicating if that event passes the cut.
91  ///
92  /// Cut objects may be combined with the standard boolean operations && ||
93  /// and !
96 
97  /// \brief Equivalent of \ref Cut acting on \ref caf::SRSpill. For use in
98  /// spill-by-spill data quality cuts
100 
101  /// \brief Cut designed to be used over the nuTree, ie all neutrinos, not
102  /// just those that got slices.
104 
105  template<class T> _Cut<T> operator>(const _Var<T>& v, double c);
106  template<class T> _Cut<T> operator<(const _Var<T>& v, double c);
107  template<class T> _Cut<T> operator>=(const _Var<T>& v, double c);
108  template<class T> _Cut<T> operator<=(const _Var<T>& v, double c);
109  template<class T> _Cut<T> operator==(const _Var<T>& v, double c);
110  template<class T> _Cut<T> operator!=(const _Var<T>& v, double c);
111 
112  template<class T> _Cut<T> operator>(const _Var<T>& a, const _Var<T>& b);
113  template<class T> _Cut<T> operator<(const _Var<T>& a, const _Var<T>& b);
114  template<class T> _Cut<T> operator>=(const _Var<T>& a, const _Var<T>& b);
115  template<class T> _Cut<T> operator<=(const _Var<T>& a, const _Var<T>& b);
116  template<class T> _Cut<T> operator==(const _Var<T>& a, const _Var<T>& b);
117  template<class T> _Cut<T> operator!=(const _Var<T>& a, const _Var<T>& b);
118 
119  template<class T> _Cut<T> operator>(double c, const _Var<T>& v);
120  template<class T> _Cut<T> operator<(double c, const _Var<T>& v);
121  template<class T> _Cut<T> operator>=(double c, const _Var<T>& v);
122  template<class T> _Cut<T> operator<=(double c, const _Var<T>& v);
123  template<class T> _Cut<T> operator!=(double c, const _Var<T>& v);
124 
125  /// The simplest possible cut: pass everything, used as a default
126  const Cut kNoCut([](const caf::SRSliceProxy*){return true;});
127 
128  /// The simplest possible cut: pass everything, used as a default
129  const SpillCut kNoSpillCut([](const caf::SRSpillProxy*){return true;});
130 } // namespace
const Cut kNoCut([](const caf::SRSliceProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
std::function< ExposureFunc_t > fPOTFunc
Definition: Cut.h:79
static int MaxID()
Definition: Cut.cxx:19
_Cut< T > operator!(const _Cut< T > &a)
Definition: Cut.cxx:100
_Cut< T > operator&&(const _Cut< T > &a, const _Cut< T > &b)
Definition: Cut.cxx:49
static int fgNextID
The next ID that hasn&#39;t yet been assigned.
Definition: Cut.h:83
double Livetime(const caf::SRSpill *spill) const
Provide a Livetime function if your cut is a timing cut etc.
Definition: Cut.h:45
_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:10
_Cut< T > operator||(const _Cut< T > &a, const _Cut< T > &b)
Definition: Cut.cxx:76
static constexpr bool
process_name opflashCryoW ana
caf::Proxy< caf::SRSlice > SRSliceProxy
Definition: EpilogFwd.h:2
process_name gaushit a
double( ExposureFunc_t)(const caf::SRSpill *spill)
Definition: Cut.h:24
_Cut(const std::function< CutFunc_t > &fun, const std::function< ExposureFunc_t > &liveFunc, const std::function< ExposureFunc_t > &potFunc, int id)
Definition: Cut.h:70
bool( CutFunc_t)(const T *sr)
The type of the function part of a cut.
Definition: Cut.h:31
_Cut< T > operator>=(const _Var< T > &v, double c)
Definition: Cut.cxx:128
double POT(const caf::SRSpill *spill) const
Could be useful for cuts on specific batches?
Definition: Cut.h:51
_Cut< caf::SRSliceProxy > Cut
Definition: Cut.h:95
caf::Proxy< caf::StandardRecord > SRSpillProxy
Definition: EpilogFwd.h:3
int ID() const
Cuts with the same definition will have the same ID.
Definition: Cut.h:57
const SpillCut kNoSpillCut([](const caf::SRSpillProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
std::function< ExposureFunc_t > fLiveFunc
Definition: Cut.h:79
_Cut< T > operator!=(const _Var< T > &v, double c)
Definition: Cut.cxx:156
An SRSlice contains overarching information for a slice.
Definition: SRSlice.h:24
_Cut< caf::SRSpillProxy > SpillCut
Equivalent of Cut acting on caf::SRSpill. For use in spill-by-spill data quality cuts.
Definition: Cut.h:99
friend std::function< ExposureFunc_t > CombineExposures(const std::function< ExposureFunc_t > &a, const std::function< ExposureFunc_t > &b)
Definition: Cut.cxx:26
The StandardRecord is the primary top-level object in the Common Analysis File trees.
_Cut< caf::SRSpillTruthBranch > SpillTruthCut
Cut designed to be used over the nuTree, ie all neutrinos, not just those that got slices...
Definition: Cut.h:103
_Cut< caf::SRSliceProxy > SliceCut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:94
_Cut< T > operator==(const _Var< T > &v, double c)
Definition: Cut.cxx:149
Template for Cut and SpillCut.
Definition: Cut.h:16
std::function< CutFunc_t > fFunc
Definition: Cut.h:78
_Cut< T > operator>(const _Var< T > &v, double c)
Definition: Cut.cxx:121
Most useful for combining weights.
Definition: Var.h:23
bool operator()(const T *sr) const
Allows a cut to be called with bool result = myCut(sr) syntax.
Definition: Cut.h:39
int fID
Definition: Cut.h:81