Berkeley Nuclear Data Software
CutClasses.h
Go to the documentation of this file.
1 #ifndef _CUT_CLASSES_H_
2 #define _CUT_CLASSES_H_
3 
4 //root includes
5 #include "TCutG.h"
6 //c++ includes
7 #include <vector>
8 #include <map>
9 #include <string>
10 #include <limits>
11 //don't pollute the global namespace with basic types
12 namespace NSDCuts
13 {
18 enum CutType
19 {
28  NA
29 };
30 
31 //quite nearly a type def to provide shorter but safe access
32 //for this type of structure
33 //should there be a basic template for doing this with JSON config stuff too
35 class CutTypeNameToEnum : public std::map<std::string , CutType>
36 {
37 public:
46  {
47  this->insert({"LowerBoundCut",LowerBound});
48  this->insert({"UpperBoundCut",UpperBound});
49  this->insert({"RangeCut",Range});
50  this->insert({"PolyBoundCut",PolyBound});
51  this->insert({"PolyRangeCut",PolyRange});
52  this->insert({"PHVTOFCut",PHVTOF});
53  this->insert({"IntegerListCut",IntListCut});
54  this->insert({"GraphCut",GrphCut});
55 
56  }
61  CutType operator[](std::string a_typeName) const;
62 };
63 //map used for fetching cut types from string based identifiers
64 static const CutTypeNameToEnum cutNameToEnum;
65 
66 }//end namespace might update the rest of code to
69 class CutBase
70 {
71 public:
72  //default constructor sets the cut names to ""
73  CutBase();
77  virtual bool passesCut(double a_X,
78  const std::vector<double>& a_Ys={})
79  const = 0;
80  //this is required for deep copies of derived classes
81  virtual CutBase* clone() = 0;
82  //getters
83  std::string getVarXName() const;
84  std::string getVarYName() const;
85  //setters
86  void setVarXName(std::string a_varXName);
87  void setVarYName(std::string a_varYName);
88  void setRange(double a_min,double a_max);
89 
94  TCutG* getTCut(int a_N = 10,
95  double a_minX=0,
96  double a_maxX=0,
97  std::string a_name = "CUTG"
98  );
99  virtual std::vector< std::pair<double,double> > getNPoints(int a_N,
100  double a_minX=0,
101  double a_maxX=0
102  );
103  virtual ~CutBase();
104 protected:
105  std::string m_varXName;
106  std::string m_varYName;
107  double m_rMin;
108  double m_rMax;
110 
111 };
112 
113 
115 class LowerBoundCut : public CutBase
116 {
117 public:
118  LowerBoundCut();
119  double getCutValue();
120  void setCut(double a_cutValue);
121 
122  inline bool passesCut(double a_X,
123  const std::vector<double>& a_Ys={}) const;
126  std::vector< std::pair<double,double> > getNPoints(int a_N,
127  double a_minX,
128  double a_maxX
129  );
130  LowerBoundCut* clone();
131 private:
132  double m_cutValue;
133 };
134 
136 class UpperBoundCut : public CutBase
137 {
138 public:
139  UpperBoundCut();
140  double getCutValue();
141  void setCut(double a_cutValue);
142 
143  inline bool passesCut(double a_X,
144  const std::vector<double>& a_Ys={}) const;
147  std::vector< std::pair<double,double> > getNPoints(int a_N,
148  double a_minX,
149  double a_maxX
150  );
151  UpperBoundCut* clone();
152 private:
153  double m_cutValue;
154 };
155 //used to provide cuts requiring all values to be within a range
156 class RangeCut : public CutBase
157 {
158 public:
159  RangeCut();
160  double getLowerBound();
161  double getUpperBound();
162  void setLowerBound(double a_cutValue);
163  void setUpperBound(double a_cutValue);
164 
167  inline bool passesCut(double a_X,
168  const std::vector<double>& a_Ys={}) const;
171  std::vector< std::pair<double,double> > getNPoints(int a_N,
172  double a_minX,
173  double a_maxX
174  );
175  RangeCut* clone();
176 private:
177  double m_lowerBound;
178  double m_upperBound;
179 };
180 
186 class PolyBoundCut : public CutBase
187 {
188 public:
190  PolyBoundCut();
191  //setters
192  void setCoeffs(std::vector<double> a_coeffs);
193  void setUpper(bool a_log);
194  //getters
195  std::vector<double> getCoeffs() const;
196  bool isUpper() const;
199  bool passesCut(double a_X,
200  const std::vector<double>& a_Ys={}) const;
201  //this will run a loop around the perimineter specified by the bound
202  //and the supplied range
203  std::vector< std::pair<double,double> > getNPoints(int a_N,
204  double a_minX,
205  double a_maxX
206  );
210  std::vector< std::pair<double,double> > getLine(int a_N,
211  double a_minX,
212  double a_maxX
213  );
214  PolyBoundCut* clone();
215 private:
217  std::vector<double> m_coeffs;
219  bool m_isUpper;
220 };
221 
224 class PolyRangeCut : public CutBase
225 {
226 public:
227  //default constuction creates a null boundary meaning this will return false
228  PolyRangeCut();
229  void setLowerBoundCoeffs(std::vector<double> a_coeffs);
230  void setUpperBoundCoeffs(std::vector<double> a_coeffs);
231  std::vector<double> getLowerBoundCoeffs() const;
232  std::vector<double> getUpperBoundCoeffs() const;
233  bool passesCut(double a_X,
234  const std::vector<double>& a_Ys={}) const;
235  //this will run a loop around the perimineter specified by the bound
236  //and the supplied range to generate a series of points oulinening the cuts
237  std::vector< std::pair<double,double> > getNPoints(int a_N,
238  double a_minX,
239  double a_maxX
240  );
241  PolyRangeCut* clone();
242 private:
243  PolyBoundCut m_lowerBound;
244  PolyBoundCut m_upperBound;
245 };
246 
249 class IntegerListCut : public CutBase
250 {
251 public:
253  IntegerListCut();
254  void setIntegerList(std::vector<int> a_integerList);
255 
256  bool passesCut(double a_X,
257  const std::vector<double>& a_Ys={}) const;
259 private:
260  std::vector<int> m_integerList;
261 };
262 
266 class GraphCut : public CutBase
267 {
268 public:
270  GraphCut();
271  void setPoints(std::vector< std::pair<double,double>> a_points);
272  bool passesCut(double a_X,
273  const std::vector<double>& a_Ys={}) const;
274  //this just returns the internal points ignoring the boundaries
275  std::vector< std::pair<double,double> > getNPoints(int a_N,
276  double a_minX,
277  double a_maxX
278  );
279  GraphCut* clone();
280 private:
281  std::vector< std::pair<double,double> > m_points;
282  TCutG* m_rootCut;
283 };
284 
285 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
286 //implementations of inline functions
287 bool LowerBoundCut::passesCut(double a_X,const std::vector<double>&) const
288 {
289  return a_X > m_cutValue;
290 }
291 
292 bool UpperBoundCut::passesCut(double a_X,const std::vector<double>&) const
293 {
294  return a_X < m_cutValue;
295 }
296 
297 bool RangeCut::passesCut(double a_X,const std::vector<double>&) const
298 {
299  return a_X < m_upperBound && a_X > m_lowerBound;
300 }
301 
302 
303 #endif
Definition: CutClasses.h:70
double m_rMax
Definition: CutClasses.h:108
std::string getVarXName() const
Definition: CutClasses.cpp:49
virtual CutBase * clone()=0
void setVarXName(std::string a_varXName)
Definition: CutClasses.cpp:58
virtual std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX=0, double a_maxX=0)
Definition: CutClasses.cpp:131
CutBase()
Definition: CutClasses.cpp:37
virtual bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const =0
std::string getVarYName() const
Definition: CutClasses.cpp:53
virtual ~CutBase()
Definition: CutClasses.cpp:72
void setRange(double a_min, double a_max)
Definition: CutClasses.cpp:66
std::string m_varYName
Definition: CutClasses.h:106
TCutG * getTCut(int a_N=10, double a_minX=0, double a_maxX=0, std::string a_name="CUTG")
Definition: CutClasses.cpp:81
bool m_hasRange
Definition: CutClasses.h:109
double m_rMin
Definition: CutClasses.h:107
void setVarYName(std::string a_varYName)
Definition: CutClasses.cpp:62
std::string m_varXName
Definition: CutClasses.h:105
Definition: CutClasses.h:267
GraphCut * clone()
Definition: CutClasses.cpp:493
void setPoints(std::vector< std::pair< double, double >> a_points)
Definition: CutClasses.cpp:462
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.cpp:474
GraphCut()
default constrcutor
Definition: CutClasses.cpp:458
std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:485
Definition: CutClasses.h:250
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.cpp:439
IntegerListCut()
default constructor
Definition: CutClasses.cpp:430
void setIntegerList(std::vector< int > a_integerList)
Definition: CutClasses.cpp:435
IntegerListCut * clone()
Definition: CutClasses.cpp:453
used to implement cuts requiring all values to be above a value
Definition: CutClasses.h:116
LowerBoundCut * clone()
Definition: CutClasses.cpp:175
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.h:287
std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:158
LowerBoundCut()
Definition: CutClasses.cpp:139
void setCut(double a_cutValue)
Definition: CutClasses.cpp:151
double getCutValue()
Definition: CutClasses.cpp:147
ya this should be abstracted ad
Definition: CutClasses.h:36
CutTypeNameToEnum()
Definition: CutClasses.h:45
CutType operator[](std::string a_typeName) const
Definition: CutClasses.cpp:19
Definition: CutClasses.h:187
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.cpp:294
std::vector< double > getCoeffs() const
Definition: CutClasses.cpp:284
std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:305
PolyBoundCut()
default constructor makes this a linear cut above 0.
Definition: CutClasses.cpp:266
std::vector< std::pair< double, double > > getLine(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:347
void setUpper(bool a_log)
Definition: CutClasses.cpp:279
void setCoeffs(std::vector< double > a_coeffs)
Definition: CutClasses.cpp:274
PolyBoundCut * clone()
Definition: CutClasses.cpp:364
bool isUpper() const
Definition: CutClasses.cpp:288
Definition: CutClasses.h:225
void setLowerBoundCoeffs(std::vector< double > a_coeffs)
Definition: CutClasses.cpp:375
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.cpp:391
std::vector< double > getUpperBoundCoeffs() const
Definition: CutClasses.cpp:387
std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:406
void setUpperBoundCoeffs(std::vector< double > a_coeffs)
Definition: CutClasses.cpp:379
PolyRangeCut()
Definition: CutClasses.cpp:369
PolyRangeCut * clone()
Definition: CutClasses.cpp:424
std::vector< double > getLowerBoundCoeffs() const
Definition: CutClasses.cpp:383
Definition: CutClasses.h:157
RangeCut()
Definition: CutClasses.cpp:220
void setUpperBound(double a_cutValue)
Definition: CutClasses.cpp:236
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.h:297
void setLowerBound(double a_cutValue)
Definition: CutClasses.cpp:232
double getUpperBound()
Definition: CutClasses.cpp:228
std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:243
double getLowerBound()
Definition: CutClasses.cpp:224
RangeCut * clone()
Definition: CutClasses.cpp:260
used to provide cuts requiring all values to be below a specific value
Definition: CutClasses.h:137
std::vector< std::pair< double, double > > getNPoints(int a_N, double a_minX, double a_maxX)
Definition: CutClasses.cpp:197
UpperBoundCut * clone()
Definition: CutClasses.cpp:214
UpperBoundCut()
Definition: CutClasses.cpp:180
double getCutValue()
Definition: CutClasses.cpp:187
void setCut(double a_cutValue)
Definition: CutClasses.cpp:191
bool passesCut(double a_X, const std::vector< double > &a_Ys={}) const
Definition: CutClasses.h:292
Definition: CutClasses.h:13
CutType
Definition: CutClasses.h:19
@ NA
Definition: CutClasses.h:28
@ PolyBound
Definition: CutClasses.h:23
@ IntListCut
Definition: CutClasses.h:26
@ Range
Definition: CutClasses.h:22
@ PHVTOF
Definition: CutClasses.h:25
@ PolyRange
Definition: CutClasses.h:24
@ GrphCut
Definition: CutClasses.h:27
@ LowerBound
Definition: CutClasses.h:20
@ UpperBound
Definition: CutClasses.h:21