| 11 |
// Implementation file for class DataRange |
// Implementation file for class DataRange |
| 12 |
|
|
| 13 |
#include "Fit/DataRange.h" |
#include "Fit/DataRange.h" |
| 14 |
|
#include "Math/Error.h" |
| 15 |
|
|
| 16 |
#include <algorithm> |
#include <algorithm> |
| 17 |
|
|
| 69 |
} |
} |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
void DataRange::AddRange(double xmin, double xmax, unsigned int icoord ) { |
bool lessRange( const std::pair<double,double> & r1, const std::pair<double,double> & r2 ) { |
| 73 |
|
// compare ranges using max position so in case of included ranges smaller one comes first |
| 74 |
|
return r1.second < r2.second; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
void DataRange::AddRange(unsigned int icoord , double xmin, double xmax ) { |
| 78 |
// add a range [xmin,xmax] for the new coordinate icoord |
// add a range [xmin,xmax] for the new coordinate icoord |
| 79 |
|
|
| 80 |
if (xmin >= xmax) return; // no op in case of bad values |
if (xmin >= xmax) return; // no op in case of bad values |
| 94 |
return; |
return; |
| 95 |
} |
} |
| 96 |
// case of an already existing range |
// case of an already existing range |
| 97 |
|
// need to establish a policy (use OR or AND ) |
| 98 |
|
|
| 99 |
CleanRangeSet(icoord,xmin,xmax); |
CleanRangeSet(icoord,xmin,xmax); |
| 100 |
// add the new one |
// add the new one |
| 101 |
rs.push_back(std::make_pair(xmin,xmax) ); |
rs.push_back(std::make_pair(xmin,xmax) ); |
| 102 |
// sort range in increasing values |
// sort range in increasing values of xmax |
| 103 |
std::sort( rs.begin(), rs.end() ); |
std::sort( rs.begin(), rs.end() , lessRange); |
| 104 |
|
|
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
void DataRange::SetRange(unsigned int icoord , double xmin, double xmax ) { |
| 108 |
|
// set a new range [xmin,xmax] for the new coordinate icoord |
| 109 |
|
|
| 110 |
|
if (xmin >= xmax) return; // no op in case of bad values |
| 111 |
|
|
| 112 |
|
// case the coordinate is larger than the current allocated vector size |
| 113 |
|
if (icoord >= fRanges.size() ) { |
| 114 |
|
fRanges.resize(icoord+1); |
| 115 |
|
RangeSet rs(1); |
| 116 |
|
rs[0] = std::make_pair(xmin, xmax); |
| 117 |
|
fRanges[icoord] = rs; |
| 118 |
|
return; |
| 119 |
|
} |
| 120 |
|
// add range |
| 121 |
|
RangeSet & rs = fRanges[icoord]; |
| 122 |
|
// deleting existing ones if (exists) |
| 123 |
|
if (rs.size() > 1) MATH_WARN_MSG("DataRange::SetRange","remove existing range and keep only the set one"); |
| 124 |
|
rs.resize(1); |
| 125 |
|
rs[0] = std::make_pair(xmin, xmax); |
| 126 |
|
return; |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
bool DataRange::IsInside(double x, unsigned int icoord ) const { |
bool DataRange::IsInside(double x, unsigned int icoord ) const { |