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 
123  inline bool passesCut(double a_X,
124  const std::vector<double>& a_Ys={}) const;
127  std::vector< std::pair<double,double> > getNPoints(int a_N,
128  double a_minX,
129  double a_maxX
130  );
131  LowerBoundCut* clone();
132 private:
133  double m_cutValue;
134 };
135 
137 class UpperBoundCut : public CutBase
138 {
139 public:
140  UpperBoundCut();
141  double getCutValue();
142  void setCut(double a_cutValue);
143 
144  inline bool passesCut(double a_X,
145  const std::vector<double>& a_Ys={}) const;
148  std::vector< std::pair<double,double> > getNPoints(int a_N,
149  double a_minX,
150  double a_maxX
151  );
152  UpperBoundCut* clone();
153 private:
154  double m_cutValue;
155 };
156 //used to provide cuts requiring all values to be within a range
157 class RangeCut : public CutBase
158 {
159 public:
160  RangeCut();
161  double getLowerBound();
162  double getUpperBound();
163  void setLowerBound(double a_cutValue);
164  void setUpperBound(double a_cutValue);
165 
168  inline bool passesCut(double a_X,
169  const std::vector<double>& a_Ys={}) const;
172  std::vector< std::pair<double,double> > getNPoints(int a_N,
173  double a_minX,
174  double a_maxX
175  );
176  RangeCut* clone();
177 private:
178  double m_lowerBound;
179  double m_upperBound;
180 };
181 
187 class PolyBoundCut : public CutBase
188 {
189 public:
191  PolyBoundCut();
192  //setters
193  void setCoeffs(std::vector<double> a_coeffs);
194  void setUpper(bool a_log);
195  //getters
196  std::vector<double> getCoeffs() const;
197  bool isUpper() const;
200  bool passesCut(double a_X,
201  const std::vector<double>& a_Ys={}) const;
202  //this will run a loop around the perimineter specified by the bound
203  //and the supplied range
204  std::vector< std::pair<double,double> > getNPoints(int a_N,
205  double a_minX,
206  double a_maxX
207  );
211  std::vector< std::pair<double,double> > getLine(int a_N,
212  double a_minX,
213  double a_maxX
214  );
215  PolyBoundCut* clone();
216 private:
218  std::vector<double> m_coeffs;
220  bool m_isUpper;
221 };
222 
225 class PolyRangeCut : public CutBase
226 {
227 public:
228  //default constuction creates a null boundary meaning this will return false
229  PolyRangeCut();
230  void setLowerBoundCoeffs(std::vector<double> a_coeffs);
231  void setUpperBoundCoeffs(std::vector<double> a_coeffs);
232  std::vector<double> getLowerBoundCoeffs() const;
233  std::vector<double> getUpperBoundCoeffs() const;
234  bool passesCut(double a_X,
235  const std::vector<double>& a_Ys={}) const;
236  //this will run a loop around the perimineter specified by the bound
237  //and the supplied range to generate a series of points oulinening the cuts
238  std::vector< std::pair<double,double> > getNPoints(int a_N,
239  double a_minX,
240  double a_maxX
241  );
242  PolyRangeCut* clone();
243 private:
244  PolyBoundCut m_lowerBound;
245  PolyBoundCut m_upperBound;
246 };
247 
250 class IntegerListCut : public CutBase
251 {
252 public:
254  IntegerListCut();
255  void setIntegerList(std::vector<int> a_integerList);
256 
257  bool passesCut(double a_X,
258  const std::vector<double>& a_Ys={}) const;
260 private:
261  std::vector<int> m_integerList;
262 };
263 
267 class GraphCut : public CutBase
268 {
269 public:
271  GraphCut();
272  void setPoints(std::vector< std::pair<double,double>> a_points);
273  bool passesCut(double a_X,
274  const std::vector<double>& a_Ys={}) const;
275  //this just returns the internal points ignoring the boundaries
276  std::vector< std::pair<double,double> > getNPoints(int a_N,
277  double a_minX,
278  double a_maxX
279  );
280  GraphCut* clone();
281 private:
282  std::vector< std::pair<double,double> > m_points;
283  TCutG* m_rootCut;
284 };
285 
286 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287 //implementations of inline functions
288 bool LowerBoundCut::passesCut(double a_X,const std::vector<double>&) const
289 {
290  return a_X > m_cutValue;
291 }
292 
293 bool UpperBoundCut::passesCut(double a_X,const std::vector<double>&) const
294 {
295  return a_X < m_cutValue;
296 }
297 
298 bool RangeCut::passesCut(double a_X,const std::vector<double>&) const
299 {
300  return a_X < m_upperBound && a_X > m_lowerBound;
301 }
302 
303 
304 #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:268
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:251
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:288
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:188
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:226
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:158
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:298
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:138
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:293
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